From c0b3a830eb6f7150b65b919ef1db4dc9040507aa Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Thu, 1 Dec 2022 18:03:49 -0500 Subject: [PATCH] Indentation --- include/deal.II/base/memory_space_data.h | 6 +- include/deal.II/lac/la_parallel_vector.h | 2 +- .../lac/la_parallel_vector.templates.h | 234 ++++++++++-------- .../deal.II/lac/vector_operations_internal.h | 12 +- source/base/kokkos.cc | 56 ++--- 5 files changed, 169 insertions(+), 141 deletions(-) diff --git a/include/deal.II/base/memory_space_data.h b/include/deal.II/base/memory_space_data.h index 77bbc00de2..afe5cbea96 100644 --- a/include/deal.II/base/memory_space_data.h +++ b/include/deal.II/base/memory_space_data.h @@ -101,7 +101,7 @@ namespace MemorySpace template MemorySpaceData::MemorySpaceData() : values_host_buffer((dealii::Impl::ensure_kokkos_initialized(), - Kokkos::View("host data", 0))) + Kokkos::View("host data", 0))) , values(Kokkos::View( "memoryspace data", 0)) @@ -157,8 +157,8 @@ namespace MemorySpace inline void swap(MemorySpaceData &u, MemorySpaceData &v) { - std::swap(u.values_host_buffer, v.values_host_buffer); - std::swap(u.values, v.values); + std::swap(u.values_host_buffer, v.values_host_buffer); + std::swap(u.values, v.values); std::swap(u.values_sm_ptr, v.values_sm_ptr); } diff --git a/include/deal.II/lac/la_parallel_vector.h b/include/deal.II/lac/la_parallel_vector.h index ecf934145a..cca0fe7736 100644 --- a/include/deal.II/lac/la_parallel_vector.h +++ b/include/deal.II/lac/la_parallel_vector.h @@ -1656,7 +1656,7 @@ namespace LinearAlgebra inline Number * Vector::get_values() const { - return data.values.data(); + return data.values.data(); } diff --git a/include/deal.II/lac/la_parallel_vector.templates.h b/include/deal.II/lac/la_parallel_vector.templates.h index 0a08efb5e1..00cba2c164 100644 --- a/include/deal.II/lac/la_parallel_vector.templates.h +++ b/include/deal.II/lac/la_parallel_vector.templates.h @@ -135,7 +135,7 @@ namespace LinearAlgebra { if (comm_shared == MPI_COMM_SELF) { - Kokkos::resize(data.values, new_alloc_size); + Kokkos::resize(data.values, new_alloc_size); allocated_size = new_alloc_size; @@ -343,7 +343,7 @@ namespace LinearAlgebra data.values.size() == 0), ExcInternalError()); - Kokkos::resize(data.values, new_alloc_size); + Kokkos::resize(data.values, new_alloc_size); allocated_size = new_alloc_size; } @@ -931,25 +931,26 @@ namespace LinearAlgebra Vector::zero_out_ghost_values() const { if (data.values.size() != 0) - { -#ifdef DEAL_II_COMPILER_CUDA_AWARE - if (std::is_same_v) { - const cudaError_t cuda_error_code = - cudaMemset(data.values.data() + - partitioner->locally_owned_size(), - 0, - partitioner->n_ghost_indices() * sizeof(Number)); - AssertCuda(cuda_error_code); - } - else +#ifdef DEAL_II_COMPILER_CUDA_AWARE + if (std::is_same_v) + { + const cudaError_t cuda_error_code = + cudaMemset(data.values.data() + + partitioner->locally_owned_size(), + 0, + partitioner->n_ghost_indices() * sizeof(Number)); + AssertCuda(cuda_error_code); + } + else #endif - { - std::fill_n(data.values.data() + partitioner->locally_owned_size(), - partitioner->n_ghost_indices(), - Number()); + { + std::fill_n(data.values.data() + + partitioner->locally_owned_size(), + partitioner->n_ghost_indices(), + Number()); + } } - } vector_is_ghosted = false; } @@ -978,7 +979,8 @@ namespace LinearAlgebra if (std::is_same::value) { if (import_data.values_host_buffer.size() == 0) - Kokkos::resize(import_data.values_host_buffer, partitioner->n_import_indices()); + Kokkos::resize(import_data.values_host_buffer, + partitioner->n_import_indices()); } else # endif @@ -990,7 +992,8 @@ namespace LinearAlgebra "This code path should only be compiled for CUDA-aware-MPI for MemorySpace::Host!"); # endif if (import_data.values.size() == 0) - Kokkos::resize(import_data.values, partitioner->n_import_indices()); + Kokkos::resize(import_data.values, + partitioner->n_import_indices()); } } @@ -1002,15 +1005,19 @@ namespace LinearAlgebra // device. We use values to store the elements because the function // uses a view of the array and thus we need the data on the host to // outlive the scope of the function. - data.values_host_buffer = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, data.values); + data.values_host_buffer = + Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, + data.values); partitioner->import_from_ghosted_array_start( operation, communication_channel, ArrayView( - data.values_host_buffer.data() + partitioner->locally_owned_size(), + data.values_host_buffer.data() + + partitioner->locally_owned_size(), partitioner->n_ghost_indices()), ArrayView( - import_data.values_host_buffer.data(), partitioner->n_import_indices()), + import_data.values_host_buffer.data(), + partitioner->n_import_indices()), compress_requests); } else @@ -1022,8 +1029,8 @@ namespace LinearAlgebra ArrayView( data.values.data() + partitioner->locally_owned_size(), partitioner->n_ghost_indices()), - ArrayView( - import_data.values.data(), partitioner->n_import_indices()), + ArrayView(import_data.values.data(), + partitioner->n_import_indices()), compress_requests); } #else @@ -1059,17 +1066,20 @@ namespace LinearAlgebra ->import_from_ghosted_array_finish( operation, ArrayView( - import_data.values_host_buffer.data(), partitioner->n_import_indices()), + import_data.values_host_buffer.data(), + partitioner->n_import_indices()), ArrayView( - data.values_host_buffer.data(), partitioner->locally_owned_size()), + data.values_host_buffer.data(), + partitioner->locally_owned_size()), ArrayView( - data.values_host_buffer.data() + partitioner->locally_owned_size(), + data.values_host_buffer.data() + + partitioner->locally_owned_size(), partitioner->n_ghost_indices()), compress_requests); - // The communication is done on the host, so we need to + // The communication is done on the host, so we need to // move the data back to the device. - cudaError_t cuda_error_code = + cudaError_t cuda_error_code = cudaMemcpy(data.values.data(), data.values_host_buffer.data(), allocated_size * sizeof(Number), @@ -1124,56 +1134,66 @@ namespace LinearAlgebra { # if defined(DEAL_II_COMPILER_CUDA_AWARE) && \ !defined(DEAL_II_MPI_WITH_CUDA_SUPPORT) - if (std::is_same_v) { - if (import_data.values_host_buffer.size() == 0) - Kokkos::resize(import_data.values_host_buffer, partitioner->n_import_indices()); - } - else + if (std::is_same_v) + { + if (import_data.values_host_buffer.size() == 0) + Kokkos::resize(import_data.values_host_buffer, + partitioner->n_import_indices()); + } + else # endif - { -# ifdef DEAL_II_MPI_WITH_CUDA_SUPPORT - static_assert( - std::is_same::value, - "This code path should only be compiled for CUDA-aware-MPI for MemorySpace::Host!"); -# endif - if (import_data.values.size() == 0) - Kokkos::resize(import_data.values, partitioner->n_import_indices()); - } + { +# ifdef DEAL_II_MPI_WITH_CUDA_SUPPORT + static_assert( + std::is_same::value, + "This code path should only be compiled for CUDA-aware-MPI for MemorySpace::Host!"); +# endif + if (import_data.values.size() == 0) + Kokkos::resize(import_data.values, + partitioner->n_import_indices()); + } } # if defined DEAL_II_COMPILER_CUDA_AWARE && \ !defined(DEAL_II_MPI_WITH_CUDA_SUPPORT) - if (std::is_same_v) { - // Move the data to the host and then move it back to the - // device. We use values to store the elements because the function - // uses a view of the array and thus we need the data on the host to - // outlive the scope of the function. - data.values_host_buffer = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, data.values); - - partitioner->export_to_ghosted_array_start( - communication_channel, - ArrayView( - data.values_host_buffer.data(), partitioner->locally_owned_size()), - ArrayView(import_data.values_host_buffer.data(), - partitioner->n_import_indices()), - ArrayView( - data.values_host_buffer.data() + partitioner->locally_owned_size(), - partitioner->n_ghost_indices()), - update_ghost_values_requests); - } else -#endif - { - partitioner->export_to_ghosted_array_start( - communication_channel, - ArrayView( - data.values.data(), partitioner->locally_owned_size()), - ArrayView(import_data.values.data(), - partitioner->n_import_indices()), - ArrayView( - data.values.data() + partitioner->locally_owned_size(), - partitioner->n_ghost_indices()), - update_ghost_values_requests); - } + if (std::is_same_v) + { + // Move the data to the host and then move it back to the + // device. We use values to store the elements because the function + // uses a view of the array and thus we need the data on the host to + // outlive the scope of the function. + data.values_host_buffer = + Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, + data.values); + + partitioner->export_to_ghosted_array_start( + communication_channel, + ArrayView( + data.values_host_buffer.data(), + partitioner->locally_owned_size()), + ArrayView( + import_data.values_host_buffer.data(), + partitioner->n_import_indices()), + ArrayView( + data.values_host_buffer.data() + + partitioner->locally_owned_size(), + partitioner->n_ghost_indices()), + update_ghost_values_requests); + } + else +# endif + { + partitioner->export_to_ghosted_array_start( + communication_channel, + ArrayView( + data.values.data(), partitioner->locally_owned_size()), + ArrayView(import_data.values.data(), + partitioner->n_import_indices()), + ArrayView( + data.values.data() + partitioner->locally_owned_size(), + partitioner->n_ghost_indices()), + update_ghost_values_requests); + } #else (void)communication_channel; @@ -1198,35 +1218,38 @@ namespace LinearAlgebra std::lock_guard lock(mutex); # if defined(DEAL_II_COMPILER_CUDA_AWARE) && \ - !defined(DEAL_II_MPI_WITH_CUDA_SUPPORT) - if (std::is_same::value) - { - partitioner->export_to_ghosted_array_finish( - ArrayView( - data.values_host_buffer.data() + partitioner->locally_owned_size(), - partitioner->n_ghost_indices()), - update_ghost_values_requests); - -// The communication is done on the host, so we need to - // move the data back to the device. - cudaError_t cuda_error_code = - cudaMemcpy(data.values.data() + - partitioner->locally_owned_size(), - data.values_host_buffer.data() + partitioner->locally_owned_size(), - partitioner->n_ghost_indices() * sizeof(Number), - cudaMemcpyHostToDevice); - AssertCuda(cuda_error_code); - - Kokkos::resize(data.values_host_buffer, 0); - } else -#endif - { - partitioner->export_to_ghosted_array_finish( - ArrayView( - data.values.data() + partitioner->locally_owned_size(), - partitioner->n_ghost_indices()), - update_ghost_values_requests); - } + !defined(DEAL_II_MPI_WITH_CUDA_SUPPORT) + if (std::is_same::value) + { + partitioner->export_to_ghosted_array_finish( + ArrayView( + data.values_host_buffer.data() + + partitioner->locally_owned_size(), + partitioner->n_ghost_indices()), + update_ghost_values_requests); + + // The communication is done on the host, so we need to + // move the data back to the device. + cudaError_t cuda_error_code = + cudaMemcpy(data.values.data() + + partitioner->locally_owned_size(), + data.values_host_buffer.data() + + partitioner->locally_owned_size(), + partitioner->n_ghost_indices() * sizeof(Number), + cudaMemcpyHostToDevice); + AssertCuda(cuda_error_code); + + Kokkos::resize(data.values_host_buffer, 0); + } + else +# endif + { + partitioner->export_to_ghosted_array_finish( + ArrayView( + data.values.data() + partitioner->locally_owned_size(), + partitioner->n_ghost_indices()), + update_ghost_values_requests); + } } #endif @@ -2033,7 +2056,8 @@ namespace LinearAlgebra if (partitioner.use_count() > 0) memory += partitioner->memory_consumption() / partitioner.use_count() + 1; - if (import_data.values_host_buffer.size() != 0 || import_data.values.size() != 0) + if (import_data.values_host_buffer.size() != 0 || + import_data.values.size() != 0) memory += (static_cast(partitioner->n_import_indices()) * sizeof(Number)); return memory; diff --git a/include/deal.II/lac/vector_operations_internal.h b/include/deal.II/lac/vector_operations_internal.h index cde2c0b491..21d08f4413 100644 --- a/include/deal.II/lac/vector_operations_internal.h +++ b/include/deal.II/lac/vector_operations_internal.h @@ -1889,8 +1889,12 @@ namespace internal ::dealii::MemorySpace::Host> &data) { - Vectorization_sadd_xavbw vector_sadd( - data.values.data(), v_data.values.data(), w_data.values.data(), x, a, b); + Vectorization_sadd_xavbw vector_sadd(data.values.data(), + v_data.values.data(), + w_data.values.data(), + x, + a, + b); parallel_for(vector_sadd, 0, size, thread_loop_partitioner); } @@ -1904,8 +1908,8 @@ namespace internal ::dealii::MemorySpace::Host> &data) { - Vectorization_multiply_factor vector_multiply(data.values.data(), - factor); + Vectorization_multiply_factor vector_multiply( + data.values.data(), factor); parallel_for(vector_multiply, 0, size, thread_loop_partitioner); } diff --git a/source/base/kokkos.cc b/source/base/kokkos.cc index 77321393bd..343929746d 100644 --- a/source/base/kokkos.cc +++ b/source/base/kokkos.cc @@ -28,34 +28,34 @@ namespace Impl ensure_kokkos_initialized() { if (!Kokkos::is_initialized()) - { - GrowingVectorMemory< - LinearAlgebra::distributed::Vector>{}; - GrowingVectorMemory< - LinearAlgebra::distributed::Vector>{}; - GrowingVectorMemory< - LinearAlgebra::distributed::Vector>{}; - GrowingVectorMemory< - LinearAlgebra::distributed::Vector>{}; - Kokkos::push_finalize_hook( - GrowingVectorMemory< - LinearAlgebra::distributed::Vector>:: - release_unused_memory); - Kokkos::push_finalize_hook( - GrowingVectorMemory< - LinearAlgebra::distributed::Vector>:: - release_unused_memory); - Kokkos::push_finalize_hook( - GrowingVectorMemory< - LinearAlgebra::distributed::Vector>:: - release_unused_memory); - Kokkos::push_finalize_hook( - GrowingVectorMemory< - LinearAlgebra::distributed::Vector>:: - release_unused_memory); - Kokkos::initialize(); - std::atexit(Kokkos::finalize); - } + { + GrowingVectorMemory< + LinearAlgebra::distributed::Vector>{}; + GrowingVectorMemory< + LinearAlgebra::distributed::Vector>{}; + GrowingVectorMemory< + LinearAlgebra::distributed::Vector>{}; + GrowingVectorMemory< + LinearAlgebra::distributed::Vector>{}; + Kokkos::push_finalize_hook( + GrowingVectorMemory< + LinearAlgebra::distributed::Vector>:: + release_unused_memory); + Kokkos::push_finalize_hook( + GrowingVectorMemory< + LinearAlgebra::distributed::Vector>:: + release_unused_memory); + Kokkos::push_finalize_hook( + GrowingVectorMemory< + LinearAlgebra::distributed::Vector>:: + release_unused_memory); + Kokkos::push_finalize_hook( + GrowingVectorMemory< + LinearAlgebra::distributed::Vector>:: + release_unused_memory); + Kokkos::initialize(); + std::atexit(Kokkos::finalize); + } } } // namespace Impl DEAL_II_NAMESPACE_CLOSE -- 2.39.5