diff --git a/.ci/env/apt.sh b/.ci/env/apt.sh index 420b958385d..be9444e66df 100755 --- a/.ci/env/apt.sh +++ b/.ci/env/apt.sh @@ -1,6 +1,7 @@ #!/bin/bash #=============================================================================== # Copyright 2021 Intel Corporation +# Copyright contributors to the oneDAL project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -54,12 +55,19 @@ function install_dev-base-conda { conda env create -f .ci/env/environment.yml } +function install_arm-cross-compilers { + sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu gfortran-aarch64-linux-gnu +} + if [ "${component}" == "dpcpp" ]; then add_repo install_dpcpp elif [ "${component}" == "mkl" ]; then add_repo install_mkl +elif [ "${component}" == "arm-compiler" ]; then + update + install_arm-cross-compilers elif [ "${component}" == "clang-format" ]; then update install_clang-format @@ -69,6 +77,6 @@ elif [ "${component}" == "dev-base" ]; then install_dev-base-conda else echo "Usage:" - echo " $0 [dpcpp|mkl|clang-format|dev-base]" + echo " $0 [dpcpp|mkl|arm-compiler|clang-format|dev-base]" exit 1 fi diff --git a/.ci/env/arm-gcc-crosscompile-toolchain.cmake b/.ci/env/arm-gcc-crosscompile-toolchain.cmake new file mode 100644 index 00000000000..2114da795e7 --- /dev/null +++ b/.ci/env/arm-gcc-crosscompile-toolchain.cmake @@ -0,0 +1,38 @@ +#=============================================================================== +# Copyright contributors to the oneDAL project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#=============================================================================== + + +# Set the CMake system name to inform CMake that we are cross-compiling +set(CMAKE_SYSTEM_NAME Linux) + +# Set the cross-compilation prefix for the toolchain +set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) +set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) + +# Set the target architecture +set(CMAKE_SYSTEM_PROCESSOR aarch64) + +# Set compiler flags and options for ARMv8-A architecture with SVE +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a+sve") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a+sve") + +# Specify the root directory of the cross-compiler toolchain +set(CMAKE_FIND_ROOT_PATH / /usr/bin) + +# Specify the search paths for libraries and headers +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/.ci/env/openblas.sh b/.ci/env/openblas.sh index 2a2e8ddf448..5cf67f093cf 100755 --- a/.ci/env/openblas.sh +++ b/.ci/env/openblas.sh @@ -1,6 +1,7 @@ #!/bin/bash #=============================================================================== # Copyright 2023 Intel Corporation +# Copyright contributors to the oneDAL project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,12 +16,49 @@ # limitations under the License. #=============================================================================== +while [[ $# -gt 0 ]]; do + key="$1" + + case $key in + --target) + target="$2" + shift;; + --compiler) + compiler="$2" + shift;; + --host_compiler) + host_compiler="$2" + shift;; + --cflags) + cflags="$2" + shift;; + --cross_compile) + cross_compile="yes" + ;; + *) + echo "Unknown option: $1" + exit 1 + ;; + esac + shift +done + +target=${target:-ARMV8} +host_compiler=${host_compiler:-gcc} +compiler=${compiler:-aarch64-linux-gnu-gcc} +cflags=${cflags:--march=armv8-a+sve} + sudo apt-get update sudo apt-get -y install build-essential gcc gfortran git clone https://github.com/xianyi/OpenBLAS.git CoreCount=$(lscpu -p | grep -Ev '^#' | wc -l) pushd OpenBLAS make clean - make -j${CoreCount} NO_FORTRAN=1 + if [ "${cross_compile}" == "yes" ]; then + echo make -j${CoreCount} TARGET=${target} HOSTCC=${host_compiler} CC=${compiler} NO_FORTRAN=1 USE_OPENMP=0 USE_THREAD=0 USE_LOCKING=1 CFLAGS=\"${cflags}\" + make -j${CoreCount} TARGET=${target} HOSTCC=${host_compiler} CC=${compiler} NO_FORTRAN=1 USE_OPENMP=0 USE_THREAD=0 USE_LOCKING=1 CFLAGS=\"${cflags}\" + else + make -j${CoreCount} NO_FORTRAN=1 USE_OPENMP=0 USE_THREAD=0 USE_LOCKING=1 + fi make install PREFIX=../__deps/open_blas popd diff --git a/.ci/env/tbb.sh b/.ci/env/tbb.sh index 3b6a991647c..cede3e9bfb4 100755 --- a/.ci/env/tbb.sh +++ b/.ci/env/tbb.sh @@ -17,43 +17,73 @@ # Function to display help show_help() { - echo "Usage: $0 [-h]" - echo " -h Display this information" - echo " Set CC and CXX environment variables to change the compiler. Default is GNU." + echo "Usage: $0 [--help]" + echo -e " --help \t\t\tDisplay this information" + echo -e " --CC \t\tPass full path to c compiler. Default is GNU gcc." + echo -e " --CXX \t\tPass full path to c++ compiler. Default is GNU g++." + echo -e " --cross-compile \tPass this flag if cross-compiling." + echo -e " --toolchain_file \tPass path to cmake toolchain file. Default is './.ci/env/arm-toolchain.cmake'. Use only with '--cross_compile'" + echo -e " --target_arch \t\tTarget architecture name (i.e aarch64, x86_64, etc.) for cross-compilation. Use only with '--cross_compile'" } -# Check for command-line options -while getopts ":h" opt; do - case $opt in - h) - show_help - exit 0 - ;; - \?) - echo "Invalid option: -$OPTARG" >&2 - show_help - exit 1 - ;; +while [[ $# -gt 0 ]]; do + key="$1" + + case $key in + --CXX) + CXX="$2" + shift;; + --CC) + CC="$2" + shift;; + --toolchain_file) + toolchain_file="$2" + shift;; + --target_arch) + target_arch="$2" + shift;; + --help) + show_help + exit 0 + ;; + --cross_compile) + cross_compile="yes" + ;; + *) + echo "Unknown option: $1" + exit 1 + ;; esac + shift done -# Set default values for CXX and CC -CXX="${CXX:-g++}" -CC="${CC:-gcc}" - -echo "CXX is set to: $CXX" -echo "CC is set to: $CC" - -TBB_VERSION="v2021.10.0" +set_arch_dir() { + local arch="$1" + local arch_dir="" + if [ "$arch" == "x86_64" ]; then + arch_dir="intel64" + elif [ "$arch" == "aarch64" ]; then + arch_dir="arm" + else + echo "Unsupported arch, quitting tbb build script." + exit 1 + fi + echo "${arch_dir}" +} -arch=$(uname -m) -if [ "${arch}" == "x86_64" ]; then - arch_dir="intel64" -elif [ "${arch}" == "aarch64" ]; then - arch_dir="arm" +if [ "${cross_compile}" == "yes" ]; then + toolchain_file=${toolchain_file:-$(pwd)/.ci/env/arm-toolchain.cmake} + if [ ! -f ${toolchain_file} ]; then + echo "'${toolchain_file}' file does not exists. Please specify using '--toolchain_file=' argument." + exit 1 + fi + target_arch=${target_arch:-aarch64} else - arch_dir=${arch} + target_arch=${target_arch:-$(uname -m)} fi +arch_dir=${arch_dir:-$(set_arch_dir "${target_arch}")} + +TBB_VERSION="v2021.10.0" sudo apt-get update sudo apt-get install build-essential gcc gfortran cmake -y @@ -63,10 +93,24 @@ CoreCount=$(lscpu -p | grep -Ev '^#' | wc -l) rm -rf __deps/tbb pushd onetbb-src +rm -rf build mkdir build pushd build -cmake -DCMAKE_CXX_COMPILER=${CXX} -DCMAKE_BUILD_TYPE=Release -DTBB_TEST=OFF -DTBB_STRICT_PROTOTYPES=OFF -DCMAKE_INSTALL_PREFIX=../../__deps/tbb .. -make -j${CoreCount} +if [ "${cross_compile}" == "yes" ]; then + unset CXX + unset CC + echo cmake -DCMAKE_TOOLCHAIN_FILE=${toolchain_file} -DCMAKE_BUILD_TYPE=Release -DTBB_TEST=OFF -DTBB_STRICT_PROTOTYPES=OFF -DCMAKE_INSTALL_PREFIX=../../__deps/tbb .. + cmake -DCMAKE_TOOLCHAIN_FILE=${toolchain_file} -DCMAKE_BUILD_TYPE=Release -DTBB_TEST=OFF -DTBB_STRICT_PROTOTYPES=OFF -DCMAKE_INSTALL_PREFIX=../../__deps/tbb .. +else + # Set default values for CXX and CC + CXX="${CXX:-g++}" + CC="${CC:-gcc}" + + echo "CXX is set to: $CXX" + echo "CC is set to: $CC" + cmake -DCMAKE_CXX_COMPILER=${CXX} -DCMAKE_CC_COMPILER=${CC} -DCMAKE_BUILD_TYPE=Release -DTBB_TEST=OFF -DTBB_STRICT_PROTOTYPES=OFF -DCMAKE_INSTALL_PREFIX=../../__deps/tbb .. +fi +make -j${CoreCount} make install popd popd diff --git a/.ci/pipeline/ci.yml b/.ci/pipeline/ci.yml index be3d1c55311..4dd26d8781d 100755 --- a/.ci/pipeline/ci.yml +++ b/.ci/pipeline/ci.yml @@ -1,3 +1,4 @@ +# Copyright contributors to the oneDAL project # C/C++ with GCC # Build your C/C++ project with GCC using make. # Add steps that publish test results, save build artifacts, deploy, and more: @@ -83,7 +84,44 @@ jobs: condition: failed() continueOnError: true -- job: 'LinuxMakeGNU_OpenBLAS' +- job: 'LinuxMakeGNU_OpenBLAS_ARM' + timeoutInMinutes: 0 + variables: + release.dir: '__release_lnx_gnu' + platform.type : 'lnxarm' + pool: + vmImage: 'ubuntu-22.04' + steps: + - script: | + .ci/env/apt.sh dev-base + displayName: 'apt-get and conda install' + - script: | + .ci/env/apt.sh arm-compiler + displayName: 'arm-compiler installation' + - script: | + .ci/scripts/describe_system.sh + displayName: 'System info' + - script: | + .ci/scripts/build.sh --compiler gnu --optimizations sve --target daal --backend_config ref --conda-env ci-env --cross_compile --arch arm --plat lnxarm + displayName: 'make daal' + - script: | + .ci/scripts/build.sh --compiler gnu --optimizations sve --target onedal_c --backend_config ref --cross_compile --arch arm --plat lnxarm + displayName: 'make onedal_c' + - task: PublishPipelineArtifact@1 + inputs: + artifactName: '$(platform.type) ARM OpenBLAS build' + targetPath: '$(Build.Repository.LocalPath)/$(release.dir)' + displayName: 'Upload build artifacts' + continueOnError: true + - task: PublishPipelineArtifact@1 + inputs: + artifactName: '$(platform.type) fail' + targetPath: '$(Build.Repository.LocalPath)/$(release.dir)' + displayName: 'Uploading on fail' + condition: failed() + continueOnError: true + +- job: 'LinuxMakeGNU_OpenBLAS_x86' timeoutInMinutes: 0 variables: release.dir: '__release_lnx_gnu' diff --git a/.ci/scripts/build.sh b/.ci/scripts/build.sh index 62b3623a3fe..8937c04ad4c 100755 --- a/.ci/scripts/build.sh +++ b/.ci/scripts/build.sh @@ -16,49 +16,76 @@ # limitations under the License. #=============================================================================== +# Obtain platform, OS and arch details automatically +PLATFORM=$(bash dev/make/identify_os.sh) +OS=${PLATFORM::3} +ARCH=${PLATFORM:3:3} + +# set default values for optimisation based on arch, these values can be overidden by passed arguments to the script. +if [[ "${ARCH}" == "32e" ]] +then +optimizations=${optimizations:-avx2} +elif [[ "${ARCH}" == "arm" ]] +then +optimizations=${optimizations:-sve} +else +echo "Unknown architecture '${ARCH}'" +exit 1 +fi + +# set PLAT based on OS +if [[ "${OS}" == "lnx" ]]; then + if [[ "${ARCH}" == "32e" ]]; then + PLAT=lnx32e + elif [[ "${ARCH}" == "arm" ]]; then + PLAT=lnxarm + fi +elif [[ "${OS}" == "win" ]]; then + if [[ "${ARCH}" == "32e" ]]; then + PLAT=win2e + fi +elif [[ "${OS}" == "mac" ]]; then + if [[ "${ARCH}" == "32e" ]]; then + PLAT=mac32e + fi +fi + while [[ $# -gt 0 ]]; do key="$1" case $key in --compiler) compiler="$2" - ;; + shift;; --optimizations) optimizations="$2" - ;; + shift;; --target) target="$2" - ;; + shift;; --backend_config) backend_config="$2" - ;; + shift;; --conda-env) conda_env="$2" + shift;; + --cross_compile) + cross_compile="yes" ;; + --arch) + ARCH="$2" + shift;; + --plat) + PLAT="$2" + shift;; *) echo "Unknown option: $1" exit 1 ;; esac shift - shift done -PLATFORM=$(bash dev/make/identify_os.sh) -OS=${PLATFORM::3} -ARCH=${PLATFORM:3:3} - -if [[ "${ARCH}" == "32e" ]] -then -optimizations=${optimizations:-avx2} -elif [[ "${ARCH}" == "arm" ]] -then -optimizations=${optimizations:-sve} -else -echo "Unknown architecture '${ARCH}'" -exit 1 -fi - backend_config=${backend_config:-mkl} GLOBAL_RETURN=0 @@ -69,6 +96,7 @@ if [ "${OS}" == "lnx" ]; then echo "conda '${conda_env}' env activated at ${CONDA_PREFIX}" fi compiler=${compiler:-gnu} + #gpu support is only for Linux 64 bit if [ "${ARCH}" == "32e" ]; then with_gpu="true" @@ -103,26 +131,45 @@ if [ "${backend_config}" == "mkl" ]; then elif [ "${backend_config}" == "ref" ]; then echo "Sourcing ref(openblas) env" if [ ! -d "__deps/open_blas" ]; then - $(pwd)/.ci/env/openblas.sh + if [ "${optimizations}" == "sve" ] && [ "${cross_compile}" == "yes" ]; then + $(pwd)/.ci/env/openblas.sh --target ARMV8 --host_compiler gcc --compiler aarch64-linux-gnu-gcc --cflags -march=armv8-a+sve --cross_compile + else + $(pwd)/.ci/env/openblas.sh + fi fi else echo "Not supported backend env" fi -#TBB setup -if [[ "${ARCH}" == "32e" ]] -then -$(pwd)/dev/download_tbb.sh -elif [[ "${ARCH}" == "arm" ]] -then -$(pwd)/.ci/env/tbb.sh +# TBB setup +if [[ "${ARCH}" == "32e" ]]; then + $(pwd)/dev/download_tbb.sh +elif [[ "${ARCH}" == "arm" ]]; then + if [[ "${cross_compile}" == "yes" ]]; then + $(pwd)/.ci/env/tbb.sh --cross_compile --toolchain_file $(pwd)/.ci/env/arm-gcc-crosscompile-toolchain.cmake --target_arch aarch64 + else + $(pwd)/.ci/env/tbb.sh + fi +fi + +if [ "${optimizations}" == "sve" ] && [ "${cross_compile}" == "yes" ]; then + export CXX=aarch64-linux-gnu-g++ + export CC=aarch64-linux-gnu-gcc fi echo "Calling make" +echo $CXX +echo $CC +echo make ${target:-daal_c} ${make_op} \ + COMPILER=${compiler} \ + REQCPU="${optimizations}" \ + BACKEND_CONFIG="${backend_config}" \ + PLAT=$PLAT make ${target:-daal_c} ${make_op} \ COMPILER=${compiler} \ REQCPU="${optimizations}" \ - BACKEND_CONFIG="${backend_config}" + BACKEND_CONFIG="${backend_config}" \ + PLAT=${PLAT} err=$? if [ ${err} -ne 0 ]; then diff --git a/cpp/oneapi/dal/detail/cpu_info_arm_impl.hpp b/cpp/oneapi/dal/detail/cpu_info_arm_impl.hpp index 8304622e3a9..6513ce5e5f0 100644 --- a/cpp/oneapi/dal/detail/cpu_info_arm_impl.hpp +++ b/cpp/oneapi/dal/detail/cpu_info_arm_impl.hpp @@ -25,12 +25,12 @@ class cpu_info_arm : public cpu_info_impl { public: cpu_info_arm() { info_["top_cpu_extension"] = cpu_extension::sve; - info_["vendor"] = cpu_vendor::arm); + info_["vendor"] = cpu_vendor::arm; } explicit cpu_info_arm(const cpu_extension cpu_extension) { info_["top_cpu_extension"] = cpu_extension; - info_["vendor"] = cpu_vendor::arm); + info_["vendor"] = cpu_vendor::arm; } };