如何在Visual Studio中编译使用MAGMA的代码



给定MAGMA附带的示例代码,如何在Visual Studio中编译它(或您制作的任何其他使用MAGMA的代码(?

我喜欢的方法是使用CMake。

注意1:您还必须包括并链接CUDA和LAPACK(如果您最初使用MKL编译MAGMA,还必须包括MKL(

注意2:如果您不希望静态链接,则需要在运行时将DLL复制到您的项目文件夹中,或将其位置添加到PATH 中,以使其可被发现

下面的CMakeLists.txt生成一个VS项目,该项目编译并运行示例代码。

add_executable(magma-test example_sparse.cpp)
find_package( CUDA ) 
set( MKLROOT "D:/Program Files (x86)/IntelSWTools/parallel_studio_xe_2019.0.045/compilers_and_libraries_2019/windows/mkl" )
set( LAPACK_LIBRARIES 
"D:/Program Files (x86)/IntelSWTools/parallel_studio_xe_2019.0.045/compilers_and_libraries_2019/windows/mkl/lib/intel64_win/mkl_intel_lp64.lib"
"D:/Program Files (x86)/IntelSWTools/parallel_studio_xe_2019.0.045/compilers_and_libraries_2019/windows/mkl/lib/intel64_win/mkl_intel_thread.lib"
"D:/Program Files (x86)/IntelSWTools/parallel_studio_xe_2019.0.045/compilers_and_libraries_2019/windows/mkl/lib/intel64_win/mkl_core.lib"
"D:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019.0.117/windows/compiler/lib/intel64_win/libiomp5md.lib")
target_include_directories(magma-test PUBLIC 
"D:/Work/Magma/magma-2.4.0/include" 
"D:/Work/Magma/magma-2.4.0/sparse/include" 
${CUDA_INCLUDE_DIRS}
${MKLROOT}/include)
target_link_libraries(magma-test 
${CUDA_CUDART_LIBRARY}
${CUDA_CUBLAS_LIBRARIES}
${CUDA_cusparse_LIBRARY}
${LAPACK_LIBRARIES}
debug D:/Work/Magma/magma-2.4.0/build/lib/Debug/magma.lib 
debug D:/Work/Magma/magma-2.4.0/build/lib/Debug/magma_sparse.lib
optimized D:/Work/Magma/magma-2.4.0/build/lib/Release/magma.lib 
optimized D:/Work/Magma/magma-2.4.0/build/lib/Release/magma_sparse.lib)
# Sets flags that cause static linking
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") 
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")

编辑:等等,不。它在Release中编译和运行,但在Debug中没有

最新更新