Skip to content

Commit b031186

Browse files
committed
[SYCL] Add exception on recompile of AOT compiled kernel by program api
Signed-off-by: Alexander Flegontov <[email protected]>
1 parent 06ac152 commit b031186

19 files changed

+302
-180
lines changed

sycl/source/detail/program_impl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ void program_impl::build_with_kernel_name(string_class KernelName,
231231
if (is_cacheable_with_options(BuildOptions)) {
232232
MProgramAndKernelCachingAllowed = true;
233233
MProgram = ProgramManager::getInstance().getBuiltPIProgram(
234-
Module, get_context(), KernelName, this);
234+
Module, get_context(), KernelName, this, true);
235235
const detail::plugin &Plugin = getPlugin();
236236
Plugin.call<PiApiKind::piProgramRetain>(MProgram);
237237
} else {
@@ -440,7 +440,7 @@ void program_impl::create_pi_program_with_kernel_name(
440440
assert(!MProgram && "This program already has an encapsulated PI program");
441441
ProgramManager &PM = ProgramManager::getInstance();
442442
RTDeviceBinaryImage &Img =
443-
PM.getDeviceImage(Module, KernelName, get_context());
443+
PM.getDeviceImage(Module, KernelName, get_context(), true);
444444
MProgram = PM.createPIProgram(Img, get_context());
445445
}
446446

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ static RT::PiProgram createSpirvProgram(const ContextImplPtr Context,
136136

137137
RTDeviceBinaryImage &
138138
ProgramManager::getDeviceImage(OSModuleHandle M, const string_class &KernelName,
139-
const context &Context) {
139+
const context &Context, bool FromProgramApi) {
140140
if (DbgProgMgr > 0)
141141
std::cerr << ">>> ProgramManager::getDeviceImage(" << M << ", \""
142142
<< KernelName << "\", " << getRawSyclObjImpl(Context) << ")\n";
143143

144144
KernelSetId KSId = getKernelSetId(M, KernelName);
145-
return getDeviceImage(M, KSId, Context);
145+
return getDeviceImage(M, KSId, Context, FromProgramApi);
146146
}
147147

148148
template <typename ExceptionT, typename RetT>
@@ -360,7 +360,7 @@ RT::PiProgram ProgramManager::createPIProgram(const RTDeviceBinaryImage &Img,
360360
RT::PiProgram ProgramManager::getBuiltPIProgram(OSModuleHandle M,
361361
const context &Context,
362362
const string_class &KernelName,
363-
const program_impl *Prg) {
363+
const program_impl *Prg, bool FromProgramApi) {
364364
KernelSetId KSId = getKernelSetId(M, KernelName);
365365

366366
const ContextImplPtr Ctx = getSyclObjImpl(Context);
@@ -376,8 +376,8 @@ RT::PiProgram ProgramManager::getBuiltPIProgram(OSModuleHandle M,
376376
auto GetF = [](const Locked<ProgramCacheT> &LockedCache) -> ProgramCacheT& {
377377
return LockedCache.get();
378378
};
379-
auto BuildF = [this, &M, &KSId, &Context, Prg] {
380-
const RTDeviceBinaryImage &Img = getDeviceImage(M, KSId, Context);
379+
auto BuildF = [this, &M, &KSId, &Context, Prg, &FromProgramApi] {
380+
const RTDeviceBinaryImage &Img = getDeviceImage(M, KSId, Context, FromProgramApi);
381381

382382
ContextImplPtr ContextImpl = getSyclObjImpl(Context);
383383
const detail::plugin &Plugin = ContextImpl->getPlugin();
@@ -634,7 +634,8 @@ ProgramManager::ProgramManager() {
634634

635635
RTDeviceBinaryImage &ProgramManager::getDeviceImage(OSModuleHandle M,
636636
KernelSetId KSId,
637-
const context &Context) {
637+
const context &Context,
638+
bool FromProgramApi) {
638639
if (DbgProgMgr > 0) {
639640
std::cerr << ">>> ProgramManager::getDeviceImage(" << M << ", \"" << KSId
640641
<< "\", " << getRawSyclObjImpl(Context) << ")\n";
@@ -660,6 +661,18 @@ RTDeviceBinaryImage &ProgramManager::getDeviceImage(OSModuleHandle M,
660661

661662
Ctx->getPlugin().call<PiApiKind::piextDeviceSelectBinary>(
662663
getFirstDevice(Ctx), RawImgs.data(), (cl_uint)RawImgs.size(), &ImgInd);
664+
665+
if (FromProgramApi) {
666+
// if the image is already compiled with AOT then throws exception
667+
const pi_device_binary_struct &RawImg = Imgs[ImgInd]->getRawData();
668+
if ((strcmp(RawImg.DeviceTargetSpec, PI_DEVICE_BINARY_TARGET_SPIRV64_X86_64) == 0) ||
669+
(strcmp(RawImg.DeviceTargetSpec, PI_DEVICE_BINARY_TARGET_SPIRV64_GEN) == 0) ||
670+
(strcmp(RawImg.DeviceTargetSpec, PI_DEVICE_BINARY_TARGET_SPIRV64_FPGA) == 0)) {
671+
throw feature_not_supported("Recompiling AOT image is not supported",
672+
PI_INVALID_OPERATION);
673+
}
674+
}
675+
663676
Img = Imgs[ImgInd].get();
664677

665678
if (DbgProgMgr > 0) {

sycl/source/detail/program_manager/program_manager.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ class ProgramManager {
6161
static ProgramManager &getInstance();
6262
RTDeviceBinaryImage &getDeviceImage(OSModuleHandle M,
6363
const string_class &KernelName,
64-
const context &Context);
64+
const context &Context,
65+
bool FromProgramApi = false);
6566
RT::PiProgram createPIProgram(const RTDeviceBinaryImage &Img,
6667
const context &Context);
6768
/// Builds or retrieves from cache a program defining the kernel with given
@@ -76,7 +77,7 @@ class ProgramManager {
7677
/// once the function returns.
7778
RT::PiProgram getBuiltPIProgram(OSModuleHandle M, const context &Context,
7879
const string_class &KernelName,
79-
const program_impl *Prg = nullptr);
80+
const program_impl *Prg = nullptr, bool FromProgramApi = false);
8081
RT::PiKernel getOrCreateKernel(OSModuleHandle M, const context &Context,
8182
const string_class &KernelName,
8283
const program_impl *Prg);
@@ -110,7 +111,7 @@ class ProgramManager {
110111
ProgramManager &operator=(ProgramManager const &) = delete;
111112

112113
RTDeviceBinaryImage &getDeviceImage(OSModuleHandle M, KernelSetId KSId,
113-
const context &Context);
114+
const context &Context, bool FromProgramApi = false);
114115
using ProgramPtr = unique_ptr_class<remove_pointer_t<RT::PiProgram>,
115116
decltype(&::piProgramRelease)>;
116117
ProgramPtr build(ProgramPtr Program, const ContextImplPtr Context,

sycl/test/aot/spec_const_aot.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ int main(int argc, char **argv) {
3838
cl::sycl::experimental::spec_constant<int32_t, MyInt32Const> i32 =
3939
prog.set_spec_constant<MyInt32Const>(10);
4040

41-
prog.build_with_kernel_type<Kernel>();
4241

4342
std::vector<int> vec(1);
4443
{
@@ -47,7 +46,6 @@ int main(int argc, char **argv) {
4746
q.submit([&](cl::sycl::handler &cgh) {
4847
auto acc = buf.get_access<cl::sycl::access::mode::write>(cgh);
4948
cgh.single_task<Kernel>(
50-
prog.get_kernel<Kernel>(),
5149
[=]() {
5250
acc[0] = i32.get();
5351
});

sycl/test/device-code-split/Inputs/split-per-source-second-file.cpp

Lines changed: 0 additions & 21 deletions
This file was deleted.

sycl/test/device-code-split/Inputs/split-per-source.h

Lines changed: 0 additions & 7 deletions
This file was deleted.

sycl/test/device-code-split/aot-accelerator.cpp

Lines changed: 0 additions & 4 deletions
This file was deleted.

sycl/test/device-code-split/aot-cpu.cpp

Lines changed: 0 additions & 4 deletions
This file was deleted.

sycl/test/device-code-split/aot-gpu.cpp

Lines changed: 0 additions & 11 deletions
This file was deleted.

sycl/test/device-code-split/split-per-kernel.cpp

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)