Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expanded Host BLAS support #675

Merged
merged 1 commit into from
Jul 19, 2024
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
33 changes: 31 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ option(MATX_EN_CUTENSOR OFF)
option(MATX_EN_FILEIO OFF)
option(MATX_EN_X86_FFTW OFF "Enable x86 FFTW support")
option(MATX_EN_NVPL OFF, "Enable NVIDIA Performance Libraries for optimized ARM CPU support")
option(MATX_EN_BLIS OFF "Enable BLIS support")
option(MATX_EN_OPENBLAS OFF "Enable OpenBLAS support")
option(MATX_DISABLE_CUB_CACHE "Disable caching for CUB allocations" ON)
option(MATX_EN_COVERAGE OFF "Enable code coverage reporting")

Expand All @@ -68,6 +70,7 @@ set(MATX_EN_PYBIND11 OFF CACHE BOOL "Enable pybind11 support")
set(cutensor_DIR "" CACHE PATH "Directory where cuTENSOR is installed.")
set(cutensornet_DIR "" CACHE PATH "Directory where cuTensorNet is installed.")
set(eigen_DIR "" CACHE PATH "Directory where Eigen is installed")
set(blas_DIR "" CACHE PATH "Directory where a BLAS library (NVPL/OpenBLAS/BLIS) is installed (install prefix)")

# Enable compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Expand Down Expand Up @@ -187,21 +190,34 @@ else()
endif()

# Host support
if (MATX_EN_NVPL OR MATX_EN_X86_FFTW)
if (MATX_EN_NVPL OR MATX_EN_X86_FFTW OR MATX_EN_BLIS OR MATX_EN_OPENBLAS)
message(STATUS "Enabling OpenMP support")
find_package(OpenMP REQUIRED)
target_link_libraries(matx INTERFACE OpenMP::OpenMP_CXX)
target_compile_options(matx INTERFACE ${OpenMP_CXX_FLAGS})
target_compile_definitions(matx INTERFACE MATX_EN_OMP=1)

set(BLAS_FLAGS MATX_EN_NVPL MATX_EN_BLIS MATX_EN_OPENBLAS)
set(ENABLED_BLAS_COUNT 0)
foreach(BLAS_FLAG IN LISTS BLAS_FLAGS)
if(${BLAS_FLAG})
math(EXPR ENABLED_BLAS_COUNT "${ENABLED_BLAS_COUNT} + 1")
endif()
endforeach()
if(ENABLED_BLAS_COUNT GREATER 1)
message(WARNING "Multiple Host BLAS libraries (${ENABLED_BLAS_COUNT}) are enabled. Only 1 will be used.")
endif()

if (MATX_EN_NVPL)
message(STATUS "Enabling NVPL library support for ARM CPUs with ${INT_TYPE} interface")
find_package(nvpl REQUIRED COMPONENTS fft blas)
find_package(nvpl REQUIRED COMPONENTS fft blas HINTS ${blas_DIR})
if (NOT MATX_BUILD_32_BIT)
target_compile_definitions(matx INTERFACE NVPL_ILP64)
endif()
target_link_libraries(matx INTERFACE nvpl::fftw nvpl::blas_${INT_TYPE}_omp)
target_compile_definitions(matx INTERFACE MATX_EN_NVPL=1)
else()
# FFTW
if (MATX_EN_X86_FFTW)
message(STATUS "Enabling x86 FFTW")
find_library(FFTW_LIB fftw3 REQUIRED)
Expand All @@ -211,6 +227,19 @@ if (MATX_EN_NVPL OR MATX_EN_X86_FFTW)
target_link_libraries(matx INTERFACE ${FFTW_LIB} ${FFTWF_LIB} ${FFTW_OMP_LIB} ${FFTWF_OMP_LIB})
target_compile_definitions(matx INTERFACE MATX_EN_X86_FFTW=1)
endif()

# BLAS
cliffburdick marked this conversation as resolved.
Show resolved Hide resolved
if (MATX_EN_BLIS)
message(STATUS "Enabling BLIS")
include(cmake/FindBLIS.cmake)
target_link_libraries(matx INTERFACE BLIS::BLIS)
target_compile_definitions(matx INTERFACE MATX_EN_BLIS=1)
elseif(MATX_EN_OPENBLAS)
message(STATUS "Enabling OpenBLAS")
include(cmake/FindOpenBLAS.cmake)
target_link_libraries(matx INTERFACE OpenBLAS::OpenBLAS)
target_compile_definitions(matx INTERFACE MATX_EN_OPENBLAS=1)
endif()
endif()
endif()

