I’m trying to save custom data in extra field of CUcontext, which has void* type using this code:
#include <cuda_runtime_api.h>
#include <cuda.h>
#include <iostream>
int main()
{
CUcontext cu_ctx;
cuCtxCreate(&cu_ctx, CU_CTX_SCHED_AUTO, 0);
// Store a pointer to some extra data in the CUcontext.extra field
int* my_extra_data = new int(42);
cu_ctx->extra = my_extra_data;
// Use the context and then destroy it
cuCtxSetCurrent(cu_ctx);
// Do some CUDA operations...
cuCtxSetCurrent(NULL);
cuCtxDestroy(cu_ctx);
// Retrieve the extra data from the CUcontext.extra field and print it
int* retrieved_extra_data = (int*)cu_ctx->extra;
std::cout << "Extra data value: " << *retrieved_extra_data << std::endl;
// Free the extra data memory
delete retrieved_extra_data;
return 0;
}
But I get the following error:
test.cpp:12:15: error: invalid use of incomplete type ‘struct CUctx_st’
12 | cu_ctx->extra = my_extra_data;
| ^~
In file included from test.cpp:2:
/usr/include/cuda.h:246:16: note: forward declaration of ‘struct CUctx_st’
246 | typedef struct CUctx_st *CUcontext; /**< CUDA context */
Why I can’t access extra like that?