Skip to content

Commit 4a2e36e

Browse files
committed
Revert changes to PM and just use prefix to identify kernels
Signed-off-by: Julian Oppermann <[email protected]>
1 parent 100ea1d commit 4a2e36e

File tree

7 files changed

+43
-35
lines changed

7 files changed

+43
-35
lines changed

sycl/source/detail/jit_compiler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ std::vector<uint8_t> jit_compiler::encodeReqdWorkGroupSize(
12101210
}
12111211

12121212
sycl_device_binaries jit_compiler::compileSYCL(
1213-
const std::string &Id, const std::string &SYCLSource,
1213+
const std::string &CompilationID, const std::string &SYCLSource,
12141214
const std::vector<std::pair<std::string, std::string>> &IncludePairs,
12151215
const std::vector<std::string> &UserArgs, std::string *LogPtr,
12161216
const std::vector<std::string> &RegisteredKernelNames) {
@@ -1227,7 +1227,7 @@ sycl_device_binaries jit_compiler::compileSYCL(
12271227

12281228
std::string FinalSource = ss.str();
12291229

1230-
std::string SYCLFileName = Id + ".cpp";
1230+
std::string SYCLFileName = CompilationID + ".cpp";
12311231
::jit_compiler::InMemoryFile SourceFile{SYCLFileName.c_str(),
12321232
FinalSource.c_str()};
12331233

@@ -1255,7 +1255,7 @@ sycl_device_binaries jit_compiler::compileSYCL(
12551255
}
12561256

12571257
return createDeviceBinaryImage(Result.getBundleInfo(),
1258-
/*OffloadEntryPrefix=*/Id + '$');
1258+
/*OffloadEntryPrefix=*/CompilationID + '$');
12591259
}
12601260

12611261
} // namespace detail

sycl/source/detail/jit_compiler.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class jit_compiler {
4646
const std::vector<unsigned char> &SpecConstBlob);
4747

4848
sycl_device_binaries compileSYCL(
49-
const std::string &Id, const std::string &SYCLSource,
49+
const std::string &CompilationID, const std::string &SYCLSource,
5050
const std::vector<std::pair<std::string, std::string>> &IncludePairs,
5151
const std::vector<std::string> &UserArgs, std::string *LogPtr,
5252
const std::vector<std::string> &RegisteredKernelNames);

