CUDA event API

Hi all,

I’m trying to get a CUDA Event set up to record GPU run times, and am getting

[SIZE=1][LEFT]Exception in thread “main” [/SIZE][SIZE=1]jcuda.CudaException[/SIZE][SIZE=1]: CUDA_ERROR_NOT_INITIALIZED
at jcuda.driver.JCudaDriver.checkResult([/SIZE][SIZE=1]JCudaDriver.java:153[/SIZE][SIZE=1])[/LEFT]
at jcuda.driver.JCudaDriver.cuEventCreate([/SIZE][SIZE=1]JCudaDriver.java:3446[/SIZE][SIZE=1])[/SIZE]
[SIZE=1]…
[/SIZE]
I couldn’t find any examples of how to get the JCudaDriver working on the cuda events, but here’s the code I tried:

[LEFT]CUevent start = [SIZE=1]new[/SIZE] CUevent();
CUevent stop = [SIZE=1]new[/SIZE] CUevent();
JCudaDriver.cuEventCreate(start, 1);
JCudaDriver.cuEventCreate(stop, 1);
[SIZE=1]float[/SIZE][] runTime = [SIZE=1]new[/SIZE] [SIZE=1]float[/SIZE][1];

[SIZE=1]…code which works fine without CUevent…[/LEFT]
[/SIZE][LEFT]

JCudaDriver.cuEventRecord( start, [SIZE=1]null[/SIZE]);
kernelLauncher.call(dResult, dA, dB);
JCudaDriver.cuEventRecord( stop, [SIZE=1]null[/SIZE]);
JCudaDriver.cuEventSynchronize( stop );
JCudaDriver.cuEventElapsedTime( runTime, start, stop );
JCudaDriver.cuEventDestroy( start );
JCudaDriver.cuEventDestroy( stop );
System.[SIZE=1]out[/SIZE].println([SIZE=1]"Run time: "[/SIZE] + runTime); [/LEFT]

Any feedback on how t

Hello

You are obviously calling the cuEventCreate method before the CUDA driver API has been initialized. The KernelLauncher automatically initializes the driver for the first device and a default context. Thus, you may either do the call to “cuEventCreate” after the KernelLauncher has been created, or add the following initialization in your program somewhere before the call to “cuEventCreate”:

JCudaDriver.cuInit(0);
CUdevice device = new CUdevice();
JCudaDriver.cuDeviceGet(device, 0);
CUcontext context = new CUcontext();
JCudaDriver.cuCtxCreate(context, 0, device);

But please note that the KernelLauncher is only a sample - some proof of concept - which is NOT yet part of the official API. It will probably be part of a utilities package sooner or later, but it might still change (For example: The “call”-method which uses VarArgs is convenient, but may be ambiguous in some cases…)

bye
Marco

Hi Marco,

Thanks for the response – that was the silly mistake I was having (i.e., not initializing the driver first).

And thanks for the warning about the KernelLancher. I like it’s simplicity in doing the behind-the-scenes driver work, so I look forward to seeing it in a utilities package at some point.

Best wishes