-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL RT] Add support for composite specialization constants #2797
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
romanovvlad
merged 6 commits into
intel:sycl
from
AlexeySachkov:private/asachkov/support-for-composite-spec-constants-in-runtime
Dec 8, 2020
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fa47324
[SYCL] Add support for POD spec constants in RT
AlexeySachkov c560a62
Apply comments
AlexeySachkov 67836cc
Fix clang-format and apply comments
AlexeySachkov 33d88b0
Align size of spec_constant class between host and device
AlexeySachkov c8b42fd
Update LIT tests for composite spec constants
AlexeySachkov ef3f168
Apply comments
AlexeySachkov 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
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
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
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,86 @@ | ||
// UNSUPPORTED: cuda | ||
// | ||
// RUN: %clangxx -fsycl %s -o %t.out | ||
// RUN: %RUN_ON_HOST %t.out | FileCheck %s | ||
// RUN: %CPU_RUN_PLACEHOLDER %t.out %CPU_CHECK_PLACEHOLDER | ||
// RUN: %GPU_RUN_PLACEHOLDER %t.out %GPU_CHECK_PLACEHOLDER | ||
// | ||
// The test checks that the specialization constant feature works correctly with | ||
// composite types: toolchain processes them correctly and runtime can correctly | ||
// execute the program. | ||
// | ||
// CHECK: 1 : 2 | ||
// CHECK-NEXT: 3 | ||
// CHECK-NEXT: 4 : 5 | ||
|
||
#include <CL/sycl.hpp> | ||
|
||
using namespace cl::sycl; | ||
|
||
struct A { | ||
float x; | ||
float y[2]; | ||
}; | ||
|
||
struct pod_t { | ||
int f1[2]; | ||
A f2; | ||
}; | ||
|
||
class my_kernel_t { | ||
public: | ||
using sc_t = | ||
sycl::ONEAPI::experimental::spec_constant<pod_t, class my_kernel_t>; | ||
|
||
my_kernel_t(const sc_t &sc, const cl::sycl::stream &strm) | ||
: sc_(sc), strm_(strm) {} | ||
|
||
void operator()(cl::sycl::id<1> i) const { | ||
auto p = sc_.get(); | ||
strm_ << p.f1[0] << " : " << p.f1[1] << "\n"; | ||
strm_ << p.f2.x << "\n"; | ||
strm_ << p.f2.y[0] << " : " << p.f2.y[1] << "\n"; | ||
strm_ << sycl::endl; | ||
} | ||
|
||
sc_t sc_; | ||
cl::sycl::stream strm_; | ||
}; | ||
|
||
int main() { | ||
cl::sycl::queue q(default_selector{}, [](exception_list l) { | ||
for (auto ep : l) { | ||
try { | ||
std::rethrow_exception(ep); | ||
} catch (cl::sycl::exception &e0) { | ||
std::cout << e0.what(); | ||
} catch (std::exception &e1) { | ||
std::cout << e1.what(); | ||
} catch (...) { | ||
std::cout << "*** catch (...)\n"; | ||
} | ||
} | ||
}); | ||
|
||
pod_t pod; | ||
pod.f1[0] = 1; | ||
pod.f1[1] = 2; | ||
pod.f2.x = 3; | ||
pod.f2.y[0] = 4; | ||
pod.f2.y[1] = 5; | ||
|
||
cl::sycl::program p(q.get_context()); | ||
auto sc = p.set_spec_constant<my_kernel_t>(pod); | ||
p.build_with_kernel_type<my_kernel_t>(); | ||
|
||
q.submit([&](cl::sycl::handler &cgh) { | ||
cl::sycl::stream strm(1024, 256, cgh); | ||
my_kernel_t func(sc, strm); | ||
|
||
auto sycl_kernel = p.get_kernel<my_kernel_t>(); | ||
cgh.parallel_for(sycl_kernel, cl::sycl::range<1>(1), func); | ||
}); | ||
q.wait(); | ||
|
||
return 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.