Skip to content

Commit

Permalink
add AOCL vendor for SCALAPACK. If vendor specified don't autobuild sc…
Browse files Browse the repository at this point in the history
…alapack
  • Loading branch information
scivision committed Feb 3, 2025
1 parent b7321ce commit 87a9700
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 54 deletions.
12 changes: 9 additions & 3 deletions Readme_LAPACK.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# LAPACK options
# LAPACK / ScaLAPACK options

The underlying "LAPACK" linear algebra interface is available from several vendors.
The underlying "LAPACK" and ScaLAPACK linear algebra interfacs are available from several vendors.
By default, the generic LAPACK library "lapack" is searched for.

To specify a particular LAPACK library, use CMake configure variable "LAPACK_VENDOR" using one of the following vendors:
To specify a particular LAPACK library, use CMake configure variable "LAPACK_VENDOR" and "SCALAPACK_VENDOR" using one of the following vendors:

* AOCL [AMD Optimizing CPU Libraries](https://www.amd.com/en/developer/aocl.html)
* Atlas [Automatically Tuned Linear Algebra Software](http://math-atlas.sourceforge.net/)
Expand All @@ -17,6 +17,12 @@ For example, to use OpenBLAS:
cmake -DLAPACK_VENDOR=OpenBLAS
```

To use AMD AOCL:

```sh
cmake -DLAPACK_VENDOR=AOCL
```

Optionally, hint the location the LAPACK library like:

```sh
Expand Down
130 changes: 94 additions & 36 deletions cmake/FindLAPACK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,15 @@ COMPONENTS default to Netlib LAPACK / LapackE, otherwise:
``AOCL``
AMD Optimizing CPU Libraries
AMD ScaLAPACK fork of Netlib ScaLAPACK.
Requires LAPACK AOCL
https://www.amd.com/en/developer/aocl/scalapack.html
``AOCL64``
AOCL 64-bit integers (default is 32-bit integers)
``LAPACKE``
Netlib LapackE for C / C++
LapackE C / C++ interface
``Netlib``
Netlib Lapack for Fortran
``OpenBLAS``
Expand Down Expand Up @@ -83,15 +88,15 @@ References
* MKL LAPACKE (C, C++): https://software.intel.com/en-us/mkl-linux-developer-guide-calling-lapack-blas-and-cblas-routines-from-c-c-language-environments
#]=======================================================================]

include(CheckFortranSourceCompiles)
include(CheckSourceCompiles)

# clear to avoid endless appending on subsequent calls
set(LAPACK_LIBRARY)
unset(LAPACK_INCLUDE_DIR)

# ===== functions ==========

function(atlas_libs)
function(lapack_atlas)

find_library(ATLAS_LIB
NAMES atlas
Expand Down Expand Up @@ -135,11 +140,11 @@ endif()

set(LAPACK_LIBRARY ${LAPACK_LIBRARY} PARENT_SCOPE)

endfunction(atlas_libs)
endfunction()

#=======================

function(netlib_libs)
function(lapack_netlib)

if(LAPACK95 IN_LIST LAPACK_FIND_COMPONENTS)
find_path(LAPACK95_INCLUDE_DIR
Expand Down Expand Up @@ -216,10 +221,10 @@ list(APPEND LAPACK_LIBRARY ${CMAKE_THREAD_LIBS_INIT})

set(LAPACK_LIBRARY ${LAPACK_LIBRARY} PARENT_SCOPE)

endfunction(netlib_libs)
endfunction()

#===============================
function(openblas_libs)
function(lapack_openblas)

find_library(LAPACK_LIBRARY
NAMES openblas
Expand All @@ -244,10 +249,15 @@ list(APPEND LAPACK_LIBRARY ${CMAKE_THREAD_LIBS_INIT})

set(LAPACK_LIBRARY ${LAPACK_LIBRARY} PARENT_SCOPE)

endfunction(openblas_libs)
endfunction()


function(lapack_aocl)

function(aocl_libs)
set(_nodef_lapack)
if(DEFINED LAPACK_ROOT)
set(_nodef_lapack NO_DEFAULT_PATH)
endif()

set(_names flame)
if(WIN32)
Expand All @@ -258,13 +268,38 @@ if(WIN32)
endif()
endif()

set(_s "LP64")
if(AOCL64 IN_LIST SCALAPACK_FIND_COMPONENTS)
string(PREPEND _s "I")
endif()

find_library(LAPACK_LIBRARY
NAMES ${_names}
NAMES_PER_DIR
PATH_SUFFIXES LP64
DOC "LAPACK Flame library"
PATH_SUFFIXES lib/${_s}
HINTS ${LAPACK_ROOT} $ENV{LAPACK_ROOT}
${_nodef_lapack}
DOC "AOCL Flame library"
)

find_path(LAPACK_INCLUDE_DIR
NAMES FLAME.h
PATH_SUFFIXES include/${_s}
HINTS ${LAPACK_ROOT} $ENV{LAPACK_ROOT}
${_nodef_lapack}
DOC "Flame header"
)

if(NOT LAPACK_LIBRARY AND LAPACK_INCLUDE_DIR)
return()
endif()

# --- BLIS
set(_nodef_blas)
if(DEFINED BLAS_ROOT)
set(_nodef_blas NO_DEFAULT_PATH)
endif()

set(_names blis-mt blis)
if(WIN32)
if(BUILD_SHARED_LIBS)
Expand All @@ -277,36 +312,61 @@ endif()
find_library(BLAS_LIBRARY
NAMES ${_names}
NAMES_PER_DIR
PATH_SUFFIXES LP64
DOC "BLAS Blis library"
)

if(NOT (LAPACK_LIBRARY AND BLAS_LIBRARY))
return()
endif()

find_path(LAPACK_INCLUDE_DIR
NAMES FLAME.h
PATH_SUFFIXES LP64
DOC "Flame header"
HINTS ${BLAS_ROOT}
PATH_SUFFIXES lib/${_s}
HINTS ${BLAS_ROOT} $ENV{BLAS_ROOT}
${_nodef_blas}
DOC "AOCL Blis library"
)

find_path(BLAS_INCLUDE_DIR
NAMES blis.h
PATH_SUFFIXES LP64
HINTS ${BLAS_ROOT}
PATH_SUFFIXES include/${_s}
HINTS ${BLAS_ROOT} $ENV{BLAS_ROOT}
${_nodef_blas}
DOC "Blis header"
)

if(NOT (LAPACK_INCLUDE_DIR AND BLAS_INCLUDE_DIR))
if(NOT BLAS_LIBRARY AND BLAS_INCLUDE_DIR)
return()
endif()


if(LAPACKE IN_LIST LAPACK_FIND_COMPONENTS)

find_library(LAPACKE_LIBRARY
NAMES lapacke
PATH_SUFFIXES lib/${_s}
HINTS ${LAPACK_ROOT} $ENV{LAPACK_ROOT}
${_nodef_lapack}
DOC "AOCL LAPACKE library"
)

# lapack/include for Homebrew
find_path(LAPACKE_INCLUDE_DIR
NAMES lapacke.h
PATH_SUFFIXES include/${_s}
HINTS ${LAPACK_ROOT} $ENV{LAPACK_ROOT}
${_nodef_lapack}
DOC "AOCL LAPACKE include directory"
)
if(NOT (LAPACKE_LIBRARY AND LAPACKE_INCLUDE_DIR))
return()
endif()

set(LAPACK_LAPACKE_FOUND true PARENT_SCOPE)
list(APPEND LAPACK_INCLUDE_DIR ${LAPACKE_INCLUDE_DIR})
list(APPEND LAPACK_LIBRARY ${LAPACKE_LIBRARY})
mark_as_advanced(LAPACKE_LIBRARY LAPACKE_INCLUDE_DIR)
endif()


set(LAPACK_AOCL_FOUND true PARENT_SCOPE)
set(LAPACK_LIBRARY ${LAPACK_LIBRARY} ${BLAS_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} PARENT_SCOPE)
set(LAPACK_INCLUDE_DIR ${LAPACK_INCLUDE_DIR} ${BLAS_INCLUDE_DIR} PARENT_SCOPE)

endfunction(aocl_libs)
endfunction()

#===============================

Expand Down Expand Up @@ -393,13 +453,13 @@ endif()
if(MKL IN_LIST LAPACK_FIND_COMPONENTS OR MKL64 IN_LIST LAPACK_FIND_COMPONENTS)
lapack_mkl()
elseif(Atlas IN_LIST LAPACK_FIND_COMPONENTS)
atlas_libs()
lapack_atlas()
elseif(Netlib IN_LIST LAPACK_FIND_COMPONENTS)
netlib_libs()
lapack_netlib()
elseif(OpenBLAS IN_LIST LAPACK_FIND_COMPONENTS)
openblas_libs()
lapack_openblas()
elseif(AOCL IN_LIST LAPACK_FIND_COMPONENTS)
aocl_libs()
lapack_aocl()
elseif(LAPACK_CRAY)
# LAPACK is implicitly part of Cray PE LibSci, use Cray compiler wrapper.
endif()
Expand All @@ -426,33 +486,31 @@ set(CMAKE_REQUIRED_LINK_OPTIONS)
set(CMAKE_REQUIRED_INCLUDES ${LAPACK_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES ${LAPACK_LIBRARY})

check_fortran_source_compiles(
check_source_compiles(Fortran
"program check_lapack
use, intrinsic :: iso_fortran_env, only : real32
implicit none
real(real32), external :: snrm2
print *, snrm2(1, [0._real32], 1)
end program"
LAPACK_s_FOUND
SRC_EXT f90
)

check_fortran_source_compiles(
check_source_compiles(Fortran
"program check_lapack
use, intrinsic :: iso_fortran_env, only : real64
implicit none
real(real64), external :: dnrm2
print *, dnrm2(1, [0._real64], 1)
end program"
LAPACK_d_FOUND
SRC_EXT f90
)

if(LAPACK_s_FOUND OR LAPACK_d_FOUND)
set(LAPACK_links true PARENT_SCOPE)
endif()

endfunction(lapack_check)
endfunction()

# --- Check library links
if(LAPACK_CRAY OR LAPACK_LIBRARY)
Expand Down
Loading

0 comments on commit 87a9700

Please sign in to comment.