diff --git a/sycl/cmake/modules/AddSYCLUnitTest.cmake b/sycl/cmake/modules/AddSYCLUnitTest.cmake index e3abede83bb41..a93896ecce354 100644 --- a/sycl/cmake/modules/AddSYCLUnitTest.cmake +++ b/sycl/cmake/modules/AddSYCLUnitTest.cmake @@ -1,8 +1,6 @@ -# add_sycl_unittest(test_dirname SHARED|OBJECT file1.cpp, file2.cpp ...) -# -# Will compile the list of files together and link against SYCL. -# Produces a binary names `basename(test_dirname)`. -macro(add_sycl_unittest test_dirname link_variant) +# Internal function to create SYCL unit tests with code reuse +# add_sycl_unittest_internal(test_dirname SHARED|OBJECT is_preview file1.cpp, file2.cpp ...) +function(add_sycl_unittest_internal test_dirname link_variant is_preview) # Enable exception handling for these unit tests set(LLVM_REQUIRES_EH ON) set(LLVM_REQUIRES_RTTI ON) @@ -10,12 +8,33 @@ macro(add_sycl_unittest test_dirname link_variant) get_target_property(SYCL_BINARY_DIR sycl-toolchain BINARY_DIR) string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type_lower) + + # Select which sycl libraries and object to link based + # on whether this is a preview build. if (MSVC AND build_type_lower MATCHES "debug") - set(sycl_obj_target "sycld_object") - set(sycl_so_target "sycld") + if (${is_preview}) + set(sycl_obj_target "sycl-previewd_object") + set(sycl_so_target "sycl-previewd") + else() + set(sycl_obj_target "sycld_object") + set(sycl_so_target "sycld") + endif() else() - set(sycl_obj_target "sycl_object") - set(sycl_so_target "sycl") + if (${is_preview}) + set(sycl_obj_target "sycl-preview_object") + set(sycl_so_target "sycl-preview") + else() + set(sycl_obj_target "sycl_object") + set(sycl_so_target "sycl") + endif() + endif() + + # This is done to ensure that preview tests are kept in a separate + # directory, so that they do not interfere with the non-preview tests. + # Chaning CMAKE_CURRENT_BINARY_DIR should not affect this variable in its + # parent scope. + if (${is_preview}) + set(CMAKE_CURRENT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/Preview") endif() if ("${link_variant}" MATCHES "SHARED") @@ -39,6 +58,13 @@ macro(add_sycl_unittest test_dirname link_variant) ) endif() + # Add preview-specific compile definition + if (${is_preview}) + target_compile_definitions(${test_dirname} + PRIVATE __INTEL_PREVIEW_BREAKING_CHANGES) + set(sycl_cache_suffix "_preview") + endif() + if (SYCL_ENABLE_XPTI_TRACING) target_compile_definitions(${test_dirname} PRIVATE XPTI_ENABLE_INSTRUMENTATION XPTI_STATIC_LIBRARY) @@ -53,9 +79,10 @@ macro(add_sycl_unittest test_dirname link_variant) LLVM_PROFILE_FILE="${SYCL_COVERAGE_PATH}/${test_dirname}.profraw" SYCL_CONFIG_FILE_NAME=null.cfg SYCL_DEVICELIB_NO_FALLBACK=1 - SYCL_CACHE_DIR="${CMAKE_BINARY_DIR}/sycl_cache" + SYCL_CACHE_DIR="${CMAKE_BINARY_DIR}/sycl_cache${sycl_cache_suffix}" "PATH=${CMAKE_BINARY_DIR}/bin;$ENV{PATH}" ${CMAKE_CURRENT_BINARY_DIR}/${test_dirname} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} DEPENDS ${test_dirname} ) @@ -65,9 +92,10 @@ macro(add_sycl_unittest test_dirname link_variant) LLVM_PROFILE_FILE="${SYCL_COVERAGE_PATH}/${test_dirname}.profraw" SYCL_CONFIG_FILE_NAME=null.cfg SYCL_DEVICELIB_NO_FALLBACK=1 - SYCL_CACHE_DIR="${CMAKE_BINARY_DIR}/sycl_cache" + SYCL_CACHE_DIR="${CMAKE_BINARY_DIR}/sycl_cache${sycl_cache_suffix}" "LD_LIBRARY_PATH=${SYCL_BINARY_DIR}/unittests/lib:${CMAKE_BINARY_DIR}/lib:$ENV{LD_LIBRARY_PATH}" ${CMAKE_CURRENT_BINARY_DIR}/${test_dirname} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} DEPENDS ${test_dirname} ) @@ -79,6 +107,7 @@ macro(add_sycl_unittest test_dirname link_variant) # Windows doesn't support LD_LIBRARY_PATH, so instead we copy the mock OpenCL binary next to the test and ensure # that the test itself links to OpenCL (rather than through ur_adapter_opencl.dll) set(mock_ocl ${CMAKE_CURRENT_BINARY_DIR}/OpenCL.dll) + add_custom_command(TARGET ${test_dirname} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ ${mock_ocl} DEPENDS mockOpenCL @@ -122,4 +151,14 @@ macro(add_sycl_unittest test_dirname link_variant) endif() target_compile_definitions(${test_dirname} PRIVATE SYCL_DISABLE_FSYCL_SYCLHPP_WARNING) +endfunction() + +# add_sycl_unittest(test_name_prefix SHARED|OBJECT file1.cpp, file2.cpp ...) +# +# Will compile the list of files together to create two builds, with and without +# the SYCL preview features enabled. +# Produces two binaries, named `basename(test_name_prefix_non_preview)` and `basename(test_name_prefix_preview)` +macro(add_sycl_unittest test_name_prefix link_variant) + add_sycl_unittest_internal(${test_name_prefix}_non_preview ${link_variant} FALSE ${ARGN}) + add_sycl_unittest_internal(${test_name_prefix}_preview ${link_variant} TRUE ${ARGN}) endmacro() diff --git a/sycl/unittests/Extensions/LaunchQueries.cpp b/sycl/unittests/Extensions/LaunchQueries.cpp index de2f4c7535fea..09f935e96cede 100644 --- a/sycl/unittests/Extensions/LaunchQueries.cpp +++ b/sycl/unittests/Extensions/LaunchQueries.cpp @@ -61,6 +61,9 @@ auto getKernel(const sycl::queue &Q) { return KernelBundle.get_kernel(KernelID); } +// These tests fail in preview breaking mode. +// Failure Tracker: https://github.com/intel/llvm/issues/18910 +#ifndef __INTEL_PREVIEW_BREAKING_CHANGES TEST(LaunchQueries, GetWorkGroupSizeSuccess) { sycl::unittest::UrMock<> Mock; mock::getCallbacks().set_replace_callback( @@ -146,6 +149,7 @@ TEST(LaunchQueries, GetMaxWorkGroupItemSizesExceptionCode) { syclex::info::kernel_queue_specific::max_work_item_sizes<3>>(Queue), sycl::exception); } +#endif // __INTEL_PREVIEW_BREAKING_CHANGES TEST(LaunchQueries, GetMaxSubGroupSize3DSuccess) { sycl::unittest::UrMock<> Mock; diff --git a/sycl/unittests/compression/CMakeLists.txt b/sycl/unittests/compression/CMakeLists.txt index 4c27c6cf56823..065b29d249632 100644 --- a/sycl/unittests/compression/CMakeLists.txt +++ b/sycl/unittests/compression/CMakeLists.txt @@ -1,4 +1,5 @@ add_sycl_unittest(CompressionTests OBJECT CompressionTests.cpp ) -target_compile_definitions(CompressionTests PRIVATE SYCL_RT_ZSTD_AVAILABLE) +target_compile_definitions(CompressionTests_non_preview PRIVATE SYCL_RT_ZSTD_AVAILABLE) +target_compile_definitions(CompressionTests_preview PRIVATE SYCL_RT_ZSTD_AVAILABLE) diff --git a/sycl/unittests/event/CMakeLists.txt b/sycl/unittests/event/CMakeLists.txt index aac9c68eb4e51..e1cd740350853 100644 --- a/sycl/unittests/event/CMakeLists.txt +++ b/sycl/unittests/event/CMakeLists.txt @@ -1,3 +1,3 @@ add_sycl_unittest(EventTests OBJECT EventDestruction.cpp -) \ No newline at end of file +) diff --git a/sycl/unittests/kernel-and-program/CMakeLists.txt b/sycl/unittests/kernel-and-program/CMakeLists.txt index 0d06d2fc29aa0..d912cfbaa9d09 100644 --- a/sycl/unittests/kernel-and-program/CMakeLists.txt +++ b/sycl/unittests/kernel-and-program/CMakeLists.txt @@ -9,4 +9,5 @@ add_sycl_unittest(KernelAndProgramTests OBJECT OutOfResources.cpp InMemCacheEviction.cpp ) -target_compile_definitions(KernelAndProgramTests PRIVATE -D__SYCL_INTERNAL_API) +target_compile_definitions(KernelAndProgramTests_non_preview PRIVATE -D__SYCL_INTERNAL_API) +target_compile_definitions(KernelAndProgramTests_preview PRIVATE -D__SYCL_INTERNAL_API) diff --git a/sycl/unittests/misc/OsUtils.cpp b/sycl/unittests/misc/OsUtils.cpp index 3dee379fd5151..3eef558e0963a 100644 --- a/sycl/unittests/misc/OsUtils.cpp +++ b/sycl/unittests/misc/OsUtils.cpp @@ -54,8 +54,12 @@ bool isSameDir(const char* LHS, const char* RHS) { class OsUtilsTest : public ::testing::Test { }; +// This test fails with preview breaking changes enabled. +// Failure tracker: https://github.com/intel/llvm/issues/19626 +#ifndef __INTEL_PREVIEW_BREAKING_CHANGES TEST_F(OsUtilsTest, getCurrentDSODir) { std::string DSODir = sycl::detail::OSUtil::getCurrentDSODir(); ASSERT_TRUE(isSameDir(DSODir.c_str(), SYCL_LIB_DIR)) << "expected: " << SYCL_LIB_DIR << ", got: " << DSODir; } +#endif diff --git a/sycl/unittests/pipes/CMakeLists.txt b/sycl/unittests/pipes/CMakeLists.txt index 58069920f5cb4..023d5bf0e79fa 100644 --- a/sycl/unittests/pipes/CMakeLists.txt +++ b/sycl/unittests/pipes/CMakeLists.txt @@ -4,5 +4,7 @@ add_sycl_unittest(PipeTests OBJECT host_pipe_registration.cpp ) -add_dependencies(PipeTests sycl) -target_include_directories(PipeTests PRIVATE SYSTEM ${sycl_inc_dir}) +add_dependencies(PipeTests_non_preview sycl) +target_include_directories(PipeTests_non_preview PRIVATE SYSTEM ${sycl_inc_dir}) +add_dependencies(PipeTests_preview sycl) +target_include_directories(PipeTests_preview PRIVATE SYSTEM ${sycl_inc_dir}) diff --git a/sycl/unittests/program_manager/arg_mask/EliminatedArgMask.cpp b/sycl/unittests/program_manager/arg_mask/EliminatedArgMask.cpp index ab322bce9022b..5f3dc3be84517 100644 --- a/sycl/unittests/program_manager/arg_mask/EliminatedArgMask.cpp +++ b/sycl/unittests/program_manager/arg_mask/EliminatedArgMask.cpp @@ -136,7 +136,8 @@ class MockHandler : public sycl::handler { using sycl::handler::impl; MockHandler(sycl::detail::queue_impl &Queue) - : sycl::handler(Queue.shared_from_this(), /*CallerNeedsEvent*/ true) {} + : sycl::handler(std::make_unique( + Queue, nullptr, /*CallerNeedsEvent*/ true)) {} std::unique_ptr finalize() { auto CGH = static_cast(this); diff --git a/sycl/unittests/scheduler/InOrderQueueSyncCheck.cpp b/sycl/unittests/scheduler/InOrderQueueSyncCheck.cpp index b6380276e5826..04d2f81281de2 100644 --- a/sycl/unittests/scheduler/InOrderQueueSyncCheck.cpp +++ b/sycl/unittests/scheduler/InOrderQueueSyncCheck.cpp @@ -44,7 +44,7 @@ class LimitedHandler { #ifdef __INTEL_PREVIEW_BREAKING_CHANGES virtual sycl::detail::EventImplPtr finalize() { - return std::make_shared(); + return detail::event_impl::create_default_event(); } #else virtual event finalize() { diff --git a/sycl/unittests/scheduler/SchedulerTestUtils.hpp b/sycl/unittests/scheduler/SchedulerTestUtils.hpp index 61ed99dd87cff..043d219386157 100644 --- a/sycl/unittests/scheduler/SchedulerTestUtils.hpp +++ b/sycl/unittests/scheduler/SchedulerTestUtils.hpp @@ -221,7 +221,8 @@ sycl::detail::Requirement getMockRequirement(const MemObjT &MemObj) { class MockHandler : public sycl::handler { public: MockHandler(sycl::detail::queue_impl &Queue, bool CallerNeedsEvent) - : sycl::handler(Queue.shared_from_this(), CallerNeedsEvent) {} + : sycl::handler(std::make_unique( + Queue, nullptr, CallerNeedsEvent)) {} // Methods using sycl::handler::addReduction; using sycl::handler::getType; diff --git a/sycl/unittests/ur/CMakeLists.txt b/sycl/unittests/ur/CMakeLists.txt index ce8e0e207c716..ec1f8c523542a 100644 --- a/sycl/unittests/ur/CMakeLists.txt +++ b/sycl/unittests/ur/CMakeLists.txt @@ -4,5 +4,7 @@ add_sycl_unittest(UrTests OBJECT UrUtility.cpp ) -add_dependencies(UrTests sycl) -target_include_directories(UrTests PRIVATE SYSTEM ${sycl_inc_dir}) +add_dependencies(UrTests_non_preview sycl) +target_include_directories(UrTests_non_preview PRIVATE SYSTEM ${sycl_inc_dir}) +add_dependencies(UrTests_preview sycl) +target_include_directories(UrTests_preview PRIVATE SYSTEM ${sycl_inc_dir}) diff --git a/sycl/unittests/xpti_trace/CMakeLists.txt b/sycl/unittests/xpti_trace/CMakeLists.txt index 195da6d566092..44574d36a9aa4 100644 --- a/sycl/unittests/xpti_trace/CMakeLists.txt +++ b/sycl/unittests/xpti_trace/CMakeLists.txt @@ -6,4 +6,5 @@ add_sycl_unittest(XptiTraceTests OBJECT NodeCreation.cpp QueueIDCheck.cpp ) -target_link_libraries(XptiTraceTests PRIVATE xpti xptitest_subscriber) +target_link_libraries(XptiTraceTests_non_preview PRIVATE xpti xptitest_subscriber) +target_link_libraries(XptiTraceTests_preview PRIVATE xpti xptitest_subscriber)