Skip to content

[CUDA] should report error for inline __device__ variable #120516

Open
@aywala

Description

@aywala

see CUDA - inline variable
A namespace scope inline variable declared with device or constant or managed memory space specifier must have internal linkage, if the code is compiled with nvcc in whole program compilation mode.

#include <stdio.h>

__device__ inline int a = 10;

__global__ void kernel() {
    printf("%d\n",a);
}

int main() {
    kernel<<<1,1>>>();
    cudaDeviceSynchronize();
}
nvcc report_error.cu -o report_error
report_error.cu(3): error: An inline __device__/__constant__/__managed__ variable must have internal linkage when the program is compiled in whole program mode (-rdc=false)
  __attribute__((device)) inline int a = 10;
                                     ^

1 error detected in the compilation of "report_error.cu".

but no error report with
clang++ report_error.cu -o report_error --cuda-gpu-arch=sm_52 -L /usr/local/cuda/lib64 -lcudart -pthread

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions