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 #90

Merged
merged 11 commits into from
Oct 7, 2024
115 changes: 110 additions & 5 deletions examples/kokkos_for.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
using namespace mtr; // matar namespace

// main
int main()
int main(int argc, char* argv[])
{
Kokkos::initialize();
{
MATAR_KOKKOS_INIT
{ // kokkos scope
printf("starting test of loop macros \n");

// Kokkos::View<int *> arr("ARR", 10);
Expand Down Expand Up @@ -348,9 +348,114 @@ int main()
printf(" %d %d %d \n", i, j, k);
});

printf("done\n");
// Hierarchical

printf("\n\n\nHierarchical\n");
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(i_i, 0, 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();
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));
}
Kokkos::finalize();
//printf("\n\n");

// Hierarchical reductions

FOR_ALL(i_i, 0, hiersize, j_j, 0, hiersize, k_k, 0, hiersize, {
hierTest3D(i_i, j_j, k_k) = i_i*hiersize*hiersize+j_j*hiersize+k_k;
});

printf("\n\n\nHierarchical Reduce\n");
//2D nesting
FOR_FIRST(i_i,0,hiersize, {
// Kokkos::parallel_for( \
//Kokkos::TeamPolicy<>( 32, Kokkos::AUTO, 32 ), \
//KOKKOS_LAMBDA ( const Kokkos::TeamPolicy<>::member_type &teamMember ) {
//const int i_i = TEAM_ID;
double result = 0;
double lsum;
FOR_REDUCE_SUM_SECOND(j_j, i_i, hiersize, lsum, {
lsum += hierTest3D(i_i,j_j,0);
// 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;
}, result);
hierTest1D(i_i)= result;
//printf("value at %d is %f\n", i_i, hierTest1D(i_i));
});
Kokkos::fence();
for (int ppp = 0; ppp < hiersize; ppp++) {
//printf("%f\n", hierTest1D(ppp));
// printf("%f\n", hierTest2D(3,ppp));
// printf("%f\n", hierTest3D(3,3,ppp));
}
printf("\n\n");

printf("\n\n\nHierarchical Vectorized Reduce\n");
//3D vector nesting
FOR_FIRST(i_i,0,hiersize, {
// Kokkos::parallel_for( \
//Kokkos::TeamPolicy<>( 32, Kokkos::AUTO, 32 ), \
//KOKKOS_LAMBDA ( const Kokkos::TeamPolicy<>::member_type &teamMember ) {
//const int i_i = TEAM_ID;
double result = 0;
double lsum;
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_REDUCE_SUM_THIRD(k_k, i_i, j_j, lsum, {
lsum += hierTest3D(i_i,j_j,k_k);
// 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;
}, result);
hierTest2D(i_i,j_j)= result;
//printf("value at %d , %d is %f\n", i_i, j_j, hierTest2D(i_i,j_j));
});
});
Kokkos::fence();
for (int ppp = 0; ppp < hiersize; ppp++) {
//printf("%f\n", hierTest1D(ppp));
// printf("%f\n", hierTest2D(3,ppp));
// printf("%f\n", hierTest3D(3,3,ppp));
}
printf("\n\n");

printf("done\n");

} // end kokkos scope
MATAR_KOKKOS_FINALIZE

return 0;
}
104 changes: 0 additions & 104 deletions examples/main_kokkos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,110 +865,6 @@ int main(int argc, char* argv[])
printf("\nalias name value [0] on device = %d \n", a_carray_device(0));
});

// Hierarchical

