2020-08-18 14:27:28 +02:00
|
|
|
/*
|
2022-09-05 10:39:42 +02:00
|
|
|
* Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
|
|
|
|
* All rights reserved. This file is part of MD-Bench.
|
|
|
|
* Use of this source code is governed by a LGPL-3.0
|
|
|
|
* license that can be found in the LICENSE file.
|
2020-08-18 14:27:28 +02:00
|
|
|
*/
|
|
|
|
#include <parameter.h>
|
2024-04-15 16:53:25 +02:00
|
|
|
#include <box.h>
|
2020-08-18 14:27:28 +02:00
|
|
|
|
|
|
|
#ifndef __ATOM_H_
|
|
|
|
#define __ATOM_H_
|
|
|
|
|
2022-03-05 03:21:52 +01:00
|
|
|
#define DELTA 20000
|
|
|
|
|
2022-03-09 02:25:39 +01:00
|
|
|
// Nbnxn layouts (as of GROMACS):
|
|
|
|
// Simd4xN: M=4, N=VECTOR_WIDTH
|
|
|
|
// Simd2xNN: M=4, N=(VECTOR_WIDTH/2)
|
2022-11-08 18:33:23 +01:00
|
|
|
// Cuda: M=8, N=VECTOR_WIDTH
|
2022-03-09 02:25:39 +01:00
|
|
|
|
2022-11-08 18:33:23 +01:00
|
|
|
#ifdef CUDA_TARGET
|
|
|
|
# undef VECTOR_WIDTH
|
|
|
|
# define VECTOR_WIDTH 8
|
|
|
|
# define KERNEL_NAME "CUDA"
|
|
|
|
# define CLUSTER_M 8
|
|
|
|
# define CLUSTER_N VECTOR_WIDTH
|
2023-03-23 00:58:25 +01:00
|
|
|
# define UNROLL_J 1
|
2022-11-08 18:33:23 +01:00
|
|
|
# define computeForceLJ computeForceLJ_cuda
|
|
|
|
# define initialIntegrate cudaInitialIntegrate
|
|
|
|
# define finalIntegrate cudaFinalIntegrate
|
|
|
|
# define updatePbc cudaUpdatePbc
|
|
|
|
#else
|
|
|
|
# define CLUSTER_M 4
|
2022-03-10 01:31:50 +01:00
|
|
|
// Simd2xNN (here used for single-precision)
|
2022-11-08 18:33:23 +01:00
|
|
|
# if VECTOR_WIDTH > CLUSTER_M * 2
|
|
|
|
# define KERNEL_NAME "Simd2xNN"
|
|
|
|
# define CLUSTER_N (VECTOR_WIDTH / 2)
|
2023-03-23 02:17:27 +01:00
|
|
|
# define UNROLL_I 4
|
2023-03-23 00:58:25 +01:00
|
|
|
# define UNROLL_J 2
|
2022-11-08 18:33:23 +01:00
|
|
|
# define computeForceLJ computeForceLJ_2xnn
|
2022-03-09 02:25:39 +01:00
|
|
|
// Simd4xN
|
2022-11-08 18:33:23 +01:00
|
|
|
# else
|
|
|
|
# define KERNEL_NAME "Simd4xN"
|
|
|
|
# define CLUSTER_N VECTOR_WIDTH
|
2023-03-23 02:17:27 +01:00
|
|
|
# define UNROLL_I 4
|
2023-03-23 00:58:25 +01:00
|
|
|
# define UNROLL_J 1
|
2022-11-08 18:33:23 +01:00
|
|
|
# define computeForceLJ computeForceLJ_4xn
|
|
|
|
# endif
|
|
|
|
# ifdef USE_REFERENCE_VERSION
|
|
|
|
# undef KERNEL_NAME
|
|
|
|
# undef computeForceLJ
|
|
|
|
# define KERNEL_NAME "Reference"
|
|
|
|
# define computeForceLJ computeForceLJ_ref
|
|
|
|
# endif
|
|
|
|
# define initialIntegrate cpuInitialIntegrate
|
|
|
|
# define finalIntegrate cpuFinalIntegrate
|
|
|
|
# define updatePbc cpuUpdatePbc
|
2022-03-09 02:25:39 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CLUSTER_M == CLUSTER_N
|
|
|
|
# define CJ0_FROM_CI(a) (a)
|
|
|
|
# define CJ1_FROM_CI(a) (a)
|
|
|
|
# define CI_BASE_INDEX(a,b) ((a) * CLUSTER_N * (b))
|
|
|
|
# define CJ_BASE_INDEX(a,b) ((a) * CLUSTER_N * (b))
|
|
|
|
#elif CLUSTER_M == CLUSTER_N * 2 // M > N
|
|
|
|
# define CJ0_FROM_CI(a) ((a) << 1)
|
|
|
|
# define CJ1_FROM_CI(a) (((a) << 1) | 0x1)
|
|
|
|
# define CI_BASE_INDEX(a,b) ((a) * CLUSTER_M * (b))
|
|
|
|
# define CJ_BASE_INDEX(a,b) (((a) >> 1) * CLUSTER_M * (b) + ((a) & 0x1) * (CLUSTER_M >> 1))
|
|
|
|
#elif CLUSTER_M == CLUSTER_N / 2 // M < N
|
|
|
|
# define CJ0_FROM_CI(a) ((a) >> 1)
|
|
|
|
# define CJ1_FROM_CI(a) ((a) >> 1)
|
|
|
|
# define CI_BASE_INDEX(a,b) (((a) >> 1) * CLUSTER_N * (b) + ((a) & 0x1) * (CLUSTER_N >> 1))
|
|
|
|
# define CJ_BASE_INDEX(a,b) ((a) * CLUSTER_N * (b))
|
|
|
|
#else
|
|
|
|
# error "Invalid cluster configuration!"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CLUSTER_N != 2 && CLUSTER_N != 4 && CLUSTER_N != 8
|
|
|
|
# error "Cluster N dimension can be only 2, 4 and 8"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define CI_SCALAR_BASE_INDEX(a) (CI_BASE_INDEX(a, 1))
|
|
|
|
#define CI_VECTOR_BASE_INDEX(a) (CI_BASE_INDEX(a, 3))
|
|
|
|
#define CJ_SCALAR_BASE_INDEX(a) (CJ_BASE_INDEX(a, 1))
|
|
|
|
#define CJ_VECTOR_BASE_INDEX(a) (CJ_BASE_INDEX(a, 3))
|
|
|
|
|
|
|
|
#if CLUSTER_M >= CLUSTER_N
|
|
|
|
# define CL_X_OFFSET (0 * CLUSTER_M)
|
|
|
|
# define CL_Y_OFFSET (1 * CLUSTER_M)
|
|
|
|
# define CL_Z_OFFSET (2 * CLUSTER_M)
|
|
|
|
#else
|
|
|
|
# define CL_X_OFFSET (0 * CLUSTER_N)
|
|
|
|
# define CL_Y_OFFSET (1 * CLUSTER_N)
|
|
|
|
# define CL_Z_OFFSET (2 * CLUSTER_N)
|
|
|
|
#endif
|
2022-01-25 00:43:10 +01:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int natoms;
|
|
|
|
MD_FLOAT bbminx, bbmaxx;
|
|
|
|
MD_FLOAT bbminy, bbmaxy;
|
|
|
|
MD_FLOAT bbminz, bbmaxz;
|
|
|
|
} Cluster;
|
|
|
|
|
2020-08-18 14:27:28 +02:00
|
|
|
typedef struct {
|
|
|
|
int Natoms, Nlocal, Nghost, Nmax;
|
2024-04-15 16:53:25 +02:00
|
|
|
int Nclusters, Nclusters_local, Nclusters_ghost, Nclusters_max, NmaxGhost,ncj;
|
2020-11-05 12:41:44 +01:00
|
|
|
MD_FLOAT *x, *y, *z;
|
|
|
|
MD_FLOAT *vx, *vy, *vz;
|
2021-11-03 00:57:24 +01:00
|
|
|
int *border_map;
|
2021-05-19 23:51:02 +02:00
|
|
|
int *type;
|
|
|
|
int ntypes;
|
|
|
|
MD_FLOAT *epsilon;
|
|
|
|
MD_FLOAT *sigma6;
|
|
|
|
MD_FLOAT *cutforcesq;
|
|
|
|
MD_FLOAT *cutneighsq;
|
2024-04-15 16:53:25 +02:00
|
|
|
//track the movement of a particle along boundaries
|
2022-01-25 12:19:28 +01:00
|
|
|
int *PBCx, *PBCy, *PBCz;
|
2022-03-09 02:25:39 +01:00
|
|
|
// Data in cluster format
|
|
|
|
MD_FLOAT *cl_x;
|
|
|
|
MD_FLOAT *cl_v;
|
|
|
|
MD_FLOAT *cl_f;
|
|
|
|
int *cl_type;
|
|
|
|
Cluster *iclusters, *jclusters;
|
2022-03-10 01:31:50 +01:00
|
|
|
int *icluster_bin;
|
2022-03-10 22:33:41 +01:00
|
|
|
int dummy_cj;
|
2023-03-23 00:58:25 +01:00
|
|
|
MD_UINT *exclusion_filter;
|
2023-03-23 02:17:27 +01:00
|
|
|
MD_FLOAT *diagonal_4xn_j_minus_i;
|
|
|
|
MD_FLOAT *diagonal_2xnn_j_minus_i;
|
2023-03-28 19:33:26 +02:00
|
|
|
unsigned int masks_2xnn_hn[8];
|
|
|
|
unsigned int masks_2xnn_fn[8];
|
2023-03-28 22:30:30 +02:00
|
|
|
unsigned int masks_4xn_hn[16];
|
|
|
|
unsigned int masks_4xn_fn[16];
|
2024-04-15 16:53:25 +02:00
|
|
|
|
|
|
|
//Info Subdomain
|
|
|
|
Box mybox;
|
2020-08-18 14:27:28 +02:00
|
|
|
} Atom;
|
|
|
|
|
2020-08-19 09:00:35 +02:00
|
|
|
extern void initAtom(Atom*);
|
2023-03-28 17:32:42 +02:00
|
|
|
extern void initMasks(Atom*);
|
2020-08-18 14:27:28 +02:00
|
|
|
extern void createAtom(Atom*, Parameter*);
|
2021-11-30 01:33:55 +01:00
|
|
|
extern int readAtom(Atom*, Parameter*);
|
2022-02-24 02:36:17 +01:00
|
|
|
extern int readAtom_pdb(Atom*, Parameter*);
|
2022-03-03 20:03:33 +01:00
|
|
|
extern int readAtom_gro(Atom*, Parameter*);
|
2022-02-24 02:36:17 +01:00
|
|
|
extern int readAtom_dmp(Atom*, Parameter*);
|
2020-08-18 14:27:28 +02:00
|
|
|
extern void growAtom(Atom*);
|
2022-01-25 00:43:10 +01:00
|
|
|
extern void growClusters(Atom*);
|
|
|
|
|
2024-04-15 16:53:25 +02:00
|
|
|
int packGhost(Atom*, int, MD_FLOAT* , int*);
|
|
|
|
int unpackGhost(Atom*, int, MD_FLOAT*);
|
|
|
|
int packExchange(Atom*, int, MD_FLOAT*);
|
|
|
|
int unpackExchange(Atom*, int, MD_FLOAT*);
|
|
|
|
void packForward(Atom*, int, int*, MD_FLOAT*, int*);
|
|
|
|
void unpackForward(Atom*, int, int, MD_FLOAT*);
|
|
|
|
void packReverse(Atom* , int , int , MD_FLOAT*);
|
|
|
|
void unpackReverse(Atom*, int, int*, MD_FLOAT*);
|
|
|
|
void pbc(Atom*);
|
|
|
|
void copy(Atom*, int, int);
|
|
|
|
|
|
|
|
|
2021-03-20 18:32:50 +01:00
|
|
|
#ifdef AOS
|
2022-08-17 17:56:31 +02:00
|
|
|
# define POS_DATA_LAYOUT "AoS"
|
|
|
|
# define atom_x(i) atom->x[(i) * 3 + 0]
|
|
|
|
# define atom_y(i) atom->x[(i) * 3 + 1]
|
|
|
|
# define atom_z(i) atom->x[(i) * 3 + 2]
|
|
|
|
/*
|
|
|
|
# define atom_vx(i) atom->vx[(i) * 3 + 0]
|
|
|
|
# define atom_vy(i) atom->vx[(i) * 3 + 1]
|
|
|
|
# define atom_vz(i) atom->vx[(i) * 3 + 2]
|
|
|
|
# define atom_fx(i) atom->fx[(i) * 3 + 0]
|
|
|
|
# define atom_fy(i) atom->fx[(i) * 3 + 1]
|
|
|
|
# define atom_fz(i) atom->fx[(i) * 3 + 2]
|
|
|
|
*/
|
2021-03-20 18:32:50 +01:00
|
|
|
#else
|
2022-08-17 17:56:31 +02:00
|
|
|
# define POS_DATA_LAYOUT "SoA"
|
|
|
|
# define atom_x(i) atom->x[i]
|
|
|
|
# define atom_y(i) atom->y[i]
|
|
|
|
# define atom_z(i) atom->z[i]
|
2022-02-02 18:00:44 +01:00
|
|
|
#endif
|
|
|
|
|
2022-08-17 17:56:31 +02:00
|
|
|
// TODO: allow to switch velocites and forces to AoS
|
|
|
|
# define atom_vx(i) atom->vx[i]
|
|
|
|
# define atom_vy(i) atom->vy[i]
|
|
|
|
# define atom_vz(i) atom->vz[i]
|
|
|
|
# define atom_fx(i) atom->fx[i]
|
|
|
|
# define atom_fy(i) atom->fy[i]
|
|
|
|
# define atom_fz(i) atom->fz[i]
|
|
|
|
|
2020-08-18 14:27:28 +02:00
|
|
|
#endif
|