CUPTI read 0 value for event

I am developing a tool to collect CUPTI event information automatically at the runtime. My library (.so, employed with LD_PRELOAD) calls CUPTI at the beginning of user “main” . It registers callback functions like the CUPTI sample “callback_event”. The “callback_event” sample works well on my machine.

At the runtime, an event group is initialized and the callback function is activated successfully for each kernel. However, the returned event value is always 0.

The source codes are attached.
You can compile with
nvcc -O3 -g -std=c++11 --compiler-options ‘-fPIC’ -I/cuda/path/extras/CUPTI/include -c manager.cpp
nvcc -O3 -g -std=c++11 --compiler-options ‘-fPIC’ -c ld_cupti.cpp
nvcc -O3 -g -std=c++11 --compiler-options ‘-fPIC’ --shared -o manager.o ld_cupti.o -L/cuda/path/extras/CUPTI/lib64 -lcuda -lcupti -lcudart -L/cuda/path/lib64

At runtime export LD_PRELOAD=/path/to/ before you start a CUDA program.

Thanks for your help.

gpu_ld_cupti.cpp (1.7 KB) gpu_manager.hpp (50 Bytes) gpu_manager.cpp (7.6 KB)

Hi Wang,

It seems the injection library attempts to enable the event collection for the CUDA context created in the injection itself. We need to operate on the CUDA context created by the application. Field ‘context’ of the callback struct CUpti_CallbackData can be used to fetch the application context in one of the CUDA API callback, preferably in the launch APIs. Event group should be created using the application context using the API cuptiEventGroupCreate().

Code snippet:
getEventValueCallback(void *userdata, CUpti_CallbackDomain domain,
CUpti_CallbackId cbid, const CUpti_CallbackData *cbInfo)

cuptiEventGroupCreate(cbInfo->context, &cuptiEvent.eventGroup, 0);


1 Like