0

I would like to know how can I map a data for future use inside of a function?

I wrote some code like the following:

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
}

The code compiles, but on execution Kernel execution error at <address> is spammed from verbose output of execution, followed by many Device kernel launch failed! and CUDA error is: an illegal memory access was encountered

4

1 回答 1

3

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

于 2017-05-18T18:03:26.333 回答