Skip to content

Commit 3118342

Browse files
authored
[SYCLomatic] Fix the issue that no viable conversion from 'sycl::ext::oneapi::experimental::device_global' to pointer (#2432)
Signed-off-by: intwanghao <[email protected]>
1 parent 3ad9c29 commit 3118342

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

clang/lib/DPCT/ASTTraversal.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8651,7 +8651,17 @@ void MemVarRefMigrationRule::runRule(const MatchFinder::MatchResult &Result) {
86518651
Info->setInitForDeviceGlobal(InitStr);
86528652
}
86538653
}
8654-
if (!Info->getType()->isArray()) {
8654+
auto VarType = Info->getType();
8655+
if (VarType->isArray()) {
8656+
if (const auto *const ICE =
8657+
dyn_cast_or_null<ImplicitCastExpr>(Parent)) {
8658+
if (ICE->getCastKind() == CK_ArrayToPointerDecay) {
8659+
if (!dyn_cast_or_null<ArraySubscriptExpr>(getParentStmt(ICE))) {
8660+
emplaceTransformation(new InsertAfterStmt(MemVarRef, ".get()"));
8661+
}
8662+
}
8663+
}
8664+
} else {
86558665
emplaceTransformation(new InsertAfterStmt(MemVarRef, ".get()"));
86568666
}
86578667
return;

clang/lib/DPCT/AnalysisInfo.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3282,15 +3282,10 @@ std::string MemVarInfo::getMemoryType(const std::string &MemoryType,
32823282
VarType->getDimension(), ">");
32833283
} else if (isUseDeviceGlobal()) {
32843284
std::string Dims;
3285-
std::string Specifier;
32863285
for (auto &D : VarType->getRange()) {
32873286
Dims = Dims + "[" + D.getSize() + "]";
32883287
}
3289-
if (isConstant()) {
3290-
Specifier = "const ";
3291-
}
3292-
return buildString(MemoryType, "<", Specifier, VarType->getBaseName(), Dims,
3293-
">");
3288+
return buildString(MemoryType, "<", VarType->getBaseName(), Dims, ">");
32943289
} else {
32953290
return buildString(MemoryType, VarType->getBaseNameWithoutQualifiers());
32963291
}

clang/test/dpct/device_global/device_global.cu

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ struct B{
2323
// CHECK: /*
2424
// CHECK: DPCT1127:{{[0-9]+}}: The constant compile-time initialization for device_global is supported when compiling with C++20. You may need to adjust the compile commands.
2525
// CHECK: */
26-
// CHECK: static sycl::ext::oneapi::experimental::device_global<const float> var_c{2.f};
26+
// CHECK: static sycl::ext::oneapi::experimental::device_global<float> var_c{2.f};
2727
// CHECK: /*
2828
// CHECK: DPCT1127:{{[0-9]+}}: The constant compile-time initialization for device_global is supported when compiling with C++20. You may need to adjust the compile commands.
2929
// CHECK: */
30-
// CHECK: static sycl::ext::oneapi::experimental::device_global<const float> var_d{1.f};
30+
// CHECK: static sycl::ext::oneapi::experimental::device_global<float> var_d{1.f};
3131
// CHECK: static sycl::ext::oneapi::experimental::device_global<A> var_e;
32-
// CHECK: static sycl::ext::oneapi::experimental::device_global<const B> var_f;
32+
// CHECK: static sycl::ext::oneapi::experimental::device_global<B> var_f;
3333
// CHECK: static dpct::global_memory<int, 0> var_g;
3434
__device__ int var_a;
3535
__device__ int var_b = 0;
@@ -46,12 +46,12 @@ __device__ int var_g;
4646
// CHECK: /*
4747
// CHECK: DPCT1127:{{[0-9]+}}: The constant compile-time initialization for device_global is supported when compiling with C++20. You may need to adjust the compile commands.
4848
// CHECK: */
49-
// CHECK: static sycl::ext::oneapi::experimental::device_global<const int[10]> arr_c{3, 2, 1};
49+
// CHECK: static sycl::ext::oneapi::experimental::device_global<int[10]> arr_c{3, 2, 1};
5050
// CHECK: /*
5151
// CHECK: DPCT1127:{{[0-9]+}}: The constant compile-time initialization for device_global is supported when compiling with C++20. You may need to adjust the compile commands.
5252
// CHECK: */
53-
// CHECK: static sycl::ext::oneapi::experimental::device_global<const int[10]> arr_d{2};
54-
// CHECK: static sycl::ext::oneapi::experimental::device_global<const A[10]> arr_e;
53+
// CHECK: static sycl::ext::oneapi::experimental::device_global<int[10]> arr_d{2};
54+
// CHECK: static sycl::ext::oneapi::experimental::device_global<A[10]> arr_e;
5555
// CHECK: static sycl::ext::oneapi::experimental::device_global<B[10]> arr_f;
5656
__device__ float arr_a[10];
5757
__device__ float arr_b[10] = {1, 2, 3};
@@ -62,6 +62,7 @@ __device__ B arr_f[10];
6262

6363

6464
// CHECK: int device_func() {
65+
// CHECK: float *p = arra_a.get();
6566
// CHECK: arr_a[0] = 1;
6667
// CHECK: return arr_a[0] + arr_b[0] + arr_c[0] + arr_d[0] + arr_e[0].data + arr_f[0].data;
6768
// CHECK: }
@@ -72,6 +73,7 @@ __device__ B arr_f[10];
7273
// CHECK: *ptr = var_a.get() + var_b.get() + var_c.get() + var_d.get() + var_e.get().data + var_f.get().data + device_func();
7374
// CHECK: }
7475
__device__ int device_func() {
76+
float *p = arra_a;
7577
arr_a[0] = 1;
7678
return arr_a[0] + arr_b[0] + arr_c[0] + arr_d[0] + arr_e[0].data + arr_f[0].data;
7779
}

0 commit comments

Comments
 (0)