Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYCLomatic] Add migration for cudaGraphGetNodes, cudaGraphGetRootNodes #2600

Open
wants to merge 5 commits into
base: SYCLomatic
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions clang/lib/DPCT/RulesLang/APINamesGraph.inc
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,24 @@ 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"))))
3 changes: 2 additions & 1 deletion clang/lib/DPCT/RulesLang/RulesLangGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/DPCT/SrcAPI/APINames.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
36 changes: 36 additions & 0 deletions clang/runtime/dpct-rt/include/dpct/graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have 1 question here.
nodes is std::vector, if more nodes are pushed into that vector, the underlying memory may reallocated and elements will be copied to the new memory. So the address assigned to nodesArray[i] will be invalid at that time. Will that case happen?

}
}

/// 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
17 changes: 17 additions & 0 deletions clang/test/dpct/cudaGraph_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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_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));

// 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);
Expand Down
11 changes: 10 additions & 1 deletion clang/test/dpct/cudaGraph_test_default_option.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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: */
Expand All @@ -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: */
Expand Down