Expand Down
81 changes: 81 additions & 0 deletions cmake/FindBLIS.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# ////////////////////////////////////////////////////////////////////////////////
# // BSD 3-Clause License
# //
# // Copyright (c) 2021, NVIDIA Corporation
# // All rights reserved.
# //
# // Redistribution and use in source and binary forms, with or without
# // modification, are permitted provided that the following conditions are met:
# //
# // 1. Redistributions of source code must retain the above copyright notice, this
# // list of conditions and the following disclaimer.
# //
# // 2. Redistributions in binary form must reproduce the above copyright notice,
# // this list of conditions and the following disclaimer in the documentation
# // and/or other materials provided with the distribution.
# //
# // 3. Neither the name of the copyright holder nor the names of its
# // contributors may be used to endorse or promote products derived from
# // this software without specific prior written permission.
# //
# // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# /////////////////////////////////////////////////////////////////////////////////

# Try using the .pc file first in case it was installed from source
find_package(PkgConfig)

if(PkgConfig_FOUND)
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:${blas_DIR}/share/pkgconfig")
pkg_check_modules(BLIS QUIET blis)
if(BLIS_FOUND)
set(BLIS_LIBRARIES ${pkgcfg_lib_BLIS_blis})
endif()
endif()

# If not found, search for the BLIS library directly
if(NOT BLIS_FOUND)
find_library(BLIS_LIBRARIES NAMES blis64 blis HINTS ${blas_DIR}/lib)

if(BLIS_LIBRARIES)
if(BLIS_LIBRARIES MATCHES ".*blis64.*")
# If the 64-bit index version is installed using a package manager like apt,
# the header files are blis64.h and cblas64.h.
set(BLIS_INCLUDE_NAME blis64.h)
set(BLIS_64_HEADER TRUE)
else()
set(BLIS_INCLUDE_NAME blis.h)
endif()

find_path(BLIS_INCLUDE_DIRS
NAMES ${BLIS_INCLUDE_NAME}
HINTS ${blas_DIR}/include
REQUIRED
)

set(BLIS_FOUND TRUE)
endif()
endif()

if(NOT BLIS_FOUND)
message(FATAL_ERROR "BLIS not found")
endif()

if(NOT TARGET BLIS::BLIS)
add_library(BLIS::BLIS INTERFACE IMPORTED)
set_target_properties(BLIS::BLIS PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${BLIS_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${BLIS_LIBRARIES}"
)
if(BLIS_64_HEADER)
target_compile_definitions(matx INTERFACE MATX_BLIS_64_HEADER=1)
endif()
endif()
47 changes: 47 additions & 0 deletions cmake/FindOpenBLAS.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# ////////////////////////////////////////////////////////////////////////////////
# // BSD 3-Clause License
# //
# // Copyright (c) 2021, NVIDIA Corporation
# // All rights reserved.
# //
# // Redistribution and use in source and binary forms, with or without
# // modification, are permitted provided that the following conditions are met:
# //
# // 1. Redistributions of source code must retain the above copyright notice, this
# // list of conditions and the following disclaimer.
# //
# // 2. Redistributions in binary form must reproduce the above copyright notice,
# // this list of conditions and the following disclaimer in the documentation
# // and/or other materials provided with the distribution.
# //
# // 3. Neither the name of the copyright holder nor the names of its
# // contributors may be used to endorse or promote products derived from
# // this software without specific prior written permission.
# //
# // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# /////////////////////////////////////////////////////////////////////////////////

set(OPENBLAS_PATH_SUFFIXES "cmake/openblas")

find_package(OpenBLAS CONFIG QUIET
HINTS ${blas_DIR}
PATH_SUFFIXES ${OPENBLAS_PATH_SUFFIXES}
REQUIRED
)

if(NOT TARGET OpenBLAS::OpenBLAS)
add_library(OpenBLAS::OpenBLAS INTERFACE IMPORTED)
set_target_properties(OpenBLAS::OpenBLAS PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${OpenBLAS_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${OpenBLAS_LIBRARIES}"
)
endif()
6 changes: 4 additions & 2 deletions include/matx.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@
#include "matx/operators/operators.h"
#include "matx/transforms/transforms.h"

using fcomplex = cuda::std::complex<float>;
using dcomplex = cuda::std::complex<double>;
namespace matx {
using fcomplex = cuda::std::complex<float>;
using dcomplex = cuda::std::complex<double>;
}

#define TEST_VECTOR_PATH "generated/"

2 changes: 1 addition & 1 deletion include/matx/executors/support.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace matx {
#endif

// MatMul
#if defined(MATX_EN_NVPL)
#if defined(MATX_EN_NVPL) || defined(MATX_EN_OPENBLAS) || defined(MATX_EN_BLIS)
#define MATX_EN_CPU_MATMUL 1
#else
#define MATX_EN_CPU_MATMUL 0
Expand Down
Loading