Skip to content

Commit

Permalink
Initial sycl support (#234)
Browse files Browse the repository at this point in the history
* initial sycl support

* add sycl tests

* add sycl ci

* fix sycl ci

* fix sycl ci

* add sycl badge
  • Loading branch information
alifahrri committed Jun 19, 2023
1 parent a3a991c commit addacec
Show file tree
Hide file tree
Showing 36 changed files with 1,853 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
// "name": "cuda-12 ubuntu20.04",
// "dockerfile": "../docker/cuda.dockerfile",

// DOCKERFILE: sycl
// "name": "sycl-clang14 ubuntu22.04",
// "dockerfile": "../docker/sycl.dockerfile",

"build": {
"args": { "USERNAME": "${localEnv:USER}" },
"target": "dev"
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/sycl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: sycl

on:
push:
branches:
- 'master'
tags:
- 'v*'
pull_request:
branches:
- '*'

jobs:
opensycl-clang14-omp-docker:
name: ${{ matrix.name }}
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: build docker
run: |
docker build . --tag nmtools:sycl-clang14-omp --file docker/sycl.dockerfile
- name: run tests
run: |
docker run --rm nmtools:sycl-clang14-omp
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
</p>

# nmtools
![gcc](https://github.com/alifahrri/nmtools/workflows/gcc/badge.svg) ![clang](https://github.com/alifahrri/nmtools/workflows/clang/badge.svg) ![web-wasm](https://github.com/alifahrri/nmtools/workflows/web-wasm/badge.svg) ![arm](https://github.com/alifahrri/nmtools/workflows/arm/badge.svg) ![android](https://github.com/alifahrri/nmtools/workflows/android/badge.svg) ![riscv](https://github.com/alifahrri/nmtools/workflows/riscv/badge.svg) ![windows](https://github.com/alifahrri/nmtools/workflows/windows-mingw/badge.svg) ![mbed](https://github.com/alifahrri/nmtools/workflows/mbed-platformio/badge.svg) ![arduino](https://github.com/alifahrri/nmtools/workflows/arduino-platformio/badge.svg) [![codecov](https://codecov.io/gh/alifahrri/nmtools/branch/master/graph/badge.svg)](https://codecov.io/gh/alifahrri/nmtools)
![gcc](https://github.com/alifahrri/nmtools/workflows/gcc/badge.svg) ![clang](https://github.com/alifahrri/nmtools/workflows/clang/badge.svg) ![web-wasm](https://github.com/alifahrri/nmtools/workflows/web-wasm/badge.svg) ![arm](https://github.com/alifahrri/nmtools/workflows/arm/badge.svg) ![android](https://github.com/alifahrri/nmtools/workflows/android/badge.svg) ![riscv](https://github.com/alifahrri/nmtools/workflows/riscv/badge.svg) ![windows](https://github.com/alifahrri/nmtools/workflows/windows-mingw/badge.svg) ![mbed](https://github.com/alifahrri/nmtools/workflows/mbed-platformio/badge.svg) ![arduino](https://github.com/alifahrri/nmtools/workflows/arduino-platformio/badge.svg) [![cuda](https://github.com/alifahrri/nmtools/actions/workflows/cuda.yml/badge.svg)](https://github.com/alifahrri/nmtools/actions/workflows/cuda.yml) [![sycl](https://github.com/alifahrri/nmtools/actions/workflows/sycl.yml/badge.svg)](https://github.com/alifahrri/nmtools/actions/workflows/sycl.yml) [![codecov](https://codecov.io/gh/alifahrri/nmtools/branch/master/graph/badge.svg)](https://codecov.io/gh/alifahrri/nmtools)

A generic, composable multidimensional array library.

Expand Down
5 changes: 5 additions & 0 deletions cmake/toolchains/sycl-clang14-omp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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 -Werror -Wextra -Wno-gnu-string-literal-operator-template --hipsycl-targets=omp --hipsycl-clang=/usr/bin/clang++-14)
59 changes: 59 additions & 0 deletions docker/sycl.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from ubuntu:jammy as dev

ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia

run apt update && apt install -y \
build-essential cmake clang \
curl git-core gnupg locales \
zsh wget fonts-powerline \
&& locale-gen en_US.UTF-8

ENV DEBIAN_FRONTEND=dialog

# generate locale for agnoster
RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && /usr/sbin/locale-gen

ENV TERM xterm

# Set the default shell to bash rather than sh
ENV SHELL /bin/zsh

# run the installation script
RUN wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh || true

# install powerlevel10k
RUN git clone https://github.com/romkatv/powerlevel10k.git ~/.oh-my-zsh/custom/themes/powerlevel10k

RUN cd $HOME && curl -fsSLO https://raw.githubusercontent.com/romkatv/dotfiles-public/master/.purepower

ADD .devcontainer/.zshrc $HOME

from dev as build

WORKDIR /workspace/nmtools

COPY cmake cmake
COPY scripts scripts
COPY include include
COPY tests tests
COPY CMakeLists.txt CMakeLists.txt
COPY nmtools.pc.in nmtools.pc.in
COPY nmtoolsConfig.cmake.in nmtoolsConfig.cmake.in

## install doctest
COPY scripts/install_doctest.sh scripts/install_doctest.sh
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 \
&& 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

CMD ["/workspace/nmtools/build/tests/sycl/numeric-tests-sycl-doctest"]
4 changes: 3 additions & 1 deletion docs/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.png
*.png
blog
milestones
3 changes: 2 additions & 1 deletion include/nmtools/array/eval/cuda/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ namespace nmtools::array::cuda
{
auto args_pack = [&](){
if constexpr (meta::is_tuple_v<arg0_t>) {
return arg0;
static_assert( sizeof...(args_t) == 0, "nmtools error" );
return static_cast<const arg0_t&>(arg0);
} else {
return nmtools_tuple<const arg0_t&, const args_t&...>{arg0, args...};
}
Expand Down
100 changes: 100 additions & 0 deletions include/nmtools/array/eval/kernel_helper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#ifndef NMTOOLS_ARRAY_EVAL_KERNEL_HELPER_HPP
#define NMTOOLS_ARRAY_EVAL_KERNEL_HELPER_HPP

#include "nmtools/meta.hpp"
#include "nmtools/array/ndarray.hpp"
#include "nmtools/array/index/product.hpp"
#include "nmtools/array/view/ref.hpp"
#include "nmtools/array/view/mutable_ref.hpp"
#include "nmtools/array/view/flatten.hpp"
#include "nmtools/array/view/mutable_flatten.hpp"
#include "nmtools/array/view/reshape.hpp"

#ifdef NMTOOLS_KERNEL_MAX_DIM
#define NMTOOLS_KERNEL_MAX_DIM_ NMTOOLS_KERNEL_MAX_DIM
#else
#define NMTOOLS_KERNEL_MAX_DIM_ 8
#endif

namespace nmtools::array
{
struct create_vector_t {};

template <auto DIM=0, typename size_type, typename type>
nmtools_func_attribute
auto create_vector(const type* data_ptr, size_type dim)
{
using vector_t = meta::resolve_optype_t<create_vector_t,meta::as_type<DIM>,type>;
auto vector = vector_t{};

if constexpr (meta::is_resizable_v<vector_t>) {
vector.resize(dim);
}

for (size_type i=0; i<dim; i++) {
at(vector,i) = data_ptr[i];
}

return vector;
}

template <typename type, typename shape_type>
nmtools_func_attribute
auto create_array(const type* data_ptr, const shape_type& shape)
{
auto numel = index::product(shape);

auto ref = view::ref(data_ptr,numel);
return view::reshape(ref,shape);
}

template <auto DIM=0, typename dim_type=unsigned long, typename size_type=unsigned long, typename type>
nmtools_func_attribute
auto create_array(const type* data_ptr, const size_type* shape_ptr, dim_type dim)
{
auto shape = create_vector<DIM>(shape_ptr,dim);
return create_array(data_ptr,shape);
}

template <typename type, typename shape_type>
nmtools_func_attribute
auto create_mutable_array(type* data_ptr, const shape_type& shape)
{
const auto numel = index::product(shape);

auto ref = view::mutable_ref(data_ptr,numel);
return view::reshape(ref,shape);
}

template <auto DIM=0, typename dim_type=unsigned long, typename size_type=unsigned long, typename type>
nmtools_func_attribute
auto create_mutable_array(type* data_ptr, const size_type* shape_ptr, dim_type dim)
{
const auto shape = create_vector<DIM>(shape_ptr,dim);
return create_mutable_array(data_ptr,shape);
}
}

namespace nmtools::meta
{
template <auto DIM, typename data_type>
struct resolve_optype<
void, array::create_vector_t, as_type<DIM>, data_type
>
{
static constexpr auto vtype = [](){
if constexpr (DIM <= 0) {
using type = utl::static_vector<remove_address_space_t<data_type>,NMTOOLS_KERNEL_MAX_DIM_>;
return as_value_v<type>;
} else {
using type = nmtools_array<remove_address_space_t<data_type>,DIM>;
return as_value_v<type>;
}
}();
using type = type_t<decltype(vtype)>;
};
}

#undef NMTOOLS_KERNEL_MAX_DIM_

#endif // NMTOOLS_ARRAY_EVAL_KERNEL_HELPER_HPP
7 changes: 7 additions & 0 deletions include/nmtools/array/eval/sycl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef NMTOOLS_ARRAY_EVAL_SYCL_HPP
#define NMTOOLS_ARRAY_EVAL_SYCL_HPP

#include "nmtools/array/eval/sycl/context.hpp"
#include "nmtools/array/eval/sycl/evaluator.hpp"

#endif // NMTOOLS_ARRAY_EVAL_SYCL_HPP
Loading

0 comments on commit addacec

Please sign in to comment.