Skip to content

Commit d149ec3

Browse files
authored
[SYCL] Fix piextProgramSetSpecializationConstant usage (#6125)
This entry point is only meant to be called when native specialization constants are supported, so AOT only targets don't support it. Still implement it in the AOT only plugins to have clearer error if it's accidentally called. This is mentioned in #6093, although it doesn't touch the alignment issue.
1 parent 0fe322c commit d149ec3

File tree

4 files changed

+41
-18
lines changed

4 files changed

+41
-18
lines changed

sycl/include/CL/sycl/detail/pi.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,9 @@ __SYCL_EXPORT pi_result piProgramRelease(pi_program program);
12831283

12841284
/// Sets a specialization constant to a specific value.
12851285
///
1286+
/// Note: Only used when specialization constants are natively supported (SPIR-V
1287+
/// binaries), and not when they are emulated (AOT binaries).
1288+
///
12861289
/// \param prog the program object which will use the value
12871290
/// \param spec_id integer ID of the constant
12881291
/// \param spec_size size of the value

sycl/plugins/cuda/pi_cuda.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3436,6 +3436,15 @@ pi_result cuda_piKernelSetExecInfo(pi_kernel, pi_kernel_exec_info, size_t,
34363436
return PI_SUCCESS;
34373437
}
34383438

3439+
pi_result cuda_piextProgramSetSpecializationConstant(pi_program, pi_uint32,
3440+
size_t, const void *) {
3441+
// This entry point is only used for native specialization constants (SPIR-V),
3442+
// and the CUDA plugin is AOT only so this entry point is not supported.
3443+
cl::sycl::detail::pi::die(
3444+
"Native specialization constants are not supported");
3445+
return {};
3446+
}
3447+
34393448
pi_result cuda_piextKernelSetArgPointer(pi_kernel kernel, pi_uint32 arg_index,
34403449
size_t arg_size,
34413450
const void *arg_value) {
@@ -5066,6 +5075,8 @@ pi_result piPluginInit(pi_plugin *PluginInit) {
50665075
_PI_CL(piKernelRetain, cuda_piKernelRetain)
50675076
_PI_CL(piKernelRelease, cuda_piKernelRelease)
50685077
_PI_CL(piKernelSetExecInfo, cuda_piKernelSetExecInfo)
5078+
_PI_CL(piextProgramSetSpecializationConstant,
5079+
cuda_piextProgramSetSpecializationConstant)
50695080
_PI_CL(piextKernelSetArgPointer, cuda_piextKernelSetArgPointer)
50705081
_PI_CL(piextKernelCreateWithNativeHandle,
50715082
cuda_piextKernelCreateWithNativeHandle)

sycl/plugins/hip/pi_hip.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3375,6 +3375,15 @@ pi_result hip_piKernelSetExecInfo(pi_kernel kernel,
33753375
return PI_SUCCESS;
33763376
}
33773377

3378+
pi_result hip_piextProgramSetSpecializationConstant(pi_program, pi_uint32,
3379+
size_t, const void *) {
3380+
// This entry point is only used for native specialization constants (SPIR-V),
3381+
// and the HIP plugin is AOT only so this entry point is not supported.
3382+
cl::sycl::detail::pi::die(
3383+
"Native specialization constants are not supported");
3384+
return {};
3385+
}
3386+
33783387
pi_result hip_piextKernelSetArgPointer(pi_kernel kernel, pi_uint32 arg_index,
33793388
size_t arg_size, const void *arg_value) {
33803389
kernel->set_kernel_arg(arg_index, arg_size, arg_value);
@@ -4959,6 +4968,8 @@ pi_result piPluginInit(pi_plugin *PluginInit) {
49594968
_PI_CL(piKernelRetain, hip_piKernelRetain)
49604969
_PI_CL(piKernelRelease, hip_piKernelRelease)
49614970
_PI_CL(piKernelSetExecInfo, hip_piKernelSetExecInfo)
4971+
_PI_CL(piextProgramSetSpecializationConstant,
4972+
hip_piextProgramSetSpecializationConstant)
49624973
_PI_CL(piextKernelSetArgPointer, hip_piextKernelSetArgPointer)
49634974
// Event
49644975
_PI_CL(piEventCreate, hip_piEventCreate)

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,24 +1855,22 @@ device_image_plain ProgramManager::build(const device_image_plain &DeviceImage,
18551855
auto [NativePrg, DeviceCodeWasInCache] = getOrCreatePIProgram(
18561856
Img, Context, Devs[0], CompileOpts + LinkOpts, SpecConsts);
18571857

1858-
if (!DeviceCodeWasInCache) {
1859-
if (InputImpl->get_bin_image_ref()->supportsSpecConstants())
1860-
enableITTAnnotationsIfNeeded(NativePrg, Plugin);
1861-
1862-
{
1863-
std::lock_guard<std::mutex> Lock{InputImpl->get_spec_const_data_lock()};
1864-
const std::map<std::string,
1865-
std::vector<device_image_impl::SpecConstDescT>>
1866-
&SpecConstData = InputImpl->get_spec_const_data_ref();
1867-
1868-
for (const auto &DescPair : SpecConstData) {
1869-
for (const device_image_impl::SpecConstDescT &SpecIDDesc :
1870-
DescPair.second) {
1871-
if (SpecIDDesc.IsSet) {
1872-
Plugin.call<PiApiKind::piextProgramSetSpecializationConstant>(
1873-
NativePrg, SpecIDDesc.ID, SpecIDDesc.Size,
1874-
SpecConsts.data() + SpecIDDesc.BlobOffset);
1875-
}
1858+
if (!DeviceCodeWasInCache &&
1859+
InputImpl->get_bin_image_ref()->supportsSpecConstants()) {
1860+
enableITTAnnotationsIfNeeded(NativePrg, Plugin);
1861+
1862+
std::lock_guard<std::mutex> Lock{InputImpl->get_spec_const_data_lock()};
1863+
const std::map<std::string,
1864+
std::vector<device_image_impl::SpecConstDescT>>
1865+
&SpecConstData = InputImpl->get_spec_const_data_ref();
1866+
1867+
for (const auto &DescPair : SpecConstData) {
1868+
for (const device_image_impl::SpecConstDescT &SpecIDDesc :
1869+
DescPair.second) {
1870+
if (SpecIDDesc.IsSet) {
1871+
Plugin.call<PiApiKind::piextProgramSetSpecializationConstant>(
1872+
NativePrg, SpecIDDesc.ID, SpecIDDesc.Size,
1873+
SpecConsts.data() + SpecIDDesc.BlobOffset);
18761874
}
18771875
}
18781876
}

0 commit comments

Comments
 (0)