Skip to content

Commit 3fdc31a

Browse files
[SYCLomatic] Migration of cudaGraphNodeType, cudaGraphNodeGetType (#2760)
Signed-off-by: Daiyaan Ahmed <daiyaan.ahmed@intel.com>
1 parent ff80033 commit 3fdc31a

8 files changed

Lines changed: 197 additions & 15 deletions

File tree

clang/lib/DPCT/RuleInfra/MapNames.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,11 @@ void MapNames::setExplicitNamespaceMap(
628628
DpctGlobalInfo::useExtGraph()
629629
? getClNamespace() + "ext::oneapi::experimental::queue_state"
630630
: "cudaStreamCaptureStatus")},
631+
{"cudaGraphNodeType",
632+
std::make_shared<TypeNameRule>(
633+
DpctGlobalInfo::useExtGraph()
634+
? getClNamespace() + "ext::oneapi::experimental::node_type"
635+
: "cudaGraphNodeType")},
631636
{"CUmem_advise", std::make_shared<TypeNameRule>("int")},
632637
{"CUmemorytype",
633638
std::make_shared<TypeNameRule>(getClNamespace() + "usm::alloc")},
@@ -1092,6 +1097,43 @@ void MapNames::setExplicitNamespaceMap(
10921097
: "cudaStreamCaptureStatusActive")},
10931098
{"cudaStreamCaptureStatusInvalidated",
10941099
std::make_shared<EnumNameRule>("cudaStreamCaptureStatusInvalidated")},
1100+
// enum cudaGraphNodeType
1101+
{"cudaGraphNodeTypeKernel",
1102+
std::make_shared<EnumNameRule>(
1103+
DpctGlobalInfo::useExtGraph()
1104+
? getClNamespace() +
1105+
"ext::oneapi::experimental::node_type::kernel"
1106+
: "cudaGraphNodeTypeKernel")},
1107+
{"cudaGraphNodeTypeMemcpy",
1108+
std::make_shared<EnumNameRule>(
1109+
DpctGlobalInfo::useExtGraph()
1110+
? getClNamespace() +
1111+
"ext::oneapi::experimental::node_type::memcpy"
1112+
: "cudaGraphNodeTypeMemcpy")},
1113+
{"cudaGraphNodeTypeMemset",
1114+
std::make_shared<EnumNameRule>(
1115+
DpctGlobalInfo::useExtGraph()
1116+
? getClNamespace() +
1117+
"ext::oneapi::experimental::node_type::memset"
1118+
: "cudaGraphNodeTypeMemset")},
1119+
{"cudaGraphNodeTypeHost",
1120+
std::make_shared<EnumNameRule>(
1121+
DpctGlobalInfo::useExtGraph()
1122+
? getClNamespace() +
1123+
"ext::oneapi::experimental::node_type::host_task"
1124+
: "cudaGraphNodeTypeHost")},
1125+
{"cudaGraphNodeTypeGraph",
1126+
std::make_shared<EnumNameRule>(
1127+
DpctGlobalInfo::useExtGraph()
1128+
? getClNamespace() +
1129+
"ext::oneapi::experimental::node_type::subgraph"
1130+
: "cudaGraphNodeTypeGraph")},
1131+
{"cudaGraphNodeTypeEmpty",
1132+
std::make_shared<EnumNameRule>(
1133+
DpctGlobalInfo::useExtGraph()
1134+
? getClNamespace() +
1135+
"ext::oneapi::experimental::node_type::empty"
1136+
: "cudaGraphNodeTypeEmpty")},
10951137
// enum CUmem_advise_enum
10961138
{"CU_MEM_ADVISE_SET_READ_MOSTLY", std::make_shared<EnumNameRule>("0")},
10971139
{"CU_MEM_ADVISE_UNSET_READ_MOSTLY", std::make_shared<EnumNameRule>("0")},

