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
af8df13
commit 74b9d8d
Showing
10 changed files
with
358 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//@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 <Kokkos_Core.hpp> | ||
|
||
namespace { | ||
|
||
template <class ExecSpace, class T> | ||
struct SetViewToValueFunctor { | ||
using value_type = T; | ||
using view_type = | ||
Kokkos::View<T, ExecSpace, Kokkos::MemoryTraits<Kokkos::Atomic>>; | ||
view_type v; | ||
T value; | ||
|
||
template <class... Ts> | ||
KOKKOS_FUNCTION void operator()(Ts&&...) const noexcept { | ||
v() = value; | ||
} | ||
}; | ||
|
||
} // namespace |
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,105 @@ | ||
//@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 <TestCuda_Category.hpp> | ||
#include <TestGraph_helpers.hpp> | ||
#include <Kokkos_Graph.hpp> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
namespace { | ||
|
||
// 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); | ||
|
||
auto graph_ptr_impl = | ||
Kokkos::Impl::GraphAccess::get_graph_weak_ptr(root).lock(); | ||
|
||
static_assert(std::is_same_v<decltype(graph_ptr_impl)::element_type, | ||
Kokkos::Impl::GraphImpl<Kokkos::Cuda>>); | ||
|
||
// Before instantiation, the Cuda graph is valid, but the Cuda executable | ||
// graph is still null. | ||
cudaGraph_t cuda_graph = graph_ptr_impl->get_cuda_graph(); | ||
|
||
ASSERT_NE(cuda_graph, nullptr); | ||
ASSERT_EQ(graph_ptr_impl->get_cuda_graph_exec(), nullptr); | ||
|
||
// After instantiation, both native objects are valid. | ||
graph.instantiate(); | ||
|
||
cudaGraphExec_t cuda_graph_exec = graph_ptr_impl->get_cuda_graph_exec(); | ||
|
||
ASSERT_EQ(graph_ptr_impl->get_cuda_graph(), cuda_graph); | ||
ASSERT_NE(cuda_graph_exec, nullptr); | ||
|
||
// Submission should not affect the underlying objects. | ||
graph.submit(); | ||
|
||
ASSERT_EQ(graph_ptr_impl->get_cuda_graph(), cuda_graph); | ||
ASSERT_EQ(graph_ptr_impl->get_cuda_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, SetViewToValueFunctor<Kokkos::Cuda, int>{data, 1}); | ||
|
||
auto graph_ptr_impl = | ||
Kokkos::Impl::GraphAccess::get_graph_weak_ptr(root).lock(); | ||
|
||
graph.instantiate(); | ||
|
||
size_t num_nodes = 0; | ||
|
||
KOKKOS_IMPL_CUDA_SAFE_CALL( | ||
cudaGraphGetNodes(graph_ptr_impl->get_cuda_graph(), nullptr, &num_nodes)); | ||
|
||
ASSERT_EQ(num_nodes, 2u); | ||
|
||
const auto dot = std::filesystem::temp_directory_path() / "cuda_graph.dot"; | ||
|
||
KOKKOS_IMPL_CUDA_SAFE_CALL( | ||
cudaGraphDebugDotPrint(graph_ptr_impl->get_cuda_graph(), dot.c_str(), | ||
cudaGraphDebugDotFlagsVerbose)); | ||
|
||
ASSERT_TRUE(std::filesystem::exists(dot)); | ||
ASSERT_GT(std::filesystem::file_size(dot), 0u); | ||
|
||
unsigned long long flags = | ||
Kokkos::Experimental::finite_max_v<unsigned long long>; | ||
KOKKOS_IMPL_CUDA_SAFE_CALL( | ||
cudaGraphExecGetFlags(graph_ptr_impl->get_cuda_graph_exec(), &flags)); | ||
|
||
ASSERT_EQ(flags, 0u); | ||
} | ||
|
||
} // namespace |
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,98 @@ | ||
//@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 <TestHIP_Category.hpp> | ||
#include <TestGraph_helpers.hpp> | ||
#include <Kokkos_Graph.hpp> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
namespace { | ||
|
||
// This test checks the promises of Kokkos::Graph against its | ||
// underlying HIP native objects. | ||
TEST(TEST_CATEGORY, graph_promises_on_native_objects) { | ||
auto graph = Kokkos::Experimental::create_graph<Kokkos::HIP>(); | ||
|
||
auto root = Kokkos::Impl::GraphAccess::create_root_ref(graph); | ||
|
||
auto graph_ptr_impl = | ||
Kokkos::Impl::GraphAccess::get_graph_weak_ptr(root).lock(); | ||
|
||
static_assert(std::is_same_v<decltype(graph_ptr_impl)::element_type, | ||
Kokkos::Impl::GraphImpl<Kokkos::HIP>>); | ||
|
||
// Before instantiation, the HIP graph is valid, but the HIP executable | ||
// graph is still null. | ||
hipGraph_t hip_graph = graph_ptr_impl->get_hip_graph(); | ||
|
||
ASSERT_NE(hip_graph, nullptr); | ||
ASSERT_EQ(graph_ptr_impl->get_hip_graph_exec(), nullptr); | ||
|
||
// After instantiation, both native objects are valid. | ||
graph.instantiate(); | ||
|
||
hipGraphExec_t hip_graph_exec = graph_ptr_impl->get_hip_graph_exec(); | ||
|
||
ASSERT_EQ(graph_ptr_impl->get_hip_graph(), hip_graph); | ||
ASSERT_NE(hip_graph_exec, nullptr); | ||
|
||
// Submission should not affect the underlying objects. | ||
graph.submit(); | ||
|
||
ASSERT_EQ(graph_ptr_impl->get_hip_graph(), hip_graph); | ||
ASSERT_EQ(graph_ptr_impl->get_hip_graph_exec(), hip_graph_exec); | ||
} | ||
|
||
// Use native HIP graph to generate a DOT representation. | ||
TEST(TEST_CATEGORY, graph_instantiate_and_debug_dot_print) { | ||
using view_t = Kokkos::View<int, Kokkos::HIP>; | ||
|
||
const Kokkos::HIP 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, SetViewToValueFunctor<Kokkos::HIP, int>{data, 1}); | ||
|
||
auto graph_ptr_impl = | ||
Kokkos::Impl::GraphAccess::get_graph_weak_ptr(root).lock(); | ||
|
||
graph.instantiate(); | ||
|
||
size_t num_nodes = 0; | ||
|
||
KOKKOS_IMPL_HIP_SAFE_CALL( | ||
hipGraphGetNodes(graph_ptr_impl->get_hip_graph(), nullptr, &num_nodes)); | ||
|
||
ASSERT_EQ(num_nodes, 2u); | ||
|
||
const auto dot = std::filesystem::temp_directory_path() / "hip_graph.dot"; | ||
|
||
KOKKOS_IMPL_HIP_SAFE_CALL( | ||
hipGraphDebugDotPrint(graph_ptr_impl->get_hip_graph(), dot.c_str(), | ||
hipGraphDebugDotFlagsVerbose)); | ||
|
||
ASSERT_TRUE(std::filesystem::exists(dot)); | ||
ASSERT_GT(std::filesystem::file_size(dot), 0u); | ||
} | ||
|
||
} // namespace |
Oops, something went wrong.