Skip to content

Commit

Permalink
Change device info query to aspect
Browse files Browse the repository at this point in the history
Based on DPC++ maintainer feedback that an aspect is
more useful for sycl-ls and lit testing. Our emulation
mode has also never been implemented.
  • Loading branch information
EwanC committed Mar 4, 2024
1 parent db01268 commit 49968e8
Show file tree
Hide file tree
Showing 25 changed files with 71 additions and 149 deletions.
3 changes: 2 additions & 1 deletion llvm/include/llvm/SYCLLowerIR/DeviceConfigFile.td
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def AspectExt_oneapi_tangle_group : Aspect<"ext_oneapi_tangle_group">;
def AspectExt_intel_matrix : Aspect<"ext_intel_matrix">;
def AspectExt_oneapi_is_composite : Aspect<"ext_oneapi_is_composite">;
def AspectExt_oneapi_is_component : Aspect<"ext_oneapi_is_component">;
def AspectExt_oneapi_graph : Aspect<"ext_oneapi_graph">;
// Deprecated aspects
def AspectInt64_base_atomics : Aspect<"int64_base_atomics">;
def AspectInt64_extended_atomics : Aspect<"int64_extended_atomics">;
Expand Down Expand Up @@ -119,7 +120,7 @@ def : TargetInfo<"__TestAspectList",
AspectExt_oneapi_interop_semaphore_import, AspectExt_oneapi_interop_semaphore_export,
AspectExt_oneapi_mipmap, AspectExt_oneapi_mipmap_anisotropy, AspectExt_oneapi_mipmap_level_reference, AspectExt_intel_esimd,
AspectExt_oneapi_ballot_group, AspectExt_oneapi_fixed_size_group, AspectExt_oneapi_opportunistic_group,
AspectExt_oneapi_tangle_group, AspectExt_intel_matrix, AspectExt_oneapi_is_composite, AspectExt_oneapi_is_component],
AspectExt_oneapi_tangle_group, AspectExt_intel_matrix, AspectExt_oneapi_is_composite, AspectExt_oneapi_is_component, AspectExt_oneapi_graph],
[]>;
// This definition serves the only purpose of testing whether the deprecated aspect list defined in here and in SYCL RT
// match.
Expand Down
35 changes: 9 additions & 26 deletions sycl/doc/extensions/experimental/sycl_ext_oneapi_graph.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Dan Holmes, Intel +
Greg Lueck, Intel +
Steffen Larsen, Intel +
Jaime Arteaga Molina, Intel +
Andrei Elovikov, Intel +
Ewan Crawford, Codeplay +
Ben Tracy, Codeplay +
Duncan McBain, Codeplay +
Expand Down Expand Up @@ -296,38 +297,20 @@ Adding an executable graph as a sub-graph does not affect its existing node
dependencies, such that it could be submitted in future without any side
effects of prior uses as a sub-graph.

=== Device Info Query

[source, c++]
----
namespace sycl::ext::oneapi::experimental {
enum class graph_support_level {
unsupported,
native,
emulated
};
}
----
=== Querying Device Support

Due to the experimental nature of the extension, support is not available across
all devices. The following device support query is added to the
`sycl::ext::oneapi::experimental` namespace for reporting devices which are
are currently supported, and how that support is implemented.
all devices.

Table {counter: tableNumber}. Device Info Queries.
Table {counter: tableNumber}. Device Support Aspect.
[%header]
|===
| Device Descriptors | Return Type | Description

|`info::device::graph_support`
|`graph_support_level`
|When passed to `device::get_info<...>()`, the function returns `native`
if there is an underlying SYCL backend command-buffer construct which is used
to propagate the graph to the backend. If no backend construct exists, or
building on top of it has not yet been implemented, then `emulated` is
returned. Otherwise `unsupported` is returned if the SYCL device doesn't
support using this graph extension.
| Device Descriptor | Description

|`aspect::ext_oneapi_graph`
| Indicates that the device supports the extension using an
underlying SYCL backend command-buffer construct to propagate the graph to
the backend.
|===


Expand Down
10 changes: 10 additions & 0 deletions sycl/include/sycl/device_aspect_macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@
#define __SYCL_ALL_DEVICES_HAVE_ext_oneapi_is_component__ 0
#endif

#ifndef __SYCL_ALL_DEVICES_HAVE_ext_oneapi_graph__
// __SYCL_ASPECT(ext_oneapi_graph, 61)
#define __SYCL_ALL_DEVICES_HAVE_ext_oneapi_graph__ 0
#endif

