diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 38865578d..7ed36a3ac 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,6 +45,16 @@ jobs: OCCA_FORTRAN_ENABLED: 1 useCMake: true + - name: "[Ubuntu] CMake + gcc + transpiler" + os: ubuntu-latest + CC: gcc + CXX: g++ + CXXFLAGS: -Wno-maybe-uninitialized -Wno-cpp + FC: gfortran + OCCA_FORTRAN_ENABLED: 1 + useCMake: true + useTranspiler: true + - name: "[Ubuntu] CMake + clang" os: ubuntu-latest CC: clang @@ -76,6 +86,9 @@ jobs: OCCA_COVERAGE: ${{ matrix.OCCA_COVERAGE }} OCCA_FORTRAN_ENABLED: ${{ matrix.OCCA_FORTRAN_ENABLED }} FORTRAN_EXAMPLES: ${{ matrix.OCCA_FORTRAN_ENABLED }} + TRANSPILER_VERSION: 1.1 + TRANSPILER_CACHE_NUMBER: 0 # Increase to reset cache manually. + steps: - uses: actions/checkout@v4 @@ -87,7 +100,16 @@ jobs: - name: Set OCCA install directory run: echo "OCCA_INSTALL_DIR=${PWD}/install" >> ${GITHUB_ENV} - - name: add oneAPI to apt + - name: Setup environment variables for oneAPI + if: ${{ matrix.useoneAPI }} + run: echo "USE_ONEAPI=1" >> ${GITHUB_ENV} + + - name: Setup environment variables for transpiler + if: ${{ matrix.useTranspiler }} + run: | + echo "USE_TRANSPILER=1" >> ${GITHUB_ENV} + + - name: Install oneAPI dpcpp compiler if: ${{ matrix.useoneAPI }} shell: bash run: | @@ -97,38 +119,54 @@ jobs: rm GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB sudo add-apt-repository "deb https://apt.repos.intel.com/oneapi all main" - - name: install oneAPI dpcpp compiler - if: ${{ matrix.useoneAPI }} - shell: bash - run: | sudo apt update sudo apt install intel-oneapi-compiler-dpcpp-cpp sudo apt install intel-oneapi-compiler-fortran - - name: Compiler info + - name: Install llvm toolchain for transpiler + if: ${{ matrix.useTranspiler }} + shell: bash + run: | + wget https://raw.githubusercontent.com/opencollab/llvm-jenkins.debian.net/master/llvm.sh + chmod +x llvm.sh + sudo ./llvm.sh 17 all + + - name: Cache transpiler install directory + if: ${{ matrix.useTranspiler }} + uses: actions/cache@v3 + id: cache + with: + path: occa-transpiler-${{ env.TRANSPILER_VERSION }}/install + key: transpiler-${{ runner.os }}-${{ env.CXX }}-${{ env.CC }}-${{ hashFiles('.github/workflows/build.yml') }}-${{ env.TRANSPILER_CACHE_NUMBER }} + + - name: Download and install transpiler + if: ${{ matrix.useTranspiler && (steps.cache.outputs.cache-hit != 'true' ) }} + shell: bash + run: | + if [ ! -z ${USE_ONEAPI+x} ] && [ "${USE_ONEAPI}" -eq 1 ]; then + source /opt/intel/oneapi/setvars.sh + fi + + wget https://github.com/libocca/occa-transpiler/releases/download/v${TRANSPILER_VERSION}/occa-transpiler-${TRANSPILER_VERSION}-including-submodules.tar.gz + tar -zxvf occa-transpiler-${TRANSPILER_VERSION}-including-submodules.tar.gz + cd occa-transpiler-${TRANSPILER_VERSION} + mkdir -p build + cmake -S . -B build -DCMAKE_INSTALL_PREFIX=install -DCMAKE_CXX_FLAGS="-Wall" + cmake --build build --target install --parallel 8 + + - name: Print compiler info for GNU Make if: ${{ !matrix.useCMake }} run: make PREFIX=${OCCA_INSTALL_DIR} -j 16 info - name: CMake configure - if: ${{ matrix.useCMake && !matrix.useoneAPI}} + if: ${{ matrix.useCMake }} run: | - cmake -S . -B build \ - -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ - -DCMAKE_INSTALL_PREFIX=${OCCA_INSTALL_DIR} \ - -DCMAKE_C_COMPILER=${CC} \ - -DCMAKE_CXX_COMPILER=${CXX} \ - -DCMAKE_Fortran_COMPILER=${FC} \ - -DOCCA_ENABLE_TESTS=ON \ - -DOCCA_ENABLE_EXAMPLES=ON \ - -DOCCA_ENABLE_FORTRAN=${OCCA_FORTRAN_ENABLED} + if [ ! -z ${USE_ONEAPI+x} ] && [ "${USE_ONEAPI}" -eq 1 ]; then + source /opt/intel/oneapi/setvars.sh + export OCCA_CC=${{ matrix.CC }} + export OCCA_CXX=${{ matrix.CXX }} + fi - - name: CMake configure - if: ${{ matrix.useCMake && matrix.useoneAPI}} - env: - OCCA_CC: ${{ matrix.CC }} - OCCA_CXX: ${{ matrix.CXX }} - run: | - source /opt/intel/oneapi/setvars.sh cmake -S . -B build \ -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ -DCMAKE_INSTALL_PREFIX=${OCCA_INSTALL_DIR} \ @@ -138,29 +176,26 @@ jobs: -DOCCA_ENABLE_TESTS=ON \ -DOCCA_ENABLE_EXAMPLES=ON \ -DOCCA_ENABLE_FORTRAN=${OCCA_FORTRAN_ENABLED} - - - name: CMake build and install - if: ${{ matrix.useCMake && !matrix.useoneAPI}} - run: | - cmake --build build --target install --parallel 16 - - name: CMake build and install - if: ${{ matrix.useCMake && matrix.useoneAPI}} - env: - OCCA_CC: ${{ matrix.CC }} - OCCA_CXX: ${{ matrix.CXX }} - run: | - source /opt/intel/oneapi/setvars.sh - cmake --build build --target install --parallel 16 - - - name: Compile library and install + - name: Build library with GNU Make if: ${{ !matrix.useCMake }} run: make -j 16 - - name: Compile tests + - name: Build tests with GNU Make if: ${{ !matrix.useCMake }} run: make -j 16 tests + - name: Build and install library with CMake + if: ${{ matrix.useCMake }} + run: | + if [ ! -z ${USE_ONEAPI+x} ] && [ "${USE_ONEAPI}" -eq 1 ]; then + source /opt/intel/oneapi/setvars.sh + export OCCA_CC=${{ matrix.CC }} + export OCCA_CXX=${{ matrix.CXX }} + fi + + cmake --build build --target install --parallel 16 + - name: Run unit tests if: ${{ !matrix.useCMake }} run: ./tests/run_tests @@ -170,20 +205,26 @@ jobs: run: ./tests/run_examples - name: Run CTests - if: ${{ matrix.useCMake && !matrix.useoneAPI }} - run: | - ctest --test-dir build --progress --output-on-failure --parallel 8 --schedule-random -E "examples_cpp_arrays-opencl|examples_cpp_for_loops-opencl|examples_cpp_generic_inline_kernel-opencl|examples_cpp_shared_memory-opencl|examples_cpp_nonblocking_streams-opencl|examples_cpp_for_loops-dpcpp|examples_cpp_arrays-dpcpp|examples_cpp_generic_inline_kernel-dpcpp|examples_cpp_nonblocking_streams-dpcpp" - - - name: Run CTests - if: ${{ matrix.useCMake && matrix.useoneAPI }} + if: ${{ matrix.useCMake }} env: - OCCA_CC: ${{ matrix.CC }} - OCCA_CXX: ${{ matrix.CXX }} OCCA_DPCPP_COMPILER: icpx run: | - source /opt/intel/oneapi/setvars.sh - export ONEAPI_DEVICE_SELECTOR=*:cpu - ctest --test-dir build --progress --output-on-failure --parallel 8 --schedule-random -E "opencl-*|dpcpp-*" + if [ ! -z ${USE_ONEAPI+x} ] && [ "${USE_ONEAPI}" -eq 1 ]; then + source /opt/intel/oneapi/setvars.sh + export ONEAPI_DEVICE_SELECTOR=*:cpu + export OCCA_CC=${{ matrix.CC }} + export OCCA_CXX=${{ matrix.CXX }} + exclude_list="opencl-*|dpcpp-*" + else + exclude_list="examples_cpp_arrays-opencl|examples_cpp_for_loops-opencl" + exclude_list="${exclude_list}|examples_cpp_generic_inline_kernel-opencl" + exclude_list="${exclude_list}|examples_cpp_shared_memory-opencl|examples_cpp_nonblocking_streams-opencl" + exclude_list="${exclude_list}|examples_cpp_for_loops-dpcpp|examples_cpp_arrays-dpcpp" + exclude_list="${exclude_list}|examples_cpp_generic_inline_kernel-dpcpp" + exclude_list="${exclude_list}|examples_cpp_nonblocking_streams-dpcpp" + fi + + ctest --test-dir build --progress --output-on-failure --parallel 8 --schedule-random -E ${exclude_list} - name: Upload code coverage if: ${{ matrix.OCCA_COVERAGE }} diff --git a/src/occa/internal/utils/transpiler_utils.cpp b/src/occa/internal/utils/transpiler_utils.cpp index ba345ac24..2ec9173c4 100644 --- a/src/occa/internal/utils/transpiler_utils.cpp +++ b/src/occa/internal/utils/transpiler_utils.cpp @@ -123,15 +123,15 @@ bool Transpiler::run(const std::string &filename, auto includes = transpiler::buildIncludes(kernelProps); auto hash = transpiler::getKernelHash(kernelProps); - oklt::UserInput input { - .backend = backend->second, - .source = std::move(sourceCode.value()), - .headers = {}, - .sourcePath = expandedFile, - .includeDirectories = std::move(includes), - .defines = std::move(defines), - .hash = std::move(hash) - }; + oklt::UserInput input; + input.backend = backend->second; + input.source = std::move(sourceCode.value()); + input.headers = {}; + input.sourcePath = expandedFile; + input.includeDirectories = std::move(includes); + input.defines = std::move(defines); + input.hash = std::move(hash); + auto result = normalizeAndTranspile(std::move(input)); if(!result) { _fail(result.error());