Skip to content

Commit 77b794b

Browse files
EwanCreblejulianmiBensuo
authored
[SYCL][Graph] Implement missing exceptions defined by SYCL-Graphs specification (#10775)
This PR contains a set of changes that implement throwing an exception on invalid usage, as defined by [sycl_ext_oneapi_graph](https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/proposed/sycl_ext_oneapi_graph.asciidoc). Covering the cases missing from the current implementation. * Error checking for `make_edge` API. * Throw exception when explicit add called on a graph recording a queue. * Throw exception when creating a graph for an unsupported backend. * Error on invalid buffer behaviour when used with graphs to reflect #10473 ## Authors Co-authored-by: Pablo Reble <pablo.reble@intel.com> Co-authored-by: Julian Miller <julian.miller@intel.com> Co-authored-by: Ben Tracy <ben.tracy@codeplay.com> Co-authored-by: Ewan Crawford <ewan@codeplay.com> Co-authored-by: Maxime France-Pillois <maxime.francepillois@codeplay.com>
1 parent e1163ff commit 77b794b

37 files changed

+1112
-350
lines changed

sycl/include/sycl/accessor.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ class __SYCL_EXPORT AccessorBaseHost {
573573
const range<3> &getMemoryRange() const;
574574
void *getPtr() const noexcept;
575575
bool isPlaceholder() const;
576+
bool isMemoryObjectUsedByGraph() const;
576577

577578
detail::AccHostDataT &getAccData();
578579

@@ -1487,6 +1488,18 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
14871488
typename std::iterator_traits<iterator>::difference_type;
14881489
using size_type = std::size_t;
14891490

1491+
/// If creating a host_accessor this checks to see if the underlying memory
1492+
/// object is currently in use by a command_graph, and throws if it is.
1493+
void throwIfUsedByGraph() const {
1494+
#ifndef __SYCL_DEVICE_ONLY__
1495+
if (IsHostBuf && AccessorBaseHost::isMemoryObjectUsedByGraph()) {
1496+
throw sycl::exception(make_error_code(errc::invalid),
1497+
"Host accessors cannot be created for buffers "
1498+
"which are currently in use by a command graph.");
1499+
}
1500+
#endif
1501+
}
1502+
14901503
// The list of accessor constructors with their arguments
14911504
// -------+---------+-------+----+-----+--------------
14921505
// Dimensions = 0
@@ -1566,6 +1579,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
15661579
detail::getSyclObjImpl(BufferRef).get(), AdjustedDim, sizeof(DataT),
15671580
IsPlaceH, BufferRef.OffsetInBytes, BufferRef.IsSubBuffer,
15681581
PropertyList) {
1582+
throwIfUsedByGraph();
15691583
preScreenAccessor(PropertyList);
15701584
if (!AccessorBaseHost::isPlaceholder())
15711585
addHostAccessorAndWait(AccessorBaseHost::impl.get());
@@ -1605,6 +1619,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
16051619
detail::getSyclObjImpl(BufferRef).get(), AdjustedDim, sizeof(DataT),
16061620
IsPlaceH, BufferRef.OffsetInBytes, BufferRef.IsSubBuffer,
16071621
PropertyList) {
1622+
throwIfUsedByGraph();
16081623
preScreenAccessor(PropertyList);
16091624
if (!AccessorBaseHost::isPlaceholder())
16101625
addHostAccessorAndWait(AccessorBaseHost::impl.get());
@@ -1640,6 +1655,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
16401655
getAdjustedMode(PropertyList),
16411656
detail::getSyclObjImpl(BufferRef).get(), Dimensions, sizeof(DataT),
16421657
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer, PropertyList) {
1658+
throwIfUsedByGraph();
16431659
preScreenAccessor(PropertyList);
16441660
detail::associateWithHandler(CommandGroupHandler, this, AccessTarget);
16451661
initHostAcc();
@@ -1676,6 +1692,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
16761692
getAdjustedMode(PropertyList),
16771693
detail::getSyclObjImpl(BufferRef).get(), Dimensions, sizeof(DataT),
16781694
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer, PropertyList) {
1695+
throwIfUsedByGraph();
16791696
preScreenAccessor(PropertyList);
16801697
detail::associateWithHandler(CommandGroupHandler, this, AccessTarget);
16811698
initHostAcc();
@@ -1708,6 +1725,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
17081725
detail::getSyclObjImpl(BufferRef).get(), Dimensions, sizeof(DataT),
17091726
IsPlaceH, BufferRef.OffsetInBytes, BufferRef.IsSubBuffer,
17101727
PropertyList) {
1728+
throwIfUsedByGraph();
17111729
preScreenAccessor(PropertyList);
17121730
if (!AccessorBaseHost::isPlaceholder())
17131731
addHostAccessorAndWait(AccessorBaseHost::impl.get());
@@ -1743,6 +1761,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
17431761
detail::getSyclObjImpl(BufferRef).get(), Dimensions, sizeof(DataT),
17441762
IsPlaceH, BufferRef.OffsetInBytes, BufferRef.IsSubBuffer,
17451763
PropertyList) {
1764+
throwIfUsedByGraph();
17461765
preScreenAccessor(PropertyList);
17471766
if (!AccessorBaseHost::isPlaceholder())
17481767
addHostAccessorAndWait(AccessorBaseHost::impl.get());
@@ -1805,6 +1824,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
18051824
getAdjustedMode(PropertyList),
18061825
detail::getSyclObjImpl(BufferRef).get(), Dimensions, sizeof(DataT),
18071826
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer, PropertyList) {
1827+
throwIfUsedByGraph();
18081828
preScreenAccessor(PropertyList);
18091829
detail::associateWithHandler(CommandGroupHandler, this, AccessTarget);
18101830
initHostAcc();
@@ -1839,6 +1859,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
18391859
getAdjustedMode(PropertyList),
18401860
detail::getSyclObjImpl(BufferRef).get(), Dimensions, sizeof(DataT),
18411861
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer, PropertyList) {
1862+
throwIfUsedByGraph();
18421863
preScreenAccessor(PropertyList);
18431864
initHostAcc();
18441865
detail::associateWithHandler(CommandGroupHandler, this, AccessTarget);
@@ -2014,6 +2035,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
20142035
detail::getSyclObjImpl(BufferRef).get(), Dimensions,
20152036
sizeof(DataT), IsPlaceH, BufferRef.OffsetInBytes,
20162037
BufferRef.IsSubBuffer, PropertyList) {
2038+
throwIfUsedByGraph();
20172039
preScreenAccessor(PropertyList);
20182040
if (!AccessorBaseHost::isPlaceholder())
20192041
addHostAccessorAndWait(AccessorBaseHost::impl.get());
@@ -2056,6 +2078,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
20562078
detail::getSyclObjImpl(BufferRef).get(), Dimensions,
20572079
sizeof(DataT), IsPlaceH, BufferRef.OffsetInBytes,
20582080
BufferRef.IsSubBuffer, PropertyList) {
2081+
throwIfUsedByGraph();
20592082
preScreenAccessor(PropertyList);
20602083
if (!AccessorBaseHost::isPlaceholder())
20612084
addHostAccessorAndWait(AccessorBaseHost::impl.get());
@@ -2127,6 +2150,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
21272150
detail::getSyclObjImpl(BufferRef).get(), Dimensions,
21282151
sizeof(DataT), BufferRef.OffsetInBytes,
21292152
BufferRef.IsSubBuffer, PropertyList) {
2153+
throwIfUsedByGraph();
21302154
preScreenAccessor(PropertyList);
21312155
if (BufferRef.isOutOfBounds(AccessOffset, AccessRange,
21322156
BufferRef.get_range()))
@@ -2169,6 +2193,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
21692193
detail::getSyclObjImpl(BufferRef).get(), Dimensions,
21702194
sizeof(DataT), BufferRef.OffsetInBytes,
21712195
BufferRef.IsSubBuffer, PropertyList) {
2196+
throwIfUsedByGraph();
21722197
preScreenAccessor(PropertyList);
21732198
if (BufferRef.isOutOfBounds(AccessOffset, AccessRange,
21742199
BufferRef.get_range()))

sycl/include/sycl/detail/property_helper.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ enum DataLessPropKind {
4444
GraphNoCycleCheck = 19,
4545
QueueSubmissionBatched = 20,
4646
QueueSubmissionImmediate = 21,
47+
GraphAssumeDataOutlivesBuffer = 22,
48+
GraphAssumeBufferOutlivesGraph = 23,
4749
// Indicates the last known dataless property.
48-
LastKnownDataLessPropKind = 21,
50+
LastKnownDataLessPropKind = 23,
4951
// Exceeding 32 may cause ABI breaking change on some of OSes.
5052
DataLessPropKindSize = 32
5153
};

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,22 @@ namespace graph {
101101

102102
/// Property passed to command_graph constructor to disable checking for cycles.
103103
///
104-
/// \todo Cycle check not yet implemented.
105104
class no_cycle_check : public ::sycl::detail::DataLessProperty<
106105
::sycl::detail::GraphNoCycleCheck> {
107106
public:
108107
no_cycle_check() = default;
109108
};
110109

110+
/// Property passed to command_graph constructor to allow buffers to be used
111+
/// with graphs. Passing this property represents a promise from the user that
112+
/// the buffer will outlive any graph that it is used in.
113+
///
114+
class assume_buffer_outlives_graph
115+
: public ::sycl::detail::DataLessProperty<
116+
::sycl::detail::GraphAssumeBufferOutlivesGraph> {
117+
public:
118+
assume_buffer_outlives_graph() = default;
119+
};
111120
} // namespace graph
112121

113122
namespace node {

sycl/include/sycl/info/ext_oneapi_device_traits.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ __SYCL_PARAM_TRAITS_SPEC(ext::oneapi::experimental, device, architecture,
1111
PI_EXT_ONEAPI_DEVICE_INFO_IP_VERSION)
1212
__SYCL_PARAM_TRAITS_SPEC(
1313
ext::oneapi::experimental, device, graph_support,
14-
ext::oneapi::experimental::info::graph_support_level,
14+
ext::oneapi::experimental::graph_support_level,
1515
0 /* No PI device code needed */)
1616

1717
// Bindless images pitched allocation

sycl/include/sycl/info/info_desc.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,14 @@ template <typename T, T param> struct compatibility_param_traits {};
191191
} /*namespace info */ \
192192
} /*namespace Namespace */
193193

194-
namespace ext::oneapi::experimental::info {
194+
namespace ext::oneapi::experimental {
195195

196-
enum class graph_support_level { unsupported = 0, native, emulated };
196+
enum class graph_support_level { unsupported = 0, native = 1, emulated = 2 };
197197

198-
namespace device {
198+
namespace info::device {
199199
template <int Dimensions> struct max_work_groups;
200-
} // namespace device
201-
} // namespace ext::oneapi::experimental::info
200+
} // namespace info::device
201+
} // namespace ext::oneapi::experimental
202202
#include <sycl/info/ext_codeplay_device_traits.def>
203203
#include <sycl/info/ext_intel_device_traits.def>
204204
#include <sycl/info/ext_oneapi_device_traits.def>

sycl/source/accessor.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include <detail/queue_impl.hpp>
10+
#include <detail/sycl_mem_obj_t.hpp>
1011
#include <sycl/accessor.hpp>
1112

1213
namespace sycl {
@@ -94,6 +95,10 @@ void *AccessorBaseHost::getMemoryObject() const { return impl->MSYCLMemObj; }
9495

9596
bool AccessorBaseHost::isPlaceholder() const { return impl->MIsPlaceH; }
9697

98+
bool AccessorBaseHost::isMemoryObjectUsedByGraph() const {
99+
return static_cast<detail::SYCLMemObjT *>(impl->MSYCLMemObj)->isUsedInGraph();
100+
}
101+
97102
LocalAccessorBaseHost::LocalAccessorBaseHost(
98103
sycl::range<3> Size, int Dims, int ElemSize,
99104
const property_list &PropertyList) {

sycl/source/detail/device_info.hpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -934,16 +934,16 @@ struct get_device_info_impl<
934934
// Specialization for graph extension support
935935
template <>
936936
struct get_device_info_impl<
937-
ext::oneapi::experimental::info::graph_support_level,
937+
ext::oneapi::experimental::graph_support_level,
938938
ext::oneapi::experimental::info::device::graph_support> {
939-
static ext::oneapi::experimental::info::graph_support_level
939+
static ext::oneapi::experimental::graph_support_level
940940
get(const DeviceImplPtr &Dev) {
941941
size_t ResultSize = 0;
942942
Dev->getPlugin()->call<PiApiKind::piDeviceGetInfo>(
943943
Dev->getHandleRef(), PI_DEVICE_INFO_EXTENSIONS, 0, nullptr,
944944
&ResultSize);
945945
if (ResultSize == 0)
946-
return ext::oneapi::experimental::info::graph_support_level::unsupported;
946+
return ext::oneapi::experimental::graph_support_level::unsupported;
947947

948948
std::unique_ptr<char[]> Result(new char[ResultSize]);
949949
Dev->getPlugin()->call<PiApiKind::piDeviceGetInfo>(
@@ -954,9 +954,8 @@ struct get_device_info_impl<
954954
bool CmdBufferSupport =
955955
ExtensionsString.find("ur_exp_command_buffer") != std::string::npos;
956956
return CmdBufferSupport
957-
? ext::oneapi::experimental::info::graph_support_level::native
958-
: ext::oneapi::experimental::info::graph_support_level::
959-
unsupported;
957+
? ext::oneapi::experimental::graph_support_level::native
958+
: ext::oneapi::experimental::graph_support_level::unsupported;
960959
}
961960
};
962961

@@ -1862,10 +1861,10 @@ inline uint32_t get_device_info_host<
18621861
}
18631862

18641863
template <>
1865-
inline ext::oneapi::experimental::info::graph_support_level
1864+
inline ext::oneapi::experimental::graph_support_level
18661865
get_device_info_host<ext::oneapi::experimental::info::device::graph_support>() {
18671866
// No support for graphs on the host device.
1868-
return ext::oneapi::experimental::info::graph_support_level::unsupported;
1867+
return ext::oneapi::experimental::graph_support_level::unsupported;
18691868
}
18701869

18711870
template <>

0 commit comments

Comments
 (0)