-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL] Fix handling of unpacked POD spec constants #2926
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 1 commit into
intel:sycl
from
AlexeySachkov:private/asachkov/fix-handling-of-unpacked-composite-spec-constants
Dec 22, 2020
Merged
Changes from all commits
Commits
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
79 changes: 79 additions & 0 deletions
79
sycl/test/on-device/spec_const/unpacked-composite-type.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,79 @@ | ||
// 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 | ||
// | ||
// This test is intended to check that unpacked composites with elemements of | ||
// various sizes are handled correctly | ||
// | ||
// CHECK: --------> 1 | ||
// CHECK: --------> 2 | ||
// CHECK: --------> 3 | ||
// CHECK: --------> 4 | ||
#include <CL/sycl.hpp> | ||
|
||
#include <stdint.h> | ||
|
||
using namespace cl::sycl; | ||
|
||
class sc_kernel_t; | ||
|
||
namespace test { | ||
|
||
struct pod_t { | ||
int a; | ||
int8_t b; | ||
int c; | ||
int64_t d; | ||
}; | ||
|
||
template <typename T> class kernel_t { | ||
public: | ||
using sc_t = sycl::ONEAPI::experimental::spec_constant<pod_t, sc_kernel_t>; | ||
|
||
kernel_t(const sc_t &sc, cl::sycl::stream &strm) : sc_(sc), strm_(strm) {} | ||
|
||
void operator()(cl::sycl::id<1> i) const { | ||
strm_ << "--------> " << sc_.get().a << sycl::endl; | ||
strm_ << "--------> " << sc_.get().b << sycl::endl; | ||
strm_ << "--------> " << sc_.get().c << sycl::endl; | ||
strm_ << "--------> " << sc_.get().d << sycl::endl; | ||
} | ||
|
||
sc_t sc_; | ||
cl::sycl::stream strm_; | ||
}; | ||
|
||
template <typename T> class kernel_driver_t { | ||
public: | ||
void execute(const pod_t &pod) { | ||
device dev = sycl::device(default_selector{}); | ||
context ctx = context(dev); | ||
queue q(dev); | ||
|
||
cl::sycl::program p(q.get_context()); | ||
auto sc = p.set_spec_constant<sc_kernel_t>(pod); | ||
p.build_with_kernel_type<kernel_t<T>>(); | ||
|
||
q.submit([&](cl::sycl::handler &cgh) { | ||
cl::sycl::stream strm(1024, 256, cgh); | ||
kernel_t<T> func(sc, strm); | ||
|
||
auto sycl_kernel = p.get_kernel<kernel_t<T>>(); | ||
cgh.parallel_for(sycl_kernel, cl::sycl::range<1>(1), func); | ||
}); | ||
q.wait(); | ||
} | ||
}; | ||
|
||
} // namespace test | ||
|
||
int main() { | ||
test::pod_t pod = {1, 2, 3, 4}; | ||
test::kernel_driver_t<float> kd_float; | ||
kd_float.execute(pod); | ||
|
||
return 0; | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to have a unit-test for this change in the pass. Technically I can do that by looking into a properties file generated by
sycl-post-link
, but non-scalar properties are encoded using base64, so, it won't be an expressive test. However, this will be my plan if I didn't think of anything better. Any ideas are welcomeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed the fix is needed urgently and the test will follow shortly, so I approved.
My idea would be adding logging to the spec constants pass and verifying the log output is expected. IIRC, some of passes use this approach.