Details
- Reviewers
tra rsmith - Commits
- rGd8805574c183: [CUDA][HIP] Allow non-ODR use of host var in device
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang/test/SemaCUDA/device-use-host-var.cu | ||
---|---|---|
55 | I do not think it should be allowed. We end up instantiating the variable on device, even though the variable should be host-only. Right now we allow it, but end up with an .extern .const which will make ptxas fail: If we do allow it, we'll need to make sure that we only use the value, but do not allow instantiating the variable. |
clang/test/SemaCUDA/device-use-host-var.cu | ||
---|---|---|
55 | will only not allow this since it results in ODR-use of the host var. |
clang/lib/Sema/SemaExpr.cpp | ||
---|---|---|
17134 | I suspect you want hasGlobalStorage rather than isFileVarDecl here (that is, preserve the condition from the deleted code), in order to disallow use of host-side local static variables from device-side functions: __host__ void f() { static int n; struct X { __device__ void g() { ++n; } }; // ... } |
clang/lib/Sema/SemaExpr.cpp | ||
---|---|---|
17134 | For function scope static variable, if the smallest enclosing function is device or device host function, the static variable without __device__ or __constant__ attribute is allowed and the variable is emitted at device side (https://godbolt.org/z/PY5d3WGas). In that case, a device function is allowed to access that static variable even if it does not have __device__ or __constant__ attribute. I will make changes to handle the function scope static variable. |
Small test nit. LGTM otherwise.
clang/test/CodeGenCUDA/device-use-host-var.cu | ||
---|---|---|
23 | Nit: You may want to add a CHECK-LABEL: <function name>. It does not make much of a difference in this file, but is useful in general to explicitly restrict the search scope. |
clang/test/CodeGenCUDA/device-use-host-var.cu | ||
---|---|---|
23 | will do |
I suspect you want hasGlobalStorage rather than isFileVarDecl here (that is, preserve the condition from the deleted code), in order to disallow use of host-side local static variables from device-side functions: