cuFFT runtime changes current context

I am building an application where I would like to create and manage my own CUDA contexts using the driver API. My understanding is that I should be able to create a context and have the CUDA runtime libraries use that context too. However, some particular cuFFT runtime calls appear to be changing the context, when I would like it to use the existing context. I have written a minimal example to demonstrate this:

#include <cuda.h>
#include <cufft.h>

#include <iostream>

int main()
CUcontext main_render_context;
// create main context
cuCtxCreate(&main_render_context, 0, 0);
// print
std::cout << "main ctx: " << main_render_context << std::endl;
// push

// cufft
cufftHandle handle;
int fftDimensions[2] = { 2048, 2048 };
size_t fftSize;
2, fftDimensions,
NULL, 0, 0, // triple of embed, stride, distance (in)
NULL, 0, 0, // triple of embed, stride, distance (out)

CUcontext current_render_context;
// prints different to above
std::cout << "current ctx: " << current_render_context << std::endl;


Building and running the above with CUDA 11.1 results in different values being printed for the contexts. Is this the expected behaviour, and if so, how should I ensure that I can run commands in my chosen context after a call to cuFFT?

I note that the call to:


doesn’t seem to be changing the context. Apart from this cufftGetSizeMany call, have you identified other cufft calls that change the context?

I have not noted any other runtime calls which change the context other than this and the related cufftEstimateMany, but I have not gone digging any further. Other calls to cuFFT in my program (e.g. cufftExecC2C) do not appear to change the context.

my guess is that the other context that is popping up here is the primary context.

Anyway you may wish to file a bug. As a workaround, I assume you know how to save and restore contexts - you can do that after your usage of these calls, if you wish.

I have submitted a bug report with bug id 3209287.