-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_hybrid.f90
64 lines (47 loc) · 1.49 KB
/
main_hybrid.f90
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
60
61
62
63
64
program main_hybrid
use m_base, only: basetype
use m_memblock, only: memblock
use m_cpu, only: cputype
use m_memblock_cpu, only: cpublock
use m_gpu, only: gputype
use m_memblock_gpu, only: gpublock
class(basetype), allocatable :: obj
class(memblock), pointer :: blk
type(cpublock), target :: cpublk
type(gpublock), target :: gpublk
select case(get_target_from_cli())
case('cpu')
cpublk = cpublock(16); blk => cpublk
allocate(cputype :: obj)
obj = cputype() ! This should automatically trigger
! allocation of obj. It does for gfortran (9.4), but not for
! nvfortran (22.5), which segfaults. Therefore obj is manually
! allocated. This might be a problem since allocation must know
! the dynamic type of obj.
write(*,*) "Executing CPU code only."
case('gpu')
gpublk = gpublock(16); blk => gpublk
allocate(gputype :: obj)
obj = gputype()
write(*,*) "Executing CUDA kernels."
case default
write(*,*) "main: unknown execution target"
error stop
end select
write(*,*) obj%doit(blk)
contains
character(3) function get_target_from_cli() result(tgt)
integer :: length, status
character(100) :: arg
call get_command_argument(1, arg, length, status)
if (status > 0) then
tgt = 'cpu'
return
end if
if (arg /= '--gpu') then
write(*,*) "ERROR: Unknown option", arg
error stop
end if
tgt = 'gpu'
end function get_target_from_cli
end program main_hybrid