QUDA
v0.5.0
A library for QCD on GPUs
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
quda
lib
lattice_field.cpp
Go to the documentation of this file.
1
#include <typeinfo>
2
#include <
quda_internal.h
>
3
#include <
lattice_field.h
>
4
#include <
gauge_field.h
>
5
#include <
clover_field.h
>
6
7
namespace
quda {
8
9
void
*
LatticeField::bufferPinned
= NULL;
10
bool
LatticeField::bufferInit
=
false
;
11
size_t
LatticeField::bufferBytes
= 0;
12
13
LatticeField::LatticeField
(
const
LatticeFieldParam
&
param
)
14
: volume(1), pad(param.pad), total_bytes(0), nDim(param.nDim), precision(param.precision)
15
{
16
for
(
int
i=0; i<
nDim
; i++) {
17
x
[i] = param.
x
[i];
18
volume
*= param.
x
[i];
19
surface
[i] = 1;
20
for
(
int
j=0; j<
nDim
; j++) {
21
if
(i==j)
continue
;
22
surface
[i] *= param.
x
[j];
23
}
24
}
25
volumeCB
=
volume
/ 2;
26
stride
=
volumeCB
+
pad
;
27
28
for
(
int
i=0; i<
nDim
; i++)
surfaceCB
[i] =
surface
[i] / 2;
29
}
30
31
void
LatticeField::checkField
(
const
LatticeField
&a) {
32
if
(a.
volume
!=
volume
)
errorQuda
(
"Volume does not match %d %d"
,
volume
, a.
volume
);
33
if
(a.
volumeCB
!=
volumeCB
)
errorQuda
(
"VolumeCB does not match %d %d"
,
volumeCB
, a.
volumeCB
);
34
if
(a.
nDim
!=
nDim
)
errorQuda
(
"nDim does not match %d %d"
,
nDim
, a.
nDim
);
35
for
(
int
i=0; i<
nDim
; i++) {
36
if
(a.
x
[i] !=
x
[i])
errorQuda
(
"x[%d] does not match %d %d"
, i,
x
[i], a.
x
[i]);
37
if
(a.
surface
[i] !=
surface
[i])
errorQuda
(
"surface[%d] does not match %d %d"
, i,
surface
[i], a.
surface
[i]);
38
if
(a.
surfaceCB
[i] !=
surfaceCB
[i])
errorQuda
(
"surfaceCB[%d] does not match %d %d"
, i,
surfaceCB
[i], a.
surfaceCB
[i]);
39
}
40
}
41
42
QudaFieldLocation
LatticeField::Location
()
const
{
43
QudaFieldLocation
location
=
QUDA_INVALID_FIELD_LOCATION
;
44
if
(
typeid
(*
this
)==
typeid
(
cudaCloverField
) ||
45
typeid
(*
this
)==
typeid
(
cudaGaugeField
)) {
46
location =
QUDA_CUDA_FIELD_LOCATION
;
47
}
else
if
(
typeid
(*
this
)==
typeid
(
cpuCloverField
) ||
48
typeid
(*
this
)==
typeid
(
cpuGaugeField
)) {
49
location =
QUDA_CPU_FIELD_LOCATION
;
50
}
else
{
51
errorQuda
(
"Unknown field %s, so cannot determine location"
,
typeid
(*this).name());
52
}
53
return
location
;
54
}
55
56
void
LatticeField::resizeBuffer
(
size_t
bytes)
const
{
57
if
(bytes >
bufferBytes
||
bufferInit
== 0) {
58
if
(
bufferInit
)
host_free
(
bufferPinned
);
59
bufferPinned
=
pinned_malloc
(bytes);
60
bufferBytes
= bytes;
61
bufferInit
=
true
;
62
}
63
}
64
65
void
LatticeField::freeBuffer
() {
66
if
(
bufferInit
) {
67
host_free
(
bufferPinned
);
68
bufferPinned
= NULL;
69
bufferBytes
= 0;
70
bufferInit
=
false
;
71
}
72
}
73
74
// This doesn't really live here, but is fine for the moment
75
std::ostream&
operator<<
(std::ostream& output,
const
LatticeFieldParam
&
param
)
76
{
77
output <<
"nDim = "
<< param.
nDim
<< std::endl;
78
for
(
int
i=0; i<param.
nDim
; i++) {
79
output <<
"x["
<< i <<
"] = "
<< param.
x
[i] << std::endl;
80
}
81
output <<
"pad = "
<< param.
pad
<< std::endl;
82
output <<
"precision = "
<< param.
precision
<< std::endl;
83
84
return
output;
// for multiple << operators.
85
}
86
87
}
// namespace quda
Generated on Wed Mar 20 2013 12:52:17 for QUDA by
1.8.2