-
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
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
@tpadioleau I have fixed based on the discussion. Can I have another review? |
Why do we need the rocfft backend already ? For performance ? |
For performance. I prefer |
I don't understand how we can explain that ? |
Me neither. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are almost there, just a concern with the FFTW backend and threads cleanup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor changes and then we are good
@tpadioleau Thank you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine for me, please can you add me as a git co-author for this PR ? As no suggestion was applied I will not appear at all.
Co-authored-by: Yuuichi Asahi <[email protected]> Co-authored-by: Thomas Padioleau <[email protected]>
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?