1.编译准备
下载Cuda工具包
PS:最开始选择的11.7版本,但是在vs中nvcc编译时会编译不过,后来选择了amgx中提到的11.0,然后下载了11.0.3
PS:最开始下载的main分支也是不能够编译通过,所以后面下载了2.3.0的版本
2.安装
1.Cuda安装
没啥好说的以此下一步,得到安装目录(我的是 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0)后续配置环境变量(CudaToolkitCustomDir):
2.cmake安装
一样下一步走;
3.AMGX cmake 构建工程
我采用的是VS2017来编译所以需要指定编译器;win+r->cmd->cd定位到源码目录->mkdir build17 -> cd build 17->输入
cmake .. -G"Visual Studio 15 2017"
构建好后就有AMG.sln了
3.AMGX编译
AMG.sln下有一系列工程有 测试程序(exe)静态库(lib)动态库(dll);其中amgx.lib,amgx_libs.lib,
amgx_template_plugin.lib有1.6xGB;
1.工程配置更改
得到的工程文件中没有x64版本的解决方案,x86+Debug的nvcc不知道啥原因会编译出错,所以从Win32解决方案复制添加x64的解决方案,编译Release工程;
改工程中链接器的命令行指令,由于之前的是x86的解决方案,且添加了命令行“/MACHINE:X86”将其删除,否则会报“模块计算机类型x64与目标计算机类型X86冲突”错误;
一些工程的源文件路径(如amgx工程的源文件为obj文件(编译的中间目标翻译文件))在amgx_libs.dir\Release下 ,所以需要将amgx_libs的中间目录修改为“amgx_libs.dir$(Configuration)\”,同理amgx_tests_libs的中间目录修改为“amgx_tests_libs.dir$(Configuration)\”;
测试程序的编译需要添加库目录:“…$(Platform)\Release;”
完全编译后得到如下文件:
在AMG-2.3.0\examples下找到matrix.mtx,在AMG-2.3.0\core\configs下找到FGMRES_AGGREGATION.json拷贝到目录通过cmd运行:
>amgx_capi.exe -m matrix.mtx -c FGMRES_AGGREGATION.json
AMGX version 2.2.0.132-opensource
Built on Aug 6 2022, 09:56:12
Compiled with CUDA Runtime 11.0, using CUDA driver 11.7
Warning: No mode specified, using dDDI by default.
Reading data...
RHS vector was not found. Using RHS b=[1,鈥?1]^T
Solution vector was not found. Setting initial solution to x=[0,鈥?0]^T
Finished reading
AMG Grid:
Number of Levels: 1
LVL ROWS NNZ SPRSTY Mem (GB)
--------------------------------------------------------------
0(D) 12 61 0.424 8.75e-07
--------------------------------------------------------------
Grid Complexity: 1
Operator Complexity: 1
Total Memory Usage: 8.75443e-07 GB
--------------------------------------------------------------
iter Mem Usage (GB) residual rate
--------------------------------------------------------------
Ini 1.24291 3.464102e+00
0 1.24291 3.045063e-14 0.0000
--------------------------------------------------------------
Total Iterations: 1
Avg Convergence Rate: 0.0000
Final Residual: 3.045063e-14
Total Reduction in Residual: 8.790338e-15
Maximum Memory Usage: 1.243 GB
--------------------------------------------------------------
Total Time: 0.00550579
setup: 0.00240749 s
solve: 0.0030983 s
solve(per iteration): 0.0030983 s
50579
setup: 0.00240749 s
solve: 0.0030983 s
solve(per iteration): 0.0030983 s