printf("\n\n\nHierarchical\n");
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(i_i, 0, 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();
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");

// Hierarchical reductions

FOR_ALL(i_i, 0, hiersize, j_j, 0, hiersize, k_k, 0, hiersize, {
hierTest3D(i_i, j_j, k_k) = i_i*hiersize*hiersize+j_j*hiersize+k_k;
});

printf("\n\n\nHierarchical Reduce\n");
//2D nesting
FOR_FIRST(i_i, 0, hiersize, {
// Kokkos::parallel_for( \
//Kokkos::TeamPolicy<>( 32, Kokkos::AUTO, 32 ), \
//KOKKOS_LAMBDA ( const Kokkos::TeamPolicy<>::member_type &teamMember ) {
//const int i_i = TEAM_ID;
double result = 0;
double lsum;
FOR_REDUCE_SUM_SECOND(j_j, i_i, hiersize, lsum, {
lsum += hierTest3D(i_i,j_j,0);
// 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;
}, result);
hierTest1D(i_i)= result;
//printf("value at %d is %f\n", i_i, hierTest1D(i_i));
});
Kokkos::fence();
for (int ppp = 0; ppp < hiersize; ppp++) {
//printf("%f\n", hierTest1D(ppp));
// printf("%f\n", hierTest2D(3,ppp));
// printf("%f\n", hierTest3D(3,3,ppp));
}
printf("\n\n");

printf("\n\n\nHierarchical Vectorized Reduce\n");
//3D vector nesting
FOR_FIRST(i_i, 1, hiersize+1, {
// Kokkos::parallel_for( \
//Kokkos::TeamPolicy<>( 32, Kokkos::AUTO, 32 ), \
//KOKKOS_LAMBDA ( const Kokkos::TeamPolicy<>::member_type &teamMember ) {
//const int i_i = TEAM_ID;
double result = 0;
double lsum;
FOR_SECOND(j_j, i_i-1, 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_REDUCE_SUM_THIRD(k_k, i_i-1, j_j, lsum, {
lsum += hierTest3D(i_i-1,j_j,k_k);
// 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;
}, result);
hierTest2D(i_i-1,j_j)= result;
printf("value at %d , %d is %f\n", i_i, j_j, hierTest2D(i_i-1,j_j));
});
});
Kokkos::fence();
for (int ppp = 0; ppp < hiersize; ppp++) {
//printf("%f\n", hierTest1D(ppp));
// printf("%f\n", hierTest2D(3,ppp));
// printf("%f\n", hierTest3D(3,3,ppp));
}
printf("\n\n");

} // end of kokkos scope

