Skip to content

[SYCL][Graph] Implement ext_oneapi_weak_object for command_graph class #16209

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

Merged
merged 6 commits into from
Dec 9, 2024
Merged
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
7 changes: 5 additions & 2 deletions sycl/include/sycl/ext/oneapi/experimental/graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <sycl/context.hpp> // for context
#include <sycl/detail/export.hpp> // for __SYCL_EXPORT
#include <sycl/detail/kernel_desc.hpp> // for kernel_param_kind_t
#include <sycl/detail/owner_less_base.hpp> // for OwnerLessBase
#include <sycl/detail/property_helper.hpp> // for DataLessPropKind, PropWith...
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
#include <sycl/detail/string_view.hpp>
Expand Down Expand Up @@ -239,7 +240,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<modifiable_command_graph> {
public:
/// Constructor.
/// @param SyclContext Context to use for graph.
Expand Down Expand Up @@ -401,7 +403,8 @@ inline
}

// Templateless executable command-graph base class.
class __SYCL_EXPORT executable_command_graph {
class __SYCL_EXPORT executable_command_graph
: public sycl::detail::OwnerLessBase<executable_command_graph> {
public:
/// An executable command-graph is not user constructable.
executable_command_graph() = delete;
Expand Down
31 changes: 18 additions & 13 deletions sycl/include/sycl/ext/oneapi/owner_less.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@

#pragma once

#include <sycl/access/access.hpp> // for access_mode
#include <sycl/accessor.hpp> // for host_acce...
#include <sycl/accessor.hpp> // for accessor
#include <sycl/context.hpp> // for context
#include <sycl/device.hpp> // for device
#include <sycl/event.hpp> // for event
#include <sycl/ext/oneapi/weak_object.hpp> // for weak_object
#include <sycl/kernel.hpp> // for kernel
#include <sycl/kernel_bundle_enums.hpp> // for bundle_state
#include <sycl/platform.hpp> // for platform
#include <sycl/properties/image_properties.hpp> // for sampled_i...
#include <sycl/queue.hpp> // for queue
#include <sycl/stream.hpp> // for stream
#include <sycl/access/access.hpp> // for access_mode
#include <sycl/accessor.hpp> // for host_acce...
#include <sycl/accessor.hpp> // for accessor
#include <sycl/context.hpp> // for context
#include <sycl/device.hpp> // for device
#include <sycl/event.hpp> // for event
#include <sycl/ext/oneapi/experimental/graph.hpp> // for command_graph
#include <sycl/ext/oneapi/weak_object.hpp> // for weak_object
#include <sycl/kernel.hpp> // for kernel
#include <sycl/kernel_bundle_enums.hpp> // for bundle_state
#include <sycl/platform.hpp> // for platform
#include <sycl/properties/image_properties.hpp> // for sampled_i...
#include <sycl/queue.hpp> // for queue
#include <sycl/stream.hpp> // for stream

namespace sycl {
inline namespace _V1 {
Expand Down Expand Up @@ -129,6 +130,10 @@ struct owner_less<host_sampled_image_accessor<DataT, Dimensions>>
: public detail::owner_less_base<
host_sampled_image_accessor<DataT, Dimensions>> {};

template <experimental::graph_state State>
struct owner_less<experimental::command_graph<State>>
: public detail::owner_less_base<experimental::command_graph<State>> {};

} // namespace ext::oneapi
} // namespace _V1
} // namespace sycl
8 changes: 8 additions & 0 deletions sycl/test/abi/sycl_symbols_windows.dump
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,14 @@
??4?$OwnerLessBase@Vdevice@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@AEBV0123@@Z
??4?$OwnerLessBase@Vevent@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@$$QEAV0123@@Z
??4?$OwnerLessBase@Vevent@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@AEBV0123@@Z
??4?$OwnerLessBase@Vexecutable_command_graph@detail@experimental@oneapi@ext@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@$$QEAV0123@@Z
??4?$OwnerLessBase@Vexecutable_command_graph@detail@experimental@oneapi@ext@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@AEBV0123@@Z
??4?$OwnerLessBase@Vkernel@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@$$QEAV0123@@Z
??4?$OwnerLessBase@Vkernel@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@AEBV0123@@Z
??4?$OwnerLessBase@Vkernel_id@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@$$QEAV0123@@Z
??4?$OwnerLessBase@Vkernel_id@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@AEBV0123@@Z
??4?$OwnerLessBase@Vmodifiable_command_graph@detail@experimental@oneapi@ext@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@$$QEAV0123@@Z
??4?$OwnerLessBase@Vmodifiable_command_graph@detail@experimental@oneapi@ext@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@AEBV0123@@Z
??4?$OwnerLessBase@Vphysical_mem@experimental@oneapi@ext@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@$$QEAV0123@@Z
??4?$OwnerLessBase@Vphysical_mem@experimental@oneapi@ext@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@AEBV0123@@Z
??4?$OwnerLessBase@Vplatform@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@$$QEAV0123@@Z
Expand Down Expand Up @@ -3856,10 +3860,14 @@
?ext_oneapi_owner_before@?$OwnerLessBase@Vdevice@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBVdevice@34@@Z
?ext_oneapi_owner_before@?$OwnerLessBase@Vevent@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBV?$weak_object_base@Vevent@_V1@sycl@@@2oneapi@ext@34@@Z
?ext_oneapi_owner_before@?$OwnerLessBase@Vevent@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBVevent@34@@Z
?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
?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
?ext_oneapi_owner_before@?$OwnerLessBase@Vkernel@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBV?$weak_object_base@Vkernel@_V1@sycl@@@2oneapi@ext@34@@Z
?ext_oneapi_owner_before@?$OwnerLessBase@Vkernel@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBVkernel@34@@Z
?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
?ext_oneapi_owner_before@?$OwnerLessBase@Vkernel_id@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBVkernel_id@34@@Z
?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
?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
?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
?ext_oneapi_owner_before@?$OwnerLessBase@Vphysical_mem@experimental@oneapi@ext@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBVphysical_mem@experimental@oneapi@ext@34@@Z
?ext_oneapi_owner_before@?$OwnerLessBase@Vplatform@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBV?$weak_object_base@Vplatform@_V1@sycl@@@2oneapi@ext@34@@Z
Expand Down
40 changes: 40 additions & 0 deletions sycl/unittests/Extensions/CommandGraph/CommandGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,49 @@
//===----------------------------------------------------------------------===//
#include "Common.hpp"

#include <map>

using namespace sycl;
using namespace sycl::ext::oneapi;

// Helper function for testing weak_object and owner_less for different graph
// types
template <typename T>
void TestGraphTypeInMaps(const T &Graph1, const T &Graph2) {
weak_object<T> WeakGraph1 = Graph1;
weak_object<T> WeakGraph2 = Graph2;

// Use the graph type directly in a map
std::map<T, int, owner_less<T>> GraphMap;
ASSERT_NO_THROW(GraphMap.insert({Graph1, 1}));
ASSERT_NO_THROW(GraphMap.insert({Graph2, 2}));

// Use the weak_object graph type in a map
std::map<weak_object<T>, int, owner_less<T>> WeakGraphMap;
ASSERT_NO_THROW(WeakGraphMap.insert({WeakGraph1, 1}));
ASSERT_NO_THROW(WeakGraphMap.insert({WeakGraph2, 2}));
}

// 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<experimental::graph_state::modifiable>;
using ExecutableGraphT =
experimental::command_graph<experimental::graph_state::executable>;
experimental::command_graph Graph2{Queue.get_context(), Dev};

// Test the default template parameter command_graph explicitly
TestGraphTypeInMaps<experimental::command_graph<>>(Graph, Graph2);

TestGraphTypeInMaps<ModifiableGraphT>(Graph, Graph2);

auto ExecGraph = Graph.finalize();
auto ExecGraph2 = Graph2.finalize();
TestGraphTypeInMaps<ExecutableGraphT>(ExecGraph, ExecGraph2);
}

TEST_F(CommandGraphTest, AddNode) {
auto GraphImpl = sycl::detail::getSyclObjImpl(Graph);

Expand Down
Loading