Skip to content

Commit

Permalink
Enable ARM(SVE) CPU support with reference backend (uxlfoundation#2614)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajay-fuji authored Feb 21, 2024
1 parent b6fbe87 commit a76316b
Show file tree
Hide file tree
Showing 66 changed files with 1,220 additions and 253 deletions.
2 changes: 1 addition & 1 deletion .ci/env/openblas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#===============================================================================

sudo apt-get update
sudo apt-get install build-essential gcc gfortran
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
Expand Down
83 changes: 83 additions & 0 deletions .ci/env/tbb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash
#===============================================================================
# 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.
#===============================================================================

# 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."
}

# 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
;;
esac
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"

arch=$(uname -m)
if [ "${arch}" == "x86_64" ]; then
arch_dir="intel64"
elif [ "${arch}" == "aarch64" ]; then
arch_dir="arm"
else
arch_dir=${arch}
fi

sudo apt-get update
sudo apt-get install build-essential gcc gfortran cmake -y
git clone --depth 1 --branch ${TBB_VERSION} https://github.com/oneapi-src/oneTBB.git onetbb-src

CoreCount=$(lscpu -p | grep -Ev '^#' | wc -l)

rm -rf __deps/tbb
pushd onetbb-src
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}
make install
popd
popd
rm -rf onetbb-src

pushd __deps/tbb
mkdir -p lnx
mv lib/ lnx/
mv include/ lnx/
pushd lnx
mkdir -p lib/${arch_dir}/gcc4.8
mv lib/libtbb* lib/${arch_dir}/gcc4.8
popd
popd
2 changes: 1 addition & 1 deletion .ci/scripts/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Buil
echo make %1 -j%CPUCOUNT% COMPILER=%2 PLAT=win32e REQCPU=%3
make %1 -j%CPUCOUNT% COMPILER=%2 PLAT=win32e REQCPU=%3

cmake -DINSTALL_DIR=__release_win_vc\daal\latest\lib\cmake\oneDAL -P cmake\scripts\generate_config.cmake
cmake -DINSTALL_DIR=__release_win_vc\daal\latest\lib\cmake\oneDAL -DARCH_DIR=intel64 -P cmake\scripts\generate_config.cmake
20 changes: 20 additions & 0 deletions .ci/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#! /bin/bash
#===============================================================================
# Copyright 2019 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.
Expand Down Expand Up @@ -47,7 +48,17 @@ 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

Expand Down Expand Up @@ -97,7 +108,16 @@ elif [ "${backend_config}" == "ref" ]; then
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
fi

echo "Calling make"
make ${target:-daal_c} ${make_op} \
COMPILER=${compiler} \
Expand Down
15 changes: 13 additions & 2 deletions .ci/scripts/test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#! /bin/bash
#===============================================================================
# Copyright 2019 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.
Expand Down Expand Up @@ -54,7 +55,17 @@ TESTING_RETURN=0
PLATFORM=$(bash dev/make/identify_os.sh)
OS=${PLATFORM::3}
ARCH=${PLATFORM:3:3}
full_arch=intel64
if [ "$ARCH" == "32e" ]; then
full_arch=intel64
arch_dir=intel_intel64
elif [ "$ARCH" == "arm" ]; then
full_arch=arm
arch_dir=arm_aarch64
else
echo "Unknown architecture ${ARCH} detected for platform ${PLATFORM}"
exit 1
fi

build_system=${build_system:-cmake}
backend=${backend:-mkl}

