Skip to content

RAII issue #197

Closed
Closed
@tpadioleau

Description

I suspect potential memory leaks.

Consider the snippet

cufftResult cufft_rt = cufftCreate(&(*plan));
KOKKOSFFT_THROW_IF(cufft_rt != CUFFT_SUCCESS, "cufftCreate failed");
cudaStream_t stream = exec_space.cuda_stream();
cufftSetStream((*plan), stream);
auto type = KokkosFFT::Impl::transform_type<ExecutionSpace, in_value_type,
out_value_type>::type();
auto [in_extents, out_extents, fft_extents, howmany] =
KokkosFFT::Impl::get_extents(in, out, axes, s, is_inplace);
const int nx = fft_extents.at(0);
int fft_size = std::accumulate(fft_extents.begin(), fft_extents.end(), 1,
std::multiplies<>());
cufft_rt = cufftPlan1d(&(*plan), nx, type, howmany);
KOKKOSFFT_THROW_IF(cufft_rt != CUFFT_SUCCESS, "cufftPlan1d failed");

It is called inside the Plan constructor. Let's assume the second KOKKOSFFT_THROW_IF actually throws, the backend destroy_plan_and_info function will never be called because the Plan object will never finish construction.

I think we need to adhere to the RAII so that if any exception is thrown the backend plan object gets automatically freed.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions