Skip to content
Merged
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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,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 +96,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 +135,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
72 changes: 72 additions & 0 deletions cmake/FindOpenBLAS.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#===============================================================================
# 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
)
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
6 changes: 6 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,9 @@ 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 +79,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
57 changes: 57 additions & 0 deletions include/oneapi/math/blas/detail/openblas/blas_ct.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*******************************************************************************
* Copyright 2020-2021 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
*******************************************************************************/

#ifndef _DETAIL_OPENBLAS_BLAS_CT_HPP_
#define _DETAIL_OPENBLAS_BLAS_CT_HPP_

#if __has_include(<sycl/sycl.hpp>)
#include <sycl/sycl.hpp>
#else
#include <CL/sycl.hpp>
#endif
#include <complex>
#include <cstdint>

#include "oneapi/math/types.hpp"
#include "oneapi/math/detail/backends.hpp"
#include "oneapi/math/blas/detail/openblas/onemath_blas_openblas.hpp"
#include "oneapi/math/blas/detail/blas_ct_backends.hpp"

namespace oneapi {
namespace math {
namespace blas {
namespace column_major {

#define MAJOR column_major
#include "blas_ct.hxx"
#undef MAJOR

} //namespace column_major
namespace row_major {

#define MAJOR row_major
#include "blas_ct.hxx"
#undef MAJOR

} //namespace row_major
} //namespace blas
} //namespace math
} //namespace oneapi

#endif //_DETAIL_OPENBLAS_BLAS_CT_HPP_
Loading
Loading