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

Disable blas #39

Merged
merged 2 commits into from
Oct 6, 2023
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
223 changes: 112 additions & 111 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ option(ROUGHPY_BUILD_TESTS "Build C++ tests for RoughPy" ON)
option(ROUGHPY_BUILD_PYMODULE_INPLACE "Buildg the pymodule in the project roughpy directory" OFF)
option(ROUGHPY_LINK_NUMPY "Link with Numpy library for array handling" ON)
option(ROUGHPY_GENERATE_DEVICE_CODE "Generate code for objects on devices" OFF)
option(ROUGHPY_DISABLE_BLAS "Disable linking to blas/lapack" OFF)
cmake_dependent_option(ROUGHPY_PREFER_ACCELERATE
"Prefer Accelerate framework on MacOS always" OFF APPLE OFF)
"Prefer Accelerate framework on MacOS always" OFF APPLE OFF)

# If testing is enabled, find GTest to make sure the tests can be
# successfully built.
Expand All @@ -49,44 +50,44 @@ if (SKBUILD)

# This is all the variables set by GNUInstallDirs, minus LIBDIR and BINDIR
set(_ignore_dirs
SBINDIR
LIBEXECDIR
SYSCONFIGDIR
SHAREDSTATEDIR
LOCALSTATEDIR
RUNSTATEDIR
INCLUDEDIR
OLDINCLUDEDIR
DATAROOTDIR
DATADIR
INFODIR
LOCALEDIR
MANDIR
DOCDIR
)
SBINDIR
LIBEXECDIR
SYSCONFIGDIR
SHAREDSTATEDIR
LOCALSTATEDIR
RUNSTATEDIR
INCLUDEDIR
OLDINCLUDEDIR
DATAROOTDIR
DATADIR
INFODIR
LOCALEDIR
MANDIR
DOCDIR
)

if (WIN32)
# On Windows, DLLs are put in BINDIR
list(APPEND _ignore_dirs LIBDIR)
set(CMAKE_INSTALL_BINDIR ${SKBUILD_PLATLIB_DIR}/roughpy CACHE STRING
"Overwritten install for BINDIR")
else()
"Overwritten install for BINDIR")
else ()
# On not Windows, Shared Objects go in LIBDIR
list(APPEND _ignore_dirs BINDIR)
set(CMAKE_INSTALL_LIBDIR ${SKBUILD_PLATLIB_DIR}/roughpy CACHE STRING
"Overwritten install for LIBDIR")
"Overwritten install for LIBDIR")

list(APPEND _ignore_dirs BINDIR)
endif()
endif ()

foreach(_dir ${_ignore_dirs})
foreach (_dir ${_ignore_dirs})
set(CMAKE_INSTALL_${_dir} ${SKBUILD_NULL_DIR} CACHE STRING
"Overwritten install for ${_dir}")
endforeach()
"Overwritten install for ${_dir}")
endforeach ()

else()
else ()
include(GNUInstallDirs)
endif()
endif ()


# Load the helper functions
Expand Down Expand Up @@ -136,15 +137,14 @@ endif ()
find_package(Python 3.8 REQUIRED COMPONENTS ${PYTHON_COMPONENTS_NEEDED})



if (NOT DEFINED pybind11_ROOT)
execute_process(COMMAND
"${Python_EXECUTABLE}" "-m" "pybind11" "--cmakedir"
COMMAND_ECHO STDOUT
RESULT_VARIABLE _python_pybind11_dir_found
OUTPUT_VARIABLE _python_pybind11_dir
OUTPUT_STRIP_TRAILING_WHITESPACE
)
"${Python_EXECUTABLE}" "-m" "pybind11" "--cmakedir"
COMMAND_ECHO STDOUT
RESULT_VARIABLE _python_pybind11_dir_found
OUTPUT_VARIABLE _python_pybind11_dir
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (_python_pybind11_dir_found EQUAL 0 AND EXISTS "${_python_pybind11_dir}")
message(STATUS "Adding Pybind11 cmake dir ${_python_pybind11_dir}")
set(pybind11_ROOT "${_python_pybind11_dir}" CACHE INTERNAL "")
Expand All @@ -164,14 +164,13 @@ check_include_file_cxx(filesystem RPY_HAS_STD_FILESYSTEM)
check_include_file_cxx(optional RPY_HAS_STD_OPTIONAL)



