Octopus
hardware.F90
Go to the documentation of this file.
1!! Copyright (C) 2008 X. Andrade, 2024. A Buccheri.
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!!
18module hardware_oct_m
19
20 implicit none
21 private
22 public :: &
24 cache_t, &
27
29 type cache_t
30 integer :: size
31 integer :: line_size
32 end type cache_t
34 interface cache_t
35 module procedure cache_t_init
36 end interface cache_t
37
39 type hardware_t
40 type(cache_t) :: l1
41 type(cache_t) :: l2
42 integer :: dblock_size
43 integer :: zblock_size
44 integer :: sblock_size
45 integer :: cblock_size
46 contains
47 procedure :: init => hardware_init
48 end type hardware_t
50 ! Same as getting sizeof(a)
52 integer, public, parameter :: sizeof_real64 = 8
53
55 integer, public, parameter :: sizeof_complex64 = 16
58 integer, public, parameter :: sizeof_real32 = 4
61 integer, public, parameter :: sizeof_complex32 = 8
63 interface
64 subroutine oct_cache_info(level, size, line_size) bind(c)
65 use iso_c_binding, only: c_int
66 integer(c_int), value :: level
67 integer(c_int), intent(out) :: size
68 integer(c_int), intent(out) :: line_size
69 end subroutine oct_cache_info
70 end interface
71
73 type(hardware_t) :: cpu_hardware
74
76 type(cache_t), public :: default_l1
77 type(cache_t), public :: default_l2
78
79contains
82 function cache_t_init(data_size, line_size) result(cache)
83 type(cache_t) :: cache
84 integer, intent(in) :: data_size
85 integer, intent(in) :: line_size
87 cache%size = data_size
88 cache%line_size = line_size
89
90 end function cache_t_init
91
92
94 function cache_detect(level, default) result(cache)
95 integer, intent(in) :: level
96 type(cache_t), intent(in) :: default
97 type(cache_t) :: cache
99 integer :: data_size, line_size
100
101 call oct_cache_info(level, data_size, line_size)
102 cache = default
103 if (data_size > 0) cache%size = data_size
104 if (line_size > 0) cache%line_size = line_size
105
106 end function cache_detect
107
108
109 ! TODO(Alex) Issue 1013. Change hardware class to a free function, and make cache_t instance global.
117 subroutine hardware_init(this, l1_cache, l2_cache)
118 class(hardware_t), intent(inout) :: this
119 type(cache_t), intent(in) :: l1_cache
120 type(cache_t), intent(in) :: l2_cache
122 integer, parameter :: cpu_default_states_per_block = 4
123
124 this%l1 = l1_cache
125 this%l2 = l2_cache
126
127 this%dblock_size = this%l1%size / (cpu_default_states_per_block * sizeof_real64)
128 this%dblock_size = this%dblock_size - mod(this%dblock_size, this%l1%line_size) - 2*this%l1%line_size
129
130 this%zblock_size = this%l1%size / (cpu_default_states_per_block * sizeof_complex64)
131 this%zblock_size = this%zblock_size - mod(this%zblock_size, this%l1%line_size) - 2*this%l1%line_size
132
133 this%sblock_size = this%l1%size / (cpu_default_states_per_block * sizeof_real32)
134 this%sblock_size = this%sblock_size - mod(this%sblock_size, this%l1%line_size) - 2*this%l1%line_size
135
136 this%cblock_size = this%l1%size / (cpu_default_states_per_block * sizeof_complex32)
137 this%cblock_size = this%cblock_size - mod(this%cblock_size, this%l1%line_size) - 2*this%l1%line_size
138
139 end subroutine hardware_init
140
141
142end module hardware_oct_m
143
144!! Local Variables:
145!! mode: f90
146!! coding: utf-8
147!! End:
subroutine hardware_init(this, l1_cache, l2_cache)
Initialise hardware object.
Definition: hardware.F90:122
type(cache_t) function, public cache_detect(level, default)
Data cache of the given level of this CPU, or the default where it cannot be detected.
Definition: hardware.F90:99
type(hardware_t), public cpu_hardware
Global instance of CPU hardware specification.
Definition: hardware.F90:77
integer, parameter, public sizeof_real64
Number of bytes to store a variable of type real(real64)
Definition: hardware.F90:56
integer, parameter, public sizeof_real32
Number of bytes to store a variable of type real(real32)
Definition: hardware.F90:62
type(cache_t), public default_l2
Definition: hardware.F90:81
type(cache_t) function cache_t_init(data_size, line_size)
Initialise cache object.
Definition: hardware.F90:87
integer, parameter, public sizeof_complex64
Number of bytes to store a variable of type complex(real64)
Definition: hardware.F90:59
integer, parameter, public sizeof_complex32
Number of bytes to store a variable of type complex(real32)
Definition: hardware.F90:65
Block-size optimisation for L1 cache size.
Definition: hardware.F90:43