#ifndef __SYCL_ANY_DEVICE_HAS_host__
// __SYCL_ASPECT(host, 0)
#define __SYCL_ANY_DEVICE_HAS_host__ 0
Expand Down Expand Up @@ -617,3 +622,8 @@
// __SYCL_ASPECT(ext_oneapi_is_component, 60)
#define __SYCL_ANY_DEVICE_HAS_ext_oneapi_is_component__ 0
#endif

#ifndef __SYCL_ANY_DEVICE_HAS_ext_oneapi_graph__
// __SYCL_ASPECT(ext_oneapi_graph, 61)
#define __SYCL_ANY_DEVICE_HAS_ext_oneapi_graph__ 0
#endif
1 change: 1 addition & 0 deletions sycl/include/sycl/info/aspects.def
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ __SYCL_ASPECT(ext_oneapi_tangle_group, 57)
__SYCL_ASPECT(ext_intel_matrix, 58)
__SYCL_ASPECT(ext_oneapi_is_composite, 59)
__SYCL_ASPECT(ext_oneapi_is_component, 60)
__SYCL_ASPECT(ext_oneapi_graph, 61)
5 changes: 0 additions & 5 deletions sycl/include/sycl/info/ext_oneapi_device_traits.def
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ __SYCL_PARAM_TRAITS_SPEC(ext::oneapi::experimental, device, matrix_combinations,
std::vector<ext::oneapi::experimental::matrix::combination>,
PI_EXT_ONEAPI_DEVICE_INFO_MATRIX_COMBINATIONS)

__SYCL_PARAM_TRAITS_SPEC(
ext::oneapi::experimental, device, graph_support,
ext::oneapi::experimental::graph_support_level,
0 /* No PI device code needed */)

// Bindless images pitched allocation
__SYCL_PARAM_TRAITS_SPEC(ext::oneapi::experimental, device,
image_row_pitch_align, uint32_t,
Expand Down
9 changes: 2 additions & 7 deletions sycl/include/sycl/info/info_desc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,9 @@ template <typename T, T param> struct compatibility_param_traits {};
} /*namespace info */ \
} /*namespace Namespace */

namespace ext::oneapi::experimental {

enum class graph_support_level { unsupported = 0, native = 1, emulated = 2 };

namespace info::device {
namespace ext::oneapi::experimental::info::device {
template <int Dimensions> struct max_work_groups;
} // namespace info::device
} // namespace ext::oneapi::experimental
} // namespace ext::oneapi::experimental::info::device
#include <sycl/info/ext_codeplay_device_traits.def>
#include <sycl/info/ext_intel_device_traits.def>
#include <sycl/info/ext_oneapi_device_traits.def>
Expand Down
25 changes: 25 additions & 0 deletions sycl/source/detail/device_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,31 @@ bool device_impl::has(aspect Aspect) const {

return Result != nullptr;
}
case aspect::ext_oneapi_graph: {
size_t ResultSize = 0;
bool CallSuccessful = getPlugin()->call_nocheck<PiApiKind::piDeviceGetInfo>(
MDevice, PI_DEVICE_INFO_EXTENSIONS, 0, nullptr,
&ResultSize) == PI_SUCCESS;
if (!CallSuccessful || ResultSize == 0) {
return PI_FALSE;
}

std::unique_ptr<char[]> Result(new char[ResultSize]);
CallSuccessful = getPlugin()->call_nocheck<PiApiKind::piDeviceGetInfo>(
MDevice, PI_DEVICE_INFO_EXTENSIONS, ResultSize,
Result.get(), nullptr) == PI_SUCCESS;

if (!CallSuccessful) {
return PI_FALSE;
}

std::string_view ExtensionsString(Result.get());
std::cout << ExtensionsString;
const bool Support =
ExtensionsString.find("ur_exp_command_buffer") != std::string::npos;

return Support;
}
}
throw runtime_error("This device aspect has not been implemented yet.",
PI_ERROR_INVALID_DEVICE);
Expand Down
35 changes: 0 additions & 35 deletions sycl/source/detail/device_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1171,34 +1171,6 @@ struct get_device_info_impl<
}
};