Kokkos::finalize();
Expand Down
84 changes: 36 additions & 48 deletions examples/test_set_values.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,98 +184,86 @@ int main()
Kokkos::initialize();
{
DFArrayKokkos <double> DFAtest (2, 3, 4);
DViewFArrayKokkos <double> DVFAtest (&DFAtest(0, 0, 0), 3, 4);
DFAtest.set_values(1.25);
DVFAtest.set_values(2.34);
printf("DViewFArrayKokkos set_values 2.34 writing over DFArrayKokkos set_values 1.25.\n");
FOR_ALL(i, 0, 4,
j, 0, 3,
k, 0, 2, {
printf("%.2f ", DFAtest(k,j,i));
});
printf("\n");
FOR_ALL(i, 0, 4,
j, 0, 3,{
printf("%.2f ", DVFAtest(j,i));
});
printf("\n");
DFMatrixKokkos <double> DFMtest (2, 3, 4);
DViewFMatrixKokkos <double> DVFMtest (&DFMtest(1, 1, 1), 3, 4);
DFMtest.set_values(1.33);
DVFMtest.set_values(3.24);
printf("DViewFMatrixKokkos set_values 3.24 writing over DFMatrixKokkos set_values 1.33.\n");
FOR_ALL(i, 1, 5,
j, 1, 4,
k, 1, 3, {
printf("%.2f ", DFMtest(k,j,i));
});
printf("\n");
FOR_ALL(i, 1, 5,
j, 1, 4,{
printf("%.2f ", DVFMtest(j,i));
});
printf("\n");
DCArrayKokkos <double> DCAtest (2, 3, 4);
DViewCArrayKokkos <double> DVCAtest (&DCAtest(0, 0, 0), 3, 4);
DCAtest.set_values(1.53);
DVCAtest.set_values(2.33);
printf("DViewCArrayKokkos set_values 2.33 writing over DCArrayKokkos set_values 1.53.\n");
FOR_ALL(i, 0, 4,
j, 0, 3,
k, 0, 2, {
printf("%.2f ", DCAtest(k,j,i));
});
printf("\n");
FOR_ALL(i, 0, 4,
j, 0, 3,{
printf("%.2f ", DVCAtest(j,i));
});
printf("\n");
DCMatrixKokkos <double> DCMtest (2, 3, 4);
DViewCMatrixKokkos <double> DVCMtest (&DCMtest(1, 1, 1), 3, 4);
DCMtest.set_values(1.77);
DVCMtest.set_values(2.17);
printf("DViewCMatrixKokkos set_values 2.17 writing over DCMatrixKokkos set_values 1.77.\n");
FOR_ALL(i, 1, 5,
j, 1, 4,
k, 1, 3, {
printf("%.2f ", DCMtest(k,j,i));
});
printf("\n");
FOR_ALL(i, 1, 5,
j, 1, 4,{
printf("%.2f ", DVCMtest(j,i));
});
printf("\n");

DynamicRaggedRightArrayKokkos <double> dynrightK (3,4);
dynrightK.stride(0) = 1;
dynrightK.stride(1) = 3;
dynrightK.stride(2) = 2;
//dynrightK.stride(0) = 1;
//dynrightK.stride(1) = 3;
//dynrightK.stride(2) = 2;
RUN({
dynrightK.stride(0) = 1;
dynrightK.stride(1) = 3;
dynrightK.stride(2) = 2;
});
dynrightK.set_values(2.14);
dynrightK.set_values_sparse(1.35);
printf("The values within the populated strides of the DynamicRaggedRight are set to 1.35 and the data in the rest of the array is set to 2.14.\n");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
printf("%.2f ", dynrightK(i,j));
}
printf("\n");
}
FOR_FIRST(i, 0, 3, {
FOR_SECOND(j, 0, dynrightK.stride(i), {
//printf("%.2f ", dynrightK(i,j));
});
});
printf("\n");
//for (int i = 0; i < 3; i++) {
// for (int j = 0; j < 4; j++) {
//printf("%.2f ", dynrightK(i,j));
// }
//printf("\n");
//}
DynamicRaggedDownArrayKokkos <double> dyndownK (3,4);
dyndownK.stride(0) = 1;
dyndownK.stride(1) = 3;
dyndownK.stride(2) = 2;
dyndownK.stride(3) = 1;
RUN({
dyndownK.stride(0) = 1;
dyndownK.stride(1) = 3;
dyndownK.stride(2) = 2;
dyndownK.stride(3) = 1;
});
dyndownK.set_values(2.14);
dyndownK.set_values_sparse(1.35);
printf("The values within the populated strides of the DynamicRaggedDown are set to 1.35 and the data in the rest of the array is set to 2.14.\n");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
printf("%.2f ", dyndownK(i,j));
}
printf("\n");
}

FOR_FIRST(i, 0, 4, {
FOR_SECOND(j, 0, dyndownK.stride(i), {
//printf("%.2f ", dyndownK(i,j));
});
});
printf("\n");
//for (int i = 0; i < 4; i++) {
// for (int j = 0; j < 3; j++) {
// }
//}
}
Kokkos::finalize();
}
2 changes: 1 addition & 1 deletion scripts/matar-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fi

if [[ "$kokkos_build_type" = *"mpi"* ]]; then
cmake_options+=(
-D MPI=ON
-D Matar_ENABLE_MPI=ON
)
fi

Expand Down
2 changes: 1 addition & 1 deletion src/Kokkos/kokkos
Submodule kokkos updated 870 files
Loading
Loading