@@ -162,7 +162,7 @@ RTDeviceBinaryImage::getProperty(const char *PropName) const {
162162 return *It;
163163}
164164
165- void RTDeviceBinaryImage::init (sycl_device_binary Bin) {
165+ RTDeviceBinaryImage::RTDeviceBinaryImage (sycl_device_binary Bin) {
166166 ImageId = ImageCounter++;
167167
168168 // If there was no binary, we let the owner handle initialization as they see
@@ -199,6 +199,7 @@ void RTDeviceBinaryImage::init(sycl_device_binary Bin) {
199199 ProgramMetadataUR.push_back (
200200 ur::mapDeviceBinaryPropertyToProgramMetadata (Prop));
201201 }
202+ KernelNames.init (Bin, __SYCL_PROPERTY_SET_SYCL_KERNEL_NAMES);
202203 ExportedSymbols.init (Bin, __SYCL_PROPERTY_SET_SYCL_EXPORTED_SYMBOLS);
203204 ImportedSymbols.init (Bin, __SYCL_PROPERTY_SET_SYCL_IMPORTED_SYMBOLS);
204205 DeviceGlobals.init (Bin, __SYCL_PROPERTY_SET_SYCL_DEVICE_GLOBALS);
@@ -211,7 +212,8 @@ void RTDeviceBinaryImage::init(sycl_device_binary Bin) {
211212
212213std::atomic<uintptr_t > RTDeviceBinaryImage::ImageCounter = 1 ;
213214
214- DynRTDeviceBinaryImage::DynRTDeviceBinaryImage () : RTDeviceBinaryImage() {
215+ DynRTDeviceBinaryImage::DynRTDeviceBinaryImage ()
216+ : RTDeviceBinaryImage(nullptr ) {
215217 Bin = new sycl_device_binary_struct ();
216218 Bin->Version = SYCL_DEVICE_BINARY_VERSION;
217219 Bin->Kind = SYCL_DEVICE_BINARY_OFFLOAD_KIND_SYCL;
@@ -227,12 +229,11 @@ DynRTDeviceBinaryImage::DynRTDeviceBinaryImage() : RTDeviceBinaryImage() {
227229 Bin->DeviceTargetSpec = __SYCL_DEVICE_BINARY_TARGET_UNKNOWN;
228230}
229231
230- DynRTDeviceBinaryImage::DynRTDeviceBinaryImage (
231- std::unique_ptr<char [], std::function<void (void *)>> &&DataPtr,
232- size_t DataSize)
233- : DynRTDeviceBinaryImage() {
234- Data = std::move (DataPtr);
235- Bin->BinaryStart = reinterpret_cast <unsigned char *>(Data.get ());
232+ std::unique_ptr<sycl_device_binary_struct> CreateDefaultDynBinary (
233+ const std::unique_ptr<char [], std::function<void (void *)>> &DataPtr,
234+ size_t DataSize) {
235+ auto Bin = std::make_unique<sycl_device_binary_struct>();
236+ Bin->BinaryStart = reinterpret_cast <unsigned char *>(DataPtr.get ());
236237 Bin->BinaryEnd = Bin->BinaryStart + DataSize;
237238 Bin->Format = ur::getBinaryImageFormat (Bin->BinaryStart , DataSize);
238239 switch (Bin->Format ) {
@@ -242,9 +243,15 @@ DynRTDeviceBinaryImage::DynRTDeviceBinaryImage(
242243 default :
243244 Bin->DeviceTargetSpec = __SYCL_DEVICE_BINARY_TARGET_UNKNOWN;
244245 }
245- init ( Bin) ;
246+ return Bin;
246247}
247248
249+ DynRTDeviceBinaryImage::DynRTDeviceBinaryImage (
250+ std::unique_ptr<char [], std::function<void (void *)>> &&DataPtr,
251+ size_t DataSize)
252+ : RTDeviceBinaryImage(CreateDefaultDynBinary(DataPtr, DataSize).release()),
253+ Data{std::move (DataPtr)} {}
254+
248255DynRTDeviceBinaryImage::~DynRTDeviceBinaryImage () {
249256 delete Bin;
250257 Bin = nullptr ;
@@ -479,8 +486,6 @@ static void copyProperty(sycl_device_binary_property &NextFreeProperty,
479486DynRTDeviceBinaryImage::DynRTDeviceBinaryImage (
480487 const std::vector<const RTDeviceBinaryImage *> &Imgs)
481488 : DynRTDeviceBinaryImage() {
482- init (nullptr );
483-
484489 // Naive merges.
485490 auto MergedSpecConstants =
486491 naiveMergeBinaryProperties (Imgs, [](const RTDeviceBinaryImage &Img) {
@@ -510,6 +515,10 @@ DynRTDeviceBinaryImage::DynRTDeviceBinaryImage(
510515 naiveMergeBinaryProperties (Imgs, [](const RTDeviceBinaryImage &Img) {
511516 return Img.getImplicitLocalArg ();
512517 });
518+ auto MergedKernelNames =
519+ naiveMergeBinaryProperties (Imgs, [](const RTDeviceBinaryImage &Img) {
520+ return Img.getKernelNames ();
521+ });
513522 auto MergedExportedSymbols =
514523 naiveMergeBinaryProperties (Imgs, [](const RTDeviceBinaryImage &Img) {
515524 return Img.getExportedSymbols ();
@@ -519,12 +528,13 @@ DynRTDeviceBinaryImage::DynRTDeviceBinaryImage(
519528 return Img.getRegisteredKernels ();
520529 });
521530
522- std::array<const std::vector<sycl_device_binary_property> *, 10 > MergedVecs{
531+ std::array<const std::vector<sycl_device_binary_property> *, 11 > MergedVecs{
523532 &MergedSpecConstants, &MergedSpecConstantsDefaultValues,
524533 &MergedKernelParamOptInfo, &MergedAssertUsed,
525534 &MergedDeviceGlobals, &MergedHostPipes,
526535 &MergedVirtualFunctions, &MergedImplicitLocalArg,
527- &MergedExportedSymbols, &MergedRegisteredKernels};
536+ &MergedKernelNames, &MergedExportedSymbols,
537+ &MergedRegisteredKernels};
528538
529539 // Exclusive merges.
530540 auto MergedDeviceLibReqMask =
@@ -648,6 +658,7 @@ DynRTDeviceBinaryImage::DynRTDeviceBinaryImage(
648658 CopyPropertiesVec (MergedHostPipes, HostPipes);
649659 CopyPropertiesVec (MergedVirtualFunctions, VirtualFunctions);
650660 CopyPropertiesVec (MergedImplicitLocalArg, ImplicitLocalArg);
661+ CopyPropertiesVec (MergedKernelNames, KernelNames);
651662 CopyPropertiesVec (MergedExportedSymbols, ExportedSymbols);
652663 CopyPropertiesVec (MergedRegisteredKernels, RegisteredKernels);
653664
@@ -675,18 +686,11 @@ DynRTDeviceBinaryImage::DynRTDeviceBinaryImage(
675686#ifdef SYCL_RT_ZSTD_AVAILABLE
676687CompressedRTDeviceBinaryImage::CompressedRTDeviceBinaryImage (
677688 sycl_device_binary CompressedBin)
678- : RTDeviceBinaryImage() {
679-
680- // 'CompressedBin' is part of the executable image loaded into memory
681- // which can't be modified easily. So, we need to make a copy of it.
682- Bin = new sycl_device_binary_struct (*CompressedBin);
683-
689+ : RTDeviceBinaryImage(new sycl_device_binary_struct(*CompressedBin)) {
684690 // Get the decompressed size of the binary image.
685691 m_ImageSize = ZSTDCompressor::GetDecompressedSize (
686692 reinterpret_cast <const char *>(Bin->BinaryStart ),
687693 static_cast <size_t >(Bin->BinaryEnd - Bin->BinaryStart ));
688-
689- init (Bin);
690694}
691695
692696void CompressedRTDeviceBinaryImage::Decompress () {
0 commit comments