// Specialization for graph extension support
template <>
struct get_device_info_impl<
ext::oneapi::experimental::graph_support_level,
ext::oneapi::experimental::info::device::graph_support> {
static ext::oneapi::experimental::graph_support_level
get(const DeviceImplPtr &Dev) {
size_t ResultSize = 0;
Dev->getPlugin()->call<PiApiKind::piDeviceGetInfo>(
Dev->getHandleRef(), PI_DEVICE_INFO_EXTENSIONS, 0, nullptr,
&ResultSize);
if (ResultSize == 0)
return ext::oneapi::experimental::graph_support_level::unsupported;

std::unique_ptr<char[]> Result(new char[ResultSize]);
Dev->getPlugin()->call<PiApiKind::piDeviceGetInfo>(
Dev->getHandleRef(), PI_DEVICE_INFO_EXTENSIONS, ResultSize,
Result.get(), nullptr);

std::string_view ExtensionsString(Result.get());
bool CmdBufferSupport =
ExtensionsString.find("ur_exp_command_buffer") != std::string::npos;
return CmdBufferSupport
? ext::oneapi::experimental::graph_support_level::native
: ext::oneapi::experimental::graph_support_level::unsupported;
}
};

// Specialization for composite devices extension.
template <>
struct get_device_info_impl<
Expand Down Expand Up @@ -2161,13 +2133,6 @@ inline uint32_t get_device_info_host<
PI_ERROR_INVALID_DEVICE);
}

template <>
inline ext::oneapi::experimental::graph_support_level
get_device_info_host<ext::oneapi::experimental::info::device::graph_support>() {
// No support for graphs on the host device.
return ext::oneapi::experimental::graph_support_level::unsupported;
}

