lone "omp target exit data" produces runtime error

Hi,

The following program produces an OpenMP runtime error. LIBOMPTARGET_DEBUG=1 reveals that the problem is that the device is uninitialized. Is this behavior specified by OpenMP?


int main() {
int x;
#pragma omp target exit data map(from:x)
return 0;

}

I’m not sure how it’s useful to have an “omp target exit data” before any other offloading code. I’ve only run into this when writing toy test programs, and my solution has been to add an empty target region before it. Also, in the call today I mentioned I’d like to encapsulate more code into CheckDeviceAndCtors. It looks like __tgt_target_data_end_mapper could benefit from that encapsulation except it doesn’t currently call CheckDeviceAndCtors. If it did call it, the above program would succeed.

Thanks.

Joel

We should add CheckDeviceAndCtors to target_data_end_mapper so the device can configured. There may be other target constructs which follow this and they should work. If the exit data construct is encounter 1st it should become a no-op. At the least we should print a meaningful message.

Thanks

Ravi

Hi,

You’re right, CheckDeviceAndCtors should be called from __tgt_target_data_end_mapper as well, just like any other _tgt* function. The reason it’s currently missing is that it was assumed (as you said) that an orphan “target exit data” directive would make no sense, in other words the device would have been initialized by some other _tgt* function already. However, since the example you provided seems to be a valid OpenMP program, then we should add code to initialize the device even in __tgt_target_data_end_mapper.

George

Thanks, Ravi, Georgios. I’ll work on that.

Joel