Skip to content

Commit 9a467fa

Browse files
authored
[SYCL][Graph] Implement ext_oneapi_weak_object for command_graph class (#16209)
- 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
1 parent 5e7de51 commit 9a467fa

File tree

4 files changed

+71
-15
lines changed

4 files changed

+71
-15
lines changed

sycl/include/sycl/ext/oneapi/experimental/graph.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <sycl/context.hpp> // for context
1313
#include <sycl/detail/export.hpp> // for __SYCL_EXPORT
1414
#include <sycl/detail/kernel_desc.hpp> // for kernel_param_kind_t
15+
#include <sycl/detail/owner_less_base.hpp> // for OwnerLessBase
1516
#include <sycl/detail/property_helper.hpp> // for DataLessPropKind, PropWith...
1617
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
1718
#include <sycl/detail/string_view.hpp>
@@ -239,7 +240,8 @@ class __SYCL_EXPORT dynamic_command_group {
239240

240241
namespace detail {
241242
// Templateless modifiable command-graph base class.
242-
class __SYCL_EXPORT modifiable_command_graph {
243+
class __SYCL_EXPORT modifiable_command_graph
244+
: public sycl::detail::OwnerLessBase<modifiable_command_graph> {
243245
public:
244246
/// Constructor.
245247
/// @param SyclContext Context to use for graph.
@@ -401,7 +403,8 @@ inline
401403
}
402404

403405
// Templateless executable command-graph base class.
404-
class __SYCL_EXPORT executable_command_graph {
406+
class __SYCL_EXPORT executable_command_graph
407+
: public sycl::detail::OwnerLessBase<executable_command_graph> {
405408
public:
406409
/// An executable command-graph is not user constructable.
407410
executable_command_graph() = delete;

sycl/include/sycl/ext/oneapi/owner_less.hpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@
88

99
#pragma once
1010

11-
#include <sycl/access/access.hpp> // for access_mode
12-
#include <sycl/accessor.hpp> // for host_acce...
13-
#include <sycl/accessor.hpp> // for accessor
14-
#include <sycl/context.hpp> // for context
15-
#include <sycl/device.hpp> // for device
16-
#include <sycl/event.hpp> // for event
17-
#include <sycl/ext/oneapi/weak_object.hpp> // for weak_object
18-
#include <sycl/kernel.hpp> // for kernel
19-
#include <sycl/kernel_bundle_enums.hpp> // for bundle_state
20-
#include <sycl/platform.hpp> // for platform
21-
#include <sycl/properties/image_properties.hpp> // for sampled_i...
22-
#include <sycl/queue.hpp> // for queue
23-
#include <sycl/stream.hpp> // for stream
11+
#include <sycl/access/access.hpp> // for access_mode
12+
#include <sycl/accessor.hpp> // for host_acce...
13+
#include <sycl/accessor.hpp> // for accessor
14+
#include <sycl/context.hpp> // for context
15+
#include <sycl/device.hpp> // for device
16+
#include <sycl/event.hpp> // for event
17+
#include <sycl/ext/oneapi/experimental/graph.hpp> // for command_graph
18+
#include <sycl/ext/oneapi/weak_object.hpp> // for weak_object
19+
#include <sycl/kernel.hpp> // for kernel
20+
#include <sycl/kernel_bundle_enums.hpp> // for bundle_state
21+
#include <sycl/platform.hpp> // for platform
22+
#include <sycl/properties/image_properties.hpp> // for sampled_i...
23+
#include <sycl/queue.hpp> // for queue
24+
#include <sycl/stream.hpp> // for stream
2425

2526
namespace sycl {
2627
inline namespace _V1 {
@@ -129,6 +130,10 @@ struct owner_less<host_sampled_image_accessor<DataT, Dimensions>>
129130
: public detail::owner_less_base<
130131
host_sampled_image_accessor<DataT, Dimensions>> {};
131132

133+
template <experimental::graph_state State>
134+
struct owner_less<experimental::command_graph<State>>
135+
: public detail::owner_less_base<experimental::command_graph<State>> {};
136+
132137
} // namespace ext::oneapi
133138
} // namespace _V1
134139
} // namespace sycl

sycl/test/abi/sycl_symbols_windows.dump

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,10 +509,14 @@
509509
??4?$OwnerLessBase@Vdevice@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@AEBV0123@@Z
510510
??4?$OwnerLessBase@Vevent@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@$$QEAV0123@@Z
511511
??4?$OwnerLessBase@Vevent@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@AEBV0123@@Z
512+
??4?$OwnerLessBase@Vexecutable_command_graph@detail@experimental@oneapi@ext@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@$$QEAV0123@@Z
513+
??4?$OwnerLessBase@Vexecutable_command_graph@detail@experimental@oneapi@ext@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@AEBV0123@@Z
512514
??4?$OwnerLessBase@Vkernel@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@$$QEAV0123@@Z
513515
??4?$OwnerLessBase@Vkernel@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@AEBV0123@@Z
514516
??4?$OwnerLessBase@Vkernel_id@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@$$QEAV0123@@Z
515517
??4?$OwnerLessBase@Vkernel_id@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@AEBV0123@@Z
518+
??4?$OwnerLessBase@Vmodifiable_command_graph@detail@experimental@oneapi@ext@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@$$QEAV0123@@Z
519+
??4?$OwnerLessBase@Vmodifiable_command_graph@detail@experimental@oneapi@ext@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@AEBV0123@@Z
516520
??4?$OwnerLessBase@Vphysical_mem@experimental@oneapi@ext@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@$$QEAV0123@@Z
517521
??4?$OwnerLessBase@Vphysical_mem@experimental@oneapi@ext@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@AEBV0123@@Z
518522
??4?$OwnerLessBase@Vplatform@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@$$QEAV0123@@Z
@@ -3856,10 +3860,14 @@
38563860
?ext_oneapi_owner_before@?$OwnerLessBase@Vdevice@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBVdevice@34@@Z
38573861
?ext_oneapi_owner_before@?$OwnerLessBase@Vevent@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBV?$weak_object_base@Vevent@_V1@sycl@@@2oneapi@ext@34@@Z
38583862
?ext_oneapi_owner_before@?$OwnerLessBase@Vevent@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBVevent@34@@Z
3863+
?ext_oneapi_owner_before@?$OwnerLessBase@Vexecutable_command_graph@detail@experimental@oneapi@ext@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBV?$weak_object_base@Vexecutable_command_graph@detail@experimental@oneapi@ext@_V1@sycl@@@2oneapi@ext@34@@Z
3864+
?ext_oneapi_owner_before@?$OwnerLessBase@Vexecutable_command_graph@detail@experimental@oneapi@ext@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBVexecutable_command_graph@2experimental@oneapi@ext@34@@Z
38593865
?ext_oneapi_owner_before@?$OwnerLessBase@Vkernel@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBV?$weak_object_base@Vkernel@_V1@sycl@@@2oneapi@ext@34@@Z
38603866
?ext_oneapi_owner_before@?$OwnerLessBase@Vkernel@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBVkernel@34@@Z
38613867
?ext_oneapi_owner_before@?$OwnerLessBase@Vkernel_id@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBV?$weak_object_base@Vkernel_id@_V1@sycl@@@2oneapi@ext@34@@Z
38623868
?ext_oneapi_owner_before@?$OwnerLessBase@Vkernel_id@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBVkernel_id@34@@Z
3869+
?ext_oneapi_owner_before@?$OwnerLessBase@Vmodifiable_command_graph@detail@experimental@oneapi@ext@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBV?$weak_object_base@Vmodifiable_command_graph@detail@experimental@oneapi@ext@_V1@sycl@@@2oneapi@ext@34@@Z
3870+
?ext_oneapi_owner_before@?$OwnerLessBase@Vmodifiable_command_graph@detail@experimental@oneapi@ext@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBVmodifiable_command_graph@2experimental@oneapi@ext@34@@Z
38633871
?ext_oneapi_owner_before@?$OwnerLessBase@Vphysical_mem@experimental@oneapi@ext@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBV?$weak_object_base@Vphysical_mem@experimental@oneapi@ext@_V1@sycl@@@2oneapi@ext@34@@Z
38643872
?ext_oneapi_owner_before@?$OwnerLessBase@Vphysical_mem@experimental@oneapi@ext@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBVphysical_mem@experimental@oneapi@ext@34@@Z
38653873
?ext_oneapi_owner_before@?$OwnerLessBase@Vplatform@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBV?$weak_object_base@Vplatform@_V1@sycl@@@2oneapi@ext@34@@Z

sycl/unittests/Extensions/CommandGraph/CommandGraph.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,49 @@
77
//===----------------------------------------------------------------------===//
88
#include "Common.hpp"
99

10+
#include <map>
11+
1012
using namespace sycl;
1113
using namespace sycl::ext::oneapi;
1214

15+
// Helper function for testing weak_object and owner_less for different graph
16+
// types
17+
template <typename T>
18+
void TestGraphTypeInMaps(const T &Graph1, const T &Graph2) {
19+
weak_object<T> WeakGraph1 = Graph1;
20+
weak_object<T> WeakGraph2 = Graph2;
21+
22+
// Use the graph type directly in a map
23+
std::map<T, int, owner_less<T>> GraphMap;
24+
ASSERT_NO_THROW(GraphMap.insert({Graph1, 1}));
25+
ASSERT_NO_THROW(GraphMap.insert({Graph2, 2}));
26+
27+
// Use the weak_object graph type in a map
28+
std::map<weak_object<T>, int, owner_less<T>> WeakGraphMap;
29+
ASSERT_NO_THROW(WeakGraphMap.insert({WeakGraph1, 1}));
30+
ASSERT_NO_THROW(WeakGraphMap.insert({WeakGraph2, 2}));
31+
}
32+
33+
// Test creating and using ext::oneapi::weak_object and owner_less for
34+
// command_graph class in a map
35+
TEST_F(CommandGraphTest, OwnerLessGraph) {
36+
37+
using ModifiableGraphT =
38+
experimental::command_graph<experimental::graph_state::modifiable>;
39+
using ExecutableGraphT =
40+
experimental::command_graph<experimental::graph_state::executable>;
41+
experimental::command_graph Graph2{Queue.get_context(), Dev};
42+
43+
// Test the default template parameter command_graph explicitly
44+
TestGraphTypeInMaps<experimental::command_graph<>>(Graph, Graph2);
45+
46+
TestGraphTypeInMaps<ModifiableGraphT>(Graph, Graph2);
47+
48+
auto ExecGraph = Graph.finalize();
49+
auto ExecGraph2 = Graph2.finalize();
50+
TestGraphTypeInMaps<ExecutableGraphT>(ExecGraph, ExecGraph2);
51+
}
52+
1353
TEST_F(CommandGraphTest, AddNode) {
1454
auto GraphImpl = sycl::detail::getSyclObjImpl(Graph);
1555

0 commit comments

Comments
 (0)