简体   繁体   English

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

[英]How to compile code that uses MAGMA in Visual Studio

给定MAGMA随附的示例代码 ,如何在Visual Studio中进行编译(或使用MAGMA的其他任何代码)?

My preferred way is making use of CMake. 我的首选方式是使用CMake。

Note1: You must also include and link CUDA and the LAPACK (plus include MKL, if you used that to compile MAGMA originally) 注意1:您还必须包括并链接CUDA和LAPACK(如果您最初是用来编译MAGMA的,则还包括MKL)

Note2: If you do not wish to link statically, you'll need to make the DLL's discoverable at run time, either by copying them into your project folder, or adding their location to PATH 注意2:如果您不希望静态链接,则需要在运行时使DLL可被发现,方法是将其复制到项目文件夹中,或者将其位置添加到PATH中。

The following CMakeLists.txt generates a VS Project that compiles and runs the example code. 以下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")

EDIT: Wait, no. 编辑:等等,不。 It's compiling and running in Release, but not in Debug.. 它是在Release中编译和运行的,但不是在Debug中运行的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM