ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
p3m_gpu_cuda.cu File Reference

P3M electrostatics on GPU. More...

#include <config/config.hpp>
#include "electrostatics/p3m_gpu_cuda.cuh"
#include "cuda/utils.cuh"
#include "p3m/math.hpp"
#include "system/System.hpp"
#include <instrumentation/fe_trap.hpp>
#include <utils/math/bspline.hpp>
#include <utils/math/int_pow.hpp>
#include <utils/math/sqr.hpp>
#include <cuda.h>
#include <cufft.h>
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <limits>
#include <numbers>
#include <stdexcept>
#include <tuple>
Include dependency graph for p3m_gpu_cuda.cu:

Go to the source code of this file.

Classes

struct  P3MGpuData
struct  P3MGpuFftPlan
struct  P3MGpuParams

Namespaces

namespace  anonymous_namespace{p3m_gpu_cuda.cu}

Macros

#define ESPRESSO_P3M_GPU_FLOAT
#define REAL_TYPE   float
#define FFT_TYPE_COMPLEX   cufftComplex
#define FFT_FORW_FFT   cufftExecR2C
#define FFT_BACK_FFT   cufftExecC2R
#define FFT_PLAN_FORW_FLAG   CUFFT_R2C
#define FFT_PLAN_BACK_FLAG   CUFFT_C2R

Functions

static auto p3m_calc_blocks (unsigned int cao, std::size_t n_part)
dim3 p3m_make_grid (unsigned int n_blocks)
static auto p3m_calc_topology (unsigned int cao, std::size_t n_part)
 Calculate the topology of a kernel launch.
template<int cao>
__device__ static void Aliasing_sums_ik (const P3MGpuData p, int NX, int NY, int NZ, REAL_TYPE *Zaehler, REAL_TYPE *Nenner)
template<int cao>
__global__ void calculate_influence_function_device (const P3MGpuData p)
__device__ auto anonymous_namespace{p3m_gpu_cuda.cu}::linear_index_r (P3MGpuData const &p, int i, int j, int k)
__device__ auto anonymous_namespace{p3m_gpu_cuda.cu}::linear_index_k (P3MGpuData const &p, int i, int j, int k)
__global__ void apply_diff_op (const P3MGpuData p)
__device__ int wrap_index (const int ind, const int mesh)
__global__ void apply_influence_function (const P3MGpuData p)
template<int cao, bool shared>
__global__ void assign_charge_kernel (P3MGpuData const params, float const *const __restrict__ part_pos, float const *const __restrict__ part_q, unsigned int const parts_per_block)
void assign_charges (P3MGpuData const &params, float const *const __restrict__ part_pos, float const *const __restrict__ part_q)
template<int cao, bool shared>
__global__ void assign_forces_kernel (P3MGpuData const params, float const *const __restrict__ part_pos, float const *const __restrict__ part_q, float *const __restrict__ part_f, REAL_TYPE prefactor, unsigned int const parts_per_block)
void assign_forces (P3MGpuData const &params, float const *const __restrict__ part_pos, float const *const __restrict__ part_q, float *const __restrict__ part_f, REAL_TYPE const prefactor)
void p3m_gpu_init (std::shared_ptr< P3MGpuParams > &data, int cao, Utils::Vector3i const &mesh, double alpha, Utils::Vector3d const &box_l, std::size_t n_part)
 Initialize the internal data structure of the P3M GPU.
void p3m_gpu_add_farfield_force (P3MGpuParams &data, GpuParticleData &gpu, double prefactor, std::size_t n_part)
 The long-range part of the P3M algorithm.
template<unsigned n, typename T>
DEVICE_QUALIFIER constexpr T int_pow (T x)
 Calculate integer powers.
template<typename T>
DEVICE_QUALIFIER constexpr T sqr (T x)
 Calculates the SQuaRe of x.

Detailed Description

P3M electrostatics on GPU.

The corresponding header file is p3m_gpu_cuda.cuh.

Definition in file p3m_gpu_cuda.cu.

Macro Definition Documentation

◆ ESPRESSO_P3M_GPU_FLOAT

#define ESPRESSO_P3M_GPU_FLOAT

Definition at line 32 of file p3m_gpu_cuda.cu.

◆ FFT_BACK_FFT

#define FFT_BACK_FFT   cufftExecC2R

Definition at line 39 of file p3m_gpu_cuda.cu.

Referenced by p3m_gpu_add_farfield_force().

◆ FFT_FORW_FFT

#define FFT_FORW_FFT   cufftExecR2C

Definition at line 38 of file p3m_gpu_cuda.cu.

Referenced by p3m_gpu_add_farfield_force().

◆ FFT_PLAN_BACK_FLAG

#define FFT_PLAN_BACK_FLAG   CUFFT_C2R

Definition at line 41 of file p3m_gpu_cuda.cu.

Referenced by p3m_gpu_init().

◆ FFT_PLAN_FORW_FLAG

#define FFT_PLAN_FORW_FLAG   CUFFT_R2C

