OpenMP 4.5不会使用目标指令卸载到GPU [英] OpenMP 4.5 won't offload to GPU with target directive

查看:517
本文介绍了OpenMP 4.5不会使用目标指令卸载到GPU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用openMP创建一个简单的GPU卸载程序.但是,当我尝试卸载时,它仍在默认设备(即我的CPU)上运行.

I am trying to make a simple GPU offloading program using openMP. However, when I try to offload it still runs on the default device, i.e. my CPU.

我已经安装了具有CUDA支持的g ++ 7.2.0编译器(位于我使用的群集中).当我运行下面的代码时,它表明可以看到8个GPU,但是当我尝试卸载时,它说它仍在CPU上.

I have installed a compiler, g++ 7.2.0 that has CUDA support (is in on a cluster that I use). When I run the below code it shows me that it can see the 8 GPUs but when I try to offload it says that it is still on the CPU.

#include <omp.h>
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm> 
#define n 10000
#define m 10000

using namespace std;

int main()
{

    double tol = 1E-10;
    double err = 1;
    size_t iter_max = 10;
    size_t iter = 0;
    bool notGPU[1] = {true};

    double Anew[n][m];
    double A[n][m];

   int target[1];
   target[0] = omp_get_initial_device();
   cout << "Total Devices: " << omp_get_num_devices() << endl;
   cout << "Target: " << target[0] << endl;


    for (int iter = 0; iter < iter_max; iter++){
        #pragma omp target 
        {
        err = 0.0;
        #pragma omp parallel for reduction(max:err)
        for (int j = 1; j < n-1; ++j){
            target[0] = omp_is_initial_device();
            for (int i = 1; i < m-1; i++){
                Anew[j][i] = 0.25 * (A[j][i+1] + A[j][i-1] + A[j-1][i] + A[j+1][i]);
                err = fmax(err, fabs(Anew[j][i] - A[j][i]));
            }

        }
        }

    }
    if (target[0]){
       cout << "not on GPU" << endl;
} else{
    cout << "On GPU" << endl;}



    return 0;
}

运行此命令时,我总会发现它不在GPU上,但是有8种设备可用.

When I run this I always get that it is not on the GPU, but that there are 8 devices available.

推荐答案

这不是一个有据可查的过程!

This is not a well documented process!

您必须安装一些看起来像这样的软件包:

You have to install some packages which look a little like:

sudo apt install gcc-offload-nvptx

您还需要在编译字符串中添加其他标志.我在下面一起讨论了其中的一些内容.混合并匹配,直到有效果为止,或者将其用作进一步谷歌搜索的基础.

You also need to add additional flags to your compilation string. I've globbed together a number of them below. Mix and match until something works, or use them as the basis for further Googling.

gcc -fopenmp -foffload=x86_64-intelmicemul-linux-gnu="-mavx2" -foffload=nvptx-none -foffload="-O3" -O2 test.c -fopenmp-targets=nvptx64-nvidia-cuda

当我上一次在2018年与GCC尝试时,它只是没有用.那时,OpenMP的目标卸载仅与 IBM一起使用XL 编译器和OpenACC(与OpenMP相似的一组指令)仅适用于Nvidia的 PGI编译器.我发现PGI在编译C/C ++方面比在其他方面做得要差(似乎效率低下,非标准标志),但是Community Edition是免费提供的,只需稍加翻译即可让您快速在OpenACC中运行.

When I last tried this with GCC in 2018 it just didn't work. At that time target offloading for OpenMP only worked with the IBM XL compiler and OpenACC (a similar set of directives to OpenMP) only worked on the Nvidia's PGI compiler. I find PGI to do a worse job of compiling C/C++ than the others (seems inefficient, non-standard flags), but a Community Edition is available for free and a little translating will get you running in OpenACC quickly.

IBM XL似乎做得很好,但是我不知道它是否免费提供.

IBM XL seems to do a fine job compiling, but I don't know if it's available for free.

GCC的情况可能已经改变.如果您找到使它正常运行的方法,不胜感激,请在此处发表评论.我的强烈建议是,您不要再尝试使用GCC7,而是使用GCC8或GCC9. GPU卸载是一个快速发展的领域,您将希望最新的编译器能够最大程度地利用它.

The situation may have changed with GCC. If you find a way to get it working, I'd appreciate you leaving a comment here. My strong recommendation is that you stop trying with GCC7 and get ahold of GCC8 or GCC9. GPU offloading is a fast-moving area and you'll want the latest compilers to take best advantage of it.

这篇关于OpenMP 4.5不会使用目标指令卸载到GPU的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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