forked from kokkos/kokkos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
graph: allow access to native graph object
The native graph objects should be accessible for advanced users.
- Loading branch information
1 parent
20fe702
commit 97a1403
Showing
12 changed files
with
445 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
//@HEADER | ||
// ************************************************************************ | ||
// | ||
// Kokkos v. 4.0 | ||
// Copyright (2022) National Technology & Engineering | ||
// Solutions of Sandia, LLC (NTESS). | ||
// | ||
// Under the terms of Contract DE-NA0003525 with NTESS, | ||
// the U.S. Government retains certain rights in this software. | ||
// | ||
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://kokkos.org/LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//@HEADER | ||
|
||
#include <filesystem> | ||
#include <fstream> | ||
#include <regex> | ||
|
||
#include <TestCuda_Category.hpp> | ||
#include <Kokkos_Core.hpp> | ||
#include <Kokkos_Graph.hpp> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
namespace { | ||
|
||
template <typename ViewType> | ||
struct Increment { | ||
ViewType data; | ||
|
||
KOKKOS_FUNCTION | ||
void operator()(const int) const { ++data(); } | ||
}; | ||
|
||
// This test checks the promises of Kokkos::Graph against its | ||
// underlying Cuda native objects. | ||
TEST(TEST_CATEGORY, graph_promises_on_native_objects) { | ||
auto graph = Kokkos::Experimental::create_graph<Kokkos::Cuda>(); | ||
|
||
auto root = Kokkos::Impl::GraphAccess::create_root_ref(graph); | ||
|
||
// Before instantiation, the Cuda graph is valid, but the Cuda executable | ||
// graph is still null. | ||
cudaGraph_t cuda_graph = graph.native_graph(); | ||
|
||
ASSERT_NE(cuda_graph, nullptr); | ||
ASSERT_EQ(graph.native_graph_exec(), nullptr); | ||
|
||
// After instantiation, both native objects are valid. | ||
graph.instantiate(); | ||
|
||
cudaGraphExec_t cuda_graph_exec = graph.native_graph_exec(); | ||
|
||
ASSERT_EQ(graph.native_graph(), cuda_graph); | ||
ASSERT_NE(cuda_graph_exec, nullptr); | ||
|
||
// Submission should not affect the underlying objects. | ||
graph.submit(); | ||
|
||
ASSERT_EQ(graph.native_graph(), cuda_graph); | ||
ASSERT_EQ(graph.native_graph_exec(), cuda_graph_exec); | ||
} | ||
|
||
// Use native Cuda graph to generate a DOT representation. | ||
TEST(TEST_CATEGORY, graph_instantiate_and_debug_dot_print) { | ||
using view_t = Kokkos::View<int, Kokkos::Cuda>; | ||
|
||
const Kokkos::Cuda exec{}; | ||
|
||
view_t data(Kokkos::view_alloc(exec, "witness")); | ||
|
||
auto graph = Kokkos::Experimental::create_graph(exec); | ||
|
||
auto root = Kokkos::Impl::GraphAccess::create_root_ref(graph); | ||
|
||
root.then_parallel_for(1, Increment<view_t>{data}); | ||
|
||
graph.instantiate(); | ||
|
||
size_t num_nodes = 0; | ||
|
||
KOKKOS_IMPL_CUDA_SAFE_CALL( | ||
cudaGraphGetNodes(graph.native_graph(), nullptr, &num_nodes)); | ||
|
||
ASSERT_EQ(num_nodes, 2u); | ||
|
||
#if CUDA_VERSION >= 11600 | ||
const auto dot = std::filesystem::temp_directory_path() / "cuda_graph.dot"; | ||
|
||
// Convert path to string then to const char * to make it work on Windows. | ||
KOKKOS_IMPL_CUDA_SAFE_CALL( | ||
cudaGraphDebugDotPrint(graph.native_graph(), dot.string().c_str(), | ||
cudaGraphDebugDotFlagsVerbose)); | ||
|
||
ASSERT_TRUE(std::filesystem::exists(dot)); | ||
ASSERT_GT(std::filesystem::file_size(dot), 0u); | ||
|
||
// We could write a check against the full kernel's function signature, but | ||
// it would make the test rely too much on internal implementation details. | ||
// Therefore, we just look for the functor and policy. Note that the | ||
// signature is mangled in the 'dot' output. | ||
const std::string expected("[A-Za-z0-9_]+Increment[A-Za-z0-9_]+RangePolicy"); | ||
|
||
std::stringstream buffer; | ||
buffer << std::ifstream(dot).rdbuf(); | ||
|
||
ASSERT_TRUE(std::regex_search(buffer.str(), std::regex(expected))) | ||
<< "Could not find expected signature regex " << std::quoted(expected) | ||
<< " in " << dot; | ||
|
||
#endif | ||
|
||
#if CUDA_VERSION >= 12000 | ||
unsigned long long flags = | ||
Kokkos::Experimental::finite_max_v<unsigned long long>; | ||
KOKKOS_IMPL_CUDA_SAFE_CALL( | ||
cudaGraphExecGetFlags(graph.native_graph_exec(), &flags)); | ||
|
||
ASSERT_EQ(flags, 0u); | ||
#endif | ||
} | ||
|
||
} // namespace |
Oops, something went wrong.