我正在使用建模工具箱Anuga,并将其设置为在并行支持下运行。据我目前所知,背后的机制是 Numpy 正在由 C 中的模块扩展,这些模块通过以下方式暴露给 OpenMP
extra_args = ['-fopenmp']
我已经开发并测试了一个脚本来运行mpirun -np 4 python <myscript.py>
并且它可以工作。由于模型越来越大,我的兴趣是通过 OpenMP 以 NVIDIA GPU 的物理形式将一些处理转移到 GPU。我读到这被称为卸载。我已经安装了 Quadro K2000
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 418.56 Driver Version: 418.56 CUDA Version: 10.1 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 Quadro K2000 Off | 00000000:01:00.0 On | N/A |
| 32% 48C P8 N/A / N/A | 403MiB / 1999MiB | 4% Default |
+-------------------------------+----------------------+----------------------+
所以我
安装
gcc-offload-nvptx
在我的 Ubuntu 19.04 上,它读取 gcc 的第 8 版。我那时将编译器标志更改为
extra_args = ['-fopenmp', '-fstack-protector']
和
- 通过编译安装
python setup.py build
。这将为目标模块返回以下消息,cg_ext.c
而不会出现任何进一步的错误:
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv - O2 -Wall -Wstrict-prototypes -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-rzpqx3/python2.7-2.7.16=。-fstack-protector-strong -Wformat -Werror=format-security -Wl,-Bsymbolic-functions -Wl,-z,relro -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2. 7-rzpqx3/python2.7-2.7.16=。-fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/anuga/utilities/cg_ext.o -Lbuild/temp.linux-x86_64-2.7 -o build/lib.linux-x86_64 -2.7/anuga/utilities/cg_ext.so -fopenmp -fstack-protector
什么时候
- 我检查编译的库,
ldd
我得到
build/lib.linux-x86_64-2.7/anuga/utilities/cg_ext.so linux-vdso.so.1 (0x00007fff7a9fa000) libgomp.so.1 => /usr/lib/x86_64-linux-gnu/libgomp.so.1 (0x00007f0650502000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0650317000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f0650311000 )
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f06502f0000)
/lib64/ld-linux-x86-64.so.2 (0x00007f0650606000)
所以我认为一切都已正确设置。我现在继续
- 改变一个例程的 pragma 注释如下:
前:
void cg_daxpy(int N, double a, double *x, double *y)
{
int i;
#pragma omp parallel for private(i)
for(i=0;i<N;i++)
{
y[i]=y[i]+a*x[i];
}
}
后:
void cg_daxpy(int N, double a, double *x, double *y)
{
int i;
#pragma omp target device(0)
{
#pragma omp parallel for
for(i=0;i<N;i++)
{
y[i]=y[i]+a*x[i];
}
}
}
然后我重新编译安装并运行我的脚本,希望得到分析信息:
nvprof --print-gpu-trace --profile-child-processes --profile-from-start off -fo %p.nvprof python -m cProfile runDamBreak.py
这将返回消息
==19444== Profiling application: orted --hnp --set-sid --report-uri 14 --singleton-died-pipe 15 -mca state_novm_select 1 -mca ess hnp -mca pmix ^s1,s2,cray,isolated
==19444== Profiling result:
No kernels were profiled.
所以总而言之,我知道编译器可以理解编译指示,但没有段发送到 GPU。非常感谢任何有关如何进一步调试的提示。
此致
塞巴斯蒂安