From 9e0c05abae2ab17eedcc0952f572f9c041c9c953 Mon Sep 17 00:00:00 2001 From: Ben Tracy Date: Thu, 28 Nov 2024 13:41:00 +0000 Subject: [PATCH] [SYCL][Graph] Implement ext_oneapi_weak_object for command_graph class - Add owner_less and weak_object support for the command_graph class - Unit test which creates objects for all graph states and tests using them in a map --- .../sycl/ext/oneapi/experimental/graph.hpp | 7 ++-- sycl/include/sycl/ext/oneapi/owner_less.hpp | 33 +++++++++-------- .../Extensions/CommandGraph/CommandGraph.cpp | 36 +++++++++++++++++++ 3 files changed, 60 insertions(+), 16 deletions(-) diff --git a/sycl/include/sycl/ext/oneapi/experimental/graph.hpp b/sycl/include/sycl/ext/oneapi/experimental/graph.hpp index 9cca0ed2aa532..88385a6f5ba34 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/graph.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/graph.hpp @@ -12,6 +12,7 @@ #include // for context #include // for __SYCL_EXPORT #include // for kernel_param_kind_t +#include // for OwnerLessBase #include // for DataLessPropKind, PropWith... #ifdef __INTEL_PREVIEW_BREAKING_CHANGES #include @@ -236,7 +237,8 @@ class __SYCL_EXPORT dynamic_command_group { namespace detail { // Templateless modifiable command-graph base class. -class __SYCL_EXPORT modifiable_command_graph { +class __SYCL_EXPORT modifiable_command_graph + : public sycl::detail::OwnerLessBase { public: /// Constructor. /// @param SyclContext Context to use for graph. @@ -390,7 +392,8 @@ class __SYCL_EXPORT modifiable_command_graph { }; // Templateless executable command-graph base class. -class __SYCL_EXPORT executable_command_graph { +class __SYCL_EXPORT executable_command_graph + : public sycl::detail::OwnerLessBase { public: /// An executable command-graph is not user constructable. executable_command_graph() = delete; diff --git a/sycl/include/sycl/ext/oneapi/owner_less.hpp b/sycl/include/sycl/ext/oneapi/owner_less.hpp index a69072652c5b7..265761a42f3c6 100644 --- a/sycl/include/sycl/ext/oneapi/owner_less.hpp +++ b/sycl/include/sycl/ext/oneapi/owner_less.hpp @@ -8,20 +8,21 @@ #pragma once -#include // for access_mode -#include // for host_acce... -#include // for accessor -#include // for context -#include // for device -#include // for event -#include // for weak_object -#include // for kernel -#include // for kernel_id -#include // for bundle_state -#include // for platform -#include // for sampled_i... -#include // for queue -#include // for stream +#include // for access_mode +#include // for host_acce... +#include // for accessor +#include // for context +#include // for device +#include // for event +#include // for command_graph +#include // for weak_object +#include // for kernel +#include // for kernel_id +#include // for bundle_state +#include // for platform +#include // for sampled_i... +#include // for queue +#include // for stream namespace sycl { inline namespace _V1 { @@ -126,6 +127,10 @@ struct owner_less> : public detail::owner_less_base< host_sampled_image_accessor> {}; +template +struct owner_less> + : public detail::owner_less_base> {}; + } // namespace ext::oneapi } // namespace _V1 } // namespace sycl diff --git a/sycl/unittests/Extensions/CommandGraph/CommandGraph.cpp b/sycl/unittests/Extensions/CommandGraph/CommandGraph.cpp index 6ac141528a589..df3c3ba81c221 100644 --- a/sycl/unittests/Extensions/CommandGraph/CommandGraph.cpp +++ b/sycl/unittests/Extensions/CommandGraph/CommandGraph.cpp @@ -7,9 +7,45 @@ //===----------------------------------------------------------------------===// #include "Common.hpp" +#include + using namespace sycl; using namespace sycl::ext::oneapi; +// Test creating and using ext::oneapi::weak_object and owner_less for +// command_graph class in a map +TEST_F(CommandGraphTest, OwnerLessGraph) { + + using ModifiableGraphT = + experimental::command_graph; + using ExecutableGraphT = + experimental::command_graph; + + // Test graph objects using the default template parameter + weak_object> DefaultWeakGraph = Graph; + std::map>, int, + owner_less>> + DefaultGraphMap; + + ASSERT_NO_THROW(DefaultGraphMap.insert({DefaultWeakGraph, 1})); + + // Test graph objects in the modifiable state + weak_object WeakGraph = Graph; + std::map, int, owner_less> + ModifiableGraphMap; + + ASSERT_NO_THROW(ModifiableGraphMap.insert({WeakGraph, 1})); + + // Test graph objects in the executable state + auto ExecGraph = Graph.finalize(); + + weak_object WeakGraphExec = ExecGraph; + std::map, int, owner_less> + ExecGraphMap; + + ASSERT_NO_THROW(ExecGraphMap.insert({WeakGraphExec, 1})); +} + TEST_F(CommandGraphTest, AddNode) { auto GraphImpl = sycl::detail::getSyclObjImpl(Graph);