Skip to content

Commit 8b6f0ab

Browse files
authored
[SYCLomatic] Refine the migration of cub::ShuffleIndex/Up/Down (#2738)
Signed-off-by: intwanghao <hao3.wang@intel.com>
1 parent 48115d2 commit 8b6f0ab

File tree

4 files changed

+37
-22
lines changed

4 files changed

+37
-22
lines changed

clang/lib/DPCT/RulesLangLib/CUB/RewriterUtilityFunctions.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,11 @@ RewriterMap dpct::createUtilityFunctionsRewriterMap() {
336336
"experimental::shift_sub_group_left",
337337
0, 1),
338338
SUBGROUP, ARG(0), ARG(1), ARG(2), ARG(3))),
339-
UNSUPPORT_FACTORY_ENTRY("cub::ShuffleDown",
340-
Diagnostics::API_NOT_MIGRATED,
341-
LITERAL("cub::ShuffleDown"))))
339+
UNSUPPORT_FACTORY_ENTRY(
340+
"cub::ShuffleDown",
341+
Diagnostics::TRY_EXPERIMENTAL_FEATURE,
342+
LITERAL("cub::ShuffleDown"),
343+
LITERAL("--use-experimental-features=non-uniform-groups"))))
342344
// cub::ShuffleUp
343345
SUBGROUPSIZE_FACTORY(
344346
UINT_MAX,
@@ -352,7 +354,8 @@ RewriterMap dpct::createUtilityFunctionsRewriterMap() {
352354
"experimental::shift_sub_group_right",
353355
0, 1),
354356
SUBGROUP, ARG(0), ARG(1), ARG(2), ARG(3))),
355-
UNSUPPORT_FACTORY_ENTRY("cub::ShuffleUp",
356-
Diagnostics::API_NOT_MIGRATED,
357-
LITERAL("cub::ShuffleUp"))))};
357+
UNSUPPORT_FACTORY_ENTRY(
358+
"cub::ShuffleUp", Diagnostics::TRY_EXPERIMENTAL_FEATURE,
359+
LITERAL("cub::ShuffleUp"),
360+
LITERAL("--use-experimental-features=non-uniform-groups"))))};
358361
}

