Skip to content

Commit

Permalink
Merge destroy_plan and destroy_info (#116)
Browse files Browse the repository at this point in the history
Co-authored-by: Yuuichi Asahi <[email protected]>
  • Loading branch information
yasahi-hpc and Yuuichi Asahi authored Jul 9, 2024
1 parent 17e97f3 commit c09d8e3
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 49 deletions.
11 changes: 2 additions & 9 deletions fft/src/KokkosFFT_Cuda_plans.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,12 @@ auto create_plan(const ExecutionSpace& exec_space,
return fft_size;
}

template <typename ExecutionSpace, typename PlanType,
template <typename ExecutionSpace, typename PlanType, typename InfoType,
std::enable_if_t<std::is_same_v<ExecutionSpace, Kokkos::Cuda>,
std::nullptr_t> = nullptr>
void destroy_plan(std::unique_ptr<PlanType>& plan) {
void destroy_plan_and_info(std::unique_ptr<PlanType>& plan, InfoType&) {
cufftDestroy(*plan);
}

template <typename ExecutionSpace, typename InfoType,
std::enable_if_t<std::is_same_v<ExecutionSpace, Kokkos::Cuda>,
std::nullptr_t> = nullptr>
void destroy_info(InfoType&) {
// not used, no finalization is required
}
} // namespace Impl
} // namespace KokkosFFT

Expand Down
11 changes: 2 additions & 9 deletions fft/src/KokkosFFT_HIP_plans.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,12 @@ auto create_plan(const ExecutionSpace& exec_space,
return fft_size;
}

template <typename ExecutionSpace, typename PlanType,
template <typename ExecutionSpace, typename PlanType, typename InfoType,
std::enable_if_t<std::is_same_v<ExecutionSpace, Kokkos::HIP>,
std::nullptr_t> = nullptr>
void destroy_plan(std::unique_ptr<PlanType>& plan) {
void destroy_plan_and_info(std::unique_ptr<PlanType>& plan, InfoType&) {
hipfftDestroy(*plan);
}

template <typename ExecutionSpace, typename InfoType,
std::enable_if_t<std::is_same_v<ExecutionSpace, Kokkos::HIP>,
std::nullptr_t> = nullptr>
void destroy_info(InfoType&) {
// not used, no finalization is required
}
} // namespace Impl
} // namespace KokkosFFT

Expand Down
12 changes: 2 additions & 10 deletions fft/src/KokkosFFT_Host_plans.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,17 @@ auto create_plan(const ExecutionSpace& exec_space,
return fft_size;
}

template <typename ExecutionSpace, typename PlanType,
template <typename ExecutionSpace, typename PlanType, typename InfoType,
std::enable_if_t<
std::is_same_v<ExecutionSpace, Kokkos::DefaultHostExecutionSpace>,
std::nullptr_t> = nullptr>
void destroy_plan(std::unique_ptr<PlanType>& plan) {
void destroy_plan_and_info(std::unique_ptr<PlanType>& plan, InfoType&) {
if constexpr (std::is_same_v<PlanType, fftwf_plan>) {
fftwf_destroy_plan(*plan);
} else {
fftw_destroy_plan(*plan);
}
}

template <typename ExecutionSpace, typename InfoType,
std::enable_if_t<
std::is_same_v<ExecutionSpace, Kokkos::DefaultHostExecutionSpace>,
std::nullptr_t> = nullptr>
void destroy_info(InfoType&) {
// not used, no finalization is required
}
} // namespace Impl
} // namespace KokkosFFT

Expand Down
4 changes: 2 additions & 2 deletions fft/src/KokkosFFT_Plans.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ class Plan {
}

~Plan() {
destroy_info<ExecutionSpace, fft_info_type>(m_info);
destroy_plan<ExecutionSpace, fft_plan_type>(m_plan);
destroy_plan_and_info<ExecutionSpace, fft_plan_type, fft_info_type>(m_plan,
m_info);
}

Plan(const Plan&) = delete;
Expand Down
13 changes: 4 additions & 9 deletions fft/src/KokkosFFT_ROCM_plans.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,13 @@ auto create_plan(const ExecutionSpace& exec_space,
return fft_size;
}

template <typename ExecutionSpace, typename PlanType,
template <typename ExecutionSpace, typename PlanType, typename InfoType,
std::enable_if_t<std::is_same_v<ExecutionSpace, Kokkos::HIP>,
std::nullptr_t> = nullptr>
void destroy_plan(std::unique_ptr<PlanType>& plan) {
rocfft_plan_destroy(*plan);
}

template <typename ExecutionSpace, typename InfoType,
std::enable_if_t<std::is_same_v<ExecutionSpace, Kokkos::HIP>,
std::nullptr_t> = nullptr>
void destroy_info(InfoType& execution_info) {
void destroy_plan_and_info(std::unique_ptr<PlanType>& plan,
InfoType& execution_info) {
rocfft_execution_info_destroy(execution_info);
rocfft_plan_destroy(*plan);
}
} // namespace Impl
} // namespace KokkosFFT
Expand Down
12 changes: 2 additions & 10 deletions fft/src/KokkosFFT_SYCL_plans.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,12 @@ auto create_plan(const ExecutionSpace& exec_space,
}

template <
typename ExecutionSpace, typename PlanType,
typename ExecutionSpace, typename PlanType, typename InfoType,
std::enable_if_t<std::is_same_v<ExecutionSpace, Kokkos::Experimental::SYCL>,
std::nullptr_t> = nullptr>
void destroy_plan(std::unique_ptr<PlanType>&) {
void destroy_plan_and_info(std::unique_ptr<PlanType>&, InfoType&) {
// In oneMKL, plans are destroybed by destructor
}

template <
typename ExecutionSpace, typename InfoType,
std::enable_if_t<std::is_same_v<ExecutionSpace, Kokkos::Experimental::SYCL>,
std::nullptr_t> = nullptr>
void destroy_info(InfoType&) {
// not used, no finalization is required
}
} // namespace Impl
} // namespace KokkosFFT

Expand Down

0 comments on commit c09d8e3

Please sign in to comment.