使用 CMake 检测 BLAS/LAPACK 供应商

发布于 2024-11-14 06:49:33 字数 69 浏览 7 评论 0原文

所以我的代码希望在不同的 BLAS/LAPACK 供应商发生时包含不同的头文件。是否有任何预定义的宏或类似的东西让我检查它?

So my code wants to include different header files when occurs to different BLAS/LAPACK vendors. Are there any predefined macros or something like that make me check it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

朱染 2024-11-21 06:49:33

CMake 2.8+ 附带 FindBLAS.cmake FindLAPACK.cmake。您可能需要查看本地 cmake 安装中的文件中的注释:cmake-2.8.5/share/cmake/Modules/FindBLAS.cmake。该模块支持各种 BLAS 和 LAPACK 实现。例如:

set( ENV{BLA_VENDOR} "ATLAS" )
find_package( BLAS REQUIRED )

祝你好运。

CMake 2.8+ ships with FindBLAS.cmake FindLAPACK.cmake. You may want to review the comments in the files from your local cmake install: cmake-2.8.5/share/cmake/Modules/FindBLAS.cmake. This module supports a variety of BLAS and LAPACK implementations. For example:

set( ENV{BLA_VENDOR} "ATLAS" )
find_package( BLAS REQUIRED )

Good luck.

屌丝范 2024-11-21 06:49:33

(这是 CMake 3.x 时代的答案)

我曾经做过一个类似于其他答案的复杂工作流程,其中我尝试与不同的显式供应商一起检测 BLAS 发行版。

这样做的问题是你必须尝试很多可能性,逻辑就会变得复杂。
如果这是从命令行进行的,那么您还将覆盖供应商的选择。

因此,我现在要做的是检查输出变量并设置变量或采取任何特定操作:

find_package(BLAS)
if(BLAS_FOUND)
    message("Some BLAS found: linker flags ${BLAS_LINKER_FLAGS}, libs ${BLAS_LIBRARIES}, libs95 ${BLAS95_LIBRARIES}")
    foreach(lib ${BLAS_LIBRARIES})
        if(${lib} MATCHES "mkl")
            message("Some BLAS found matches MKL")
            add_definitions(-DBLAS_DOT_RETURNS_VOID)
            # in some systems with MKL, regular BLAS headers need to be found for it to work
            SET(CMAKE_SKIP_BUILD_RPATH  FALSE)
            SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
            SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib64")
            SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
            SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib64")
        endif()
        if(${lib} MATCHES "hpc_sdk")
            message("Some BLAS found matches hpc_sdk (nvhpc)")
            add_definitions(-DBLAS_DOT_RETURNS_VOID)
        endif()
        ... do this for Apple Accelerate, ATLAS, etc
    endforeach()
endif()

(this is an answer for the CMake 3.x era)

I used to do a complicated workflow similar to the other answer, in which I tried with different explicit vendors to detect the BLAS distribution.

The problem with that is that you have to try many possibilities and the logic becomes complicated.
Also you are overriding the vendor choice if this was made from the command line.

So, what I do now is to inspect the output variables and set variables or take any specific action:

find_package(BLAS)
if(BLAS_FOUND)
    message("Some BLAS found: linker flags ${BLAS_LINKER_FLAGS}, libs ${BLAS_LIBRARIES}, libs95 ${BLAS95_LIBRARIES}")
    foreach(lib ${BLAS_LIBRARIES})
        if(${lib} MATCHES "mkl")
            message("Some BLAS found matches MKL")
            add_definitions(-DBLAS_DOT_RETURNS_VOID)
            # in some systems with MKL, regular BLAS headers need to be found for it to work
            SET(CMAKE_SKIP_BUILD_RPATH  FALSE)
            SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
            SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib64")
            SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
            SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib64")
        endif()
        if(${lib} MATCHES "hpc_sdk")
            message("Some BLAS found matches hpc_sdk (nvhpc)")
            add_definitions(-DBLAS_DOT_RETURNS_VOID)
        endif()
        ... do this for Apple Accelerate, ATLAS, etc
    endforeach()
endif()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文