clang/lib/DPCT/RulesLang/APINamesGraph.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,13 @@ ASSIGNABLE_FACTORY(CONDITIONAL_FACTORY_ENTRY(
6666
Diagnostics::TRY_EXPERIMENTAL_FEATURE,
6767
ARG("cudaGraphExecUpdate"),
6868
ARG("--use-experimental-features=graph"))))
69+
70+
CONDITIONAL_FACTORY_ENTRY(
71+
UseExtGraph,
72+
ASSIGNABLE_FACTORY(ASSIGN_FACTORY_ENTRY("cudaGraphNodeGetType", DEREF(1),
73+
MEMBER_CALL(ARG(0), true,
74+
"get_type"))),
75+
UNSUPPORT_FACTORY_ENTRY("cudaGraphNodeGetType",
76+
Diagnostics::TRY_EXPERIMENTAL_FEATURE,
77+
ARG("cudaGraphNodeGetType"),
78+
ARG("--use-experimental-features=graph")))

clang/lib/DPCT/RulesLang/RulesLang.cpp

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ void TypeInDeclRule::registerMatcher(MatchFinder &MF) {
347347
"cublasLtMatrixTransformDesc_t", "cudaGraphicsMapFlags",
348348
"cudaGraphicsRegisterFlags", "cudaExternalMemoryHandleType",
349349
"cudaExternalSemaphoreHandleType", "CUstreamCallback",
350-
"cudaHostFn_t", "__nv_half2", "__nv_half"))))))
350+
"cudaHostFn_t", "__nv_half2", "__nv_half",
351+
"cudaGraphNodeType"))))))
351352
.bind("cudaTypeDef"),
352353
this);
353354

@@ -921,6 +922,13 @@ void TypeInDeclRule::runRule(const MatchFinder::MatchResult &Result) {
921922
}
922923
}
923924

