NVPL CMake Guide#
NVPL provides CMake Package Config files for the each component library.
Finding NVPL Packages#
If NVPL was installed via the OS package manager under the /usr directory, the NVPL packages will already
be on the default CMAKE_PREFIX_PATH.
The nvpl_ROOT environment variable should be used to override
the default search path and force a search for nvpl under a specific prefix. If you have downloaded
nvpl as a standalone tarball expand the tarball and set the full path to the resulting directory as nvpl_ROOT.
The find_package() command is used to find nvpl and any component libraries:
find_package(nvpl)
Each NVPL component library found will print a brief status message with important locations.
Tip
CMake variable
nvpl_FOUNDwill be true if nvpl is successfully foundCMake variable
nvpl_VERSIONwill contain the found versionPass the
REQUIREDkeyword to raise an error ifnvplpackage is not found.Regardless of the
COMPONENTSkeyword, all available nvpl component libraries installed in the same prefix will be found.To raise an error if a particular component is not found, use
REQUIRED COMPONENTS ...Set
QUIETto avoid printing status messages, or reporting an error if nvpl is not foundfind_package(nvpl)can safely be called multiple times from different locations in a project.Users of
CMake >= 3.27can also use the upper-caseNVPL_ROOTenvironment variable to set the search path for NVPL. See: CMake Package Name Variables
Linking to NVPL Packages#
The NVPL component libraries provide Imported Interface Targets
under the common nvpl:: namespace.
To add all the necessary flags to compile and link against NVPL libraries,
use the target_link_libraries() command:
target_link_libraries(my_target PUBLIC nvpl::<lib>_<opts>)
Here <lib> is the lowercase shorthand for the library/API and and <opts> are defined by the library.
NVPL Targets#
NVPL component and target names use all-lowercase naming schema. See individual libraries for details on available options.
Component |
Targets |
Options / Notes |
|---|---|---|
blas |
|
|
fft |
|
FFTW API interface |
lapack |
|
|
rand |
|
Single-threaded Multi-threaded (OpenMP) |
scalapack |
|
|
sparse |
|
|
tensor |
|
NVPL Variables#
Each nvpl component library also exports CMake variables:
nvpl_<comp>_VERSION- Version of component librarynvpl_<comp>_INCLUDE_DIR- Full path to component headers directorynvpl_<comp>_LIBRARY_DIR- Full path to component libraries directory
Using CMake FindBLAS and FindLAPACK Modules#
Starting with CMake 4.1, the FindBLAS and FindLAPACK modules have built-in
support for detecting and linking NVPL BLAS and LAPACK libraries. This provides a
portable, standards-based way to integrate NVPL into CMake projects.
Important
Due to the design of the FindBLAS.cmake module, using find_package(BLAS)
with BLA_VENDOR set to NVPL automatically links both BLAS and LAPACK
libraries together through the BLAS::BLAS target. This means you get full
BLAS and LAPACK functionality from a single find_package(BLAS) call when
using NVPL as the vendor.
Alternatively, you can use find_package(LAPACK) which provides the
LAPACK::LAPACK target that includes both BLAS and LAPACK.
Example Usage#
A complete example using find_package(BLAS) with NVPL:
cmake_minimum_required(VERSION 4.1)
project(MyApp C)
# Configure search for NVPL with ILP64 interface and OpenMP threading
set(BLA_VENDOR NVPL)
set(BLA_SIZEOF_INTEGER 8)
set(BLA_THREAD OMP)
# Find BLAS (includes LAPACK when using NVPL)
find_package(BLAS REQUIRED)
# Find OpenMP for the application
find_package(OpenMP REQUIRED)
add_executable(myapp app.c)
# Define NVPL_ILP64 macro for ILP64 interface
target_compile_definitions(myapp PRIVATE NVPL_ILP64)
# Link BLAS and OpenMP (BLAS::BLAS includes both BLAS and LAPACK)
target_link_libraries(myapp PRIVATE BLAS::BLAS OpenMP::OpenMP_C)
Alternatively, using find_package(LAPACK):
cmake_minimum_required(VERSION 4.1)
project(MyApp C)
# Configure search for NVPL with LP64 interface and sequential threading
set(BLA_VENDOR NVPL)
set(BLA_SIZEOF_INTEGER 4)
set(BLA_THREAD SEQ)
# Find LAPACK (includes BLAS when using NVPL)
find_package(LAPACK REQUIRED)
add_executable(myapp app.c)
# Link LAPACK (LAPACK::LAPACK includes both BLAS and LAPACK)
target_link_libraries(myapp PRIVATE LAPACK::LAPACK)
Examples#
See the NVPLSamples Repo for example CMake usage for each library.