How to obtain streamId inside a CUPTI callback CUPTI Callback

I am using NVIDIA CUDA Profiler Tools Interface (CUPTI) from CUDA Toolkit 4.1
I am trying to obtain stream ID inside a CUPTI callback function.

When I get a call back for CUPTI_CB_DOMAIN_RUNTIME_API domain with CUPTI_RUNTIME_TRACE_CBID_cudaLaunch_v3020 as the cbid, I want to know the stream that is launching the kernel.

I use the following piece of code to achieve this:

const cuLaunchKernel_params * p = (const cuLaunchKernel_params *) cbInfo->functionParams;
CUstream hStream = p->hStream;
uint32_t id;

However, cuptiGetStreamId() crashes and on examination I observed that cbInfo->functionParams does not contain values that can be casted to (cuLaunchKernel_params *).

The CUPTI user manual for “CUpti_CallbackData::functionParams” does not give any clear information on how to use this field correctly.

Any information on this subject will be helpful.


PS: ActivityAPI provides facility to know stream Id, but I don’t want to take that path.

For the callback you are registering for (CUPTI_RUNTIME_TRACE_CBID_cudaLaunch_v3020), the parameter structure is actually cudaLaunch_v3020_params from generated_cuda_runtime_api_meta.h. You will find that that structure only contains the name of the kernel. But you can get the stream from the cudaConfigureCall callback which will occur on the same thread just before the cudaLaunch callback. It’s parameters are:

typedef struct cudaConfigureCall_v3020_params_st {
dim3 gridDim;
dim3 blockDim;
size_t sharedMem;
cudaStream_t stream;
} cudaConfigureCall_v3020_params;

You can then cast cudaStream_t to CUstream and use it in the cuptiGetStreamId() call.