-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL][Graph] Enable specialization constants with graph #11556
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
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d95717a
[SYCL][Graph] Enable specification constants with graph
mfrancepillois 9d5fd94
Merge branch 'sycl' into graph_spec_constants
EwanC 8877e53
Merge branch 'sycl' into graph_spec_constants
EwanC 62b554c
Merge branch 'sycl' into graph_spec_constants
EwanC 36dcf6d
Address PR feedback to remove superficial brackets
EwanC 4133e58
Merge branch 'sycl' into graph_spec_constants
EwanC aa9fcb4
Merge branch 'sycl' into graph_spec_constants
EwanC 06c6af8
Fix clang-format
EwanC 7ff1ef9
Merge branch 'sycl' into graph_spec_constants
EwanC 70594a5
Enable cuda in new tests
EwanC 9f43fc2
Merge branch 'sycl' into graph_spec_constants
EwanC 4e993bb
Merge branch 'sycl' into graph_spec_constants
EwanC f1ff1b9
Don't exit early on fail in spec constants tests
EwanC e08ee53
Merge branch 'sycl' into graph_spec_constants
EwanC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
sycl/test-e2e/Graph/Explicit/spec_constants_handler_api.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// REQUIRES: cuda || level_zero, gpu | ||
// RUN: %{build} -o %t.out | ||
// RUN: %{run} %t.out | ||
// Extra run to check for leaks in Level Zero using ZE_DEBUG | ||
// RUN: %if ext_oneapi_level_zero %{env ZE_DEBUG=4 %{run} %t.out 2>&1 | FileCheck %s %} | ||
// | ||
// CHECK-NOT: LEAK | ||
|
||
// The following limitation is not restricted to Sycl-Graph | ||
// but comes from the orignal test : `SpecConstants/2020/handler-api.cpp` | ||
// FIXME: ACC devices use emulation path, which is not yet supported | ||
// UNSUPPORTED: accelerator | ||
|
||
#define GRAPH_E2E_EXPLICIT | ||
|
||
#include "../Inputs/spec_constants_handler_api.cpp" |
17 changes: 17 additions & 0 deletions
17
sycl/test-e2e/Graph/Explicit/spec_constants_kernel_bundle_api.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// REQUIRES: cuda || level_zero, gpu | ||
// RUN: %{build} -o %t.out | ||
// RUN: %{run} %t.out | ||
// Extra run to check for leaks in Level Zero using ZE_DEBUG | ||
// RUN: %if ext_oneapi_level_zero %{env ZE_DEBUG=4 %{run} %t.out 2>&1 | FileCheck %s %} | ||
// | ||
// CHECK-NOT: LEAK | ||
|
||
// The following limitation is not restricted to Sycl-Graph | ||
// but comes from the orignal test : `SpecConstants/2020/kernel-bundle-api.cpp` | ||
// FIXME: ACC devices use emulation path, which is not yet supported | ||
// UNSUPPORTED: accelerator | ||
// UNSUPPORTED: hip | ||
|
||
#define GRAPH_E2E_EXPLICIT | ||
|
||
#include "../Inputs/spec_constants_kernel_bundle_api.cpp" |
210 changes: 210 additions & 0 deletions
210
sycl/test-e2e/Graph/Inputs/spec_constants_handler_api.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
// This test is intended to check basic operations with SYCL 2020 specialization | ||
// constants using Graph and sycl::handler and sycl::kernel_handler APIs | ||
// This test was taken from `SpecConstants/2020/handler-api.cpp`. | ||
// Variable names have been changed to meet PascalCase naming convention | ||
// requirements. | ||
|
||
#include "../graph_common.hpp" | ||
|
||
constexpr sycl::specialization_id<int> IntId; | ||
constexpr sycl::specialization_id<int> IntId2(2); | ||
constexpr sycl::specialization_id<float> FloatId(3.14); | ||
|
||
class TestDefaultValuesKernel; | ||
class EmptyKernel; | ||
class TestSetAndGetOnDevice; | ||
|
||
bool test_default_values(sycl::queue Queue); | ||
bool test_set_and_get_on_host(sycl::queue Queue); | ||
bool test_set_and_get_on_device(sycl::queue Queue); | ||
|
||
bool test_set_and_get_on_device(sycl::queue Queue); | ||
|
||
int main() { | ||
auto ExceptionHandler = [&](sycl::exception_list Exceptions) { | ||
for (std::exception_ptr const &E : Exceptions) { | ||
try { | ||
std::rethrow_exception(E); | ||
} catch (sycl::exception const &E) { | ||
std::cout << "An async SYCL exception was caught: " << E.what() | ||
<< std::endl; | ||
std::exit(1); | ||
} | ||
} | ||
}; | ||
|
||
queue Queue{ExceptionHandler, | ||
{sycl::ext::intel::property::queue::no_immediate_command_list{}}}; | ||
|
||
unsigned Errors = 0; | ||
if (!test_default_values(Queue)) { | ||
std::cout << "Test for default values of specialization constants failed!" | ||
<< std::endl; | ||
Errors++; | ||
} | ||
|
||
if (!test_set_and_get_on_host(Queue)) { | ||
std::cout << "Test for set and get API on host failed!" << std::endl; | ||
Errors++; | ||
} | ||
|
||
if (!test_set_and_get_on_device(Queue)) { | ||
std::cout << "Test for set and get API on device failed!" << std::endl; | ||
Errors++; | ||
} | ||
|
||
return (Errors == 0) ? 0 : 1; | ||
}; | ||
|
||
bool test_default_values(sycl::queue Queue) { | ||
sycl::buffer<int> IntBuffer(1); | ||
IntBuffer.set_write_back(false); | ||
sycl::buffer<int> IntBuffer2(1); | ||
IntBuffer2.set_write_back(false); | ||
sycl::buffer<float> FloatBuffer(1); | ||
FloatBuffer.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, ([&](sycl::handler &CGH) { | ||
auto IntAcc = | ||
IntBuffer.get_access<sycl::access::mode::write>(CGH); | ||
auto IntAcc2 = | ||
IntBuffer2.get_access<sycl::access::mode::write>(CGH); | ||
auto FloatAcc = | ||
FloatBuffer.get_access<sycl::access::mode::write>(CGH); | ||
|
||
CGH.single_task<TestDefaultValuesKernel>( | ||
[=](sycl::kernel_handler KH) { | ||
IntAcc[0] = KH.get_specialization_constant<IntId>(); | ||
IntAcc2[0] = KH.get_specialization_constant<IntId2>(); | ||
FloatAcc[0] = KH.get_specialization_constant<FloatId>(); | ||
}); | ||
})); | ||
|
||
auto GraphExec = Graph.finalize(); | ||
|
||
Queue.submit([&](handler &CGH) { CGH.ext_oneapi_graph(GraphExec); }); | ||
Queue.wait_and_throw(); | ||
} | ||
|
||
unsigned Errors = 0; | ||
sycl::host_accessor IntAcc(IntBuffer, sycl::read_only); | ||
if (!check_value( | ||
0, IntAcc[0], | ||
"integer specialization constant (defined without default value)")) | ||
Errors++; | ||
|
||
sycl::host_accessor IntAcc2(IntBuffer2, sycl::read_only); | ||
if (!check_value(2, IntAcc2[0], "integer specialization constant")) | ||
Errors++; | ||
|
||
sycl::host_accessor FloatAcc(FloatBuffer, sycl::read_only); | ||
if (!check_value(3.14f, FloatAcc[0], "float specialization constant")) | ||
Errors++; | ||
|
||
return Errors == 0; | ||
} | ||
|
||
bool test_set_and_get_on_host(sycl::queue Queue) { | ||
unsigned Errors = 0; | ||
|
||
exp_ext::command_graph Graph{ | ||
Queue.get_context(), | ||
Queue.get_device(), | ||
{exp_ext::property::graph::assume_buffer_outlives_graph{}}}; | ||
|
||
add_node( | ||
Graph, Queue, ([&](sycl::handler &CGH) { | ||
if (!check_value( | ||
0, CGH.get_specialization_constant<IntId>(), | ||
"integer specializaiton constant before setting any value")) | ||
++Errors; | ||
|
||
if (!check_value( | ||
3.14f, CGH.get_specialization_constant<FloatId>(), | ||
"float specializaiton constant before setting any value")) | ||
++Errors; | ||
|
||
int NewIntValue = 8; | ||
float NewFloatValue = 3.0f; | ||
CGH.set_specialization_constant<IntId>(NewIntValue); | ||
CGH.set_specialization_constant<FloatId>(NewFloatValue); | ||
|
||
if (!check_value( | ||
NewIntValue, CGH.get_specialization_constant<IntId>(), | ||
"integer specializaiton constant after setting a new value")) | ||
++Errors; | ||
|
||
if (!check_value( | ||
NewFloatValue, CGH.get_specialization_constant<FloatId>(), | ||
"float specializaiton constant after setting a new value")) | ||
++Errors; | ||
|
||
CGH.single_task<EmptyKernel>([=]() {}); | ||
})); | ||
|
||
return Errors == 0; | ||
} | ||
|
||
bool test_set_and_get_on_device(sycl::queue Queue) { | ||
sycl::buffer<int> IntBuffer(1); | ||
IntBuffer.set_write_back(false); | ||
sycl::buffer<int> IntBuffer2(1); | ||
IntBuffer2.set_write_back(false); | ||
sycl::buffer<float> FloatBuffer(1); | ||
FloatBuffer.set_write_back(false); | ||
|
||
int NewIntValue = 8; | ||
int NewIntValue2 = 0; | ||
float NewFloatValue = 3.0f; | ||
|
||
{ | ||
exp_ext::command_graph Graph{ | ||
Queue.get_context(), | ||
Queue.get_device(), | ||
{exp_ext::property::graph::assume_buffer_outlives_graph{}}}; | ||
|
||
add_node( | ||
Graph, Queue, ([&](sycl::handler &CGH) { | ||
auto IntAcc = IntBuffer.get_access<sycl::access::mode::write>(CGH); | ||
auto IntAcc2 = IntBuffer2.get_access<sycl::access::mode::write>(CGH); | ||
auto FloatAcc = | ||
FloatBuffer.get_access<sycl::access::mode::write>(CGH); | ||
|
||
CGH.set_specialization_constant<IntId>(NewIntValue); | ||
CGH.set_specialization_constant<IntId2>(NewIntValue2); | ||
CGH.set_specialization_constant<FloatId>(NewFloatValue); | ||
|
||
CGH.single_task<TestSetAndGetOnDevice>([=](sycl::kernel_handler KH) { | ||
IntAcc[0] = KH.get_specialization_constant<IntId>(); | ||
IntAcc2[0] = KH.get_specialization_constant<IntId2>(); | ||
FloatAcc[0] = KH.get_specialization_constant<FloatId>(); | ||
}); | ||
})); | ||
|
||
auto GraphExec = Graph.finalize(); | ||
|
||
Queue.submit([&](handler &CGH) { CGH.ext_oneapi_graph(GraphExec); }); | ||
Queue.wait_and_throw(); | ||
} | ||
|
||
unsigned Errors = 0; | ||
sycl::host_accessor IntAcc(IntBuffer, sycl::read_only); | ||
if (!check_value(NewIntValue, IntAcc[0], "integer specialization constant")) | ||
Errors++; | ||
|
||
sycl::host_accessor IntAcc2(IntBuffer2, sycl::read_only); | ||
if (!check_value(NewIntValue2, IntAcc2[0], "integer specialization constant")) | ||
Errors++; | ||
|
||
sycl::host_accessor FloatAcc(FloatBuffer, sycl::read_only); | ||
if (!check_value(NewFloatValue, FloatAcc[0], "float specialization constant")) | ||
Errors++; | ||
|
||
return Errors == 0; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.