Octopus
alloc_cache.F90
Go to the documentation of this file.
1!! Copyright (C) 2019 X. Andrade
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the Lesser GNU General Public License as published by
5!! the Free Software Foundation; either version 3, 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#ifdef HAVE_OPENCL
24 use cl
25#endif
26 use global_oct_m
27 use iso_c_binding
28 use, intrinsic :: iso_fortran_env
29
30 implicit none
31
32 private
33
34 public :: &
40
41 type alloc_cache_t
42 private
43 integer(int64) :: dummy
44 end type alloc_cache_t
45
46 integer(int64), public, parameter :: &
47 ALLOC_CACHE_ANY_SIZE = -1_8
48
49 interface
50
51 subroutine alloc_cache_init(alloc_cache, max_size)
52 use, intrinsic :: iso_fortran_env
53 import :: alloc_cache_t
54 implicit none
55
56 type(alloc_cache_t), intent(out) :: alloc_cache
57 integer(int64), intent(in) :: max_size
58 end subroutine alloc_cache_init
59
60 ! -------------------------------------------------
61
62 subroutine alloc_cache_end(alloc_cache, hits, misses, vol_hits, vol_misses)
63 use iso_c_binding
64 use, intrinsic :: iso_fortran_env
65 import :: alloc_cache_t
66 implicit none
67
68 type(alloc_cache_t), intent(inout) :: alloc_cache
69 integer(int64), intent(out) :: hits
70 integer(int64), intent(out) :: misses
71 real(c_double), intent(out) :: vol_hits
72 real(c_double), intent(out) :: vol_misses
73 end subroutine alloc_cache_end
74
75 end interface
76
77contains
78
79 subroutine alloc_cache_put(alloc_cache, size, loc, put)
80 type(alloc_cache_t), intent(inout) :: alloc_cache
81 integer(int64), intent(in) :: size
82#ifdef HAVE_OPENCL
83 type(cl_mem), intent(in) :: loc
84#else
85 type(c_ptr), intent(in) :: loc
86#endif
87 logical, intent(out) :: put
88
89 interface
90 subroutine alloc_cache_put_low(alloc_cache, size, loc, put)
91#ifdef HAVE_OPENCL
92 use cl
93#endif
94 use iso_c_binding
95 use, intrinsic :: iso_fortran_env
96 import :: alloc_cache_t
97 implicit none
98
99 type(alloc_cache_t), intent(inout) :: alloc_cache
100 integer(int64), intent(in) :: size
101#ifdef HAVE_OPENCL
102 type(cl_mem), intent(in) :: loc
103#else
104 type(c_ptr), intent(in) :: loc
105#endif
106 integer, intent(out) :: put
107 end subroutine alloc_cache_put_low
108 end interface
109
110 integer :: iput
111
112 call alloc_cache_put_low(alloc_cache, size, loc, iput)
113
114 put = (iput /= 0)
116 end subroutine alloc_cache_put
117
118 ! -------------------------------------------------
119
120 subroutine alloc_cache_get(alloc_cache, size, found, loc)
121 type(alloc_cache_t), intent(inout) :: alloc_cache
122 integer(int64), intent(in) :: size
123 logical, intent(out) :: found
124#ifdef HAVE_OPENCL
125 type(cl_mem), intent(out) :: loc
126#else
127 type(c_ptr), intent(out) :: loc
128#endif
129
130 interface
131 subroutine alloc_cache_get_low(alloc_cache, size, found, loc)
132#ifdef HAVE_OPENCL
133 use cl
134#endif
135 use iso_c_binding
136 use, intrinsic :: iso_fortran_env
137 import :: alloc_cache_t
138 implicit none
140 type(alloc_cache_t), intent(inout) :: alloc_cache
141 integer(int64), intent(in) :: size
142 integer, intent(out) :: found
143#ifdef HAVE_OPENCL
144 type(cl_mem), intent(out) :: loc
145#else
146 type(c_ptr), intent(out) :: loc
147#endif
148 end subroutine alloc_cache_get_low
149 end interface
150
151 integer :: ifound
152
153 call alloc_cache_get_low(alloc_cache, size, ifound, loc)
154
155 found = (ifound /= 0)
156
157 end subroutine alloc_cache_get
158
159
160end module alloc_cache_oct_m
161
162!! Local Variables:
163!! mode: f90
164!! coding: utf-8
165!! End:
subroutine, public alloc_cache_put(alloc_cache, size, loc, put)
subroutine, public alloc_cache_get(alloc_cache, size, found, loc)