|
| 1 | +! Offloading test checking lowering of arrays with dynamic extents. |
| 2 | +! REQUIRES: flang, amdgpu |
| 3 | + |
| 4 | +! RUN: %libomptarget-compile-fortran-run-and-check-generic |
| 5 | + |
| 6 | +program test_openmp_mapper |
| 7 | + implicit none |
| 8 | + integer, parameter :: n = 1024 |
| 9 | + type :: mytype |
| 10 | + integer :: data(n) |
| 11 | + end type mytype |
| 12 | + |
| 13 | + type :: mytype2 |
| 14 | + type(mytype) :: my_data |
| 15 | + end type mytype2 |
| 16 | + |
| 17 | + ! Declare custom mappers for the derived type `mytype` |
| 18 | + !$omp declare mapper(my_mapper1 : mytype :: t) map(to: t%data(1 : n)) |
| 19 | + |
| 20 | + ! Declare custom mappers for the derived type `mytype2` |
| 21 | + !$omp declare mapper(my_mapper2 : mytype2 :: t) map(mapper(my_mapper1): t%my_data) |
| 22 | + |
| 23 | + type(mytype2) :: obj |
| 24 | + integer :: i, sum_host, sum_device |
| 25 | + |
| 26 | + ! Initialize the host data |
| 27 | + do i = 1, n |
| 28 | + obj%my_data%data(i) = 1 |
| 29 | + end do |
| 30 | + |
| 31 | + ! Compute the sum on the host for verification |
| 32 | + sum_host = sum(obj%my_data%data) |
| 33 | + |
| 34 | + ! Offload computation to the device using the named mapper `my_mapper2` |
| 35 | + sum_device = 0 |
| 36 | + !$omp target map(tofrom: sum_device) map(mapper(my_mapper2) : obj) |
| 37 | + do i = 1, n |
| 38 | + sum_device = sum_device + obj%my_data%data(i) |
| 39 | + end do |
| 40 | + !$omp end target |
| 41 | + |
| 42 | + ! Check results |
| 43 | + print *, "Sum on host: ", sum_host |
| 44 | + print *, "Sum on device: ", sum_device |
| 45 | + |
| 46 | + if (sum_device == sum_host) then |
| 47 | + print *, "Test passed!" |
| 48 | + else |
| 49 | + print *, "Test failed!" |
| 50 | + end if |
| 51 | + end program test_openmp_mapper |
| 52 | + |
| 53 | +! CHECK: Test passed! |
0 commit comments