Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
43 changes: 41 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 @@ -236,7 +237,11 @@ 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
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
: public sycl::detail::OwnerLessBase<modifiable_command_graph>
#endif
{
public:
/// Constructor.
/// @param SyclContext Context to use for graph.
Expand Down Expand Up @@ -398,7 +403,11 @@ inline
}

// Templateless executable command-graph base class.
class __SYCL_EXPORT executable_command_graph {
class __SYCL_EXPORT executable_command_graph
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
: public sycl::detail::OwnerLessBase<executable_command_graph>
#endif
{
public:
/// An executable command-graph is not user constructable.
executable_command_graph() = delete;
Expand Down Expand Up @@ -456,6 +465,21 @@ class command_graph : public detail::modifiable_command_graph {
const property_list &PropList = {})
: modifiable_command_graph(SyclQueue, PropList) {}

// Temporary implementation of ext_oneapi_owner_before, shoudl be removed during
// the next ABI break window.
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
bool ext_oneapi_owner_before(
const ext::oneapi::detail::weak_object_base<
command_graph<graph_state::modifiable>> &Other) const noexcept {
return this->impl.owner_before(
ext::oneapi::detail::getSyclWeakObjImpl(Other));
}
bool ext_oneapi_owner_before(
const command_graph<graph_state::modifiable> &Other) const noexcept {
return this->impl.owner_before(sycl::detail::getSyclObjImpl(Other));
}
#endif

private:
/// Constructor used internally by the runtime.
/// @param Impl Detail implementation class to construct object with.
Expand All @@ -469,6 +493,21 @@ class command_graph : public detail::modifiable_command_graph {
template <>
class command_graph<graph_state::executable>
: public detail::executable_command_graph {
public:
// Temporary implementation of ext_oneapi_owner_before, shoudl be removed during
// the next ABI break window.
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
bool ext_oneapi_owner_before(
const ext::oneapi::detail::weak_object_base<
command_graph<graph_state::executable>> &Other) const noexcept {
return this->impl.owner_before(
ext::oneapi::detail::getSyclWeakObjImpl(Other));
}
bool ext_oneapi_owner_before(
const command_graph<graph_state::executable> &Other) const noexcept {
return this->impl.owner_before(sycl::detail::getSyclObjImpl(Other));
}
#endif
protected:
friend command_graph<graph_state::executable>
detail::modifiable_command_graph::finalize(const sycl::property_list &) const;
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
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