Jithin Pavithran
Jithin Pavithran

Reputation: 1351

Same name for host and device variables in CUDA

The following code gives me an error:

Node *nodes;
__device__ Node *nodes;

Error: error: variable "nodes" has already been defined

Why can't I have the same name for variables in host and device?
I assume it should be possible since they have different scopes.

Upvotes: 0

Views: 278

Answers (1)

talonmies
talonmies

Reputation: 72349

I assume it should be possible since they have different scopes.

That is your mistake. They do not have different scopes. They are tagged to exist in different logical CUDA memory spaces, but that does not imply a different scope, as C++ defines it. Both are compiled and emitted as symbols within the same compilation unit, which is why a compiler error is emitted.

Upvotes: 1

Related Questions