From 3cf81d46d0f1919bce0ab1235ebf24d2bde550f7 Mon Sep 17 00:00:00 2001 From: Peter Thoman Date: Mon, 11 Dec 2023 16:25:49 +0100 Subject: [PATCH] Add github CI workflow and multi-platform/config CMake --- .github/workflows/simsycl_ci.yml | 79 +++++++++++++++++++ .gitignore | 2 +- CMakeLists.txt | 29 ++++--- README.md | 14 ++++ .../simsycl/detail/group_operation_impl.hh | 6 +- include/simsycl/sycl/accessor.hh | 6 -- include/simsycl/sycl/group_algorithms.hh | 6 +- test/CMakeLists.txt | 13 ++- 8 files changed, 123 insertions(+), 32 deletions(-) create mode 100644 .github/workflows/simsycl_ci.yml diff --git a/.github/workflows/simsycl_ci.yml b/.github/workflows/simsycl_ci.yml new file mode 100644 index 0000000..dcea68a --- /dev/null +++ b/.github/workflows/simsycl_ci.yml @@ -0,0 +1,79 @@ +name: SimSYCL CI + +on: + push: + pull_request: + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. + fail-fast: false + + matrix: + os: [ubuntu-latest, windows-latest] + build_type: [Release, Debug] + c_compiler: [gcc, clang, cl] + include: + - os: windows-latest + c_compiler: cl + cpp_compiler: cl + - os: ubuntu-latest + c_compiler: gcc + cpp_compiler: g++ + - os: ubuntu-latest + c_compiler: clang + cpp_compiler: clang++ + exclude: + - os: windows-latest + c_compiler: gcc + - os: windows-latest + c_compiler: clang + - os: ubuntu-latest + c_compiler: cl + + steps: + - uses: actions/checkout@v3 + + - name: Set reusable strings + # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. + id: strings + shell: bash + run: | + echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + + - name: Install boost + uses: MarkusJx/install-boost@v2.4.4 + id: install-boost + with: + boost_version: 1.78.0 + + - name: Install LLVM and Clang + uses: KyleMayes/install-llvm-action@v1 + if: matrix.cpp_compiler == 'clang++' + with: + version: "17" + + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: > + cmake + -D "BOOST_ROOT=${{ steps.install-boost.outputs.BOOST_ROOT }}" + -B ${{ steps.strings.outputs.build-output-dir }} + -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} + -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -S ${{ github.workspace }} + + - name: Build + # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} + + - name: Test + working-directory: ${{ steps.strings.outputs.build-output-dir }} + # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest --build-config ${{ matrix.build_type }} diff --git a/.gitignore b/.gitignore index 423cfaf..7587ed8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ .cache/ .vscode/ -/build +/build* /compile_commands.json \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d7de21..e91ce40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,20 @@ project(SimSYCL VERSION 0.1 LANGUAGES CXX) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -find_package(Boost 1.60 COMPONENTS context REQUIRED) +find_package(Boost 1.70 COMPONENTS context REQUIRED) + +# Function to set properties, compile options, and link options for all simsycl targets +function(set_simsycl_target_options target) + set_target_properties(${target} PROPERTIES CXX_STANDARD 20) + set_target_properties(${target} PROPERTIES CXX_STANDARD_REQUIRED ON) + target_compile_options(${target} PRIVATE + $<$:/W4> + $<$>:-Wall -Wextra -Wpedantic $<$:-fsanitize=address>> + ) + target_link_options(${target} PRIVATE + $<$>:$<$:-fsanitize=address>> + ) +endfunction() add_library(simsycl include/sycl/sycl.hpp @@ -46,20 +59,12 @@ add_library(simsycl src/simsycl/dummy.cc ) target_link_libraries(simsycl Boost::context) - target_include_directories(simsycl PUBLIC include) -set_target_properties(simsycl PROPERTIES CXX_STANDARD 20) -set_target_properties(simsycl PROPERTIES CXX_STANDARD_REQUIRED ON) -target_compile_options(simsycl PRIVATE -Wall -Wextra -Wpedantic) -target_compile_options(simsycl PRIVATE -fsanitize=address) -target_link_options(simsycl PRIVATE -fsanitize=address) +set_simsycl_target_options(simsycl) add_executable(main src/test/main.cc) target_link_libraries(main simsycl) -set_target_properties(main PROPERTIES CXX_STANDARD 20) -set_target_properties(main PROPERTIES CXX_STANDARD_REQUIRED ON) -target_compile_options(main PRIVATE -Wall -Wextra -Wpedantic) -target_compile_options(main PRIVATE -fsanitize=address) -target_link_options(main PRIVATE -fsanitize=address) +set_simsycl_target_options(main) +enable_testing() add_subdirectory(test) diff --git a/README.md b/README.md index 6bfd900..12decc5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,20 @@ ![simSYCL](resources/logo.png) ### The SYCL implementation you did (not) know you wanted +# Requirements +SimSYCL requires the Boost `context` libary. + +# Supported Platforms +The following platform and compiler combinations are currently tested in CI: + + * Linux with GCC 11 + * Linux with Clang 17 + * Windows with MSVC + +Other platforms and compilers should also work, as long as they have sufficient C++20 support. +Note that clang versions prior to 17 do not currently work in SimSYCL due to their CTAD limitations. + # Acknowlegments - Fabian Knorr +- Peter Thoman - Luigi Crisci \ No newline at end of file diff --git a/include/simsycl/detail/group_operation_impl.hh b/include/simsycl/detail/group_operation_impl.hh index 9ff61a3..116582d 100644 --- a/include/simsycl/detail/group_operation_impl.hh +++ b/include/simsycl/detail/group_operation_impl.hh @@ -152,7 +152,7 @@ void default_group_op_function(T &per_group) { } template ::element_type, + typename PerOpT = typename std::invoke_result_t::element_type, typename ReachedF = decltype(default_group_op_function), typename CompleteF = decltype(default_group_op_function)> struct group_operation_spec { @@ -188,7 +188,7 @@ auto perform_group_operation(G g, group_operation_id id, const Spec &spec) { SIMSYCL_CHECK(op.id == new_op.id); SIMSYCL_CHECK(op.expected_num_work_items == new_op.expected_num_work_items); SIMSYCL_CHECK(op.num_work_items_participating < op.expected_num_work_items); - spec.reached(dynamic_cast(*op.per_op_data)); + spec.reached(dynamic_cast(*op.per_op_data)); ops_reached++; op.num_work_items_participating++; @@ -200,7 +200,7 @@ auto perform_group_operation(G g, group_operation_id id, const Spec &spec) { } this_nd_item_impl.barrier(); - return spec.complete(dynamic_cast(*group_impl.operations[ops_reached - 1].per_op_data)); + return spec.complete(dynamic_cast(*group_impl.operations[ops_reached - 1].per_op_data)); } // more specific helper functions for group operations diff --git a/include/simsycl/sycl/accessor.hh b/include/simsycl/sycl/accessor.hh index 85634c4..99b000f 100644 --- a/include/simsycl/sycl/accessor.hh +++ b/include/simsycl/sycl/accessor.hh @@ -137,11 +137,8 @@ class accessor { template = 0> reference operator[](id index) const; - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated-declarations" template = 0> [[deprecated]] atomic operator[](id index) const; - #pragma GCC diagnostic pop decltype(auto) operator[](size_t index) const { return detail::subscript(*this, index); } @@ -221,11 +218,8 @@ class accessor { template = 0> const accessor &operator=(value_type &&other) const; - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated-declarations" template = 0> [[deprecated]] operator atomic() const; - #pragma GCC diagnostic pop std::add_pointer_t get_pointer() const noexcept; diff --git a/include/simsycl/sycl/group_algorithms.hh b/include/simsycl/sycl/group_algorithms.hh index 217a45a..34d9ce5 100644 --- a/include/simsycl/sycl/group_algorithms.hh +++ b/include/simsycl/sycl/group_algorithms.hh @@ -238,7 +238,7 @@ T select_from_group(G g, T x, typename G::id_type remote_local_id) { // reduce -template ::value_type> +template ::value_type> T joint_reduce(G g, Ptr first, Ptr last, Op binary_op) { T result = *first; for(auto i = first + 1; first != last && i != last; ++i) { result = binary_op(result, *i); } @@ -267,7 +267,7 @@ T reduce_over_group(G g, V x, T init, Op binary_op) { // exclusive_scan template ::value_type> + typename T = typename std::iterator_traits::value_type> OutPtr joint_exclusive_scan(G g, InPtr first, InPtr last, OutPtr result, Op binary_op) { std::vector results(std::distance(first, last)); results[0] = known_identity_v; @@ -303,7 +303,7 @@ T exclusive_scan_over_group(G g, V x, T init, Op binary_op) { // inclusive_scan template ::value_type> + typename T = typename std::iterator_traits::value_type> OutPtr joint_inclusive_scan(G g, InPtr first, InPtr last, OutPtr result, Op binary_op) { std::vector results(std::distance(first, last)); results[0] = *first; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3cbf22d..9fc9b3b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,11 +9,10 @@ FetchContent_Declare( FetchContent_MakeAvailable(Catch2) add_executable(tests group_op_tests.cc) - -set_target_properties(tests PROPERTIES CXX_STANDARD 20) -set_target_properties(tests PROPERTIES CXX_STANDARD_REQUIRED ON) -target_compile_options(tests PRIVATE -Wall -Wextra -Wpedantic) -target_compile_options(tests PRIVATE -fsanitize=address) - target_link_libraries(tests PRIVATE Catch2::Catch2WithMain simsycl) -target_link_options(tests PRIVATE -fsanitize=address) +set_simsycl_target_options(tests) + +list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras) +include(CTest) +include(Catch) +catch_discover_tests(tests)