Skip to content

Commit 47db10c

Browse files
authored
[SYCLomatic][ASM] Support migration of PTX instruction "membar" with level on .cta .gl and sys (#2476)
Signed-off-by: chenwei.sun <[email protected]>
1 parent d26e309 commit 47db10c

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

clang/lib/DPCT/RulesAsm/AsmMigration.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,6 @@ class SYCLGen : public SYCLGenBase {
12271227
if (Inst->hasAttr(InstAttr::sc) && Inst->hasAttr(InstAttr::cta)) {
12281228
OS() << MapNames::getClNamespace() << "memory_order::seq_cst,"
12291229
<< MapNames::getClNamespace() << "memory_scope::work_group";
1230-
12311230
} else if (Inst->hasAttr(InstAttr::sc) && Inst->hasAttr(InstAttr::gpu)) {
12321231
OS() << MapNames::getClNamespace() << "memory_order::seq_cst,"
12331232
<< MapNames::getClNamespace() << "memory_scope::device";
@@ -1248,7 +1247,7 @@ class SYCLGen : public SYCLGenBase {
12481247
OS() << MapNames::getClNamespace() << "memory_order::acq_rel,"
12491248
<< MapNames::getClNamespace() << "memory_scope::system";
12501249
} else {
1251-
SYCLGenError();
1250+
return SYCLGenError();
12521251
}
12531252

12541253
OS() << ')';
@@ -1260,6 +1259,28 @@ class SYCLGen : public SYCLGenBase {
12601259
return HandleAddSub(Inst);
12611260
}
12621261

1262+
bool handle_membar(const InlineAsmInstruction *Inst) override {
1263+
if (Inst->getNumInputOperands() != 0)
1264+
return SYCLGenError();
1265+
1266+
OS() << MapNames::getClNamespace() << "atomic_fence("
1267+
<< MapNames::getClNamespace() << "memory_order::seq_cst,";
1268+
1269+
if (Inst->hasAttr(InstAttr::cta)) {
1270+
OS() << MapNames::getClNamespace() << "memory_scope::work_group";
1271+
} else if (Inst->hasAttr(InstAttr::gl)) {
1272+
OS() << MapNames::getClNamespace() << "memory_scope::device";
1273+
} else if (Inst->hasAttr(InstAttr::sys)) {
1274+
OS() << MapNames::getClNamespace() << "memory_scope::system";
1275+
} else {
1276+
return SYCLGenError();
1277+
}
1278+
1279+
OS() << ')';
1280+
endstmt();
1281+
return SYCLGenSuccess();
1282+
}
1283+
12631284
StringRef GetWiderTypeAsString(const InlineAsmBuiltinType *Type) const {
12641285
switch (Type->getKind()) {
12651286
case InlineAsmBuiltinType::s16:

clang/lib/DPCT/RulesAsm/Parser/AsmTokenKinds.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ MODIFIER(down, ".down")
403403
MODIFIER(idx, ".idx")
404404
MODIFIER(bfly, ".bfly")
405405
MODIFIER(sc, ".sc")
406+
MODIFIER(gl, ".gl")
406407

407408
#undef LINKAGE
408409
#undef TARGET

clang/lib/DPCT/SrcAPI/APINames_ASM.inc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ ENTRY("dp4a", "dp4a", true, NO_FLAG, P1, "Successful")
6767
ENTRY("elect", "elect", false, NO_FLAG, P1, "Comment")
6868
ENTRY("ex2", "ex2", true, NO_FLAG, P1, "Successful")
6969
ENTRY("exit", "exit", false, NO_FLAG, P1, "Comment")
70-
ENTRY("fence", "true", false, NO_FLAG, P1,
71-
"Only support thread fence on scope '.cta', '.gpu' and '.sys'")
70+
ENTRY("fence", "true", false, NO_FLAG, P1, "Only support thread fence on scope '.cta', '.gpu' and '.sys'")
7271
ENTRY("fma", "fma", true, NO_FLAG, P1, "Partial")
7372
ENTRY("fns", "fns", false, NO_FLAG, P1, "Comment")
7473
ENTRY("getctarank", "getctarank", false, NO_FLAG, P1, "Comment")
@@ -87,7 +86,7 @@ ENTRY("mapa", "mapa", false, NO_FLAG, P1, "Comment")
8786
ENTRY("match", "match", false, NO_FLAG, P1, "Comment")
8887
ENTRY("max", "max", true, NO_FLAG, P1, "Successful")
8988
ENTRY("mbarrier", "mbarrier", false, NO_FLAG, P1, "Comment")
90-
ENTRY("membar", "membar", false, NO_FLAG, P1, "Comment")
89+
ENTRY("membar", "membar", true, NO_FLAG, P1, "only support level on .cta .gl and sys)
9190
ENTRY("min", "min", true, NO_FLAG, P1, "Successful")
9291
ENTRY("mma", "mma", false, NO_FLAG, P1, "Comment")
9392
ENTRY("mov", "mov", true, NO_FLAG, P1, "Successful")

clang/test/dpct/asm/membar_fence.cu

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,16 @@ __global__ void fence() {
2828
asm volatile("fence.acq_rel.sys; " : : : "memory");
2929
}
3030

31+
__global__ void membar() {
32+
33+
// CHECK: sycl::atomic_fence(sycl::memory_order::seq_cst,sycl::memory_scope::work_group);
34+
asm volatile("membar.cta;":::"memory");
35+
36+
// CHECK: sycl::atomic_fence(sycl::memory_order::seq_cst,sycl::memory_scope::device);
37+
asm volatile("membar.gl;":::"memory");
38+
39+
// CHECK: sycl::atomic_fence(sycl::memory_order::seq_cst,sycl::memory_scope::system);
40+
asm volatile("membar.sys;":::"memory");
41+
}
42+
3143
// clang-format off

0 commit comments

Comments
 (0)