-2

为什么下面的代码不允许我var通过10函数设置intfun

#include <iostream>

void intfun(int * variable){
    #pragma acc parallel deviceptr(variable) num_gangs(1) num_workers(1)
    {
        *variable = 10;
    }
}

int main(){
    int var;

    #pragma acc enter data create(var)
    #pragma acc host_data use_device(var)
    {
        intfun(&var);
    }
    #pragma acc exit data copyout(var)

    std::cout << var << std::endl;
}

汇编:

pgcpp -acc main.cpp

执行:

PGCC-S-0155-Compiler failed to translate accelerator region (see -Minfo messages): Unknown variable reference (main.cpp: 5)
PGCC/x86 Linux 14.9-0: compilation completed with severe errors

如何在设备上intfun设置参数值int var

4

1 回答 1

2

您没有为编译器提供足够的信息来确定 within 的使用*variable范围intfun

以下似乎工作正常:

$ cat main7.cpp
#include <iostream>

void intfun(int * variable){
    #pragma acc parallel copy(variable[:1])
    {
        *variable = 10;
    }
}

int main(){
    int var;

        intfun(&var);

    std::cout << var << std::endl;
}
$ pgcpp -acc -Minfo main7.cpp
intfun(int *):
      5, Generating copy(variable[:1])
         Accelerator kernel generated
         Generating Tesla code
$ ./a.out
10
$

对于这个特定的例子,我有copy(variable[:1]),copyout(variable[:1])也可以工作。

于 2014-09-22T22:17:39.543 回答