Skip to content

[SYCL][Graph] Enable use of kernel properties #12062

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
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
Original file line number Diff line number Diff line change
Expand Up @@ -1282,11 +1282,8 @@ which is layered ontop of `sycl_ext_oneapi_graph`.

The new handler methods, and queue shortcuts, defined by
link:../experimental/sycl_ext_oneapi_kernel_properties.asciidoc[sycl_ext_oneapi_kernel_properties]
cannot be used in graph nodes. A synchronous exception will be thrown with error
code `invalid` if a user tries to add them to a graph.

Removing this restriction is something we may look at for future revisions of
`sycl_ext_oneapi_graph`.
can be used in graph nodes in the same way as they are used in normal queue
submission.

==== sycl_ext_oneapi_prod

Expand Down
21 changes: 0 additions & 21 deletions sycl/include/sycl/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2317,7 +2317,6 @@ class __SYCL_EXPORT handler {
std::enable_if_t<
ext::oneapi::experimental::is_property_list<PropertiesT>::value>
single_task(PropertiesT Props, _KERNELFUNCPARAM(KernelFunc)) {
throwIfGraphAssociatedAndKernelProperties<PropertiesT>();
single_task_lambda_impl<KernelName, KernelType, PropertiesT>(Props,
KernelFunc);
}
Expand All @@ -2328,7 +2327,6 @@ class __SYCL_EXPORT handler {
ext::oneapi::experimental::is_property_list<PropertiesT>::value>
parallel_for(range<1> NumWorkItems, PropertiesT Props,
_KERNELFUNCPARAM(KernelFunc)) {
throwIfGraphAssociatedAndKernelProperties<PropertiesT>();
parallel_for_lambda_impl<KernelName, KernelType, 1, PropertiesT>(
NumWorkItems, Props, std::move(KernelFunc));
}
Expand All @@ -2339,7 +2337,6 @@ class __SYCL_EXPORT handler {
ext::oneapi::experimental::is_property_list<PropertiesT>::value>
parallel_for(range<2> NumWorkItems, PropertiesT Props,
_KERNELFUNCPARAM(KernelFunc)) {
throwIfGraphAssociatedAndKernelProperties<PropertiesT>();
parallel_for_lambda_impl<KernelName, KernelType, 2, PropertiesT>(
NumWorkItems, Props, std::move(KernelFunc));
}
Expand All @@ -2350,7 +2347,6 @@ class __SYCL_EXPORT handler {
ext::oneapi::experimental::is_property_list<PropertiesT>::value>
parallel_for(range<3> NumWorkItems, PropertiesT Props,
_KERNELFUNCPARAM(KernelFunc)) {
throwIfGraphAssociatedAndKernelProperties<PropertiesT>();
parallel_for_lambda_impl<KernelName, KernelType, 3, PropertiesT>(
NumWorkItems, Props, std::move(KernelFunc));
}
Expand All @@ -2361,7 +2357,6 @@ class __SYCL_EXPORT handler {
ext::oneapi::experimental::is_property_list<PropertiesT>::value>
parallel_for(nd_range<Dims> Range, PropertiesT Properties,
_KERNELFUNCPARAM(KernelFunc)) {
throwIfGraphAssociatedAndKernelProperties<PropertiesT>();
parallel_for_impl<KernelName>(Range, Properties, std::move(KernelFunc));
}

Expand All @@ -2376,7 +2371,6 @@ class __SYCL_EXPORT handler {
parallel_for(range<1> Range, PropertiesT Properties, RestT &&...Rest) {
throwIfGraphAssociated<ext::oneapi::experimental::detail::
UnsupportedGraphFeatures::sycl_reductions>();
throwIfGraphAssociatedAndKernelProperties<PropertiesT>();
detail::reduction_parallel_for<KernelName>(*this, Range, Properties,
std::forward<RestT>(Rest)...);
}
Expand All @@ -2390,7 +2384,6 @@ class __SYCL_EXPORT handler {
parallel_for(range<2> Range, PropertiesT Properties, RestT &&...Rest) {
throwIfGraphAssociated<ext::oneapi::experimental::detail::
UnsupportedGraphFeatures::sycl_reductions>();
throwIfGraphAssociatedAndKernelProperties<PropertiesT>();
detail::reduction_parallel_for<KernelName>(*this, Range, Properties,
std::forward<RestT>(Rest)...);
}
Expand All @@ -2404,7 +2397,6 @@ class __SYCL_EXPORT handler {
parallel_for(range<3> Range, PropertiesT Properties, RestT &&...Rest) {
throwIfGraphAssociated<ext::oneapi::experimental::detail::
UnsupportedGraphFeatures::sycl_reductions>();
throwIfGraphAssociatedAndKernelProperties<PropertiesT>();
detail::reduction_parallel_for<KernelName>(*this, Range, Properties,
std::forward<RestT>(Rest)...);
}
Expand Down Expand Up @@ -2461,7 +2453,6 @@ class __SYCL_EXPORT handler {
int Dims, typename PropertiesT>
void parallel_for_work_group(range<Dims> NumWorkGroups, PropertiesT Props,
_KERNELFUNCPARAM(KernelFunc)) {
throwIfGraphAssociatedAndKernelProperties<PropertiesT>();
parallel_for_work_group_lambda_impl<KernelName, KernelType, Dims,
PropertiesT>(NumWorkGroups, Props,
KernelFunc);
Expand All @@ -2472,7 +2463,6 @@ class __SYCL_EXPORT handler {
void parallel_for_work_group(range<Dims> NumWorkGroups,
range<Dims> WorkGroupSize, PropertiesT Props,
_KERNELFUNCPARAM(KernelFunc)) {
throwIfGraphAssociatedAndKernelProperties<PropertiesT>();
parallel_for_work_group_lambda_impl<KernelName, KernelType, Dims,
PropertiesT>(
NumWorkGroups, WorkGroupSize, Props, KernelFunc);
Expand Down Expand Up @@ -3621,17 +3611,6 @@ class __SYCL_EXPORT handler {
"handler::require() before it can be used.");
}

template <typename PropertiesT>
std::enable_if_t<
ext::oneapi::experimental::is_property_list<PropertiesT>::value>
throwIfGraphAssociatedAndKernelProperties() const {
if (!std::is_same_v<PropertiesT,
ext::oneapi::experimental::empty_properties_t>)
throwIfGraphAssociated<
ext::oneapi::experimental::detail::UnsupportedGraphFeatures::
sycl_ext_oneapi_kernel_properties>();
}

// Set value of the gpu cache configuration for the kernel.
void setKernelCacheConfig(sycl::detail::pi::PiKernelCacheConfig);

Expand Down
10 changes: 10 additions & 0 deletions sycl/test-e2e/Graph/Explicit/sub_group_prop.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %{build} -fsycl-device-code-split=per_kernel -o %t.out
// RUN: %{run} %t.out
// Extra run to check for leaks in Level Zero using UR_L0_LEAKS_DEBUG
// RUN: %if ext_oneapi_level_zero %{env UR_L0_LEAKS_DEBUG=1 %{run} %t.out 2>&1 | FileCheck %s %}
//
// CHECK-NOT: LEAK

#define GRAPH_E2E_EXPLICIT

#include "../Inputs/sub_group_prop.cpp"
15 changes: 15 additions & 0 deletions sycl/test-e2e/Graph/Explicit/work_group_size_prop.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %{build} -o %t.out
// RUN: %{run} %t.out
// Extra run to check for leaks in Level Zero using UR_L0_LEAKS_DEBUG
// RUN: %if ext_oneapi_level_zero %{env UR_L0_LEAKS_DEBUG=1 %{run} %t.out 2>&1 | FileCheck %s %}
//
// CHECK-NOT: LEAK

// Temporarily disabled for CUDA.
// XFAIL: cuda
// Note: failing negative test with HIP in the original test
// TODO: disable hip when HIP backend will be supported by Graph

#define GRAPH_E2E_EXPLICIT

#include "../Inputs/work_group_size_prop.cpp"
160 changes: 160 additions & 0 deletions sycl/test-e2e/Graph/Inputs/sub_group_prop.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
// This test is adapted from "test-e2e/Basic/sub_group_size_prop.cpp"

#include "../graph_common.hpp"

enum class Variant { Function, Functor, FunctorAndProperty };

template <Variant KernelVariant, size_t SGSize> class SubGroupKernel;

template <size_t SGSize> struct KernelFunctorWithSGSizeProp {
accessor<size_t, 1, access_mode::write> Acc;

KernelFunctorWithSGSizeProp(accessor<size_t, 1, access_mode::write> Acc)
: Acc(Acc) {}

void operator()(nd_item<1> NdItem) const {
auto SG = NdItem.get_sub_group();
if (NdItem.get_global_linear_id() == 0)
Acc[0] = SG.get_local_linear_range();
}

auto get(sycl::ext::oneapi::experimental::properties_tag) {
return sycl::ext::oneapi::experimental::properties{
sycl::ext::oneapi::experimental::sub_group_size<SGSize>};
}
};

template <size_t SGSize>
void test(queue &Queue, const std::vector<size_t> SupportedSGSizes) {
std::cout << "Testing sub_group_size property for sub-group size=" << SGSize
<< std::endl;

auto SGSizeSupported =
std::find(SupportedSGSizes.begin(), SupportedSGSizes.end(), SGSize) !=
SupportedSGSizes.end();
if (!SGSizeSupported) {
std::cout << "Sub-group size " << SGSize
<< " is not supported on the device." << std::endl;
return;
}

auto Props = ext::oneapi::experimental::properties{
ext::oneapi::experimental::sub_group_size<SGSize>};

nd_range<1> NdRange(SGSize * 4, SGSize * 2);

size_t ReadSubGroupSize = 0;
{
buffer ReadSubGroupSizeBuf(&ReadSubGroupSize, range(1));
ReadSubGroupSizeBuf.set_write_back(false);

{
exp_ext::command_graph Graph{
Queue.get_context(),
Queue.get_device(),
{exp_ext::property::graph::assume_buffer_outlives_graph{}}};

add_node(Graph, Queue, [&](handler &CGH) {
accessor ReadSubGroupSizeBufAcc{ReadSubGroupSizeBuf, CGH,
sycl::write_only, sycl::no_init};

CGH.parallel_for<SubGroupKernel<Variant::Function, SGSize>>(
NdRange, Props, [=](nd_item<1> NdItem) {
auto SG = NdItem.get_sub_group();
if (NdItem.get_global_linear_id() == 0)
ReadSubGroupSizeBufAcc[0] = SG.get_local_linear_range();
});
});

auto ExecGraph = Graph.finalize();
Queue.submit([&](handler &CGH) { CGH.ext_oneapi_graph(ExecGraph); });
Queue.wait_and_throw();
}

host_accessor HostAcc(ReadSubGroupSizeBuf);
ReadSubGroupSize = HostAcc[0];
}
assert(ReadSubGroupSize == SGSize && "Failed check for function.");

ReadSubGroupSize = 0;
{
buffer ReadSubGroupSizeBuf(&ReadSubGroupSize, range(1));
ReadSubGroupSizeBuf.set_write_back(false);

{
exp_ext::command_graph Graph{
Queue.get_context(),
Queue.get_device(),
{exp_ext::property::graph::assume_buffer_outlives_graph{}}};

add_node(Graph, Queue, [&](handler &CGH) {
accessor ReadSubGroupSizeBufAcc{ReadSubGroupSizeBuf, CGH,
sycl::write_only, sycl::no_init};
KernelFunctorWithSGSizeProp<SGSize> KernelFunctor{
ReadSubGroupSizeBufAcc};

CGH.parallel_for<SubGroupKernel<Variant::Functor, SGSize>>(
NdRange, KernelFunctor);
});

auto ExecGraph = Graph.finalize();
Queue.submit([&](handler &CGH) { CGH.ext_oneapi_graph(ExecGraph); });
Queue.wait_and_throw();
}

host_accessor HostAcc(ReadSubGroupSizeBuf);
ReadSubGroupSize = HostAcc[0];
}
assert(ReadSubGroupSize == SGSize && "Failed check for functor.");

ReadSubGroupSize = 0;
{
buffer ReadSubGroupSizeBuf(&ReadSubGroupSize, range(1));
ReadSubGroupSizeBuf.set_write_back(false);

{
exp_ext::command_graph Graph{
Queue.get_context(),
Queue.get_device(),
{exp_ext::property::graph::assume_buffer_outlives_graph{}}};

add_node(Graph, Queue, [&](handler &CGH) {
accessor ReadSubGroupSizeBufAcc{ReadSubGroupSizeBuf, CGH,
sycl::write_only, sycl::no_init};
KernelFunctorWithSGSizeProp<SGSize> KernelFunctor{
ReadSubGroupSizeBufAcc};

CGH.parallel_for<SubGroupKernel<Variant::Functor, SGSize>>(
NdRange, Props, KernelFunctor);
});

auto ExecGraph = Graph.finalize();
Queue.submit([&](handler &CGH) { CGH.ext_oneapi_graph(ExecGraph); });
Queue.wait_and_throw();
}

host_accessor HostAcc(ReadSubGroupSizeBuf);
ReadSubGroupSize = HostAcc[0];
}
assert(ReadSubGroupSize == SGSize &&
"Failed check for functor and properties.");
}

int main() {
queue Queue({sycl::ext::intel::property::queue::no_immediate_command_list{}});

if (!are_graphs_supported(Queue)) {
return 0;
}

std::vector<size_t> SupportedSGSizes =
Queue.get_device().get_info<info::device::sub_group_sizes>();

test<1>(Queue, SupportedSGSizes);
test<8>(Queue, SupportedSGSizes);
test<16>(Queue, SupportedSGSizes);
test<32>(Queue, SupportedSGSizes);
test<64>(Queue, SupportedSGSizes);

return 0;
}
Loading