From afcdafeac5d4f5ade392a67cd0dac513ac58576e Mon Sep 17 00:00:00 2001 From: Daniel Dunning <39738037+djdunning@users.noreply.github.com> Date: Tue, 30 Jul 2024 10:19:31 -0600 Subject: [PATCH 1/9] missed a use case when not using MPI in the examples --- examples/CMakeLists.txt | 8 +++++--- scripts/matar-install.sh | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 050cf586..993d01df 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -14,6 +14,7 @@ set(LINKING_LIBRARIES matar) find_package(Matar REQUIRED) if (MPI) + message("We should not be here") find_package(MPI REQUIRED) add_definitions(-DHAVE_MPI=1) list(APPEND LINKING_LIBRARIES MPI::MPI_CXX) @@ -107,9 +108,10 @@ add_subdirectory(sparsetests) include_directories(test_rocm) add_subdirectory(test_rocm) - -include_directories(laplaceMPI) -add_subdirectory(laplaceMPI) +if (MPI) + include_directories(laplaceMPI) + add_subdirectory(laplaceMPI) +endif() #include_directories(phaseField/srcKokkosVerbose) #add_subdirectory(phaseField/srcKokkosVerbose) diff --git a/scripts/matar-install.sh b/scripts/matar-install.sh index ad2b0bf6..b1ef7def 100644 --- a/scripts/matar-install.sh +++ b/scripts/matar-install.sh @@ -22,7 +22,7 @@ fi if [[ "$kokkos_build_type" = *"mpi"* ]]; then cmake_options+=( - -D MPI=ON + -D Matar_ENABLE_MPI=ON ) fi From f375c8ed73ebeb324899e46f9db70b00db66ff9f Mon Sep 17 00:00:00 2001 From: Daniel Dunning <39738037+djdunning@users.noreply.github.com> Date: Tue, 30 Jul 2024 10:20:19 -0600 Subject: [PATCH 2/9] missed a use case when not using MPI in the examples --- examples/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 993d01df..384db62d 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -14,7 +14,6 @@ set(LINKING_LIBRARIES matar) find_package(Matar REQUIRED) if (MPI) - message("We should not be here") find_package(MPI REQUIRED) add_definitions(-DHAVE_MPI=1) list(APPEND LINKING_LIBRARIES MPI::MPI_CXX) From 37d96384aa38aefabc74709514d95e80ae5de97a Mon Sep 17 00:00:00 2001 From: Daniel Dunning Date: Thu, 3 Oct 2024 10:07:46 -0600 Subject: [PATCH 3/9] Matar housekeeping --- examples/test_set_values.cpp | 84 ++++++++++++++++-------------------- src/Kokkos/kokkos | 2 +- src/include/kokkos_types.h | 66 ++++------------------------ 3 files changed, 45 insertions(+), 107 deletions(-) diff --git a/examples/test_set_values.cpp b/examples/test_set_values.cpp index b02a92d1..1f7b54bf 100644 --- a/examples/test_set_values.cpp +++ b/examples/test_set_values.cpp @@ -184,9 +184,7 @@ int main() Kokkos::initialize(); { DFArrayKokkos DFAtest (2, 3, 4); - DViewFArrayKokkos 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, @@ -194,15 +192,8 @@ int main() printf("%.2f ", DFAtest(k,j,i)); }); printf("\n"); - FOR_ALL(i, 0, 4, - j, 0, 3,{ - printf("%.2f ", DVFAtest(j,i)); - }); - printf("\n"); DFMatrixKokkos DFMtest (2, 3, 4); - DViewFMatrixKokkos 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, @@ -210,15 +201,8 @@ int main() printf("%.2f ", DFMtest(k,j,i)); }); printf("\n"); - FOR_ALL(i, 1, 5, - j, 1, 4,{ - printf("%.2f ", DVFMtest(j,i)); - }); - printf("\n"); DCArrayKokkos DCAtest (2, 3, 4); - DViewCArrayKokkos 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, @@ -226,15 +210,8 @@ int main() printf("%.2f ", DCAtest(k,j,i)); }); printf("\n"); - FOR_ALL(i, 0, 4, - j, 0, 3,{ - printf("%.2f ", DVCAtest(j,i)); - }); - printf("\n"); DCMatrixKokkos DCMtest (2, 3, 4); - DViewCMatrixKokkos 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, @@ -242,40 +219,51 @@ int main() printf("%.2f ", DCMtest(k,j,i)); }); printf("\n"); - FOR_ALL(i, 1, 5, - j, 1, 4,{ - printf("%.2f ", DVCMtest(j,i)); - }); - printf("\n"); DynamicRaggedRightArrayKokkos 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, 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 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, 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(); } diff --git a/src/Kokkos/kokkos b/src/Kokkos/kokkos index 71a9bcae..22fea839 160000 --- a/src/Kokkos/kokkos +++ b/src/Kokkos/kokkos @@ -1 +1 @@ -Subproject commit 71a9bcae52543bd065522bf3e41b5bfa467d8015 +Subproject commit 22fea8395ac617d3b5a933e8cc2905a4c3b3b6f4 diff --git a/src/include/kokkos_types.h b/src/include/kokkos_types.h index 514da94f..8f7c5020 100644 --- a/src/include/kokkos_types.h +++ b/src/include/kokkos_types.h @@ -231,7 +231,6 @@ class FArrayKokkos { T* pointer() const; // set values - KOKKOS_INLINE_FUNCTION void set_values(T val); //return kokkos view @@ -543,7 +542,6 @@ const std::string FArrayKokkos::get_name() cons // set values of array template -KOKKOS_INLINE_FUNCTION void FArrayKokkos::set_values(T val) { Kokkos::parallel_for("SetValues_FArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { this_array_(i) = val; @@ -642,7 +640,6 @@ class ViewFArrayKokkos { T* pointer() const; // set values on host to input - KOKKOS_INLINE_FUNCTION void set_values(T val); KOKKOS_INLINE_FUNCTION @@ -895,7 +892,6 @@ T* ViewFArrayKokkos::pointer() const { } template -KOKKOS_INLINE_FUNCTION void ViewFArrayKokkos::set_values(T val) { Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ this_array_(i) = val; @@ -989,7 +985,6 @@ class FMatrixKokkos { T* pointer() const; // set values - KOKKOS_INLINE_FUNCTION void set_values(T val); //return kokkos view @@ -1284,7 +1279,6 @@ const std::string FMatrixKokkos::get_name() con // set values of array template -KOKKOS_INLINE_FUNCTION void FMatrixKokkos::set_values(T val) { Kokkos::parallel_for("SetValues_FMatrixKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { this_matrix_(i) = val; @@ -1384,7 +1378,6 @@ class ViewFMatrixKokkos { T* pointer() const; // set values on host to input - KOKKOS_INLINE_FUNCTION void set_values(T val); KOKKOS_INLINE_FUNCTION @@ -1640,7 +1633,6 @@ T* ViewFMatrixKokkos::pointer() const { } template -KOKKOS_INLINE_FUNCTION void ViewFMatrixKokkos::set_values(T val) { Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ this_matrix_(i) = val; @@ -1754,7 +1746,6 @@ class DFArrayKokkos { // set values on host to input - KOKKOS_INLINE_FUNCTION void set_values(T val); // Get the name of the view @@ -2061,10 +2052,9 @@ const std::string DFArrayKokkos::get_name() con } template -KOKKOS_INLINE_FUNCTION void DFArrayKokkos::set_values(T val) { Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ - this_array_.h_view(i) = val; + this_array_.d_view(i) = val; }); } @@ -2182,7 +2172,6 @@ class DViewFArrayKokkos { // set values on host to input - KOKKOS_INLINE_FUNCTION void set_values(T val); // Get the name of the view @@ -2536,10 +2525,9 @@ const std::string DViewFArrayKokkos::get_name() } template -KOKKOS_INLINE_FUNCTION void DViewFArrayKokkos::set_values(T val) { Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ - this_array_host_(i) = val; + this_array_(i) = val; }); } @@ -2647,7 +2635,6 @@ class DFMatrixKokkos { // set values on host to input - KOKKOS_INLINE_FUNCTION void set_values(T val); // Get the name of the view @@ -2954,10 +2941,9 @@ const std::string DFMatrixKokkos::get_name() co } template -KOKKOS_INLINE_FUNCTION void DFMatrixKokkos::set_values(T val) { Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ - this_matrix_.h_view(i) = val; + this_matrix_.d_view(i) = val; }); } @@ -3070,7 +3056,6 @@ class DViewFMatrixKokkos { // set values on host to input - KOKKOS_INLINE_FUNCTION void set_values(T val); // Get the name of the view @@ -3415,10 +3400,9 @@ const std::string DViewFMatrixKokkos::get_name( template -KOKKOS_INLINE_FUNCTION void DViewFMatrixKokkos::set_values(T val) { Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ - this_matrix_host_(i) = val; + this_matrix_(i) = val; }); } @@ -3511,7 +3495,6 @@ class CArrayKokkos { T* pointer() const; // set values - KOKKOS_INLINE_FUNCTION void set_values(T val); //return the view @@ -3802,7 +3785,6 @@ const std::string CArrayKokkos::get_name() cons // set values of array template -KOKKOS_INLINE_FUNCTION void CArrayKokkos::set_values(T val) { Kokkos::parallel_for("SetValues_CArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { this_array_(i) = val; @@ -3900,7 +3882,6 @@ class ViewCArrayKokkos { T* pointer() const; // set values on host to input - KOKKOS_INLINE_FUNCTION void set_values(T val); KOKKOS_INLINE_FUNCTION @@ -4151,7 +4132,6 @@ T* ViewCArrayKokkos::pointer() const { } template -KOKKOS_INLINE_FUNCTION void ViewCArrayKokkos::set_values(T val) { Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ this_array_(i) = val; @@ -4244,7 +4224,6 @@ class CMatrixKokkos { T* pointer() const; // set values - KOKKOS_INLINE_FUNCTION void set_values(T val); //return the view @@ -4541,7 +4520,6 @@ const std::string CMatrixKokkos::get_name() con // set values of array template -KOKKOS_INLINE_FUNCTION void CMatrixKokkos::set_values(T val) { Kokkos::parallel_for("SetValues_CMatrixKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { this_matrix_(i) = val; @@ -4635,7 +4613,6 @@ class ViewCMatrixKokkos { T* pointer() const; // set values on host to input - KOKKOS_INLINE_FUNCTION void set_values(T val); KOKKOS_INLINE_FUNCTION @@ -4883,7 +4860,6 @@ T* ViewCMatrixKokkos::pointer() const { } template -KOKKOS_INLINE_FUNCTION void ViewCMatrixKokkos::set_values(T val) { Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ this_matrix_(i) = val; @@ -5003,7 +4979,6 @@ class DCArrayKokkos { void update_device(); // set values on host to input - KOKKOS_INLINE_FUNCTION void set_values(T val); // Deconstructor @@ -5311,10 +5286,9 @@ void DCArrayKokkos::update_device() { } template -KOKKOS_INLINE_FUNCTION void DCArrayKokkos::set_values(T val) { Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ - this_array_.h_view(i) = val; + this_array_.d_view(i) = val; }); } @@ -5428,7 +5402,6 @@ class DViewCArrayKokkos { // set values on host to input - KOKKOS_INLINE_FUNCTION void set_values(T val); // Get the name of the view @@ -5782,10 +5755,9 @@ void DViewCArrayKokkos::update_device() { } template -KOKKOS_INLINE_FUNCTION void DViewCArrayKokkos::set_values(T val) { Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ - this_array_host_(i) = val; + this_array_(i) = val; }); } @@ -5898,7 +5870,6 @@ class DCMatrixKokkos { void update_device(); // set values on host to input - KOKKOS_INLINE_FUNCTION void set_values(T val); // Get the name of the view @@ -6205,10 +6176,9 @@ const std::string DCMatrixKokkos::get_name() co } template -KOKKOS_INLINE_FUNCTION void DCMatrixKokkos::set_values(T val) { Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ - this_matrix_.h_view(i) = val; + this_matrix_.d_view(i) = val; }); } @@ -6320,7 +6290,6 @@ class DViewCMatrixKokkos { void update_device(); // set values on host to input - KOKKOS_INLINE_FUNCTION void set_values(T val); // Get the name of the view @@ -6663,10 +6632,9 @@ const std::string DViewCMatrixKokkos::get_name( } template -KOKKOS_INLINE_FUNCTION void DViewCMatrixKokkos::set_values(T val) { Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ - this_matrix_host_(i) = val; + this_matrix_(i) = val; }); } @@ -6754,7 +6722,6 @@ class RaggedRightArrayKokkos { void print() const; //set values to input - KOKKOS_INLINE_FUNCTION void set_values(T val); // Get the name of the view @@ -7082,7 +7049,6 @@ Kokkos::View RaggedRightArrayKokkos -KOKKOS_INLINE_FUNCTION void RaggedRightArrayKokkos::set_values(T val) { Kokkos::parallel_for("SetValues_RaggedRightArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { array_(i) = val; @@ -7257,7 +7223,6 @@ class RaggedRightArrayofVectorsKokkos { }; // set values on host to input - KOKKOS_INLINE_FUNCTION void set_values(T val); // Destructor @@ -7452,7 +7417,6 @@ Kokkos::View RaggedRightArrayofVectorsKokko template -KOKKOS_INLINE_FUNCTION void RaggedRightArrayofVectorsKokkos::set_values(T val) { Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, length_), KOKKOS_CLASS_LAMBDA(const int i){ array_(i) = val; @@ -7592,7 +7556,6 @@ class RaggedDownArrayKokkos { }; // set values on host to input - KOKKOS_INLINE_FUNCTION void set_values(T val); // Destructor @@ -7827,7 +7790,6 @@ Kokkos::View RaggedDownArrayKokkos -KOKKOS_INLINE_FUNCTION void RaggedDownArrayKokkos::set_values(T val) { Kokkos::parallel_for("SetValues_RaggedDownArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { array_(i) = val; @@ -7918,11 +7880,9 @@ class DynamicRaggedRightArrayKokkos { }; // set values on host to input - KOKKOS_INLINE_FUNCTION void set_values(T val); // set values to only previously non-empty indices based upon stride value - KOKKOS_INLINE_FUNCTION void set_values_sparse(T val); // Destructor @@ -8030,7 +7990,6 @@ Kokkos::View DynamicRaggedRightArrayKokkos< //set values to input template -KOKKOS_INLINE_FUNCTION void DynamicRaggedRightArrayKokkos::set_values(T val) { Kokkos::parallel_for("SetValues_DynamicRaggedRightArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { array_(i) = val; @@ -8038,7 +7997,6 @@ void DynamicRaggedRightArrayKokkos::set_values( } template -KOKKOS_INLINE_FUNCTION void DynamicRaggedRightArrayKokkos::set_values_sparse(T val) { // Kokkos::parallel_for( Kokkos::TeamPolicy<>( dim1_, Kokkos::AUTO, 32 ), KOKKOS_CLASS_LAMBDA ( const Kokkos::TeamPolicy<>::member_type &teamMember ) { // const int i_i = teamMember.league_rank(); @@ -8136,11 +8094,9 @@ class DynamicRaggedDownArrayKokkos { }; // set values on host to input - KOKKOS_INLINE_FUNCTION void set_values(T val); // set values to only previously non-empty indices based upon stride value - KOKKOS_INLINE_FUNCTION void set_values_sparse(T val); // Destructor @@ -8249,7 +8205,6 @@ Kokkos::View DynamicRaggedDownArrayKokkos -KOKKOS_INLINE_FUNCTION void DynamicRaggedDownArrayKokkos::set_values(T val) { Kokkos::parallel_for("SetValues_DynamicRaggedDownArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { array_(i) = val; @@ -8257,7 +8212,6 @@ void DynamicRaggedDownArrayKokkos::set_values(T } template -KOKKOS_INLINE_FUNCTION void DynamicRaggedDownArrayKokkos::set_values_sparse(T val) { // Kokkos::parallel_for( Kokkos::TeamPolicy<>( dim2_, Kokkos::AUTO, 32 ), KOKKOS_CLASS_LAMBDA ( const Kokkos::TeamPolicy<>::member_type &teamMember ) { // const int j_j = teamMember.league_rank(); @@ -8468,7 +8422,6 @@ class CSRArrayKokkos { }; // set values on host to input - KOKKOS_INLINE_FUNCTION void set_values(T val); //destructor @@ -8778,7 +8731,6 @@ int CSRArray::toCSC(CArray &data, CArray &col_ptrs, CArray */ template -KOKKOS_INLINE_FUNCTION void CSRArrayKokkos::set_values(T val) { Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, nnz_), KOKKOS_CLASS_LAMBDA(const int i){ array_(i) = val; @@ -8961,7 +8913,6 @@ class CSCArrayKokkos //void to_dense(FArray &A); // set values on host to input - KOKKOS_INLINE_FUNCTION void set_values(T val); // destructor @@ -9148,7 +9099,6 @@ int CSCArrayKokkos::flat_index(size_t i, size } template -KOKKOS_INLINE_FUNCTION void CSCArrayKokkos::set_values(T val) { Kokkos:parallel_for( Kokkos::RangePolicy<> ( 0, nnz_), KOKKOS_CLASS_LAMBDA(const int i){ array_(i) = val; From 6cea5aa90d2eb8f25e9bcb2c3ae36d656fe2677d Mon Sep 17 00:00:00 2001 From: Daniel Dunning Date: Thu, 3 Oct 2024 10:45:13 -0600 Subject: [PATCH 4/9] moving tests around --- examples/kokkos_for.cpp | 115 +++++++++++++++++++++++++++++++++++++-- examples/main_kokkos.cpp | 104 ----------------------------------- 2 files changed, 110 insertions(+), 109 deletions(-) diff --git a/examples/kokkos_for.cpp b/examples/kokkos_for.cpp index 0026211a..462593bb 100644 --- a/examples/kokkos_for.cpp +++ b/examples/kokkos_for.cpp @@ -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 arr("ARR", 10); @@ -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(hiersize); + auto hierTest2D = CArrayKokkos(hiersize, hiersize); + auto hierTest3D = CArrayKokkos(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,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,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,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; } diff --git a/examples/main_kokkos.cpp b/examples/main_kokkos.cpp index 5bdc2740..cb67bb9c 100644 --- a/examples/main_kokkos.cpp +++ b/examples/main_kokkos.cpp @@ -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(hiersize); - auto hierTest2D = CArrayKokkos(hiersize, hiersize); - auto hierTest3D = CArrayKokkos(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,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,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,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"); - } // end of kokkos scope Kokkos::finalize(); From c6fdf534682d7c8d24725122aeb4e05f395ada4d Mon Sep 17 00:00:00 2001 From: Daniel Dunning Date: Thu, 3 Oct 2024 12:12:39 -0600 Subject: [PATCH 5/9] just a saving commit --- src/include/kokkos_types.h | 414 +++++++++++++++++++++++++++++++++++++ 1 file changed, 414 insertions(+) diff --git a/src/include/kokkos_types.h b/src/include/kokkos_types.h index 8f7c5020..6f1db721 100644 --- a/src/include/kokkos_types.h +++ b/src/include/kokkos_types.h @@ -6643,6 +6643,420 @@ KOKKOS_INLINE_FUNCTION DViewCMatrixKokkos::~DViewCMatrixKokkos() {} // End DViewCMatrixKokkos +/*! \brief Dynamic version of the C/FArrayKokkos type. + * + */ +template +class DynamicArrayKokkos { + + using TArray1D = Kokkos::View; + +private: + size_t dims_[7]; + size_t dim_strides_[7]; + size_t order_; + size_t length_; + TArray1D this_array_; + Strides1D this_strides_; + +public: + DynamicArrayKokkos(); + + DynamicArrayKokkos(size_t dim0, const std::string& tag_string = DEFAULTSTRINGARRAY); + + DynamicArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string = DEFAULTSTRINGARRAY); + + DynamicArrayKokkos (size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); + + DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, + size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); + + DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, + size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); + + DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, + size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGARRAY); + + DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, + size_t dim3, size_t dim4, size_t dim5, + size_t dim6, const std::string& tag_string = DEFAULTSTRINGARRAY); + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k, size_t l) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n, size_t o) const; + + KOKKOS_INLINE_FUNCTION + DynamicArrayKokkos& operator=(const DynamicArrayKokkos& temp); + + // GPU Method + // Method that returns size + KOKKOS_INLINE_FUNCTION + size_t size() const; + + // Host Method + // Method that returns size + KOKKOS_INLINE_FUNCTION + size_t extent() const; + + KOKKOS_INLINE_FUNCTION + size_t dims(size_t i) const; + + KOKKOS_INLINE_FUNCTION + size_t dims_max(size_t i) const; + + KOKKOS_INLINE_FUNCTION + size_t order() const; + + // Methods returns the raw pointer (most likely GPU) of the Kokkos View + KOKKOS_INLINE_FUNCTION + T* pointer() const; + + // set values + void set_values(T val); + + //return the view + KOKKOS_INLINE_FUNCTION + TArray1D get_kokkos_view() const; + + // Get the name of the view + KOKKOS_INLINE_FUNCTION + const std::string get_name() const; + + // Deconstructor + KOKKOS_INLINE_FUNCTION + ~DynamicArrayKokkos (); +}; // End of DynamicArrayKokkos + +// Default constructor +template +DynamicArrayKokkos::DynamicArrayKokkos() { + length_ = order_ = 0; + for (int i = 0; i < 7; i++) { + dims_[i] = 0; + dim_strides_[i] = 0; + } +} + +// Overloaded 1D constructor +template +DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + for (int i = 0; i < 1; i++) { + dim_strides_[i] = 0; + } + order_ = 1; + length_ = dim0; + this_array_ = TArray1D(tag_string, length_); +} + +// Overloaded 2D constructor +template +DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + for (int i = 0; i < 2; i++) { + dim_strides_[i] = 0; + } + order_ = 2; + length_ = (dim0 * dim1); + this_array_ = TArray1D(tag_string, length_); +} + +template +DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, size_t dim1, + size_t dim2, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + for (int i = 0; i < 3; i++) { + dim_strides_[i] = 0; + } + order_ = 3; + length_ = (dim0 * dim1 * dim2); + this_array_ = TArray1D(tag_string, length_); +} + +template +DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, size_t dim1, + size_t dim2, size_t dim3, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + for (int i = 0; i < 4; i++) { + dim_strides_[i] = 0; + } + order_ = 4; + length_ = (dim0 * dim1 * dim2 * dim3); + this_array_ = TArray1D(tag_string, length_); +} + +template +DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, size_t dim1, + size_t dim2, size_t dim3, + size_t dim4, const std::string& tag_string) { + + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + for (int i = 0; i < 5; i++) { + dim_strides_[i] = 0; + } + order_ = 5; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4); + this_array_ = TArray1D(tag_string, length_); +} + +template +DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, size_t dim1, + size_t dim2, size_t dim3, + size_t dim4, size_t dim5, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + dims_[5] = dim5; + for (int i = 0; i < 6; i++) { + dim_strides_[i] = 0; + } + order_ = 6; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5); + this_array_ = TArray1D(tag_string, length_); +} + +template +DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, size_t dim1, + size_t dim2, size_t dim3, + size_t dim4, size_t dim5, + size_t dim6, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + dims_[5] = dim5; + dims_[6] = dim6; + for (int i = 0; i < 7; i++) { + dim_strides_[i] = 0; + } + order_ = 7; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); + this_array_ = TArray1D(tag_string, length_); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicArrayKokkos::operator()(size_t i) const { + assert(order_ == 1 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 1D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 1D!"); + return this_array_(i); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicArrayKokkos::operator()(size_t i, size_t j) const { + assert(order_ == 2 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 2D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 2D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 2D!"); + return this_array_(j + (i * dims_[1])); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k) const { + assert(order_ == 3 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 3D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 3D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 3D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicArrayKokkos 3D!"); + return this_array_(k + (j * dims_[2]) + + (i * dims_[2] * dims_[1])); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { + assert(order_ == 4 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 4D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 4D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 4D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicArrayKokkos 4D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicArrayKokkos 4D!"); + return this_array_(l + (k * dims_[3]) + + (j * dims_[3] * dims_[2]) + + (i * dims_[3] * dims_[2] * dims_[1])); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, + size_t m) const { + assert(order_ == 5 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 5D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 5D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 5D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicArrayKokkos 5D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicArrayKokkos 5D!"); + assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicArrayKokkos 5D!"); + return this_array_(m + (l * dims_[4]) + + (k * dims_[4] * dims_[3]) + + (j * dims_[4] * dims_[3] * dims_[2]) + + (i * dims_[4] * dims_[3] * dims_[2] * dims_[1])); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, + size_t m, size_t n) const { + assert(order_ == 6 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 6D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 6D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 6D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicArrayKokkos 6D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicArrayKokkos 6D!"); + assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicArrayKokkos 6D!"); + assert(n >= 0 && n < dims_[5] && "n is out of bounds in DynamicArrayKokkos 6D!"); + return this_array_(n + (m * dims_[5]) + + (l * dims_[5] * dims_[4]) + + (k * dims_[5] * dims_[4] * dims_[3]) + + (j * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + + (i * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, + size_t m, size_t n, size_t o) const { + assert(order_ == 7 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 7D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 7D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 7D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicArrayKokkos 7D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicArrayKokkos 7D!"); + assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicArrayKokkos 7D!"); + assert(n >= 0 && n < dims_[5] && "n is out of bounds in DynamicArrayKokkos 7D!"); + assert(o >= 0 && o < dims_[6] && "o is out of bounds in DynamicArrayKokkos 7D!"); + return this_array_(o + (n * dims_[6]) + + (m * dims_[6] * dims_[5]) + + (l * dims_[6] * dims_[5] * dims_[4]) + + (k * dims_[6] * dims_[5] * dims_[4] * dims_[3]) + + (j * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + + (i * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); +} + +template +KOKKOS_INLINE_FUNCTION +DynamicArrayKokkos& DynamicArrayKokkos::operator= (const DynamicArrayKokkos& temp) { + using TArray1D = Kokkos::View; + + // Do nothing if the assignment is of the form x = x + if (this != &temp) { + for (int iter = 0; iter < temp.order_; iter++){ + dims_[iter] = temp.dims_[iter]; + dim_strides_[iter] = temp.dim_strides_[iter]; + } // end for + + order_ = temp.order_; + length_ = temp.length_; + this_array_ = temp.this_array_; + } + + return *this; +} + +// Return size +template +KOKKOS_INLINE_FUNCTION +size_t DynamicArrayKokkos::size() const { + return length_; +} + +template +KOKKOS_INLINE_FUNCTION +size_t DynamicArrayKokkos::extent() const { + return length_; +} + +template +KOKKOS_INLINE_FUNCTION +size_t DynamicArrayKokkos::dims(size_t i) const { + assert(i < order_ && "DynamicArrayKokkos order (rank) does not match constructor, dim[i] does not exist!"); + assert(i >= 0 && dims_[i]>0 && "Access to DynamicArrayKokkos dims is out of bounds!"); + return dims_[i]; +} + +template +KOKKOS_INLINE_FUNCTION +size_t DynamicArrayKokkos::order() const { + return order_; +} + +template +KOKKOS_INLINE_FUNCTION +T* DynamicArrayKokkos::pointer() const { + return this_array_.data(); +} + +//return the stored Kokkos view +template +KOKKOS_INLINE_FUNCTION +Kokkos::View DynamicArrayKokkos::get_kokkos_view() const { + return this_array_; +} + +// Get the name of the view +template +KOKKOS_INLINE_FUNCTION +const std::string DynamicArrayKokkos::get_name() const{ + return this_array_.label(); +} + +// set values of array +template +void DynamicArrayKokkos::set_values(T val) { + Kokkos::parallel_for("SetValues_DynamicArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { + this_array_(i) = val; + }); +} + +template +KOKKOS_INLINE_FUNCTION +DynamicArrayKokkos::~DynamicArrayKokkos() {} + +//////////////////////////////////////////////////////////////////////////////// +// End of DynamicArrayKokkos +//////////////////////////////////////////////////////////////////////////////// /*! \brief Kokkos version of the serial RaggedRightArray class. * From 52e429e1ffbafd731f8856ebf0cc1ae247f6bb46 Mon Sep 17 00:00:00 2001 From: Daniel Dunning Date: Thu, 3 Oct 2024 15:28:24 -0600 Subject: [PATCH 6/9] added other dynamic types, working on DualView ones next --- src/include/kokkos_types.h | 1493 +++++++++++++++++++++++++++++++++--- 1 file changed, 1405 insertions(+), 88 deletions(-) diff --git a/src/include/kokkos_types.h b/src/include/kokkos_types.h index 6f1db721..1f0aee3a 100644 --- a/src/include/kokkos_types.h +++ b/src/include/kokkos_types.h @@ -6643,41 +6643,40 @@ KOKKOS_INLINE_FUNCTION DViewCMatrixKokkos::~DViewCMatrixKokkos() {} // End DViewCMatrixKokkos -/*! \brief Dynamic version of the C/FArrayKokkos type. +/*! \brief Dynamic version of the CArrayKokkos type. * */ template -class DynamicArrayKokkos { +class DynamicCArrayKokkos { using TArray1D = Kokkos::View; private: size_t dims_[7]; - size_t dim_strides_[7]; + size_t dims_actual_size_[7]; size_t order_; size_t length_; TArray1D this_array_; - Strides1D this_strides_; public: - DynamicArrayKokkos(); + DynamicCArrayKokkos(); - DynamicArrayKokkos(size_t dim0, const std::string& tag_string = DEFAULTSTRINGARRAY); + DynamicCArrayKokkos(size_t dim0, const std::string& tag_string = DEFAULTSTRINGARRAY); - DynamicArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string = DEFAULTSTRINGARRAY); + DynamicCArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string = DEFAULTSTRINGARRAY); - DynamicArrayKokkos (size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); + DynamicCArrayKokkos (size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); - DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, + DynamicCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); - DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, + DynamicCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); - DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, + DynamicCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGARRAY); - DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, + DynamicCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, const std::string& tag_string = DEFAULTSTRINGARRAY); @@ -6705,7 +6704,7 @@ class DynamicArrayKokkos { size_t n, size_t o) const; KOKKOS_INLINE_FUNCTION - DynamicArrayKokkos& operator=(const DynamicArrayKokkos& temp); + DynamicCArrayKokkos& operator=(const DynamicCArrayKokkos& temp); // GPU Method // Method that returns size @@ -6726,6 +6725,9 @@ class DynamicArrayKokkos { KOKKOS_INLINE_FUNCTION size_t order() const; + //KOKKOS_INLINE_FUNCTION + //void push_back() const; + // Methods returns the raw pointer (most likely GPU) of the Kokkos View KOKKOS_INLINE_FUNCTION T* pointer() const; @@ -6743,27 +6745,27 @@ class DynamicArrayKokkos { // Deconstructor KOKKOS_INLINE_FUNCTION - ~DynamicArrayKokkos (); -}; // End of DynamicArrayKokkos + ~DynamicCArrayKokkos (); +}; // End of DynamicCArrayKokkos // Default constructor template -DynamicArrayKokkos::DynamicArrayKokkos() { +DynamicCArrayKokkos::DynamicCArrayKokkos() { length_ = order_ = 0; for (int i = 0; i < 7; i++) { dims_[i] = 0; - dim_strides_[i] = 0; + dims_actual_size_[i] = 0; } } // Overloaded 1D constructor template -DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, const std::string& tag_string) { +DynamicCArrayKokkos::DynamicCArrayKokkos(size_t dim0, const std::string& tag_string) { using TArray1D = Kokkos::View; dims_[0] = dim0; for (int i = 0; i < 1; i++) { - dim_strides_[i] = 0; + dims_actual_size_[i] = 0; } order_ = 1; length_ = dim0; @@ -6772,13 +6774,13 @@ DynamicArrayKokkos::DynamicArrayKokkos(size_t d // Overloaded 2D constructor template -DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string) { +DynamicCArrayKokkos::DynamicCArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string) { using TArray1D = Kokkos::View; dims_[0] = dim0; dims_[1] = dim1; for (int i = 0; i < 2; i++) { - dim_strides_[i] = 0; + dims_actual_size_[i] = 0; } order_ = 2; length_ = (dim0 * dim1); @@ -6786,7 +6788,7 @@ DynamicArrayKokkos::DynamicArrayKokkos(size_t d } template -DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, size_t dim1, +DynamicCArrayKokkos::DynamicCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string) { using TArray1D = Kokkos::View; @@ -6794,7 +6796,7 @@ DynamicArrayKokkos::DynamicArrayKokkos(size_t d dims_[1] = dim1; dims_[2] = dim2; for (int i = 0; i < 3; i++) { - dim_strides_[i] = 0; + dims_actual_size_[i] = 0; } order_ = 3; length_ = (dim0 * dim1 * dim2); @@ -6802,7 +6804,7 @@ DynamicArrayKokkos::DynamicArrayKokkos(size_t d } template -DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, size_t dim1, +DynamicCArrayKokkos::DynamicCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string) { using TArray1D = Kokkos::View; @@ -6811,7 +6813,7 @@ DynamicArrayKokkos::DynamicArrayKokkos(size_t d dims_[2] = dim2; dims_[3] = dim3; for (int i = 0; i < 4; i++) { - dim_strides_[i] = 0; + dims_actual_size_[i] = 0; } order_ = 4; length_ = (dim0 * dim1 * dim2 * dim3); @@ -6819,7 +6821,7 @@ DynamicArrayKokkos::DynamicArrayKokkos(size_t d } template -DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, size_t dim1, +DynamicCArrayKokkos::DynamicCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, const std::string& tag_string) { @@ -6831,7 +6833,7 @@ DynamicArrayKokkos::DynamicArrayKokkos(size_t d dims_[3] = dim3; dims_[4] = dim4; for (int i = 0; i < 5; i++) { - dim_strides_[i] = 0; + dims_actual_size_[i] = 0; } order_ = 5; length_ = (dim0 * dim1 * dim2 * dim3 * dim4); @@ -6839,7 +6841,7 @@ DynamicArrayKokkos::DynamicArrayKokkos(size_t d } template -DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, size_t dim1, +DynamicCArrayKokkos::DynamicCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string) { using TArray1D = Kokkos::View; @@ -6851,7 +6853,7 @@ DynamicArrayKokkos::DynamicArrayKokkos(size_t d dims_[4] = dim4; dims_[5] = dim5; for (int i = 0; i < 6; i++) { - dim_strides_[i] = 0; + dims_actual_size_[i] = 0; } order_ = 6; length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5); @@ -6859,7 +6861,7 @@ DynamicArrayKokkos::DynamicArrayKokkos(size_t d } template -DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, size_t dim1, +DynamicCArrayKokkos::DynamicCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, const std::string& tag_string) { @@ -6873,7 +6875,7 @@ DynamicArrayKokkos::DynamicArrayKokkos(size_t d dims_[5] = dim5; dims_[6] = dim6; for (int i = 0; i < 7; i++) { - dim_strides_[i] = 0; + dims_actual_size_[i] = 0; } order_ = 7; length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); @@ -6882,40 +6884,40 @@ DynamicArrayKokkos::DynamicArrayKokkos(size_t d template KOKKOS_INLINE_FUNCTION -T& DynamicArrayKokkos::operator()(size_t i) const { - assert(order_ == 1 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 1D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 1D!"); +T& DynamicCArrayKokkos::operator()(size_t i) const { + assert(order_ == 1 && "Tensor order (rank) does not match constructor in DynamicCArrayKokkos 1D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCArrayKokkos 1D!"); return this_array_(i); } template KOKKOS_INLINE_FUNCTION -T& DynamicArrayKokkos::operator()(size_t i, size_t j) const { - assert(order_ == 2 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 2D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 2D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 2D!"); +T& DynamicCArrayKokkos::operator()(size_t i, size_t j) const { + assert(order_ == 2 && "Tensor order (rank) does not match constructor in DynamicCArrayKokkos 2D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCArrayKokkos 2D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicCArrayKokkos 2D!"); return this_array_(j + (i * dims_[1])); } template KOKKOS_INLINE_FUNCTION -T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k) const { - assert(order_ == 3 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 3D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 3D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 3D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicArrayKokkos 3D!"); +T& DynamicCArrayKokkos::operator()(size_t i, size_t j, size_t k) const { + assert(order_ == 3 && "Tensor order (rank) does not match constructor in DynamicCArrayKokkos 3D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCArrayKokkos 3D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicCArrayKokkos 3D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicCArrayKokkos 3D!"); return this_array_(k + (j * dims_[2]) + (i * dims_[2] * dims_[1])); } template KOKKOS_INLINE_FUNCTION -T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { - assert(order_ == 4 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 4D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 4D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 4D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicArrayKokkos 4D!"); - assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicArrayKokkos 4D!"); +T& DynamicCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { + assert(order_ == 4 && "Tensor order (rank) does not match constructor in DynamicCArrayKokkos 4D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCArrayKokkos 4D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicCArrayKokkos 4D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicCArrayKokkos 4D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicCArrayKokkos 4D!"); return this_array_(l + (k * dims_[3]) + (j * dims_[3] * dims_[2]) + (i * dims_[3] * dims_[2] * dims_[1])); @@ -6923,14 +6925,14 @@ T& DynamicArrayKokkos::operator()(size_t i, siz template KOKKOS_INLINE_FUNCTION -T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, +T& DynamicCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { - assert(order_ == 5 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 5D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 5D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 5D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicArrayKokkos 5D!"); - assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicArrayKokkos 5D!"); - assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicArrayKokkos 5D!"); + assert(order_ == 5 && "Tensor order (rank) does not match constructor in DynamicCArrayKokkos 5D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCArrayKokkos 5D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicCArrayKokkos 5D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicCArrayKokkos 5D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicCArrayKokkos 5D!"); + assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicCArrayKokkos 5D!"); return this_array_(m + (l * dims_[4]) + (k * dims_[4] * dims_[3]) + (j * dims_[4] * dims_[3] * dims_[2]) @@ -6939,15 +6941,15 @@ T& DynamicArrayKokkos::operator()(size_t i, siz template KOKKOS_INLINE_FUNCTION -T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, +T& DynamicCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const { - assert(order_ == 6 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 6D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 6D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 6D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicArrayKokkos 6D!"); - assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicArrayKokkos 6D!"); - assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicArrayKokkos 6D!"); - assert(n >= 0 && n < dims_[5] && "n is out of bounds in DynamicArrayKokkos 6D!"); + assert(order_ == 6 && "Tensor order (rank) does not match constructor in DynamicCArrayKokkos 6D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCArrayKokkos 6D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicCArrayKokkos 6D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicCArrayKokkos 6D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicCArrayKokkos 6D!"); + assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicCArrayKokkos 6D!"); + assert(n >= 0 && n < dims_[5] && "n is out of bounds in DynamicCArrayKokkos 6D!"); return this_array_(n + (m * dims_[5]) + (l * dims_[5] * dims_[4]) + (k * dims_[5] * dims_[4] * dims_[3]) @@ -6957,16 +6959,16 @@ T& DynamicArrayKokkos::operator()(size_t i, siz template KOKKOS_INLINE_FUNCTION -T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, +T& DynamicCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const { - assert(order_ == 7 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 7D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 7D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 7D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicArrayKokkos 7D!"); - assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicArrayKokkos 7D!"); - assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicArrayKokkos 7D!"); - assert(n >= 0 && n < dims_[5] && "n is out of bounds in DynamicArrayKokkos 7D!"); - assert(o >= 0 && o < dims_[6] && "o is out of bounds in DynamicArrayKokkos 7D!"); + assert(order_ == 7 && "Tensor order (rank) does not match constructor in DynamicCArrayKokkos 7D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCArrayKokkos 7D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicCArrayKokkos 7D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicCArrayKokkos 7D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicCArrayKokkos 7D!"); + assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicCArrayKokkos 7D!"); + assert(n >= 0 && n < dims_[5] && "n is out of bounds in DynamicCArrayKokkos 7D!"); + assert(o >= 0 && o < dims_[6] && "o is out of bounds in DynamicCArrayKokkos 7D!"); return this_array_(o + (n * dims_[6]) + (m * dims_[6] * dims_[5]) + (l * dims_[6] * dims_[5] * dims_[4]) @@ -6977,14 +6979,14 @@ T& DynamicArrayKokkos::operator()(size_t i, siz template KOKKOS_INLINE_FUNCTION -DynamicArrayKokkos& DynamicArrayKokkos::operator= (const DynamicArrayKokkos& temp) { +DynamicCArrayKokkos& DynamicCArrayKokkos::operator= (const DynamicCArrayKokkos& temp) { using TArray1D = Kokkos::View; // Do nothing if the assignment is of the form x = x if (this != &temp) { for (int iter = 0; iter < temp.order_; iter++){ dims_[iter] = temp.dims_[iter]; - dim_strides_[iter] = temp.dim_strides_[iter]; + dims_actual_size_[iter] = temp.dims_actual_size_[iter]; } // end for order_ = temp.order_; @@ -6998,64 +7000,1379 @@ DynamicArrayKokkos& DynamicArrayKokkos KOKKOS_INLINE_FUNCTION -size_t DynamicArrayKokkos::size() const { +size_t DynamicCArrayKokkos::size() const { return length_; } template KOKKOS_INLINE_FUNCTION -size_t DynamicArrayKokkos::extent() const { +size_t DynamicCArrayKokkos::extent() const { return length_; } template KOKKOS_INLINE_FUNCTION -size_t DynamicArrayKokkos::dims(size_t i) const { - assert(i < order_ && "DynamicArrayKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(i >= 0 && dims_[i]>0 && "Access to DynamicArrayKokkos dims is out of bounds!"); +size_t DynamicCArrayKokkos::dims(size_t i) const { + assert(i < order_ && "DynamicCArrayKokkos order (rank) does not match constructor, dim[i] does not exist!"); + assert(i >= 0 && dims_actual_size_[i]>0 && "Access to DynamicCArrayKokkos dims is out of bounds!"); + return dims_actual_size_[i]; +} + +template +KOKKOS_INLINE_FUNCTION +size_t DynamicCArrayKokkos::dims_max(size_t i) const { + assert(i < order_ && "DynamicCArrayKokkos order (rank) does not match constructor, dim[i] does not exist!"); + assert(i >= 0 && dims_[i]>0 && "Access to DynamicCArrayKokkos dims is out of bounds!"); return dims_[i]; } template KOKKOS_INLINE_FUNCTION -size_t DynamicArrayKokkos::order() const { +size_t DynamicCArrayKokkos::order() const { return order_; } +/* +template +KOKKOS_INLINE_FUNCTION +void DynamicCArrayKokkos::push_back(size_t dim_idx) const { + dims_actual_size_[dim_idx]++; +} +*/ + template KOKKOS_INLINE_FUNCTION -T* DynamicArrayKokkos::pointer() const { +T* DynamicCArrayKokkos::pointer() const { return this_array_.data(); } //return the stored Kokkos view template KOKKOS_INLINE_FUNCTION -Kokkos::View DynamicArrayKokkos::get_kokkos_view() const { +Kokkos::View DynamicCArrayKokkos::get_kokkos_view() const { return this_array_; } // Get the name of the view template KOKKOS_INLINE_FUNCTION -const std::string DynamicArrayKokkos::get_name() const{ +const std::string DynamicCArrayKokkos::get_name() const{ return this_array_.label(); } // set values of array template -void DynamicArrayKokkos::set_values(T val) { - Kokkos::parallel_for("SetValues_DynamicArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { +void DynamicCArrayKokkos::set_values(T val) { + Kokkos::parallel_for("SetValues_DynamicCArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { this_array_(i) = val; }); } template KOKKOS_INLINE_FUNCTION -DynamicArrayKokkos::~DynamicArrayKokkos() {} +DynamicCArrayKokkos::~DynamicCArrayKokkos() {} + +//////////////////////////////////////////////////////////////////////////////// +// End of DynamicCArrayKokkos +//////////////////////////////////////////////////////////////////////////////// + +/*! \brief Dynamic version of the CArrayKokkos type. + * + */ +template +class DynamicFArrayKokkos { + + using TArray1D = Kokkos::View; + +private: + size_t dims_[7]; + size_t dims_actual_size_[7]; + size_t order_; + size_t length_; + TArray1D this_array_; + +public: + DynamicFArrayKokkos(); + + DynamicFArrayKokkos(size_t dim0, const std::string& tag_string = DEFAULTSTRINGARRAY); + + DynamicFArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string = DEFAULTSTRINGARRAY); + + DynamicFArrayKokkos (size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); + + DynamicFArrayKokkos(size_t dim0, size_t dim1, size_t dim2, + size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); + + DynamicFArrayKokkos(size_t dim0, size_t dim1, size_t dim2, + size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); + + DynamicFArrayKokkos(size_t dim0, size_t dim1, size_t dim2, + size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGARRAY); + + DynamicFArrayKokkos(size_t dim0, size_t dim1, size_t dim2, + size_t dim3, size_t dim4, size_t dim5, + size_t dim6, const std::string& tag_string = DEFAULTSTRINGARRAY); + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k, size_t l) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n, size_t o) const; + + KOKKOS_INLINE_FUNCTION + DynamicFArrayKokkos& operator=(const DynamicFArrayKokkos& temp); + + // GPU Method + // Method that returns size + KOKKOS_INLINE_FUNCTION + size_t size() const; + + // Host Method + // Method that returns size + KOKKOS_INLINE_FUNCTION + size_t extent() const; + + KOKKOS_INLINE_FUNCTION + size_t dims(size_t i) const; + + KOKKOS_INLINE_FUNCTION + size_t dims_max(size_t i) const; + + KOKKOS_INLINE_FUNCTION + size_t order() const; + + //KOKKOS_INLINE_FUNCTION + //void push_back() const; + + // Methods returns the raw pointer (most likely GPU) of the Kokkos View + KOKKOS_INLINE_FUNCTION + T* pointer() const; + + // set values + void set_values(T val); + + //return the view + KOKKOS_INLINE_FUNCTION + TArray1D get_kokkos_view() const; + + // Get the name of the view + KOKKOS_INLINE_FUNCTION + const std::string get_name() const; + + // Deconstructor + KOKKOS_INLINE_FUNCTION + ~DynamicFArrayKokkos (); +}; // End of DynamicFArrayKokkos + +// Default constructor +template +DynamicFArrayKokkos::DynamicFArrayKokkos() { + length_ = order_ = 0; + for (int i = 0; i < 7; i++) { + dims_[i] = 0; + dims_actual_size_[i] = 0; + } +} + +// Overloaded 1D constructor +template +DynamicFArrayKokkos::DynamicFArrayKokkos(size_t dim0, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + for (int i = 0; i < 1; i++) { + dims_actual_size_[i] = 0; + } + order_ = 1; + length_ = dim0; + this_array_ = TArray1D(tag_string, length_); +} + +// Overloaded 2D constructor +template +DynamicFArrayKokkos::DynamicFArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + for (int i = 0; i < 2; i++) { + dims_actual_size_[i] = 0; + } + order_ = 2; + length_ = (dim0 * dim1); + this_array_ = TArray1D(tag_string, length_); +} + +template +DynamicFArrayKokkos::DynamicFArrayKokkos(size_t dim0, size_t dim1, + size_t dim2, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + for (int i = 0; i < 3; i++) { + dims_actual_size_[i] = 0; + } + order_ = 3; + length_ = (dim0 * dim1 * dim2); + this_array_ = TArray1D(tag_string, length_); +} + +template +DynamicFArrayKokkos::DynamicFArrayKokkos(size_t dim0, size_t dim1, + size_t dim2, size_t dim3, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + for (int i = 0; i < 4; i++) { + dims_actual_size_[i] = 0; + } + order_ = 4; + length_ = (dim0 * dim1 * dim2 * dim3); + this_array_ = TArray1D(tag_string, length_); +} + +template +DynamicFArrayKokkos::DynamicFArrayKokkos(size_t dim0, size_t dim1, + size_t dim2, size_t dim3, + size_t dim4, const std::string& tag_string) { + + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + for (int i = 0; i < 5; i++) { + dims_actual_size_[i] = 0; + } + order_ = 5; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4); + this_array_ = TArray1D(tag_string, length_); +} + +template +DynamicFArrayKokkos::DynamicFArrayKokkos(size_t dim0, size_t dim1, + size_t dim2, size_t dim3, + size_t dim4, size_t dim5, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + dims_[5] = dim5; + for (int i = 0; i < 6; i++) { + dims_actual_size_[i] = 0; + } + order_ = 6; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5); + this_array_ = TArray1D(tag_string, length_); +} + +template +DynamicFArrayKokkos::DynamicFArrayKokkos(size_t dim0, size_t dim1, + size_t dim2, size_t dim3, + size_t dim4, size_t dim5, + size_t dim6, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + dims_[5] = dim5; + dims_[6] = dim6; + for (int i = 0; i < 7; i++) { + dims_actual_size_[i] = 0; + } + order_ = 7; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); + this_array_ = TArray1D(tag_string, length_); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicFArrayKokkos::operator()(size_t i) const { + assert(order_ == 1 && "Tensor order (rank) does not match constructor in DynamicFArrayKokkos 1D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFArrayKokkos 1D!"); + return this_array_(i); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicFArrayKokkos::operator()(size_t i, size_t j) const { + assert(order_ == 2 && "Tensor order (rank) does not match constructor in DynamicFArrayKokkos 2D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFArrayKokkos 2D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicFArrayKokkos 2D!"); + return this_array_(j + (i * dims_[1])); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicFArrayKokkos::operator()(size_t i, size_t j, size_t k) const { + assert(order_ == 3 && "Tensor order (rank) does not match constructor in DynamicFArrayKokkos 3D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFArrayKokkos 3D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicFArrayKokkos 3D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicFArrayKokkos 3D!"); + return this_array_(k + (j * dims_[2]) + + (i * dims_[2] * dims_[1])); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { + assert(order_ == 4 && "Tensor order (rank) does not match constructor in DynamicFArrayKokkos 4D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFArrayKokkos 4D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicFArrayKokkos 4D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicFArrayKokkos 4D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicFArrayKokkos 4D!"); + return this_array_(l + (k * dims_[3]) + + (j * dims_[3] * dims_[2]) + + (i * dims_[3] * dims_[2] * dims_[1])); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, + size_t m) const { + assert(order_ == 5 && "Tensor order (rank) does not match constructor in DynamicFArrayKokkos 5D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFArrayKokkos 5D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicFArrayKokkos 5D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicFArrayKokkos 5D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicFArrayKokkos 5D!"); + assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicFArrayKokkos 5D!"); + return this_array_(m + (l * dims_[4]) + + (k * dims_[4] * dims_[3]) + + (j * dims_[4] * dims_[3] * dims_[2]) + + (i * dims_[4] * dims_[3] * dims_[2] * dims_[1])); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, + size_t m, size_t n) const { + assert(order_ == 6 && "Tensor order (rank) does not match constructor in DynamicFArrayKokkos 6D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFArrayKokkos 6D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicFArrayKokkos 6D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicFArrayKokkos 6D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicFArrayKokkos 6D!"); + assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicFArrayKokkos 6D!"); + assert(n >= 0 && n < dims_[5] && "n is out of bounds in DynamicFArrayKokkos 6D!"); + return this_array_(n + (m * dims_[5]) + + (l * dims_[5] * dims_[4]) + + (k * dims_[5] * dims_[4] * dims_[3]) + + (j * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + + (i * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, + size_t m, size_t n, size_t o) const { + assert(order_ == 7 && "Tensor order (rank) does not match constructor in DynamicFArrayKokkos 7D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFArrayKokkos 7D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicFArrayKokkos 7D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicFArrayKokkos 7D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicFArrayKokkos 7D!"); + assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicFArrayKokkos 7D!"); + assert(n >= 0 && n < dims_[5] && "n is out of bounds in DynamicFArrayKokkos 7D!"); + assert(o >= 0 && o < dims_[6] && "o is out of bounds in DynamicFArrayKokkos 7D!"); + return this_array_(o + (n * dims_[6]) + + (m * dims_[6] * dims_[5]) + + (l * dims_[6] * dims_[5] * dims_[4]) + + (k * dims_[6] * dims_[5] * dims_[4] * dims_[3]) + + (j * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + + (i * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); +} + +template +KOKKOS_INLINE_FUNCTION +DynamicFArrayKokkos& DynamicFArrayKokkos::operator= (const DynamicFArrayKokkos& temp) { + using TArray1D = Kokkos::View; + + // Do nothing if the assignment is of the form x = x + if (this != &temp) { + for (int iter = 0; iter < temp.order_; iter++){ + dims_[iter] = temp.dims_[iter]; + dims_actual_size_[iter] = temp.dims_actual_size_[iter]; + } // end for + + order_ = temp.order_; + length_ = temp.length_; + this_array_ = temp.this_array_; + } + + return *this; +} + +// Return size +template +KOKKOS_INLINE_FUNCTION +size_t DynamicFArrayKokkos::size() const { + return length_; +} + +template +KOKKOS_INLINE_FUNCTION +size_t DynamicFArrayKokkos::extent() const { + return length_; +} + +template +KOKKOS_INLINE_FUNCTION +size_t DynamicFArrayKokkos::dims(size_t i) const { + assert(i < order_ && "DynamicFArrayKokkos order (rank) does not match constructor, dim[i] does not exist!"); + assert(i >= 0 && dims_actual_size_[i]>0 && "Access to DynamicFArrayKokkos dims is out of bounds!"); + return dims_actual_size_[i]; +} + +template +KOKKOS_INLINE_FUNCTION +size_t DynamicFArrayKokkos::dims_max(size_t i) const { + assert(i < order_ && "DynamicFArrayKokkos order (rank) does not match constructor, dim[i] does not exist!"); + assert(i >= 0 && dims_[i]>0 && "Access to DynamicFArrayKokkos dims is out of bounds!"); + return dims_[i]; +} + +template +KOKKOS_INLINE_FUNCTION +size_t DynamicFArrayKokkos::order() const { + return order_; +} + +/* +template +KOKKOS_INLINE_FUNCTION +void DynamicFArrayKokkos::push_back(size_t dim_idx) const { + dims_actual_size_[dim_idx]++; +} +*/ + +template +KOKKOS_INLINE_FUNCTION +T* DynamicFArrayKokkos::pointer() const { + return this_array_.data(); +} + +//return the stored Kokkos view +template +KOKKOS_INLINE_FUNCTION +Kokkos::View DynamicFArrayKokkos::get_kokkos_view() const { + return this_array_; +} + +// Get the name of the view +template +KOKKOS_INLINE_FUNCTION +const std::string DynamicFArrayKokkos::get_name() const{ + return this_array_.label(); +} + +// set values of array +template +void DynamicFArrayKokkos::set_values(T val) { + Kokkos::parallel_for("SetValues_DynamicFArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { + this_array_(i) = val; + }); +} + +template +KOKKOS_INLINE_FUNCTION +DynamicFArrayKokkos::~DynamicFArrayKokkos() {} + +//////////////////////////////////////////////////////////////////////////////// +// End of DynamicFArrayKokkos +//////////////////////////////////////////////////////////////////////////////// + +/*! \brief Dynamic version of the CArrayKokkos type. + * + */ +template +class DynamicCMatrixKokkos { + + using TArray1D = Kokkos::View; + +private: + size_t dims_[7]; + size_t dims_actual_size_[7]; + size_t order_; + size_t length_; + TArray1D this_matrix_; + +public: + DynamicCMatrixKokkos(); + + DynamicCMatrixKokkos(size_t dim0, const std::string& tag_string = DEFAULTSTRINGARRAY); + + DynamicCMatrixKokkos(size_t dim0, size_t dim1, const std::string& tag_string = DEFAULTSTRINGARRAY); + + DynamicCMatrixKokkos (size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); + + DynamicCMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, + size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); + + DynamicCMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, + size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); + + DynamicCMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, + size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGARRAY); + + DynamicCMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, + size_t dim3, size_t dim4, size_t dim5, + size_t dim6, const std::string& tag_string = DEFAULTSTRINGARRAY); + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k, size_t l) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n, size_t o) const; + + KOKKOS_INLINE_FUNCTION + DynamicCMatrixKokkos& operator=(const DynamicCMatrixKokkos& temp); + + // GPU Method + // Method that returns size + KOKKOS_INLINE_FUNCTION + size_t size() const; + + // Host Method + // Method that returns size + KOKKOS_INLINE_FUNCTION + size_t extent() const; + + KOKKOS_INLINE_FUNCTION + size_t dims(size_t i) const; + + KOKKOS_INLINE_FUNCTION + size_t dims_max(size_t i) const; + + KOKKOS_INLINE_FUNCTION + size_t order() const; + + //KOKKOS_INLINE_FUNCTION + //void push_back() const; + + // Methods returns the raw pointer (most likely GPU) of the Kokkos View + KOKKOS_INLINE_FUNCTION + T* pointer() const; + + // set values + void set_values(T val); + + //return the view + KOKKOS_INLINE_FUNCTION + TArray1D get_kokkos_view() const; + + // Get the name of the view + KOKKOS_INLINE_FUNCTION + const std::string get_name() const; + + // Deconstructor + KOKKOS_INLINE_FUNCTION + ~DynamicCMatrixKokkos (); +}; // End of DynamicCMatrixKokkos + +// Default constructor +template +DynamicCMatrixKokkos::DynamicCMatrixKokkos() { + length_ = order_ = 0; + for (int i = 0; i < 7; i++) { + dims_[i] = 0; + dims_actual_size_[i] = 0; + } +} + +// Overloaded 1D constructor +template +DynamicCMatrixKokkos::DynamicCMatrixKokkos(size_t dim0, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + for (int i = 0; i < 1; i++) { + dims_actual_size_[i] = 0; + } + order_ = 1; + length_ = dim0; + this_matrix_ = TArray1D(tag_string, length_); +} + +// Overloaded 2D constructor +template +DynamicCMatrixKokkos::DynamicCMatrixKokkos(size_t dim0, size_t dim1, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + for (int i = 0; i < 2; i++) { + dims_actual_size_[i] = 0; + } + order_ = 2; + length_ = (dim0 * dim1); + this_matrix_ = TArray1D(tag_string, length_); +} + +template +DynamicCMatrixKokkos::DynamicCMatrixKokkos(size_t dim0, size_t dim1, + size_t dim2, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + for (int i = 0; i < 3; i++) { + dims_actual_size_[i] = 0; + } + order_ = 3; + length_ = (dim0 * dim1 * dim2); + this_matrix_ = TArray1D(tag_string, length_); +} + +template +DynamicCMatrixKokkos::DynamicCMatrixKokkos(size_t dim0, size_t dim1, + size_t dim2, size_t dim3, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + for (int i = 0; i < 4; i++) { + dims_actual_size_[i] = 0; + } + order_ = 4; + length_ = (dim0 * dim1 * dim2 * dim3); + this_matrix_ = TArray1D(tag_string, length_); +} + +template +DynamicCMatrixKokkos::DynamicCMatrixKokkos(size_t dim0, size_t dim1, + size_t dim2, size_t dim3, + size_t dim4, const std::string& tag_string) { + + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + for (int i = 0; i < 5; i++) { + dims_actual_size_[i] = 0; + } + order_ = 5; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4); + this_matrix_ = TArray1D(tag_string, length_); +} + +template +DynamicCMatrixKokkos::DynamicCMatrixKokkos(size_t dim0, size_t dim1, + size_t dim2, size_t dim3, + size_t dim4, size_t dim5, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + dims_[5] = dim5; + for (int i = 0; i < 6; i++) { + dims_actual_size_[i] = 0; + } + order_ = 6; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5); + this_matrix_ = TArray1D(tag_string, length_); +} + +template +DynamicCMatrixKokkos::DynamicCMatrixKokkos(size_t dim0, size_t dim1, + size_t dim2, size_t dim3, + size_t dim4, size_t dim5, + size_t dim6, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + dims_[5] = dim5; + dims_[6] = dim6; + for (int i = 0; i < 7; i++) { + dims_actual_size_[i] = 0; + } + order_ = 7; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); + this_matrix_ = TArray1D(tag_string, length_); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicCMatrixKokkos::operator()(size_t i) const { + assert(order_ == 1 && "Tensor order (rank) does not match constructor in DynamicCMatrixKokkos 1D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCMatrixKokkos 1D!"); + return this_matrix_((i - 1)); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicCMatrixKokkos::operator()(size_t i, size_t j) const { + assert(order_ == 2 && "Tensor order (rank) does not match constructor in DynamicCMatrixKokkos 2D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCMatrixKokkos 2D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicCMatrixKokkos 2D!"); + return this_matrix_((j - 1) + ((i - 1) * dims_[1])); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicCMatrixKokkos::operator()(size_t i, size_t j, size_t k) const { + assert(order_ == 3 && "Tensor order (rank) does not match constructor in DynamicCMatrixKokkos 3D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCMatrixKokkos 3D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicCMatrixKokkos 3D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicCMatrixKokkos 3D!"); + return this_matrix_((k - 1) + ((j - 1) * dims_[2]) + + ((i - 1) * dims_[2] * dims_[1])); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { + assert(order_ == 4 && "Tensor order (rank) does not match constructor in DynamicCMatrixKokkos 4D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCMatrixKokkos 4D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicCMatrixKokkos 4D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicCMatrixKokkos 4D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicCMatrixKokkos 4D!"); + return this_matrix_((l - 1) + ((k - 1) * dims_[3]) + + ((j - 1) * dims_[3] * dims_[2]) + + ((i - 1) * dims_[3] * dims_[2] * dims_[1])); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, + size_t m) const { + assert(order_ == 5 && "Tensor order (rank) does not match constructor in DynamicCMatrixKokkos 5D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCMatrixKokkos 5D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicCMatrixKokkos 5D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicCMatrixKokkos 5D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicCMatrixKokkos 5D!"); + assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicCMatrixKokkos 5D!"); + return this_matrix_((m - 1) + ((l - 1) * dims_[4]) + + ((k - 1) * dims_[4] * dims_[3]) + + ((j - 1) * dims_[4] * dims_[3] * dims_[2]) + + ((i - 1) * dims_[4] * dims_[3] * dims_[2] * dims_[1])); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, + size_t m, size_t n) const { + assert(order_ == 6 && "Tensor order (rank) does not match constructor in DynamicCMatrixKokkos 6D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCMatrixKokkos 6D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicCMatrixKokkos 6D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicCMatrixKokkos 6D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicCMatrixKokkos 6D!"); + assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicCMatrixKokkos 6D!"); + assert(n >= 0 && n < dims_[5] && "n is out of bounds in DynamicCMatrixKokkos 6D!"); + return this_matrix_((n - 1) + ((m - 1) * dims_[5]) + + ((l - 1) * dims_[5] * dims_[4]) + + ((k - 1) * dims_[5] * dims_[4] * dims_[3]) + + ((j - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + + ((i - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, + size_t m, size_t n, size_t o) const { + assert(order_ == 7 && "Tensor order (rank) does not match constructor in DynamicCMatrixKokkos 7D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCMatrixKokkos 7D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicCMatrixKokkos 7D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicCMatrixKokkos 7D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicCMatrixKokkos 7D!"); + assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicCMatrixKokkos 7D!"); + assert(n >= 0 && n < dims_[5] && "n is out of bounds in DynamicCMatrixKokkos 7D!"); + assert(o >= 0 && o < dims_[6] && "o is out of bounds in DynamicCMatrixKokkos 7D!"); + return this_matrix_((o - 1) + ((n - 1) * dims_[6]) + + ((m - 1) * dims_[6] * dims_[5]) + + ((l - 1) * dims_[6] * dims_[5] * dims_[4]) + + ((k - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3]) + + ((j - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + + ((i - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); +} + +template +KOKKOS_INLINE_FUNCTION +DynamicCMatrixKokkos& DynamicCMatrixKokkos::operator= (const DynamicCMatrixKokkos& temp) { + using TArray1D = Kokkos::View; + + // Do nothing if the assignment is of the form x = x + if (this != &temp) { + for (int iter = 0; iter < temp.order_; iter++){ + dims_[iter] = temp.dims_[iter]; + dims_actual_size_[iter] = temp.dims_actual_size_[iter]; + } // end for + + order_ = temp.order_; + length_ = temp.length_; + this_matrix_ = temp.this_matrix_; + } + + return *this; +} + +// Return size +template +KOKKOS_INLINE_FUNCTION +size_t DynamicCMatrixKokkos::size() const { + return length_; +} + +template +KOKKOS_INLINE_FUNCTION +size_t DynamicCMatrixKokkos::extent() const { + return length_; +} + +template +KOKKOS_INLINE_FUNCTION +size_t DynamicCMatrixKokkos::dims(size_t i) const { + assert(i < order_ && "DynamicCMatrixKokkos order (rank) does not match constructor, dim[i] does not exist!"); + assert(i >= 0 && dims_actual_size_[i]>0 && "Access to DynamicCMatrixKokkos dims is out of bounds!"); + return dims_actual_size_[i]; +} + +template +KOKKOS_INLINE_FUNCTION +size_t DynamicCMatrixKokkos::dims_max(size_t i) const { + assert(i < order_ && "DynamicCMatrixKokkos order (rank) does not match constructor, dim[i] does not exist!"); + assert(i >= 0 && dims_[i]>0 && "Access to DynamicCMatrixKokkos dims is out of bounds!"); + return dims_[i]; +} + +template +KOKKOS_INLINE_FUNCTION +size_t DynamicCMatrixKokkos::order() const { + return order_; +} + +/* +template +KOKKOS_INLINE_FUNCTION +void DynamicCMatrixKokkos::push_back(size_t dim_idx) const { + dims_actual_size_[dim_idx]++; +} +*/ + +template +KOKKOS_INLINE_FUNCTION +T* DynamicCMatrixKokkos::pointer() const { + return this_matrix_.data(); +} + +//return the stored Kokkos view +template +KOKKOS_INLINE_FUNCTION +Kokkos::View DynamicCMatrixKokkos::get_kokkos_view() const { + return this_matrix_; +} + +// Get the name of the view +template +KOKKOS_INLINE_FUNCTION +const std::string DynamicCMatrixKokkos::get_name() const{ + return this_matrix_.label(); +} + +// set values of array +template +void DynamicCMatrixKokkos::set_values(T val) { + Kokkos::parallel_for("SetValues_DynamicCMatrixKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { + this_matrix_(i) = val; + }); +} + +template +KOKKOS_INLINE_FUNCTION +DynamicCMatrixKokkos::~DynamicCMatrixKokkos() {} + +//////////////////////////////////////////////////////////////////////////////// +// End of DynamicCMatrixKokkos +//////////////////////////////////////////////////////////////////////////////// + +/*! \brief Dynamic version of the CArrayKokkos type. + * + */ +template +class DynamicFMatrixKokkos { + + using TArray1D = Kokkos::View; + +private: + size_t dims_[7]; + size_t dims_actual_size_[7]; + size_t order_; + size_t length_; + TArray1D this_matrix_; + +public: + DynamicFMatrixKokkos(); + + DynamicFMatrixKokkos(size_t dim0, const std::string& tag_string = DEFAULTSTRINGARRAY); + + DynamicFMatrixKokkos(size_t dim0, size_t dim1, const std::string& tag_string = DEFAULTSTRINGARRAY); + + DynamicFMatrixKokkos (size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); + + DynamicFMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, + size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); + + DynamicFMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, + size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); + + DynamicFMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, + size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGARRAY); + + DynamicFMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, + size_t dim3, size_t dim4, size_t dim5, + size_t dim6, const std::string& tag_string = DEFAULTSTRINGARRAY); + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k, size_t l) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n) const; + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, + size_t n, size_t o) const; + + KOKKOS_INLINE_FUNCTION + DynamicFMatrixKokkos& operator=(const DynamicFMatrixKokkos& temp); + + // GPU Method + // Method that returns size + KOKKOS_INLINE_FUNCTION + size_t size() const; + + // Host Method + // Method that returns size + KOKKOS_INLINE_FUNCTION + size_t extent() const; + + KOKKOS_INLINE_FUNCTION + size_t dims(size_t i) const; + + KOKKOS_INLINE_FUNCTION + size_t dims_max(size_t i) const; + + KOKKOS_INLINE_FUNCTION + size_t order() const; + + //KOKKOS_INLINE_FUNCTION + //void push_back() const; + + // Methods returns the raw pointer (most likely GPU) of the Kokkos View + KOKKOS_INLINE_FUNCTION + T* pointer() const; + + // set values + void set_values(T val); + + //return the view + KOKKOS_INLINE_FUNCTION + TArray1D get_kokkos_view() const; + + // Get the name of the view + KOKKOS_INLINE_FUNCTION + const std::string get_name() const; + + // Deconstructor + KOKKOS_INLINE_FUNCTION + ~DynamicFMatrixKokkos (); +}; // End of DynamicFMatrixKokkos + +// Default constructor +template +DynamicFMatrixKokkos::DynamicFMatrixKokkos() { + length_ = order_ = 0; + for (int i = 0; i < 7; i++) { + dims_[i] = 0; + dims_actual_size_[i] = 0; + } +} + +// Overloaded 1D constructor +template +DynamicFMatrixKokkos::DynamicFMatrixKokkos(size_t dim0, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + for (int i = 0; i < 1; i++) { + dims_actual_size_[i] = 0; + } + order_ = 1; + length_ = dim0; + this_matrix_ = TArray1D(tag_string, length_); +} + +// Overloaded 2D constructor +template +DynamicFMatrixKokkos::DynamicFMatrixKokkos(size_t dim0, size_t dim1, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + for (int i = 0; i < 2; i++) { + dims_actual_size_[i] = 0; + } + order_ = 2; + length_ = (dim0 * dim1); + this_matrix_ = TArray1D(tag_string, length_); +} + +template +DynamicFMatrixKokkos::DynamicFMatrixKokkos(size_t dim0, size_t dim1, + size_t dim2, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + for (int i = 0; i < 3; i++) { + dims_actual_size_[i] = 0; + } + order_ = 3; + length_ = (dim0 * dim1 * dim2); + this_matrix_ = TArray1D(tag_string, length_); +} + +template +DynamicFMatrixKokkos::DynamicFMatrixKokkos(size_t dim0, size_t dim1, + size_t dim2, size_t dim3, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + for (int i = 0; i < 4; i++) { + dims_actual_size_[i] = 0; + } + order_ = 4; + length_ = (dim0 * dim1 * dim2 * dim3); + this_matrix_ = TArray1D(tag_string, length_); +} + +template +DynamicFMatrixKokkos::DynamicFMatrixKokkos(size_t dim0, size_t dim1, + size_t dim2, size_t dim3, + size_t dim4, const std::string& tag_string) { + + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + for (int i = 0; i < 5; i++) { + dims_actual_size_[i] = 0; + } + order_ = 5; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4); + this_matrix_ = TArray1D(tag_string, length_); +} + +template +DynamicFMatrixKokkos::DynamicFMatrixKokkos(size_t dim0, size_t dim1, + size_t dim2, size_t dim3, + size_t dim4, size_t dim5, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + dims_[5] = dim5; + for (int i = 0; i < 6; i++) { + dims_actual_size_[i] = 0; + } + order_ = 6; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5); + this_matrix_ = TArray1D(tag_string, length_); +} + +template +DynamicFMatrixKokkos::DynamicFMatrixKokkos(size_t dim0, size_t dim1, + size_t dim2, size_t dim3, + size_t dim4, size_t dim5, + size_t dim6, const std::string& tag_string) { + using TArray1D = Kokkos::View; + + dims_[0] = dim0; + dims_[1] = dim1; + dims_[2] = dim2; + dims_[3] = dim3; + dims_[4] = dim4; + dims_[5] = dim5; + dims_[6] = dim6; + for (int i = 0; i < 7; i++) { + dims_actual_size_[i] = 0; + } + order_ = 7; + length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); + this_matrix_ = TArray1D(tag_string, length_); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicFMatrixKokkos::operator()(size_t i) const { + assert(order_ == 1 && "Tensor order (rank) does not match constructor in DynamicFMatrixKokkos 1D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFMatrixKokkos 1D!"); + return this_matrix_((i - 1)); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicFMatrixKokkos::operator()(size_t i, size_t j) const { + assert(order_ == 2 && "Tensor order (rank) does not match constructor in DynamicFMatrixKokkos 2D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFMatrixKokkos 2D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicFMatrixKokkos 2D!"); + return this_matrix_((j - 1) + ((i - 1) * dims_[1])); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicFMatrixKokkos::operator()(size_t i, size_t j, size_t k) const { + assert(order_ == 3 && "Tensor order (rank) does not match constructor in DynamicFMatrixKokkos 3D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFMatrixKokkos 3D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicFMatrixKokkos 3D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicFMatrixKokkos 3D!"); + return this_matrix_((k - 1) + ((j - 1) * dims_[2]) + + ((i - 1) * dims_[2] * dims_[1])); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { + assert(order_ == 4 && "Tensor order (rank) does not match constructor in DynamicFMatrixKokkos 4D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFMatrixKokkos 4D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicFMatrixKokkos 4D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicFMatrixKokkos 4D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicFMatrixKokkos 4D!"); + return this_matrix_((l - 1) + ((k - 1) * dims_[3]) + + ((j - 1) * dims_[3] * dims_[2]) + + ((i - 1) * dims_[3] * dims_[2] * dims_[1])); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, + size_t m) const { + assert(order_ == 5 && "Tensor order (rank) does not match constructor in DynamicFMatrixKokkos 5D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFMatrixKokkos 5D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicFMatrixKokkos 5D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicFMatrixKokkos 5D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicFMatrixKokkos 5D!"); + assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicFMatrixKokkos 5D!"); + return this_matrix_((m - 1) + ((l - 1) * dims_[4]) + + ((k - 1) * dims_[4] * dims_[3]) + + ((j - 1) * dims_[4] * dims_[3] * dims_[2]) + + ((i - 1) * dims_[4] * dims_[3] * dims_[2] * dims_[1])); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, + size_t m, size_t n) const { + assert(order_ == 6 && "Tensor order (rank) does not match constructor in DynamicFMatrixKokkos 6D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFMatrixKokkos 6D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicFMatrixKokkos 6D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicFMatrixKokkos 6D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicFMatrixKokkos 6D!"); + assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicFMatrixKokkos 6D!"); + assert(n >= 0 && n < dims_[5] && "n is out of bounds in DynamicFMatrixKokkos 6D!"); + return this_matrix_((n - 1) + ((m - 1) * dims_[5]) + + ((l - 1) * dims_[5] * dims_[4]) + + ((k - 1) * dims_[5] * dims_[4] * dims_[3]) + + ((j - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + + ((i - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); +} + +template +KOKKOS_INLINE_FUNCTION +T& DynamicFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, + size_t m, size_t n, size_t o) const { + assert(order_ == 7 && "Tensor order (rank) does not match constructor in DynamicFMatrixKokkos 7D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFMatrixKokkos 7D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicFMatrixKokkos 7D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicFMatrixKokkos 7D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicFMatrixKokkos 7D!"); + assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicFMatrixKokkos 7D!"); + assert(n >= 0 && n < dims_[5] && "n is out of bounds in DynamicFMatrixKokkos 7D!"); + assert(o >= 0 && o < dims_[6] && "o is out of bounds in DynamicFMatrixKokkos 7D!"); + return this_matrix_((o - 1) + ((n - 1) * dims_[6]) + + ((m - 1) * dims_[6] * dims_[5]) + + ((l - 1) * dims_[6] * dims_[5] * dims_[4]) + + ((k - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3]) + + ((j - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + + ((i - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); +} + +template +KOKKOS_INLINE_FUNCTION +DynamicFMatrixKokkos& DynamicFMatrixKokkos::operator= (const DynamicFMatrixKokkos& temp) { + using TArray1D = Kokkos::View; + + // Do nothing if the assignment is of the form x = x + if (this != &temp) { + for (int iter = 0; iter < temp.order_; iter++){ + dims_[iter] = temp.dims_[iter]; + dims_actual_size_[iter] = temp.dims_actual_size_[iter]; + } // end for + + order_ = temp.order_; + length_ = temp.length_; + this_matrix_ = temp.this_matrix_; + } + + return *this; +} + +// Return size +template +KOKKOS_INLINE_FUNCTION +size_t DynamicFMatrixKokkos::size() const { + return length_; +} + +template +KOKKOS_INLINE_FUNCTION +size_t DynamicFMatrixKokkos::extent() const { + return length_; +} + +template +KOKKOS_INLINE_FUNCTION +size_t DynamicFMatrixKokkos::dims(size_t i) const { + assert(i < order_ && "DynamicFMatrixKokkos order (rank) does not match constructor, dim[i] does not exist!"); + assert(i >= 0 && dims_actual_size_[i]>0 && "Access to DynamicFMatrixKokkos dims is out of bounds!"); + return dims_actual_size_[i]; +} + +template +KOKKOS_INLINE_FUNCTION +size_t DynamicFMatrixKokkos::dims_max(size_t i) const { + assert(i < order_ && "DynamicFMatrixKokkos order (rank) does not match constructor, dim[i] does not exist!"); + assert(i >= 0 && dims_[i]>0 && "Access to DynamicFMatrixKokkos dims is out of bounds!"); + return dims_[i]; +} + +template +KOKKOS_INLINE_FUNCTION +size_t DynamicFMatrixKokkos::order() const { + return order_; +} + +/* +template +KOKKOS_INLINE_FUNCTION +void DynamicFMatrixKokkos::push_back(size_t dim_idx) const { + dims_actual_size_[dim_idx]++; +} +*/ + +template +KOKKOS_INLINE_FUNCTION +T* DynamicFMatrixKokkos::pointer() const { + return this_matrix_.data(); +} + +//return the stored Kokkos view +template +KOKKOS_INLINE_FUNCTION +Kokkos::View DynamicFMatrixKokkos::get_kokkos_view() const { + return this_matrix_; +} + +// Get the name of the view +template +KOKKOS_INLINE_FUNCTION +const std::string DynamicFMatrixKokkos::get_name() const{ + return this_matrix_.label(); +} + +// set values of array +template +void DynamicFMatrixKokkos::set_values(T val) { + Kokkos::parallel_for("SetValues_DynamicFMatrixKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { + this_matrix_(i) = val; + }); +} + +template +KOKKOS_INLINE_FUNCTION +DynamicFMatrixKokkos::~DynamicFMatrixKokkos() {} //////////////////////////////////////////////////////////////////////////////// -// End of DynamicArrayKokkos +// End of DynamicFMatrixKokkos //////////////////////////////////////////////////////////////////////////////// /*! \brief Kokkos version of the serial RaggedRightArray class. From ce443d4d09e39994711e3fd1c5e67bc713975491 Mon Sep 17 00:00:00 2001 From: Daniel Dunning <39738037+djdunning@users.noreply.github.com> Date: Fri, 4 Oct 2024 14:45:41 -0600 Subject: [PATCH 7/9] updated the types as we want them now. DynamicMatrix will need other indexes fixed in the future --- src/Kokkos/kokkos | 2 +- src/include/kokkos_types.h | 1251 ++++++------------------------------ 2 files changed, 207 insertions(+), 1046 deletions(-) diff --git a/src/Kokkos/kokkos b/src/Kokkos/kokkos index 22fea839..71a9bcae 160000 --- a/src/Kokkos/kokkos +++ b/src/Kokkos/kokkos @@ -1 +1 @@ -Subproject commit 22fea8395ac617d3b5a933e8cc2905a4c3b3b6f4 +Subproject commit 71a9bcae52543bd065522bf3e41b5bfa467d8015 diff --git a/src/include/kokkos_types.h b/src/include/kokkos_types.h index 1f0aee3a..3a923b36 100644 --- a/src/include/kokkos_types.h +++ b/src/include/kokkos_types.h @@ -6647,7 +6647,7 @@ DViewCMatrixKokkos::~DViewCMatrixKokkos() {} * */ template -class DynamicCArrayKokkos { +class DynamicArrayKokkos { using TArray1D = Kokkos::View; @@ -6659,30 +6659,31 @@ class DynamicCArrayKokkos { TArray1D this_array_; public: - DynamicCArrayKokkos(); + DynamicArrayKokkos(); - DynamicCArrayKokkos(size_t dim0, const std::string& tag_string = DEFAULTSTRINGARRAY); + DynamicArrayKokkos(size_t dim0, const std::string& tag_string = DEFAULTSTRINGARRAY); - DynamicCArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string = DEFAULTSTRINGARRAY); + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i) const; + +/* + DynamicArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string = DEFAULTSTRINGARRAY); - DynamicCArrayKokkos (size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); + DynamicArrayKokkos (size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); - DynamicCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, + DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); - DynamicCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, + DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); - DynamicCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, + DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGARRAY); - DynamicCArrayKokkos(size_t dim0, size_t dim1, size_t dim2, + DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, const std::string& tag_string = DEFAULTSTRINGARRAY); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i) const; - KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; @@ -6702,9 +6703,10 @@ class DynamicCArrayKokkos { KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; +*/ KOKKOS_INLINE_FUNCTION - DynamicCArrayKokkos& operator=(const DynamicCArrayKokkos& temp); + DynamicArrayKokkos& operator=(const DynamicArrayKokkos& temp); // GPU Method // Method that returns size @@ -6725,8 +6727,9 @@ class DynamicCArrayKokkos { KOKKOS_INLINE_FUNCTION size_t order() const; - //KOKKOS_INLINE_FUNCTION - //void push_back() const; + void push_back(T value); + + void pop(); // Methods returns the raw pointer (most likely GPU) of the Kokkos View KOKKOS_INLINE_FUNCTION @@ -6745,12 +6748,12 @@ class DynamicCArrayKokkos { // Deconstructor KOKKOS_INLINE_FUNCTION - ~DynamicCArrayKokkos (); -}; // End of DynamicCArrayKokkos + ~DynamicArrayKokkos (); +}; // End of DynamicArrayKokkos // Default constructor template -DynamicCArrayKokkos::DynamicCArrayKokkos() { +DynamicArrayKokkos::DynamicArrayKokkos() { length_ = order_ = 0; for (int i = 0; i < 7; i++) { dims_[i] = 0; @@ -6760,7 +6763,7 @@ DynamicCArrayKokkos::DynamicCArrayKokkos() { // Overloaded 1D constructor template -DynamicCArrayKokkos::DynamicCArrayKokkos(size_t dim0, const std::string& tag_string) { +DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, const std::string& tag_string) { using TArray1D = Kokkos::View; dims_[0] = dim0; @@ -6772,9 +6775,10 @@ DynamicCArrayKokkos::DynamicCArrayKokkos(size_t this_array_ = TArray1D(tag_string, length_); } +/* // Overloaded 2D constructor template -DynamicCArrayKokkos::DynamicCArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string) { +DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string) { using TArray1D = Kokkos::View; dims_[0] = dim0; @@ -6788,7 +6792,7 @@ DynamicCArrayKokkos::DynamicCArrayKokkos(size_t } template -DynamicCArrayKokkos::DynamicCArrayKokkos(size_t dim0, size_t dim1, +DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string) { using TArray1D = Kokkos::View; @@ -6804,7 +6808,7 @@ DynamicCArrayKokkos::DynamicCArrayKokkos(size_t } template -DynamicCArrayKokkos::DynamicCArrayKokkos(size_t dim0, size_t dim1, +DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string) { using TArray1D = Kokkos::View; @@ -6821,7 +6825,7 @@ DynamicCArrayKokkos::DynamicCArrayKokkos(size_t } template -DynamicCArrayKokkos::DynamicCArrayKokkos(size_t dim0, size_t dim1, +DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, const std::string& tag_string) { @@ -6841,7 +6845,7 @@ DynamicCArrayKokkos::DynamicCArrayKokkos(size_t } template -DynamicCArrayKokkos::DynamicCArrayKokkos(size_t dim0, size_t dim1, +DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string) { using TArray1D = Kokkos::View; @@ -6861,7 +6865,7 @@ DynamicCArrayKokkos::DynamicCArrayKokkos(size_t } template -DynamicCArrayKokkos::DynamicCArrayKokkos(size_t dim0, size_t dim1, +DynamicArrayKokkos::DynamicArrayKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, const std::string& tag_string) { @@ -6881,43 +6885,45 @@ DynamicCArrayKokkos::DynamicCArrayKokkos(size_t length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); this_array_ = TArray1D(tag_string, length_); } +*/ template KOKKOS_INLINE_FUNCTION -T& DynamicCArrayKokkos::operator()(size_t i) const { - assert(order_ == 1 && "Tensor order (rank) does not match constructor in DynamicCArrayKokkos 1D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCArrayKokkos 1D!"); +T& DynamicArrayKokkos::operator()(size_t i) const { + assert(order_ == 1 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 1D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 1D!"); return this_array_(i); } +/* template KOKKOS_INLINE_FUNCTION -T& DynamicCArrayKokkos::operator()(size_t i, size_t j) const { - assert(order_ == 2 && "Tensor order (rank) does not match constructor in DynamicCArrayKokkos 2D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCArrayKokkos 2D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicCArrayKokkos 2D!"); +T& DynamicArrayKokkos::operator()(size_t i, size_t j) const { + assert(order_ == 2 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 2D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 2D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 2D!"); return this_array_(j + (i * dims_[1])); } template KOKKOS_INLINE_FUNCTION -T& DynamicCArrayKokkos::operator()(size_t i, size_t j, size_t k) const { - assert(order_ == 3 && "Tensor order (rank) does not match constructor in DynamicCArrayKokkos 3D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCArrayKokkos 3D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicCArrayKokkos 3D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicCArrayKokkos 3D!"); +T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k) const { + assert(order_ == 3 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 3D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 3D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 3D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicArrayKokkos 3D!"); return this_array_(k + (j * dims_[2]) + (i * dims_[2] * dims_[1])); } template KOKKOS_INLINE_FUNCTION -T& DynamicCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { - assert(order_ == 4 && "Tensor order (rank) does not match constructor in DynamicCArrayKokkos 4D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCArrayKokkos 4D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicCArrayKokkos 4D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicCArrayKokkos 4D!"); - assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicCArrayKokkos 4D!"); +T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { + assert(order_ == 4 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 4D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 4D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 4D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicArrayKokkos 4D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicArrayKokkos 4D!"); return this_array_(l + (k * dims_[3]) + (j * dims_[3] * dims_[2]) + (i * dims_[3] * dims_[2] * dims_[1])); @@ -6925,14 +6931,14 @@ T& DynamicCArrayKokkos::operator()(size_t i, si template KOKKOS_INLINE_FUNCTION -T& DynamicCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, +T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { - assert(order_ == 5 && "Tensor order (rank) does not match constructor in DynamicCArrayKokkos 5D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCArrayKokkos 5D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicCArrayKokkos 5D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicCArrayKokkos 5D!"); - assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicCArrayKokkos 5D!"); - assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicCArrayKokkos 5D!"); + assert(order_ == 5 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 5D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 5D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 5D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicArrayKokkos 5D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicArrayKokkos 5D!"); + assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicArrayKokkos 5D!"); return this_array_(m + (l * dims_[4]) + (k * dims_[4] * dims_[3]) + (j * dims_[4] * dims_[3] * dims_[2]) @@ -6941,15 +6947,15 @@ T& DynamicCArrayKokkos::operator()(size_t i, si template KOKKOS_INLINE_FUNCTION -T& DynamicCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, +T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const { - assert(order_ == 6 && "Tensor order (rank) does not match constructor in DynamicCArrayKokkos 6D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCArrayKokkos 6D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicCArrayKokkos 6D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicCArrayKokkos 6D!"); - assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicCArrayKokkos 6D!"); - assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicCArrayKokkos 6D!"); - assert(n >= 0 && n < dims_[5] && "n is out of bounds in DynamicCArrayKokkos 6D!"); + assert(order_ == 6 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 6D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 6D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 6D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicArrayKokkos 6D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicArrayKokkos 6D!"); + assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicArrayKokkos 6D!"); + assert(n >= 0 && n < dims_[5] && "n is out of bounds in DynamicArrayKokkos 6D!"); return this_array_(n + (m * dims_[5]) + (l * dims_[5] * dims_[4]) + (k * dims_[5] * dims_[4] * dims_[3]) @@ -6959,16 +6965,16 @@ T& DynamicCArrayKokkos::operator()(size_t i, si template KOKKOS_INLINE_FUNCTION -T& DynamicCArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, +T& DynamicArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const { - assert(order_ == 7 && "Tensor order (rank) does not match constructor in DynamicCArrayKokkos 7D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCArrayKokkos 7D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicCArrayKokkos 7D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicCArrayKokkos 7D!"); - assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicCArrayKokkos 7D!"); - assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicCArrayKokkos 7D!"); - assert(n >= 0 && n < dims_[5] && "n is out of bounds in DynamicCArrayKokkos 7D!"); - assert(o >= 0 && o < dims_[6] && "o is out of bounds in DynamicCArrayKokkos 7D!"); + assert(order_ == 7 && "Tensor order (rank) does not match constructor in DynamicArrayKokkos 7D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicArrayKokkos 7D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicArrayKokkos 7D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicArrayKokkos 7D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicArrayKokkos 7D!"); + assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicArrayKokkos 7D!"); + assert(n >= 0 && n < dims_[5] && "n is out of bounds in DynamicArrayKokkos 7D!"); + assert(o >= 0 && o < dims_[6] && "o is out of bounds in DynamicArrayKokkos 7D!"); return this_array_(o + (n * dims_[6]) + (m * dims_[6] * dims_[5]) + (l * dims_[6] * dims_[5] * dims_[4]) @@ -6976,10 +6982,11 @@ T& DynamicCArrayKokkos::operator()(size_t i, si + (j * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + (i * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); } +*/ template KOKKOS_INLINE_FUNCTION -DynamicCArrayKokkos& DynamicCArrayKokkos::operator= (const DynamicCArrayKokkos& temp) { +DynamicArrayKokkos& DynamicArrayKokkos::operator= (const DynamicArrayKokkos& temp) { using TArray1D = Kokkos::View; // Do nothing if the assignment is of the form x = x @@ -7000,87 +7007,93 @@ DynamicCArrayKokkos& DynamicCArrayKokkos KOKKOS_INLINE_FUNCTION -size_t DynamicCArrayKokkos::size() const { +size_t DynamicArrayKokkos::size() const { return length_; } template KOKKOS_INLINE_FUNCTION -size_t DynamicCArrayKokkos::extent() const { +size_t DynamicArrayKokkos::extent() const { return length_; } template KOKKOS_INLINE_FUNCTION -size_t DynamicCArrayKokkos::dims(size_t i) const { - assert(i < order_ && "DynamicCArrayKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(i >= 0 && dims_actual_size_[i]>0 && "Access to DynamicCArrayKokkos dims is out of bounds!"); +size_t DynamicArrayKokkos::dims(size_t i) const { + assert(i < order_ && "DynamicArrayKokkos order (rank) does not match constructor, dim[i] does not exist!"); + assert(i >= 0 && dims_actual_size_[i]>0 && "Access to DynamicArrayKokkos dims is out of bounds!"); return dims_actual_size_[i]; } template KOKKOS_INLINE_FUNCTION -size_t DynamicCArrayKokkos::dims_max(size_t i) const { - assert(i < order_ && "DynamicCArrayKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(i >= 0 && dims_[i]>0 && "Access to DynamicCArrayKokkos dims is out of bounds!"); +size_t DynamicArrayKokkos::dims_max(size_t i) const { + assert(i < order_ && "DynamicArrayKokkos order (rank) does not match constructor, dim[i] does not exist!"); + assert(i >= 0 && dims_[i]>0 && "Access to DynamicArrayKokkos dims is out of bounds!"); return dims_[i]; } template KOKKOS_INLINE_FUNCTION -size_t DynamicCArrayKokkos::order() const { +size_t DynamicArrayKokkos::order() const { return order_; } -/* template -KOKKOS_INLINE_FUNCTION -void DynamicCArrayKokkos::push_back(size_t dim_idx) const { - dims_actual_size_[dim_idx]++; +void DynamicArrayKokkos::pop() { + dims_actual_size_[0]--; +} + +template +void DynamicArrayKokkos::push_back(T value) { + size_t idx = dims_actual_size_[0]; + Kokkos::parallel_for("pushback_DynamicArrayKokkos", 1, KOKKOS_CLASS_LAMBDA(const int i) { + this_array_(idx) = value; + }); + dims_actual_size_[0]++; } -*/ template KOKKOS_INLINE_FUNCTION -T* DynamicCArrayKokkos::pointer() const { +T* DynamicArrayKokkos::pointer() const { return this_array_.data(); } //return the stored Kokkos view template KOKKOS_INLINE_FUNCTION -Kokkos::View DynamicCArrayKokkos::get_kokkos_view() const { +Kokkos::View DynamicArrayKokkos::get_kokkos_view() const { return this_array_; } // Get the name of the view template KOKKOS_INLINE_FUNCTION -const std::string DynamicCArrayKokkos::get_name() const{ +const std::string DynamicArrayKokkos::get_name() const{ return this_array_.label(); } // set values of array template -void DynamicCArrayKokkos::set_values(T val) { - Kokkos::parallel_for("SetValues_DynamicCArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { +void DynamicArrayKokkos::set_values(T val) { + Kokkos::parallel_for("SetValues_DynamicArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { this_array_(i) = val; }); } template KOKKOS_INLINE_FUNCTION -DynamicCArrayKokkos::~DynamicCArrayKokkos() {} +DynamicArrayKokkos::~DynamicArrayKokkos() {} //////////////////////////////////////////////////////////////////////////////// -// End of DynamicCArrayKokkos +// End of DynamicArrayKokkos //////////////////////////////////////////////////////////////////////////////// -/*! \brief Dynamic version of the CArrayKokkos type. +/*! \brief Dynamic version of the CMatrixKokkos type. * */ template -class DynamicFArrayKokkos { +class DynamicMatrixKokkos { using TArray1D = Kokkos::View; @@ -7092,30 +7105,31 @@ class DynamicFArrayKokkos { TArray1D this_array_; public: - DynamicFArrayKokkos(); + DynamicMatrixKokkos(); - DynamicFArrayKokkos(size_t dim0, const std::string& tag_string = DEFAULTSTRINGARRAY); + DynamicMatrixKokkos(size_t dim0, const std::string& tag_string = DEFAULTSTRINGARRAY); + + KOKKOS_INLINE_FUNCTION + T& operator()(size_t i) const; - DynamicFArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string = DEFAULTSTRINGARRAY); +/* + DynamicMatrixKokkos(size_t dim0, size_t dim1, const std::string& tag_string = DEFAULTSTRINGARRAY); - DynamicFArrayKokkos (size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); + DynamicMatrixKokkos (size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); - DynamicFArrayKokkos(size_t dim0, size_t dim1, size_t dim2, + DynamicMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); - DynamicFArrayKokkos(size_t dim0, size_t dim1, size_t dim2, + DynamicMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); - DynamicFArrayKokkos(size_t dim0, size_t dim1, size_t dim2, + DynamicMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGARRAY); - DynamicFArrayKokkos(size_t dim0, size_t dim1, size_t dim2, + DynamicMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, const std::string& tag_string = DEFAULTSTRINGARRAY); - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i) const; - KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j) const; @@ -7135,9 +7149,10 @@ class DynamicFArrayKokkos { KOKKOS_INLINE_FUNCTION T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const; +*/ KOKKOS_INLINE_FUNCTION - DynamicFArrayKokkos& operator=(const DynamicFArrayKokkos& temp); + DynamicMatrixKokkos& operator=(const DynamicMatrixKokkos& temp); // GPU Method // Method that returns size @@ -7158,8 +7173,9 @@ class DynamicFArrayKokkos { KOKKOS_INLINE_FUNCTION size_t order() const; - //KOKKOS_INLINE_FUNCTION - //void push_back() const; + void push_back(T value); + + void pop(); // Methods returns the raw pointer (most likely GPU) of the Kokkos View KOKKOS_INLINE_FUNCTION @@ -7178,12 +7194,12 @@ class DynamicFArrayKokkos { // Deconstructor KOKKOS_INLINE_FUNCTION - ~DynamicFArrayKokkos (); -}; // End of DynamicFArrayKokkos + ~DynamicMatrixKokkos (); +}; // End of DynamicMatrixKokkos // Default constructor template -DynamicFArrayKokkos::DynamicFArrayKokkos() { +DynamicMatrixKokkos::DynamicMatrixKokkos() { length_ = order_ = 0; for (int i = 0; i < 7; i++) { dims_[i] = 0; @@ -7193,7 +7209,7 @@ DynamicFArrayKokkos::DynamicFArrayKokkos() { // Overloaded 1D constructor template -DynamicFArrayKokkos::DynamicFArrayKokkos(size_t dim0, const std::string& tag_string) { +DynamicMatrixKokkos::DynamicMatrixKokkos(size_t dim0, const std::string& tag_string) { using TArray1D = Kokkos::View; dims_[0] = dim0; @@ -7205,9 +7221,10 @@ DynamicFArrayKokkos::DynamicFArrayKokkos(size_t this_array_ = TArray1D(tag_string, length_); } +/* // Overloaded 2D constructor template -DynamicFArrayKokkos::DynamicFArrayKokkos(size_t dim0, size_t dim1, const std::string& tag_string) { +DynamicMatrixKokkos::DynamicMatrixKokkos(size_t dim0, size_t dim1, const std::string& tag_string) { using TArray1D = Kokkos::View; dims_[0] = dim0; @@ -7221,7 +7238,7 @@ DynamicFArrayKokkos::DynamicFArrayKokkos(size_t } template -DynamicFArrayKokkos::DynamicFArrayKokkos(size_t dim0, size_t dim1, +DynamicMatrixKokkos::DynamicMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string) { using TArray1D = Kokkos::View; @@ -7237,7 +7254,7 @@ DynamicFArrayKokkos::DynamicFArrayKokkos(size_t } template -DynamicFArrayKokkos::DynamicFArrayKokkos(size_t dim0, size_t dim1, +DynamicMatrixKokkos::DynamicMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, const std::string& tag_string) { using TArray1D = Kokkos::View; @@ -7254,7 +7271,7 @@ DynamicFArrayKokkos::DynamicFArrayKokkos(size_t } template -DynamicFArrayKokkos::DynamicFArrayKokkos(size_t dim0, size_t dim1, +DynamicMatrixKokkos::DynamicMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, const std::string& tag_string) { @@ -7274,7 +7291,7 @@ DynamicFArrayKokkos::DynamicFArrayKokkos(size_t } template -DynamicFArrayKokkos::DynamicFArrayKokkos(size_t dim0, size_t dim1, +DynamicMatrixKokkos::DynamicMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string) { using TArray1D = Kokkos::View; @@ -7294,7 +7311,7 @@ DynamicFArrayKokkos::DynamicFArrayKokkos(size_t } template -DynamicFArrayKokkos::DynamicFArrayKokkos(size_t dim0, size_t dim1, +DynamicMatrixKokkos::DynamicMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, const std::string& tag_string) { @@ -7314,43 +7331,45 @@ DynamicFArrayKokkos::DynamicFArrayKokkos(size_t length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); this_array_ = TArray1D(tag_string, length_); } +*/ template KOKKOS_INLINE_FUNCTION -T& DynamicFArrayKokkos::operator()(size_t i) const { - assert(order_ == 1 && "Tensor order (rank) does not match constructor in DynamicFArrayKokkos 1D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFArrayKokkos 1D!"); - return this_array_(i); +T& DynamicMatrixKokkos::operator()(size_t i) const { + assert(order_ == 1 && "Tensor order (rank) does not match constructor in DynamicMatrixKokkos 1D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicMatrixKokkos 1D!"); + return this_array_((i-1)); } +/* template KOKKOS_INLINE_FUNCTION -T& DynamicFArrayKokkos::operator()(size_t i, size_t j) const { - assert(order_ == 2 && "Tensor order (rank) does not match constructor in DynamicFArrayKokkos 2D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFArrayKokkos 2D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicFArrayKokkos 2D!"); +T& DynamicMatrixKokkos::operator()(size_t i, size_t j) const { + assert(order_ == 2 && "Tensor order (rank) does not match constructor in DynamicMatrixKokkos 2D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicMatrixKokkos 2D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicMatrixKokkos 2D!"); return this_array_(j + (i * dims_[1])); } template KOKKOS_INLINE_FUNCTION -T& DynamicFArrayKokkos::operator()(size_t i, size_t j, size_t k) const { - assert(order_ == 3 && "Tensor order (rank) does not match constructor in DynamicFArrayKokkos 3D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFArrayKokkos 3D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicFArrayKokkos 3D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicFArrayKokkos 3D!"); +T& DynamicMatrixKokkos::operator()(size_t i, size_t j, size_t k) const { + assert(order_ == 3 && "Tensor order (rank) does not match constructor in DynamicMatrixKokkos 3D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicMatrixKokkos 3D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicMatrixKokkos 3D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicMatrixKokkos 3D!"); return this_array_(k + (j * dims_[2]) + (i * dims_[2] * dims_[1])); } template KOKKOS_INLINE_FUNCTION -T& DynamicFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { - assert(order_ == 4 && "Tensor order (rank) does not match constructor in DynamicFArrayKokkos 4D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFArrayKokkos 4D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicFArrayKokkos 4D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicFArrayKokkos 4D!"); - assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicFArrayKokkos 4D!"); +T& DynamicMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { + assert(order_ == 4 && "Tensor order (rank) does not match constructor in DynamicMatrixKokkos 4D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicMatrixKokkos 4D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicMatrixKokkos 4D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicMatrixKokkos 4D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicMatrixKokkos 4D!"); return this_array_(l + (k * dims_[3]) + (j * dims_[3] * dims_[2]) + (i * dims_[3] * dims_[2] * dims_[1])); @@ -7358,14 +7377,14 @@ T& DynamicFArrayKokkos::operator()(size_t i, si template KOKKOS_INLINE_FUNCTION -T& DynamicFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, +T& DynamicMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const { - assert(order_ == 5 && "Tensor order (rank) does not match constructor in DynamicFArrayKokkos 5D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFArrayKokkos 5D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicFArrayKokkos 5D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicFArrayKokkos 5D!"); - assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicFArrayKokkos 5D!"); - assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicFArrayKokkos 5D!"); + assert(order_ == 5 && "Tensor order (rank) does not match constructor in DynamicMatrixKokkos 5D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicMatrixKokkos 5D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicMatrixKokkos 5D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicMatrixKokkos 5D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicMatrixKokkos 5D!"); + assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicMatrixKokkos 5D!"); return this_array_(m + (l * dims_[4]) + (k * dims_[4] * dims_[3]) + (j * dims_[4] * dims_[3] * dims_[2]) @@ -7374,15 +7393,15 @@ T& DynamicFArrayKokkos::operator()(size_t i, si template KOKKOS_INLINE_FUNCTION -T& DynamicFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, +T& DynamicMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const { - assert(order_ == 6 && "Tensor order (rank) does not match constructor in DynamicFArrayKokkos 6D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFArrayKokkos 6D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicFArrayKokkos 6D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicFArrayKokkos 6D!"); - assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicFArrayKokkos 6D!"); - assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicFArrayKokkos 6D!"); - assert(n >= 0 && n < dims_[5] && "n is out of bounds in DynamicFArrayKokkos 6D!"); + assert(order_ == 6 && "Tensor order (rank) does not match constructor in DynamicMatrixKokkos 6D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicMatrixKokkos 6D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicMatrixKokkos 6D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicMatrixKokkos 6D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicMatrixKokkos 6D!"); + assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicMatrixKokkos 6D!"); + assert(n >= 0 && n < dims_[5] && "n is out of bounds in DynamicMatrixKokkos 6D!"); return this_array_(n + (m * dims_[5]) + (l * dims_[5] * dims_[4]) + (k * dims_[5] * dims_[4] * dims_[3]) @@ -7392,16 +7411,16 @@ T& DynamicFArrayKokkos::operator()(size_t i, si template KOKKOS_INLINE_FUNCTION -T& DynamicFArrayKokkos::operator()(size_t i, size_t j, size_t k, size_t l, +T& DynamicMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t o) const { - assert(order_ == 7 && "Tensor order (rank) does not match constructor in DynamicFArrayKokkos 7D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFArrayKokkos 7D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicFArrayKokkos 7D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicFArrayKokkos 7D!"); - assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicFArrayKokkos 7D!"); - assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicFArrayKokkos 7D!"); - assert(n >= 0 && n < dims_[5] && "n is out of bounds in DynamicFArrayKokkos 7D!"); - assert(o >= 0 && o < dims_[6] && "o is out of bounds in DynamicFArrayKokkos 7D!"); + assert(order_ == 7 && "Tensor order (rank) does not match constructor in DynamicMatrixKokkos 7D!"); + assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicMatrixKokkos 7D!"); + assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicMatrixKokkos 7D!"); + assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicMatrixKokkos 7D!"); + assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicMatrixKokkos 7D!"); + assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicMatrixKokkos 7D!"); + assert(n >= 0 && n < dims_[5] && "n is out of bounds in DynamicMatrixKokkos 7D!"); + assert(o >= 0 && o < dims_[6] && "o is out of bounds in DynamicMatrixKokkos 7D!"); return this_array_(o + (n * dims_[6]) + (m * dims_[6] * dims_[5]) + (l * dims_[6] * dims_[5] * dims_[4]) @@ -7409,10 +7428,11 @@ T& DynamicFArrayKokkos::operator()(size_t i, si + (j * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) + (i * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); } +*/ template KOKKOS_INLINE_FUNCTION -DynamicFArrayKokkos& DynamicFArrayKokkos::operator= (const DynamicFArrayKokkos& temp) { +DynamicMatrixKokkos& DynamicMatrixKokkos::operator= (const DynamicMatrixKokkos& temp) { using TArray1D = Kokkos::View; // Do nothing if the assignment is of the form x = x @@ -7433,947 +7453,88 @@ DynamicFArrayKokkos& DynamicFArrayKokkos KOKKOS_INLINE_FUNCTION -size_t DynamicFArrayKokkos::size() const { +size_t DynamicMatrixKokkos::size() const { return length_; } template KOKKOS_INLINE_FUNCTION -size_t DynamicFArrayKokkos::extent() const { +size_t DynamicMatrixKokkos::extent() const { return length_; } template KOKKOS_INLINE_FUNCTION -size_t DynamicFArrayKokkos::dims(size_t i) const { - assert(i < order_ && "DynamicFArrayKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(i >= 0 && dims_actual_size_[i]>0 && "Access to DynamicFArrayKokkos dims is out of bounds!"); +size_t DynamicMatrixKokkos::dims(size_t i) const { + assert(i < order_ && "DynamicMatrixKokkos order (rank) does not match constructor, dim[i] does not exist!"); + assert(i >= 0 && dims_actual_size_[i]>0 && "Access to DynamicMatrixKokkos dims is out of bounds!"); return dims_actual_size_[i]; } template KOKKOS_INLINE_FUNCTION -size_t DynamicFArrayKokkos::dims_max(size_t i) const { - assert(i < order_ && "DynamicFArrayKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(i >= 0 && dims_[i]>0 && "Access to DynamicFArrayKokkos dims is out of bounds!"); +size_t DynamicMatrixKokkos::dims_max(size_t i) const { + assert(i < order_ && "DynamicMatrixKokkos order (rank) does not match constructor, dim[i] does not exist!"); + assert(i >= 0 && dims_[i]>0 && "Access to DynamicMatrixKokkos dims is out of bounds!"); return dims_[i]; } template KOKKOS_INLINE_FUNCTION -size_t DynamicFArrayKokkos::order() const { +size_t DynamicMatrixKokkos::order() const { return order_; } -/* template -KOKKOS_INLINE_FUNCTION -void DynamicFArrayKokkos::push_back(size_t dim_idx) const { - dims_actual_size_[dim_idx]++; +void DynamicMatrixKokkos::pop() { + dims_actual_size_[0]--; +} + +template +void DynamicMatrixKokkos::push_back(T value) { + size_t idx = dims_actual_size_[0]; + Kokkos::parallel_for("pushback_DynamicMatrixKokkos", 1, KOKKOS_CLASS_LAMBDA(const int i) { + this_array_(idx) = value; + }); + dims_actual_size_[0]++; } -*/ template KOKKOS_INLINE_FUNCTION -T* DynamicFArrayKokkos::pointer() const { +T* DynamicMatrixKokkos::pointer() const { return this_array_.data(); } //return the stored Kokkos view template KOKKOS_INLINE_FUNCTION -Kokkos::View DynamicFArrayKokkos::get_kokkos_view() const { +Kokkos::View DynamicMatrixKokkos::get_kokkos_view() const { return this_array_; } // Get the name of the view template KOKKOS_INLINE_FUNCTION -const std::string DynamicFArrayKokkos::get_name() const{ +const std::string DynamicMatrixKokkos::get_name() const{ return this_array_.label(); } // set values of array template -void DynamicFArrayKokkos::set_values(T val) { - Kokkos::parallel_for("SetValues_DynamicFArrayKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { +void DynamicMatrixKokkos::set_values(T val) { + Kokkos::parallel_for("SetValues_DynamicMatrixKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { this_array_(i) = val; }); } template KOKKOS_INLINE_FUNCTION -DynamicFArrayKokkos::~DynamicFArrayKokkos() {} +DynamicMatrixKokkos::~DynamicMatrixKokkos() {} //////////////////////////////////////////////////////////////////////////////// -// End of DynamicFArrayKokkos +// End of DynamicMatrixKokkos //////////////////////////////////////////////////////////////////////////////// -/*! \brief Dynamic version of the CArrayKokkos type. - * - */ -template -class DynamicCMatrixKokkos { - - using TArray1D = Kokkos::View; - -private: - size_t dims_[7]; - size_t dims_actual_size_[7]; - size_t order_; - size_t length_; - TArray1D this_matrix_; - -public: - DynamicCMatrixKokkos(); - - DynamicCMatrixKokkos(size_t dim0, const std::string& tag_string = DEFAULTSTRINGARRAY); - - DynamicCMatrixKokkos(size_t dim0, size_t dim1, const std::string& tag_string = DEFAULTSTRINGARRAY); - - DynamicCMatrixKokkos (size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); - - DynamicCMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); - - DynamicCMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); - - DynamicCMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGARRAY); - - DynamicCMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, - size_t dim6, const std::string& tag_string = DEFAULTSTRINGARRAY); - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i) const; - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k) const; - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l) const; - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n) const; - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n, size_t o) const; - - KOKKOS_INLINE_FUNCTION - DynamicCMatrixKokkos& operator=(const DynamicCMatrixKokkos& temp); - - // GPU Method - // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t size() const; - - // Host Method - // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t extent() const; - - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; - - KOKKOS_INLINE_FUNCTION - size_t dims_max(size_t i) const; - - KOKKOS_INLINE_FUNCTION - size_t order() const; - - //KOKKOS_INLINE_FUNCTION - //void push_back() const; - - // Methods returns the raw pointer (most likely GPU) of the Kokkos View - KOKKOS_INLINE_FUNCTION - T* pointer() const; - - // set values - void set_values(T val); - - //return the view - KOKKOS_INLINE_FUNCTION - TArray1D get_kokkos_view() const; - - // Get the name of the view - KOKKOS_INLINE_FUNCTION - const std::string get_name() const; - - // Deconstructor - KOKKOS_INLINE_FUNCTION - ~DynamicCMatrixKokkos (); -}; // End of DynamicCMatrixKokkos - -// Default constructor -template -DynamicCMatrixKokkos::DynamicCMatrixKokkos() { - length_ = order_ = 0; - for (int i = 0; i < 7; i++) { - dims_[i] = 0; - dims_actual_size_[i] = 0; - } -} - -// Overloaded 1D constructor -template -DynamicCMatrixKokkos::DynamicCMatrixKokkos(size_t dim0, const std::string& tag_string) { - using TArray1D = Kokkos::View; - - dims_[0] = dim0; - for (int i = 0; i < 1; i++) { - dims_actual_size_[i] = 0; - } - order_ = 1; - length_ = dim0; - this_matrix_ = TArray1D(tag_string, length_); -} - -// Overloaded 2D constructor -template -DynamicCMatrixKokkos::DynamicCMatrixKokkos(size_t dim0, size_t dim1, const std::string& tag_string) { - using TArray1D = Kokkos::View; - - dims_[0] = dim0; - dims_[1] = dim1; - for (int i = 0; i < 2; i++) { - dims_actual_size_[i] = 0; - } - order_ = 2; - length_ = (dim0 * dim1); - this_matrix_ = TArray1D(tag_string, length_); -} - -template -DynamicCMatrixKokkos::DynamicCMatrixKokkos(size_t dim0, size_t dim1, - size_t dim2, const std::string& tag_string) { - using TArray1D = Kokkos::View; - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - for (int i = 0; i < 3; i++) { - dims_actual_size_[i] = 0; - } - order_ = 3; - length_ = (dim0 * dim1 * dim2); - this_matrix_ = TArray1D(tag_string, length_); -} - -template -DynamicCMatrixKokkos::DynamicCMatrixKokkos(size_t dim0, size_t dim1, - size_t dim2, size_t dim3, const std::string& tag_string) { - using TArray1D = Kokkos::View; - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - for (int i = 0; i < 4; i++) { - dims_actual_size_[i] = 0; - } - order_ = 4; - length_ = (dim0 * dim1 * dim2 * dim3); - this_matrix_ = TArray1D(tag_string, length_); -} - -template -DynamicCMatrixKokkos::DynamicCMatrixKokkos(size_t dim0, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, const std::string& tag_string) { - - using TArray1D = Kokkos::View; - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - for (int i = 0; i < 5; i++) { - dims_actual_size_[i] = 0; - } - order_ = 5; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4); - this_matrix_ = TArray1D(tag_string, length_); -} - -template -DynamicCMatrixKokkos::DynamicCMatrixKokkos(size_t dim0, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, size_t dim5, const std::string& tag_string) { - using TArray1D = Kokkos::View; - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - dims_[5] = dim5; - for (int i = 0; i < 6; i++) { - dims_actual_size_[i] = 0; - } - order_ = 6; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5); - this_matrix_ = TArray1D(tag_string, length_); -} - -template -DynamicCMatrixKokkos::DynamicCMatrixKokkos(size_t dim0, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, size_t dim5, - size_t dim6, const std::string& tag_string) { - using TArray1D = Kokkos::View; - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - dims_[5] = dim5; - dims_[6] = dim6; - for (int i = 0; i < 7; i++) { - dims_actual_size_[i] = 0; - } - order_ = 7; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); - this_matrix_ = TArray1D(tag_string, length_); -} - -template -KOKKOS_INLINE_FUNCTION -T& DynamicCMatrixKokkos::operator()(size_t i) const { - assert(order_ == 1 && "Tensor order (rank) does not match constructor in DynamicCMatrixKokkos 1D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCMatrixKokkos 1D!"); - return this_matrix_((i - 1)); -} - -template -KOKKOS_INLINE_FUNCTION -T& DynamicCMatrixKokkos::operator()(size_t i, size_t j) const { - assert(order_ == 2 && "Tensor order (rank) does not match constructor in DynamicCMatrixKokkos 2D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCMatrixKokkos 2D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicCMatrixKokkos 2D!"); - return this_matrix_((j - 1) + ((i - 1) * dims_[1])); -} - -template -KOKKOS_INLINE_FUNCTION -T& DynamicCMatrixKokkos::operator()(size_t i, size_t j, size_t k) const { - assert(order_ == 3 && "Tensor order (rank) does not match constructor in DynamicCMatrixKokkos 3D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCMatrixKokkos 3D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicCMatrixKokkos 3D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicCMatrixKokkos 3D!"); - return this_matrix_((k - 1) + ((j - 1) * dims_[2]) - + ((i - 1) * dims_[2] * dims_[1])); -} - -template -KOKKOS_INLINE_FUNCTION -T& DynamicCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { - assert(order_ == 4 && "Tensor order (rank) does not match constructor in DynamicCMatrixKokkos 4D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCMatrixKokkos 4D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicCMatrixKokkos 4D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicCMatrixKokkos 4D!"); - assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicCMatrixKokkos 4D!"); - return this_matrix_((l - 1) + ((k - 1) * dims_[3]) - + ((j - 1) * dims_[3] * dims_[2]) - + ((i - 1) * dims_[3] * dims_[2] * dims_[1])); -} - -template -KOKKOS_INLINE_FUNCTION -T& DynamicCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m) const { - assert(order_ == 5 && "Tensor order (rank) does not match constructor in DynamicCMatrixKokkos 5D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCMatrixKokkos 5D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicCMatrixKokkos 5D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicCMatrixKokkos 5D!"); - assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicCMatrixKokkos 5D!"); - assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicCMatrixKokkos 5D!"); - return this_matrix_((m - 1) + ((l - 1) * dims_[4]) - + ((k - 1) * dims_[4] * dims_[3]) - + ((j - 1) * dims_[4] * dims_[3] * dims_[2]) - + ((i - 1) * dims_[4] * dims_[3] * dims_[2] * dims_[1])); -} - -template -KOKKOS_INLINE_FUNCTION -T& DynamicCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n) const { - assert(order_ == 6 && "Tensor order (rank) does not match constructor in DynamicCMatrixKokkos 6D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCMatrixKokkos 6D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicCMatrixKokkos 6D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicCMatrixKokkos 6D!"); - assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicCMatrixKokkos 6D!"); - assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicCMatrixKokkos 6D!"); - assert(n >= 0 && n < dims_[5] && "n is out of bounds in DynamicCMatrixKokkos 6D!"); - return this_matrix_((n - 1) + ((m - 1) * dims_[5]) - + ((l - 1) * dims_[5] * dims_[4]) - + ((k - 1) * dims_[5] * dims_[4] * dims_[3]) - + ((j - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2]) - + ((i - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); -} - -template -KOKKOS_INLINE_FUNCTION -T& DynamicCMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n, size_t o) const { - assert(order_ == 7 && "Tensor order (rank) does not match constructor in DynamicCMatrixKokkos 7D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicCMatrixKokkos 7D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicCMatrixKokkos 7D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicCMatrixKokkos 7D!"); - assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicCMatrixKokkos 7D!"); - assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicCMatrixKokkos 7D!"); - assert(n >= 0 && n < dims_[5] && "n is out of bounds in DynamicCMatrixKokkos 7D!"); - assert(o >= 0 && o < dims_[6] && "o is out of bounds in DynamicCMatrixKokkos 7D!"); - return this_matrix_((o - 1) + ((n - 1) * dims_[6]) - + ((m - 1) * dims_[6] * dims_[5]) - + ((l - 1) * dims_[6] * dims_[5] * dims_[4]) - + ((k - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3]) - + ((j - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) - + ((i - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); -} - -template -KOKKOS_INLINE_FUNCTION -DynamicCMatrixKokkos& DynamicCMatrixKokkos::operator= (const DynamicCMatrixKokkos& temp) { - using TArray1D = Kokkos::View; - - // Do nothing if the assignment is of the form x = x - if (this != &temp) { - for (int iter = 0; iter < temp.order_; iter++){ - dims_[iter] = temp.dims_[iter]; - dims_actual_size_[iter] = temp.dims_actual_size_[iter]; - } // end for - - order_ = temp.order_; - length_ = temp.length_; - this_matrix_ = temp.this_matrix_; - } - - return *this; -} - -// Return size -template -KOKKOS_INLINE_FUNCTION -size_t DynamicCMatrixKokkos::size() const { - return length_; -} - -template -KOKKOS_INLINE_FUNCTION -size_t DynamicCMatrixKokkos::extent() const { - return length_; -} - -template -KOKKOS_INLINE_FUNCTION -size_t DynamicCMatrixKokkos::dims(size_t i) const { - assert(i < order_ && "DynamicCMatrixKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(i >= 0 && dims_actual_size_[i]>0 && "Access to DynamicCMatrixKokkos dims is out of bounds!"); - return dims_actual_size_[i]; -} - -template -KOKKOS_INLINE_FUNCTION -size_t DynamicCMatrixKokkos::dims_max(size_t i) const { - assert(i < order_ && "DynamicCMatrixKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(i >= 0 && dims_[i]>0 && "Access to DynamicCMatrixKokkos dims is out of bounds!"); - return dims_[i]; -} - -template -KOKKOS_INLINE_FUNCTION -size_t DynamicCMatrixKokkos::order() const { - return order_; -} - -/* -template -KOKKOS_INLINE_FUNCTION -void DynamicCMatrixKokkos::push_back(size_t dim_idx) const { - dims_actual_size_[dim_idx]++; -} -*/ - -template -KOKKOS_INLINE_FUNCTION -T* DynamicCMatrixKokkos::pointer() const { - return this_matrix_.data(); -} - -//return the stored Kokkos view -template -KOKKOS_INLINE_FUNCTION -Kokkos::View DynamicCMatrixKokkos::get_kokkos_view() const { - return this_matrix_; -} - -// Get the name of the view -template -KOKKOS_INLINE_FUNCTION -const std::string DynamicCMatrixKokkos::get_name() const{ - return this_matrix_.label(); -} - -// set values of array -template -void DynamicCMatrixKokkos::set_values(T val) { - Kokkos::parallel_for("SetValues_DynamicCMatrixKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { - this_matrix_(i) = val; - }); -} - -template -KOKKOS_INLINE_FUNCTION -DynamicCMatrixKokkos::~DynamicCMatrixKokkos() {} - -//////////////////////////////////////////////////////////////////////////////// -// End of DynamicCMatrixKokkos -//////////////////////////////////////////////////////////////////////////////// - -/*! \brief Dynamic version of the CArrayKokkos type. - * - */ -template -class DynamicFMatrixKokkos { - - using TArray1D = Kokkos::View; - -private: - size_t dims_[7]; - size_t dims_actual_size_[7]; - size_t order_; - size_t length_; - TArray1D this_matrix_; - -public: - DynamicFMatrixKokkos(); - - DynamicFMatrixKokkos(size_t dim0, const std::string& tag_string = DEFAULTSTRINGARRAY); - - DynamicFMatrixKokkos(size_t dim0, size_t dim1, const std::string& tag_string = DEFAULTSTRINGARRAY); - - DynamicFMatrixKokkos (size_t dim0, size_t dim1, size_t dim2, const std::string& tag_string = DEFAULTSTRINGARRAY); - - DynamicFMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, const std::string& tag_string = DEFAULTSTRINGARRAY); - - DynamicFMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, const std::string& tag_string = DEFAULTSTRINGARRAY); - - DynamicFMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, const std::string& tag_string = DEFAULTSTRINGARRAY); - - DynamicFMatrixKokkos(size_t dim0, size_t dim1, size_t dim2, - size_t dim3, size_t dim4, size_t dim5, - size_t dim6, const std::string& tag_string = DEFAULTSTRINGARRAY); - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i) const; - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j) const; - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k) const; - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l) const; - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const; - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n) const; - - KOKKOS_INLINE_FUNCTION - T& operator()(size_t i, size_t j, size_t k, size_t l, size_t m, - size_t n, size_t o) const; - - KOKKOS_INLINE_FUNCTION - DynamicFMatrixKokkos& operator=(const DynamicFMatrixKokkos& temp); - - // GPU Method - // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t size() const; - - // Host Method - // Method that returns size - KOKKOS_INLINE_FUNCTION - size_t extent() const; - - KOKKOS_INLINE_FUNCTION - size_t dims(size_t i) const; - - KOKKOS_INLINE_FUNCTION - size_t dims_max(size_t i) const; - - KOKKOS_INLINE_FUNCTION - size_t order() const; - - //KOKKOS_INLINE_FUNCTION - //void push_back() const; - - // Methods returns the raw pointer (most likely GPU) of the Kokkos View - KOKKOS_INLINE_FUNCTION - T* pointer() const; - - // set values - void set_values(T val); - - //return the view - KOKKOS_INLINE_FUNCTION - TArray1D get_kokkos_view() const; - - // Get the name of the view - KOKKOS_INLINE_FUNCTION - const std::string get_name() const; - - // Deconstructor - KOKKOS_INLINE_FUNCTION - ~DynamicFMatrixKokkos (); -}; // End of DynamicFMatrixKokkos - -// Default constructor -template -DynamicFMatrixKokkos::DynamicFMatrixKokkos() { - length_ = order_ = 0; - for (int i = 0; i < 7; i++) { - dims_[i] = 0; - dims_actual_size_[i] = 0; - } -} - -// Overloaded 1D constructor -template -DynamicFMatrixKokkos::DynamicFMatrixKokkos(size_t dim0, const std::string& tag_string) { - using TArray1D = Kokkos::View; - - dims_[0] = dim0; - for (int i = 0; i < 1; i++) { - dims_actual_size_[i] = 0; - } - order_ = 1; - length_ = dim0; - this_matrix_ = TArray1D(tag_string, length_); -} - -// Overloaded 2D constructor -template -DynamicFMatrixKokkos::DynamicFMatrixKokkos(size_t dim0, size_t dim1, const std::string& tag_string) { - using TArray1D = Kokkos::View; - - dims_[0] = dim0; - dims_[1] = dim1; - for (int i = 0; i < 2; i++) { - dims_actual_size_[i] = 0; - } - order_ = 2; - length_ = (dim0 * dim1); - this_matrix_ = TArray1D(tag_string, length_); -} - -template -DynamicFMatrixKokkos::DynamicFMatrixKokkos(size_t dim0, size_t dim1, - size_t dim2, const std::string& tag_string) { - using TArray1D = Kokkos::View; - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - for (int i = 0; i < 3; i++) { - dims_actual_size_[i] = 0; - } - order_ = 3; - length_ = (dim0 * dim1 * dim2); - this_matrix_ = TArray1D(tag_string, length_); -} - -template -DynamicFMatrixKokkos::DynamicFMatrixKokkos(size_t dim0, size_t dim1, - size_t dim2, size_t dim3, const std::string& tag_string) { - using TArray1D = Kokkos::View; - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - for (int i = 0; i < 4; i++) { - dims_actual_size_[i] = 0; - } - order_ = 4; - length_ = (dim0 * dim1 * dim2 * dim3); - this_matrix_ = TArray1D(tag_string, length_); -} - -template -DynamicFMatrixKokkos::DynamicFMatrixKokkos(size_t dim0, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, const std::string& tag_string) { - - using TArray1D = Kokkos::View; - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - for (int i = 0; i < 5; i++) { - dims_actual_size_[i] = 0; - } - order_ = 5; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4); - this_matrix_ = TArray1D(tag_string, length_); -} - -template -DynamicFMatrixKokkos::DynamicFMatrixKokkos(size_t dim0, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, size_t dim5, const std::string& tag_string) { - using TArray1D = Kokkos::View; - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - dims_[5] = dim5; - for (int i = 0; i < 6; i++) { - dims_actual_size_[i] = 0; - } - order_ = 6; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5); - this_matrix_ = TArray1D(tag_string, length_); -} - -template -DynamicFMatrixKokkos::DynamicFMatrixKokkos(size_t dim0, size_t dim1, - size_t dim2, size_t dim3, - size_t dim4, size_t dim5, - size_t dim6, const std::string& tag_string) { - using TArray1D = Kokkos::View; - - dims_[0] = dim0; - dims_[1] = dim1; - dims_[2] = dim2; - dims_[3] = dim3; - dims_[4] = dim4; - dims_[5] = dim5; - dims_[6] = dim6; - for (int i = 0; i < 7; i++) { - dims_actual_size_[i] = 0; - } - order_ = 7; - length_ = (dim0 * dim1 * dim2 * dim3 * dim4 * dim5 * dim6); - this_matrix_ = TArray1D(tag_string, length_); -} - -template -KOKKOS_INLINE_FUNCTION -T& DynamicFMatrixKokkos::operator()(size_t i) const { - assert(order_ == 1 && "Tensor order (rank) does not match constructor in DynamicFMatrixKokkos 1D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFMatrixKokkos 1D!"); - return this_matrix_((i - 1)); -} - -template -KOKKOS_INLINE_FUNCTION -T& DynamicFMatrixKokkos::operator()(size_t i, size_t j) const { - assert(order_ == 2 && "Tensor order (rank) does not match constructor in DynamicFMatrixKokkos 2D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFMatrixKokkos 2D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicFMatrixKokkos 2D!"); - return this_matrix_((j - 1) + ((i - 1) * dims_[1])); -} - -template -KOKKOS_INLINE_FUNCTION -T& DynamicFMatrixKokkos::operator()(size_t i, size_t j, size_t k) const { - assert(order_ == 3 && "Tensor order (rank) does not match constructor in DynamicFMatrixKokkos 3D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFMatrixKokkos 3D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicFMatrixKokkos 3D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicFMatrixKokkos 3D!"); - return this_matrix_((k - 1) + ((j - 1) * dims_[2]) - + ((i - 1) * dims_[2] * dims_[1])); -} - -template -KOKKOS_INLINE_FUNCTION -T& DynamicFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l) const { - assert(order_ == 4 && "Tensor order (rank) does not match constructor in DynamicFMatrixKokkos 4D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFMatrixKokkos 4D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicFMatrixKokkos 4D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicFMatrixKokkos 4D!"); - assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicFMatrixKokkos 4D!"); - return this_matrix_((l - 1) + ((k - 1) * dims_[3]) - + ((j - 1) * dims_[3] * dims_[2]) - + ((i - 1) * dims_[3] * dims_[2] * dims_[1])); -} - -template -KOKKOS_INLINE_FUNCTION -T& DynamicFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m) const { - assert(order_ == 5 && "Tensor order (rank) does not match constructor in DynamicFMatrixKokkos 5D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFMatrixKokkos 5D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicFMatrixKokkos 5D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicFMatrixKokkos 5D!"); - assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicFMatrixKokkos 5D!"); - assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicFMatrixKokkos 5D!"); - return this_matrix_((m - 1) + ((l - 1) * dims_[4]) - + ((k - 1) * dims_[4] * dims_[3]) - + ((j - 1) * dims_[4] * dims_[3] * dims_[2]) - + ((i - 1) * dims_[4] * dims_[3] * dims_[2] * dims_[1])); -} - -template -KOKKOS_INLINE_FUNCTION -T& DynamicFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n) const { - assert(order_ == 6 && "Tensor order (rank) does not match constructor in DynamicFMatrixKokkos 6D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFMatrixKokkos 6D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicFMatrixKokkos 6D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicFMatrixKokkos 6D!"); - assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicFMatrixKokkos 6D!"); - assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicFMatrixKokkos 6D!"); - assert(n >= 0 && n < dims_[5] && "n is out of bounds in DynamicFMatrixKokkos 6D!"); - return this_matrix_((n - 1) + ((m - 1) * dims_[5]) - + ((l - 1) * dims_[5] * dims_[4]) - + ((k - 1) * dims_[5] * dims_[4] * dims_[3]) - + ((j - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2]) - + ((i - 1) * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); -} - -template -KOKKOS_INLINE_FUNCTION -T& DynamicFMatrixKokkos::operator()(size_t i, size_t j, size_t k, size_t l, - size_t m, size_t n, size_t o) const { - assert(order_ == 7 && "Tensor order (rank) does not match constructor in DynamicFMatrixKokkos 7D!"); - assert(i >= 0 && i < dims_[0] && "i is out of bounds in DynamicFMatrixKokkos 7D!"); - assert(j >= 0 && j < dims_[1] && "j is out of bounds in DynamicFMatrixKokkos 7D!"); - assert(k >= 0 && k < dims_[2] && "k is out of bounds in DynamicFMatrixKokkos 7D!"); - assert(l >= 0 && l < dims_[3] && "l is out of bounds in DynamicFMatrixKokkos 7D!"); - assert(m >= 0 && m < dims_[4] && "m is out of bounds in DynamicFMatrixKokkos 7D!"); - assert(n >= 0 && n < dims_[5] && "n is out of bounds in DynamicFMatrixKokkos 7D!"); - assert(o >= 0 && o < dims_[6] && "o is out of bounds in DynamicFMatrixKokkos 7D!"); - return this_matrix_((o - 1) + ((n - 1) * dims_[6]) - + ((m - 1) * dims_[6] * dims_[5]) - + ((l - 1) * dims_[6] * dims_[5] * dims_[4]) - + ((k - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3]) - + ((j - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2]) - + ((i - 1) * dims_[6] * dims_[5] * dims_[4] * dims_[3] * dims_[2] * dims_[1])); -} - -template -KOKKOS_INLINE_FUNCTION -DynamicFMatrixKokkos& DynamicFMatrixKokkos::operator= (const DynamicFMatrixKokkos& temp) { - using TArray1D = Kokkos::View; - - // Do nothing if the assignment is of the form x = x - if (this != &temp) { - for (int iter = 0; iter < temp.order_; iter++){ - dims_[iter] = temp.dims_[iter]; - dims_actual_size_[iter] = temp.dims_actual_size_[iter]; - } // end for - - order_ = temp.order_; - length_ = temp.length_; - this_matrix_ = temp.this_matrix_; - } - - return *this; -} - -// Return size -template -KOKKOS_INLINE_FUNCTION -size_t DynamicFMatrixKokkos::size() const { - return length_; -} - -template -KOKKOS_INLINE_FUNCTION -size_t DynamicFMatrixKokkos::extent() const { - return length_; -} - -template -KOKKOS_INLINE_FUNCTION -size_t DynamicFMatrixKokkos::dims(size_t i) const { - assert(i < order_ && "DynamicFMatrixKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(i >= 0 && dims_actual_size_[i]>0 && "Access to DynamicFMatrixKokkos dims is out of bounds!"); - return dims_actual_size_[i]; -} - -template -KOKKOS_INLINE_FUNCTION -size_t DynamicFMatrixKokkos::dims_max(size_t i) const { - assert(i < order_ && "DynamicFMatrixKokkos order (rank) does not match constructor, dim[i] does not exist!"); - assert(i >= 0 && dims_[i]>0 && "Access to DynamicFMatrixKokkos dims is out of bounds!"); - return dims_[i]; -} - -template -KOKKOS_INLINE_FUNCTION -size_t DynamicFMatrixKokkos::order() const { - return order_; -} - -/* -template -KOKKOS_INLINE_FUNCTION -void DynamicFMatrixKokkos::push_back(size_t dim_idx) const { - dims_actual_size_[dim_idx]++; -} -*/ - -template -KOKKOS_INLINE_FUNCTION -T* DynamicFMatrixKokkos::pointer() const { - return this_matrix_.data(); -} - -//return the stored Kokkos view -template -KOKKOS_INLINE_FUNCTION -Kokkos::View DynamicFMatrixKokkos::get_kokkos_view() const { - return this_matrix_; -} - -// Get the name of the view -template -KOKKOS_INLINE_FUNCTION -const std::string DynamicFMatrixKokkos::get_name() const{ - return this_matrix_.label(); -} - -// set values of array -template -void DynamicFMatrixKokkos::set_values(T val) { - Kokkos::parallel_for("SetValues_DynamicFMatrixKokkos", length_, KOKKOS_CLASS_LAMBDA(const int i) { - this_matrix_(i) = val; - }); -} - -template -KOKKOS_INLINE_FUNCTION -DynamicFMatrixKokkos::~DynamicFMatrixKokkos() {} - -//////////////////////////////////////////////////////////////////////////////// -// End of DynamicFMatrixKokkos -//////////////////////////////////////////////////////////////////////////////// /*! \brief Kokkos version of the serial RaggedRightArray class. * From 8d1f654dfb2f29e2e93e7bee5d488d86476bd7a6 Mon Sep 17 00:00:00 2001 From: Daniel Dunning <39738037+djdunning@users.noreply.github.com> Date: Mon, 7 Oct 2024 08:26:57 -0600 Subject: [PATCH 8/9] hopefully updated kokkos module --- src/Kokkos/kokkos | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kokkos/kokkos b/src/Kokkos/kokkos index 71a9bcae..cbcf4cf1 160000 --- a/src/Kokkos/kokkos +++ b/src/Kokkos/kokkos @@ -1 +1 @@ -Subproject commit 71a9bcae52543bd065522bf3e41b5bfa467d8015 +Subproject commit cbcf4cf10f1454fa71b433fb840b683abf09b457 From 545794ff0695145f065327b8a2c1df04a9bf0905 Mon Sep 17 00:00:00 2001 From: Daniel Dunning <39738037+djdunning@users.noreply.github.com> Date: Mon, 7 Oct 2024 08:48:00 -0600 Subject: [PATCH 9/9] updated FOR_FIRST loops in examples --- examples/kokkos_for.cpp | 6 +++--- examples/test_set_values.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/kokkos_for.cpp b/examples/kokkos_for.cpp index 462593bb..35185191 100644 --- a/examples/kokkos_for.cpp +++ b/examples/kokkos_for.cpp @@ -358,7 +358,7 @@ int main(int argc, char* argv[]) 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,hiersize, { + FOR_FIRST(i_i, 0, hiersize, { // Kokkos::parallel_for( \ //Kokkos::TeamPolicy<>( 32, Kokkos::AUTO, 32 ), \ //KOKKOS_LAMBDA ( const Kokkos::TeamPolicy<>::member_type &teamMember ) { @@ -391,7 +391,7 @@ int main(int argc, char* argv[]) printf("\n\n\nHierarchical Reduce\n"); //2D nesting - FOR_FIRST(i_i,hiersize, { + FOR_FIRST(i_i,0,hiersize, { // Kokkos::parallel_for( \ //Kokkos::TeamPolicy<>( 32, Kokkos::AUTO, 32 ), \ //KOKKOS_LAMBDA ( const Kokkos::TeamPolicy<>::member_type &teamMember ) { @@ -419,7 +419,7 @@ int main(int argc, char* argv[]) printf("\n\n\nHierarchical Vectorized Reduce\n"); //3D vector nesting - FOR_FIRST(i_i,hiersize, { + FOR_FIRST(i_i,0,hiersize, { // Kokkos::parallel_for( \ //Kokkos::TeamPolicy<>( 32, Kokkos::AUTO, 32 ), \ //KOKKOS_LAMBDA ( const Kokkos::TeamPolicy<>::member_type &teamMember ) { diff --git a/examples/test_set_values.cpp b/examples/test_set_values.cpp index 1f7b54bf..82d3f5d5 100644 --- a/examples/test_set_values.cpp +++ b/examples/test_set_values.cpp @@ -232,7 +232,7 @@ int main() 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_FIRST(i, 3, { + FOR_FIRST(i, 0, 3, { FOR_SECOND(j, 0, dynrightK.stride(i), { //printf("%.2f ", dynrightK(i,j)); }); @@ -254,7 +254,7 @@ int main() 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_FIRST(i, 4, { + FOR_FIRST(i, 0, 4, { FOR_SECOND(j, 0, dyndownK.stride(i), { //printf("%.2f ", dyndownK(i,j)); });