Skip to content

Commit b0a8698

Browse files
committed
Make compat with full device_global impl.
Signed-off-by: JackAKirk <[email protected]>
1 parent 8c38eda commit b0a8698

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5759,9 +5759,15 @@ LangAS CodeGenModule::GetGlobalVarAddressSpace(const VarDecl *D) {
57595759
if (Scope && Scope->isWorkGroup())
57605760
return LangAS::sycl_local;
57615761

5762-
const RecordDecl *RD = D->getType()->getAsRecordDecl();
5763-
if (getTriple().isNVPTX() && RD && RD->hasAttr<SYCLDeviceGlobalAttr>() && D->getType().isConstQualified())
5764-
return LangAS::cuda_constant;
5762+
if (getTriple().isNVPTX() || getTriple().isAMDGPU()) {
5763+
const RecordDecl *RD = D->getType()->getAsRecordDecl();
5764+
if (RD && RD->hasAttr<SYCLDeviceGlobalAttr>()) {
5765+
clang::CXXRecordDecl *record = D->getType()->getAsCXXRecordDecl();
5766+
const auto *Spec = cast<ClassTemplateSpecializationDecl>(record);
5767+
if (Spec->getTemplateArgs().get(0).getAsType().isConstQualified())
5768+
return LangAS::opencl_constant;
5769+
}
5770+
}
57655771
}
57665772

57675773
if (LangOpts.SYCLIsDevice &&
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %{build} -o %t.out
2+
// RUN: %{run} %t.out
3+
//
4+
// The OpenCL GPU backends do not currently support device_global backend
5+
// calls.
6+
//
7+
// UNSUPPORTED: opencl && gpu
8+
9+
#include "common.hpp"
10+
11+
device_global<const int, TestProperties> DeviceGlobalVar;
12+
13+
int main() {
14+
queue Q;
15+
16+
int HostVal = 42;
17+
Q.memcpy(DeviceGlobalVar, &HostVal);
18+
Q.wait();
19+
int OutVal = 0;
20+
21+
{
22+
buffer<int, 1> OutBuf(&OutVal, 1);
23+
Q.submit([&](handler &CGH) {
24+
auto OutAcc = OutBuf.get_access<access::mode::write>(CGH);
25+
CGH.single_task([=]() { OutAcc[0] = DeviceGlobalVar.get(); });
26+
});
27+
}
28+
29+
assert(OutVal == 42 && "Read value does not match.");
30+
return 0;
31+
}

0 commit comments

Comments
 (0)