From 7d5f825f32746c050d47c215f9aebc44571120ed Mon Sep 17 00:00:00 2001 From: Fabian Knorr Date: Sat, 17 Feb 2024 18:49:48 +0100 Subject: [PATCH] Add support for SimSYCL as a SYCL implementation --- CMakeLists.txt | 7 ++- ci/generate_exclude_filter.py | 2 +- ci/simsycl.filter | 15 +++++++ cmake/AdaptSimSYCL.cmake | 45 +++++++++++++++++++ cmake/AddSYCLExecutable.cmake | 4 +- tests/buffer/buffer_api_common.h | 8 ++++ tests/buffer/buffer_constructors_common.h | 9 ++++ tests/common/common.h | 6 +-- tests/common/disabled_for_test_case.h | 4 +- tests/device/device_api.cpp | 4 ++ tests/device/device_info.cpp | 6 +++ tests/event/event.cpp | 16 +++++++ tests/event/event_semantics.cpp | 4 ++ tests/handler/handler_copy_core.cpp | 15 ++++--- tests/handler/handler_copy_fp64.cpp | 6 ++- tests/invoke/execution_and_memory_models.cpp | 3 +- tests/invoke/parallel_for_simplifications.cpp | 8 ++-- tests/usm/CMakeLists.txt | 6 +++ util/sycl_exceptions.h | 9 ++++ 19 files changed, 157 insertions(+), 20 deletions(-) create mode 100644 ci/simsycl.filter create mode 100644 cmake/AdaptSimSYCL.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 17b5dcd1b..dc6bc3d5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,12 @@ cmake_minimum_required(VERSION 3.15) project(sycl_cts LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 17) +if(SYCL_IMPLEMENTATION STREQUAL SimSYCL) + set(CMAKE_CXX_STANDARD 20) +else() + set(CMAKE_CXX_STANDARD 17) +endif() + set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS ON) # Required for hex floats in C++11 mode on gcc 6+ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin") diff --git a/ci/generate_exclude_filter.py b/ci/generate_exclude_filter.py index bfd578620..42f660d54 100755 --- a/ci/generate_exclude_filter.py +++ b/ci/generate_exclude_filter.py @@ -42,7 +42,7 @@ def parse_arguments(): configuration-time test category filters for all failing targets.""") parser.add_argument('sycl_implementation', metavar="SYCL-Implementation", - choices=['DPCPP', 'AdaptiveCpp'], type=str, + choices=['DPCPP', 'AdaptiveCpp', 'SimSYCL'], type=str, help="The SYCL implementation to use") parser.add_argument('--cmake-args', type=str, help="Arguments to pass on to CMake during configuration") diff --git a/ci/simsycl.filter b/ci/simsycl.filter new file mode 100644 index 000000000..3a98602fd --- /dev/null +++ b/ci/simsycl.filter @@ -0,0 +1,15 @@ +accessor_legacy +atomic +atomic_ref_stress +exception_handling +image +image_accessor +kernel +kernel_args +kernel_bundle +math_builtin_api +multi_ptr +reduction +sampler +spec_constants +stream diff --git a/cmake/AdaptSimSYCL.cmake b/cmake/AdaptSimSYCL.cmake new file mode 100644 index 000000000..388157689 --- /dev/null +++ b/cmake/AdaptSimSYCL.cmake @@ -0,0 +1,45 @@ +add_library(SYCL::SYCL INTERFACE IMPORTED GLOBAL) +target_link_libraries(SYCL::SYCL INTERFACE SimSYCL::simsycl) +# add_sycl_executable_implementation function +# Builds a SYCL program, compiling multiple SYCL test case source files into a +# test executable, invoking a single-source/device compiler +# Parameters are: +# - NAME Name of the test executable +# - OBJECT_LIBRARY Name of the object library of all the compiled test cases +# - TESTS List of SYCL test case source files to be built into the +# test executable +function(add_sycl_executable_implementation) + cmake_parse_arguments(args "" "NAME;OBJECT_LIBRARY" "TESTS" ${ARGN}) + set(exe_name ${args_NAME}) + set(object_lib_name ${args_OBJECT_LIBRARY}) + set(test_cases_list ${args_TESTS}) + + add_library(${object_lib_name} OBJECT ${test_cases_list}) + add_executable(${exe_name} $) + + # hipSYCL needs the macro to be called on both the object library (to + # override the compiler) and the executable (to override the linker). + add_sycl_to_target(TARGET ${object_lib_name} SOURCES ${test_cases_list}) + add_sycl_to_target(TARGET ${exe_name}) + + set_target_properties(${object_lib_name} PROPERTIES + INCLUDE_DIRECTORIES $ + COMPILE_DEFINITIONS $ + COMPILE_OPTIONS $ + COMPILE_FEATURES $ + POSITION_INDEPENDENT_CODE ON) +endfunction() + +function(add_sycl_to_target) + set(options) + set(one_value_keywords TARGET) + set(multi_value_keywords SOURCES) + cmake_parse_arguments(ADD_SYCL + "${options}" + "${one_value_keywords}" + "${multi_value_keywords}" + ${ARGN} + ) + + target_link_libraries(${ADD_SYCL_TARGET} PUBLIC SimSYCL::simsycl) +endfunction() diff --git a/cmake/AddSYCLExecutable.cmake b/cmake/AddSYCLExecutable.cmake index 8cda35248..32fb962d2 100644 --- a/cmake/AddSYCLExecutable.cmake +++ b/cmake/AddSYCLExecutable.cmake @@ -1,8 +1,8 @@ -set (KNOWN_SYCL_IMPLEMENTATIONS "DPCPP;AdaptiveCpp") +set (KNOWN_SYCL_IMPLEMENTATIONS "DPCPP;AdaptiveCpp;SimSYCL") if ("${SYCL_IMPLEMENTATION}" STREQUAL "" OR NOT ${SYCL_IMPLEMENTATION} IN_LIST KNOWN_SYCL_IMPLEMENTATIONS) message(FATAL_ERROR "The SYCL CTS requires specifying a SYCL implementation with " - "-DSYCL_IMPLEMENTATION=[DPCPP;AdaptiveCpp]") + "-DSYCL_IMPLEMENTATION=[${KNOWN_SYCL_IMPLEMENTATIONS}]") endif() if(NOT TARGET OpenCL_Proxy) diff --git a/tests/buffer/buffer_api_common.h b/tests/buffer/buffer_api_common.h index 887d24d61..5722de47b 100644 --- a/tests/buffer/buffer_api_common.h +++ b/tests/buffer/buffer_api_common.h @@ -393,6 +393,7 @@ void test_buffer(util::logger& log, sycl::range& r, sycl::id& i) { allocator.deallocate(ptr, 1); } +#if !SYCL_CTS_COMPILING_WITH_SIMSYCL /* check is_sub_buffer() */ { sycl::buffer buf(r); @@ -405,6 +406,9 @@ void test_buffer(util::logger& log, sycl::range& r, sycl::id& i) { CHECK(isSubBuffer); CHECK_FALSE(isOrigSubBuffer); } +#else + FAIL_CHECK("SimSYCL does not implement sub-buffers yet"); +#endif /* check buffer properties */ { @@ -540,10 +544,14 @@ class check_buffer_api_for_type { test_buffer(log, range2d, id2d); test_buffer(log, range3d, id3d); +#if !SYCL_CTS_COMPILING_WITH_SIMSYCL /* check reinterpret() */ test_type_reinterpret(log); test_type_reinterpret(log); test_type_reinterpret(log); +#else + FAIL("SimSYCL does not implement buffer::reinterpret() yet") +#endif } public: diff --git a/tests/buffer/buffer_constructors_common.h b/tests/buffer/buffer_constructors_common.h index 9f1042d82..2b1208c20 100644 --- a/tests/buffer/buffer_constructors_common.h +++ b/tests/buffer/buffer_constructors_common.h @@ -235,6 +235,7 @@ class buffer_ctors { CHECK(check_buffer_constructor(buf_iter1, r_exp, data_verify)); } +#if !SYCL_CTS_COMPILING_WITH_SIMSYCL { INFO("Check subBuffer (buffer, id, range) constructor"); auto r_sub = r; @@ -244,6 +245,10 @@ class buffer_ctors { CHECK(buf_sub.is_sub_buffer()); CHECK(check_buffer_constructor(buf_sub, r_sub)); } +#else + FAIL_CHECK("SimSYCL does not implement sub-buffers yet"); +#endif + /* Check range constructor */ { sycl::buffer> buf(r, propList); @@ -312,6 +317,7 @@ class buffer_ctors { CHECK(check_buffer_constructor(buf_iter1, r_exp, data_verify)); } +#if !SYCL_CTS_COMPILING_WITH_SIMSYCL { INFO( "Check subBuffer (buffer, id, range) constructor with allocator " @@ -323,6 +329,9 @@ class buffer_ctors { CHECK(buf_sub.is_sub_buffer()); CHECK(check_buffer_constructor(buf_sub, r_sub)); } +#else + FAIL_CHECK("SimSYCL does not implement sub-buffers yet"); +#endif { INFO("Check (range, allocator) constructor"); diff --git a/tests/common/common.h b/tests/common/common.h index e760cb82e..3663471c5 100644 --- a/tests/common/common.h +++ b/tests/common/common.h @@ -286,7 +286,7 @@ bool check_equal_values(const T& lhs, const T& rhs) { } /** - * @brief Instantiation for vectors with the same API as for scalar values. + * @brief Instantiation for vectors with the same API as for scalar values. * Deprecated. Use \c value_operations::are_equal instead */ template @@ -416,8 +416,8 @@ namespace pixel_tag { struct upper: generic {}; }; -// AdaptiveCpp does not yet support images -#if !SYCL_CTS_COMPILING_WITH_ADAPTIVECPP +// AdaptiveCpp and SimSYCL do not yet support images +#if !SYCL_CTS_COMPILING_WITH_HIPSYCL && !SYCL_CTS_COMPILING_WITH_SIMSYCL /** * @brief Helps with retrieving the right access type for reading/writing diff --git a/tests/common/disabled_for_test_case.h b/tests/common/disabled_for_test_case.h index ca22bc5c9..5ad31732c 100644 --- a/tests/common/disabled_for_test_case.h +++ b/tests/common/disabled_for_test_case.h @@ -23,7 +23,7 @@ * currently does not compile for a given implementation, while other test cases * in the same translation unit would otherwise compile. * - * The following implementations can be specified: DPCPP, AdaptiveCpp. + * The following implementations can be specified: DPCPP, AdaptiveCpp, SimSYCL. * A disabled test case will fail automatically at runtime. * * Usage example: @@ -53,6 +53,8 @@ #define INTERNAL_CTS_SYCL_IMPL_DPCPP () #elif SYCL_CTS_COMPILING_WITH_ADAPTIVECPP #define INTERNAL_CTS_SYCL_IMPL_AdaptiveCpp () +#elif SYCL_CTS_COMPILING_WITH_SIMSYCL +#define INTERNAL_CTS_SYCL_IMPL_SimSYCL () #else #error Unknown SYCL implementation #endif diff --git a/tests/device/device_api.cpp b/tests/device/device_api.cpp index f8750e252..72af8e823 100644 --- a/tests/device/device_api.cpp +++ b/tests/device/device_api.cpp @@ -123,6 +123,7 @@ class TEST_NAME : public util::test_base { "device::has(sycl::aspect)"); } +#if !SYCL_CTS_COMPILING_WITH_SIMSYCL /** check * create_sub_devices(size_t) * member function @@ -180,6 +181,9 @@ class TEST_NAME : public util::test_base { } } } +#else + FAIL_CHECK("SimSYCL does not implement sub-devices yet"); +#endif /** check get_devices() static member function */ diff --git a/tests/device/device_info.cpp b/tests/device/device_info.cpp index 06e1a5341..60ee9f26d 100644 --- a/tests/device/device_info.cpp +++ b/tests/device/device_info.cpp @@ -232,6 +232,8 @@ TEST_CASE("device info", "[device]") { check_get_info_param(dev); check_get_info_param( dev); + +#if !SYCL_CTS_COMPILING_WITH_SIMSYCL auto SupportedProperties = dev.get_info(); if (std::find(SupportedProperties.begin(), SupportedProperties.end(), @@ -243,6 +245,10 @@ TEST_CASE("device info", "[device]") { check_get_info_param( sub_device_partition_equal[0]); } +#else + FAIL_CHECK("SimSYCL does not implement sub-devices yet"); +#endif + check_get_info_param(dev); check_get_info_param(make_device_event()); SECTION("for host_task event") { +#if SYCL_CTS_COMPILING_WITH_SIMSYCL + SKIP("SimSYCL does not implement asynchronous execution."); +#endif + resolvable_host_event rhe; auto& event = rhe.get_sycl_event(); diff --git a/tests/event/event_semantics.cpp b/tests/event/event_semantics.cpp index faf550bbe..474f68d60 100644 --- a/tests/event/event_semantics.cpp +++ b/tests/event/event_semantics.cpp @@ -43,6 +43,10 @@ TEST_CASE("event common reference semantics", "[event]") { } TEST_CASE("event common reference semantics, mutation", "[event]") { +#if SYCL_CTS_COMPILING_WITH_SIMSYCL + SKIP("SimSYCL does not implement asynchronous execution."); +#endif + resolvable_host_event dependent_event; resolvable_host_event rhe_t0{{dependent_event.get_sycl_event()}}; diff --git a/tests/handler/handler_copy_core.cpp b/tests/handler/handler_copy_core.cpp index ce65ce39c..89340e201 100644 --- a/tests/handler/handler_copy_core.cpp +++ b/tests/handler/handler_copy_core.cpp @@ -6,6 +6,7 @@ // *******************************************************************************/ +#include "../common/disabled_for_test_case.h" #include "../common/string_makers.h" #include "../common/type_coverage.h" #include "catch2/catch_test_macros.hpp" @@ -14,7 +15,10 @@ namespace handler_copy_core { using namespace handler_copy_common; -TEST_CASE("Tests the API for sycl::handler::copy", "[handler]") { +// Disabled: SimSYCL does not implement copies between accessors of different dimensionality +DISABLED_FOR_TEST_CASE(SimSYCL)( + "Tests the API for sycl::handler::copy", + "[handler]")({ auto queue = util::get_cts_object::queue(); log_helper lh; @@ -33,12 +37,13 @@ TEST_CASE("Tests the API for sycl::handler::copy", "[handler]") { test_all_variants(lh, queue); test_all_variants(lh, queue); #endif -} +}); -TEST_CASE( +// Disabled: SimSYCL does not implement copies between accessors of different dimensionality +DISABLED_FOR_TEST_CASE(SimSYCL)( "Check exception on copy(accessor, accessor) in case of invalid " "destination accessor size", - "[handler]") { + "[handler]")({ auto queue = util::get_cts_object::queue(); const auto types = @@ -72,6 +77,6 @@ TEST_CASE( for_all_combinations(types, dims, dims, src_modes, dst_modes, queue); -} +}); } // namespace handler_copy_core diff --git a/tests/handler/handler_copy_fp64.cpp b/tests/handler/handler_copy_fp64.cpp index f580234de..999984ac5 100644 --- a/tests/handler/handler_copy_fp64.cpp +++ b/tests/handler/handler_copy_fp64.cpp @@ -7,13 +7,15 @@ *******************************************************************************/ #include "handler_copy_common.h" +#include "../common/disabled_for_test_case.h" #include "catch2/catch_test_macros.hpp" namespace handler_copy_fp64 { using namespace handler_copy_common; -TEST_CASE("Tests the API for sycl::handler::copy for double", "[handler]") { +// Disabled: SimSYCL does not implement copies between accessors of different dimensionality +DISABLED_FOR_TEST_CASE(SimSYCL)("Tests the API for sycl::handler::copy for double", "[handler]")({ auto queue = util::get_cts_object::queue(); if (!queue.get_device().has(sycl::aspect::fp64)) { WARN( @@ -25,6 +27,6 @@ TEST_CASE("Tests the API for sycl::handler::copy for double", "[handler]") { log_helper lh; test_all_variants(lh, queue); test_all_variants(lh, queue); -} +}); } // namespace handler_copy_fp64 diff --git a/tests/invoke/execution_and_memory_models.cpp b/tests/invoke/execution_and_memory_models.cpp index 3f1fb2cd1..81cacd37e 100644 --- a/tests/invoke/execution_and_memory_models.cpp +++ b/tests/invoke/execution_and_memory_models.cpp @@ -150,7 +150,8 @@ TEST_CASE( } } -DISABLED_FOR_TEST_CASE(AdaptiveCpp) +// Disabled: SimSYCL does not implement sub-buffers yet +DISABLED_FOR_TEST_CASE(AdaptiveCpp, SimSYCL) ("Requirements on overlapping sub-buffers", "[invoke]")({ auto device = sycl_cts::util::get_cts_object::device(); auto queue = sycl_cts::util::get_cts_object::queue(); diff --git a/tests/invoke/parallel_for_simplifications.cpp b/tests/invoke/parallel_for_simplifications.cpp index 4c35bb644..2b647952d 100644 --- a/tests/invoke/parallel_for_simplifications.cpp +++ b/tests/invoke/parallel_for_simplifications.cpp @@ -82,8 +82,8 @@ DISABLED_FOR_TEST_CASE(AdaptiveCpp) check(action); }); -// FIXME: re-enable when parallel_for simplifications implemented in AdaptiveCpp -DISABLED_FOR_TEST_CASE(AdaptiveCpp) +// FIXME: re-enable when parallel_for simplifications implemented in AdaptiveCpp / SimSYCL +DISABLED_FOR_TEST_CASE(AdaptiveCpp, SimSYCL) ("Check parallel_for({N1, N2}, some_kernel)", "[parallel_for_simplifications]")({ constexpr int N1 = 2; @@ -95,8 +95,8 @@ DISABLED_FOR_TEST_CASE(AdaptiveCpp) check(action); }); -// FIXME: re-enable when parallel_for simplifications implemented in AdaptiveCpp -DISABLED_FOR_TEST_CASE(AdaptiveCpp) +// FIXME: re-enable when parallel_for simplifications implemented in AdaptiveCpp / SimSYCL +DISABLED_FOR_TEST_CASE(AdaptiveCpp, SimSYCL) ("Check parallel_for({N1, N2, N3}, some_kernel)", "[parallel_for_simplifications]")({ constexpr int N1 = 2; diff --git a/tests/usm/CMakeLists.txt b/tests/usm/CMakeLists.txt index 82f462065..2ca732b56 100644 --- a/tests/usm/CMakeLists.txt +++ b/tests/usm/CMakeLists.txt @@ -1,3 +1,9 @@ file(GLOB test_cases_list *.cpp) +if(SYCL_IMPLEMENTATION STREQUAL SimSYCL) + message(WARNING "SimSYCL does not provide true concurrency between host and device, disabling USM atomic tests") + list(FILTER test_cases_list EXCLUDE REGEX usm_atomic_access_.*\\.cpp$) +endif() + + add_cts_test(${test_cases_list}) diff --git a/util/sycl_exceptions.h b/util/sycl_exceptions.h index c06a7050e..deaa69624 100644 --- a/util/sycl_exceptions.h +++ b/util/sycl_exceptions.h @@ -38,6 +38,15 @@ #define SYCL_CTS_SUPPORT_HAS_EXCEPTION_CATEGORY 1 #define SYCL_CTS_SUPPORT_HAS_MAKE_ERROR_CODE 0 +#elif SYCL_CTS_COMPILING_WITH_SIMSYCL +// Feature flags for SimSYCL + +#define SYCL_CTS_SUPPORT_HAS_EXCEPTION_CODE 1 +#define SYCL_CTS_SUPPORT_HAS_EXCEPTION_CATEGORY 1 +#define SYCL_CTS_SUPPORT_HAS_ERRC_FOR 0 +#define SYCL_CTS_SUPPORT_HAS_ERROR_CATEGORY_FOR 0 +#define SYCL_CTS_SUPPORT_HAS_MAKE_ERROR_CODE 1 + #else #define SYCL_CTS_SUPPORT_HAS_EXCEPTION_CODE 1