Skip to content

Commit

Permalink
Add hipsycl-cuda tests (#268)
Browse files Browse the repository at this point in the history
* add sycl-cuda toolchain

* update sycl composition tests

* add sycl tests with hipsycl-cuda

* try to fix ci

* try to fix ci

* try to fix ci

* try to fix build

* try to fix build

* add sycl device info query utility

* fix cuda build
  • Loading branch information
alifahrri authored Mar 16, 2024
1 parent 98303b6 commit 5f96390
Show file tree
Hide file tree
Showing 13 changed files with 530 additions and 59 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/sycl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ on:
- '*'

jobs:
opensycl-clang14-omp-docker:
name: ${{ matrix.name }}
hipsycl-clang14-omp-docker:
name: hipsycl-clang14-omp-docker
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
Expand All @@ -21,4 +21,12 @@ jobs:
docker build . --tag nmtools:sycl-clang14-omp --file docker/sycl.dockerfile
- name: run tests
run: |
docker run --rm nmtools:sycl-clang14-omp
docker run --rm nmtools:sycl-clang14-omp
hipsycl-clang14-cuda-docker:
name: hipsycl-clang14-cuda-docker
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: build docker
run: |
docker build . --tag nmtools:sycl-clang14-cuda --file docker/sycl-cuda.dockerfile
17 changes: 17 additions & 0 deletions cmake/toolchains/sycl-clang14-cuda.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
set(CMAKE_C_COMPILER /usr/local/bin/syclcc)
set(CMAKE_CXX_COMPILER /usr/local/bin/syclcc)

SET (CMAKE_C_COMPILER_WORKS 1)
add_compile_options(-W -Wall -Wextra -Werror
-Wno-gnu-string-literal-operator-template
-Wno-unknown-cuda-version
--acpp-targets="cuda:sm_60"
--acpp-clang=/usr/bin/clang++-14
)
add_link_options(
--acpp-targets="cuda:sm_60"
--acpp-clang=/usr/bin/clang++-14
)
set(NMTOOLS_TEST_CUDA_PATH "/usr/local/cuda/" CACHE STRING "manually set cuda path")
link_directories("${NMTOOLS_TEST_CUDA_PATH}/lib64")
link_libraries(cudart_static dl rt pthread)
4 changes: 4 additions & 0 deletions cmake/toolchains/sycl-clang14-omp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ SET (CMAKE_C_COMPILER_WORKS 1)
add_compile_options(-W -Wall -Werror -Wextra -Wno-gnu-string-literal-operator-template
--acpp-targets=omp
--acpp-clang=/usr/bin/clang++-14
)
add_link_options(
--acpp-targets=omp
--acpp-clang=/usr/bin/clang++-14
)
11 changes: 6 additions & 5 deletions docker/cuda-sycl.dockerfile → docker/sycl-cuda.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ RUN bash scripts/install_doctest.sh
RUN apt install -y libclang-dev clang-tools libomp-dev llvm-dev lld libboost-dev libboost-fiber-dev libboost-context-dev
RUN bash scripts/install_opensycl.sh

ARG toolchain=sycl-clang14-omp
RUN mkdir -p build && cd build \
ARG toolchain=sycl-clang14-cuda
RUN mkdir -p build/${toolchain} && cd build/${toolchain} \
&& cmake -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/${toolchain}.cmake \
-DNMTOOLS_BUILD_META_TESTS=OFF -DNMTOOLS_BUILD_UTL_TESTS=OFF -DNMTOOLS_TEST_ALL=OFF \
-DNMTOOLS_BUILD_SYCL_TESTS=ON \
../ \
&& make -j2 VERBOSE=1
../.. \
&& make -j2 VERBOSE=1 numeric-tests-sycl-doctest

CMD ["/workspace/nmtools/build/tests/sycl/numeric-tests-sycl-doctest"]
ENV toolchain=${toolchain}
CMD ["sh", "-c", "/workspace/nmtools/build/${toolchain}/tests/sycl/numeric-tests-sycl-doctest"]
9 changes: 5 additions & 4 deletions docker/sycl.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ RUN apt install -y libclang-dev clang-tools libomp-dev llvm-dev lld libboost-dev
RUN bash scripts/install_opensycl.sh

ARG toolchain=sycl-clang14-omp
RUN mkdir -p build && cd build \
RUN mkdir -p build/${toolchain} && cd build/${toolchain} \
&& cmake -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/${toolchain}.cmake \
-DNMTOOLS_BUILD_META_TESTS=OFF -DNMTOOLS_BUILD_UTL_TESTS=OFF -DNMTOOLS_TEST_ALL=OFF \
-DNMTOOLS_BUILD_SYCL_TESTS=ON \
../ \
&& make -j2 VERBOSE=1
../.. \
&& make -j2 VERBOSE=1 numeric-tests-sycl-doctest

CMD ["/workspace/nmtools/build/tests/sycl/numeric-tests-sycl-doctest"]
ENV toolchain=${toolchain}
CMD ["sh", "-c", "/workspace/nmtools/build/${toolchain}/tests/sycl/numeric-tests-sycl-doctest"]
12 changes: 10 additions & 2 deletions include/nmtools/array/eval/kernel_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ namespace nmtools::array
}
};

template <typename T>
constexpr auto compute_offset(kernel_size<T> thread_id, kernel_size<T> block_id, kernel_size<T> block_size)
{
// TODO: check for grid shape
auto idx = block_id.x() * block_size.x() + thread_id.x();
return idx;
}

template <
typename size_type=nm_size_t
, typename mutable_array_t
Expand All @@ -169,14 +177,14 @@ namespace nmtools::array
, kernel_size<size_type> block_id
, kernel_size<size_type> block_size
) {
if constexpr (meta::is_maybe_v<array_t>) {
if constexpr (meta::is_maybe_v<meta::remove_cvref_t<decltype(result)>>) {
if (!static_cast<bool>(result)) {
return;
}
assign_result(output,*result,thread_id,block_id,block_size);
} else {
auto size = nmtools::size(output);
auto idx = block_id.x() * block_size.x() + thread_id.x();
auto idx = compute_offset(thread_id,block_id,block_size);
if (idx < size) {
auto flat_lhs = view::mutable_flatten(output);
auto flat_rhs = view::flatten(result);
Expand Down
Loading

0 comments on commit 5f96390

Please sign in to comment.