On Mon, 26 Oct 2015 19:34:22 +0100 Jakub Jelinek <ja...@redhat.com> wrote:
> Your use_device sounds very similar to use_device_ptr clause in > OpenMP, which is allowed on #pragma omp target data construct and is > implemented quite a bit differently from this; it is unclear if the > OpenACC standard requires this kind of implementation, or you just > chose to implement it this way. In particular, the GOMP_target_data > call puts the variables mentioned in the use_device_ptr clauses into > the mapping structures (similarly how map clause appears) and the > corresponding vars are privatized within the target data region > (which is a host region, basically a fancy { } braces), where the > private variables contain the offloading device's pointers. As the author of the original patch, I have to say using the mapping structures seems like a far better approach, but I've hit some trouble with the details of adapting OpenACC to use that method. Firstly, on trunk at least, use_device_ptr variables are restricted to pointer or array types: that restriction doesn't exist in OpenACC, nor actually could I find it in the OpenMP 4.1 document (my guess is the standards are supposed to match in this regard). I think that a program such as this should work: void target_fn (int *targ_data); int main (int argc, char *argv[]) { char out; int myvar; #pragma omp target enter data map(to: myvar) #pragma omp target data use_device_ptr(myvar) map(from:out) { target_fn (&myvar); out = 5; } return 0; } "myvar" would have its address taken in the use_device_ptr region, and places where the corresponding mapped variable has its address taken would be replaced by a direct use of the mapped pointer. (Or is that not a well-formed thing to do, in general?). This fails with "error: 'use_device_ptr' variable is neither a pointer nor an array". Secondly, attempts to use use_device_ptr on (e.g. dynamically-allocated) arrays accessed through a pointer cause an ICE with the existing trunk OpenMP code: #include <stdlib.h> void target_fn (char *targ_data); int main (int argc, char *argv[]) { char *myarr, out; myarr = malloc (1024); #pragma omp target data map(to: myarr[0:1024]) { #pragma omp target data use_device_ptr(myarr) map(from:out) { target_fn (myarr); out = 5; } } return 0; } udp3.c: In function 'main': udp3.c:6:1: internal compiler error: in make_decl_rtl, at varasm.c:1298 main (int argc, char *argv[]) ^ 0x111256b make_decl_rtl(tree_node*) /scratch/jbrown/openacc-trunk/src/gcc-mainline/gcc/varasm.c:1294 0x9ea005 expand_expr_real_1(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**, bool) /scratch/jbrown/openacc-trunk/src/gcc-mainline/gcc/expr.c:9559 0x9e31c2 expand_expr_real(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**, bool) /scratch/jbrown/openacc-trunk/src/gcc-mainline/gcc/expr.c:7892 0x9cb4ae expand_expr /scratch/jbrown/openacc-trunk/src/gcc-mainline/gcc/expr.h:255 0x9d907d expand_assignment(tree_node*, tree_node*, bool) /scratch/jbrown/openacc-trunk/src/gcc-mainline/gcc/expr.c:5089 0x89e219 expand_gimple_stmt_1 /scratch/jbrown/openacc-trunk/src/gcc-mainline/gcc/cfgexpand.c:3576 0x89e60d expand_gimple_stmt /scratch/jbrown/openacc-trunk/src/gcc-mainline/gcc/cfgexpand.c:3672 0x8a5773 expand_gimple_basic_block /scratch/jbrown/openacc-trunk/src/gcc-mainline/gcc/cfgexpand.c:5676 0x8a72d4 execute /scratch/jbrown/openacc-trunk/src/gcc-mainline/gcc/cfgexpand.c:6288 Furthermore, this looks strange to me (006t.omplower): .omp_data_arr.5.out = &out; myarr.8 = myarr; .omp_data_arr.5.myarr = myarr.8; #pragma omp target data map(from:out [len: 1]) use_device_ptr(myarr) { D.2436 = .omp_data_arr.5.myarr; myarr = D.2436; That's clobbering the original myarr variable, right? Any clues on these two? The omp-low.c code is rather opaque to me... Thanks, Julian