How ints81/cuda_driver_hooking works
Project type and purpose
• This is an open-source tooling project whose sole purpose is to demonstrate and implement CUDA Driver API hooking via the LD_PRELOAD mechanism.
• It provides a small shared library (“hook.so”) that intercepts calls into the CUDA driver, plus sample executables (test.cu, conv_test.cu) and a PyTorch script (torch_op_test.py) to exercise that hook.
File structure
• Top level:
• hook.cpp – source of the preloaded shared library
• test.cu – minimal CUDA program to test basic driver API calls
• conv_test.cu – small convolution example that also links against cuDNN
• torch_op_test.py – Python script running a Torch operation to exercise more CUDA calls
• README.md – build/run instructions
• .gitignore – ignore rules
• No rigid MVC or microservice pattern—this is a single-component hooking tool with multiple test drivers.
Extract insights from the README
• Build steps:
1. nvcc compiles hook.cpp into a PIC shared object, linking CUDA Driver API and dl.
2. nvcc compiles test.cu and conv_test.cu into executables.
3. You run any CUDA-using binary under LD_PRELOAD=./hook.so so that hook.so is injected at load time.