(git:374b731)
Loading...
Searching...
No Matches
grid_dgemm_private_header.h
Go to the documentation of this file.
1/*----------------------------------------------------------------------------*/
2/* CP2K: A general program to perform molecular dynamics simulations */
3/* Copyright 2000-2024 CP2K developers group <https://cp2k.org> */
4/* */
5/* SPDX-License-Identifier: BSD-3-Clause */
6/*----------------------------------------------------------------------------*/
7
8#ifndef GRID_DGEMM_PRIVATE_HEADER_H
9#define GRID_DGEMM_PRIVATE_HEADER_H
10
12#include <assert.h>
13#include <stdbool.h>
14/* everything here is specific to the dgemm and gpu backends*/
15#include "../../offload/offload_buffer.h"
16#include "../common/grid_basis_set.h"
17#include "../common/grid_common.h"
18#include "../common/grid_constants.h"
19enum checksum_ { task_checksum = 0x2384989, ctx_checksum = 0x2356734 };
20
21typedef struct {
22 int xmin, xmax;
23} Interval;
24
25typedef struct {
26 int level;
27 int iatom;
28 int jatom;
29 int iset;
30 int jset;
31 int ipgf;
32 int jpgf;
35 double radius;
36 double zetp;
37 double zeta[2];
38 double ra[3];
39 double rb[3];
40 double rp[3];
41 int lmax[2];
42 int lmin[2];
44 int offset[2];
46 double rab[3];
47 double prefactor;
49} _task;
50
51typedef struct {
52 int npts_global[3];
53 int npts_local[3];
54 int shift_local[3];
55 int border_width[3];
56 double dh[3][3];
57 double dh_inv[3][3];
58} _layout;
59
90
91static inline void update_loop_index(const int global_grid_size, int x1,
92 int *const x) {
93 *x += global_grid_size - x1 - 1;
94}
95
96static inline Interval create_interval(const int xmin, const int xmax) {
97 assert(xmax >= xmin);
98
99 Interval t = {.xmin = xmin, .xmax = xmax};
100 return t;
101}
102
103static inline bool is_point_in_interval(const int value, Interval x) {
104 return (value >= x.xmin) && (value <= x.xmax);
105}
106
107static inline bool intersection_interval_is_empty(const Interval x,
108 const Interval y) {
109 /* return true if the intersection is empty */
110 if ((x.xmin > y.xmax) || (x.xmax < y.xmin))
111 return true;
112 else
113 return false;
114}
115
117 const Interval y) {
118 Interval z;
119 z.xmin = imax(x.xmin, y.xmin);
120 z.xmax = imin(x.xmax, y.xmax);
121 return z;
122}
123
124static inline int compute_next_boundaries(const int y1, const int y,
125 const int grid_size,
126 const int cube_size) {
127 return y1 + imin(cube_size - y, grid_size - y1);
128}
129
130extern void grid_transform_coef_jik_to_yxz(const double dh[3][3],
131 const tensor *coef_xyz);
132extern void grid_transform_coef_xzy_to_ikj(const double dh[3][3],
133 const tensor *coef_xyz);
135 const int *blockDim, const int *lb_grid, const int *grid_size,
136 const int *blocked_grid_size, const int *period, const int *cube_center,
137 const int *cube_size, const int *lower_boundaries_cube,
138 int *lower_block_corner, int *upper_block_corner, int *pol_offsets);
139
140extern void grid_fill_pol_dgemm(const bool transpose, const double dr,
141 const double roffset, const int pol_offset,
142 const int xmin, const int xmax, const int lp,
143 const int cmax, const double zetp,
144 double *pol_);
145
146/* this function is not exported outside. Should move */
148 double *scratch, const double alpha, const bool *const orthogonal,
149 const struct tensor_ *Exp, const struct tensor_ *co,
150 const struct tensor_ *p_alpha_beta_reduced_, struct tensor_ *cube);
151
152extern void set_grid_parameters(
153 tensor *grid, /* tensor describing the grid */
154 const bool orthorhombic,
155 const int grid_full_size[3], /* size of the full grid */
156 const int grid_local_size[3], /* size of the local grid block */
157 const int shift_local[3], /* coordinates of the lower coordinates of the
158 local grid window */
159 const int border_width[3], /* width of the borders */
160 const double
161 dh[3][3], /* displacement vectors of the grid (cartesian) -> (ijk) */
162 const double dh_inv[3][3], /* (ijk) -> (x,y,z) */
163 offload_buffer *grid_);
164
165extern void collocate_one_grid_level_dgemm(grid_context *const ctx,
166 const int *const, const int *const,
167 const enum grid_func func,
168 const int level,
169 const offload_buffer *pab_blocks);
170
172 grid_context *const ctx, const int level, const bool calculate_tau,
173 const bool calculate_forces, const bool calculate_virial,
174 const int *const shift_local, const int *const border_width,
175 const offload_buffer *const pab_blocks, offload_buffer *const hab_blocks,
176 tensor *forces_, tensor *virial_);
177
178extern void compute_coefficients(grid_context *const ctx,
179 struct collocation_integration_ *handler,
180 const _task *previous_task, const _task *task,
181 const offload_buffer *pab_blocks,
182 tensor *const pab, tensor *const work,
183 tensor *const pab_prep);
184
185extern void extract_blocks(grid_context *const ctx, const _task *const task,
186 const offload_buffer *pab_blocks, tensor *const work,
187 tensor *const pab);
188
189#endif
static int imax(int x, int y)
Returns the larger of two given integer (missing from the C standard)
static int imin(int x, int y)
Returns the smaller of two given integer (missing from the C standard)
Definition dbm_miniapp.c:38
grid_func
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 cmax
static void const int const int const int const int const int const double const int const int const int npts_local[3]
void grid_fill_pol_dgemm(const bool transpose, const double dr, const double roffset, const int pol_offset, const int xmin, const int xmax, const int lp, const int cmax, const double zetp, double *pol_)
static bool is_point_in_interval(const int value, Interval x)
void compute_block_boundaries(const int *blockDim, const int *lb_grid, const int *grid_size, const int *blocked_grid_size, const int *period, const int *cube_center, const int *cube_size, const int *lower_boundaries_cube, int *lower_block_corner, int *upper_block_corner, int *pol_offsets)
struct grid_context_ grid_context
void integrate_one_grid_level_dgemm(grid_context *const ctx, const int level, const bool calculate_tau, const bool calculate_forces, const bool calculate_virial, const int *const shift_local, const int *const border_width, const offload_buffer *const pab_blocks, offload_buffer *const hab_blocks, tensor *forces_, tensor *virial_)
void extract_blocks(grid_context *const ctx, const _task *const task, const offload_buffer *pab_blocks, tensor *const work, tensor *const pab)
void grid_transform_coef_xzy_to_ikj(const double dh[3][3], const tensor *coef_xyz)
void tensor_reduction_for_collocate_integrate(double *scratch, const double alpha, const bool *const orthogonal, const struct tensor_ *Exp, const struct tensor_ *co, const struct tensor_ *p_alpha_beta_reduced_, struct tensor_ *cube)
static int compute_next_boundaries(const int y1, const int y, const int grid_size, const int cube_size)
static Interval create_interval(const int xmin, const int xmax)
void compute_coefficients(grid_context *const ctx, struct collocation_integration_ *handler, const _task *previous_task, const _task *task, const offload_buffer *pab_blocks, tensor *const pab, tensor *const work, tensor *const pab_prep)
static Interval intersection_interval(const Interval x, const Interval y)
void collocate_one_grid_level_dgemm(grid_context *const ctx, const int *const, const int *const, const enum grid_func func, const int level, const offload_buffer *pab_blocks)
static void update_loop_index(const int global_grid_size, int x1, int *const x)
void grid_transform_coef_jik_to_yxz(const double dh[3][3], const tensor *coef_xyz)
static bool intersection_interval_is_empty(const Interval x, const Interval y)
void set_grid_parameters(tensor *grid, const bool orthorhombic, const int grid_full_size[3], const int grid_local_size[3], const int shift_local[3], const int border_width[3], const double dh[3][3], const double dh_inv[3][3], offload_buffer *grid_)
enum checksum_ checksum
Internal representation of a basis set.
grid_basis_set ** basis_sets
struct collocation_integration_ ** handler
Internal representation of a buffer.