-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathallocatableArraySimple_with_bindings.f90
More file actions
59 lines (48 loc) · 1.95 KB
/
Copy pathallocatableArraySimple_with_bindings.f90
File metadata and controls
59 lines (48 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
! REQUIRES: fortran
! RUN: if [[ %fc != ifx ]]; then %fc -flto -O0 -c %loadFortran %s -o /dev/stdout | %opt %loadEnzyme %enzyme -o /dev/stdout | %opt %oflags -O0 -S -o %t.ll && %fc -flto -O0 %t.ll -o %t1 && %t1 | FileCheck %s; fi
! RUN: %fc -flto -O1 -c %loadFortran %s -o /dev/stdout | %opt %loadEnzyme %enzyme -o /dev/stdout | %opt %oflags -O1 -S -o %t.ll && %fc -flto -O1 %t.ll -o %t1 && %t1 | FileCheck %s
! RUN: %fc -flto -O2 -c %loadFortran %s -o /dev/stdout | %opt %loadEnzyme %enzyme -o /dev/stdout | %opt %oflags -O2 -S -o %t.ll && %fc -flto -O2 %t.ll -o %t1 && %t1 | FileCheck %s
! RUN: %fc -flto -O3 -c %loadFortran %s -o /dev/stdout | %opt %loadEnzyme %enzyme -o /dev/stdout | %opt %oflags -O3 -S -o %t.ll && %fc -flto -O3 %t.ll -o %t1 && %t1 | FileCheck %s
! NOTE: This test is only configured to run with the flang compiler at -O0
! For it to work with the ifx compiler we will need to figure out how to
! handle the indirection involved in the enzyme_autodiff binding
module AD
implicit none
contains
! TODO: Switch to assumed shape implementation once
! https://github.com/EnzymeAD/Enzyme/issues/2820
! has been addressed
subroutine selectFirst(n, x, y)
integer, intent(in) :: n
real, intent(in) :: x(n)
real, intent(inout) :: y
y = x(1)
end subroutine
end module
program app
use AD, only: selectFirst
use enzyme, only: enzyme_const, enzyme_dup, enzyme_autodiff
implicit none
integer :: n
real, allocatable :: x(:), dx(:)
real :: y, dy
n = 3
allocate(x(n))
allocate(dx(n))
x = [2,3,4]
dx = [0,0,0]
y = 0
dy = 1
call enzyme_autodiff(selectFirst, enzyme_const, n, &
enzyme_dup, x, dx, enzyme_dup, y, dy)
print *, int(y)
print *, int(dx(1))
print *, int(dx(2))
print *, int(dx(3))
print *, int(dy)
end program
! CHECK: 2
! CHECK-NEXT: 1
! CHECK-NEXT: 0
! CHECK-NEXT: 0
! CHECK-NEXT: 0