cudaprofilingnvidianvccnsight

Command to run callback_profiling sample from CUPTI


I am running the sample code available for Nvidia CUDA CUPTI in /usr/local/cuda-11.8/extras/CUPTI/samples/callback_profiling. There is a Makefile, but I want to run it using single command (without the Makefile) because it is giving me permission errors with the Makefile. Based on the Makefile, this is the command I am writing:

nvcc --generate-line-info callback_profiling.cu -o callback_profiling -lnvperf_host -lnvperf_target -lcuda -lcupti -I/usr/local/cuda-11.8/extras/CUPTI/samples/callback_profiling/../extensions/include/profilerhost_util -I/usr/local/cuda-11.8/extras/CUPTI/samples/callback_profiling/../extensions/include/c_util -I/usr/local/cuda-11.8/extras/CUPTI/samples/callback_profiling/../../include -L /usr/local/cuda-11.8/extras/CUPTI/samples/callback_profiling/../extensions/src/profilerhost_util

I am getting the error

/usr/bin/ld: /tmp/tmpxft_00005e71_00000000-11_callback_profiling.o: in function `setupProfiling(ProfilingData_t*)':
tmpxft_00005e71_00000000-6_callback_profiling.cudafe1.cpp:(.text+0xe48): undefined reference to `NV::Metric::Config::GetConfigImage(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned char const*)'
/usr/bin/ld: tmpxft_00005e71_00000000-6_callback_profiling.cudafe1.cpp:(.text+0xed3): undefined reference to `NV::Metric::Config::GetCounterDataPrefixImage(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned char const*)'
/usr/bin/ld: /tmp/tmpxft_00005e71_00000000-11_callback_profiling.o: in function `main':
tmpxft_00005e71_00000000-6_callback_profiling.cudafe1.cpp:(.text+0x2751): undefined reference to `NV::Metric::Eval::PrintMetricValues(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<unsigned char, std::allocator<unsigned char> > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, unsigned char const*)'
collect2: error: ld returned 1 exit status

Can someone help me with what will be the right command to run the application? I have an Ubuntu machine with CUDA 11.8


Solution

  • There is a library (libprofilerHostUtil.a) that doesn't get built as part of the samples build process that you will need to build manually.

    On a typical linux install, the Makefile to build that library is in /usr/local/cuda/extras/CUPTI/samples/extensions/src/profilerhost_util. As a root user you should be able to go into that directory, and type make, and then the necessary library will get built.

    Once you have done that, as an ordinary user, you should be able to build the code you are asking about like this:

    nvcc callback_profiling.cu -o callback_profiling -I/usr/local/cuda/extras/CUPTI/samples/callback_profiling/../extensions/include/profilerhost_util -I/usr/local/cuda/extras/CUPTI/samples/callback_profiling/../extensions/include/c_util -I/usr/local/cuda/extras/CUPTI/samples/callback_profiling/../../include -L /usr/local/cuda/extras/CUPTI/samples/callback_profiling/../extensions/src/profilerhost_util -L/usr/local/cuda/extras/CUPTI/lib64 -lcupti -lnvperf_host -lnvperf_target -lprofilerHostUtil -lcuda
    

    wherever you see /cuda/ in the paths above, you may need to change that to /cuda-11.8/ or whatever is needed to match your install, if you have not set up the symbolic link that the CUDA installer asks to set up.

    If you want to build the library I mentioned somewhere else, manually, you will need to do something like this. First, change to the indicated directory (cd /usr/local/cuda/extras/CUPTI/samples/extensions/src/profilerhost_util), then use these commands, replacing /my/build/dir/ with the path to a location you have write access to:

    nvcc  -c --std=c++11 -Xcompiler -fPIC -I../../../../include -I../../../../../../include -I../../include/profilerhost_util -I../../include/c_util List.cpp -o /my/build/dir/List.o
    nvcc  -c --std=c++11 -Xcompiler -fPIC -I../../../../include -I../../../../../../include -I../../include/profilerhost_util -I../../include/c_util Metric.cpp -o /my/build/dir/Metric.o
    nvcc  -c --std=c++11 -Xcompiler -fPIC -I../../../../include -I../../../../../../include -I../../include/profilerhost_util -I../../include/c_util Eval.cpp -o /my/build/dir/Eval.o
    nvcc  -o /my/build/dir/libprofilerHostUtil.a -lib /my/build/dir/List.o /my/build/dir/Metric.o /my/build/dir/Eval.o   -lcuda -L ../../../../../../lib64 -lnvperf_host -lnvperf_target
    

    And if you use that route, you will need to add -L. to the command to build the executable.