Octopus
allocate_hardware_aware_f.F90
Go to the documentation of this file.
1!! Copyright (C) 2019 S. Ohlmann
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
21! -----------------------------------------------------------------------
23! -----------------------------------------------------------------------
25 use accel_oct_m
26 use global_oct_m
27 use iso_c_binding
28 use, intrinsic :: iso_fortran_env
30
31 implicit none
32
33 private
34
35 public :: &
41
42 interface
43
44 function dallocate_aligned(size) bind(c)
45 import :: c_ptr, int64
46 integer(int64), value :: size
47 type(c_ptr) :: dallocate_aligned
48 end function dallocate_aligned
49 end interface
50
51 interface
52
53 function zallocate_aligned(size) bind(c)
54 import :: c_ptr, int64
55 integer(int64), value :: size
56 type(c_ptr) :: zallocate_aligned
57 end function zallocate_aligned
58 end interface
59
60 interface
61
62 function sallocate_aligned(size) bind(c)
63 import :: c_ptr, int64
64 integer(int64), value :: size
65 type(c_ptr) :: sallocate_aligned
66 end function sallocate_aligned
67 end interface
68
69 interface
70
71 function callocate_aligned(size) bind(c)
72 import :: c_ptr, int64
73 integer(int64), value :: size
74 type(c_ptr) :: callocate_aligned
75 end function callocate_aligned
76 end interface
77
78 interface
79
80 subroutine deallocate_aligned(array) bind(c)
81 import :: c_ptr
82 type(c_ptr), value :: array
83 end subroutine deallocate_aligned
84 end interface
85
86 interface
87
88 function dallocate_pinned(size) bind(c)
89 import :: c_ptr, int64
90 integer(int64), value :: size
91 type(c_ptr) :: dallocate_pinned
92 end function dallocate_pinned
93 end interface
94
95 interface
96
97 function zallocate_pinned(size) bind(c)
98 import :: c_ptr, int64
99 integer(int64), value :: size
100 type(c_ptr) :: zallocate_pinned
101 end function zallocate_pinned
102 end interface
103
104 interface
105
106 function sallocate_pinned(size) bind(c)
107 import :: c_ptr, int64
108 integer(int64), value :: size
109 type(c_ptr) :: sallocate_pinned
110 end function sallocate_pinned
111 end interface
112
113 interface
114
115 function callocate_pinned(size) bind(c)
116 import :: c_ptr, int64
117 integer(int64), value :: size
118 type(c_ptr) :: callocate_pinned
119 end function callocate_pinned
120 end interface
121
122 interface
123
124 subroutine deallocate_pinned(array) bind(c)
125 import :: c_ptr
126 type(c_ptr), value :: array
127 end subroutine deallocate_pinned
128 end interface
129
130contains
131
132 function zallocate_hardware_aware(size)
133 integer(int64) :: size
134 type(c_ptr) :: zallocate_hardware_aware
135
136 ! allocate pinned memory for GPU runs, otherwise aligned memory
138 zallocate_hardware_aware = zallocate_pinned(size)
139 else
140 zallocate_hardware_aware = zallocate_aligned(size)
141 end if
142
143 if (bitand(prof_vars%mode, profiling_memory) /= 0) then
144 call profiling_memory_allocate("batch", "allocate_hardware_aware_f.F90", 131, size*16)
145 end if
147
148 function dallocate_hardware_aware(size)
149 integer(int64) :: size
150 type(c_ptr) :: dallocate_hardware_aware
151
152 ! allocate pinned memory for GPU runs, otherwise aligned memory
153 if (accel_is_enabled()) then
155 else
157 end if
158
159 if (bitand(prof_vars%mode, profiling_memory) /= 0) then
160 call profiling_memory_allocate("batch", "allocate_hardware_aware_f.F90", 146, size*8)
161 end if
162 end function dallocate_hardware_aware
163
165 integer(int64) :: size
166 type(c_ptr) :: callocate_hardware_aware
167
168 ! allocate pinned memory for GPU runs, otherwise aligned memory
169 if (accel_is_enabled()) then
171 else
173 end if
174
175 if (bitand(prof_vars%mode, profiling_memory) /= 0) then
176 call profiling_memory_allocate("batch", "allocate_hardware_aware_f.F90", 161, size*8)
177 end if
178 end function callocate_hardware_aware
179
180 function sallocate_hardware_aware(size)
181 integer(int64) :: size
182 type(c_ptr) :: sallocate_hardware_aware
183
184 ! allocate pinned memory for GPU runs, otherwise aligned memory
185 if (accel_is_enabled()) then
187 else
189 end if
191 if (bitand(prof_vars%mode, profiling_memory) /= 0) then
192 call profiling_memory_allocate("batch", "allocate_hardware_aware_f.F90", 176, size*4)
193 end if
194 end function sallocate_hardware_aware
195
196 subroutine deallocate_hardware_aware(array, size)
197 type(c_ptr), value :: array
198 integer(int64) :: size
200 ! deallocate pinned memory for GPU runs, otherwise aligned memory
201 if (accel_is_enabled()) then
202 call deallocate_pinned(array)
203 else
204 call deallocate_aligned(array)
205 end if
206
207 if (bitand(prof_vars%mode, profiling_memory) /= 0) then
208 call profiling_memory_deallocate("batch", "allocate_hardware_aware_f.F90", 190, size)
209 end if
210 end subroutine deallocate_hardware_aware
211
213
214!! Local Variables:
215!! mode: f90
216!! coding: utf-8
217!! End:
allocate aligned memory for a dingle complex array
allocate pinned memory for a single complex array
allocate aligned memory for a double precision array
allocate pinned memory for a double precision array
allocate aligned memory for a single precision array
allocate pinned memory for a single precision array
allocate aligned memory for a double complex array
allocate pinned memory for a double complex array
pure logical function, public accel_is_enabled()
Definition: accel.F90:400
This module contains interfaces for routines in allocate_hardware_aware.c.
type(c_ptr) function, public callocate_hardware_aware(size)
subroutine, public deallocate_hardware_aware(array, size)
type(c_ptr) function, public zallocate_hardware_aware(size)
type(c_ptr) function, public dallocate_hardware_aware(size)
type(c_ptr) function, public sallocate_hardware_aware(size)
type(profile_vars_t), target, save, public prof_vars
Definition: profiling.F90:246
integer, parameter, public profiling_memory
Definition: profiling.F90:206
subroutine, public profiling_memory_deallocate(var, file, line, size)
Definition: profiling.F90:1392
subroutine, public profiling_memory_allocate(var, file, line, size_)
Definition: profiling.F90:1321