如何使用 openmp 目标映射数据以在函数中使用



我想知道如何映射数据以供将来在函数中使用?

我写了一些代码,如下所示:

struct {
    int* a;
    int *b;
    // other members...
} s;
void func1(struct s* _s){
    int a* = _s->a;
    int b* = _s->b;
    // do something with _s
    #pragma omp target
    {
        // do something with a and b;
    }
}
int main(){
    struct s* _s;
    // alloc _s, a and b
    int *a = _s->a;
    int *b = _s->b;
    #pragma omp target data map(to: a, b)
    {
        func1(_s);
        // call another funcs with device use of mapped data...
    }
    // free data
}

代码可以编译,但在执行时Kernel execution error at <address>会从执行的详细输出中发送垃圾邮件,然后是许多Device kernel launch failed!CUDA error is: an illegal memory access was encountered

map 指令看起来可能是将指针的值映射到设备,而不是它们指向的数组ab。我认为您希望调整它们,以便运行时映射数据而不仅仅是指针。就个人而言,我也会将 map 子句放在您的目标区域,因为这为编译器提供了更多信息,并且当前的检查将从外部数据区域查找设备上已有的数据,而不会执行任何进一步的数据移动。

最新更新