Expand Down Expand Up @@ -161,7 +172,7 @@ for link_mode in ${link_modes}; do
fi
output_result=
err=
cmake_results_dir="_cmake_results/intel_intel64_${lib_ext}"
cmake_results_dir="_cmake_results/${arch_dir}_${lib_ext}"
for p in ${cmake_results_dir}/*; do
e=$(basename "$p")
${p} 2>&1 > ${e}.res
Expand Down
3 changes: 2 additions & 1 deletion cmake/scripts/generate_config.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#===============================================================================
# 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.
Expand All @@ -19,7 +20,7 @@ set(DAL_ROOT_REL_PATH "../../..")
set(INC_REL_PATH "include")
set(LIB_REL_PATH "lib")
set(DLL_REL_PATH "redist")
set(SUB_DIR "intel64")
set(ARCH_DIR_ONEDAL "${ARCH_DIR_ONEDAL}")

# Parse version info if possible
if (NOT "$ENV{DALROOT}" STREQUAL "")
Expand Down
4 changes: 2 additions & 2 deletions cmake/templates/oneDALConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ foreach (_dal_component ${DAL_LIBS})
find_library(
_dal_lib
NAMES "${LIB_PREFIX}${_dal_component}${LIB_EXT}"
PATH_SUFFIXES "lib/intel64"
PATH_SUFFIXES "lib/@ARCH_DIR_ONEDAL@"
PATHS "${_dal_root}")
elseif (${ONEDAL_LINK} STREQUAL "dynamic")
add_library(oneDAL::${_dal_component} SHARED IMPORTED)
find_library(
_dal_lib
NAMES "${LIB_PREFIX}${_dal_component}${DLL_EXT}"
PATH_SUFFIXES "lib/intel64"
PATH_SUFFIXES "lib/@ARCH_DIR_ONEDAL@"
PATHS "${_dal_root}")
endif()

Expand Down
8 changes: 8 additions & 0 deletions cpp/daal/include/algorithms/algorithm_container_base_batch.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* file: algorithm_container_base_batch.h */
/*******************************************************************************
* Copyright 2014 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.
Expand Down Expand Up @@ -142,11 +143,18 @@ class AlgorithmContainerImpl<batch> : public AlgorithmContainer<batch>
* \tparam sse42Container Implementation for Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2)
* \tparam avx2Container Implementation for Intel(R) Advanced Vector Extensions 2 (Intel(R) AVX2)
* \tparam avx512Container Implementation for Intel(R) Xeon(R) processors based on Intel AVX-512
* \tparam sve Implementation for ARM processors based on Arm Scalable Vector Extension
*/

