Search code examples
javadebuggingcudajcuda

how to debug kernels called by a java(jcuda) program


Is there any way to debug cuda functions called by java (jcuda) ?

My program launch this exception:

Exception in thread "main" jcuda.CudaException:CUDA_ERROR_ILLEGAL_ADDRESS
at jcuda.driver.JCudaDriver.checkResult(JCudaDriver.java:288)
at jcuda.driver.JCudaDriver.cuCtxSynchronize(JCudaDriver.java:1852)
at CalculateurGPU.updateAndCompute(rGPUcalculator.java:129)
at Test.main(Test.java:90)

I have a very long cuda code, and i can't find any information in that to help me find where the error is.

Another question: when i click on "JCudaDriver.java:288" i don't have access to it, it says "source not found". How can i attach thesesources to my project ?

Thanks in advance


Solution

  • The best way I have been able to debug my JCuda executable code is by putting printf statements everywhere. Obviously delete them after you are done but you have to start somewhere.

    Add the following to your .java code that is calling your kernel code.

    JCudaDriver.cuCtxSetLimit(CUlimit.CU_LIMIT_PRINTF_FIFO_SIZE, 4096);

    Then inside your CUDA kernel, use printf(""); statements in your CUDA kernel code to determine where the problem exists. If I had a guess it would be due to you access a piece of memory that you shouldn't be.

    I would also suggest wrapping the printf with a if(gtid == 0){printf("hello\n");} otherwise you are going to have every thread trying to perform the printf.

    Source: http://forum.byte-welt.net/byte-welt-projekte-projects/swogl-jcuda-jocl/jcuda/3255-gpu-printf-compute-capility-2-0-a.html

    EDIT:

    I would like to add that there has been a debugging section added on the JCuda website. It suggests using a tool called "cuda-memcheck" to aid in debugging your CUDA applications.

    http://www.jcuda.org/debugging/Debugging.html