Definition at line 40 of file p3m_gpu_cuda.cu.

Referenced by p3m_gpu_init().

◆ FFT_TYPE_COMPLEX

#define FFT_TYPE_COMPLEX   cufftComplex

Definition at line 37 of file p3m_gpu_cuda.cu.

Referenced by apply_diff_op(), and p3m_gpu_init().

◆ REAL_TYPE

Function Documentation

◆ Aliasing_sums_ik()

template<int cao>
__device__ static void Aliasing_sums_ik ( const P3MGpuData p,
int NX,
int NY,
int NZ,
REAL_TYPE * Zaehler,
REAL_TYPE * Nenner )
static

◆ apply_diff_op()

◆ apply_influence_function()

__global__ void apply_influence_function ( const P3MGpuData p)

◆ assign_charge_kernel()

template<int cao, bool shared>
__global__ void assign_charge_kernel ( P3MGpuData const params,
float const *const __restrict__ part_pos,
float const *const __restrict__ part_q,
unsigned int const parts_per_block )

◆ assign_charges()

void assign_charges ( P3MGpuData const & params,
float const *const __restrict__ part_pos,
float const *const __restrict__ part_q )

◆ assign_forces()

void assign_forces ( P3MGpuData const & params,
float const *const __restrict__ part_pos,
float const *const __restrict__ part_q,
float *const __restrict__ part_f,
REAL_TYPE const prefactor )

◆ assign_forces_kernel()

template<int cao, bool shared>
__global__ void assign_forces_kernel ( P3MGpuData const params,
float const *const __restrict__ part_pos,
float const *const __restrict__ part_q,
float *const __restrict__ part_f,
REAL_TYPE prefactor,
unsigned int const parts_per_block )

◆ calculate_influence_function_device()

template<int cao>
__global__ void calculate_influence_function_device ( const P3MGpuData p)

◆ int_pow()

template<unsigned n, typename T>
DEVICE_QUALIFIER constexpr T Utils::int_pow ( T x)
constexpr

Calculate integer powers.

This functions calculates x^n, where n is a positive integer that is known at compile time. It uses exponentiation by squaring to construct an efficient function.

Definition at line 34 of file int_pow.hpp.

Referenced by Aliasing_sums_ik(), gb_pair_energy(), gb_pair_force(), and p3m_k_space_error_gpu_kernel_ik().

◆ p3m_calc_blocks()

auto p3m_calc_blocks ( unsigned int cao,
std::size_t n_part )
static

Definition at line 144 of file p3m_gpu_cuda.cu.

References Utils::int_pow().

Referenced by p3m_calc_topology().

◆ p3m_calc_topology()

auto p3m_calc_topology ( unsigned int cao,
std::size_t n_part )
static

Calculate the topology of a kernel launch.

Each particle spreads its charge on a cube of size cao, hence cao^3 threads are needed per particle. Each block may only contain up to 1024 threads. Compute the maximal number of particles that can be processed by a block, and the total number of blocks to allocate to process all particles. Distribute these blocks on a 2D grid, since each accelerator may only contain up to 2^16 blocks per dimension.

Definition at line 176 of file p3m_gpu_cuda.cu.

References block(), p3m_calc_blocks(), p3m_make_grid(), and REAL_TYPE.

Referenced by assign_charges(), and assign_forces().

◆ p3m_gpu_add_farfield_force()

◆ p3m_gpu_init()

void p3m_gpu_init ( std::shared_ptr< P3MGpuParams > & data,
int cao,
Utils::Vector3i const & mesh,
double alpha,
Utils::Vector3d const & box_l,
std::size_t n_part )

Initialize the internal data structure of the P3M GPU.

Mainly allocation on the device and influence function calculation. Be advised: this needs mesh^3*5*sizeof(REAL_TYPE) of device memory. We use real to complex FFTs, so the size of the reciprocal mesh is (cuFFT convention) Nx * Ny * ( Nz /2 + 1 ).

Definition at line 559 of file p3m_gpu_cuda.cu.

References block(), Utils::Vector< int, N >::broadcast(), calculate_influence_function_device(), cuda_safe_mem, FFT_PLAN_BACK_FLAG, FFT_PLAN_FORW_FLAG, FFT_TYPE_COMPLEX, KERNELCALL, fe_trap::make_shared_pause_scoped(), and REAL_TYPE.

Referenced by CoulombP3MImpl< FloatType, Architecture, FFTConfig >::init_gpu_kernels().

◆ p3m_make_grid()

dim3 p3m_make_grid ( unsigned int n_blocks)

Definition at line 155 of file p3m_gpu_cuda.cu.

Referenced by p3m_calc_topology().

◆ sqr()

template<typename T>
DEVICE_QUALIFIER constexpr T Utils::sqr ( T x)
constexpr

◆ wrap_index()

__device__ int wrap_index ( const int ind,
const int mesh )
inline

Definition at line 317 of file p3m_gpu_cuda.cu.

Referenced by assign_charge_kernel(), and assign_forces_kernel().