Compilation error: Unknown variable reference

Why does the following code…

#include <iostream>

void intfun(int * pointer, int value){
    #pragma acc parallel deviceptr(pointer) present(value) num_gangs(1) num_workers(1)
        *pointer = value;
}

int main(){
    int *variable_ptr;
    int variable_value = 5;

    #pragma acc enter data create(variable_ptr) copyin(variable_value)
        #pragma acc host_data use_device(variable_ptr)
        {
                intfun(variable_ptr,variable_value);
        }
    #pragma acc exit data copyout(variable_ptr) delete(variable_value)

    std::cout << *variable_ptr << std::endl;
}

… return the following error upon compilation?

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

I’m running pgcpp 14.9 with Cuda 6.5.

Hi LO_UZH,

While not a typical use case, your code should compile. Hence, I wrote up a report (TPR#20869) and sent it on to engineer for further investigation.

The work around is tread pointer as and array by changing “*pointer” to “pointer[0]”.

Note that since “value” is being passed by value, it is a local copy of the variable. Hence, the present clause will fail to find the variable on the device. Instead, you would need to pass “value” in by reference so it’s the same variable. Granted since “value” is just a read-only scalar, it’s unnecessary to manually copy it over to the device.

Thanks,
Mat

% cat test.cpp
#include <iostream>

 void intfun(int * pointer, int value){
     #pragma acc parallel deviceptr(pointer) num_gangs(1) num_workers(1)
     {
#ifdef WORKS
         pointer[0] = value;
#else
         *pointer = value;
#endif
     }
 }

 int main(){
     int *variable_ptr;
     int variable_value = 5;

     #pragma acc enter data create(variable_ptr) copyin(variable_value)
         #pragma acc host_data use_device(variable_ptr)
         {
                 intfun(variable_ptr,variable_value);
         }
     #pragma acc exit data copyout(variable_ptr) delete(variable_value)

     std::cout << *variable_ptr << std::endl;
 }
% pgcpp -acc -Minfo=accel test.cpp -DWORKS; a.out
intfun(int *, int):
      5, Accelerator kernel generated
         Generating Tesla code
main:
     20, Generating enter data copyin(variable_value)
         Accelerator clause: upper bound for dimension 0 of array 'variable_ptr' is unknown
         Generating enter data create(variable_ptr[:1])
     25, Generating exit data delete(variable_value)
         Accelerator clause: upper bound for dimension 0 of array 'variable_ptr' is unknown
         Generating exit data copyout(variable_ptr[:1])
5