Skip to content

Commit 0eb8140

Browse files
authored
Merge pull request #250 from bonachea/prif_alias_create_0.6
Implement new `prif_alias_create(data_pointer_offset)` argument for PRIF 0.6
2 parents 72f1a9b + d736837 commit 0eb8140

File tree

4 files changed

+58
-7
lines changed

4 files changed

+58
-7
lines changed

docs/implementation-status.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ are accepted, but in some cases, the associated runtime behavior is not fully im
7171
| `prif_allocate` | **YES** | |
7272
| `prif_deallocate_coarray` | *partial* | no `final_func` arg support |
7373
| `prif_deallocate` | **YES** | |
74-
| `prif_alias_create` | **YES** | |
74+
| `prif_alias_create` | **YES** | includes `data_pointer_offset` argument expected in PRIF 0.6 |
7575
| `prif_alias_destroy` | **YES** | |
7676

7777
---

src/caffeine/alias_s.F90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
! start with a copy of the source descriptor
2121
alias_handle%info = source_handle%info
2222

23+
# if !FORCE_PRIF_0_5
24+
alias_handle%info%coarray_data = &
25+
as_c_ptr(as_int(alias_handle%info%coarray_data) + data_pointer_offset)
26+
# endif
27+
2328
! apply provided cobounds
2429
alias_handle%info%corank = size(alias_lcobounds)
2530
alias_handle%info%lcobounds(1:size(alias_lcobounds)) = alias_lcobounds

src/prif.F90

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,18 @@ module subroutine prif_put_strided_indirect_with_notify_indirect( &
436436
character(len=:), intent(inout), allocatable, optional :: errmsg_alloc
437437
end subroutine
438438

439-
module subroutine prif_alias_create(source_handle, alias_lcobounds, alias_ucobounds, alias_handle)
439+
module subroutine prif_alias_create(source_handle, alias_lcobounds, alias_ucobounds, &
440+
# if !FORCE_PRIF_0_5
441+
data_pointer_offset, &
442+
# endif
443+
alias_handle)
440444
implicit none
441445
type(prif_coarray_handle), intent(in) :: source_handle
442446
integer(c_int64_t), intent(in) :: alias_lcobounds(:)
443447
integer(c_int64_t), intent(in) :: alias_ucobounds(:)
448+
# if !FORCE_PRIF_0_5
449+
integer(c_size_t), intent(in) :: data_pointer_offset
450+
# endif
444451
type(prif_coarray_handle), intent(out) :: alias_handle
445452
end subroutine
446453

test/prif_allocate_test.F90

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module caf_allocate_test
88
use veggies, only: result_t, test_item_t, assert_that, assert_equals, describe, it, succeed
99
use iso_c_binding, only: &
1010
c_ptr, c_int, c_int64_t, c_size_t, c_funptr, c_null_funptr, &
11-
c_f_pointer, c_null_ptr, c_loc, c_sizeof, c_associated
11+
c_f_pointer, c_null_ptr, c_loc, c_sizeof, c_associated, c_intptr_t
1212

1313
implicit none
1414
private
@@ -97,9 +97,23 @@ function check_allocate_non_symmetric() result(result_)
9797
call prif_deallocate(c_loc(local_slice))
9898
end function
9999

100-
function assert_aliased(h1, h2) result(result_)
100+
! returns (p + off)
101+
pure function c_ptr_add(p, off)
102+
type(c_ptr), intent(in) :: p
103+
integer(c_size_t), intent(in) :: off
104+
type(c_ptr) :: c_ptr_add
105+
integer(c_intptr_t) :: tmp
106+
107+
tmp = transfer(p, tmp)
108+
tmp = tmp + off
109+
c_ptr_add = transfer(tmp, c_ptr_add)
110+
end function
111+
112+
function assert_aliased(h1, h2, offset) result(result_)
101113
type(result_t) :: result_
102114
type(prif_coarray_handle) :: h1, h2
115+
integer(c_size_t), optional :: offset
116+
integer(c_size_t) :: offset_
103117
type(c_ptr) :: p1, p2
104118
integer(c_size_t) :: s1, s2
105119
type(c_ptr) :: c1, c2, cx
@@ -108,11 +122,19 @@ function assert_aliased(h1, h2) result(result_)
108122

109123
result_ = succeed("")
110124

125+
if (present(offset)) then
126+
offset_ = offset
127+
else
128+
offset_ = 0
129+
endif
130+
111131
call prif_local_data_pointer(h1, p1)
112132
call prif_local_data_pointer(h2, p2)
113133
result_ = result_ .and. &
114-
assert_that(c_associated(p1, p2))
134+
assert_that(c_associated(c_ptr_add(p1, offset_), p2))
115135

136+
! As of PRIF 0.6. prif_size_bytes is unspecified for aliases,
137+
! so this particular check is specific to the current Caffeine implementation
116138
call prif_size_bytes(h1, s1)
117139
call prif_size_bytes(h2, s2)
118140
result_ = result_ .and. &
@@ -190,6 +212,11 @@ function check_allocate_integer_array_coarray_with_corank2() result(result_)
190212
end block
191213

192214
block ! check aliasing creation
215+
# if FORCE_PRIF_0_5
216+
# define data_pointer_offset
217+
# else
218+
# define data_pointer_offset 0_c_size_t,
219+
# endif
193220
integer i, j
194221
integer, parameter :: lim = 10
195222
type(prif_coarray_handle) :: a(lim)
@@ -198,18 +225,30 @@ function check_allocate_integer_array_coarray_with_corank2() result(result_)
198225
do i=2, lim
199226
lco(1) = i
200227
uco(1) = i + num_imgs
201-
call prif_alias_create(a(i-1), lco, uco, a(i))
228+
call prif_alias_create(a(i-1), lco, uco, data_pointer_offset a(i))
202229
result_ = result_ .and. &
203230
assert_aliased(a(i-1), a(i))
204231
do j = i+1,lim
205232
lco(1) = j
206233
uco(1) = j + num_imgs
207-
call prif_alias_create(a(i), lco, uco, a(j))
234+
call prif_alias_create(a(i), lco, uco, data_pointer_offset a(j))
208235
result_ = result_ .and. &
209236
assert_aliased(a(i), a(j))
210237
result_ = result_ .and. &
211238
assert_aliased(a(j), coarray_handle)
212239
end do
240+
# if !FORCE_PRIF_0_5
241+
! test PRIF 0.6 data_pointer_offset
242+
block
243+
type(prif_coarray_handle) :: b
244+
integer(c_size_t) :: off
245+
off = i
246+
call prif_alias_create(a(i), lco, uco, off, b)
247+
result_ = result_ .and. &
248+
assert_aliased(a(i), b, off)
249+
call prif_alias_destroy(b)
250+
end block
251+
# endif
213252
do j = i+1,lim
214253
call prif_alias_destroy(a(j))
215254
end do

0 commit comments

Comments
 (0)