diff --git a/sycl/unittests/CMakeLists.txt b/sycl/unittests/CMakeLists.txt index fd8d01f3bd40e..8120f8ee44599 100644 --- a/sycl/unittests/CMakeLists.txt +++ b/sycl/unittests/CMakeLists.txt @@ -10,12 +10,11 @@ endforeach() include(AddSYCLUnitTest) add_subdirectory(allowlist) -add_subdirectory(get_native_interop) add_subdirectory(misc) add_subdirectory(pi) add_subdirectory(kernel-and-program) add_subdirectory(queue) add_subdirectory(scheduler) -add_subdirectory(spec_constants) +add_subdirectory(SYCL2020) add_subdirectory(thread_safety) add_subdirectory(program_manager) diff --git a/sycl/unittests/spec_constants/CMakeLists.txt b/sycl/unittests/SYCL2020/CMakeLists.txt similarity index 54% rename from sycl/unittests/spec_constants/CMakeLists.txt rename to sycl/unittests/SYCL2020/CMakeLists.txt index cff537cd2963a..c284fabd5f09f 100644 --- a/sycl/unittests/spec_constants/CMakeLists.txt +++ b/sycl/unittests/SYCL2020/CMakeLists.txt @@ -2,7 +2,8 @@ set(CMAKE_CXX_EXTENSIONS OFF) # Enable exception handling for these unit tests set(LLVM_REQUIRES_EH 1) -add_sycl_unittest(SpecConstantsTests OBJECT - DefaultValues.cpp +add_sycl_unittest(SYCL2020Tests OBJECT + GetNativeOpenCL.cpp + SpecConstDefaultValues.cpp ) diff --git a/sycl/unittests/get_native_interop/test_get_native.cpp b/sycl/unittests/SYCL2020/GetNativeOpenCL.cpp similarity index 69% rename from sycl/unittests/get_native_interop/test_get_native.cpp rename to sycl/unittests/SYCL2020/GetNativeOpenCL.cpp index 5945c3130a305..151c56d8e9a8a 100644 --- a/sycl/unittests/get_native_interop/test_get_native.cpp +++ b/sycl/unittests/SYCL2020/GetNativeOpenCL.cpp @@ -1,6 +1,4 @@ -//==----------- test_get_native.cpp --- get_native interop unit test only for -// opencl -//-------------==// +//==----------- GetNativeOpenCL.cpp --- interop unit test only for opencl -==// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -13,9 +11,12 @@ #include #include #include -#include + +#include #include +#include + #include #include @@ -48,27 +49,6 @@ static pi_result redefinedEventRetain(pi_event c) { return PI_SUCCESS; } -static pi_result redefinedProgramCreateWithSource(pi_context context, - pi_uint32 count, - const char **strings, - const size_t *lengths, - pi_program *ret_program) { - return PI_SUCCESS; -} - -static pi_result -redefinedProgramBuild(pi_program program, pi_uint32 num_devices, - const pi_device *device_list, const char *options, - void (*pfn_notify)(pi_program program, void *user_data), - void *user_data) { - return PI_SUCCESS; -} - -pi_result redefinedEventsWait(pi_uint32 num_events, - const pi_event *event_list) { - return PI_SUCCESS; -} - pi_result redefinedEventGetInfo(pi_event event, pi_event_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) { @@ -81,9 +61,7 @@ pi_result redefinedEventGetInfo(pi_event event, pi_event_info param_name, return PI_SUCCESS; } -pi_result redefinedEventRelease(pi_event event) { return PI_SUCCESS; } - -TEST(GetNativeTest, GetNativeHandle) { +TEST(GetNative, GetNativeHandle) { platform Plt{default_selector()}; if (Plt.get_backend() != backend::opencl) { std::cout << "Test is created for opencl only" << std::endl; @@ -97,14 +75,9 @@ TEST(GetNativeTest, GetNativeHandle) { TestCounter = 0; unittest::PiMock Mock{Plt}; - Mock.redefine( - redefinedProgramCreateWithSource); - Mock.redefine(redefinedProgramBuild); + setupDefaultMockAPIs(Mock); - Mock.redefine(redefinedEventsWait); Mock.redefine(redefinedEventGetInfo); - Mock.redefine(redefinedEventRelease); - Mock.redefine(redefinedContextRetain); Mock.redefine(redefinedQueueRetain); Mock.redefine(redefinedDeviceRetain); diff --git a/sycl/unittests/SYCL2020/SpecConstDefaultValues.cpp b/sycl/unittests/SYCL2020/SpecConstDefaultValues.cpp new file mode 100644 index 0000000000000..83c18e1ec72b1 --- /dev/null +++ b/sycl/unittests/SYCL2020/SpecConstDefaultValues.cpp @@ -0,0 +1,156 @@ +//==---- DefaultValues.cpp --- Spec constants default values unit test -----==// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#define SYCL2020_DISABLE_DEPRECATION_WARNINGS + +#include + +#include +#include +#include + +#include + +class TestKernel; +const static sycl::specialization_id SpecConst1{42}; + +__SYCL_INLINE_NAMESPACE(cl) { +namespace sycl { +namespace detail { +template <> struct KernelInfo { + static constexpr unsigned getNumParams() { return 0; } + static const kernel_param_desc_t &getParamDesc(int) { + static kernel_param_desc_t Dummy; + return Dummy; + } + static constexpr const char *getName() { return "TestKernel"; } + static constexpr bool isESIMD() { return false; } + static constexpr bool callsThisItem() { return false; } + static constexpr bool callsAnyThisFreeFunction() { return false; } +}; + +template <> const char *get_spec_constant_symbolic_ID() { + return "SC1"; +} +} // namespace detail +} // namespace sycl +} // __SYCL_INLINE_NAMESPACE(cl) + +int SpecConstVal0 = 0; +int SpecConstVal1 = 0; + +static pi_result +redefinedProgramSetSpecializationConstant(pi_program prog, pi_uint32 spec_id, + size_t spec_size, + const void *spec_value) { + if (spec_id == 0) + SpecConstVal0 = *static_cast(spec_value); + if (spec_id == 1) + SpecConstVal1 = *static_cast(spec_value); + + return PI_SUCCESS; +} + +static sycl::unittest::PiImage generateImageWithSpecConsts() { + using namespace sycl::unittest; + + std::vector SpecConstData; + PiProperty SC1 = makeSpecConstant(SpecConstData, "SC1", {0}, {0}, {42}); + PiProperty SC2 = makeSpecConstant(SpecConstData, "SC2", {1}, {0}, {8}); + + PiPropertySet PropSet; + addSpecConstants({SC1, SC2}, std::move(SpecConstData), PropSet); + + std::vector Bin{0, 1, 2, 3, 4, 5}; // Random data + + PiArray Entries = makeEmptyKernels({"TestKernel"}); + + PiImage Img{PI_DEVICE_BINARY_TYPE_SPIRV, // Format + __SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec + "", // Compile options + "", // Link options + std::move(Bin), + std::move(Entries), + std::move(PropSet)}; + + return Img; +} + +sycl::unittest::PiImage Img = generateImageWithSpecConsts(); +sycl::unittest::PiImageArray ImgArray{Img}; + +TEST(SpecConstDefaultValues, DISABLED_DefaultValuesAreSet) { + sycl::platform Plt{sycl::default_selector()}; + if (Plt.is_host()) { + std::cerr << "Test is not supported on host, skipping\n"; + return; // test is not supported on host. + } + + if (Plt.get_backend() == sycl::backend::cuda) { + std::cerr << "Test is not supported on CUDA platform, skipping\n"; + return; + } + + sycl::unittest::PiMock Mock{Plt}; + setupDefaultMockAPIs(Mock); + Mock.redefine( + redefinedProgramSetSpecializationConstant); + + const sycl::device Dev = Plt.get_devices()[0]; + + sycl::queue Queue{Dev}; + + const sycl::context Ctx = Queue.get_context(); + + sycl::kernel_bundle KernelBundle = + sycl::get_kernel_bundle(Ctx, {Dev}); + auto ExecBundle = sycl::build(KernelBundle); + Queue.submit([&](sycl::handler &CGH) { + CGH.use_kernel_bundle(ExecBundle); + CGH.single_task([] {}); // Actual kernel does not matter + }); + + EXPECT_EQ(SpecConstVal0, 42); + EXPECT_EQ(SpecConstVal1, 8); +} + +TEST(SpecConstDefaultValues, DISABLED_DefaultValuesAreOverriden) { + sycl::platform Plt{sycl::default_selector()}; + if (Plt.is_host()) { + std::cerr << "Test is not supported on host, skipping\n"; + return; // test is not supported on host. + } + + if (Plt.get_backend() == sycl::backend::cuda) { + std::cerr << "Test is not supported on CUDA platform, skipping\n"; + return; + } + + sycl::unittest::PiMock Mock{Plt}; + setupDefaultMockAPIs(Mock); + Mock.redefine( + redefinedProgramSetSpecializationConstant); + + const sycl::device Dev = Plt.get_devices()[0]; + + sycl::queue Queue{Dev}; + + const sycl::context Ctx = Queue.get_context(); + + sycl::kernel_bundle KernelBundle = + sycl::get_kernel_bundle(Ctx, {Dev}); + KernelBundle.set_specialization_constant(80); + auto ExecBundle = sycl::build(KernelBundle); + Queue.submit([&](sycl::handler &CGH) { + CGH.use_kernel_bundle(ExecBundle); + CGH.single_task([] {}); // Actual kernel does not matter + }); + + EXPECT_EQ(SpecConstVal0, 80); + EXPECT_EQ(SpecConstVal1, 8); +} diff --git a/sycl/unittests/get_native_interop/CMakeLists.txt b/sycl/unittests/get_native_interop/CMakeLists.txt deleted file mode 100644 index c2937df5d83c6..0000000000000 --- a/sycl/unittests/get_native_interop/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -add_sycl_unittest(GetNativeTests OBJECT - test_get_native.cpp -) diff --git a/sycl/unittests/helpers/CommonRedefinitions.hpp b/sycl/unittests/helpers/CommonRedefinitions.hpp new file mode 100644 index 0000000000000..d9b82a9f58425 --- /dev/null +++ b/sycl/unittests/helpers/CommonRedefinitions.hpp @@ -0,0 +1,136 @@ +//==---- CommonRedefinitions.hpp --- Header with common PI redefinitions ---==// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include +#include +#include + +inline pi_result redefinedProgramCreateCommon(pi_context, const void *, size_t, + pi_program *) { + return PI_SUCCESS; +} + +inline pi_result redefinedProgramBuildCommon( + pi_program prog, pi_uint32, const pi_device *, const char *, + void (*pfn_notify)(pi_program program, void *user_data), void *user_data) { + if (pfn_notify) { + pfn_notify(prog, user_data); + } + return PI_SUCCESS; +} + +inline pi_result redefinedProgramCompileCommon( + pi_program, pi_uint32, const pi_device *, const char *, pi_uint32, + const pi_program *, const char **, void (*)(pi_program, void *), void *) { + return PI_SUCCESS; +} + +inline pi_result redefinedProgramLinkCommon(pi_context, pi_uint32, + const pi_device *, const char *, + pi_uint32, const pi_program *, + void (*)(pi_program, void *), + void *, pi_program *) { + return PI_SUCCESS; +} + +inline pi_result redefinedProgramGetInfoCommon(pi_program program, + pi_program_info param_name, + size_t param_value_size, + void *param_value, + size_t *param_value_size_ret) { + if (param_name == PI_PROGRAM_INFO_NUM_DEVICES) { + auto value = reinterpret_cast(param_value); + *value = 1; + } + + if (param_name == PI_PROGRAM_INFO_BINARY_SIZES) { + auto value = reinterpret_cast(param_value); + value[0] = 1; + } + + if (param_name == PI_PROGRAM_INFO_BINARIES) { + auto value = reinterpret_cast(param_value); + value[0] = 1; + } + + return PI_SUCCESS; +} + +inline pi_result redefinedProgramRetainCommon(pi_program program) { + return PI_SUCCESS; +} + +inline pi_result redefinedProgramReleaseCommon(pi_program program) { + return PI_SUCCESS; +} + +inline pi_result redefinedKernelCreateCommon(pi_program program, + const char *kernel_name, + pi_kernel *ret_kernel) { + *ret_kernel = reinterpret_cast(new int[1]); + return PI_SUCCESS; +} + +inline pi_result redefinedKernelRetainCommon(pi_kernel kernel) { + return PI_SUCCESS; +} + +inline pi_result redefinedKernelReleaseCommon(pi_kernel kernel) { + delete[] reinterpret_cast(kernel); + return PI_SUCCESS; +} + +inline pi_result redefinedKernelGetInfoCommon(pi_kernel kernel, + pi_kernel_info param_name, + size_t param_value_size, + void *param_value, + size_t *param_value_size_ret) { + return PI_SUCCESS; +} + +inline pi_result redefinedKernelSetExecInfoCommon( + pi_kernel kernel, pi_kernel_exec_info value_name, size_t param_value_size, + const void *param_value) { + return PI_SUCCESS; +} + +inline pi_result redefinedEventsWaitCommon(pi_uint32 num_events, + const pi_event *event_list) { + return PI_SUCCESS; +} + +inline pi_result redefinedEventReleaseCommon(pi_event event) { + return PI_SUCCESS; +} + +inline pi_result redefinedEnqueueKernelLaunchCommon( + pi_queue, pi_kernel, pi_uint32, const size_t *, const size_t *, + const size_t *, pi_uint32, const pi_event *, pi_event *) { + return PI_SUCCESS; +} + +inline void setupDefaultMockAPIs(sycl::unittest::PiMock &Mock) { + using namespace sycl::detail; + Mock.redefine(redefinedProgramCreateCommon); + Mock.redefine(redefinedProgramCompileCommon); + Mock.redefine(redefinedProgramLinkCommon); + Mock.redefine(redefinedProgramBuildCommon); + Mock.redefine(redefinedProgramGetInfoCommon); + Mock.redefine(redefinedProgramRetainCommon); + Mock.redefine(redefinedProgramReleaseCommon); + Mock.redefine(redefinedKernelCreateCommon); + Mock.redefine(redefinedKernelRetainCommon); + Mock.redefine(redefinedKernelReleaseCommon); + Mock.redefine(redefinedKernelGetInfoCommon); + Mock.redefine( + redefinedKernelSetExecInfoCommon); + Mock.redefine(redefinedEventsWaitCommon); + Mock.redefine(redefinedEventReleaseCommon); + Mock.redefine( + redefinedEnqueueKernelLaunchCommon); +} diff --git a/sycl/unittests/helpers/PiImage.hpp b/sycl/unittests/helpers/PiImage.hpp index f55d4ccaaafe9..85c7225f6f2fb 100644 --- a/sycl/unittests/helpers/PiImage.hpp +++ b/sycl/unittests/helpers/PiImage.hpp @@ -283,7 +283,7 @@ std::enable_if_t iterate_tuple(Func &F, } template std::enable_if_t < - Idx iterate_tuple(Func &F, std::tuple &Tuple) { + Idx inline iterate_tuple(Func &F, std::tuple &Tuple) { const auto &Value = std::get(Tuple); const char *Begin = reinterpret_cast(&Value); const char *End = Begin + sizeof(Value); @@ -301,10 +301,11 @@ template /// \param Offsets is a list of offsets inside composite spec constant. /// \param DefaultValues is a tuple of default values for composite spec const. template -PiProperty makeSpecConstant(std::vector &ValData, const std::string &Name, - std::initializer_list IDs, - std::initializer_list Offsets, - std::tuple DefaultValues) { +inline PiProperty makeSpecConstant(std::vector &ValData, + const std::string &Name, + std::initializer_list IDs, + std::initializer_list Offsets, + std::tuple DefaultValues) { const size_t PropByteArraySize = sizeof...(T) * sizeof(uint32_t) * 3; std::vector DescData; DescData.resize(8 + PropByteArraySize); @@ -360,8 +361,8 @@ PiProperty makeSpecConstant(std::vector &ValData, const std::string &Name, /// Utility function to add specialization constants to property set. /// /// This function overrides the default spec constant values. -void addSpecConstants(PiArray SpecConstants, - std::vector ValData, PiPropertySet &Props) { +inline void addSpecConstants(PiArray SpecConstants, + std::vector ValData, PiPropertySet &Props) { Props.insert(__SYCL_PI_PROPERTY_SET_SPEC_CONST_MAP, std::move(SpecConstants)); PiProperty Prop{"all", std::move(ValData), PI_PROPERTY_TYPE_BYTE_ARRAY}; @@ -373,7 +374,7 @@ void addSpecConstants(PiArray SpecConstants, } /// Utility function to add ESIMD kernel flag to property set. -void addESIMDFlag(PiPropertySet &Props) { +inline void addESIMDFlag(PiPropertySet &Props) { std::vector ValData(sizeof(uint32_t)); ValData[0] = 1; PiProperty Prop{"isEsimdImage", ValData, PI_PROPERTY_TYPE_UINT32}; @@ -384,7 +385,7 @@ void addESIMDFlag(PiPropertySet &Props) { } /// Utility function to generate offload entries for kernels without arguments. -PiArray +inline PiArray makeEmptyKernels(std::initializer_list KernelNames) { PiArray Entries; diff --git a/sycl/unittests/helpers/PiMock.hpp b/sycl/unittests/helpers/PiMock.hpp index fa415a3b26f6c..9d08a01cd53d8 100644 --- a/sycl/unittests/helpers/PiMock.hpp +++ b/sycl/unittests/helpers/PiMock.hpp @@ -25,6 +25,8 @@ // //===----------------------------------------------------------------------===// +#pragma once + #include #include #include diff --git a/sycl/unittests/spec_constants/DefaultValues.cpp b/sycl/unittests/spec_constants/DefaultValues.cpp deleted file mode 100644 index a5605124a533a..0000000000000 --- a/sycl/unittests/spec_constants/DefaultValues.cpp +++ /dev/null @@ -1,273 +0,0 @@ -//==---- DefaultValues.cpp --- Spec constants default values unit test -----==// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#define SYCL2020_DISABLE_DEPRECATION_WARNINGS - -#include -#include -#include - -#include - -class TestKernel; -class TestKernel2; -const static sycl::specialization_id SpecConst1{42}; - -__SYCL_INLINE_NAMESPACE(cl) { -namespace sycl { -namespace detail { -template <> struct KernelInfo { - static constexpr unsigned getNumParams() { return 0; } - static const kernel_param_desc_t &getParamDesc(int) { - static kernel_param_desc_t Dummy; - return Dummy; - } - static constexpr const char *getName() { return "TestKernel"; } - static constexpr bool isESIMD() { return false; } - static constexpr bool callsThisItem() { return false; } - static constexpr bool callsAnyThisFreeFunction() { return false; } -}; - -template <> const char *get_spec_constant_symbolic_ID() { - return "SC1"; -} -} // namespace detail -} // namespace sycl -} // __SYCL_INLINE_NAMESPACE(cl) - -static pi_result redefinedProgramCreate(pi_context, const void *, size_t, - pi_program *) { - return PI_SUCCESS; -} - -static pi_result redefinedProgramBuild( - pi_program prog, pi_uint32, const pi_device *, const char *, - void (*pfn_notify)(pi_program program, void *user_data), void *user_data) { - if (pfn_notify) { - pfn_notify(prog, user_data); - } - return PI_SUCCESS; -} - -static pi_result redefinedProgramCompile(pi_program, pi_uint32, - const pi_device *, const char *, - pi_uint32, const pi_program *, - const char **, - void (*)(pi_program, void *), void *) { - return PI_SUCCESS; -} - -static pi_result redefinedProgramLink(pi_context, pi_uint32, const pi_device *, - const char *, pi_uint32, - const pi_program *, - void (*)(pi_program, void *), void *, - pi_program *) { - return PI_SUCCESS; -} - -static pi_result redefinedProgramGetInfo(pi_program program, - pi_program_info param_name, - size_t param_value_size, - void *param_value, - size_t *param_value_size_ret) { - if (param_name == PI_PROGRAM_INFO_NUM_DEVICES) { - auto value = reinterpret_cast(param_value); - *value = 1; - } - - if (param_name == PI_PROGRAM_INFO_BINARY_SIZES) { - auto value = reinterpret_cast(param_value); - value[0] = 1; - } - - if (param_name == PI_PROGRAM_INFO_BINARIES) { - auto value = reinterpret_cast(param_value); - value[0] = 1; - } - - return PI_SUCCESS; -} - -static pi_result redefinedProgramRetain(pi_program program) { - return PI_SUCCESS; -} - -static pi_result redefinedProgramRelease(pi_program program) { - return PI_SUCCESS; -} - -static pi_result redefinedKernelCreate(pi_program program, - const char *kernel_name, - pi_kernel *ret_kernel) { - *ret_kernel = reinterpret_cast(new int[1]); - return PI_SUCCESS; -} - -static pi_result redefinedKernelRetain(pi_kernel kernel) { return PI_SUCCESS; } - -static pi_result redefinedKernelRelease(pi_kernel kernel) { - delete[] reinterpret_cast(kernel); - return PI_SUCCESS; -} - -static pi_result redefinedKernelGetInfo(pi_kernel kernel, - pi_kernel_info param_name, - size_t param_value_size, - void *param_value, - size_t *param_value_size_ret) { - return PI_SUCCESS; -} - -static pi_result redefinedKernelSetExecInfo(pi_kernel kernel, - pi_kernel_exec_info value_name, - size_t param_value_size, - const void *param_value) { - return PI_SUCCESS; -} - -static pi_result redefinedEventsWait(pi_uint32 num_events, - const pi_event *event_list) { - return PI_SUCCESS; -} - -int SpecConstVal0 = 0; -int SpecConstVal1 = 0; - -static pi_result -redefinedProgramSetSpecializationConstant(pi_program prog, pi_uint32 spec_id, - size_t spec_size, - const void *spec_value) { - if (spec_id == 0) - SpecConstVal0 = *static_cast(spec_value); - if (spec_id == 1) - SpecConstVal1 = *static_cast(spec_value); - - return PI_SUCCESS; -} - -static pi_result redefinedEnqueueKernelLaunch(pi_queue, pi_kernel, pi_uint32, - const size_t *, const size_t *, - const size_t *, pi_uint32, - const pi_event *, pi_event *) { - return PI_SUCCESS; -} - -static void setupDefaultMockAPIs(sycl::unittest::PiMock &Mock) { - using namespace sycl::detail; - Mock.redefine(redefinedProgramCreate); - Mock.redefine(redefinedProgramCompile); - Mock.redefine(redefinedProgramLink); - Mock.redefine(redefinedProgramBuild); - Mock.redefine(redefinedProgramGetInfo); - Mock.redefine(redefinedProgramRetain); - Mock.redefine(redefinedProgramRelease); - Mock.redefine(redefinedKernelCreate); - Mock.redefine(redefinedKernelRetain); - Mock.redefine(redefinedKernelRelease); - Mock.redefine(redefinedKernelGetInfo); - Mock.redefine(redefinedKernelSetExecInfo); - Mock.redefine( - redefinedProgramSetSpecializationConstant); - Mock.redefine(redefinedEventsWait); - Mock.redefine(redefinedEnqueueKernelLaunch); -} - -static sycl::unittest::PiImage generateDefaultImage() { - using namespace sycl::unittest; - - std::vector SpecConstData; - PiProperty SC1 = makeSpecConstant(SpecConstData, "SC1", {0}, {0}, {42}); - PiProperty SC2 = makeSpecConstant(SpecConstData, "SC2", {1}, {0}, {8}); - - PiPropertySet PropSet; - addSpecConstants({SC1, SC2}, std::move(SpecConstData), PropSet); - - std::vector Bin{0, 1, 2, 3, 4, 5}; // Random data - - PiArray Entries = makeEmptyKernels({"TestKernel"}); - - PiImage Img{PI_DEVICE_BINARY_TYPE_SPIRV, // Format - __SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec - "", // Compile options - "", // Link options - std::move(Bin), - std::move(Entries), - std::move(PropSet)}; - - return Img; -} - -sycl::unittest::PiImage Img = generateDefaultImage(); -sycl::unittest::PiImageArray ImgArray{Img}; - -TEST(DefaultValues, DISABLED_DefaultValuesAreSet) { - sycl::platform Plt{sycl::default_selector()}; - if (Plt.is_host()) { - std::cerr << "Test is not supported on host, skipping\n"; - return; // test is not supported on host. - } - - if (Plt.get_backend() == sycl::backend::cuda) { - std::cerr << "Test is not supported on CUDA platform, skipping\n"; - return; - } - - sycl::unittest::PiMock Mock{Plt}; - setupDefaultMockAPIs(Mock); - - const sycl::device Dev = Plt.get_devices()[0]; - - sycl::queue Queue{Dev}; - - const sycl::context Ctx = Queue.get_context(); - - sycl::kernel_bundle KernelBundle = - sycl::get_kernel_bundle(Ctx, {Dev}); - auto ExecBundle = sycl::build(KernelBundle); - Queue.submit([&](sycl::handler &CGH) { - CGH.use_kernel_bundle(ExecBundle); - CGH.single_task([] {}); // Actual kernel does not matter - }); - - EXPECT_EQ(SpecConstVal0, 42); - EXPECT_EQ(SpecConstVal1, 8); -} - -TEST(DefaultValues, DISABLED_DefaultValuesAreOverriden) { - sycl::platform Plt{sycl::default_selector()}; - if (Plt.is_host()) { - std::cerr << "Test is not supported on host, skipping\n"; - return; // test is not supported on host. - } - - if (Plt.get_backend() == sycl::backend::cuda) { - std::cerr << "Test is not supported on CUDA platform, skipping\n"; - return; - } - - sycl::unittest::PiMock Mock{Plt}; - setupDefaultMockAPIs(Mock); - - const sycl::device Dev = Plt.get_devices()[0]; - - sycl::queue Queue{Dev}; - - const sycl::context Ctx = Queue.get_context(); - - sycl::kernel_bundle KernelBundle = - sycl::get_kernel_bundle(Ctx, {Dev}); - KernelBundle.set_specialization_constant(80); - auto ExecBundle = sycl::build(KernelBundle); - Queue.submit([&](sycl::handler &CGH) { - CGH.use_kernel_bundle(ExecBundle); - CGH.single_task([] {}); // Actual kernel does not matter - }); - - EXPECT_EQ(SpecConstVal0, 80); - EXPECT_EQ(SpecConstVal1, 8); -}