HILA
Loading...
Searching...
No Matches
field_storage.h
Go to the documentation of this file.
1/** @file field_storage.h */
2
3#ifndef FIELD_STORAGEH
4#define FIELD_STORAGEH
5
6#include "plumbing/defs.h"
8#include "plumbing/field.h"
9#include "plumbing/backend_vector/vector_types.h"
10
11#include "plumbing/has_unary_minus.h"
12
13
14template <typename T>
15class field_struct;
16
17#if defined(CUDA) || defined(HIP)
18#define DEVICE __device__
19#else
20#define DEVICE
21#endif
22
23/**
24 * @brief The field_storage struct contains minimal information for using
25 * the field in a loop. It is communicated to CUDA kernels and other
26 * accelerator functions.
27 */
28template <typename T>
30 public:
31 // The actual data content of the class: a pointer to the field and a
32 // list of neighbour pointers.
33 T *RESTRICT fieldbuf = nullptr;
34 const unsigned *RESTRICT neighbours[NDIRS];
35
36 void allocate_field(const lattice_struct &lattice);
37 void free_field();
38
39#ifndef VECTORIZED
40 // Get an element in a loop
41 DEVICE inline auto get(const unsigned i, const unsigned field_alloc_size) const;
42
43 // template <typename A>
44 DEVICE inline void set(const T &value, const unsigned i, const unsigned field_alloc_size);
45
46 // Get a single element outside loops
47 auto get_element(const unsigned i, const lattice_struct &lattice) const;
48 template <typename A>
49 void set_element(A &value, const unsigned i, const lattice_struct &lattice);
50
51#else
52 inline T get_element(const unsigned i) const;
53
54 inline void set_element(const T &value, const unsigned i);
55
56 // in vector code, write only 1 element to field at site index idx
57 template <typename vecT>
58 inline void set_vector(const vecT &val, const unsigned idx);
59
60 template <typename vecT>
61 inline vecT get_vector(const unsigned idx) const;
62
63 void gather_comm_vectors(
64 T *RESTRICT buffer, const lattice_struct::comm_node_struct &to_node, Parity par,
66 bool antiperiodic) const;
67
68 void place_recv_elements(
69 const T *RESTRICT buffer, Direction d, Parity par,
71
72#endif
73
74 void gather_comm_elements(T *RESTRICT buffer, const lattice_struct::comm_node_struct &to_node,
75 Parity par, const lattice_struct &lattice, bool antiperiodic) const;
76
77 void gather_elements(T *RESTRICT buffer, const unsigned *RESTRICT index_list, int n,
78 const lattice_struct &lattice) const;
79
80 void gather_elements_negated(T *RESTRICT buffer, const unsigned *RESTRICT index_list, int n,
81 const lattice_struct &lattice) const;
82
83 /// Place boundary elements from neighbour
84 void place_comm_elements(Direction d, Parity par, T *RESTRICT buffer,
85 const lattice_struct::comm_node_struct &from_node,
86 const lattice_struct &lattice);
87 void place_elements(T *RESTRICT buffer, const unsigned *RESTRICT index_list, int n,
88 const lattice_struct &lattice);
89 /// Place boundary elements from local lattice (used in vectorized version)
90 void set_local_boundary_elements(Direction dir, Parity par, const lattice_struct &lattice,
91 bool antiperiodic);
92
93 // Allocate buffers for mpi communication
94 T *allocate_mpi_buffer(unsigned n);
95 void free_mpi_buffer(T *buffer);
96
97 T *RESTRICT get_buffer() {
98 return static_cast<T *>(fieldbuf);
99 }
100};
101
102/*
103Import backend
104*/
105
106#ifdef VECTORIZED
107
108#include "plumbing/backend_vector/field_storage_backend.h"
109
110#elif defined(CUDA) || defined(HIP)
111
112#include "plumbing/backend_gpu/field_storage_backend.h"
113
114#elif defined(VANILLA)
115
116#include "plumbing/backend_cpu/field_storage_backend.h"
117
118#else
119Something must be defined !
120
121#endif
122
123#endif // field storage
The field_storage struct contains minimal information for using the field in a loop....
void place_elements(T *__restrict__ buffer, const unsigned *__restrict__ index_list, int n, const lattice_struct &lattice)
CUDA implementation of place_elements without CUDA aware MPI.
void gather_elements(T *__restrict__ buffer, const unsigned *__restrict__ index_list, int n, const lattice_struct &lattice) const
CUDA implementation of gather_elements without CUDA aware MPI.
void gather_elements_negated(T *__restrict__ buffer, const unsigned *__restrict__ index_list, int n, const lattice_struct &lattice) const
CUDA implementation of gather_elements_negated without CUDA aware MPI.
void set_local_boundary_elements(Direction dir, Parity par, const lattice_struct &lattice, bool antiperiodic)
Place boundary elements from local lattice (used in vectorized version)
auto get_element(const unsigned i, const lattice_struct &lattice) const
void place_comm_elements(Direction d, Parity par, T *__restrict__ buffer, const lattice_struct::comm_node_struct &from_node, const lattice_struct &lattice)
Place boundary elements from neighbour.
This header file defines:
Parity
Parity enum with values EVEN, ODD, ALL; refers to parity of the site. Parity of site (x,...
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
This file defines all includes for HILA.
#define RESTRICT
Definition defs.h:51
This files containts definitions for the Field class and the classes required to define it such as fi...
Information necessary to communicate with a node.
Definition lattice.h:134