You could try to add assert statements to your custom CUDA extension to get a proper error message by running the code via CUDA_LAUNCH_BLOCKING=1 python script.py args, use cuda-memcheck to debug the illegal memory access, or run the code via cuda-gdb --args python script.py to get an interactive debugging session.