From 9e570d1e1a1b23247344af2edb1910ab88679d08 Mon Sep 17 00:00:00 2001 From: "Ahmed, Daiyaan" Date: Tue, 7 Jan 2025 14:01:27 +0800 Subject: [PATCH 1/5] [SYCLomatic] Add migration for cudaGraphGetNodes, cudaGraphGetRootNodes Signed-off-by: Ahmed, Daiyaan --- clang/lib/DPCT/RulesLang/APINamesGraph.inc | 22 ++++++++++++ clang/lib/DPCT/RulesLang/RulesLangGraph.cpp | 3 +- clang/lib/DPCT/SrcAPI/APINames.inc | 4 +-- clang/runtime/dpct-rt/include/dpct/graph.hpp | 36 +++++++++++++++++++ clang/test/dpct/cudaGraph_test.cu | 17 +++++++++ .../dpct/cudaGraph_test_default_option.cu | 11 +++++- 6 files changed, 89 insertions(+), 4 deletions(-) diff --git a/clang/lib/DPCT/RulesLang/APINamesGraph.inc b/clang/lib/DPCT/RulesLang/APINamesGraph.inc index e72b6c3f1cfd..de29f9ec9ab7 100644 --- a/clang/lib/DPCT/RulesLang/APINamesGraph.inc +++ b/clang/lib/DPCT/RulesLang/APINamesGraph.inc @@ -66,3 +66,25 @@ ASSIGNABLE_FACTORY(CONDITIONAL_FACTORY_ENTRY( Diagnostics::TRY_EXPERIMENTAL_FEATURE, ARG("cudaGraphExecUpdate"), ARG("--use-experimental-features=graph")))) + +ASSIGNABLE_FACTORY(CONDITIONAL_FACTORY_ENTRY( + UseExtGraph, + CALL_FACTORY_ENTRY("cudaGraphGetNodes", + CALL(MapNames::getDpctNamespace() + + "experimental::get_nodes", + ARG(0), ARG(1), ARG(2))), + UNSUPPORT_FACTORY_ENTRY("cudaGraphGetNodes", + Diagnostics::TRY_EXPERIMENTAL_FEATURE, + ARG("cudaGraphGetNodes"), + ARG("--use-experimental-features=graph")))) + +ASSIGNABLE_FACTORY(CONDITIONAL_FACTORY_ENTRY( + UseExtGraph, + CALL_FACTORY_ENTRY("cudaGraphGetRootNodes", + CALL(MapNames::getDpctNamespace() + + "experimental::get_root_nodes", + ARG(0), ARG(1), ARG(2))), + UNSUPPORT_FACTORY_ENTRY("cudaGraphGetRootNodes", + Diagnostics::TRY_EXPERIMENTAL_FEATURE, + ARG("cudaGraphGetRootNodes"), + ARG("--use-experimental-features=graph")))) diff --git a/clang/lib/DPCT/RulesLang/RulesLangGraph.cpp b/clang/lib/DPCT/RulesLang/RulesLangGraph.cpp index 8e5c61f0b59c..d8139d16c3f9 100644 --- a/clang/lib/DPCT/RulesLang/RulesLangGraph.cpp +++ b/clang/lib/DPCT/RulesLang/RulesLangGraph.cpp @@ -32,7 +32,8 @@ void GraphRule::registerMatcher(MatchFinder &MF) { auto functionName = [&]() { return hasAnyName("cudaGraphInstantiate", "cudaGraphLaunch", "cudaGraphExecDestroy", "cudaGraphAddEmptyNode", - "cudaGraphAddDependencies", "cudaGraphExecUpdate"); + "cudaGraphAddDependencies", "cudaGraphExecUpdate", + "cudaGraphGetNodes", "cudaGraphGetRootNodes"); }; MF.addMatcher( callExpr(callee(functionDecl(functionName()))).bind("FunctionCall"), diff --git a/clang/lib/DPCT/SrcAPI/APINames.inc b/clang/lib/DPCT/SrcAPI/APINames.inc index adf71b72a25b..95c156d20eb9 100644 --- a/clang/lib/DPCT/SrcAPI/APINames.inc +++ b/clang/lib/DPCT/SrcAPI/APINames.inc @@ -447,8 +447,8 @@ ENTRY(cudaGraphExternalSemaphoresWaitNodeGetParams, cudaGraphExternalSemaphoresW ENTRY(cudaGraphExternalSemaphoresWaitNodeSetParams, cudaGraphExternalSemaphoresWaitNodeSetParams, false, NO_FLAG, P4, "comment") ENTRY(cudaGraphGetEdges, cudaGraphGetEdges, false, NO_FLAG, P4, "comment") ENTRY(cudaGraphGetEdges_v2, cudaGraphGetEdges_v2, false, NO_FLAG, P4, "comment") -ENTRY(cudaGraphGetNodes, cudaGraphGetNodes, false, NO_FLAG, P4, "comment") -ENTRY(cudaGraphGetRootNodes, cudaGraphGetRootNodes, false, NO_FLAG, P4, "comment") +ENTRY(cudaGraphGetNodes, cudaGraphGetNodes, true, NO_FLAG, P4, "Successful/DPCT1119") +ENTRY(cudaGraphGetRootNodes, cudaGraphGetRootNodes, true, NO_FLAG, P4, "Successful/DPCT1119") ENTRY(cudaGraphHostNodeGetParams, cudaGraphHostNodeGetParams, false, NO_FLAG, P4, "comment") ENTRY(cudaGraphHostNodeSetParams, cudaGraphHostNodeSetParams, false, NO_FLAG, P4, "comment") ENTRY(cudaGraphInstantiate, cudaGraphInstantiate, true, NO_FLAG, P4, "Successful/DPCT1119") diff --git a/clang/runtime/dpct-rt/include/dpct/graph.hpp b/clang/runtime/dpct-rt/include/dpct/graph.hpp index fbb90aa69543..eb88194d9afa 100644 --- a/clang/runtime/dpct-rt/include/dpct/graph.hpp +++ b/clang/runtime/dpct-rt/include/dpct/graph.hpp @@ -133,5 +133,41 @@ static void add_dependencies(dpct::experimental::command_graph_ptr graph, } } +/// Gets the nodes in the command graph. +/// \param [in] graph A pointer to the command graph. +/// \param [out] nodesArray An array of node pointers where the +/// nodes will be assigned. +/// \param [out] numberOfNodes The number of nodes in the graph. +static void get_nodes(dpct::experimental::command_graph_ptr graph, + dpct::experimental::node_ptr *nodesArray, + std::size_t *numberOfNodes) { + auto nodes = graph->get_nodes(); + *numberOfNodes = nodes.size(); + if (!nodesArray) { + return; + } + for (std::size_t i = 0; i < *numberOfNodes; i++) { + nodesArray[i] = &nodes[i]; + } +} + +/// Gets the root nodes in the command graph. +/// \param [in] graph A pointer to the command graph. +/// \param [out] nodesArray An array of node pointers where the +/// root nodes will be assigned. +/// \param [out] numberOfNodes The number of root nodes in the graph. +static void get_root_nodes(dpct::experimental::command_graph_ptr graph, + dpct::experimental::node_ptr *nodesArray, + std::size_t *numberOfNodes) { + auto nodes = graph->get_root_nodes(); + *numberOfNodes = nodes.size(); + if (!nodesArray) { + return; + } + for (std::size_t i = 0; i < *numberOfNodes; i++) { + nodesArray[i] = &nodes[i]; + } +} + } // namespace experimental } // namespace dpct diff --git a/clang/test/dpct/cudaGraph_test.cu b/clang/test/dpct/cudaGraph_test.cu index 8d07cf610f75..71e99a8c9e05 100644 --- a/clang/test/dpct/cudaGraph_test.cu +++ b/clang/test/dpct/cudaGraph_test.cu @@ -70,6 +70,23 @@ int main() { // CHECK: dpct::experimental::add_empty_node(&node, graph, node10, 1); cudaGraphAddEmptyNode(&node, graph, node10, 1); + size_t *numNodes; + // CHECK: dpct::experimental::get_nodes(graph, node2, numNodes); + // CHECK-NEXT: CUDA_CHECK_THROW(DPCT_CHECK_ERROR(dpct::experimental::get_nodes(graph, node2, numNodes))); + cudaGraphGetNodes(graph, node4, numNodes); + CUDA_CHECK_THROW(cudaGraphGetNodes(graph, node4, numNodes)); + + // CHECK: dpct::experimental::get_nodes(*graph2, node5, numNodes); + cudaGraphGetNodes(*graph2, node5, numNodes); + + // CHECK: dpct::experimental::get_nodes(graph, node2, numNodes); + // CHECK-NEXT: CUDA_CHECK_THROW(DPCT_CHECK_ERROR(dpct::experimental::get_nodes(graph, node2, numNodes))); + cudaGraphGetRootNodes(graph, node4, numNodes); + CUDA_CHECK_THROW(cudaGraphGetRootNodes(graph, node4, numNodes)); + + // CHECK: dpct::experimental::get_root_nodes(*graph2, node5, numNodes); + cudaGraphGetRootNodes(*graph2, node5, numNodes); + // CHECK: dpct::experimental::add_dependencies(graph, node4, node5, 10); // CHECK-NEXT: CUDA_CHECK_THROW(DPCT_CHECK_ERROR(dpct::experimental::add_dependencies(graph, node4, node5, 10))); cudaGraphAddDependencies(graph, node4, node5, 10); diff --git a/clang/test/dpct/cudaGraph_test_default_option.cu b/clang/test/dpct/cudaGraph_test_default_option.cu index f1574548cb0e..947b449d00e9 100644 --- a/clang/test/dpct/cudaGraph_test_default_option.cu +++ b/clang/test/dpct/cudaGraph_test_default_option.cu @@ -51,7 +51,6 @@ int main() { // CHECK-NEXT: */ captureStatus = cudaStreamCaptureStatusInvalidated; - // CHECK: /* // CHECK-NEXT: DPCT1119:{{[0-9]+}}: Migration of cudaStreamIsCapturing is not supported, please try to remigrate with option: --use-experimental-features=graph. // CHECK-NEXT: */ @@ -72,6 +71,16 @@ int main() { // CHECK-NEXT: */ cudaGraphAddDependencies(graph, NULL, NULL, 0); + // CHECK: /* + // CHECK-NEXT: DPCT1119:{{[0-9]+}}: Migration of cudaGraphGetNodes is not supported, please try to remigrate with option: --use-experimental-features=graph. + // CHECK-NEXT: */ + cudaGraphGetNodes(graph, NULL, nullptr); + + // CHECK: /* + // CHECK-NEXT: DPCT1119:{{[0-9]+}}: Migration of cudaGraphGetRootNodes is not supported, please try to remigrate with option: --use-experimental-features=graph. + // CHECK-NEXT: */ + cudaGraphGetRootNodes(graph, NULL, nullptr); + // CHECK: /* // CHECK-NEXT: DPCT1119:{{[0-9]+}}: Migration of cudaGraphInstantiate is not supported, please try to remigrate with option: --use-experimental-features=graph. // CHECK-NEXT: */ From 71b64d3507a5aa815b5ee23d500266054bacb809 Mon Sep 17 00:00:00 2001 From: "Ahmed, Daiyaan" Date: Tue, 7 Jan 2025 14:28:42 +0800 Subject: [PATCH 2/5] Fix clang format Signed-off-by: Ahmed, Daiyaan --- clang/lib/DPCT/RulesLang/APINamesGraph.inc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/clang/lib/DPCT/RulesLang/APINamesGraph.inc b/clang/lib/DPCT/RulesLang/APINamesGraph.inc index de29f9ec9ab7..0b1f8f091c9d 100644 --- a/clang/lib/DPCT/RulesLang/APINamesGraph.inc +++ b/clang/lib/DPCT/RulesLang/APINamesGraph.inc @@ -69,10 +69,9 @@ ASSIGNABLE_FACTORY(CONDITIONAL_FACTORY_ENTRY( ASSIGNABLE_FACTORY(CONDITIONAL_FACTORY_ENTRY( UseExtGraph, - CALL_FACTORY_ENTRY("cudaGraphGetNodes", - CALL(MapNames::getDpctNamespace() + - "experimental::get_nodes", - ARG(0), ARG(1), ARG(2))), + CALL_FACTORY_ENTRY("cudaGraphGetNodes", CALL(MapNames::getDpctNamespace() + + "experimental::get_nodes", + ARG(0), ARG(1), ARG(2))), UNSUPPORT_FACTORY_ENTRY("cudaGraphGetNodes", Diagnostics::TRY_EXPERIMENTAL_FEATURE, ARG("cudaGraphGetNodes"), From 872e5846b7c984918557a819c10df904a0b6556e Mon Sep 17 00:00:00 2001 From: "Ahmed, Daiyaan" Date: Tue, 7 Jan 2025 15:23:25 +0800 Subject: [PATCH 3/5] Fix LIT test Signed-off-by: Ahmed, Daiyaan --- clang/test/dpct/cudaGraph_test.cu | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/test/dpct/cudaGraph_test.cu b/clang/test/dpct/cudaGraph_test.cu index 71e99a8c9e05..f8a0473810d4 100644 --- a/clang/test/dpct/cudaGraph_test.cu +++ b/clang/test/dpct/cudaGraph_test.cu @@ -79,8 +79,8 @@ int main() { // CHECK: dpct::experimental::get_nodes(*graph2, node5, numNodes); cudaGraphGetNodes(*graph2, node5, numNodes); - // CHECK: dpct::experimental::get_nodes(graph, node2, numNodes); - // CHECK-NEXT: CUDA_CHECK_THROW(DPCT_CHECK_ERROR(dpct::experimental::get_nodes(graph, node2, numNodes))); + // CHECK: dpct::experimental::get_nodes(graph, node4, numNodes); + // CHECK-NEXT: CUDA_CHECK_THROW(DPCT_CHECK_ERROR(dpct::experimental::get_nodes(graph, node4, numNodes))); cudaGraphGetRootNodes(graph, node4, numNodes); CUDA_CHECK_THROW(cudaGraphGetRootNodes(graph, node4, numNodes)); From 7b9f24ab4d1d1c024b69609fd7a2b282a525b989 Mon Sep 17 00:00:00 2001 From: "Ahmed, Daiyaan" Date: Tue, 7 Jan 2025 15:24:12 +0800 Subject: [PATCH 4/5] Fix LIT test Signed-off-by: Ahmed, Daiyaan --- clang/test/dpct/cudaGraph_test.cu | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/test/dpct/cudaGraph_test.cu b/clang/test/dpct/cudaGraph_test.cu index f8a0473810d4..272ea1a499c6 100644 --- a/clang/test/dpct/cudaGraph_test.cu +++ b/clang/test/dpct/cudaGraph_test.cu @@ -71,8 +71,8 @@ int main() { cudaGraphAddEmptyNode(&node, graph, node10, 1); size_t *numNodes; - // CHECK: dpct::experimental::get_nodes(graph, node2, numNodes); - // CHECK-NEXT: CUDA_CHECK_THROW(DPCT_CHECK_ERROR(dpct::experimental::get_nodes(graph, node2, numNodes))); + // CHECK: dpct::experimental::get_nodes(graph, node4, numNodes); + // CHECK-NEXT: CUDA_CHECK_THROW(DPCT_CHECK_ERROR(dpct::experimental::get_nodes(graph, node4 numNodes))); cudaGraphGetNodes(graph, node4, numNodes); CUDA_CHECK_THROW(cudaGraphGetNodes(graph, node4, numNodes)); From 51cdddb9dce53760ab06c95bbaca8298e74f72c7 Mon Sep 17 00:00:00 2001 From: "Ahmed, Daiyaan" Date: Tue, 7 Jan 2025 20:10:37 +0800 Subject: [PATCH 5/5] Fix LIT test Signed-off-by: Ahmed, Daiyaan --- clang/test/dpct/cudaGraph_test.cu | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/test/dpct/cudaGraph_test.cu b/clang/test/dpct/cudaGraph_test.cu index 272ea1a499c6..c9d22786a99c 100644 --- a/clang/test/dpct/cudaGraph_test.cu +++ b/clang/test/dpct/cudaGraph_test.cu @@ -72,15 +72,15 @@ int main() { size_t *numNodes; // CHECK: dpct::experimental::get_nodes(graph, node4, numNodes); - // CHECK-NEXT: CUDA_CHECK_THROW(DPCT_CHECK_ERROR(dpct::experimental::get_nodes(graph, node4 numNodes))); + // CHECK-NEXT: CUDA_CHECK_THROW(DPCT_CHECK_ERROR(dpct::experimental::get_nodes(graph, node4, numNodes))); cudaGraphGetNodes(graph, node4, numNodes); CUDA_CHECK_THROW(cudaGraphGetNodes(graph, node4, numNodes)); // CHECK: dpct::experimental::get_nodes(*graph2, node5, numNodes); cudaGraphGetNodes(*graph2, node5, numNodes); - // CHECK: dpct::experimental::get_nodes(graph, node4, numNodes); - // CHECK-NEXT: CUDA_CHECK_THROW(DPCT_CHECK_ERROR(dpct::experimental::get_nodes(graph, node4, numNodes))); + // CHECK: dpct::experimental::get_root_nodes(graph, node4, numNodes); + // CHECK-NEXT: CUDA_CHECK_THROW(DPCT_CHECK_ERROR(dpct::experimental::get_root_nodes(graph, node4, numNodes))); cudaGraphGetRootNodes(graph, node4, numNodes); CUDA_CHECK_THROW(cudaGraphGetRootNodes(graph, node4, numNodes));