From 4c534a7b46a766539a9b2793f95a69d527bb41f2 Mon Sep 17 00:00:00 2001 From: KornevNikita Date: Thu, 9 Mar 2023 07:22:32 -0800 Subject: [PATCH 1/2] [SYCL] Implement native_specialization_constant() native_specialization_constant() returns true only in JIT mode on opencl & level-zero backends (because only SPIR-V supports them) --- sycl/source/detail/device_image_impl.hpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/sycl/source/detail/device_image_impl.hpp b/sycl/source/detail/device_image_impl.hpp index f04fea1b8c774..b67a2b63137f1 100644 --- a/sycl/source/detail/device_image_impl.hpp +++ b/sycl/source/detail/device_image_impl.hpp @@ -110,8 +110,19 @@ class device_image_impl { } bool all_specialization_constant_native() const noexcept { - assert(false && "Not implemented"); - return false; + // Specialization constants are natively supported in JIT mode on backends, + // that are using SPIR-V as IR + auto IsAOTBinary = [](const char *Format) { + return ( + (strcmp(Format, __SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64_X86_64) == + 0) || + (strcmp(Format, __SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64_GEN) == 0) || + (strcmp(Format, __SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64_FPGA) == 0)); + }; + + return !IsAOTBinary(MBinImage->getRawData().DeviceTargetSpec) && + (MContext.get_backend() == backend::opencl || + MContext.get_backend() == backend::ext_oneapi_level_zero); } bool has_specialization_constant(const char *SpecName) const noexcept { From 44d85885ac92dacd39193277f170e6bddd5b4509 Mon Sep 17 00:00:00 2001 From: KornevNikita Date: Mon, 13 Mar 2023 05:01:31 -0700 Subject: [PATCH 2/2] [SYCL] Improve all_specialization_constant_native() --- sycl/source/detail/device_image_impl.hpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/sycl/source/detail/device_image_impl.hpp b/sycl/source/detail/device_image_impl.hpp index b67a2b63137f1..ea23b6828986c 100644 --- a/sycl/source/detail/device_image_impl.hpp +++ b/sycl/source/detail/device_image_impl.hpp @@ -112,17 +112,13 @@ class device_image_impl { bool all_specialization_constant_native() const noexcept { // Specialization constants are natively supported in JIT mode on backends, // that are using SPIR-V as IR - auto IsAOTBinary = [](const char *Format) { - return ( - (strcmp(Format, __SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64_X86_64) == - 0) || - (strcmp(Format, __SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64_GEN) == 0) || - (strcmp(Format, __SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64_FPGA) == 0)); + auto IsJITSPIRVTarget = [](const char *Target) { + return (strcmp(Target, __SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64) == 0 || + strcmp(Target, __SYCL_PI_DEVICE_BINARY_TARGET_SPIRV32) == 0); }; - - return !IsAOTBinary(MBinImage->getRawData().DeviceTargetSpec) && - (MContext.get_backend() == backend::opencl || - MContext.get_backend() == backend::ext_oneapi_level_zero); + return (MContext.get_backend() == backend::opencl || + MContext.get_backend() == backend::ext_oneapi_level_zero) && + IsJITSPIRVTarget(MBinImage->getRawData().DeviceTargetSpec); } bool has_specialization_constant(const char *SpecName) const noexcept {