sycl/source/detail/kernel_bundle_impl.hpp

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -479,34 +479,30 @@ class kernel_bundle_impl {
479479
// TODO: Support persistent caching.
480480

481481
const std::string &SourceStr = std::get<std::string>(this->Source);
482-
auto [Binaries, Id] = syclex::detail::SYCL_JIT_to_SPIRV(
482+
auto [Binaries, CompilationID] = syclex::detail::SYCL_JIT_to_SPIRV(
483483
SourceStr, IncludePairs, BuildOptions, LogPtr, RegisteredKernelNames);
484484

485485
assert(Binaries->NumDeviceBinaries == 1);
486486

487487
auto &PM = detail::ProgramManager::getInstance();
488-
std::unordered_set<uintptr_t> ImageIds;
489-
PM.addImages(Binaries, &ImageIds);
490-
auto DevImgs = PM.getSYCLDeviceImages(
491-
MContext, MDevices,
492-
[&ImageIds](const detail::DeviceImageImplPtr &DevImgImpl) -> bool {
493-
return ImageIds.count(
494-
DevImgImpl->get_bin_image_ref()->getImageID());
495-
},
496-
bundle_state::executable);
497-
498-
PM.bringSYCLDeviceImagesToState(DevImgs, bundle_state::executable);
488+
PM.addImages(Binaries);
499489

490+
std::vector<kernel_id> KernelIDs;
500491
std::vector<std::string> KernelNames;
501-
std::transform(Binaries->DeviceBinaries->EntriesBegin,
502-
Binaries->DeviceBinaries->EntriesEnd,
503-
std::back_inserter(KernelNames),
504-
[PrefixLen = Id.length() + 1](auto &OffloadEntry) {
505-
// `jit_compiler::compileSYCL` uses `Id + '$'` as name
506-
// prefix; drop that here.
507-
return std::string{OffloadEntry.name + PrefixLen};
508-
});
492+
// `jit_compiler::compileSYCL(..)` uses `CompilationID + '$'` as prefix
493+
// for offload entry names.
494+
std::string Prefix = CompilationID + '$';
495+
for (const auto &KernelID : PM.getAllSYCLKernelIDs()) {
496+
std::string_view KernelName{KernelID.get_name()};
497+
if (KernelName.find(Prefix) == 0) {
498+
KernelIDs.push_back(KernelID);
499+
KernelName.remove_prefix(Prefix.length());
500+
KernelNames.emplace_back(KernelName);
501+
}
502+
}
509503

504+
auto DevImgs = PM.getSYCLDeviceImages(MContext, MDevices, KernelIDs,
505+
bundle_state::executable);
510506
assert(DevImgs.size() == 1);
511507
assert(!DevImgs.front().hasDeps());
512508

sycl/source/detail/kernel_compiler/kernel_compiler_sycl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,13 @@ std::pair<sycl_device_binaries, std::string> SYCL_JIT_to_SPIRV(
350350
[[maybe_unused]] std::string *LogPtr,
351351
[[maybe_unused]] const std::vector<std::string> &RegisteredKernelNames) {
352352
#if SYCL_EXT_JIT_ENABLE
353-
static std::atomic_uintptr_t CompilationId;
354-
std::string Id = "rtc_" + std::to_string(CompilationId++);
353+
static std::atomic_uintptr_t CompilationCounter;
354+
std::string CompilationID = "rtc_" + std::to_string(CompilationCounter++);
355355
sycl_device_binaries Binaries =
356356
sycl::detail::jit_compiler::get_instance().compileSYCL(
357-
Id, SYCLSource, IncludePairs, UserArgs, LogPtr,
357+
CompilationID, SYCLSource, IncludePairs, UserArgs, LogPtr,
358358
RegisteredKernelNames);
359-
return std::make_pair(Binaries, std::move(Id));
359+
return std::make_pair(Binaries, std::move(CompilationID));
360360
#else
361361
throw sycl::exception(sycl::errc::build,
362362
"kernel_compiler via sycl-jit is not available");

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,8 +1802,7 @@ ProgramManager::kernelImplicitLocalArgPos(const std::string &KernelName) const {
18021802
return {};
18031803
}
18041804

1805-
void ProgramManager::addImages(sycl_device_binaries DeviceBinary,
1806-
std::unordered_set<uintptr_t> *ImageIds) {
1805+
void ProgramManager::addImages(sycl_device_binaries DeviceBinary) {
18071806
const bool DumpImages = std::getenv("SYCL_DUMP_IMAGES") && !m_UseSpvFile;
18081807
for (int I = 0; I < DeviceBinary->NumDeviceBinaries; I++) {
18091808
sycl_device_binary RawImg = &(DeviceBinary->DeviceBinaries[I]);
@@ -1826,9 +1825,6 @@ void ProgramManager::addImages(sycl_device_binaries DeviceBinary,
18261825
else
18271826
Img = std::make_unique<RTDeviceBinaryImage>(RawImg);
18281827

1829-
if (ImageIds)
1830-
ImageIds->insert(Img->getImageID());
1831-
18321828
static uint32_t SequenceID = 0;
18331829

18341830
// Fill the kernel argument mask map

sycl/source/detail/program_manager/program_manager.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,7 @@ class ProgramManager {
210210
ur_program_handle_t getUrProgramFromUrKernel(ur_kernel_handle_t Kernel,
211211
const ContextImplPtr Context);
212212

213-
void addImages(sycl_device_binaries DeviceImages,
214-
std::unordered_set<uintptr_t> *ImageIds = nullptr);
213+
void addImages(sycl_device_binaries DeviceImages);
215214
void debugPrintBinaryImages() const;
216215
static std::string getProgramBuildLog(const ur_program_handle_t &Program,
217216
const ContextImplPtr Context);

sycl/test-e2e/KernelCompiler/kernel_compiler_sycl_jit.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,23 @@ int test_build_and_run() {
194194
test_1(q, k, 37 + 5); // ff_cp seeds 37. AddEm will add 5 more.
195195
test_1(q, k2, 38 + 6); // ff_templated seeds 38. PlusEm adds 6 more.
196196

197+
// Create and compile new bundle with different header.
198+
std::string AddEmHModified = AddEmH;
199+
AddEmHModified[AddEmHModified.find('5')] = '7';
200+
syclex::include_files incFiles2{"intermediate/AddEm.h", AddEmHModified};
201+
incFiles2.add("intermediate/PlusEm.h", PlusEmH);
202+
source_kb kbSrc2 = syclex::create_kernel_bundle_from_source(
203+
ctx, syclex::source_language::sycl_jit, SYCLSource,
204+
syclex::properties{incFiles2});
205+
206+
exe_kb kbExe3 = syclex::build(kbSrc2);
207+
sycl::kernel k3 = kbExe3.ext_oneapi_get_kernel("ff_cp");
208+
test_1(q, k3, 37 + 7);
209+
210+
// Can we still run the original compilation?
211+
sycl::kernel k4 = kbExe1.ext_oneapi_get_kernel("ff_cp");
212+
test_1(q, k4, 37 + 5);
213+
197214
return 0;
198215
}
199216

0 commit comments

Comments
 (0)