17#ifndef GRID_GPU_SEPARABLE_H
18#define GRID_GPU_SEPARABLE_H
34#ifndef GRID_SEP_COLLOCATE_ROW_LANES
35#define GRID_SEP_COLLOCATE_ROW_LANES 8
37#ifndef GRID_SEP_INTEGRATE_ROW_LANES
38#define GRID_SEP_INTEGRATE_ROW_LANES 4
43 "GRID_SEP_COLLOCATE_ROW_LANES must be a power of two <= 32");
47 "GRID_SEP_INTEGRATE_ROW_LANES must be a power of two <= 32");
49#define GRID_SEP_MAX_L 18
55 const int next = x2 + STRIDE;
56 return (next >= n) ? next % n : next;
88 static bool initialized =
false;
96 for (
int a = s; a >= 0; a--)
97 pairs[ip++] = make_char2(a, s - a);
98 offloadMemcpyToSymbol(
sep_pair_ab, pairs,
sizeof(pairs));
103 const int nl = (l + 1) * (l + 2) / 2;
107 offloadMemcpyToSymbol(
sep_m_offset, m_offset,
sizeof(m_offset));
152 std::vector<double> matrix;
153 const int n =
ncoset(lmax);
154 std::vector<double> poly(n), next(n);
156 for (
int l = 0; l <= lmax; l++) {
157 for (
int a = l; a >= 0; a--) {
158 for (
int b = l - a; b >= 0; b--) {
160 const int pw[3] = {a, b, l - a - b};
163 std::fill(poly.begin(), poly.end(), 0.0);
166 for (
int d = 0; d < 3; d++) {
167 for (
int p = 0; p < pw[d]; p++) {
168 std::fill(next.begin(), next.end(), 0.0);
169 for (
int i = 0;
i <= deg;
i++) {
170 for (
int j = 0; j <= deg -
i; j++) {
171 const int k = deg -
i - j;
172 const double val = poly[
coset(
i, j, k)];
173 next[
coset(
i + 1, j, k)] += dh[0 + d] * val;
174 next[
coset(
i, j + 1, k)] += dh[3 + d] * val;
175 next[
coset(
i, j, k + 1)] += dh[6 + d] * val;
182 const int base = (l > 0) ?
ncoset(l - 1) : 0;
183 matrix.insert(matrix.end(), poly.begin() + base,
184 poly.begin() +
ncoset(l));
198 if (
grid.lattice_to_cartesian_lmax() < lmax) {
199 const std::vector<double> matrix =
201 grid.lattice_to_cartesian().resize(matrix.size());
202 grid.lattice_to_cartesian().copy_to_gpu(matrix);
203 grid.lattice_to_cartesian_lmax(lmax);
205 return grid.lattice_to_cartesian().data();
static void const int const int const int const int const int const double const int const int const int int GRID_CONST_WHEN_COLLOCATE double GRID_CONST_WHEN_INTEGRATE double * grid
static void const int const int i
#define GRID_SEP_INTEGRATE_ROW_LANES
#define GRID_SEP_COLLOCATE_ROW_LANES
__device__ __inline__ int sep_advance_wrapped_index(const int x2, const int n)
int separable_lmax_bucket(const int lp_max)
static std::vector< double > build_lattice_to_cartesian_matrix(const double *dh, const int lmax)
Builds the matrix expanding the cartesian monomials x^a y^b z^c in lattice monomials u^i v^j w^k,...
static void init_separable_constant_memory()
Initializes the constant memory of integrate_separable_kernel.
__host__ __device__ __inline__ int coset(int lx, int ly, int lz)
Maps three angular momentum components to a single zero based index.
static const double * get_lattice_to_cartesian(grid_info< double > &grid, const int lmax)
Returns the lattice to cartesian matrix of a grid level on the device, (re)computing it when the latt...
__host__ __device__ __inline__ int ncoset(const int l)
Number of Cartesian orbitals up to given angular momentum quantum.
__constant__ int sep_m_offset[GRID_SEP_MAX_L+1]
__constant__ char2 sep_pair_ab[(GRID_SEP_MAX_L+1) *(GRID_SEP_MAX_L+2)/2]
constexpr size_t separable_max_smem
__global__ const int const int lp_max