925+
if (CanonicalTypeStr == "cudaGraphNodeType") {
926+
if (!DpctGlobalInfo::useExtGraph()) {
927+
report(TL->getBeginLoc(), Diagnostics::TRY_EXPERIMENTAL_FEATURE, false,
928+
"cudaGraphNodeType", "--use-experimental-features=graph");
929+
}
930+
}
931+
924932
if (CanonicalTypeStr == "cudaGraphExecUpdateResult") {
925933
report(TL->getBeginLoc(), Diagnostics::API_NOT_MIGRATED, false,
926934
CanonicalTypeStr);
@@ -1909,17 +1917,17 @@ void DeviceInfoVarRule::runRule(const MatchFinder::MatchResult &Result) {
19091917
// Rule for Enums constants.
19101918
void EnumConstantRule::registerMatcher(MatchFinder &MF) {
19111919
MF.addMatcher(
1912-
declRefExpr(
1913-
to(enumConstantDecl(anyOf(
1914-
hasType(enumDecl(hasAnyName(
1915-
"cudaComputeMode", "cudaMemcpyKind", "cudaMemoryAdvise",
1916-
"cudaStreamCaptureStatus", "cudaDeviceAttr",
1917-
"libraryPropertyType_t", "cudaDataType_t",
1918-
"CUmem_advise_enum", "cufftType_t",
1919-
"cufftType", "cudaMemoryType", "CUctx_flags_enum",
1920-
"CUpointer_attribute_enum", "CUmemorytype_enum",
1921-
"cudaGraphicsMapFlags", "cudaGraphicsRegisterFlags"))),
1922-
matchesName("CUDNN_.*"), matchesName("CUSOLVER_.*")))))
1920+
declRefExpr(to(enumConstantDecl(anyOf(
1921+
hasType(enumDecl(hasAnyName(
1922+
"cudaComputeMode", "cudaMemcpyKind",
1923+
"cudaMemoryAdvise", "cudaStreamCaptureStatus",
1924+
"cudaDeviceAttr", "libraryPropertyType_t",
1925+
"cudaDataType_t", "CUmem_advise_enum", "cufftType_t",
1926+
"cufftType", "cudaMemoryType", "CUctx_flags_enum",
1927+
"CUpointer_attribute_enum", "CUmemorytype_enum",
1928+
"cudaGraphicsMapFlags", "cudaGraphicsRegisterFlags",
1929+
"cudaGraphNodeType"))),
1930+
matchesName("CUDNN_.*"), matchesName("CUSOLVER_.*")))))
19231931
.bind("EnumConstant"),
19241932
this);
19251933
}
@@ -1991,7 +1999,14 @@ void EnumConstantRule::runRule(const MatchFinder::MatchResult &Result) {
19911999
EnumName == "cudaExternalSemaphoreHandleTypeKeyedMutex" ||
19922000
EnumName == "cudaExternalSemaphoreHandleTypeKeyedMutexKmt" ||
19932001
EnumName == "cudaExternalSemaphoreHandleTypeTimelineSemaphoreFd" ||
1994-
EnumName == "cudaExternalSemaphoreHandleTypeTimelineSemaphoreWin32") {
2002+
EnumName == "cudaExternalSemaphoreHandleTypeTimelineSemaphoreWin32" ||
2003+
EnumName == "cudaGraphNodeTypeWaitEvent" ||
2004+
EnumName == "cudaGraphNodeTypeEventRecord" ||
2005+
EnumName == "cudaGraphNodeTypeExtSemaphoreSignal" ||
2006+
EnumName == "cudaGraphNodeTypeExtSemaphoreWait" ||
2007+
EnumName == "cudaGraphNodeTypeMemAlloc" ||
2008+
EnumName == "cudaGraphNodeTypeMemFree" ||
2009+
EnumName == "cudaGraphNodeTypeConditional") {
19952010
report(E->getBeginLoc(), Diagnostics::API_NOT_MIGRATED, false, EnumName);
19962011
return;
19972012
} else if (EnumName == "cudaComputeModeDefault" ||
@@ -2024,6 +2039,16 @@ void EnumConstantRule::runRule(const MatchFinder::MatchResult &Result) {
20242039
report(E->getBeginLoc(), Diagnostics::TRY_EXPERIMENTAL_FEATURE, false,
20252040
EnumName, "--use-experimental-features=bindless_images");
20262041
return;
2042+
} else if (!DpctGlobalInfo::useExtGraph() &&
2043+
(EnumName == "cudaGraphNodeTypeKernel" ||
2044+
EnumName == "cudaGraphNodeTypeMemcpy" ||
2045+
EnumName == "cudaGraphNodeTypeMemset" ||
2046+
EnumName == "cudaGraphNodeTypeHost" ||
2047+
EnumName == "cudaGraphNodeTypeGraph" ||
2048+
EnumName == "cudaGraphNodeTypeEmpty")) {
2049+
report(E->getBeginLoc(), Diagnostics::TRY_EXPERIMENTAL_FEATURE, false,
2050+
EnumName, "--use-experimental-features=graph");
2051+
return;
20272052
} else if (auto ET = dyn_cast<EnumType>(E->getType())) {
20282053
if (auto ETD = ET->getDecl()) {
20292054
auto EnumTypeName = ETD->getName().str();

clang/lib/DPCT/RulesLang/RulesLangGraph.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ void GraphRule::registerMatcher(MatchFinder &MF) {
3232
auto functionName = [&]() {
3333
return hasAnyName("cudaGraphInstantiate", "cudaGraphLaunch",
3434
"cudaGraphExecDestroy", "cudaGraphAddEmptyNode",
35-
"cudaGraphAddDependencies", "cudaGraphExecUpdate");
35+
"cudaGraphAddDependencies", "cudaGraphExecUpdate",
36+
"cudaGraphNodeGetType");
3637
};
3738
MF.addMatcher(
3839
callExpr(callee(functionDecl(functionName()))).bind("FunctionCall"),

clang/lib/DPCT/SrcAPI/APINames.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ ENTRY(cudaGraphNodeGetDependencies_v2, cudaGraphNodeGetDependencies_v2, false, N
479479
ENTRY(cudaGraphNodeGetDependentNodes, cudaGraphNodeGetDependentNodes, false, NO_FLAG, P4, "comment")
480480
ENTRY(cudaGraphNodeGetDependentNodes_v2, cudaGraphNodeGetDependentNodes_v2, false, NO_FLAG, P4, "comment")
481481
ENTRY(cudaGraphNodeGetEnabled, cudaGraphNodeGetEnabled, false, NO_FLAG, P4, "comment")
482-
ENTRY(cudaGraphNodeGetType, cudaGraphNodeGetType, false, NO_FLAG, P4, "comment")
482+
ENTRY(cudaGraphNodeGetType, cudaGraphNodeGetType, true, NO_FLAG, P4, "Successful/DPCT1119")
483483
ENTRY(cudaGraphNodeSetEnabled, cudaGraphNodeSetEnabled, false, NO_FLAG, P4, "comment")
484484
ENTRY(cudaGraphNodeSetParams, cudaGraphNodeSetParams, false, NO_FLAG, P4, "comment")
485485
ENTRY(cudaGraphReleaseUserObject, cudaGraphReleaseUserObject, false, NO_FLAG, P4, "comment")
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// UNSUPPORTED: cuda-8.0, cuda-9.0, cuda-9.1, cuda-9.2, cuda-10.0, cuda-10.1, cuda-10.2, cuda-11.0, cuda-11.1, cuda-11.2, cuda-11.3, cuda-11.4, cuda-11.5, cuda-11.6, cuda-11.7, cuda-11.8, cuda-12.0, cuda-12.1, cuda-12.2, cuda-12.3
2+
// UNSUPPORTED: v8.0, v9.0, v9.1, v9.2, v10.0, v10.1, v10.2, v11.0, v11.1, v11.2, v11.3, v11.4, v11.5, v11.6, v11.7, v11.8, v12.0, v12.1, v12.2, v12.3
3+
// RUN: dpct --use-experimental-features=graph --format-range=none -out-root %T/cudaGraphNodeType_test %s --cuda-include-path="%cuda-path/include" -- -x cuda --cuda-host-only --std=c++14
4+
// RUN: FileCheck --input-file %T/cudaGraphNodeType_test/cudaGraphNodeType_test.dp.cpp --match-full-lines %s
5+
// RUN: %if build_lit %{icpx -c -DNO_BUILD_TEST -fsycl %T/cudaGraphNodeType_test/cudaGraphNodeType_test.dp.cpp -o %T/cudaGraphNodeType_test/cudaGraphNodeType_test.dp.o %}
6+
7+
#include <cuda.h>
8+
#define CUDA_CHECK_THROW(x) \
9+
do { \
10+
cudaError_t _result = x; \
11+
} while (0)
12+
13+
int main() {
14+
// CHECK: sycl::ext::oneapi::experimental::node_type nodeType;
15+
cudaGraphNodeType nodeType;
16+
17+
// CHECK: nodeType = sycl::ext::oneapi::experimental::node_type::kernel;
18+
nodeType = cudaGraphNodeTypeKernel;
19+
20+
// CHECK: nodeType = sycl::ext::oneapi::experimental::node_type::memcpy;
21+
nodeType = cudaGraphNodeTypeMemcpy;
22+
23+
// CHECK: nodeType = sycl::ext::oneapi::experimental::node_type::memset;
24+
nodeType = cudaGraphNodeTypeMemset;
25+
26+
// CHECK: nodeType = sycl::ext::oneapi::experimental::node_type::host_task;
27+
nodeType = cudaGraphNodeTypeHost;
28+
29+
// CHECK: nodeType = sycl::ext::oneapi::experimental::node_type::subgraph;
30+
nodeType = cudaGraphNodeTypeGraph;
31+
32+
// CHECK: nodeType = sycl::ext::oneapi::experimental::node_type::empty;
33+
nodeType = cudaGraphNodeTypeEmpty;
34+
35+
#ifndef NO_BUILD_TEST
36+
37+
// CHECK: /*
38+
// CHECK-NEXT: DPCT1007:{{[0-9]+}}: Migration of cudaGraphNodeTypeWaitEvent is not supported.
39+
// CHECK-NEXT: */
40+
// CHECK-NEXT: nodeType = cudaGraphNodeTypeWaitEvent;
41+
nodeType = cudaGraphNodeTypeWaitEvent;
42+
43+
// CHECK: /*
44+
// CHECK-NEXT: DPCT1007:{{[0-9]+}}: Migration of cudaGraphNodeTypeEventRecord is not supported.
45+
// CHECK-NEXT: */
46+
// CHECK-NEXT: nodeType = cudaGraphNodeTypeEventRecord;
47+
nodeType = cudaGraphNodeTypeEventRecord;
48+
49+
// CHECK: /*
50+
// CHECK-NEXT: DPCT1007:{{[0-9]+}}: Migration of cudaGraphNodeTypeExtSemaphoreSignal is not supported.
51+
// CHECK-NEXT: */
52+
// CHECK-NEXT: nodeType = cudaGraphNodeTypeExtSemaphoreSignal;
53+
nodeType = cudaGraphNodeTypeExtSemaphoreSignal;
54+
55+
// CHECK: /*
56+
// CHECK-NEXT: DPCT1007:{{[0-9]+}}: Migration of cudaGraphNodeTypeExtSemaphoreWait is not supported.
57+
// CHECK-NEXT: */
58+
// CHECK-NEXT: nodeType = cudaGraphNodeTypeExtSemaphoreWait;
59+
nodeType = cudaGraphNodeTypeExtSemaphoreWait;
60+
61+
// CHECK: /*
62+
// CHECK-NEXT: DPCT1007:{{[0-9]+}}: Migration of cudaGraphNodeTypeMemAlloc is not supported.
63+
// CHECK-NEXT: */
64+
// CHECK-NEXT: nodeType = cudaGraphNodeTypeMemAlloc;
65+
nodeType = cudaGraphNodeTypeMemAlloc;
66+
67+
// CHECK: /*
68+
// CHECK-NEXT: DPCT1007:{{[0-9]+}}: Migration of cudaGraphNodeTypeMemFree is not supported.
69+
// CHECK-NEXT: */
70+
// CHECK-NEXT: nodeType = cudaGraphNodeTypeMemFree;
71+
nodeType = cudaGraphNodeTypeMemFree;
72+
73+
// CHECK: /*
74+
// CHECK-NEXT: DPCT1007:{{[0-9]+}}: Migration of cudaGraphNodeTypeConditional is not supported.
75+
// CHECK-NEXT: */
76+
// CHECK-NEXT: nodeType = cudaGraphNodeTypeConditional;
77+
nodeType = cudaGraphNodeTypeConditional;
78+
79+
#endif
80+
81+
return 0;
82+
}

clang/test/dpct/cudaGraph_test.cu

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ int main() {
107107
CUDA_CHECK_THROW(cudaGraphExecUpdate(execGraph, graph, nullptr, nullptr));
108108
#endif
109109

110+
// CHECK: sycl::ext::oneapi::experimental::node_type nodeType;
111+
// CHECK-NEXT: nodeType = node->get_type();
112+
// CHECK-NEXT: CUDA_CHECK_THROW(DPCT_CHECK_ERROR(nodeType = node->get_type()));
113+
cudaGraphNodeType nodeType;
114+
cudaGraphNodeGetType(node, &nodeType);
115+
CUDA_CHECK_THROW(cudaGraphNodeGetType(node, &nodeType));
116+
110117
// CHECK: delete (execGraph);
111118
// CHECK-NEXT: delete (*execGraph2);
112119
// CHECK-NEXT: delete (**execGraph3);

clang/test/dpct/cudaGraph_test_default_option.cu

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,21 @@ int main() {
9797
// CHECK-NEXT: */
9898
cudaGraphExecDestroy(execGraph);
9999

100+
// CHECK: /*
101+
// CHECK-NEXT: DPCT1119:{{[0-9]+}}: Migration of cudaGraphNodeType is not supported, please try to remigrate with option: --use-experimental-features=graph.
102+
// CHECK-NEXT: */
103+
cudaGraphNodeType nodeType;
104+
105+
// CHECK: /*
106+
// CHECK-NEXT: DPCT1119:{{[0-9]+}}: Migration of cudaGraphNodeGetType is not supported, please try to remigrate with option: --use-experimental-features=graph.
107+
// CHECK-NEXT: */
108+
cudaGraphNodeGetType(node, &nodeType);
109+
110+
// CHECK: /*
111+
// CHECK-NEXT: DPCT1119:{{[0-9]+}}: Migration of cudaGraphNodeTypeKernel is not supported, please try to remigrate with option: --use-experimental-features=graph.
112+
// CHECK-NEXT: */
113+
nodeType = cudaGraphNodeTypeKernel;
114+
100115
return 0;
101116
}
102117

0 commit comments

Comments
 (0)