我正在try 使用OpenMP卸载为NVIDIA图形处理器编译一个简单的测试问题.我使用的是带有NVPTX-NONE目标的GCC.我已经用Spack安装了GCC+nvptx包(或者我自己用nvptx-Tools编译了GCC-13,结果是一样的). 在链接过程中,我收到以下错误:
unresolved symbol _fputwc_r
collect2: error: ld returned 1 exit status
mkoffload: fatal error: x86_64-pc-linux-gnu-accel-nvptx-none-gcc returned 1 exit status
compilation terminated.
lto-wrapper: fatal error: /path/to/spack/opt/spack/linux-centos8-x86_64_v3/gcc-13.0.0/gcc-12.2.0-6olbpwbs53cquwnpsvrmuxprmaofwjtk/libexec/gcc/x86_64-pc-linux-gnu/12.2.0//accel/nvptx-none/mkoffload returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
按照建议使用-fno-stack-protector
编译,例如here或
here,并没有缓解这个问题.-fno-lto
可以,但然后卸载就不起作用了.不同的优化标志没有区别.
所使用的ld
似乎就是系统安装.Spack安装在spack/linux-centos8-x86_64_v3/gcc-13.0.0/gcc-12.2.0-6olbpwbs53cquwnpsvrmuxprmaofwjtk/nvptx-none
中提供了另一个id,但Spack通常不会将其添加到路径中.我想有很好的理由,因为把它包括在内会导致
as: unrecognized option '--64'
nvptx-as: missing .version directive at start of file '/tmp/cc9YfveM.s'``
这是链接器的问题,还是其他问题?该问题仅在实际包括并行for循环时发生,仅设置#pragma omp target
就不会.设备实际上是可识别的,只要不存在并行区域,此杂注中的代码就会根据OpenMP在设备上运行,这将产生上述错误.
补充资料:
系统是Rocky Linux release 8.7 (Green Obsidian)
我正在执行的测试程序基于OpenMP测试程序.它的完整代码是:
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
void saxpy(float a, float* x, float* y, int sz) {
#pragma omp target teams distribute parallel for simd \
num_teams(3) map(to:x[0:sz]) map(tofrom:y[0:sz])
for (int i = 0; i < sz; i++) {
if (omp_is_initial_device()) {
printf("Running on host\n");
} else {
int nthreads= omp_get_num_threads();
int nteams= omp_get_num_teams();
printf("Running on device with %d teams (fixed) in total and %d threads in each team\n",nteams,nthreads);
}
fprintf(stdout, "Thread %d %i\n", omp_get_thread_num(), i );
y[i] = a * x[i] + y[i];
}
}
int main(int argc, char** argv) {
float a = 2.0;
int sz = 16;
float *x = calloc( sz, sizeof *x );
float *y = calloc( sz, sizeof *y );
//Set values
int num_devices = omp_get_num_devices();
printf("Number of available devices %d\n", num_devices);
saxpy( a, x, y, sz );
return 0;
}
我试着用以下命令编译它
gcc -O0 -fopenmp -foffload=nvptx-none -o mintest mintest.c
或上面提到的旗帜.