diff --git a/CMakeLists.txt b/CMakeLists.txt index 6086cd04..e75f3c7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ option(MDSPAN_ENABLE_EXAMPLES "Build examples." Off) option(MDSPAN_ENABLE_BENCHMARKS "Enable benchmarks." Off) option(MDSPAN_ENABLE_COMP_BENCH "Enable compilation benchmarks." Off) option(MDSPAN_ENABLE_CUDA "Enable Cuda tests/benchmarks/examples if tests/benchmarks/examples are enabled." Off) +option(MDSPAN_ENABLE_SYCL "Enable SYCL tests/benchmarks/examples if tests/benchmarks/examples are enabled." Off) option(MDSPAN_ENABLE_HIP "Enable HIP tests/benchmarks/examples if tests/benchmarks/examples are enabled." Off) option(MDSPAN_ENABLE_OPENMP "Enable OpenMP benchmarks if benchmarks are enabled." On) option(MDSPAN_USE_SYSTEM_GTEST "Use system-installed GoogleTest library for tests." Off) @@ -137,6 +138,11 @@ endif() add_library(mdspan INTERFACE) add_library(std::mdspan ALIAS mdspan) +if(MDSPAN_ENABLE_SYCL) + target_compile_options(mdspan INTERFACE "-fsycl") + target_link_options(mdspan INTERFACE "-fsycl") +endif() + target_include_directories(mdspan INTERFACE $ $ diff --git a/include/experimental/__p0009_bits/config.hpp b/include/experimental/__p0009_bits/config.hpp index 8a47b3c2..1b17a72a 100644 --- a/include/experimental/__p0009_bits/config.hpp +++ b/include/experimental/__p0009_bits/config.hpp @@ -82,6 +82,12 @@ static_assert(_MDSPAN_CPLUSPLUS >= MDSPAN_CXX_STD_14, "mdspan requires C++14 or # endif #endif +#ifndef _MDSPAN_HAS_SYCL +# if defined(SYCL_LANGUAGE_VERSION) +# define _MDSPAN_HAS_SYCL SYCL_LANGUAGE_VERSION +# endif +#endif + #ifndef __has_cpp_attribute # define __has_cpp_attribute(x) 0 #endif diff --git a/tests/offload_utils.hpp b/tests/offload_utils.hpp index 971c0039..a71ae060 100644 --- a/tests/offload_utils.hpp +++ b/tests/offload_utils.hpp @@ -14,6 +14,10 @@ // //@HEADER +#ifdef _MDSPAN_HAS_SYCL +#include +#endif + #ifdef _MDSPAN_HAS_HIP #include #include @@ -24,11 +28,19 @@ namespace { bool dispatch_host = true; +#ifdef _MDSPAN_HAS_SYCL #define __MDSPAN_DEVICE_ASSERT_EQ(LHS, RHS) \ if (!(LHS == RHS)) { \ + sycl::ext::oneapi::experimental::printf("expected equality of %s and %s\n", #LHS, #RHS); \ + errors[0]++; \ +} +#else + #define __MDSPAN_DEVICE_ASSERT_EQ(LHS, RHS) \ + if (!(LHS == RHS)) { \ printf("expected equality of %s and %s\n", #LHS, #RHS); \ errors[0]++; \ } +#endif #if defined(_MDSPAN_HAS_CUDA) || defined(_MDSPAN_HAS_HIP) @@ -90,6 +102,60 @@ void free_array(T* ptr) { #define __MDSPAN_TESTS_DISPATCH_DEFINED #endif // _MDSPAN_HAS_CUDA +#ifdef _MDSPAN_HAS_SYCL + +sycl::queue get_test_queue() +{ + static sycl::queue q; + return q; +} + +template +void dispatch(LAMBDA&& f) { + if(dispatch_host) { + static_cast(f)(); + } else { + sycl::queue q = get_test_queue(); + q.submit([&](sycl::handler &cgh) { + cgh.single_task([=]() { + f(); + }); + }); + q.wait_and_throw(); + } +} + +template +T* allocate_array(size_t size) { + if(dispatch_host == true) + return new T[size]; + else + { + sycl::queue q = get_test_queue(); + return sycl::malloc_shared(size, q); + } +} + +template +void free_array(T* ptr) { + if(dispatch_host == true) + delete [] ptr; + else + { + sycl::queue q = get_test_queue(); + sycl::free(ptr, q); + } +} + +#define __MDSPAN_TESTS_RUN_TEST(A) \ + dispatch_host = true; \ + A; \ + dispatch_host = false; \ + A; + +#define __MDSPAN_TESTS_DISPATCH_DEFINED +#endif // _MDSPAN_HAS_SYCL + #ifndef __MDSPAN_TESTS_DISPATCH_DEFINED template void dispatch(LAMBDA&& f) { diff --git a/tests/test_mdarray_ctors.cpp b/tests/test_mdarray_ctors.cpp index 669baf58..94245c24 100644 --- a/tests/test_mdarray_ctors.cpp +++ b/tests/test_mdarray_ctors.cpp @@ -166,7 +166,7 @@ void test_mdarray_ctor_data_carray() { errors[0] = 0; dispatch([=] _MDSPAN_HOST_DEVICE () { - stdex::mdarray> m(stdex::extents{}); + stdex::mdarray, stdex::layout_right, std::array> m(stdex::extents{}); __MDSPAN_DEVICE_ASSERT_EQ(m.rank(), 1); __MDSPAN_DEVICE_ASSERT_EQ(m.rank_dynamic(), 0); __MDSPAN_DEVICE_ASSERT_EQ(m.extent(0), 1);