-
Notifications
You must be signed in to change notification settings - Fork 797
[SYCL] Add DPC++ RT support for non-native SYCL 2020 spec constants #3589
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
Changes from all commits
6ff1202
bb81670
43669f6
06a15c2
b5eb9b4
8e944f5
2d85e62
665ace5
7ae2181
0501008
022503a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -442,7 +442,11 @@ class kernel_bundle_impl { | |
return SetInDevImg || MSpecConstValues.count(std::string{SpecName}) != 0; | ||
} | ||
|
||
const device_image_plain *begin() const { return &MDeviceImages.front(); } | ||
const device_image_plain *begin() const { | ||
assert(!MDeviceImages.empty() && "MDeviceImages can't be empty"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please clarify why MDeviceImages can't be empty? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree that this is not a valid assert. I'll submit a fix as a separate pull request. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dm-vodopyanov it's UB to access |
||
// UB in case MDeviceImages is empty | ||
return &MDeviceImages.front(); | ||
} | ||
|
||
const device_image_plain *end() const { return &MDeviceImages.back() + 1; } | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1309,7 +1309,8 @@ void ProgramManager::bringSYCLDeviceImagesToState( | |
break; | ||
} | ||
case bundle_state::executable: | ||
// Device image is already in the desired state. | ||
DevImage = build(DevImage, getSyclObjImpl(DevImage)->get_devices(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I assume this build call is optionally needed to do native device code linking? Why not call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Build is needed here to create device image which contain spec constants; as device image is in executable state because of AOT, build instead of link (object state) is used. |
||
/*PropList=*/{}); | ||
break; | ||
} | ||
break; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,10 @@ handler::getOrInsertHandlerKernelBundle(bool Insert) const { | |
if (!KernelBundleImpPtr && Insert) { | ||
KernelBundleImpPtr = detail::getSyclObjImpl( | ||
get_kernel_bundle<bundle_state::input>(MQueue->get_context())); | ||
if (KernelBundleImpPtr->empty()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT. It would be nice to have a comment explaining this logic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll submit some comments as a separate PR. |
||
KernelBundleImpPtr = detail::getSyclObjImpl( | ||
get_kernel_bundle<bundle_state::executable>(MQueue->get_context())); | ||
} | ||
|
||
detail::ExtendedMemberT EMember = { | ||
detail::ExtendedMembersType::HANDLER_KERNEL_BUNDLE, KernelBundleImpPtr}; | ||
|
@@ -340,9 +344,9 @@ void handler::processArg(void *Ptr, const detail::kernel_param_kind_t &Kind, | |
break; | ||
} | ||
case kernel_param_kind_t::kind_specialization_constants_buffer: { | ||
throw cl::sycl::feature_not_supported( | ||
"SYCL2020 specialization constants are not yet fully supported", | ||
PI_INVALID_OPERATION); | ||
MArgs.emplace_back( | ||
kernel_param_kind_t::kind_specialization_constants_buffer, Ptr, Size, | ||
Index + IndexShift); | ||
break; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include <sycl/sycl.hpp> | ||
alexbatashev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#include <cmath> | ||
|
||
class Kernel1Name; | ||
class Kernel2Name; | ||
|
||
struct TestStruct { | ||
int a; | ||
int b; | ||
}; | ||
|
||
const static sycl::specialization_id<int> SpecConst1{42}; | ||
const static sycl::specialization_id<int> SpecConst2{42}; | ||
const static sycl::specialization_id<TestStruct> SpecConst3{TestStruct{42, 42}}; | ||
const static sycl::specialization_id<short> SpecConst4{42}; | ||
|
||
int main() { | ||
sycl::queue Q; | ||
|
||
// No support for host device so far | ||
if (Q.is_host()) | ||
return 0; | ||
|
||
{ | ||
sycl::buffer<int, 1> Buf{sycl::range{1}}; | ||
Q.submit([&](sycl::handler &CGH) { | ||
CGH.set_specialization_constant<SpecConst2>(1); | ||
auto Acc = Buf.get_access<sycl::access::mode::read_write>(CGH); | ||
CGH.single_task<class Kernel1Name>([=](sycl::kernel_handler KH) { | ||
Acc[0] = KH.get_specialization_constant<SpecConst2>(); | ||
}); | ||
}); | ||
auto Acc = Buf.get_access<sycl::access::mode::read>(); | ||
assert(Acc[0] == 1); | ||
} | ||
|
||
{ | ||
sycl::buffer<TestStruct, 1> Buf{sycl::range{1}}; | ||
Q.submit([&](sycl::handler &CGH) { | ||
auto Acc = Buf.get_access<sycl::access::mode::read_write>(CGH); | ||
CGH.set_specialization_constant<SpecConst3>(TestStruct{1, 2}); | ||
const auto SC = CGH.get_specialization_constant<SpecConst4>(); | ||
assert(SC == 42); | ||
CGH.single_task<class Kernel2Name>([=](sycl::kernel_handler KH) { | ||
Acc[0] = KH.get_specialization_constant<SpecConst3>(); | ||
}); | ||
}); | ||
auto Acc = Buf.get_access<sycl::access::mode::read>(); | ||
assert(Acc[0].a == 1 && Acc[0].b == 2); | ||
} | ||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// REQUIRES: aoc, accelerator | ||
|
||
// RUN: %clangxx -fsycl -fsycl-targets=spir64_fpga-unknown-unknown-sycldevice %S/Inputs/common.cpp -o %t.out | ||
// RUN: %ACC_RUN_PLACEHOLDER %t.out | ||
|
||
// This test checks correctness of SYCL2020 non-native specialization constants | ||
// on accelerator device |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out | ||
// RUN: %CPU_RUN_PLACEHOLDER %t.out | ||
|
||
// This test checks correctness of compiling and running of application with | ||
// kernel lambdas containing kernel_handler arguments and w/o usage of | ||
// specialization constants in AOT mode | ||
|
||
#include <CL/sycl.hpp> | ||
|
||
int main() { | ||
sycl::queue q; | ||
|
||
q.submit([&](sycl::handler &cgh) { | ||
cgh.single_task<class KernelSingleTaskWithKernelHandler>( | ||
[=](sycl::kernel_handler kh) {}); | ||
}); | ||
|
||
q.submit([&](sycl::handler &cgh) { | ||
cgh.parallel_for<class KernelParallelForNDItemWithKernelHandler>( | ||
sycl::nd_range<3>(sycl::range<3>(4, 4, 4), sycl::range<3>(2, 2, 2)), | ||
[=](sycl::nd_item<3> item, sycl::kernel_handler kh) {}); | ||
}); | ||
|
||
// parallel_for_work_group with kernel_handler arg | ||
q.submit([&](sycl::handler &cgh) { | ||
cgh.parallel_for_work_group< | ||
class KernelParallelForWorkGroupWithoutKernelHandler>( | ||
sycl::range<3>(2, 2, 2), sycl::range<3>(2, 2, 2), | ||
[=](sycl::group<3> myGroup, sycl::kernel_handler kh) { | ||
myGroup.parallel_for_work_item([&](sycl::h_item<3> myItem) {}); | ||
myGroup.parallel_for_work_item([&](sycl::h_item<3> myItem) {}); | ||
}); | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// REQUIRES: opencl-aot, cpu | ||
|
||
// RUN: %clangxx -fsycl -fsycl-targets=spir64_x86_64-unknown-unknown-sycldevice %S/Inputs/common.cpp -o %t.out | ||
// RUN: %CPU_RUN_PLACEHOLDER %t.out | ||
|
||
// This test checks correctness of SYCL2020 non-native specialization constants | ||
// on CPU device |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// REQUIRES: cuda | ||
|
||
// RUN: %clangxx -fsycl -fsycl-targets=nvptx64-unknown-unknown-sycldevice %S/Inputs/common.cpp -o %t.out | ||
// RUN: env SYCL_DEVICE_FILTER=cuda %t.out | ||
|
||
// TODO: enable this test then compile-time error in sycl-post-link is fixed | ||
// UNSUPPORTED: cuda | ||
|
||
// This test checks correctness of SYCL2020 non-native specialization constants | ||
// on CUDA device |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// REQUIRES: ocloc, gpu | ||
// UNSUPPORTED: cuda | ||
// CUDA is not compatible with SPIR. | ||
|
||
// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen-unknown-unknown-sycldevice -Xsycl-target-backend=spir64_gen-unknown-unknown-sycldevice "-device *" %S/Inputs/common.cpp -o %t.out | ||
// RUN: %GPU_RUN_PLACEHOLDER %t.out | ||
|
||
// This test checks correctness of SYCL2020 non-native specialization constants | ||
// on GPU device |
Uh oh!
There was an error while loading. Please reload this page.