HILA
Loading...
Searching...
No Matches
backend_gpu/lattice.h
1#ifndef _BACKEND_LATTICE_H_
2#define _BACKEND_LATTICE_H_
3
4#include "coordinates.h"
5#include "globals.h"
6
7/// Lattice related data that needs to be communicated
8/// to kernels
10 /// Storage for the neighbour indexes. Stored on device
11 unsigned *d_neighb[NDIRS];
12
13#ifdef SPECIAL_BOUNDARY_CONDITIONS
14 /// Neighbour indexes with special boundaries. Stored on device
15 unsigned *d_neighb_special[NDIRS];
16#endif
17
18 /// The full number of elements in a field, including haloes.
19 /// This is necessary for structure-of-arrays -storage
21 /// beginning and end of this loop (using lattice to communicate,
22 /// which may not be the clearest choice.)
23 int loop_begin, loop_end;
24
25#ifdef EVEN_SITES_FIRST
26 /// Finally a pointer to the list of coordinates, stored on device
27 CoordinateVector *d_coordinates;
28
29#if defined(CUDA) || defined(HIP)
30
31 /// get the coordinates at a given site
32 __host__ __device__ const CoordinateVector &coordinates(unsigned idx) const {
33 return d_coordinates[idx];
34 }
35 __host__ __device__ int coordinate(unsigned idx, Direction dir) const {
36 return d_coordinates[idx][dir];
37 }
38
39#endif
40
41#else
42 // Now not EVEN_SITES_FIRST
43
44 // these defined in hila_gpu.cpp
45 __device__ const CoordinateVector coordinates(unsigned idx) const;
46 __device__ int coordinate(unsigned idx, Direction dir) const;
47
48#endif
49
50 /// setup the backend lattice data
51 void setup(lattice_struct &lattice);
52
53 void set_lattice_globals( lattice_struct &lattice);
54
55};
56
57////////////////////////////////////////////////////////////////////////////
58// Define here some globals and inline functions
59
60#ifdef IN_HILA_GPU
61#define HILA_GPU_EXTERN /* nothing */
62#else
63#define HILA_GPU_EXTERN extern
64#endif
65
66// Save "constants" lattice size and volume here
67HILA_GPU_EXTERN hila::global<int64_t> _d_volume;
68HILA_GPU_EXTERN hila::global<CoordinateVector> _d_size;
69
70#ifndef EVEN_SITES_FIRST
71HILA_GPU_EXTERN hila::global<CoordinateVector> _d_nodesize;
72HILA_GPU_EXTERN hila::global<CoordinateVector> _d_nodemin;
73HILA_GPU_EXTERN hila::global<CoordinateVector> _d_nodefactor;
74#endif
75
76
77// Then, define global functions loop_lattice_size() and _volume()
78#pragma hila loop_function
79inline int loop_lattice_size(Direction dir) {
80 return _d_size()[dir];
81}
82
83#pragma hila loop_function
84inline CoordinateVector loop_lattice_size(void) {
85 return _d_size();
86}
87
88#pragma hila loop_function
89inline int64_t loop_lattice_volume(void) {
90 return _d_volume();
91}
92
93#ifndef EVEN_SITES_FIRST
94
95inline __device__ const CoordinateVector backend_lattice_struct::coordinates(unsigned idx) const {
97 unsigned vdiv, ndiv;
98
99 vdiv = idx;
100 for (int d = 0; d < NDIM - 1; ++d) {
101 ndiv = vdiv / _d_nodesize()[d];
102 c[d] = vdiv - ndiv * _d_nodesize()[d] + _d_nodemin()[d];
103 vdiv = ndiv;
104 }
105 c[NDIM - 1] = vdiv + _d_nodemin()[NDIM - 1];
106
107 return c;
108}
109
110inline __device__ int backend_lattice_struct::coordinate(unsigned idx, Direction dir) const {
111 return (idx / _d_nodefactor()[dir]) % _d_nodesize()[dir] + _d_nodemin()[dir];
112}
113
114#endif // not EVEN_SITES_FIRST
115
116
117#endif
Global variable class within hila namespace.
Definition globals.h:95
This header file defines:
constexpr unsigned NDIRS
Number of directions.
Definition coordinates.h:57
Direction
Enumerator for direction that assigns integer to direction to be interpreted as unit vector.
Definition coordinates.h:34
Definition of global variable class.
Helper class for loading the vectorized lattice.
void setup(lattice_struct *lattice)
unsigned * d_neighb[NDIRS]
Storage for the neighbour indexes. Stored on device.