Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ option(ENABLE_MKLCPU_BACKEND "Enable the Intel oneMKL CPU backend for supported
option(ENABLE_MKLGPU_BACKEND "Enable the Intel oneMKL GPU backend for supported interfaces" ON)
if(ENABLE_MKLCPU_BACKEND)
option(ENABLE_MKLCPU_THREAD_TBB "Enable the use of Intel TBB with the oneMath CPU backend" ON)
option(ENABLE_MKLCPU_THREAD_OMP "Enable the use of Intel OpenMP with the oneMath CPU backend" OFF)
endif()

option(ENABLE_ARMPL_BACKEND "Enable the ArmPl backend for BLAS/LAPACK interface" OFF)
Expand All @@ -51,6 +50,7 @@ endif()
option(ENABLE_CUBLAS_BACKEND "Enable the cuBLAS backend for the BLAS interface" OFF)
option(ENABLE_ROCBLAS_BACKEND "Enable the rocBLAS backend for the BLAS interface" OFF)
option(ENABLE_NETLIB_BACKEND "Enable the Netlib backend for the BLAS interface" OFF)
option(ENABLE_OPENBLAS_BACKEND "Enable the OpenBLAS backend for the BLAS interface" OFF)
option(ENABLE_GENERIC_BLAS_BACKEND "Enable the generic BLAS backend for the BLAS interface. Cannot be used with other BLAS backends." OFF)

# rand
Expand Down Expand Up @@ -95,6 +95,7 @@ if(ENABLE_MKLCPU_BACKEND
OR ENABLE_CUBLAS_BACKEND
OR ENABLE_ROCBLAS_BACKEND
OR ENABLE_NETLIB_BACKEND
OR ENABLE_OPENBLAS_BACKEND
OR ENABLE_GENERIC_BLAS_BACKEND
OR ENABLE_ARMPL_BACKEND)
list(APPEND DOMAINS_LIST "blas")
Expand Down Expand Up @@ -133,6 +134,7 @@ if(ENABLE_GENERIC_BLAS_BACKEND
OR ENABLE_MKLGPU_BACKEND
OR ENABLE_CUBLAS_BACKEND
OR ENABLE_ROCBLAS_BACKEND
OR ENABLE_OPENBLAS_BACKEND
OR ENABLE_NETLIB_BACKEND))
message(FATAL_ERROR "ENABLE_GENERIC_BLAS_BACKEND cannot be enabled at the same time as other BLAS backends.")
endif()
Expand Down Expand Up @@ -257,12 +259,14 @@ if(ENABLE_MKLGPU_BACKEND OR ENABLE_MKLCPU_BACKEND)
set(MKL_INTERFACE ilp64)
if(ENABLE_MKLCPU_THREAD_TBB)
set(MKL_THREADING tbb_thread)
elseif(ENABLE_MKLCPU_THREAD_OMP)
set(MKL_THREADING intel_thread)
else()
set(MKL_THREADING sequential)
endif()
set(MKL_LINK dynamic)
if(BUILD_SHARED_LIBS AND NOT WIN32)
set(MKL_LINK dynamic)
else()
set(MKL_LINK static)
endif()
# Enable SYCL API
set(DPCPP_COMPILER ON)
set(SYCL_COMPILER ON)
Expand Down Expand Up @@ -319,8 +323,6 @@ endif()
if(DEFINED REF_BLAS_ROOT OR DEFINED REF_LAPACK_ROOT)
find_file(ONEMATH_REF_BLAS_LIBNAME NAMES blas.dll libblas.so HINTS ${REF_BLAS_ROOT} ${REF_LAPACK_ROOT} PATH_SUFFIXES lib lib64)
find_file(ONEMATH_REF_CBLAS_LIBNAME NAMES cblas.dll libcblas.so HINTS ${REF_BLAS_ROOT} ${REF_LAPACK_ROOT} PATH_SUFFIXES lib lib64)
find_file(ONEMATH_REF_LAPACKE_LIBNAME NAMES lapacke64.dll liblapacke64.so HINTS ${REF_LAPACK_ROOT} PATH_SUFFIXES lib lib64)
find_file(ONEMATH_REF_LAPACK_LIBNAME NAMES lapack64.dll liblapack64.so HINTS ${REF_LAPACK_ROOT} PATH_SUFFIXES lib lib64)
endif()

# Add source directory and output to bin/
Expand Down
74 changes: 74 additions & 0 deletions cmake/FindOpenBLAS.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#===============================================================================
# Copyright 2020-2023 Intel Corporation
#
# 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.
#
#
# SPDX-License-Identifier: Apache-2.0
#===============================================================================

include_guard()
include(FindPackageHandleStandardArgs)

if(DEFINED OPENBLAS_DIR)
set(_OPENBLAS_HINTS ${OPENBLAS_DIR})
elseif(DEFINED ENV{OPENBLAS_DIR})
set(_OPENBLAS_HINTS $ENV{OPENBLAS_DIR})
elseif(CMAKE_PREFIX_PATH)
set(_OPENBLAS_HINTS ${CMAKE_PREFIX_PATH})
endif()


find_library(OPENBLAS_LIBRARY
NAMES openblas libopenblas
HINTS ${_OPENBLAS_HINTS}
PATH_SUFFIXES lib lib64
)

find_path(OPENBLAS_INCLUDE
NAMES cblas.h
HINTS ${_OPENBLAS_HINTS}
PATH_SUFFIXES include include/openblas
)

find_package_handle_standard_args(OpenBLAS
REQUIRED_VARS OPENBLAS_LIBRARY OPENBLAS_INCLUDE
)

if(OpenBLAS_FOUND)

get_filename_component(OPENBLAS_LIB_DIR
${OPENBLAS_LIBRARY}
DIRECTORY
)

add_library(ONEMATH::OPENBLAS::OPENBLAS UNKNOWN IMPORTED)

set_target_properties(ONEMATH::OPENBLAS::OPENBLAS PROPERTIES
IMPORTED_LOCATION ${OPENBLAS_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${OPENBLAS_INCLUDE}
)

if(UNIX AND OPENBLAS_LIB_DIR)
set_target_properties(ONEMATH::OPENBLAS::OPENBLAS PROPERTIES
INTERFACE_LINK_OPTIONS "-Wl,-rpath,${OPENBLAS_LIB_DIR}"
)
endif()

endif()

mark_as_advanced(
OPENBLAS_LIBRARY
OPENBLAS_INCLUDE
)

10 changes: 10 additions & 0 deletions cmake/mkl/MKLConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,11 @@ if(NOT MKL_THREADING STREQUAL "tbb_thread" AND MKL_THREADING MATCHES "_thread")
"windows/compiler/lib/${MKL_ARCH}_win"
"../compiler/lib/${MKL_ARCH}_lin" "../compiler/lib/${MKL_ARCH}_win"
"../compiler/lib/${MKL_ARCH}" "../compiler/lib" "compiler/lib"
"../../compiler/latest/lib"
"../../compiler/latest/linux/compiler/lib/${MKL_ARCH}"
"../../compiler/latest/linux/compiler/lib/${MKL_ARCH}_lin"
"../../compiler/latest/windows/compiler/lib/${MKL_ARCH}"
"../../compiler/latest/windows/compiler/lib/${MKL_ARCH}_win"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the changes!
Looks like this branch CDAC-Bengaluru:openblas-backend-implementation is not synced with the latest develop branch from the main repo, so this PR contains reverted changes for some recent changes in the develop, like this change is reverting #719.
Could you please rebase your branch on the lates develop so these reverted changes will go away?

NO_DEFAULT_PATH)
if(WIN32)
set(OMP_DLLNAME ${LIB_PREFIX}${MKL_OMP_LIB}.dll)
Expand All @@ -990,6 +995,11 @@ if(NOT MKL_THREADING STREQUAL "tbb_thread" AND MKL_THREADING MATCHES "_thread")
"redist/${MKL_ARCH}"
"redist/${MKL_ARCH}_win" "redist/${MKL_ARCH}_win/compiler"
"../redist/${MKL_ARCH}/compiler" "../compiler/lib"
"../../compiler/latest/bin"
"../../compiler/latest/windows/redist/${MKL_ARCH}_win"
"../../compiler/latest/windows/redist/${MKL_ARCH}_win/compiler"
"../../compiler/latest/windows/compiler/redist/${MKL_ARCH}_win"
"../../compiler/latest/windows/compiler/redist/${MKL_ARCH}_win/compiler"
NO_DEFAULT_PATH)
if(MKL_LINK STREQUAL "sdl" AND NOT OMP_DLL_DIR)
mkl_message(WARNING "${OMP_DLLNAME} not found. MKL_ENV will not contain paths for ${OMP_DLLNAME}.")
Expand Down
5 changes: 1 addition & 4 deletions docs/building_the_project_with_adaptivecpp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ The most important supported build options are:
- False
* - ENABLE_MKLCPU_THREAD_TBB
- True, False
- True
* - ENABLE_MKLCPU_THREAD_OMP
- True, False
- False
- True
* - BUILD_FUNCTIONAL_TESTS
- True, False
- True
Expand Down
5 changes: 1 addition & 4 deletions docs/building_the_project_with_dpcpp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ The most important supported build options are:
- False
* - ENABLE_MKLCPU_THREAD_TBB
- True, False
- True
* - ENABLE_MKLCPU_THREAD_OMP
- True, False
- False
- True
* - ENABLE_GENERIC_BLAS_BACKEND
- True, False
- False
Expand Down
175 changes: 175 additions & 0 deletions docs/building_the_project_with_openblas.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
.. _building_the_project_with_openblas:

