Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions sycl/include/CL/sycl/detail/pi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ class DeviceBinaryImage {
return AssertUsed;
}
const PropertyRange &getProgramMetadata() const { return ProgramMetadata; }
const PropertyRange &getExportedSymbols() const { return ExportedSymbols; }
virtual ~DeviceBinaryImage() {}

protected:
Expand All @@ -381,6 +382,7 @@ class DeviceBinaryImage {
DeviceBinaryImage::PropertyRange DeviceLibReqMask;
DeviceBinaryImage::PropertyRange KernelParamOptInfo;
DeviceBinaryImage::PropertyRange ProgramMetadata;
DeviceBinaryImage::PropertyRange ExportedSymbols;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smaslov-intel do we have usages of this structure outside of sycl/source directory? If not, we should move this class inside the lib, otherwise this is a breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I see something similar is done for getSpecConstantsDefaultValues. I will adopt that approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been changed. It should no longer be a breaking change. Thanks for pointing it out!

};

/// Tries to determine the device binary image foramat. Returns
Expand Down
1 change: 1 addition & 0 deletions sycl/source/detail/pi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ void DeviceBinaryImage::init(pi_device_binary Bin) {
DeviceLibReqMask.init(Bin, __SYCL_PI_PROPERTY_SET_DEVICELIB_REQ_MASK);
KernelParamOptInfo.init(Bin, __SYCL_PI_PROPERTY_SET_KERNEL_PARAM_OPT_INFO);
ProgramMetadata.init(Bin, __SYCL_PI_PROPERTY_SET_PROGRAM_METADATA);
ExportedSymbols.init(Bin, __SYCL_PI_PROPERTY_SET_SYCL_EXPORTED_SYMBOLS);
}

} // namespace pi
Expand Down
21 changes: 18 additions & 3 deletions sycl/source/detail/program_manager/program_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,12 @@ void ProgramManager::addImages(pi_device_binaries DeviceBinary) {
KernelSetId KSId = getNextKernelSetId();
{
std::lock_guard<std::mutex> KernelIDsGuard(m_KernelIDsMutex);

// Register all exported symbols
auto ExportedSymbols = Img->getExportedSymbols();
for (const pi_device_binary_property &ExportedSymbol : ExportedSymbols)
m_ExportedSymbols.insert(ExportedSymbol->Name);

for (_pi_offload_entry EntriesIt = EntriesB; EntriesIt != EntriesE;
++EntriesIt) {
auto Result = KSIdMap.insert(std::make_pair(EntriesIt->name, KSId));
Expand All @@ -1074,6 +1080,13 @@ void ProgramManager::addImages(pi_device_binaries DeviceBinary) {
continue;
}

// Skip creating unique kernel ID if it is an exported device
// function. Exported device functions appear in the offload entries
// among kernels, but are identifiable by being listed in properties.
if (m_ExportedSymbols.find(EntriesIt->name) !=
m_ExportedSymbols.end())
continue;

// ... and create a unique kernel ID for the entry
std::shared_ptr<detail::kernel_id_impl> KernelIDImpl =
std::make_shared<detail::kernel_id_impl>(EntriesIt->name);
Expand Down Expand Up @@ -1373,9 +1386,11 @@ ProgramManager::getSYCLDeviceImagesWithCompatibleState(
auto KernelID = m_KernelIDs.find(EntriesIt->name);

if (KernelID == m_KernelIDs.end()) {
// Service kernels do not have kernel IDs
assert(m_ServiceKernels.find(EntriesIt->name) !=
m_ServiceKernels.end() &&
// Service kernels and exported symbols do not have kernel IDs
assert((m_ServiceKernels.find(EntriesIt->name) !=
m_ServiceKernels.end() ||
m_ExportedSymbols.find(EntriesIt->name) !=
m_ExportedSymbols.end()) &&
"Kernel ID in device binary missing from cache");
continue;
}
Expand Down
5 changes: 5 additions & 0 deletions sycl/source/detail/program_manager/program_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ class ProgramManager {
/// Access must be guarded by the m_KernelIDsMutex mutex.
std::unordered_set<std::string> m_ServiceKernels;

/// Caches all exported symbols to allow faster lookup when excluding these
// from kernel bundles.
/// Access must be guarded by the m_KernelIDsMutex mutex.
std::unordered_set<std::string> m_ExportedSymbols;

// Keeps track of pi_program to image correspondence. Needed for:
// - knowing which specialization constants are used in the program and
// injecting their current values before compiling the SPIR-V; the binary
Expand Down