-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix RAII issue by introducing wrapper classes for backend plans #208
base: main
Are you sure you want to change the base?
Conversation
e302632
to
05a023b
Compare
I would go a step further and make these RAII classes unique-owners. That implies to disallow shallow copy either by simply deleting copy constructor and assignment or make them allocate and copy a new plan if backends offer such a copy function. We can keep the move semantics but we have to keep track if the current object must call class ScopedCufftPlanType {
private:
cufftHandle m_plan;
public:
ScopedCufftPlanType() {
cufftResult cufft_rt = cufftCreate(&m_plan);
KOKKOSFFT_THROW_IF(cufft_rt != CUFFT_SUCCESS, "cufftCreate failed");
}
ScopedCufftPlanType(ScopedCufftPlanType const& rhs) = delete;
ScopedCufftPlanType(ScopedCufftPlanType&& rhs) = delete;
~ScopedCufftPlanType() noexcept {
cufftResult cufft_rt = cufftDestroy(m_plan);
if (cufft_rt != CUFFT_SUCCESS) Kokkos::abort("cufftDestroy failed");
}
ScopedCufftPlanType& operator=(ScopedCufftPlanType const& rhs) = delete;
ScopedCufftPlanType& operator=(ScopedCufftPlanType&& rhs) = delete;
cufftHandle plan() const noexcept { return m_plan; }
}; The I notice that we could also improve the error messages, I see that |
I would prefer to disallow both copy and move, because it may be unsafe for some backends.
Does it return a shallow copy of the
That is true. We can improve the error messages |
Ok for me. I don't think there should be any problem with implementing the move semantics later. It requires us to only pass these objects by reference.
I mean if we do ScopedCufftPlanType plan1;
ScopedCufftPlanType plan2;
plan2 = plan1; This compiles fine and |
That is right. This does not work in the current implementation. Yes, for safety, it is better to disallow copy |
e510c5e
to
46a3630
Compare
Resolves #197
In this PR, we try to resolve RAII issues by introducing a thin wrapper for backend fft plans.
Following modifications are made,
KokkosFFT_FFTW_Types.hpp
file including theFFTW
plan wrapper class and common code bases related fftwFFTW
,cufft
,hipfft
, androcfft
(Scoped***Plan
)For CUDA, we have
Info
andBuffer
that are required only for rocfft are moved insiderocfft
helper classcleanup_threads()
in the destructor of FFTW helper classdestroy_plan_and_info
since it is automatically done in destructors of helper classesQuestions
cufft
andhipfft
. Should we raise assertions in constructor if it fails?