set(Boost_NO_WARN_NEW_VERSIONS ON)
set(RYP_BOOST_VERSION 1.81)
find_package(Boost ${RPY_BOOST_VERSION} REQUIRED COMPONENTS url system)

if (NOT RPY_HAS_STD_FILESYSTEM)
find_package(Boost ${RPY_BOOST_VERSION} REQUIRED COMPONENTS filesystem)
endif()
endif ()


find_package(Eigen3 CONFIG REQUIRED)
Expand All @@ -181,82 +180,84 @@ find_package(SndFile CONFIG REQUIRED)
find_package(tomlplusplus CONFIG REQUIRED)

message(STATUS "Target architecture ${RPY_ARCH}")
if (RPY_ARCH MATCHES "[xX](86(_64)?|64)|[aA][mM][dD]64" AND NOT
if (NOT ROUGHPY_DISABLE_BLAS)
if (RPY_ARCH MATCHES "[xX](86(_64)?|64)|[aA][mM][dD]64" AND NOT
ROUGHPY_PREFER_ACCELERATE)

# If we're looking for MKL then we might have installed it via pip.
# To make sure we can find this, let's use Python's importlib metadata to
# locate the directory containing MKLConfig.cmake and add the relevant
# directory to the prefix path.
execute_process(COMMAND ${Python_EXECUTABLE}
# If we're looking for MKL then we might have installed it via pip.
# To make sure we can find this, let's use Python's importlib metadata to
# locate the directory containing MKLConfig.cmake and add the relevant
# directory to the prefix path.
execute_process(COMMAND ${Python_EXECUTABLE}
"${CMAKE_CURRENT_LIST_DIR}/tools/python-get-binary-obj-path.py"
"--directory" "mkl-devel" "cmake/mkl/MKLConfig.cmake"
RESULT_VARIABLE _python_mkl_dir_found
OUTPUT_VARIABLE _python_mkl_dir
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if (NOT _python_mkl_dir_found AND EXISTS "${_python_mkl_dir}")
cmake_path(GET _python_mkl_dir PARENT_PATH _python_mkl_dir)
message(STATUS "Adding MKL dir from pip-installed mkl: ${_python_mkl_dir}")
list(APPEND CMAKE_PREFIX_PATH "${_python_mkl_dir}")
if (NOT MKL_ROOT)
set(MKL_ROOT "${_python_mkl_dir}")
)
if (NOT _python_mkl_dir_found AND EXISTS "${_python_mkl_dir}")
cmake_path(GET _python_mkl_dir PARENT_PATH _python_mkl_dir)
message(STATUS "Adding MKL dir from pip-installed mkl: ${_python_mkl_dir}")
list(APPEND CMAKE_PREFIX_PATH "${_python_mkl_dir}")
if (NOT MKL_ROOT)
set(MKL_ROOT "${_python_mkl_dir}")
endif ()
set(MKL_DIR "${_python_mkl_dir}")
endif ()
set(MKL_DIR "${_python_mkl_dir}")
endif ()

# Set the variables that determine the actual MKL library that we need to
# link. At the moment, we force 32-bit addressing on both 32- and 64-bit
# platforms, statically linked, and using the Intel OMP library (except on
# Windows).
if (RPY_ARCH STREQUAL "x86")
set(MKL_ARCH ia32)
else ()
set(MKL_ARCH intel64)
set(MKL_INTERFACE lp64)
endif ()
# Set the variables that determine the actual MKL library that we need to
# link. At the moment, we force 32-bit addressing on both 32- and 64-bit
# platforms, statically linked, and using the Intel OMP library (except on
# Windows).
if (RPY_ARCH STREQUAL "x86")
set(MKL_ARCH ia32)
else ()
set(MKL_ARCH intel64)
set(MKL_INTERFACE lp64)
endif ()

set(MKL_LINK static)
if (WIN32)
# Currently there is no way to get this working with threading
# on Windows using this distribution of MKL
set(MKL_THREADING sequential)
else ()
set(MKL_THREADING intel_thread)
endif ()
set(MKL_LINK static)
if (WIN32)
# Currently there is no way to get this working with threading
# on Windows using this distribution of MKL
set(MKL_THREADING sequential)
else ()
set(MKL_THREADING intel_thread)
endif ()

find_package(MKL CONFIG)
if (TARGET MKL::MKL)
set(RPY_USE_MKL ON CACHE INTERNAL "BLAS/LAPACK provided by mkl")
add_library(BLAS::BLAS ALIAS MKL::MKL)
add_library(LAPACK::LAPACK ALIAS MKL::MKL)

if (DEFINED MKL_OMP_LIB AND MKL_OMP_LIB)
# if (APPLE)
# foreach (LANG IN ITEMS C CXX)
# set(OpenMP_${LANG}_LIB_NAMES "${MKL_OMP_LIB}" CACHE STRING "libomp location for OpenMP")
# endforeach ()
# endif ()
# set(OpenMP_${MKL_OMP_LIB}_LIBRARY "${MKL_THREAD_LIB}")
find_package(MKL CONFIG)
if (TARGET MKL::MKL)
set(RPY_USE_MKL ON CACHE INTERNAL "BLAS/LAPACK provided by mkl")
add_library(BLAS::BLAS ALIAS MKL::MKL)
add_library(LAPACK::LAPACK ALIAS MKL::MKL)

if (DEFINED MKL_OMP_LIB AND MKL_OMP_LIB)
# if (APPLE)
# foreach (LANG IN ITEMS C CXX)
# set(OpenMP_${LANG}_LIB_NAMES "${MKL_OMP_LIB}" CACHE STRING "libomp location for OpenMP")
# endforeach ()
# endif ()
# set(OpenMP_${MKL_OMP_LIB}_LIBRARY "${MKL_THREAD_LIB}")
endif ()
else ()
set(RPY_USE_MKL OFF CACHE INTERNAL "BLAS/LAPACK not provided by mkl")
set(BLA_SIZEOF_INTEGER 4)
set(BLA_STATIC ON)
endif ()
else ()
set(RPY_USE_MKL OFF CACHE INTERNAL "BLAS/LAPACK not provided by mkl")
elseif (APPLE)
set(RPY_USE_ACCELERATE ON CACHE INTERNAL "BLAS/LAPACK provided by Accelerate")
set(BLA_VENDOR Apple)
set(BLA_SIZEOF_INTEGER 4)
set(BLA_STATIC ON)
endif ()
elseif (APPLE)
set(RPY_USE_ACCELERATE ON CACHE INTERNAL "BLAS/LAPACK provided by Accelerate")
set(BLA_VENDOR Apple)
set(BLA_SIZEOF_INTEGER 4)
set(BLA_STATIC ON)
endif ()

if (NOT TARGET BLAS::BLAS)
find_package(BLAS REQUIRED)
endif ()
if (NOT TARGET LAPACK::LAPACK)
find_package(LAPACK REQUIRED)
if (NOT TARGET BLAS::BLAS)
find_package(BLAS REQUIRED)
endif ()
if (NOT TARGET LAPACK::LAPACK)
find_package(LAPACK REQUIRED)
endif ()
endif ()

#if (APPLE AND NOT DEFINED MKL_OMP_LIB)
Expand Down Expand Up @@ -320,27 +321,27 @@ endif ()
#set(CMAKE_INSTALL_BINDIR "roughpy" CACHE STRING "install binary dir")

install(TARGETS
RoughPy_PyModule
EXPORT RoughPy_EXPORTS
RUNTIME DESTINATION roughpy
LIBRARY
DESTINATION roughpy
NAMELINK_SKIP
ARCHIVE DESTINATION ${SKBUILD_NULL_DIR}
COMPONENT Development
EXCLUDE_FROM_ALL
INCLUDES DESTINATION ${SKBUILD_NULL_DIR}
COMPONENT Development
EXCLUDE_FROM_ALL
)
RoughPy_PyModule
EXPORT RoughPy_EXPORTS
RUNTIME DESTINATION roughpy
LIBRARY
DESTINATION roughpy
NAMELINK_SKIP
ARCHIVE DESTINATION ${SKBUILD_NULL_DIR}
COMPONENT Development
EXCLUDE_FROM_ALL
INCLUDES DESTINATION ${SKBUILD_NULL_DIR}
COMPONENT Development
EXCLUDE_FROM_ALL
)

install(FILES roughpy/py.typed DESTINATION roughpy)
install(DIRECTORY roughpy
DESTINATION .
FILES_MATCHING
PATTERN "*.py"
PATTERN "*.pyi"
PATTERN "src/*" EXCLUDE)
DESTINATION .
FILES_MATCHING
PATTERN "*.py"
PATTERN "*.pyi"
PATTERN "src/*" EXCLUDE)

