Eclipse CUDA keyword highlighting fix

Hello,

I’m using the Eclipse CDT for NVIDIA CUDA development. It’s pretty nice. However, I’d like to disable some C++ syntax errors as there is a handful of CUDA keywords that the Eclipse parser doesn’t like.

Specifically, some of the keywords that makes eclipse barf are

extern “C”

global

device

shared

Here are some screenshots to illustrate:

External Media

The global keyword along with the extern “C” stuff throws the Eclipse parser off, see how the entire function is yellowed, and I lose autocompletion in the affected function. This is of course legal CUDA code.

External Media

Here I’ve commented out the extern “C” line. The Eclipse parser accepts the function, and autocompletion works.

External Media

Just for fun, I’ve disabled the global keyword and the function now appears nice and clean to Eclipse.

So, what to do? On the eclipse.tools.cdt mailing list there was some info about the built in Eclipse C Development Tools parser. If you do this at the top of your .cu file, it fixes things:

#ifdef __CDT_PARSER__

#define __global__

#define __device__

#define __shared__

#endif

… and Eclipse starts playing nicer. What it does is that when the Eclipse parser is running, CDT_PARSER is defined, and this causes the Eclipse parser to define global and friends to nothing, and they stop getting in the way. However, nvcc doesn’t define CDT_PARSER and things compile normally.

Hope this helps someone!

Also, running Eclipse with the JRockit realtime JRE makes Eclipse very very snappy. It eats a bit of RAM, but not that much.

[url=“http://blogs.oracle.com/hirt/2008/08/running_eclipseworkshop_on_jro.html”]http://blogs.oracle.com/hirt/2008/08/runni...hop_on_jro.html[/url]

(I tried the “scary” deterministic GC stuff the guy talks about and it’s even nicer, and it didn’t topple my box.)

I find that

#include <cuda_runtime.h>

is a better option, partly because it highlights some cuda commands like cudaMalloc, cudaFree and cudaThreadSynchronize.

Unfortunately, the only thing I can’t get the CDT to stop whining about (and format correctly) are calls to global functions because it doesn’t understand the <<< >>> notation.

Interesting, thanks

This is my solution:

#ifdef __CDT_PARSER__

#define __global__

#define __device__

#define __shared__

#define CUDA_KERNEL_DIM(...)

#else

#define CUDA_KERNEL_DIM(...)  <<< __VA_ARGS__ >>>

#endif

Then invoke kernels like:

myKernel CUDA_KERNEL_DIM(gridDim, blockDim) (foo, bar);