Skip to content

Commit 07b2796

Browse files
dm-vodopyanovAlexander Batashev
andauthored
[SYCL] Add DPC++ RT support for SYCL2020 spec constants' default values (#3667)
This patch introduces the support of default values for SYCL2020 specialization constants in DPC++ runtime. Co-authored-by: Alexander Batashev <[email protected]>
1 parent 2be4117 commit 07b2796

File tree

7 files changed

+692
-1
lines changed

7 files changed

+692
-1
lines changed

sycl/include/CL/sycl/detail/pi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,10 @@ static const uint8_t PI_DEVICE_BINARY_OFFLOAD_KIND_SYCL = 4;
673673
/// PropertySetRegistry::SYCL_SPECIALIZATION_CONSTANTS defined in
674674
/// PropertySetIO.h
675675
#define __SYCL_PI_PROPERTY_SET_SPEC_CONST_MAP "SYCL/specialization constants"
676+
/// PropertySetRegistry::SYCL_SPEC_CONSTANTS_DEFAULT_VALUES defined in
677+
/// PropertySetIO.h
678+
#define __SYCL_PI_PROPERTY_SET_SPEC_CONST_DEFAULT_VALUES_MAP \
679+
"SYCL/specialization constants default values"
676680
/// PropertySetRegistry::SYCL_DEVICELIB_REQ_MASK defined in PropertySetIO.h
677681
#define __SYCL_PI_PROPERTY_SET_DEVICELIB_REQ_MASK "SYCL/devicelib req mask"
678682
/// PropertySetRegistry::SYCL_KERNEL_PARAM_OPT_INFO defined in PropertySetIO.h

sycl/include/CL/sycl/detail/pi.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,14 @@ class DeviceBinaryImage {
318318
/// like:
319319
/// { ID5, 0, 4 }
320320
const PropertyRange &getSpecConstants() const { return SpecConstIDMap; }
321+
const PropertyRange getSpecConstantsDefaultValues() const {
322+
// We can't have this variable as a class member, since it would break
323+
// the ABI backwards compatibility.
324+
DeviceBinaryImage::PropertyRange SpecConstDefaultValuesMap;
325+
SpecConstDefaultValuesMap.init(
326+
Bin, __SYCL_PI_PROPERTY_SET_SPEC_CONST_DEFAULT_VALUES_MAP);
327+
return SpecConstDefaultValuesMap;
328+
}
321329
const PropertyRange &getDeviceLibReqMask() const { return DeviceLibReqMask; }
322330
const PropertyRange &getKernelParamOptInfo() const {
323331
return KernelParamOptInfo;

sycl/source/detail/device_image_impl.hpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ class device_image_impl {
218218
MBinImage->getSpecConstants();
219219
using SCItTy = pi::DeviceBinaryImage::PropertyRange::ConstIterator;
220220

221+
// get default values for specialization constants
222+
const pi::DeviceBinaryImage::PropertyRange &SCDefValRange =
223+
MBinImage->getSpecConstantsDefaultValues();
224+
225+
bool HasDefaultValues = SCDefValRange.begin() != SCDefValRange.end();
226+
221227
// This variable is used to calculate spec constant value offset in a
222228
// flat byte array.
223229
unsigned BlobOffset = 0;
@@ -250,12 +256,20 @@ class device_image_impl {
250256
// supposed to be called from c'tor.
251257
MSpecConstSymMap[std::string{SCName}].push_back(
252258
SpecConstDescT{/*ID*/ It[0], /*CompositeOffset*/ It[1],
253-
/*Size*/ It[2], BlobOffset});
259+
/*Size*/ It[2], BlobOffset, HasDefaultValues});
254260
BlobOffset += /*Size*/ It[2];
255261
It += NumElements;
256262
}
257263
}
258264
MSpecConstsBlob.resize(BlobOffset);
265+
266+
if (HasDefaultValues) {
267+
pi::ByteArray DefValDescriptors =
268+
pi::DeviceBinaryProperty(*SCDefValRange.begin()).asByteArray();
269+
std::uninitialized_copy(&DefValDescriptors[8],
270+
&DefValDescriptors[8] + MSpecConstsBlob.size(),
271+
MSpecConstsBlob.data());
272+
}
259273
}
260274
}
261275

sycl/unittests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ add_subdirectory(pi)
1515
add_subdirectory(kernel-and-program)
1616
add_subdirectory(queue)
1717
add_subdirectory(scheduler)
18+
add_subdirectory(spec_constants)
1819
add_subdirectory(thread_safety)

0 commit comments

Comments
 (0)