From 58ce0d73e5c3f4f54bd46a28b3036898df8345fa Mon Sep 17 00:00:00 2001 From: Yuuichi Asahi Date: Sat, 6 Jul 2024 16:29:47 +0900 Subject: [PATCH 1/7] Rename:unuse under score in Plan functions --- fft/src/KokkosFFT_Cuda_plans.hpp | 60 ++++++++++++++----------------- fft/src/KokkosFFT_HIP_plans.hpp | 62 +++++++++++++++----------------- fft/src/KokkosFFT_Host_plans.hpp | 30 +++++++--------- fft/src/KokkosFFT_Plans.hpp | 12 +++---- fft/src/KokkosFFT_ROCM_plans.hpp | 29 +++++++-------- fft/src/KokkosFFT_SYCL_plans.hpp | 27 ++++++-------- 6 files changed, 95 insertions(+), 125 deletions(-) diff --git a/fft/src/KokkosFFT_Cuda_plans.hpp b/fft/src/KokkosFFT_Cuda_plans.hpp index 6ea457f..935be54 100644 --- a/fft/src/KokkosFFT_Cuda_plans.hpp +++ b/fft/src/KokkosFFT_Cuda_plans.hpp @@ -17,14 +17,14 @@ template , std::nullptr_t> = nullptr> -auto _create(const ExecutionSpace& exec_space, std::unique_ptr& plan, - const InViewType& in, const OutViewType& out, BufferViewType&, - InfoType&, Direction /*direction*/, axis_type<1> axes, - shape_type<1> s) { +auto create_plan(const ExecutionSpace& exec_space, + std::unique_ptr& plan, const InViewType& in, + const OutViewType& out, BufferViewType&, InfoType&, + Direction /*direction*/, axis_type<1> axes, shape_type<1> s) { static_assert(Kokkos::is_view::value, - "KokkosFFT::_create: InViewType is not a Kokkos::View."); + "KokkosFFT::create_plan: InViewType is not a Kokkos::View."); static_assert(Kokkos::is_view::value, - "KokkosFFT::_create: OutViewType is not a Kokkos::View."); + "KokkosFFT::create_plan: OutViewType is not a Kokkos::View."); using in_value_type = typename InViewType::non_const_value_type; using out_value_type = typename OutViewType::non_const_value_type; @@ -54,14 +54,14 @@ template , std::nullptr_t> = nullptr> -auto _create(const ExecutionSpace& exec_space, std::unique_ptr& plan, - const InViewType& in, const OutViewType& out, BufferViewType&, - InfoType&, Direction /*direction*/, axis_type<2> axes, - shape_type<2> s) { +auto create_plan(const ExecutionSpace& exec_space, + std::unique_ptr& plan, const InViewType& in, + const OutViewType& out, BufferViewType&, InfoType&, + Direction /*direction*/, axis_type<2> axes, shape_type<2> s) { static_assert(Kokkos::is_view::value, - "KokkosFFT::_create: InViewType is not a Kokkos::View."); + "KokkosFFT::create_plan: InViewType is not a Kokkos::View."); static_assert(Kokkos::is_view::value, - "KokkosFFT::_create: OutViewType is not a Kokkos::View."); + "KokkosFFT::create_plan: OutViewType is not a Kokkos::View."); using in_value_type = typename InViewType::non_const_value_type; using out_value_type = typename OutViewType::non_const_value_type; @@ -91,14 +91,14 @@ template , std::nullptr_t> = nullptr> -auto _create(const ExecutionSpace& exec_space, std::unique_ptr& plan, - const InViewType& in, const OutViewType& out, BufferViewType&, - InfoType&, Direction /*direction*/, axis_type<3> axes, - shape_type<3> s) { +auto create_plan(const ExecutionSpace& exec_space, + std::unique_ptr& plan, const InViewType& in, + const OutViewType& out, BufferViewType&, InfoType&, + Direction /*direction*/, axis_type<3> axes, shape_type<3> s) { static_assert(Kokkos::is_view::value, - "KokkosFFT::_create: InViewType is not a Kokkos::View."); + "KokkosFFT::create_plan: InViewType is not a Kokkos::View."); static_assert(Kokkos::is_view::value, - "KokkosFFT::_create: OutViewType is not a Kokkos::View."); + "KokkosFFT::create_plan: OutViewType is not a Kokkos::View."); using in_value_type = typename InViewType::non_const_value_type; using out_value_type = typename OutViewType::non_const_value_type; @@ -130,14 +130,15 @@ template , std::nullptr_t> = nullptr> -auto _create(const ExecutionSpace& exec_space, std::unique_ptr& plan, - const InViewType& in, const OutViewType& out, BufferViewType&, - InfoType&, Direction /*direction*/, axis_type axes, - shape_type s) { +auto create_plan(const ExecutionSpace& exec_space, + std::unique_ptr& plan, const InViewType& in, + const OutViewType& out, BufferViewType&, InfoType&, + Direction /*direction*/, axis_type axes, + shape_type s) { static_assert(Kokkos::is_view::value, - "KokkosFFT::_create: InViewType is not a Kokkos::View."); + "KokkosFFT::create_plan: InViewType is not a Kokkos::View."); static_assert(Kokkos::is_view::value, - "KokkosFFT::_create: OutViewType is not a Kokkos::View."); + "KokkosFFT::create_plan: OutViewType is not a Kokkos::View."); using in_value_type = typename InViewType::non_const_value_type; using out_value_type = typename OutViewType::non_const_value_type; @@ -176,19 +177,12 @@ auto _create(const ExecutionSpace& exec_space, std::unique_ptr& plan, return fft_size; } -template , std::nullptr_t> = nullptr> -void _destroy_plan(std::unique_ptr& plan) { +void destroy_plan_and_info(std::unique_ptr& plan, InfoType&) { cufftDestroy(*plan); } - -template , - std::nullptr_t> = nullptr> -void _destroy_info(InfoType&) { - // not used, no finalization is required -} } // namespace Impl } // namespace KokkosFFT diff --git a/fft/src/KokkosFFT_HIP_plans.hpp b/fft/src/KokkosFFT_HIP_plans.hpp index 5247e9f..bc2b338 100644 --- a/fft/src/KokkosFFT_HIP_plans.hpp +++ b/fft/src/KokkosFFT_HIP_plans.hpp @@ -17,14 +17,14 @@ template , std::nullptr_t> = nullptr> -auto _create(const ExecutionSpace& exec_space, std::unique_ptr& plan, - const InViewType& in, const OutViewType& out, BufferViewType&, - InfoType&, Direction /*direction*/, axis_type<1> axes, - shape_type<1> s) { +auto create_plan(const ExecutionSpace& exec_space, + std::unique_ptr& plan, const InViewType& in, + const OutViewType& out, BufferViewType&, InfoType&, + Direction /*direction*/, axis_type<1> axes, shape_type<1> s) { static_assert(Kokkos::is_view::value, - "KokkosFFT::_create: InViewType is not a Kokkos::View."); + "KokkosFFT::create_plan: InViewType is not a Kokkos::View."); static_assert(Kokkos::is_view::value, - "KokkosFFT::_create: OutViewType is not a Kokkos::View."); + "KokkosFFT::create_plan: OutViewType is not a Kokkos::View."); using in_value_type = typename InViewType::non_const_value_type; using out_value_type = typename OutViewType::non_const_value_type; @@ -56,14 +56,14 @@ template , std::nullptr_t> = nullptr> -auto _create(const ExecutionSpace& exec_space, std::unique_ptr& plan, - const InViewType& in, const OutViewType& out, BufferViewType&, - InfoType&, Direction /*direction*/, axis_type<2> axes, - shape_type<2> s) { +auto create_plan(const ExecutionSpace& exec_space, + std::unique_ptr& plan, const InViewType& in, + const OutViewType& out, BufferViewType&, InfoType&, + Direction /*direction*/, axis_type<2> axes, shape_type<2> s) { static_assert(Kokkos::is_view::value, - "KokkosFFT::_create: InViewType is not a Kokkos::View."); + "KokkosFFT::create_plan: InViewType is not a Kokkos::View."); static_assert(Kokkos::is_view::value, - "KokkosFFT::_create: OutViewType is not a Kokkos::View."); + "KokkosFFT::create_plan: OutViewType is not a Kokkos::View."); using in_value_type = typename InViewType::non_const_value_type; using out_value_type = typename OutViewType::non_const_value_type; @@ -95,14 +95,14 @@ template , std::nullptr_t> = nullptr> -auto _create(const ExecutionSpace& exec_space, std::unique_ptr& plan, - const InViewType& in, const OutViewType& out, BufferViewType&, - InfoType&, Direction /*direction*/, axis_type<3> axes, - shape_type<3> s) { +auto create_plan(const ExecutionSpace& exec_space, + std::unique_ptr& plan, const InViewType& in, + const OutViewType& out, BufferViewType&, InfoType&, + Direction /*direction*/, axis_type<3> axes, shape_type<3> s) { static_assert(Kokkos::is_view::value, - "KokkosFFT::_create: InViewType is not a Kokkos::View."); + "KokkosFFT::create_plan: InViewType is not a Kokkos::View."); static_assert(Kokkos::is_view::value, - "KokkosFFT::_create: OutViewType is not a Kokkos::View."); + "KokkosFFT::create_plan: OutViewType is not a Kokkos::View."); using in_value_type = typename InViewType::non_const_value_type; using out_value_type = typename OutViewType::non_const_value_type; @@ -136,20 +136,21 @@ template , std::nullptr_t> = nullptr> -auto _create(const ExecutionSpace& exec_space, std::unique_ptr& plan, - const InViewType& in, const OutViewType& out, BufferViewType&, - InfoType&, Direction /*direction*/, axis_type axes, - shape_type s) { +auto create_plan(const ExecutionSpace& exec_space, + std::unique_ptr& plan, const InViewType& in, + const OutViewType& out, BufferViewType&, InfoType&, + Direction /*direction*/, axis_type axes, + shape_type s) { static_assert(Kokkos::is_view::value, - "KokkosFFT::_create: InViewType is not a Kokkos::View."); + "KokkosFFT::create_plan: InViewType is not a Kokkos::View."); static_assert(Kokkos::is_view::value, - "KokkosFFT::_create: OutViewType is not a Kokkos::View."); + "KokkosFFT::create_plan: OutViewType is not a Kokkos::View."); using in_value_type = typename InViewType::non_const_value_type; using out_value_type = typename OutViewType::non_const_value_type; static_assert( InViewType::rank() >= fft_rank, - "KokkosFFT::_create: Rank of View must be larger than Rank of FFT."); + "KokkosFFT::create_plan: Rank of View must be larger than Rank of FFT."); const int rank = fft_rank; constexpr auto type = KokkosFFT::Impl::transform_type& plan, return fft_size; } -template , std::nullptr_t> = nullptr> -void _destroy_plan(std::unique_ptr& plan) { +void destroy_plan_and_info(std::unique_ptr& plan, InfoType&) { hipfftDestroy(*plan); } - -template , - std::nullptr_t> = nullptr> -void _destroy_info(InfoType&) { - // not used, no finalization is required -} } // namespace Impl } // namespace KokkosFFT diff --git a/fft/src/KokkosFFT_Host_plans.hpp b/fft/src/KokkosFFT_Host_plans.hpp index d1b7923..9416938 100644 --- a/fft/src/KokkosFFT_Host_plans.hpp +++ b/fft/src/KokkosFFT_Host_plans.hpp @@ -12,7 +12,7 @@ namespace KokkosFFT { namespace Impl { template -void _init_threads([[maybe_unused]] const ExecutionSpace& exec_space) { +void init_threads([[maybe_unused]] const ExecutionSpace& exec_space) { #if defined(KOKKOS_ENABLE_OPENMP) || defined(KOKKOS_ENABLE_THREADS) int nthreads = exec_space.concurrency(); @@ -33,23 +33,24 @@ template , std::nullptr_t> = nullptr> -auto _create(const ExecutionSpace& exec_space, std::unique_ptr& plan, - const InViewType& in, const OutViewType& out, BufferViewType&, - InfoType&, [[maybe_unused]] Direction direction, - axis_type axes, shape_type s) { +auto create_plan(const ExecutionSpace& exec_space, + std::unique_ptr& plan, const InViewType& in, + const OutViewType& out, BufferViewType&, InfoType&, + [[maybe_unused]] Direction direction, axis_type axes, + shape_type s) { static_assert(Kokkos::is_view::value, - "KokkosFFT::_create: InViewType is not a Kokkos::View."); + "KokkosFFT::create_plan: InViewType is not a Kokkos::View."); static_assert(Kokkos::is_view::value, - "KokkosFFT::_create: OutViewType is not a Kokkos::View."); + "KokkosFFT::create_plan: OutViewType is not a Kokkos::View."); using in_value_type = typename InViewType::non_const_value_type; using out_value_type = typename OutViewType::non_const_value_type; static_assert( InViewType::rank() >= fft_rank, - "KokkosFFT::_create: Rank of View must be larger than Rank of FFT."); + "KokkosFFT::create_plan: Rank of View must be larger than Rank of FFT."); const int rank = fft_rank; - _init_threads>( + init_threads>( exec_space); constexpr auto type = @@ -104,11 +105,11 @@ auto _create(const ExecutionSpace& exec_space, std::unique_ptr& plan, return fft_size; } -template , std::nullptr_t> = nullptr> -void _destroy_plan(std::unique_ptr& plan) { +void destroy_plan_and_info(std::unique_ptr& plan, InfoType&) { if constexpr (std::is_same_v) { fftwf_destroy_plan(*plan); } else { @@ -116,13 +117,6 @@ void _destroy_plan(std::unique_ptr& plan) { } } -template , - std::nullptr_t> = nullptr> -void _destroy_info(InfoType&) { - // not used, no finalization is required -} } // namespace Impl } // namespace KokkosFFT diff --git a/fft/src/KokkosFFT_Plans.hpp b/fft/src/KokkosFFT_Plans.hpp index 537f708..641fa00 100644 --- a/fft/src/KokkosFFT_Plans.hpp +++ b/fft/src/KokkosFFT_Plans.hpp @@ -213,8 +213,8 @@ class Plan { m_shape = KokkosFFT::Impl::get_modified_shape(in, out, s, m_axes); m_is_crop_or_pad_needed = KokkosFFT::Impl::is_crop_or_pad_needed(in, m_shape); - m_fft_size = KokkosFFT::Impl::_create(exec_space, m_plan, in, out, m_buffer, - m_info, direction, m_axes, s); + m_fft_size = KokkosFFT::Impl::create_plan( + exec_space, m_plan, in, out, m_buffer, m_info, direction, m_axes, s); } /// \brief Constructor for multidimensional FFT @@ -280,13 +280,13 @@ class Plan { m_shape = KokkosFFT::Impl::get_modified_shape(in, out, s, m_axes); m_is_crop_or_pad_needed = KokkosFFT::Impl::is_crop_or_pad_needed(in, m_shape); - m_fft_size = KokkosFFT::Impl::_create(exec_space, m_plan, in, out, m_buffer, - m_info, direction, axes, s); + m_fft_size = KokkosFFT::Impl::create_plan( + exec_space, m_plan, in, out, m_buffer, m_info, direction, axes, s); } ~Plan() { - _destroy_info(m_info); - _destroy_plan(m_plan); + destroy_plan_and_info(m_plan, + m_info); } Plan(const Plan&) = delete; diff --git a/fft/src/KokkosFFT_ROCM_plans.hpp b/fft/src/KokkosFFT_ROCM_plans.hpp index a8103fb..b1ea115 100644 --- a/fft/src/KokkosFFT_ROCM_plans.hpp +++ b/fft/src/KokkosFFT_ROCM_plans.hpp @@ -85,21 +85,21 @@ template , std::nullptr_t> = nullptr> -auto _create(const ExecutionSpace& exec_space, std::unique_ptr& plan, - const InViewType& in, const OutViewType& out, - BufferViewType& buffer, InfoType& execution_info, - Direction direction, axis_type axes, - shape_type s) { +auto create_plan(const ExecutionSpace& exec_space, + std::unique_ptr& plan, const InViewType& in, + const OutViewType& out, BufferViewType& buffer, + InfoType& execution_info, Direction direction, + axis_type axes, shape_type s) { static_assert(Kokkos::is_view::value, - "KokkosFFT::_create: InViewType is not a Kokkos::View."); + "KokkosFFT::create_plan: InViewType is not a Kokkos::View."); static_assert(Kokkos::is_view::value, - "KokkosFFT::_create: OutViewType is not a Kokkos::View."); + "KokkosFFT::create_plan: OutViewType is not a Kokkos::View."); using in_value_type = typename InViewType::non_const_value_type; using out_value_type = typename OutViewType::non_const_value_type; static_assert( InViewType::rank() >= fft_rank, - "KokkosFFT::_create: Rank of View must be larger than Rank of FFT."); + "KokkosFFT::create_plan: Rank of View must be larger than Rank of FFT."); constexpr auto type = KokkosFFT::Impl::transform_type& plan, return fft_size; } -template , std::nullptr_t> = nullptr> -void _destroy_plan(std::unique_ptr& plan) { - rocfft_plan_destroy(*plan); -} - -template , - std::nullptr_t> = nullptr> -void _destroy_info(InfoType& execution_info) { +void destroy_plan_and_info(std::unique_ptr& plan, + InfoType& execution_info) { rocfft_execution_info_destroy(execution_info); + rocfft_plan_destroy(*plan); } } // namespace Impl } // namespace KokkosFFT diff --git a/fft/src/KokkosFFT_SYCL_plans.hpp b/fft/src/KokkosFFT_SYCL_plans.hpp index f4c0ec4..8e9fdcd 100644 --- a/fft/src/KokkosFFT_SYCL_plans.hpp +++ b/fft/src/KokkosFFT_SYCL_plans.hpp @@ -48,20 +48,21 @@ template < std::size_t fft_rank = 1, std::enable_if_t, std::nullptr_t> = nullptr> -auto _create(const ExecutionSpace& exec_space, std::unique_ptr& plan, - const InViewType& in, const OutViewType& out, BufferViewType&, - InfoType&, Direction /*direction*/, axis_type axes, - shape_type s) { +auto create_plan(const ExecutionSpace& exec_space, + std::unique_ptr& plan, const InViewType& in, + const OutViewType& out, BufferViewType&, InfoType&, + Direction /*direction*/, axis_type axes, + shape_type s) { static_assert(Kokkos::is_view::value, - "KokkosFFT::_create: InViewType is not a Kokkos::View."); + "KokkosFFT::create_plan: InViewType is not a Kokkos::View."); static_assert(Kokkos::is_view::value, - "KokkosFFT::_create: OutViewType is not a Kokkos::View."); + "KokkosFFT::create_plan: OutViewType is not a Kokkos::View."); using in_value_type = typename InViewType::non_const_value_type; using out_value_type = typename OutViewType::non_const_value_type; static_assert( InViewType::rank() >= fft_rank, - "KokkosFFT::_create: Rank of View must be larger than Rank of FFT."); + "KokkosFFT::create_plan: Rank of View must be larger than Rank of FFT."); auto [in_extents, out_extents, fft_extents, howmany] = KokkosFFT::Impl::get_extents(in, out, axes, s); @@ -105,20 +106,12 @@ auto _create(const ExecutionSpace& exec_space, std::unique_ptr& plan, } template < - typename ExecutionSpace, typename PlanType, + typename ExecutionSpace, typename PlanType, typename InfoType, std::enable_if_t, std::nullptr_t> = nullptr> -void _destroy_plan(std::unique_ptr&) { +void destroy_plan_and_info(std::unique_ptr&, InfoType&) { // In oneMKL, plans are destroybed by destructor } - -template < - typename ExecutionSpace, typename InfoType, - std::enable_if_t, - std::nullptr_t> = nullptr> -void _destroy_info(InfoType&) { - // not used, no finalization is required -} } // namespace Impl } // namespace KokkosFFT From 714e563945b7c3f9d94e5259e56ef8110f0a7fc5 Mon Sep 17 00:00:00 2001 From: Yuuichi Asahi Date: Sat, 6 Jul 2024 16:32:10 +0900 Subject: [PATCH 2/7] Rename: unuse under score in Transform functions --- fft/src/KokkosFFT_Cuda_transform.hpp | 24 +++++++++---------- fft/src/KokkosFFT_HIP_transform.hpp | 24 +++++++++---------- fft/src/KokkosFFT_Host_transform.hpp | 24 +++++++++---------- fft/src/KokkosFFT_ROCM_transform.hpp | 36 ++++++++++++++-------------- fft/src/KokkosFFT_SYCL_transform.hpp | 24 +++++++++---------- fft/src/KokkosFFT_Transform.hpp | 2 +- 6 files changed, 67 insertions(+), 67 deletions(-) diff --git a/fft/src/KokkosFFT_Cuda_transform.hpp b/fft/src/KokkosFFT_Cuda_transform.hpp index 2072fd7..8878039 100644 --- a/fft/src/KokkosFFT_Cuda_transform.hpp +++ b/fft/src/KokkosFFT_Cuda_transform.hpp @@ -10,48 +10,48 @@ namespace KokkosFFT { namespace Impl { template -inline void _exec(cufftHandle& plan, cufftReal* idata, cufftComplex* odata, - int /*direction*/, Args...) { +inline void exec_plan(cufftHandle& plan, cufftReal* idata, cufftComplex* odata, + int /*direction*/, Args...) { cufftResult cufft_rt = cufftExecR2C(plan, idata, odata); if (cufft_rt != CUFFT_SUCCESS) throw std::runtime_error("cufftExecR2C failed"); } template -inline void _exec(cufftHandle& plan, cufftDoubleReal* idata, - cufftDoubleComplex* odata, int /*direction*/, Args...) { +inline void exec_plan(cufftHandle& plan, cufftDoubleReal* idata, + cufftDoubleComplex* odata, int /*direction*/, Args...) { cufftResult cufft_rt = cufftExecD2Z(plan, idata, odata); if (cufft_rt != CUFFT_SUCCESS) throw std::runtime_error("cufftExecD2Z failed"); } template -inline void _exec(cufftHandle& plan, cufftComplex* idata, cufftReal* odata, - int /*direction*/, Args...) { +inline void exec_plan(cufftHandle& plan, cufftComplex* idata, cufftReal* odata, + int /*direction*/, Args...) { cufftResult cufft_rt = cufftExecC2R(plan, idata, odata); if (cufft_rt != CUFFT_SUCCESS) throw std::runtime_error("cufftExecC2R failed"); } template -inline void _exec(cufftHandle& plan, cufftDoubleComplex* idata, - cufftDoubleReal* odata, int /*direction*/, Args...) { +inline void exec_plan(cufftHandle& plan, cufftDoubleComplex* idata, + cufftDoubleReal* odata, int /*direction*/, Args...) { cufftResult cufft_rt = cufftExecZ2D(plan, idata, odata); if (cufft_rt != CUFFT_SUCCESS) throw std::runtime_error("cufftExecZ2D failed"); } template -inline void _exec(cufftHandle& plan, cufftComplex* idata, cufftComplex* odata, - int direction, Args...) { +inline void exec_plan(cufftHandle& plan, cufftComplex* idata, + cufftComplex* odata, int direction, Args...) { cufftResult cufft_rt = cufftExecC2C(plan, idata, odata, direction); if (cufft_rt != CUFFT_SUCCESS) throw std::runtime_error("cufftExecC2C failed"); } template -inline void _exec(cufftHandle& plan, cufftDoubleComplex* idata, - cufftDoubleComplex* odata, int direction, Args...) { +inline void exec_plan(cufftHandle& plan, cufftDoubleComplex* idata, + cufftDoubleComplex* odata, int direction, Args...) { cufftResult cufft_rt = cufftExecZ2Z(plan, idata, odata, direction); if (cufft_rt != CUFFT_SUCCESS) throw std::runtime_error("cufftExecZ2Z failed"); diff --git a/fft/src/KokkosFFT_HIP_transform.hpp b/fft/src/KokkosFFT_HIP_transform.hpp index 62ab520..8102df4 100644 --- a/fft/src/KokkosFFT_HIP_transform.hpp +++ b/fft/src/KokkosFFT_HIP_transform.hpp @@ -10,48 +10,48 @@ namespace KokkosFFT { namespace Impl { template -inline void _exec(hipfftHandle& plan, hipfftReal* idata, hipfftComplex* odata, - int /*direction*/, Args...) { +inline void exec_plan(hipfftHandle& plan, hipfftReal* idata, + hipfftComplex* odata, int /*direction*/, Args...) { hipfftResult hipfft_rt = hipfftExecR2C(plan, idata, odata); if (hipfft_rt != HIPFFT_SUCCESS) throw std::runtime_error("hipfftExecR2C failed"); } template -inline void _exec(hipfftHandle& plan, hipfftDoubleReal* idata, - hipfftDoubleComplex* odata, int /*direction*/, Args...) { +inline void exec_plan(hipfftHandle& plan, hipfftDoubleReal* idata, + hipfftDoubleComplex* odata, int /*direction*/, Args...) { hipfftResult hipfft_rt = hipfftExecD2Z(plan, idata, odata); if (hipfft_rt != HIPFFT_SUCCESS) throw std::runtime_error("hipfftExecD2Z failed"); } template -inline void _exec(hipfftHandle& plan, hipfftComplex* idata, hipfftReal* odata, - int /*direction*/, Args...) { +inline void exec_plan(hipfftHandle& plan, hipfftComplex* idata, + hipfftReal* odata, int /*direction*/, Args...) { hipfftResult hipfft_rt = hipfftExecC2R(plan, idata, odata); if (hipfft_rt != HIPFFT_SUCCESS) throw std::runtime_error("hipfftExecC2R failed"); } template -inline void _exec(hipfftHandle& plan, hipfftDoubleComplex* idata, - hipfftDoubleReal* odata, int /*direction*/, Args...) { +inline void exec_plan(hipfftHandle& plan, hipfftDoubleComplex* idata, + hipfftDoubleReal* odata, int /*direction*/, Args...) { hipfftResult hipfft_rt = hipfftExecZ2D(plan, idata, odata); if (hipfft_rt != HIPFFT_SUCCESS) throw std::runtime_error("hipfftExecZ2D failed"); } template -inline void _exec(hipfftHandle& plan, hipfftComplex* idata, - hipfftComplex* odata, int direction, Args...) { +inline void exec_plan(hipfftHandle& plan, hipfftComplex* idata, + hipfftComplex* odata, int direction, Args...) { hipfftResult hipfft_rt = hipfftExecC2C(plan, idata, odata, direction); if (hipfft_rt != HIPFFT_SUCCESS) throw std::runtime_error("hipfftExecC2C failed"); } template -inline void _exec(hipfftHandle& plan, hipfftDoubleComplex* idata, - hipfftDoubleComplex* odata, int direction, Args...) { +inline void exec_plan(hipfftHandle& plan, hipfftDoubleComplex* idata, + hipfftDoubleComplex* odata, int direction, Args...) { hipfftResult hipfft_rt = hipfftExecZ2Z(plan, idata, odata, direction); if (hipfft_rt != HIPFFT_SUCCESS) throw std::runtime_error("hipfftExecZ2Z failed"); diff --git a/fft/src/KokkosFFT_Host_transform.hpp b/fft/src/KokkosFFT_Host_transform.hpp index a47243a..094bb0a 100644 --- a/fft/src/KokkosFFT_Host_transform.hpp +++ b/fft/src/KokkosFFT_Host_transform.hpp @@ -10,38 +10,38 @@ namespace KokkosFFT { namespace Impl { template -void _exec(PlanType& plan, float* idata, fftwf_complex* odata, - int /*direction*/, Args...) { +void exec_plan(PlanType& plan, float* idata, fftwf_complex* odata, + int /*direction*/, Args...) { fftwf_execute_dft_r2c(plan, idata, odata); } template -void _exec(PlanType& plan, double* idata, fftw_complex* odata, - int /*direction*/, Args...) { +void exec_plan(PlanType& plan, double* idata, fftw_complex* odata, + int /*direction*/, Args...) { fftw_execute_dft_r2c(plan, idata, odata); } template -void _exec(PlanType& plan, fftwf_complex* idata, float* odata, - int /*direction*/, Args...) { +void exec_plan(PlanType& plan, fftwf_complex* idata, float* odata, + int /*direction*/, Args...) { fftwf_execute_dft_c2r(plan, idata, odata); } template -void _exec(PlanType& plan, fftw_complex* idata, double* odata, - int /*direction*/, Args...) { +void exec_plan(PlanType& plan, fftw_complex* idata, double* odata, + int /*direction*/, Args...) { fftw_execute_dft_c2r(plan, idata, odata); } template -void _exec(PlanType& plan, fftwf_complex* idata, fftwf_complex* odata, - int /*direction*/, Args...) { +void exec_plan(PlanType& plan, fftwf_complex* idata, fftwf_complex* odata, + int /*direction*/, Args...) { fftwf_execute_dft(plan, idata, odata); } template -void _exec(PlanType plan, fftw_complex* idata, fftw_complex* odata, - int /*direction*/, Args...) { +void exec_plan(PlanType plan, fftw_complex* idata, fftw_complex* odata, + int /*direction*/, Args...) { fftw_execute_dft(plan, idata, odata); } } // namespace Impl diff --git a/fft/src/KokkosFFT_ROCM_transform.hpp b/fft/src/KokkosFFT_ROCM_transform.hpp index 4dfbc75..5c177d6 100644 --- a/fft/src/KokkosFFT_ROCM_transform.hpp +++ b/fft/src/KokkosFFT_ROCM_transform.hpp @@ -10,54 +10,54 @@ namespace KokkosFFT { namespace Impl { -inline void _exec(rocfft_plan& plan, float* idata, std::complex* odata, - int /*direction*/, - const rocfft_execution_info& execution_info) { +inline void exec_plan(rocfft_plan& plan, float* idata, + std::complex* odata, int /*direction*/, + const rocfft_execution_info& execution_info) { rocfft_status status = rocfft_execute(plan, (void**)&idata, (void**)&odata, execution_info); if (status != rocfft_status_success) throw std::runtime_error("rocfft_execute for R2C failed"); } -inline void _exec(rocfft_plan& plan, double* idata, std::complex* odata, - int /*direction*/, - const rocfft_execution_info& execution_info) { +inline void exec_plan(rocfft_plan& plan, double* idata, + std::complex* odata, int /*direction*/, + const rocfft_execution_info& execution_info) { rocfft_status status = rocfft_execute(plan, (void**)&idata, (void**)&odata, execution_info); if (status != rocfft_status_success) throw std::runtime_error("rocfft_execute for D2Z failed"); } -inline void _exec(rocfft_plan& plan, std::complex* idata, float* odata, - int /*direction*/, - const rocfft_execution_info& execution_info) { +inline void exec_plan(rocfft_plan& plan, std::complex* idata, + float* odata, int /*direction*/, + const rocfft_execution_info& execution_info) { rocfft_status status = rocfft_execute(plan, (void**)&idata, (void**)&odata, execution_info); if (status != rocfft_status_success) throw std::runtime_error("rocfft_execute for C2R failed"); } -inline void _exec(rocfft_plan& plan, std::complex* idata, double* odata, - int /*direction*/, - const rocfft_execution_info& execution_info) { +inline void exec_plan(rocfft_plan& plan, std::complex* idata, + double* odata, int /*direction*/, + const rocfft_execution_info& execution_info) { rocfft_status status = rocfft_execute(plan, (void**)&idata, (void**)&odata, execution_info); if (status != rocfft_status_success) throw std::runtime_error("rocfft_execute for Z2D failed"); } -inline void _exec(rocfft_plan& plan, std::complex* idata, - std::complex* odata, int /*direction*/, - const rocfft_execution_info& execution_info) { +inline void exec_plan(rocfft_plan& plan, std::complex* idata, + std::complex* odata, int /*direction*/, + const rocfft_execution_info& execution_info) { rocfft_status status = rocfft_execute(plan, (void**)&idata, (void**)&odata, execution_info); if (status != rocfft_status_success) throw std::runtime_error("rocfft_execute for C2C failed"); } -inline void _exec(rocfft_plan& plan, std::complex* idata, - std::complex* odata, int /*direction*/, - const rocfft_execution_info& execution_info) { +inline void exec_plan(rocfft_plan& plan, std::complex* idata, + std::complex* odata, int /*direction*/, + const rocfft_execution_info& execution_info) { rocfft_status status = rocfft_execute(plan, (void**)&idata, (void**)&odata, execution_info); if (status != rocfft_status_success) diff --git a/fft/src/KokkosFFT_SYCL_transform.hpp b/fft/src/KokkosFFT_SYCL_transform.hpp index 7575bf4..5cff1c1 100644 --- a/fft/src/KokkosFFT_SYCL_transform.hpp +++ b/fft/src/KokkosFFT_SYCL_transform.hpp @@ -11,36 +11,36 @@ namespace KokkosFFT { namespace Impl { template -void _exec(PlanType& plan, float* idata, std::complex* odata, - int /*direction*/, Args...) { +void exec_plan(PlanType& plan, float* idata, std::complex* odata, + int /*direction*/, Args...) { oneapi::mkl::dft::compute_forward(plan, idata, reinterpret_cast(odata)); } template -void _exec(PlanType& plan, double* idata, std::complex* odata, - int /*direction*/, Args...) { +void exec_plan(PlanType& plan, double* idata, std::complex* odata, + int /*direction*/, Args...) { oneapi::mkl::dft::compute_forward(plan, idata, reinterpret_cast(odata)); } template -void _exec(PlanType& plan, std::complex* idata, float* odata, - int /*direction*/, Args...) { +void exec_plan(PlanType& plan, std::complex* idata, float* odata, + int /*direction*/, Args...) { oneapi::mkl::dft::compute_backward(plan, reinterpret_cast(idata), odata); } template -void _exec(PlanType& plan, std::complex* idata, double* odata, - int /*direction*/, Args...) { +void exec_plan(PlanType& plan, std::complex* idata, double* odata, + int /*direction*/, Args...) { oneapi::mkl::dft::compute_backward(plan, reinterpret_cast(idata), odata); } template -void _exec(PlanType& plan, std::complex* idata, - std::complex* odata, int direction, Args...) { +void exec_plan(PlanType& plan, std::complex* idata, + std::complex* odata, int direction, Args...) { if (direction == 1) { oneapi::mkl::dft::compute_forward(plan, idata, odata); } else { @@ -49,8 +49,8 @@ void _exec(PlanType& plan, std::complex* idata, } template -void _exec(PlanType& plan, std::complex* idata, - std::complex* odata, int direction, Args...) { +void exec_plan(PlanType& plan, std::complex* idata, + std::complex* odata, int direction, Args...) { if (direction == 1) { oneapi::mkl::dft::compute_forward(plan, idata, odata); } else { diff --git a/fft/src/KokkosFFT_Transform.hpp b/fft/src/KokkosFFT_Transform.hpp index 9aeafee..6cf80d7 100644 --- a/fft/src/KokkosFFT_Transform.hpp +++ b/fft/src/KokkosFFT_Transform.hpp @@ -89,7 +89,7 @@ void exec_impl( auto const exec_space = plan.exec_space(); auto const direction = direction_type(plan.direction()); - KokkosFFT::Impl::_exec(plan.plan(), idata, odata, direction, plan.info()); + KokkosFFT::Impl::exec_plan(plan.plan(), idata, odata, direction, plan.info()); KokkosFFT::Impl::normalize(exec_space, out, plan.direction(), norm, plan.fft_size()); } From a7632746e37f3e3ce16bebb44264adf6680ce562 Mon Sep 17 00:00:00 2001 From: Yuuichi Asahi Date: Sat, 6 Jul 2024 16:36:42 +0900 Subject: [PATCH 3/7] Rename: unuse under score in util functions --- common/src/KokkosFFT_normalization.hpp | 12 ++-- common/src/KokkosFFT_padding.hpp | 38 ++++++----- common/src/KokkosFFT_transpose.hpp | 64 +++++++++---------- common/unit_test/Test_prep_transpose_view.cpp | 10 +-- 4 files changed, 59 insertions(+), 65 deletions(-) diff --git a/common/src/KokkosFFT_normalization.hpp b/common/src/KokkosFFT_normalization.hpp index 48a2a27..90f6ef6 100644 --- a/common/src/KokkosFFT_normalization.hpp +++ b/common/src/KokkosFFT_normalization.hpp @@ -12,8 +12,8 @@ namespace KokkosFFT { namespace Impl { template -void _normalize(const ExecutionSpace& exec_space, ViewType& inout, - const T coef) { +void normalize_impl(const ExecutionSpace& exec_space, ViewType& inout, + const T coef) { std::size_t size = inout.size(); auto* data = inout.data(); @@ -24,8 +24,8 @@ void _normalize(const ExecutionSpace& exec_space, ViewType& inout, } template -auto _coefficients(ViewType, Direction direction, Normalization normalization, - std::size_t fft_size) { +auto coefficients_impl(ViewType, Direction direction, + Normalization normalization, std::size_t fft_size) { using value_type = KokkosFFT::Impl::real_type_t; value_type coef = 1; @@ -63,8 +63,8 @@ void normalize(const ExecutionSpace& exec_space, ViewType& inout, Direction direction, Normalization normalization, std::size_t fft_size) { auto [coef, to_normalize] = - _coefficients(inout, direction, normalization, fft_size); - if (to_normalize) _normalize(exec_space, inout, coef); + coefficients_impl(inout, direction, normalization, fft_size); + if (to_normalize) normalize_impl(exec_space, inout, coef); } inline auto swap_direction(Normalization normalization) { diff --git a/common/src/KokkosFFT_padding.hpp b/common/src/KokkosFFT_padding.hpp index d69a9f4..6889ddb 100644 --- a/common/src/KokkosFFT_padding.hpp +++ b/common/src/KokkosFFT_padding.hpp @@ -88,10 +88,8 @@ auto is_crop_or_pad_needed(const ViewType& view, "is_crop_or_pad_needed: Rank of View must be equal to Rank " "of extended shape."); - // [TO DO] Add a is_C2R arg. If is_C2R is true, then shape should be shape/2+1 constexpr int rank = static_cast(ViewType::rank()); - - bool not_same = false; + bool not_same = false; for (int i = 0; i < rank; i++) { if (modified_shape.at(i) != view.extent(i)) { not_same = true; @@ -103,8 +101,8 @@ auto is_crop_or_pad_needed(const ViewType& view, } template -void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in, - OutViewType& out, shape_type<1> s) { +void crop_or_pad_impl(const ExecutionSpace& exec_space, const InViewType& in, + OutViewType& out, shape_type<1> s) { auto _n0 = s.at(0); out = OutViewType("out", _n0); @@ -117,8 +115,8 @@ void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in, } template -void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in, - OutViewType& out, shape_type<2> s) { +void crop_or_pad_impl(const ExecutionSpace& exec_space, const InViewType& in, + OutViewType& out, shape_type<2> s) { constexpr std::size_t DIM = 2; auto [_n0, _n1] = s; @@ -143,8 +141,8 @@ void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in, } template -void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in, - OutViewType& out, shape_type<3> s) { +void crop_or_pad_impl(const ExecutionSpace& exec_space, const InViewType& in, + OutViewType& out, shape_type<3> s) { constexpr std::size_t DIM = 3; auto [_n0, _n1, _n2] = s; @@ -172,8 +170,8 @@ void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in, } template -void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in, - OutViewType& out, shape_type<4> s) { +void crop_or_pad_impl(const ExecutionSpace& exec_space, const InViewType& in, + OutViewType& out, shape_type<4> s) { constexpr std::size_t DIM = 4; auto [_n0, _n1, _n2, _n3] = s; @@ -202,8 +200,8 @@ void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in, } template -void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in, - OutViewType& out, shape_type<5> s) { +void crop_or_pad_impl(const ExecutionSpace& exec_space, const InViewType& in, + OutViewType& out, shape_type<5> s) { constexpr std::size_t DIM = 5; auto [_n0, _n1, _n2, _n3, _n4] = s; @@ -233,8 +231,8 @@ void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in, } template -void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in, - OutViewType& out, shape_type<6> s) { +void crop_or_pad_impl(const ExecutionSpace& exec_space, const InViewType& in, + OutViewType& out, shape_type<6> s) { constexpr std::size_t DIM = 6; auto [_n0, _n1, _n2, _n3, _n4, _n5] = s; @@ -266,8 +264,8 @@ void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in, } template -void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in, - OutViewType& out, shape_type<7> s) { +void crop_or_pad_impl(const ExecutionSpace& exec_space, const InViewType& in, + OutViewType& out, shape_type<7> s) { constexpr std::size_t DIM = 6; auto [_n0, _n1, _n2, _n3, _n4, _n5, _n6] = s; @@ -302,8 +300,8 @@ void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in, } template -void _crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in, - OutViewType& out, shape_type<8> s) { +void crop_or_pad_impl(const ExecutionSpace& exec_space, const InViewType& in, + OutViewType& out, shape_type<8> s) { constexpr std::size_t DIM = 6; auto [_n0, _n1, _n2, _n3, _n4, _n5, _n6, _n7] = s; @@ -351,7 +349,7 @@ void crop_or_pad(const ExecutionSpace& exec_space, const InViewType& in, static_assert(OutViewType::rank() == DIM, "crop_or_pad: Rank of View must be equal to Rank " "of extended shape."); - _crop_or_pad(exec_space, in, out, s); + crop_or_pad_impl(exec_space, in, out, s); } } // namespace Impl } // namespace KokkosFFT diff --git a/common/src/KokkosFFT_transpose.hpp b/common/src/KokkosFFT_transpose.hpp index a9b3b86..d74e03c 100644 --- a/common/src/KokkosFFT_transpose.hpp +++ b/common/src/KokkosFFT_transpose.hpp @@ -87,15 +87,15 @@ auto get_map_axes(const ViewType& view, int axis) { } template -void _prep_transpose_view(InViewType& in, OutViewType& out, - axis_type _map) { +void prep_transpose_view(InViewType& in, OutViewType& out, + axis_type map) { constexpr int rank = OutViewType::rank(); // Assign a View if not a shallow copy bool is_out_view_ready = true; std::array out_extents; for (int i = 0; i < rank; i++) { - out_extents.at(i) = in.extent(_map.at(i)); + out_extents.at(i) = in.extent(map.at(i)); if (static_cast(out_extents.at(i)) != out.extent(i)) { is_out_view_ready = false; } @@ -111,16 +111,9 @@ void _prep_transpose_view(InViewType& in, OutViewType& out, } } -template = nullptr> -void _transpose(const ExecutionSpace&, InViewType&, OutViewType&, - axis_type<1>) { - // FIXME: Comment why empty? -} - template -void _transpose(const ExecutionSpace& exec_space, InViewType& in, - OutViewType& out, axis_type<2> _map) { +void transpose_impl(const ExecutionSpace& exec_space, InViewType& in, + OutViewType& out, axis_type<2> _map) { constexpr std::size_t DIM = 2; using range_type = Kokkos::MDRangePolicy< @@ -136,15 +129,15 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in, // [TO DO] Choose optimal tile sizes for each device ); - _prep_transpose_view(in, out, _map); + prep_transpose_view(in, out, _map); Kokkos::parallel_for( range, KOKKOS_LAMBDA(int i0, int i1) { out(i1, i0) = in(i0, i1); }); } template -void _transpose(const ExecutionSpace& exec_space, InViewType& in, - OutViewType& out, axis_type<3> _map) { +void transpose_impl(const ExecutionSpace& exec_space, InViewType& in, + OutViewType& out, axis_type<3> _map) { constexpr std::size_t DIM = 3; constexpr std::size_t rank = InViewType::rank(); @@ -161,7 +154,7 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in, tile_type{{4, 4, 4}} // [TO DO] Choose optimal tile sizes for each device ); - _prep_transpose_view(in, out, _map); + prep_transpose_view(in, out, _map); Kokkos::Array map = {_map[0], _map[1], _map[2]}; Kokkos::parallel_for( @@ -176,8 +169,8 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in, } template -void _transpose(const ExecutionSpace& exec_space, InViewType& in, - OutViewType& out, axis_type<4> _map) { +void transpose_impl(const ExecutionSpace& exec_space, InViewType& in, + OutViewType& out, axis_type<4> _map) { constexpr std::size_t DIM = 4; constexpr std::size_t rank = InViewType::rank(); @@ -195,7 +188,7 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in, // [TO DO] Choose optimal tile sizes for each device ); - _prep_transpose_view(in, out, _map); + prep_transpose_view(in, out, _map); Kokkos::Array map = {_map[0], _map[1], _map[2], _map[3]}; Kokkos::parallel_for( @@ -211,8 +204,8 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in, } template -void _transpose(const ExecutionSpace& exec_space, InViewType& in, - OutViewType& out, axis_type<5> _map) { +void transpose_impl(const ExecutionSpace& exec_space, InViewType& in, + OutViewType& out, axis_type<5> _map) { constexpr std::size_t DIM = 5; constexpr std::size_t rank = InViewType::rank(); @@ -231,7 +224,7 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in, // [TO DO] Choose optimal tile sizes for each device ); - _prep_transpose_view(in, out, _map); + prep_transpose_view(in, out, _map); Kokkos::Array map = {_map[0], _map[1], _map[2], _map[3], _map[4]}; Kokkos::parallel_for( @@ -248,8 +241,8 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in, } template -void _transpose(const ExecutionSpace& exec_space, InViewType& in, - OutViewType& out, axis_type<6> _map) { +void transpose_impl(const ExecutionSpace& exec_space, InViewType& in, + OutViewType& out, axis_type<6> _map) { constexpr std::size_t DIM = 6; constexpr std::size_t rank = InViewType::rank(); @@ -269,7 +262,7 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in, // [TO DO] Choose optimal tile sizes for each device ); - _prep_transpose_view(in, out, _map); + prep_transpose_view(in, out, _map); Kokkos::Array map = {_map[0], _map[1], _map[2], _map[3], _map[4], _map[5]}; @@ -288,8 +281,8 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in, } template -void _transpose(const ExecutionSpace& exec_space, InViewType& in, - OutViewType& out, axis_type<7> _map) { +void transpose_impl(const ExecutionSpace& exec_space, InViewType& in, + OutViewType& out, axis_type<7> _map) { constexpr std::size_t DIM = 6; constexpr std::size_t rank = InViewType::rank(); @@ -309,7 +302,7 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in, // [TO DO] Choose optimal tile sizes for each device ); - _prep_transpose_view(in, out, _map); + prep_transpose_view(in, out, _map); Kokkos::Array map = {_map[0], _map[1], _map[2], _map[3], _map[4], _map[5], _map[6]}; @@ -332,8 +325,8 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in, } template -void _transpose(const ExecutionSpace& exec_space, InViewType& in, - OutViewType& out, axis_type<8> _map) { +void transpose_impl(const ExecutionSpace& exec_space, InViewType& in, + OutViewType& out, axis_type<8> _map) { constexpr std::size_t DIM = 6; constexpr std::size_t rank = InViewType::rank(); @@ -355,7 +348,7 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in, // [TO DO] Choose optimal tile sizes for each device ); - _prep_transpose_view(in, out, _map); + prep_transpose_view(in, out, _map); Kokkos::Array map = {_map[0], _map[1], _map[2], _map[3], _map[4], _map[5], _map[6], _map[7]}; @@ -402,7 +395,7 @@ void _transpose(const ExecutionSpace& exec_space, InViewType& in, template void transpose(const ExecutionSpace& exec_space, InViewType& in, - OutViewType& out, axis_type _map) { + OutViewType& out, axis_type map) { static_assert(Kokkos::is_view::value, "transpose: InViewType is not a Kokkos::View."); static_assert(Kokkos::is_view::value, @@ -416,11 +409,14 @@ void transpose(const ExecutionSpace& exec_space, InViewType& in, "transpose: Rank of View must be equal to Rank of " "transpose axes."); - if (!KokkosFFT::Impl::is_transpose_needed(_map)) { + if (!KokkosFFT::Impl::is_transpose_needed(map)) { throw std::runtime_error("transpose: transpose not necessary"); } - _transpose(exec_space, in, out, _map); + // in order not to call transpose_impl for 1D case + if constexpr (DIM > 1) { + transpose_impl(exec_space, in, out, map); + } } } // namespace Impl } // namespace KokkosFFT diff --git a/common/unit_test/Test_prep_transpose_view.cpp b/common/unit_test/Test_prep_transpose_view.cpp index fb6136a..3348c91 100644 --- a/common/unit_test/Test_prep_transpose_view.cpp +++ b/common/unit_test/Test_prep_transpose_view.cpp @@ -42,7 +42,7 @@ void test_managed_prep_transpose_view() { InViewType in("in", layout); OutViewType out("out", layout); auto data_prev = out.data(); - KokkosFFT::Impl::_prep_transpose_view(in, out, map); + KokkosFFT::Impl::prep_transpose_view(in, out, map); // ensure no allocation EXPECT_EQ(data_prev, out.data()); // check shape @@ -60,7 +60,7 @@ void test_managed_prep_transpose_view() { } InViewType in("in", layout); OutViewType out; - KokkosFFT::Impl::_prep_transpose_view(in, out, map); + KokkosFFT::Impl::prep_transpose_view(in, out, map); // check shape for (int i = 0; i < DIMS; ++i) { EXPECT_EQ(out.extent(i), 5); @@ -96,7 +96,7 @@ void test_unmanaged_prep_transpose_view() { OutManagedViewType out("out", layout); OutViewType u_out(out.data(), layout); auto data_prev = out.data(); - KokkosFFT::Impl::_prep_transpose_view(in, u_out, map); + KokkosFFT::Impl::prep_transpose_view(in, u_out, map); EXPECT_EQ(data_prev, u_out.data()); // check shape for (int i = 0; i < DIMS; ++i) { @@ -126,7 +126,7 @@ void test_unmanaged_prep_transpose_view() { InManagedViewType in("in", layout); OutManagedViewType out("out", layout_orig); OutViewType u_out(out.data(), layout_orig); - KokkosFFT::Impl::_prep_transpose_view(in, u_out, map); + KokkosFFT::Impl::prep_transpose_view(in, u_out, map); // check shape for (int i = 0; i < DIMS; ++i) { EXPECT_EQ(u_out.extent(i), 5); @@ -148,7 +148,7 @@ void test_unmanaged_prep_transpose_view() { InManagedViewType in("in", layout); OutManagedViewType out("out", layout_orig); OutViewType u_out(out.data(), layout_orig); - EXPECT_THROW(KokkosFFT::Impl::_prep_transpose_view(in, u_out, map), + EXPECT_THROW(KokkosFFT::Impl::prep_transpose_view(in, u_out, map), std::runtime_error); } } From 52aa591346325848476c97e5e3501516d2cb69f1 Mon Sep 17 00:00:00 2001 From: Yuuichi Asahi Date: Sat, 6 Jul 2024 17:23:43 +0900 Subject: [PATCH 4/7] Rename: unuse under score in helper functions --- common/src/KokkosFFT_Helpers.hpp | 61 ++++++++++++++++---------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/common/src/KokkosFFT_Helpers.hpp b/common/src/KokkosFFT_Helpers.hpp index 2ab751c..4f53ef7 100644 --- a/common/src/KokkosFFT_Helpers.hpp +++ b/common/src/KokkosFFT_Helpers.hpp @@ -12,10 +12,9 @@ namespace KokkosFFT { namespace Impl { template -auto _get_shift(const ViewType& inout, axis_type _axes, - int direction = 1) { +auto get_shift(const ViewType& inout, axis_type _axes, int direction = 1) { static_assert(DIM > 0, - "_get_shift: Rank of shift axes must be " + "get_shift: Rank of shift axes must be " "larger than or equal to 1."); // Convert the input axes to be in the range of [0, rank-1] @@ -39,10 +38,10 @@ auto _get_shift(const ViewType& inout, axis_type _axes, } template -void _roll(const ExecutionSpace& exec_space, ViewType& inout, - axis_type<1> shift, axis_type<1>) { +void roll_impl(const ExecutionSpace& exec_space, ViewType& inout, + axis_type<1> shift, axis_type<1>) { // Last parameter is ignored but present for keeping the interface consistent - static_assert(ViewType::rank() == 1, "_roll: Rank of View must be 1."); + static_assert(ViewType::rank() == 1, "roll_impl: Rank of View must be 1."); std::size_t n0 = inout.extent(0); ViewType tmp("tmp", n0); @@ -69,10 +68,10 @@ void _roll(const ExecutionSpace& exec_space, ViewType& inout, } template -void _roll(const ExecutionSpace& exec_space, ViewType& inout, - axis_type<2> shift, axis_type axes) { +void roll_impl(const ExecutionSpace& exec_space, ViewType& inout, + axis_type<2> shift, axis_type axes) { constexpr int DIM0 = 2; - static_assert(ViewType::rank() == DIM0, "_roll: Rank of View must be 2."); + static_assert(ViewType::rank() == DIM0, "roll_impl: Rank of View must be 2."); int n0 = inout.extent(0), n1 = inout.extent(1); ViewType tmp("tmp", n0, n1); @@ -130,43 +129,43 @@ void _roll(const ExecutionSpace& exec_space, ViewType& inout, } template -void _fftshift(const ExecutionSpace& exec_space, ViewType& inout, - axis_type axes) { +void fftshift_impl(const ExecutionSpace& exec_space, ViewType& inout, + axis_type axes) { static_assert(Kokkos::is_view::value, - "_fftshift: ViewType is not a Kokkos::View."); + "fftshift_impl: ViewType is not a Kokkos::View."); static_assert( KokkosFFT::Impl::is_layout_left_or_right_v, - "_fftshift: ViewType must be either LayoutLeft or LayoutRight."); + "fftshift_impl: ViewType must be either LayoutLeft or LayoutRight."); static_assert( Kokkos::SpaceAccessibility::accessible, - "_fftshift: execution_space cannot access data in ViewType"); + "fftshift_impl: execution_space cannot access data in ViewType"); static_assert(ViewType::rank() >= DIM, - "_fftshift: Rank of View must be larger thane " + "fftshift_impl: Rank of View must be larger thane " "or equal to the Rank of shift axes."); - auto shift = _get_shift(inout, axes); - _roll(exec_space, inout, shift, axes); + auto shift = get_shift(inout, axes); + roll_impl(exec_space, inout, shift, axes); } template -void _ifftshift(const ExecutionSpace& exec_space, ViewType& inout, - axis_type axes) { +void ifftshift_impl(const ExecutionSpace& exec_space, ViewType& inout, + axis_type axes) { static_assert(Kokkos::is_view::value, - "_ifftshift: ViewType is not a Kokkos::View."); + "ifftshift_impl: ViewType is not a Kokkos::View."); static_assert( KokkosFFT::Impl::is_layout_left_or_right_v, - "_ifftshift: ViewType must be either LayoutLeft or LayoutRight."); + "ifftshift_impl: ViewType must be either LayoutLeft or LayoutRight."); static_assert( Kokkos::SpaceAccessibility::accessible, - "_ifftshift: execution_space cannot access data in ViewType"); + "ifftshift_impl: execution_space cannot access data in ViewType"); static_assert(ViewType::rank() >= DIM, - "_ifftshift: Rank of View must be larger " + "ifftshift_impl: Rank of View must be larger " "thane or equal to the Rank of shift axes."); - auto shift = _get_shift(inout, axes, -1); - _roll(exec_space, inout, shift, axes); + auto shift = get_shift(inout, axes, -1); + roll_impl(exec_space, inout, shift, axes); } } // namespace Impl } // namespace KokkosFFT @@ -246,12 +245,12 @@ void fftshift(const ExecutionSpace& exec_space, ViewType& inout, std::optional axes = std::nullopt) { if (axes) { axis_type<1> _axes{axes.value()}; - KokkosFFT::Impl::_fftshift(exec_space, inout, _axes); + KokkosFFT::Impl::fftshift_impl(exec_space, inout, _axes); } else { constexpr std::size_t rank = ViewType::rank(); constexpr int start = -static_cast(rank); axis_type _axes = KokkosFFT::Impl::index_sequence(start); - KokkosFFT::Impl::_fftshift(exec_space, inout, _axes); + KokkosFFT::Impl::fftshift_impl(exec_space, inout, _axes); } } @@ -263,7 +262,7 @@ void fftshift(const ExecutionSpace& exec_space, ViewType& inout, template void fftshift(const ExecutionSpace& exec_space, ViewType& inout, axis_type axes) { - KokkosFFT::Impl::_fftshift(exec_space, inout, axes); + KokkosFFT::Impl::fftshift_impl(exec_space, inout, axes); } /// \brief The inverse of fftshift @@ -276,12 +275,12 @@ void ifftshift(const ExecutionSpace& exec_space, ViewType& inout, std::optional axes = std::nullopt) { if (axes) { axis_type<1> _axes{axes.value()}; - KokkosFFT::Impl::_ifftshift(exec_space, inout, _axes); + KokkosFFT::Impl::ifftshift_impl(exec_space, inout, _axes); } else { constexpr std::size_t rank = ViewType::rank(); constexpr int start = -static_cast(rank); axis_type _axes = KokkosFFT::Impl::index_sequence(start); - KokkosFFT::Impl::_ifftshift(exec_space, inout, _axes); + KokkosFFT::Impl::ifftshift_impl(exec_space, inout, _axes); } } @@ -293,7 +292,7 @@ void ifftshift(const ExecutionSpace& exec_space, ViewType& inout, template void ifftshift(const ExecutionSpace& exec_space, ViewType& inout, axis_type axes) { - KokkosFFT::Impl::_ifftshift(exec_space, inout, axes); + KokkosFFT::Impl::ifftshift_impl(exec_space, inout, axes); } } // namespace KokkosFFT From 9ced14584d8973d24444f498893b53763dfdb03a Mon Sep 17 00:00:00 2001 From: Yuuichi Asahi Date: Sat, 6 Jul 2024 17:30:24 +0900 Subject: [PATCH 5/7] update _get_shift to get_shift --- common/unit_test/Test_Helpers.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/common/unit_test/Test_Helpers.cpp b/common/unit_test/Test_Helpers.cpp index bb818e3..60a0576 100644 --- a/common/unit_test/Test_Helpers.cpp +++ b/common/unit_test/Test_Helpers.cpp @@ -154,21 +154,21 @@ void test_get_shift(int direction) { KokkosFFT::axis_type<2> shift2_even_ref = {direction * n_even / 2, direction * n2 / 2}; - auto shift1_odd = KokkosFFT::Impl::_get_shift( + auto shift1_odd = KokkosFFT::Impl::get_shift( x1_odd, KokkosFFT::axis_type<1>({0}), direction); - auto shift1_even = KokkosFFT::Impl::_get_shift( + auto shift1_even = KokkosFFT::Impl::get_shift( x1_even, KokkosFFT::axis_type<1>({0}), direction); - auto shift1_axis0_odd = KokkosFFT::Impl::_get_shift( + auto shift1_axis0_odd = KokkosFFT::Impl::get_shift( x2_odd, KokkosFFT::axis_type<1>({0}), direction); - auto shift1_axis0_even = KokkosFFT::Impl::_get_shift( + auto shift1_axis0_even = KokkosFFT::Impl::get_shift( x2_even, KokkosFFT::axis_type<1>({0}), direction); - auto shift1_axis1_odd = KokkosFFT::Impl::_get_shift( + auto shift1_axis1_odd = KokkosFFT::Impl::get_shift( x2_odd, KokkosFFT::axis_type<1>({1}), direction); - auto shift1_axis1_even = KokkosFFT::Impl::_get_shift( + auto shift1_axis1_even = KokkosFFT::Impl::get_shift( x2_even, KokkosFFT::axis_type<1>({1}), direction); - auto shift2_odd = KokkosFFT::Impl::_get_shift( + auto shift2_odd = KokkosFFT::Impl::get_shift( x2_odd, KokkosFFT::axis_type<2>({0, 1}), direction); - auto shift2_even = KokkosFFT::Impl::_get_shift( + auto shift2_even = KokkosFFT::Impl::get_shift( x2_even, KokkosFFT::axis_type<2>({0, 1}), direction); EXPECT_TRUE(shift1_odd == shift1_odd_ref); From 85f2ebc6e94a820535e1c1568c41204337d9c21f Mon Sep 17 00:00:00 2001 From: Yuuichi Asahi Date: Mon, 8 Jul 2024 18:33:53 +0900 Subject: [PATCH 6/7] rename roll_impl and coefficients_impl --- common/src/KokkosFFT_Helpers.hpp | 16 ++++++++-------- common/src/KokkosFFT_normalization.hpp | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/common/src/KokkosFFT_Helpers.hpp b/common/src/KokkosFFT_Helpers.hpp index 4f53ef7..6b69efa 100644 --- a/common/src/KokkosFFT_Helpers.hpp +++ b/common/src/KokkosFFT_Helpers.hpp @@ -38,10 +38,10 @@ auto get_shift(const ViewType& inout, axis_type _axes, int direction = 1) { } template -void roll_impl(const ExecutionSpace& exec_space, ViewType& inout, - axis_type<1> shift, axis_type<1>) { +void roll(const ExecutionSpace& exec_space, ViewType& inout, axis_type<1> shift, + axis_type<1>) { // Last parameter is ignored but present for keeping the interface consistent - static_assert(ViewType::rank() == 1, "roll_impl: Rank of View must be 1."); + static_assert(ViewType::rank() == 1, "roll: Rank of View must be 1."); std::size_t n0 = inout.extent(0); ViewType tmp("tmp", n0); @@ -68,10 +68,10 @@ void roll_impl(const ExecutionSpace& exec_space, ViewType& inout, } template -void roll_impl(const ExecutionSpace& exec_space, ViewType& inout, - axis_type<2> shift, axis_type axes) { +void roll(const ExecutionSpace& exec_space, ViewType& inout, axis_type<2> shift, + axis_type axes) { constexpr int DIM0 = 2; - static_assert(ViewType::rank() == DIM0, "roll_impl: Rank of View must be 2."); + static_assert(ViewType::rank() == DIM0, "roll: Rank of View must be 2."); int n0 = inout.extent(0), n1 = inout.extent(1); ViewType tmp("tmp", n0, n1); @@ -145,7 +145,7 @@ void fftshift_impl(const ExecutionSpace& exec_space, ViewType& inout, "fftshift_impl: Rank of View must be larger thane " "or equal to the Rank of shift axes."); auto shift = get_shift(inout, axes); - roll_impl(exec_space, inout, shift, axes); + roll(exec_space, inout, shift, axes); } template @@ -165,7 +165,7 @@ void ifftshift_impl(const ExecutionSpace& exec_space, ViewType& inout, "ifftshift_impl: Rank of View must be larger " "thane or equal to the Rank of shift axes."); auto shift = get_shift(inout, axes, -1); - roll_impl(exec_space, inout, shift, axes); + roll(exec_space, inout, shift, axes); } } // namespace Impl } // namespace KokkosFFT diff --git a/common/src/KokkosFFT_normalization.hpp b/common/src/KokkosFFT_normalization.hpp index 90f6ef6..b57e974 100644 --- a/common/src/KokkosFFT_normalization.hpp +++ b/common/src/KokkosFFT_normalization.hpp @@ -24,8 +24,8 @@ void normalize_impl(const ExecutionSpace& exec_space, ViewType& inout, } template -auto coefficients_impl(ViewType, Direction direction, - Normalization normalization, std::size_t fft_size) { +auto get_coefficients(ViewType, Direction direction, + Normalization normalization, std::size_t fft_size) { using value_type = KokkosFFT::Impl::real_type_t; value_type coef = 1; @@ -63,7 +63,7 @@ void normalize(const ExecutionSpace& exec_space, ViewType& inout, Direction direction, Normalization normalization, std::size_t fft_size) { auto [coef, to_normalize] = - coefficients_impl(inout, direction, normalization, fft_size); + get_coefficients(inout, direction, normalization, fft_size); if (to_normalize) normalize_impl(exec_space, inout, coef); } From 9784d4872e7752df2373387a06944bb5b506d1fa Mon Sep 17 00:00:00 2001 From: Yuuichi Asahi Date: Mon, 8 Jul 2024 18:39:15 +0900 Subject: [PATCH 7/7] Undo merging destroy_plan and destroy_info functions --- fft/src/KokkosFFT_Cuda_plans.hpp | 11 +++++++++-- fft/src/KokkosFFT_HIP_plans.hpp | 11 +++++++++-- fft/src/KokkosFFT_Host_plans.hpp | 11 +++++++++-- fft/src/KokkosFFT_Plans.hpp | 4 ++-- fft/src/KokkosFFT_ROCM_plans.hpp | 13 +++++++++---- fft/src/KokkosFFT_SYCL_plans.hpp | 12 ++++++++++-- 6 files changed, 48 insertions(+), 14 deletions(-) diff --git a/fft/src/KokkosFFT_Cuda_plans.hpp b/fft/src/KokkosFFT_Cuda_plans.hpp index 935be54..f868a65 100644 --- a/fft/src/KokkosFFT_Cuda_plans.hpp +++ b/fft/src/KokkosFFT_Cuda_plans.hpp @@ -177,12 +177,19 @@ auto create_plan(const ExecutionSpace& exec_space, return fft_size; } -template , std::nullptr_t> = nullptr> -void destroy_plan_and_info(std::unique_ptr& plan, InfoType&) { +void destroy_plan(std::unique_ptr& plan) { cufftDestroy(*plan); } + +template , + std::nullptr_t> = nullptr> +void destroy_info(InfoType&) { + // not used, no finalization is required +} } // namespace Impl } // namespace KokkosFFT diff --git a/fft/src/KokkosFFT_HIP_plans.hpp b/fft/src/KokkosFFT_HIP_plans.hpp index bc2b338..a910ffa 100644 --- a/fft/src/KokkosFFT_HIP_plans.hpp +++ b/fft/src/KokkosFFT_HIP_plans.hpp @@ -184,12 +184,19 @@ auto create_plan(const ExecutionSpace& exec_space, return fft_size; } -template , std::nullptr_t> = nullptr> -void destroy_plan_and_info(std::unique_ptr& plan, InfoType&) { +void destroy_plan(std::unique_ptr& plan) { hipfftDestroy(*plan); } + +template , + std::nullptr_t> = nullptr> +void destroy_info(InfoType&) { + // not used, no finalization is required +} } // namespace Impl } // namespace KokkosFFT diff --git a/fft/src/KokkosFFT_Host_plans.hpp b/fft/src/KokkosFFT_Host_plans.hpp index 9416938..3ab86d7 100644 --- a/fft/src/KokkosFFT_Host_plans.hpp +++ b/fft/src/KokkosFFT_Host_plans.hpp @@ -105,11 +105,11 @@ auto create_plan(const ExecutionSpace& exec_space, return fft_size; } -template , std::nullptr_t> = nullptr> -void destroy_plan_and_info(std::unique_ptr& plan, InfoType&) { +void destroy_plan(std::unique_ptr& plan) { if constexpr (std::is_same_v) { fftwf_destroy_plan(*plan); } else { @@ -117,6 +117,13 @@ void destroy_plan_and_info(std::unique_ptr& plan, InfoType&) { } } +template , + std::nullptr_t> = nullptr> +void destroy_info(InfoType&) { + // not used, no finalization is required +} } // namespace Impl } // namespace KokkosFFT diff --git a/fft/src/KokkosFFT_Plans.hpp b/fft/src/KokkosFFT_Plans.hpp index 641fa00..532f5bb 100644 --- a/fft/src/KokkosFFT_Plans.hpp +++ b/fft/src/KokkosFFT_Plans.hpp @@ -285,8 +285,8 @@ class Plan { } ~Plan() { - destroy_plan_and_info(m_plan, - m_info); + destroy_info(m_info); + destroy_plan(m_plan); } Plan(const Plan&) = delete; diff --git a/fft/src/KokkosFFT_ROCM_plans.hpp b/fft/src/KokkosFFT_ROCM_plans.hpp index b1ea115..7fbb263 100644 --- a/fft/src/KokkosFFT_ROCM_plans.hpp +++ b/fft/src/KokkosFFT_ROCM_plans.hpp @@ -192,14 +192,19 @@ auto create_plan(const ExecutionSpace& exec_space, return fft_size; } -template , std::nullptr_t> = nullptr> -void destroy_plan_and_info(std::unique_ptr& plan, - InfoType& execution_info) { - rocfft_execution_info_destroy(execution_info); +void destroy_plan(std::unique_ptr& plan) { rocfft_plan_destroy(*plan); } + +template , + std::nullptr_t> = nullptr> +void destroy_info(InfoType& execution_info) { + rocfft_execution_info_destroy(execution_info); +} } // namespace Impl } // namespace KokkosFFT diff --git a/fft/src/KokkosFFT_SYCL_plans.hpp b/fft/src/KokkosFFT_SYCL_plans.hpp index 8e9fdcd..e62f6b2 100644 --- a/fft/src/KokkosFFT_SYCL_plans.hpp +++ b/fft/src/KokkosFFT_SYCL_plans.hpp @@ -106,12 +106,20 @@ auto create_plan(const ExecutionSpace& exec_space, } template < - typename ExecutionSpace, typename PlanType, typename InfoType, + typename ExecutionSpace, typename PlanType, std::enable_if_t, std::nullptr_t> = nullptr> -void destroy_plan_and_info(std::unique_ptr&, InfoType&) { +void destroy_plan(std::unique_ptr&) { // In oneMKL, plans are destroybed by destructor } + +template < + typename ExecutionSpace, typename InfoType, + std::enable_if_t, + std::nullptr_t> = nullptr> +void destroy_info(InfoType&) { + // not used, no finalization is required +} } // namespace Impl } // namespace KokkosFFT