#define and CUDA

Why does the following snippet not work with CUDA (and 3.2 and 4.0)?

#define NUM_BLOCKS 16

// lots of code.

dim3 dimBlock(NUM_BLOCKS, NUM_BLOCKS);

but this,

dim3 dimBlock(16, 16);

does?

I keep getting error : expected a ")"and error : expected an expression. What am I missing?

+3
source share
3 answers

Are you sure you didn’t write

#define NUM_BLOCKS 16;

(note the semicolon at the end)?

I get exactly the errors that you described when there is a semicolon erroneus.

+8
source

This is strange. This may be due to a common macro problem. If you know, macros do not take into account the scope. Maybe the same macro is defined elsewhere, but in different ways.

Why aren't you using const intor enuminstead of a macro?

Do you know this: C ++ - enum vs. const vs. #define

+2

One way to figure out how to get your compiler driver to stop after the preprocessing phase so you can see what was created. This will show you that the preprocessor has replaced and therefore gives you something to look for.

The -E option if you are using gcc and / E for MSVC.

For an nvcc compiler driver, a typical command would be

nvcc -E file.cu -o file.cup
+1
source

Source: https://habr.com/ru/post/1796630/


All Articles