clang/lib/DPCT/RulesLangLib/CUBAPIMigration.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,38 +1081,43 @@ void CubRule::processWarpLevelFuncCall(const CallExpr *CE, bool FuncCallUsed) {
10811081
if (!TA)
10821082
return;
10831083
WarpSize = TA->get(0).getAsIntegral().getExtValue();
1084-
std::string ValueType =
1085-
TA->get(1).getAsType().getUnqualifiedType().getAsString();
10861084
const auto *MemberMask = CE->getArg(2);
1087-
const auto *Mask = dyn_cast<IntegerLiteral>(MemberMask);
10881085
const Expr *Value = CE->getArg(0);
10891086
const Expr *Lane = CE->getArg(1);
10901087
const auto *DeviceFuncDecl = getImmediateOuterFuncDecl(CE);
10911088
ExprAnalysis ValueEA(Value);
10921089
ExprAnalysis LaneEA(Lane);
10931090
llvm::raw_string_ostream OS(Repl);
1094-
if (Mask) {
1091+
1092+
if (const auto *Mask =
1093+
dyn_cast<IntegerLiteral>(MemberMask->IgnoreImplicitAsWritten())) {
10951094
if (Mask->getValue().getZExtValue() == 0xffffffff) {
10961095
OS << MapNames::getDpctNamespace() << "select_from_sub_group("
10971096
<< DpctGlobalInfo::getSubGroup(CE, DeviceFuncDecl) << ", "
10981097
<< ValueEA.getReplacedString() << ", " << LaneEA.getReplacedString();
10991098
if (WarpSize != 32)
11001099
OS << ", " << WarpSize;
11011100
OS << ')';
1102-
} else {
1103-
OS << MapNames::getDpctNamespace() << "experimental::"
1104-
<< "select_from_sub_group(" << getStmtSpelling(Mask) << ", "
1105-
<< DpctGlobalInfo::getSubGroup(CE, DeviceFuncDecl) << ", "
1106-
<< ValueEA.getReplacedString() << ", " << LaneEA.getReplacedString();
1107-
if (WarpSize != 32)
1108-
OS << ", " << WarpSize;
1109-
OS << ')';
1101+
emplaceTransformation(new ReplaceStmt(CE, Repl));
1102+
return;
11101103
}
1104+
}
1105+
if (DpctGlobalInfo::useExpNonUniformGroups()) {
1106+
ExprAnalysis MaskEA(MemberMask);
1107+
OS << MapNames::getDpctNamespace() << "experimental::"
1108+
<< "select_from_sub_group(" << MaskEA.getReplacedString() << ", "
1109+
<< DpctGlobalInfo::getSubGroup(CE, DeviceFuncDecl) << ", "
1110+
<< ValueEA.getReplacedString() << ", " << LaneEA.getReplacedString();
1111+
if (WarpSize != 32)
1112+
OS << ", " << WarpSize;
1113+
OS << ')';
11111114
emplaceTransformation(new ReplaceStmt(CE, Repl));
11121115
} else {
1113-
report(CE->getBeginLoc(), Diagnostics::API_NOT_MIGRATED, false,
1114-
GetFunctionName(CE));
1116+
report(CE->getBeginLoc(), Diagnostics::TRY_EXPERIMENTAL_FEATURE, false,
1117+
"cub::ShuffleIndex",
1118+
"--use-experimental-features=non-uniform-groups");
11151119
}
1120+
return;
11161121
}
11171122
}
11181123

clang/test/dpct/cub/warplevel/shuffle.cu

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ __global__ void ShuffleIndexKernel2(int* data) {
5454
// CHECK: output = dpct::experimental::select_from_sub_group(0xaaaaaaaa, item_ct1.get_sub_group(), input, 0);
5555
output = cub::ShuffleIndex<32>(input, 0, 0xaaaaaaaa);
5656
data[threadid] = output;
57+
// CHECK: vec_output = dpct::select_from_sub_group(item_ct1.get_sub_group(), vec_input, 0);
58+
float2 vec_input, vec_output;
59+
vec_output = cub::ShuffleIndex<32>(vec_input, 0, 0xffffffff);
5760
}
5861

5962
__global__ void ShuffleIndexKernel3(int* data) {

clang/test/dpct/cub/warplevel/shuffle_without_exp.cu

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ __global__ void ShuffleDownKernel(int *data) {
1010
int tid = cub::LaneId();
1111
unsigned mask = 0x8;
1212
int val = tid;
13-
// CHECK: DPCT1007:{{.*}}: Migration of cub::ShuffleDown is not supported.
13+
// CHECK: /*
14+
// CHECK: DPCT1119:{{.*}}: Migration of cub::ShuffleDown is not supported, please try to remigrate with option: --use-experimental-features=non-uniform-groups.
15+
// CHECK: */
1416
data[tid] = cub::ShuffleDown<8>(val, 3, 6, mask);
1517
}
1618

1719
__global__ void ShuffleUpKernel(int *data) {
1820
int tid = cub::LaneId();
1921
unsigned mask = 0x8;
2022
int val = tid;
21-
// CHECK: DPCT1007:{{.*}}: Migration of cub::ShuffleUp is not supported.
23+
// CHECK: /*
24+
// CHECK: DPCT1119:{{.*}}: Migration of cub::ShuffleUp is not supported, please try to remigrate with option: --use-experimental-features=non-uniform-groups.
25+
// CHECK: */
2226
data[tid] = cub::ShuffleUp<8>(val, 3, 6, mask);
2327
}

0 commit comments

Comments
 (0)