Skip to content

[SYCL] Add DPC++ RT support for SYCL2020 spec constants' default values #3667

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
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
4 changes: 4 additions & 0 deletions sycl/include/CL/sycl/detail/pi.h
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,10 @@ static const uint8_t PI_DEVICE_BINARY_OFFLOAD_KIND_SYCL = 4;
/// PropertySetRegistry::SYCL_SPECIALIZATION_CONSTANTS defined in
/// PropertySetIO.h
#define __SYCL_PI_PROPERTY_SET_SPEC_CONST_MAP "SYCL/specialization constants"
/// PropertySetRegistry::SYCL_SPEC_CONSTANTS_DEFAULT_VALUES defined in
/// PropertySetIO.h
#define __SYCL_PI_PROPERTY_SET_SPEC_CONST_DEFAULT_VALUES_MAP \
"SYCL/specialization constants default values"
/// PropertySetRegistry::SYCL_DEVICELIB_REQ_MASK defined in PropertySetIO.h
#define __SYCL_PI_PROPERTY_SET_DEVICELIB_REQ_MASK "SYCL/devicelib req mask"
/// PropertySetRegistry::SYCL_KERNEL_PARAM_OPT_INFO defined in PropertySetIO.h
Expand Down
8 changes: 8 additions & 0 deletions sycl/include/CL/sycl/detail/pi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,14 @@ class DeviceBinaryImage {
/// like:
/// { ID5, 0, 4 }
const PropertyRange &getSpecConstants() const { return SpecConstIDMap; }
const PropertyRange getSpecConstantsDefaultValues() const {
// We can't have this variable as a class member, since it would break
// the ABI backwards compatibility.
DeviceBinaryImage::PropertyRange SpecConstDefaultValuesMap;
SpecConstDefaultValuesMap.init(
Bin, __SYCL_PI_PROPERTY_SET_SPEC_CONST_DEFAULT_VALUES_MAP);
return SpecConstDefaultValuesMap;
}
const PropertyRange &getDeviceLibReqMask() const { return DeviceLibReqMask; }
const PropertyRange &getKernelParamOptInfo() const {
return KernelParamOptInfo;
Expand Down
16 changes: 15 additions & 1 deletion sycl/source/detail/device_image_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ class device_image_impl {
MBinImage->getSpecConstants();
using SCItTy = pi::DeviceBinaryImage::PropertyRange::ConstIterator;

// get default values for specialization constants
const pi::DeviceBinaryImage::PropertyRange &SCDefValRange =
MBinImage->getSpecConstantsDefaultValues();

bool HasDefaultValues = SCDefValRange.begin() != SCDefValRange.end();

// This variable is used to calculate spec constant value offset in a
// flat byte array.
unsigned BlobOffset = 0;
Expand Down Expand Up @@ -237,12 +243,20 @@ class device_image_impl {
// supposed to be called from c'tor.
MSpecConstSymMap[std::string{SCName}].push_back(
SpecConstDescT{/*ID*/ It[0], /*CompositeOffset*/ It[1],
/*Size*/ It[2], BlobOffset});
/*Size*/ It[2], BlobOffset, HasDefaultValues});
BlobOffset += /*Size*/ It[2];
It += NumElements;
}
}
MSpecConstsBlob.resize(BlobOffset);

if (HasDefaultValues) {
pi::ByteArray DefValDescriptors =
pi::DeviceBinaryProperty(*SCDefValRange.begin()).asByteArray();
std::uninitialized_copy(&DefValDescriptors[8],
&DefValDescriptors[8] + MSpecConstsBlob.size(),
MSpecConstsBlob.data());
}
}
}

Expand Down
1 change: 1 addition & 0 deletions sycl/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ add_subdirectory(pi)
add_subdirectory(kernel-and-program)
add_subdirectory(queue)
add_subdirectory(scheduler)
add_subdirectory(spec_constants)
add_subdirectory(thread_safety)
Loading