Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Daniel #77

Merged
merged 8 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@ target_include_directories(matar INTERFACE
if(Matar_ENABLE_KOKKOS)
if("${Matar_KOKKOS_PACKAGE}" STREQUAL "Trilinos")
find_package(Trilinos REQUIRED)
target_link_libraries(matar INTERFACE ${Trilinos_LIBRARIES})
add_definitions(-DTRILINOS_INTERFACE=1)
else()
find_package(Kokkos REQUIRED)
target_link_libraries(matar INTERFACE Kokkos::kokkos)
endif()
target_link_libraries(matar INTERFACE Kokkos::kokkos)
add_definitions(-DHAVE_KOKKOS=1)
endif()

Expand Down
40 changes: 38 additions & 2 deletions examples/main_kokkos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,8 @@ int main(int argc, char *argv[]) {
pass_view_by_ref(viewfmk3D);
});
Kokkos::fence();



// -----------------------
// functors
Expand Down Expand Up @@ -923,6 +923,42 @@ int main(int argc, char *argv[]) {
});


// Hierarchical

size_t hiersize = 4;
auto hierTest1D = CArrayKokkos <double> (hiersize);
auto hierTest2D = CArrayKokkos <double> (hiersize,hiersize);
auto hierTest3D = CArrayKokkos <double> (hiersize,hiersize,hiersize);
FOR_ALL(i_i, 0, hiersize, j_j, 0, hiersize, k_k, 0, hiersize, {
hierTest3D(i_i, j_j, k_k) = 0.0;
});
FOR_FIRST(hiersize,{
//Kokkos::parallel_for( \
//Kokkos::TeamPolicy<>( 32, Kokkos::AUTO, 32 ), \
//KOKKOS_LAMBDA ( const Kokkos::TeamPolicy<>::member_type &teamMember ) {
const int i_i = TEAM_ID;
FOR_SECOND(j_j,i_i,hiersize,{
//Kokkos::parallel_for( \
//Kokkos::TeamThreadRange( teamMember, istart, iend ), [&] ( const int (j_j) ) {
//hierTest2D(i_i,j_j) = i_i * (j_j+1);
// int jstart = j_j*32;
// int jend = (j_j+1)*32;
FOR_THIRD(k_k, i_i, j_j, {
printf("%d,%d,%d\n", i_i,j_j,k_k);
//hierTest3D(i_i,j_j,k_k) = i_i*j_j*k_k;
});
});
});
Kokkos::fence();
printf("\n\n\nHierarchical\n");
for (int ppp = 0; ppp < hiersize; ppp++) {
//printf("%f\n", hierTest3D(0,0,ppp));
//printf("%f\n", hierTest2D(3,ppp));
//printf("%f\n", hierTest3D(3,3,ppp));
}
printf("\n\n");




} // end of kokkos scope
Expand Down
27 changes: 27 additions & 0 deletions src/include/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,33 @@ Kokkos::parallel_reduce( \
REDUCE_MIN_CLASS(...) \
GET_MACRO(__VA_ARGS__, _13, RMINCLASS3D, _11, _10, RMINCLASS2D, _8, _7, RMINCLASS1D)(__VA_ARGS__)

#define \
TEAM_ID \
teamMember.league_rank()

#define \
THREAD_ID \
teamMember.team_rank()

#define \
FOR_FIRST(x1, fcn) \
Kokkos::parallel_for( \
Kokkos::TeamPolicy<>( x1, Kokkos::AUTO, 32 ), \
KOKKOS_LAMBDA ( const Kokkos::TeamPolicy<>::member_type &teamMember ) \
{fcn} )

#define \
FOR_SECOND(j, y0, y1, fcn) \
Kokkos::parallel_for( \
Kokkos::TeamThreadRange( teamMember, y0, y1 ), [&] ( const int (j) ) \
{fcn} )

#define \
FOR_THIRD(k, z0, z1, fcn) \
Kokkos::parallel_for( \
Kokkos::ThreadVectorRange( teamMember, z0, z1 ), [&] ( const int (k) ) \
{fcn} )

#endif


Expand Down