#if defined(TARGET_X86_64)
template <typename sse2Container DAAL_KERNEL_SSE42_ONLY(typename sse42Container) DAAL_KERNEL_AVX2_ONLY(typename avx2Container)
DAAL_KERNEL_AVX512_ONLY(typename avx512Container)>
class DAAL_EXPORT AlgorithmDispatchContainer<batch, sse2Container DAAL_KERNEL_SSE42_ONLY(sse42Container) DAAL_KERNEL_AVX2_ONLY(avx2Container)
DAAL_KERNEL_AVX512_ONLY(avx512Container)> : public AlgorithmContainerImpl<batch>
#elif defined(TARGET_ARM)
template <typename SVEContainer DAAL_KERNEL_SVE_ONLY(typename sveContainer)>
class DAAL_EXPORT AlgorithmDispatchContainer<batch, SVEContainer DAAL_KERNEL_SVE_ONLY(sveContainer)> : public AlgorithmContainerImpl<batch>
#endif
{
public:
/**
Expand Down
19 changes: 16 additions & 3 deletions cpp/daal/include/algorithms/algorithm_container_base_common.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* file: algorithm_container_base_common.h */
/*******************************************************************************
* Copyright 2014 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.
Expand All @@ -24,6 +25,8 @@
#ifndef __ALGORITHM_CONTAINER_BASE_COMMON_H__
#define __ALGORITHM_CONTAINER_BASE_COMMON_H__

#include "services/daal_defines.h"

#include "algorithms/algorithm_container_base.h"
#include "services/error_handling.h"
#include "services/internal/gpu_support_checker.h"
Expand Down Expand Up @@ -53,8 +56,13 @@ namespace interface1
* \tparam avx2Container Implementation for Intel(R) Advanced Vector Extensions 2 (Intel(R) AVX2)
* \tparam avx512Container Implementation for Intel(R) Xeon(R) processors based on Intel AVX-512
*/

#if defined(TARGET_X86_64)
template <ComputeMode mode, typename sse2Container DAAL_KERNEL_SSE42_ONLY(typename sse42Container) DAAL_KERNEL_AVX2_ONLY(typename avx2Container)
DAAL_KERNEL_AVX512_ONLY(typename avx512Container)>
#elif defined(TARGET_ARM)
template <ComputeMode mode, typename SVEContainer DAAL_KERNEL_SVE_ONLY(typename sveContainer)>
#endif
class DAAL_EXPORT AlgorithmDispatchContainer : public AlgorithmContainerImpl<mode>
{
public:
Expand Down Expand Up @@ -99,10 +107,15 @@ class DAAL_EXPORT AlgorithmDispatchContainer : public AlgorithmContainerImpl<mod
AlgorithmDispatchContainer & operator=(const AlgorithmDispatchContainer &);
};

#define __DAAL_ALGORITHM_CONTAINER(Mode, ContainerTemplate, ...) \
algorithms::AlgorithmDispatchContainer<Mode, ContainerTemplate<__VA_ARGS__, sse2> DAAL_KERNEL_SSE42_CONTAINER(ContainerTemplate, __VA_ARGS__) \
DAAL_KERNEL_AVX2_CONTAINER(ContainerTemplate, __VA_ARGS__) \
#if defined(TARGET_X86_64)
#define __DAAL_ALGORITHM_CONTAINER(Mode, ContainerTemplate, ...) \
algorithms::AlgorithmDispatchContainer<Mode, ContainerTemplate<__VA_ARGS__, sse2> DAAL_KERNEL_SSE42_CONTAINER( \
ContainerTemplate, __VA_ARGS__) DAAL_KERNEL_AVX2_CONTAINER(ContainerTemplate, __VA_ARGS__) \
DAAL_KERNEL_AVX512_CONTAINER(ContainerTemplate, __VA_ARGS__)>
#elif defined(TARGET_ARM)
#define __DAAL_ALGORITHM_CONTAINER(Mode, ContainerTemplate, ...) \
algorithms::AlgorithmDispatchContainer<Mode, ContainerTemplate<__VA_ARGS__, sve> DAAL_KERNEL_SVE_CONTAINER(ContainerTemplate, __VA_ARGS__)>
#endif

/** @} */
} // namespace interface1
Expand Down
11 changes: 11 additions & 0 deletions cpp/daal/include/services/daal_defines.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* file: daal_defines.h */
/*******************************************************************************
* Copyright 2014 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.
Expand Down Expand Up @@ -28,6 +29,14 @@

#include <cstddef> // for size_t

#if defined(__x86_64__) || defined(__x86_64) || defined(__amd64) || defined(_M_AMD64)
#define TARGET_X86_64
#endif

#if defined(__ARM_ARCH) || defined(__aarch64__)
#define TARGET_ARM
#endif

#if (defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER)) && !defined(SYCL_LANGUAGE_VERSION)
#define DAAL_INTEL_CPP_COMPILER
#endif
Expand Down Expand Up @@ -65,6 +74,8 @@
#if !defined(DAAL_INT)
#if defined(_WIN64) || defined(__x86_64__)
#define DAAL_INT __int64
#elif defined(TARGET_ARM)
#define DAAL_INT __int64
#else
#define DAAL_INT __int32
#endif
Expand Down
18 changes: 16 additions & 2 deletions cpp/daal/include/services/env_detect.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* file: env_detect.h */
/*******************************************************************************
* Copyright 2014 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.
Expand Down Expand Up @@ -42,11 +43,16 @@ namespace daal
*/
enum CpuType
{
#if defined(TARGET_X86_64)
sse2 = 0, /*!< Intel(R) Streaming SIMD Extensions 2 (Intel(R) SSE2) */
sse42 = 2, /*!< Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) */
avx2 = 4, /*!< Intel(R) Advanced Vector Extensions 2 (Intel(R) AVX2) */
avx512 = 6, /*!< Intel(R) Xeon(R) processors based on Intel(R) Advanced Vector Extensions 512 (Intel(R) AVX-512) */
lastCpuType = avx512
#elif defined(TARGET_ARM)
sve = 0, /*!< ARM(R) processors based on Arm's Scalable Vector Extension (SVE) */
lastCpuType = sve
#endif
};

namespace services
Expand Down Expand Up @@ -91,7 +97,12 @@ class DAAL_EXPORT Environment : public Base
enum CpuTypeEnable
{
cpu_default = 0, /*!< Default processor type */
avx512 = 2 /*!< Intel(R) Xeon(R) processors based on Intel(R) Advanced Vector Extensions 512 (Intel(R) AVX-512) \DAAL_DEPRECATED */

#if defined(TARGET_X86_64)
avx512 = 2 /*!< Intel(R) Xeon(R) processors based on Intel(R) Advanced Vector Extensions 512 (Intel(R) AVX-512) \DAAL_DEPRECATED */
#elif defined(TARGET_ARM)
sve = 2, /*!< ARM(R) processors based on Arm's Scalable Vector Extension (SVE) */
#endif
};

/**
Expand Down Expand Up @@ -167,7 +178,10 @@ class DAAL_EXPORT Environment : public Base
_executionContext = internal::ImplAccessor::getImplPtr<services::internal::sycl::ExecutionContextIface>(ctx);
}

services::internal::sycl::ExecutionContextIface & getDefaultExecutionContext() { return *_executionContext; }
services::internal::sycl::ExecutionContextIface & getDefaultExecutionContext()
{
return *_executionContext;
}

private:
Environment();
Expand Down
Loading

0 comments on commit a76316b

Please sign in to comment.