maxwelllink.matter.md.kernels.kernels_qtip4pf module¶
Compiled q-TIP4P/F forces for the CPU and the GPU.
Note: The CPU runs in float64 throughout, while the GPU runs the bonded term in float64 and the non-bonded sums in float32, because consumer GPUs run float64 at 1/64 speed.
- class maxwelllink.matter.md.kernels.kernels_qtip4pf.QTIP4PFForceKernels[source]¶
Bases:
objectCompiled q-TIP4P/F forces for a batch of identical systems.
- __init__(ff, xp, threads_per_block=THREADS_PER_BLOCK)[source]¶
Compile the kernels and upload the constants of one water force field.
- Parameters:
ff (qtip4pf.QTIP4PFForceField) – A constructed force field; its geometry, box and cutoffs are read here.
xp (module) – Array module:
numpyfor the CPU path,cupyfor the GPU path.threads_per_block (int, default: 128) – CUDA block size, ignored on the CPU path.
- forces_cpu(x, F, efield, terms=None)[source]¶
Evaluate the force and potential of one system.
- Parameters:
x (numpy.ndarray of float, shape (na, 3)) – Atomic positions in atomic units (Bohr).
F (numpy.ndarray of float, shape (na, 3)) – Output force array, overwritten in place.
efield (numpy.ndarray of float, shape (3,)) – Effective electric field in atomic units.
terms (numpy.ndarray of float, shape (2,), optional) – Output stretch and bend energy, in the order of
reported_term_names.
- Returns:
Mechanical potential energy in atomic units (Hartree).
- Return type:
float
- forces_gpu(x, F, potential, efield, terms=None)[source]¶
Evaluate the force and potential of every system with two kernel launches.
- Parameters:
x (cupy.ndarray of float, shape (num, na, 3)) – Atomic positions of every system in atomic units (Bohr).
F (cupy.ndarray of float, shape (num, na, 3)) – Output force array, overwritten in place.
potential (cupy.ndarray of float, shape (num,)) – Output potential energy of every system.
efield (cupy.ndarray of float, shape (num, 3)) – Effective electric field of every system in atomic units.
terms (cupy.ndarray of float, shape (num, 2), optional) – Output stretch and bend energy of every system, in the order of
reported_term_names.
- reported_term_names = ('stretch_au', 'bend_au')¶
- maxwelllink.matter.md.kernels.kernels_qtip4pf.build_cpu_kernel()[source]¶
Build (once per process) the
njitq-TIP4P/F force evaluator.- Returns:
compute(x, F, efield, sites, fsite, s_re, s_im, q3, kvec, ak, par)returning the potential energy; all arrays float64.- Return type:
callable
- maxwelllink.matter.md.kernels.kernels_qtip4pf.build_cuda_kernels(n_atoms, n_kvec, threads_per_block=THREADS_PER_BLOCK)[source]¶
Build (once per shape) the CUDA force kernels for a batch of water systems.
One block handles one system with two kernels:
intraBonded stretches and bend in float64; writes the force array.
nonbondedLennard-Jones, Ewald and the external field in float32, then the chain-rule redistribution of the M-site force; adds to the force array.
- Parameters:
n_atoms (int) – Atoms and half-space k-vectors per system; both become compile-time loop bounds and size the per-system work arrays. Those live in static shared memory when they fit its 48 KB (the fastest path) and in global memory otherwise (see
QTIP4PFForceKernels.forces_gpu()), so the system size is bounded by the device memory.n_kvec (int) – Atoms and half-space k-vectors per system; both become compile-time loop bounds and size the per-system work arrays. Those live in static shared memory when they fit its 48 KB (the fastest path) and in global memory otherwise (see
QTIP4PFForceKernels.forces_gpu()), so the system size is bounded by the device memory.threads_per_block (int, default: 128) – CUDA block size, a multiple of the warp size (32).
- Returns:
The kernels, keyed
"intra"and"nonbonded", and the flag"work_in_shared"telling which non-bonded variant was chosen.- Return type:
dict
- Raises:
ImportError – If numba’s CUDA target is unavailable.