因此,我有一个使用OpenBLAS的程序,并且使用cmake来制作它。
问题是我希望它能在2种不同情况下顺利编译:
对于Linux系统,Debian的说,一个可以安装预编译的libopenblas
带apt-get install libopenblas
,这与我的程序工作正常。这是因为我有包括:
#include <openblas/cblas.h>
现在,此选项适用于测试,不适用于真正的交易。如果与用户编译的OpenBLAS版本一起使用,我的程序的性能会更好,因为OpenBLAS对于每台计算机(取决于处理器)的编译方式都不同。但是,如果您想使用该程序,则此预编译版本很好。
对于任何人自己编译的版本,OpenBLAS安装的结构为:
├── bin
├── include
│ ├── cblas.h
│ ├── f77blas.h
│ ├── lapacke_config.h
│ ├── lapacke.h
│ ├── lapacke_mangling.h
│ ├── lapacke_utils.h
│ └── openblas_config.h
└── lib
├── libopenblas.a -> libopenblas_haswellp-r0.2.19.a
├── libopenblas_haswellp-r0.2.19.a
├── libopenblas_haswellp-r0.2.19.so
├── libopenblas.so -> libopenblas_haswellp-r0.2.19.so
└── libopenblas.so.0 -> libopenblas_haswellp-r0.2.19.so
如您所见,这里没有名为“ openblas”的目录,这意味着我的include应该是:
#include <cblas.h>
但是这很危险,因为该文件cblas.h
不仅适用于OpenBLAS,而且可以从BLAS的其他实现中获得。这导致文件可用,但是我需要的功能openblas_set_num_threads(int num_threads);
不可用。因此,如果我默认情况下将目录添加openblas
到我的cmake的包含列表中,那么如果用户没有自定义安装的OpenBLAS,则可能包含错误的文件。
所以我的问题是:您将如何正确处理此问题,以便如果不存在OpenBLAS的预编译版本,那么在没有openblas
目录的情况下进行正确的包含吗?
如果您需要更多详细信息,请告诉我。
所以我发现的解决方案是,如果找到了本地编译库,则在cmake中进行定义
if(${foundOpenBLAS})
message("I found OpenBLAS that you compiled.")
TARGET_LINK_LIBRARIES(mylibs -L"${OpenBLASPath}/lib")
else()
message("I couldn't find OpenBLAS that you compiled, so I'm assuming that you have it installed in your system.")
add_definitions(-DOPENBLAS_FROM_SYSTEM)
endif()
现在,在C ++代码中,我们执行以下操作:
#ifdef OPENBLAS_FROM_SYSTEM
#include <openblas/cblas.h>
#else
#include "include/cblas.h"
#endif
第一个版本是找不到OpenBLAS的版本,它是默认的Debian include。另一种情况是找到OpenBLAS。这将包括正确的文件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句