template <>
inline uint32_t get_device_info_host<
ext::oneapi::experimental::info::device::image_row_pitch_align>() {
Expand Down
22 changes: 3 additions & 19 deletions sycl/source/detail/graph_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
#include <sycl/feature_test.hpp>
#include <sycl/queue.hpp>

// Developer switch to use emulation mode on all backends, even those that
// report native support, this is useful for debugging.
#define FORCE_EMULATION_MODE 0

namespace sycl {
inline namespace _V1 {

Expand Down Expand Up @@ -1280,21 +1276,9 @@ void executable_command_graph::finalizeImpl() {
impl->makePartitions();

auto Device = impl->getGraphImpl()->getDevice();
bool CmdBufSupport =
Device
.get_info<ext::oneapi::experimental::info::device::graph_support>() ==
graph_support_level::native;

#if FORCE_EMULATION_MODE
// Above query should still succeed in emulation mode, but ignore the
// result and use emulation.
CmdBufSupport = false;
#endif
if (CmdBufSupport) {
for (auto Partition : impl->getPartitions()) {
if (!Partition->isHostTask()) {
impl->createCommandBuffers(Device, Partition);
}
for (auto Partition : impl->getPartitions()) {
if (!Partition->isHostTask()) {
impl->createCommandBuffers(Device, Partition);
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions sycl/source/detail/graph_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,7 @@ class graph_impl {
MAllowBuffers = true;
}

if (SyclDevice.get_info<
ext::oneapi::experimental::info::device::graph_support>() ==
graph_support_level::unsupported) {
if (!SyclDevice.has(aspect::ext_oneapi_graph)) {
std::stringstream Stream;
Stream << SyclDevice.get_backend();
std::string BackendString = Stream.str();
Expand Down
2 changes: 1 addition & 1 deletion sycl/test-e2e/Graph/Error/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -1 +1 @@
config.required_features += ['graph-extension']
config.required_features += ['aspect-ext_oneapi_graph']
2 changes: 1 addition & 1 deletion sycl/test-e2e/Graph/Explicit/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -1 +1 @@
config.required_features += ['graph-extension']
config.required_features += ['aspect-ext_oneapi_graph']
2 changes: 1 addition & 1 deletion sycl/test-e2e/Graph/Profiling/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -1 +1 @@
config.required_features += ['graph-extension']
config.required_features += ['aspect-ext_oneapi_graph']
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// RUN: %{run-unfiltered-devices} %t.out
//

// This test checks that an expection is thrown when we try to
// This test checks that an exception is thrown when we try to
// record a graph whose device differs from the queue device.
// We ensure that the exception code matches the expected code.

Expand Down Expand Up @@ -30,12 +30,12 @@ int main() {
return 0;
}

queue Queue{Dev1};

if (!are_graphs_supported(Queue)) {
if (!Dev0.has(aspect::ext_oneapi_graph)) {
std::cout << "Test skipped: device doesn't support graphs" << std::endl;
return 0;
}

queue Queue{Dev1};
exp_ext::command_graph Graph{Queue.get_context(), Dev0};

std::error_code ExceptionCode = make_error_code(sycl::errc::success);
Expand Down
2 changes: 1 addition & 1 deletion sycl/test-e2e/Graph/RecordReplay/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -1 +1 @@
config.required_features += ['graph-extension']
config.required_features += ['aspect-ext_oneapi_graph']
2 changes: 1 addition & 1 deletion sycl/test-e2e/Graph/Threading/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -1 +1 @@
config.required_features += ['graph-extension']
config.required_features += ['aspect-ext_oneapi_graph']
15 changes: 5 additions & 10 deletions sycl/test-e2e/Graph/UnsupportedDevice/device_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,16 @@ int main() {
queue Queue;

auto Device = Queue.get_device();

exp_ext::graph_support_level SupportsGraphs =
Device.get_info<exp_ext::info::device::graph_support>();
bool SupportsGraphs = Device.has(aspect::ext_oneapi_graph);
auto Backend = Device.get_backend();

if ((Backend == backend::ext_oneapi_level_zero) ||
(Backend == backend::ext_oneapi_cuda) ||
(Backend == backend::ext_oneapi_hip)) {
assert(SupportsGraphs == exp_ext::graph_support_level::native);
} else if (Backend == backend::opencl) {
assert(SupportsGraphs);
} else if (Backend != backend::opencl) {
// OpenCL backend support is conditional on the cl_khr_command_buffer
// extension being available
assert(SupportsGraphs == exp_ext::graph_support_level::native ||
SupportsGraphs == exp_ext::graph_support_level::unsupported);
} else {
assert(SupportsGraphs == exp_ext::graph_support_level::unsupported);
// extension being available.
assert(!SupportsGraphs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@
int GetUnsupportedBackend(const sycl::device &Dev) {
// Return 1 if the device backend is unsupported or 0 else.
// 0 does not prevent another device to be picked as a second choice
return Dev.get_info<
ext::oneapi::experimental::info::device::graph_support>() ==
ext::oneapi::experimental::graph_support_level::unsupported;
return !Dev.has(aspect::ext_oneapi_graph);
}

int main() {
sycl::device Dev{GetUnsupportedBackend};
queue Queue{Dev};

if (Dev.get_info<ext::oneapi::experimental::info::device::graph_support>() !=
ext::oneapi::experimental::graph_support_level::unsupported)
if (Dev.has(aspect::ext_oneapi_graph))
return 0;

std::error_code ExceptionCode = make_error_code(sycl::errc::success);
Expand Down
2 changes: 1 addition & 1 deletion sycl/test-e2e/Graph/ValidUsage/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -1 +1 @@
config.required_features += ['graph-extension']
config.required_features += ['aspect-ext_oneapi_graph']
9 changes: 0 additions & 9 deletions sycl/test-e2e/Graph/graph_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,3 @@ bool inline check_value(const size_t index, const T &Ref, const T &Got,

return true;
}

bool are_graphs_supported(queue &Queue) {
auto Device = Queue.get_device();

exp_ext::graph_support_level SupportsGraphs =
Device.get_info<exp_ext::info::device::graph_support>();

return SupportsGraphs != exp_ext::graph_support_level::unsupported;
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ int main() {
{sycl::property::queue::in_order{},
sycl::ext::intel::property::queue::no_immediate_command_list{}}};

if (GQueue.get_device().get_info<syclex::info::device::graph_support>() !=
syclex::graph_support_level::unsupported) {
if (GQueue.get_device().has(sycl::aspect::ext_oneapi_graph)) {
std::cout << "Test 4" << std::endl;
syclex::command_graph Graph{GQueue.get_context(), GQueue.get_device()};
*Res = 1;
Expand Down
6 changes: 0 additions & 6 deletions sycl/test-e2e/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,6 @@

dev_aspects = []
dev_sg_sizes = []
graph_support = False
# See format.py's parse_min_intel_driver_req for explanation.
is_intel_driver = False
intel_driver_ver = {}
Expand All @@ -644,8 +643,6 @@
# str.removeprefix isn't universally available...
sg_sizes_str = line.strip().replace("info::device::sub_group_sizes: ", "")
dev_sg_sizes.append(sg_sizes_str.strip().split(" "))
if re.match(r" *sycl_ext_oneapi_graph", line):
graph_support = True

if dev_aspects == []:
lit_config.error(
Expand Down Expand Up @@ -677,9 +674,6 @@
features.update(aspect_features)
features.update(sg_size_features)

if graph_support:
features.add("graph-extension")

be, dev = sycl_device.split(":")
features.add(dev.replace("fpga", "accelerator"))
# Use short names for LIT rules.
Expand Down
Loading

0 comments on commit 49968e8

Please sign in to comment.