27#error "OpenMP should not be used in .cu files to accommodate HIP."
34template <
typename T,
bool IS_FUNC_AB>
45 for (
int jco =
task.first_cosetb +
tid / 16; jco <
task.ncosetb; jco += 4) {
46 for (
int ico =
task.first_coseta + (
tid % 16); ico <
task.ncoseta;
49 for (
int i = 0;
i <
task.nsgf_setb;
i++) {
50 const T sphib =
task.sphib[
i *
task.maxcob + jco];
52 for (
int j = 0; j <
task.nsgf_seta; j++) {
54 if (
task.block_transposed) {
61 tmp_val += block_val *
task.sphia[j *
task.maxcoa + ico];
63 pab_val += tmp_val * sphib;
67 cab[jco *
task.ncoseta + ico] += pab_val;
81template <
typename T,
bool IS_FUNC_AB>
91 T *
smem_cab =
reinterpret_cast<double *
>(
96 const int task_id = dev_.task_sorted_by_blocks_dev[
offset + tk];
97 if (dev_.tasks[task_id].skip_task)
101 T *__restrict__ coef_ =
102 &dev_.buffers_dev.coef[dev_.tasks[task_id].coef_offset];
105 z += blockDim.x * blockDim.y * blockDim.z)
127template <
typename T,
bool IS_FUNC_AB>
130 extern __shared__ T shared_memory[];
139 const int nthreads = blockDim.x * blockDim.y * blockDim.z;
151 T *__restrict__ coef_ =
158 const int nco_a =
task.ncoseta -
task.first_coseta;
159 const int nco_b =
task.ncosetb -
task.first_cosetb;
161 const int i = k / nco_a;
162 const int ico =
task.first_coseta + (k -
i * nco_a);
164 for (
int j = 0; j <
task.nsgf_seta; j++) {
165 const T block_val =
task.block_transposed
168 val += block_val *
task.sphia[j *
task.maxcoa + ico];
175 for (
int k =
tid; k < nco_b * nco_a; k +=
nthreads) {
176 const int jj = k / nco_a;
177 const int jco =
task.first_cosetb + jj;
178 const int ico =
task.first_coseta + (k - jj * nco_a);
180 for (
int i = 0;
i <
task.nsgf_setb;
i++)
192 for (
int k =
tid; k < nco_b * nco_a; k +=
nthreads) {
193 const int jj = k / nco_a;
194 const int jco =
task.first_cosetb + jj;
195 const int ico =
task.first_coseta + (k - jj * nco_a);
260template <
bool distributed__,
bool axis_aligned_,
bool chunked_>
263 const
double *__restrict__
M) {
266 constexpr bool orthogonal_ = axis_aligned_;
268 constexpr bool tables_ = axis_aligned_ && !chunked_;
274 const int tid = threadIdx.x;
277 extern __shared__
double sep_smem[];
295 const bool trim = orthogonal_ && !
task.apply_border_mask;
297 const double *__restrict__
coef =
306 const int l = co.l[0] + co.l[1] + co.l[2];
307 const int base = (l > 0) ?
ncoset(l - 1) : 0;
308 const int nl =
ncoset(l) - base;
312 for (
int k = 0; k < nl; k++)
313 val += Ml[k * nl] *
coef[base + k];
320 for (
int x =
tid; x <
task.cube_size.x; x += 64) {
321 const double r = (x +
task.lb_cube.x +
task.roffset.x) * dev_.
dh_[0];
322 ex[x] = exp(-
zetp * r * r);
324 for (
int y =
tid;
y <
task.cube_size.y;
y += 64) {
325 const double r = (
y +
task.lb_cube.y +
task.roffset.y) * dev_.
dh_[4];
336 for (
int z = 0; z <
task.cube_size.z; z++) {
340 if (distributed__ &&
task.apply_border_mask &&
341 ((z2 <
task.window_shift.z) || (z2 >
task.window_size.z)))
344 int ymin = 0, ymax =
task.cube_size.y - 1;
345 double kremain = 0.0;
351 const double w = z +
task.lb_cube.z +
task.roffset.z;
352 const double rz = axis_aligned_ ? w * dev_.
dh_[8] : w;
353 const double ez = axis_aligned_ ? exp(-
zetp * rz * rz) : 1.0;
357 for (
int ip =
tid; ip <
npairs; ip += 64) {
361 for (
int c =
lp - a - b; c >= 0; c--)
362 d = d * rz +
C[
coset(a, b, c)];
363 D[a *
ls + b] = d * ez;
370 for (
int y0 = ymin; y0 <= ymax; y0 = chunked_ ? y0 +
erows : ymax + 1) {
371 const int y1 = chunked_ ? min(ymax, y0 +
erows - 1) : ymax;
372 const int nyc = y1 - y0 + 1;
375 for (
int k =
tid; k < nyc * (
lp + 1); k += 64) {
376 const int yy = k / (
lp + 1);
377 const int a = k - yy * (
lp + 1);
378 const int y = y0 + yy;
379 const double v =
y +
task.lb_cube.y +
task.roffset.y;
380 const double r = axis_aligned_ ? v * dev_.
dh_[4] : v;
381 double p =
tables_ ?
ey[
y] : (axis_aligned_ ? exp(-
zetp * r * r) : 1.0);
383 for (
int b = 0; b <=
lp - a; b++, p *= r)
384 e +=
D[a *
ls + b] * p;
394 if (distributed__ &&
task.apply_border_mask &&
395 ((y2 <
task.window_shift.y) || (y2 >
task.window_size.y)))
398 int xmin = 0, xmax =
task.cube_size.x - 1;
402 const double v =
y +
task.lb_cube.y +
task.roffset.y;
403 const double *__restrict__ Ey = &
E[(
y - y0) *
ls];
404 double *__restrict__ row =
414 if (distributed__ &&
task.apply_border_mask &&
415 ((x2 <
task.window_shift.x) || (x2 >
task.window_size.x)))
418 const double u = x +
task.lb_cube.x +
task.roffset.x;
419 const double r = axis_aligned_ ? u * dev_.
dh_[0] : u;
426 const double r2 = r3.x * r3.x + r3.y * r3.y + r3.z * r3.z;
428 const bool outside = (
r2max <= r2);
430 if (outside && (!orthogonal_ ||
task.apply_border_mask))
432 }
else if (!orthogonal_ && outside) {
435 gauss = exp(-
zetp * r2);
437 if (axis_aligned_ && distributed__ &&
task.apply_border_mask) {
438 const double ry = v * dev_.
dh_[4];
439 const double r2 = r * r + ry * ry + rz * rz;
445 for (
int a =
lp - 1; a >= 0; a--)
446 val = val * r + Ey[a];
447 atomicAdd(&row[x2], val * gauss);
451 if (chunked_ && (y1 < ymax))
469 const bool axis_aligned,
470 const size_t smem_max) {
472 const size_t per_edge =
473 sizeof(double) * (
lp_max + 1 + (axis_aligned ? 2 : 0));
474 return (smem_max > fixed) ? (int)((smem_max - fixed) / per_edge) : 0;
479 const size_t smem_max) {
481 const size_t per_row =
sizeof(double) * (
lp_max + 1);
482 if (fixed + per_row > smem_max) {
483 fprintf(stderr,
"ERROR: lp %d too large for collocate_separable_kernel.\n",
487 return (
int)std::min<size_t>(
mc, (smem_max - fixed) / per_row);
496 *lp_diff = smem_params.
lp_diff();
501 kernel_params params = set_kernel_parameters(-1, smem_params);
505 const dim3 threads_per_block(4, 4, 4);
510 const size_t smem_two_steps =
512 const auto two_steps_kernel =
513 (func ==
GRID_FUNC_AB) ? calculate_coefficients_two_steps<double, true>
514 : calculate_coefficients_two_steps<double, false>;
515 if (smem_two_steps <=
523 ? calculate_coefficients<double, true>
524 : calculate_coefficients<double, false>;
529 const int,
const int,
532template <
bool chunked_>
536 return axis_aligned ? collocate_separable_kernel<true, true, chunked_>
537 : collocate_separable_kernel<true, false, chunked_>;
538 return axis_aligned ? collocate_separable_kernel<false, true, chunked_>
539 : collocate_separable_kernel<false, false, chunked_>;
556 *lp_diff = smem_params.
lp_diff();
560 kernel_params params = set_kernel_parameters(level, smem_params);
567 const int max_cube_size = std::max(
grid.max_cube_size(), 1);
568 const bool axis_aligned =
grid.is_axis_aligned();
575 const bool distributed =
grid.is_distributed();
582 const int mc = std::min(max_cube_size,
594 if (max_cube_size >
mc) {
std::vector< offloadStream_t > level_streams
offloadStream_t main_stream
std::vector< int > number_of_tasks_per_level_
void calculate_all_coefficients(const enum grid_func func, int *lp_diff)
void collocate_one_grid_level(const int level, const enum grid_func func, int *lp_diff)
Launches the Cuda kernel that collocates all tasks of one grid level.
void prepare_cab_workspace(const int la_max_diff, const int lb_max_diff)
Lays out the cab workspace of the coefficient kernels for the angular momentum offsets of the current...
std::vector< grid_info< double > > grid_
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_COLLOCATE_ROW_LANES
fill_smem_task_reduced(dev_, dev_.first_task+block_index(), task)
__device__ __inline__ int sep_advance_wrapped_index(const int x2, const int n)
int sphi_work_size(const int lmax, const int max_nsgf_set)
Size (in doubles) of the work arrays of the two step spherical <-> cartesian transformations of calcu...
__inline__ __host__ __device__ double3 compute_coordinates(const double *__restrict__ dh_, const double x, const double y, const double z)
const task_info & glb_task
static void init_constant_memory()
Initializes the device's constant memory.
__inline__ __device__ unsigned int block_index()
static collocate_separable_kernel_t select_collocate_separable(const bool distributed, const bool axis_aligned)
__device__ __inline__ void setup_task_cube_center(const kernel_params &dev_, smem_task_reduced< T, T3 > &task)
Shifts task.cube_center into the local grid's coordinate system and, for distributed grids,...
__global__ const int const int const int erows
__device__ __inline__ void prepare_pab(const enum grid_func func, const orbital a, const orbital b, const T zeta, const T zetb, const T pab_val, const int n, T *cab)
Transforms a given element of the density matrix according to func.
__device__ __inline__ T calculate_ymix_ymax_boundaries(smem_task_reduced< T, T3 > &task, const int z, int &ymin, int &ymax)
static int collocate_separable_erows(const int mc, const int lp_max, const size_t smem_max)
__shared__ double sep_smem[]
__device__ __inline__ void fill_smem_task_coef(const kernel_params &dev, const int task_id, smem_task< T > &task)
Copies a task from global to shared memory and does precomputations.
constexpr int nrow_groups
__inline__ __device__ unsigned int thread_global_index()
static int collocate_separable_max_edge(const int lp_max, const bool axis_aligned, const size_t smem_max)
const int number_of_tasks
__device__ __inline__ void cab_to_cxyz_factorized(const smem_task< T > &task, T *__restrict__ cab, T *__restrict__ cxyz)
Transforms the coefficients C_ab into C_xyz, cxyz[c] = prefactor sum_{a, b} alpha[a][b][c] cab[b][a] ...
static void init_separable_constant_memory()
Initializes the constant memory of integrate_separable_kernel.
__inline__ __device__ int wrap_grid_index(const int idx, const int full_size)
Wraps a cube-local coordinate into the periodic full grid along one axis. Single point of entry share...
__constant__ orbital coset_inv[1330]
size_t max_dynamic_smem(Kernel kernel, const size_t budget)
Largest dynamic shared memory the kernel can be launched with when its static and dynamic shared memo...
__host__ __device__ __inline__ int coset(int lx, int ly, int lz)
Maps three angular momentum components to a single zero based index.
__device__ __inline__ void block_to_cab(const kernel_params ¶ms, const smem_task< T > &task, T *cab)
Decontracts the subblock, going from spherical to cartesian harmonics.
__global__ const int const int max_nsgf_set
static size_t collocate_separable_smem_size(const int lp_max, const int erows, const int ntab)
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...
__device__ __inline__ bool sep_skip_task(const task_info &task, const int mc)
__global__ __launch_bounds__(64) void calculate_coefficients(const kernel_params dev_)
Same as calculate_coefficients, with the spherical to cartesian transformation of block_to_cab done i...
__global__ const int const int const int const double *__restrict__ M
__inline__ __device__ T * allocate_workspace(const kernel_params &dev_)
__host__ __device__ __inline__ int ncoset(const int l)
Number of Cartesian orbitals up to given angular momentum quantum.
void(*)(const kernel_params, const int, const int, const int, const double *) collocate_separable_kernel_t
__constant__ int sep_m_offset[GRID_SEP_MAX_L+1]
__device__ __inline__ void calculate_xmin_xmax_boundaries(smem_task_reduced< T, T3 > &task, const int y, const T kremain, int &xmin, int &xmax)
constexpr int grid_gpu_max_l
ldiffs_value prepare_get_ldiffs(const enum grid_func func)
Returns difference in angular momentum range for given func.
__global__ const int const int const int const double *__restrict__ lattice_to_cartesian
__shared__ smem_task_reduced< double, double3 > task
const double *__restrict__ coef
__constant__ char2 sep_pair_ab[(GRID_SEP_MAX_L+1) *(GRID_SEP_MAX_L+2)/2]
constexpr size_t grid_gpu_smem_budget
__global__ const int const int lp_max
Parameters of the collocate kernel.
int * task_sorted_by_blocks_dev
int * num_tasks_per_block_dev
kernel_buffers buffers_dev
int * sorted_blocks_offset_dev
Differences in angular momentum.
Orbital angular momentum.
data needed for collocate and integrate kernels
data needed for calculating the coefficients, forces, and stress
Internal representation of a task.