Skip to content

Commit 768c110

Browse files
committed
add device image map in ProgramManager
Signed-off-by: jinge90 <[email protected]>
1 parent 7004d14 commit 768c110

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

sycl/source/detail/compiler.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
"SYCL/specialization constants default values"
4747
/// PropertySetRegistry::SYCL_DEVICELIB_REQ_MASK defined in PropertySetIO.h
4848
#define __SYCL_PROPERTY_SET_DEVICELIB_REQ_MASK "SYCL/devicelib req mask"
49+
/// PropertySetRegistry::SYCL_DEVICELIB_METADATA defined in PropertySetIO.h
50+
#define __SYCL_PROPERTY_SET_DEVICELIB_METADATA "SYCL/devicelib metadata"
4951
/// PropertySetRegistry::SYCL_KERNEL_PARAM_OPT_INFO defined in PropertySetIO.h
5052
#define __SYCL_PROPERTY_SET_KERNEL_PARAM_OPT_INFO "SYCL/kernel param opt"
5153
/// PropertySetRegistry::SYCL_KERNEL_PROGRAM_METADATA defined in PropertySetIO.h

sycl/source/detail/device_binary_image.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ void RTDeviceBinaryImage::init(sycl_device_binary Bin) {
180180
SpecConstDefaultValuesMap.init(
181181
Bin, __SYCL_PROPERTY_SET_SPEC_CONST_DEFAULT_VALUES_MAP);
182182
DeviceLibReqMask.init(Bin, __SYCL_PROPERTY_SET_DEVICELIB_REQ_MASK);
183+
DeviceLibMetaData.init(Bin, __SYCL_PROPERTY_SET_DEVICELIB_METADATA);
183184
KernelParamOptInfo.init(Bin, __SYCL_PROPERTY_SET_KERNEL_PARAM_OPT_INFO);
184185
AssertUsed.init(Bin, __SYCL_PROPERTY_SET_SYCL_ASSERT_USED);
185186
ProgramMetadata.init(Bin, __SYCL_PROPERTY_SET_PROGRAM_METADATA);

sycl/source/detail/device_binary_image.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ class RTDeviceBinaryImage {
214214
return SpecConstDefaultValuesMap;
215215
}
216216
const PropertyRange &getDeviceLibReqMask() const { return DeviceLibReqMask; }
217+
const PropertyRange &getDeviceLibMetaData() const {
218+
return DeviceLibMetaData;
219+
}
217220
const PropertyRange &getKernelParamOptInfo() const {
218221
return KernelParamOptInfo;
219222
}
@@ -246,6 +249,7 @@ class RTDeviceBinaryImage {
246249
RTDeviceBinaryImage::PropertyRange SpecConstIDMap;
247250
RTDeviceBinaryImage::PropertyRange SpecConstDefaultValuesMap;
248251
RTDeviceBinaryImage::PropertyRange DeviceLibReqMask;
252+
RTDeviceBinaryImage::PropertyRange DeviceLibMetaData;
249253
RTDeviceBinaryImage::PropertyRange KernelParamOptInfo;
250254
RTDeviceBinaryImage::PropertyRange AssertUsed;
251255
RTDeviceBinaryImage::PropertyRange ProgramMetadata;

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,8 @@ setSpecializationConstants(const std::shared_ptr<device_image_impl> &InputImpl,
752752
}
753753
}
754754

755-
static inline void CheckAndDecompressImage([[maybe_unused]] RTDeviceBinaryImage *Img) {
755+
static inline void
756+
CheckAndDecompressImage([[maybe_unused]] RTDeviceBinaryImage *Img) {
756757
#ifndef SYCL_RT_ZSTD_NOT_AVAIABLE
757758
if (auto CompImg = dynamic_cast<CompressedRTDeviceBinaryImage *>(Img))
758759
if (CompImg->IsCompressed())
@@ -1772,9 +1773,25 @@ void ProgramManager::addImages(sycl_device_binaries DeviceBinary) {
17721773
sycl_device_binary RawImg = &(DeviceBinary->DeviceBinaries[I]);
17731774
const sycl_offload_entry EntriesB = RawImg->EntriesBegin;
17741775
const sycl_offload_entry EntriesE = RawImg->EntriesEnd;
1775-
// Treat the image as empty one
1776-
if (EntriesB == EntriesE)
1776+
// Treat the image as empty one or devicelib images
1777+
if (EntriesB == EntriesE) {
1778+
std::unique_ptr<RTDeviceBinaryImage> Img =
1779+
std::make_unique<RTDeviceBinaryImage>(RawImg);
1780+
const RTDeviceBinaryImage::PropertyRange &DeviceLibMetaProp =
1781+
Img->getDeviceLibMetaData();
1782+
if (DeviceLibMetaProp.isAvailable()) {
1783+
std::lock_guard<std::mutex> DeviceLibImagesGuard(
1784+
m_DeviceLibImagesMutex);
1785+
unsigned DeviceLibMetaData =
1786+
DeviceBinaryProperty(*(DeviceLibMetaProp.begin())).asUint32();
1787+
// Add device library image to device image map only when current
1788+
// key has not been inserted.
1789+
if (m_DeviceLibImages.find(DeviceLibMetaData) ==
1790+
m_DeviceLibImages.end())
1791+
m_DeviceLibImages[DeviceLibMetaData] = std::move(Img);
1792+
}
17771793
continue;
1794+
}
17781795

17791796
std::unique_ptr<RTDeviceBinaryImage> Img;
17801797
if (isDeviceImageCompressed(RawImg))

sycl/source/detail/program_manager/program_manager.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ class ProgramManager {
343343
/// identified by its name.
344344
using RTDeviceBinaryImageUPtr = std::unique_ptr<RTDeviceBinaryImage>;
345345

346+
std::mutex m_DeviceLibImagesMutex;
347+
348+
std::unordered_map<unsigned, RTDeviceBinaryImageUPtr> m_DeviceLibImages;
349+
346350
/// Maps names of kernels to their unique kernel IDs.
347351
/// TODO: Use std::unordered_set with transparent hash and equality functions
348352
/// when C++20 is enabled for the runtime library.

0 commit comments

Comments
 (0)