| ! Test that OpenMP privatization of CUDA Fortran allocatable device arrays: | |
| ! 1. Allocates the descriptor in managed memory (cuf.alloc) so CUF kernels | |
| ! can access it from the GPU. | |
| ! 2. Sets allocator_idx = 2 on the null descriptor so that allocate() uses | |
| ! cudaMalloc. | |
| ! 3. Frees the managed descriptor in the dealloc region (cuf.free). | |
| ! RUN: bbc -emit-hlfir -fcuda -fopenmp %s -o - | FileCheck %s | |
| subroutine omp_private_device_allocatable() | |
| implicit none | |
| real(8), device, allocatable :: adev(:) | |
| !$omp parallel private(adev) | |
| allocate(adev(10)) | |
| adev(1) = 1.0d0 | |
| deallocate(adev) | |
| !$omp end parallel | |
| end subroutine | |
| ! CHECK-LABEL: omp.private {type = private} | |
| ! CHECK-SAME: @{{.*}} : !fir.box<!fir.heap<!fir.array<?xf64>>> init { | |
| ! Descriptor must be allocated in managed memory for GPU accessibility. | |
| ! CHECK: cuf.alloc !fir.box<!fir.heap<!fir.array<?xf64>>> {data_attr = #cuf.cuda<device>} | |
| ! Null descriptor must carry allocator_idx = 2. | |
| ! CHECK: fir.embox %{{.*}}(%{{.*}}) {allocator_idx = 2 : i32} | |
| ! CHECK: fir.store | |
| ! CHECK: } dealloc { | |
| ! Managed descriptor must be freed. | |
| ! CHECK: cuf.free %{{.*}} : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf64>>>> {data_attr = #cuf.cuda<device>} | |
| ! CHECK: } | |
| ! CHECK-LABEL: func.func |