Code coverage for CUDA NVIDIA (GPU code) is crucial for several reasons, especially given the increasing complexity and criticality of GPU-accelerated applications in this age. RKTracer measures coverage for both the host code and the device (GPU) code, so you can see exactly which parts of your CUDA application your tests exercise.
Prefix rktracer to the make command to build and instrument your CUDA application, run your tests, then run rkresults to generate the HTML report.
Why CUDA code coverage matters
Coverage gives you confidence that your tests actually reach the GPU and host code paths that matter. The reasons it is important for CUDA NVIDIA applications include the following.
- GPU code complexity. GPU-accelerated code is increasingly complex, and coverage shows which parts the tests reach.
- Parallel execution. CUDA code runs in parallel across many threads, and coverage helps confirm those paths are exercised.
- Identifying performance bottlenecks. Coverage data helps locate code that is, or is not, being executed.
- Avoiding blind spots and bug detection. Coverage exposes untested code that can hide bugs.
- Regression testing. Coverage helps maintain confidence as the code changes over time.
- Comprehensive testing. Coverage of both host and device code gives a complete picture of what the tests exercise.
Step 1: Build your application with RKTracer
Prefix the rktracer command to your make build command:
rktracer make
When you build this way, RKTracer preprocesses all the source files by the nvcc compiler, then instruments the preprocessed files with coverage collection mechanisms.
Step 2: Run your tests
Run your tests against the RKTracer-instrumented application. For example:
./run_tests
As the instrumented application runs, RKTracer captures the coverage data for both the host and the device (GPU) code.
Step 3: Generate the code coverage report
Run the rkresults command to generate the HTML code coverage report:
rkresults
In the report, the lines are color coded:
- Green means fully covered (executed).
- Yellow means partial coverage.
- Red means not executed during the tests.
Enable coverage for selected files and functions
You can scope coverage to specific folders, files, or functions by editing rktracer.config.
Coverage for selected folders
To instrument source files from some folders while ignoring others, add the following:
ignore *.c instrument */power/* */core/* */keys/* never */firmware_loader/* */lockdown/*
Coverage for selected functions
To generate coverage only for specific functions in specific files, edit rktracer.config:
ignore *.c instrument *source-file-X.c *source-file-Y.c *source-file-Z.c function-ignore * function-instrument fun_X() fun_Y() fun_Z()
Next steps
Once your CUDA project reports coverage on both host and device, the same RKTracer workflow applies across other platforms. Browse the rest of the documentation, or read more about how RKTracer measures coverage.