OpenMP GPU卸载数学库? [英] OpenMP GPU offloading math library?

查看:310
本文介绍了OpenMP GPU卸载数学库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用OpenMP 4+指令卸载GPU代码.我在GCC 7.2中使用ubuntu 16.04,对于一般情况,它工作正常.当我尝试卸载对在"math.h"中定义的 sqrtf 函数具有调用的代码时,就会出现我的问题.麻烦的代码是这样的:

I am trying to offload code the GPU using OpenMP 4+ directives. I am using ubuntu 16.04 with GCC 7.2 and for general cases it is working fine. My problem comes when I am trying to offload a code that has a call to the sqrtf function that is defined in "math.h". The troubeling code is this:

#pragma omp target teams distribute \
map(to:posx[:n],posy[:n],posz[:n]) \
map(from:frcx[:n],frcy[:n],frcz[:n])
for (int i = 0; i < n; i++) {
  frcx[i] = 0.0f;
  frcy[i] = 0.0f;
  frcz[i] = 0.0f;

  for (int j = 0; j < n; j++) {
    float dx = posx[j] - posx[i];
    float dy = posy[j] - posy[i];
    float dz = posz[j] - posz[i];
    float distSqr = dx*dx + dy*dy + dz*dz + SOFTENING;
    float invDist = 1.0f / sqrtf(distSqr);
    float invDist3 = invDist * invDist * invDist;

    frcx[i] += dx * invDist3;
    frcy[i] += dy * invDist3;
    frcz[i] += dz * invDist3;
  }
}

当我尝试使用以下命令进行编译时:

When I try to compile it with:

$ gcc -Wall -O2 -march=native -mtune=native -fopenmp -o nbody_cpu_arrays_parallel_gpu common_funcs.c nbody_cpu_arrays_parallel_gpu.c -lm
unresolved symbol sqrtf
collect2: error: ld returned 1 exit status
mkoffload: fatal error: x86_64-linux-gnu-accel-nvptx-none-gcc-7 returned 1 exit status
compilation terminated.
lto-wrapper: fatal error: /usr/lib/gcc/x86_64-linux-gnu/7//accel/nvptx-none/mkoffload returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status

将OMP代码卸载到GPU时,如何利用平方根运算(或其他数学函数)?

How can I make use of square root operations (or other mathematical functions) when offloading OMP code to GPUs?

推荐答案

我遇到了类似的问题. https://github.com/bisqwit/cpp_parallelization_examples/blob/master/README. md 非常有帮助地描述了解决方案:

I encountered a similar issue. https://github.com/bisqwit/cpp_parallelization_examples/blob/master/README.md very helpfully describes the solution:

卸载时,如果出现以下情况,您可能会从数学函数中遇到链接器问题: 您进行了优化的构建.要解决,请添加-foffload = -lm -fno-fast-math -fno-associative-math

When offloading, you may get linker problems from math functions if you do an optimized build. To resolve, add -foffload=-lm -fno-fast-math -fno-associative-math

作为参考,我在sqrt中遇到的错误:

For reference, the errors I got with sqrt:

libgomp: Link error log ptxas application ptx input, line 138; error   : Label expected for argument 0 of instruction 'call'
ptxas application ptx input, line 138; fatal   : Call target not recognized
ptxas <macro util>, line 9; error   : Illegal modifier '.div' for instruction 'mov'
ptxas fatal   : Ptx assembly aborted due to errors


libgomp: cuLinkAddData (ptx_code) error: a PTX JIT compilation failed

libgomp: Cannot map target functions or variables (expected 2, have 4294967295)

使用sqrtf:

unresolved symbol sqrtf
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: gcc/x86_64-pc-linux-gnu/7.3.0//accel/nvptx-none/mkoffload returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed

这篇关于OpenMP GPU卸载数学库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