<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/147373>147373</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang does not treat __managed__ variables like nvcc
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
cbuchner1
</td>
</tr>
</table>
<pre>
Hi,
I am having difficulty declaring__managed__ variables with clang++. I am trying this with clang-20 and CUDA toolkit 12.1 which is supposed to be supported.
The declaration (in global scope)
__managed__ int val;
leads to clang++-20 (also clang++-17) output the warning
test.cu:1:1: warning: 'managed' attribute ignored [-Wignored-attributes]
1 | __managed__ int val;
The variable val will not be accessible from __device__ functions and __global__ kernels and it leads to compilation errors.
Here is a short reproducer
`__managed__ int val;
#include <cstdio>
__device__ void test_devicefunc()
{
printf("devicefunc val=%d\n", val);
}
__global__ void test_kernel()
{
printf("kernel val=%d\n", val);
test_devicefunc();
}
int main(int argc, char *argv[])
{
val = 100;
test_kernel<<<1, 1>>>();
cudaDeviceSynchronize();
return 0;
}`
The same code compiles fine with nvcc and creates the output
kernel val=100
devicefunc val=100
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyEVE2vqzYQ_TWTzehGxoQQFixI0uh13VZdImNPwL2OHdkmV7e_vjJw8_HavicRRcwMc86c-RAh6N4S1VDsoTiuxBgH52vZjXKw5LNV59Rn_U0DPwBrgDW_orjgIG7a9qj0-azlaOInKpJGeG37tr0IK3pSbYs34bXoDAXEDx0HlEbYHvge-H6NU6LoP1OiOOjwFPLGGQqr8PDHscHonHnXETO-zvBj0HJAHTCM16sLpDA67Gh-9ZHUemb5-0ALJRG1swh8py32xnXCYJDuSsCrOfSZsLYRb8JAvp99hoQKCeKJeSIHfCdMeDVnJfAK3RivY8Q4EH4Ib7Xt50yRQlzLEfImW353f94g8HIhAbxEEaPX3RgJdW-dJ4VQ7N_-X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