set(_runtime_deps "")
foreach (_rpy_lib IN LISTS ROUGHPY_LIBS)
Expand Down
4 changes: 3 additions & 1 deletion roughpy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ if (ROUGHPY_BUILD_PYMODULE_INPLACE)
endif ()


set_target_properties(RoughPy_PyModule PROPERTIES
INSTALL_RPATH $ORIGIN)
if (LINUX)
set_target_properties(RoughPy_PyModule PROPERTIES
INSTALL_RPATH "$ORIGIN")
INSTALL_RPATH $ORIGIN)
elseif (APPLE)
set_target_properties(RoughPy_PyModule PROPERTIES
INSTALL_RPATH "@loader_path;@loader_path/../../..")
Expand Down
4 changes: 2 additions & 2 deletions scalars/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ add_roughpy_component(Scalars
Boost::boost
Eigen3::Eigen
Libalgebra_lite::Libalgebra_lite
BLAS::BLAS
LAPACK::LAPACK
BLAS::BLAS IF NOT ROUGHPY_DISABLE_BLAS
LAPACK::LAPACK IF NOT ROUGHPY_DISABLE_BLAS
PRIVATE
PCGRandom::pcg_random
CONFIGURE
Expand Down
4 changes: 3 additions & 1 deletion scalars/scalar_blas_defs.h.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#ifndef ROUGHPY_SCALARS_SCALAR_BLAS_DEFS
#define ROUGHPY_SCALARS_SCALAR_BLAS_DEFS

#cmakedefine ROUGHPY_DISABLE_BLAS

#ifndef ROUGHPY_DISABLE_BLAS
#cmakedefine RPY_USE_MKL
#cmakedefine RPY_USE_ACCELERATE
#cmakedefine RPY_LAPACK_ILP64
Expand Down Expand Up @@ -88,5 +90,5 @@ using integer = lapack_int;
}
}


