From f8e0f106039026f513ed4b900136e4ef781427d1 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Fri, 27 Jan 2023 15:58:46 +0000 Subject: [PATCH 1/6] Add MDSPAN_ENABLE_SYCL option and set corresponding flags --- CMakeLists.txt | 6 ++++++ include/experimental/__p0009_bits/config.hpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 69abff9f..5b2d963f 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_OPENMP "Enable OpenMP benchmarks if benchmarks are enabled." On) option(MDSPAN_USE_SYSTEM_GTEST "Use system-installed GoogleTest library for tests." Off) @@ -120,6 +121,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 727a565d..f373329c 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 From 03b0c85a1a9f06cd7c62fe9e5ad2df5715d0c68b Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Fri, 27 Jan 2023 16:00:18 +0000 Subject: [PATCH 2/6] Run tests with SYCL --- tests/offload_utils.hpp | 66 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/offload_utils.hpp b/tests/offload_utils.hpp index 18f5b52a..5526c166 100644 --- a/tests/offload_utils.hpp +++ b/tests/offload_utils.hpp @@ -14,14 +14,26 @@ // //@HEADER +#ifdef _MDSPAN_HAS_SYCL +#include +#endif + 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 #ifdef _MDSPAN_HAS_CUDA @@ -67,6 +79,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) { From 0a26397924952f06e6597fa29d70b78c0bc7c35b Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Fri, 27 Jan 2023 16:00:49 +0000 Subject: [PATCH 3/6] Disable TestMdarrayCtorDataCArray::test_mdarray_ctor_data_carray test for SYCL --- tests/test_mdarray_ctors.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_mdarray_ctors.cpp b/tests/test_mdarray_ctors.cpp index 669baf58..fe2155a4 100644 --- a/tests/test_mdarray_ctors.cpp +++ b/tests/test_mdarray_ctors.cpp @@ -181,9 +181,12 @@ void test_mdarray_ctor_data_carray() { free_array(errors); } +// host data can't be used in device code +#if !defined(_MDSPAN_HAS_SYCL) TEST(TestMdarrayCtorDataCArray, test_mdarray_ctor_data_carray) { __MDSPAN_TESTS_RUN_TEST(test_mdarray_ctor_data_carray()) } +#endif // Construct from extents only TEST(TestMdarrayCtorFromExtents, 0d_static) { From 694191694765f2250b4f1888973b6c1bf0b7893f Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Fri, 27 Jan 2023 16:50:56 +0000 Subject: [PATCH 4/6] Use std::array instead --- tests/test_mdarray_ctors.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/test_mdarray_ctors.cpp b/tests/test_mdarray_ctors.cpp index fe2155a4..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); @@ -181,12 +181,9 @@ void test_mdarray_ctor_data_carray() { free_array(errors); } -// host data can't be used in device code -#if !defined(_MDSPAN_HAS_SYCL) TEST(TestMdarrayCtorDataCArray, test_mdarray_ctor_data_carray) { __MDSPAN_TESTS_RUN_TEST(test_mdarray_ctor_data_carray()) } -#endif // Construct from extents only TEST(TestMdarrayCtorFromExtents, 0d_static) { From 3c4de9b1a8949cc2fb6d025fff550aafa52cf7b5 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Fri, 27 Jan 2023 17:05:07 +0000 Subject: [PATCH 5/6] Try enabling SYCL in the CI --- .github/workflows/cmake.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 8fffb951..afb2ba4b 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -23,6 +23,7 @@ jobs: # To get new URL, look here: # https://www.intel.com/content/www/us/en/developer/articles/tool/oneapi-standalone-components.html#inpage-nav-6-undefined compiler_url: https://registrationcenter-download.intel.com/akdlm/irc_nas/18849/l_dpcpp-cpp-compiler_p_2022.2.0.8772_offline.sh + enable_backend: "-DMDSPAN_ENABLE_SYCL=ON" name: ${{ matrix.compiler_driver }} steps: @@ -52,7 +53,7 @@ jobs: - name: Configure CMake shell: bash working-directory: ${{github.workspace}}/mdspan-build - run: CXX=${{ matrix.compiler_prefix}}/${{ matrix.compiler_driver }} cmake $GITHUB_WORKSPACE/mdspan-src -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/mdspan-install -DMDSPAN_ENABLE_TESTS=ON -DMDSPAN_ENABLE_EXAMPLES=ON + run: CXX=${{ matrix.compiler_prefix}}/${{ matrix.compiler_driver }} cmake $GITHUB_WORKSPACE/mdspan-src -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/mdspan-install -DMDSPAN_ENABLE_TESTS=ON -DMDSPAN_ENABLE_EXAMPLES=ON ${{ matrix.enable_backend }} - name: Build shell: bash From 9c3dbf64cec7c2649c566b8bc6df13fe79e70f39 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Mon, 30 Jan 2023 13:13:37 -0500 Subject: [PATCH 6/6] Revert changes to .github/workflows/cmake.yml --- .github/workflows/cmake.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index afb2ba4b..8fffb951 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -23,7 +23,6 @@ jobs: # To get new URL, look here: # https://www.intel.com/content/www/us/en/developer/articles/tool/oneapi-standalone-components.html#inpage-nav-6-undefined compiler_url: https://registrationcenter-download.intel.com/akdlm/irc_nas/18849/l_dpcpp-cpp-compiler_p_2022.2.0.8772_offline.sh - enable_backend: "-DMDSPAN_ENABLE_SYCL=ON" name: ${{ matrix.compiler_driver }} steps: @@ -53,7 +52,7 @@ jobs: - name: Configure CMake shell: bash working-directory: ${{github.workspace}}/mdspan-build - run: CXX=${{ matrix.compiler_prefix}}/${{ matrix.compiler_driver }} cmake $GITHUB_WORKSPACE/mdspan-src -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/mdspan-install -DMDSPAN_ENABLE_TESTS=ON -DMDSPAN_ENABLE_EXAMPLES=ON ${{ matrix.enable_backend }} + run: CXX=${{ matrix.compiler_prefix}}/${{ matrix.compiler_driver }} cmake $GITHUB_WORKSPACE/mdspan-src -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/mdspan-install -DMDSPAN_ENABLE_TESTS=ON -DMDSPAN_ENABLE_EXAMPLES=ON - name: Build shell: bash