Building the Project with OpenBLAS
==================================

This page describes building oneMath with the OpenBLAS backend using
different SYCL implementations:

- DPC++ (Intel oneAPI)
- AdaptiveCpp

Environment Setup
#################

#.
Install and build OpenBLAS. The installation prefix will be referred to as
``<path to openblas>``.

#.
Clone this project. The root directory will be referred to as
``<path to onemath>``.

#.
(Optional) Install a reference BLAS/LAPACK implementation for functional
testing. The installation prefix will be referred to as
``<path to reference lapack install>``.

#.
Ensure required shared libraries are visible at runtime:

.. code-block:: bash

export LD_LIBRARY_PATH=<path to system libraries>:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=<path to openblas>/lib:$LD_LIBRARY_PATH

# Optional (only if functional tests are enabled)
export LD_LIBRARY_PATH=<path to reference lapack install>/lib:$LD_LIBRARY_PATH


Building with DPC++
###################

If using Intel oneAPI DPC++, load the compiler environment:

.. code-block:: bash

source <path to dpcpp environment script>

Build commands:

.. code-block:: bash

cd <path to onemath>
mkdir build && cd build

cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=<path to icx> \
-DCMAKE_CXX_COMPILER=<path to icpx> \
-DONEMATH_SYCL_IMPLEMENTATION=dpc++ \
-DENABLE_MKLCPU_BACKEND=False \
-DENABLE_MKLGPU_BACKEND=False \
-DENABLE_NETLIB_BACKEND=False \
-DENABLE_OPENBLAS_BACKEND=True \
-DOPENBLAS_DIR=<path to openblas> \
-DBUILD_FUNCTIONAL_TESTS=True \
-DBUILD_EXAMPLES=True \
-DCMAKE_INSTALL_PREFIX=<path to install directory> \
-DREF_BLAS_ROOT=<path to reference lapack install> \
-DREF_LAPACK_ROOT=<path to reference lapack install>

make -j && make install


Building with AdaptiveCpp
#########################

If using AdaptiveCpp, load the compiler environment:

.. code-block:: bash

source <path to adaptivecpp environment script>

Build commands:

.. code-block:: bash

cd <path to onemath>
mkdir build && cd build

cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=<path to clang> \
-DCMAKE_CXX_COMPILER=<path to acpp> \
-DONEMATH_SYCL_IMPLEMENTATION=adaptivecpp \
-DACPP_TARGETS=omp \
-DENABLE_MKLCPU_BACKEND=False \
-DENABLE_MKLGPU_BACKEND=False \
-DENABLE_NETLIB_BACKEND=False \
-DENABLE_OPENBLAS_BACKEND=True \
-DOPENBLAS_DIR=<path to openblas> \
-DBUILD_FUNCTIONAL_TESTS=True|False \
-DBUILD_EXAMPLES=True \
-DCMAKE_INSTALL_PREFIX=<path to install directory>

make -j && make install


Common Build Options
####################

.. list-table::
:header-rows: 1

* - CMake Option
- Supported Values
- Description
* - ONEMATH_SYCL_IMPLEMENTATION
- dpc++, adaptivecpp
- Selects the SYCL implementation
* - ENABLE_OPENBLAS_BACKEND
- True, False
- Enables the OpenBLAS backend
* - OPENBLAS_DIR
- Path
- Path to the OpenBLAS installation
* - ENABLE_MKLCPU_BACKEND
- True, False
- Enables/disables MKL CPU backend
* - ENABLE_MKLGPU_BACKEND
- True, False
- Enables/disables MKL GPU backend
* - ENABLE_NETLIB_BACKEND
- True, False
- Enables/disables Netlib backend
* - BUILD_FUNCTIONAL_TESTS
- True, False
- Enables functional tests
* - BUILD_EXAMPLES
- True, False
- Builds example programs
* - CMAKE_INSTALL_PREFIX
- Path
- Installation directory


Running Tests
#############

Running Test Binaries Directly
-----------------------------

The BLAS test executables are located in the ``bin`` directory inside the
build folder.

.. code-block:: bash

cd <path to onemath>/build

# Run BLAS runtime tests
./bin/test_main_blas_rt

# Run BLAS compile-time tests
./bin/test_main_blas_ct


Notes
#####

* OpenBLAS is used as the CPU BLAS backend in this configuration.
* Ensure that OpenBLAS shared libraries are available via
``LD_LIBRARY_PATH`` or system linker configuration.
* AdaptiveCpp requires proper target configuration via ``ACPP_TARGETS``.
* Functional tests require a reference BLAS/LAPACK installation.
* Test binaries are generated only if functional tests are enabled.
3 changes: 3 additions & 0 deletions include/oneapi/math/blas.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
#ifdef ONEMATH_ENABLE_NETLIB_BACKEND
#include "oneapi/math/blas/detail/netlib/blas_ct.hpp"
#endif
#ifdef ONEMATH_ENABLE_OPENBLAS_BACKEND
#include "oneapi/math/blas/detail/openblas/blas_ct.hpp"
#endif
#ifdef ONEMATH_ENABLE_ARMPL_BACKEND
#include "oneapi/math/blas/detail/armpl/blas_ct.hpp"
#endif
Expand Down
7 changes: 7 additions & 0 deletions include/oneapi/math/blas/detail/blas_ct_backends.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ namespace column_major {
#define BACKEND netlib
#include "blas_ct_backends.hxx"
#undef BACKEND
#define BACKEND openblas
#include "blas_ct_backends.hxx"
#undef BACKEND

#define BACKEND armpl
#include "blas_ct_backends.hxx"
#undef BACKEND
Expand All @@ -76,6 +80,9 @@ namespace row_major {
#define BACKEND netlib
#include "blas_ct_backends.hxx"
#undef BACKEND
#define BACKEND openblas
#include "blas_ct_backends.hxx"
#undef BACKEND
#define BACKEND armpl
#include "blas_ct_backends.hxx"
#undef BACKEND
Expand Down
1 change: 1 addition & 0 deletions include/oneapi/math/blas/detail/blas_loader.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

// Buffer APIs


ONEMATH_EXPORT void herk(oneapi::math::device libkey, sycl::queue& queue, uplo upper_lower,
transpose trans, std::int64_t n, std::int64_t k, float alpha,
sycl::buffer<std::complex<float>, 1>& a, std::int64_t lda, float beta,
Expand Down
Loading
Loading