#endif // ROUGHPY_DISABLE_BLAS
#endif // ROUGHPY_SCALARS_SCALAR_BLAS_DEFS
3 changes: 2 additions & 1 deletion scalars/src/linear_algebra/blas.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include "scalar_blas_defs.h"

#ifndef ROUGHPY_DISABLE_BLAS
#define RPY_BLAS_FUNC_(NAME) RPY_JOIN(cblas_, NAME)
#define RPY_BLAS_FUNC(NAME) RPY_BLAS_FUNC_(RPY_JOIN(RPY_BLA_SPRX, NAME))

Expand Down Expand Up @@ -133,5 +134,5 @@ struct blas_funcs {
}// namespace blas
}// namespace scalars
}// namespace rpy

#endif
#endif// ROUGHPY_SCALARS_SRC_LINEAR_ALGEBRA_BLAS_H_
3 changes: 3 additions & 0 deletions scalars/src/linear_algebra/blas_complex_double.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

#include "blas.h"


#ifndef ROUGHPY_DISABLE_BLAS
#define RPY_BLA_SPRX z
#define RPY_BLA_RPRX d

Expand Down Expand Up @@ -143,4 +145,5 @@ void blas_funcs<double_complex, double>::gemm(
}// namespace scalars
}// namespace rpy

#endif // ROUGHPY_DISABLE_BLAS
#endif// ROUGHPY_SCALARS_SRC_LINEAR_ALGEBRA_BLAS_COMPLEX_DOUBLE_CPP_
4 changes: 4 additions & 0 deletions scalars/src/linear_algebra/blas_complex_float.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#define ROUGHPY_SCALARS_SRC_LINEAR_ALGEBRA_BLAS_COMPLEX_FLOAT_CPP_

#include "blas.h"

#ifndef ROUGHPY_DISABLE_BLAS

#define RPY_BLA_SPRX c
#define RPY_BLA_RPRX s

Expand Down Expand Up @@ -147,4 +150,5 @@ void blas_funcs<float_complex, float>::gemm(
}// namespace scalars
}// namespace rpy

#endif
#endif// ROUGHPY_SCALARS_SRC_LINEAR_ALGEBRA_BLAS_COMPLEX_FLOAT_CPP_
Loading