Loading...
Searching...
No Matches
q3::GPUPlanewaveHamiltonianApplicator Class Reference

#include <gpu.hpp>

+ Inheritance diagram for q3::GPUPlanewaveHamiltonianApplicator:

Public Member Functions

 GPUPlanewaveHamiltonianApplicator (const Crystal &crystal_structure, const PlanewaveBasis &planewave_basis, const KPointsGrid &kpoint_grid, const NormConservingPlanewaveKohnShamQuantumSystem &pseudopotential_quantum_system, execution::gpu::blas::GPUBLAS &gpu_blas, gpu::GPUFFTGrid *gpu_fft_grid, std::shared_ptr< execution::gpu::device::GPUDeviceBackend > device_backend)
 
void apply_batch (const Complex *input_wavefunctions, Complex *output_hamiltonian_wavefunctions, int number_of_vectors) override
 
void apply_batch_single_precision (const ComplexSingle *input_wavefunctions, ComplexSingle *output_hamiltonian_wavefunctions, int number_of_vectors)
 
const std::vector< Real > & cached_scaled_potential () const
 
const std::vector< int > & g_to_fft_mapping () const
 
const q3::Matrix< Complex > * get_cached_projectors (int) const override
 
void invalidate_smooth_potential_cache () override
 
bool is_gamma_only_current () const override
 
bool is_smooth_potential_cache_valid () const override
 
const std::vector< int > & minus_g_to_fft_mapping () const
 
void prepare_kpoint (int kpoint_index, int number_of_plane_waves, const std::vector< int > &g_vector_indices, const std::vector< Real > &kinetic_energy_squared) override
 
void set_cached_projectors (int, const q3::Matrix< Complex > *) override
 
void set_use_mixed_precision (bool use_mixed_precision)
 
void update_potential (const std::vector< Real > &real_space_potential) override
 
- Public Member Functions inherited from q3::PlanewaveHamiltonianApplicator
virtual ~PlanewaveHamiltonianApplicator ()=default
 
virtual bool gamma_origin_is_local_current () const
 
virtual void set_cached_hubbard_projectors (int kpoint_index, const q3::Matrix< Complex > *projectors)
 
virtual void set_hubbard_d_matrix (const std::vector< Complex > *dense_d_matrix_column_major)
 
void set_spin_channel (int spin_channel)
 
int spin_channel () const
 

Additional Inherited Members

- Protected Attributes inherited from q3::PlanewaveHamiltonianApplicator
int spin_channel_ {0}
 Spin channel the current potential and D belong to; 0 when unpolarized.
 

Detailed Description

Definition at line 51 of file gpu.hpp.

Constructor & Destructor Documentation

◆ GPUPlanewaveHamiltonianApplicator()

q3::GPUPlanewaveHamiltonianApplicator::GPUPlanewaveHamiltonianApplicator ( const Crystal &  crystal_structure,
const PlanewaveBasis &  planewave_basis,
const KPointsGrid &  kpoint_grid,
const NormConservingPlanewaveKohnShamQuantumSystem &  pseudopotential_quantum_system,
execution::gpu::blas::GPUBLAS &  gpu_blas,
gpu::GPUFFTGrid *  gpu_fft_grid,
std::shared_ptr< execution::gpu::device::GPUDeviceBackend >  device_backend 
)
inline

Construct with run-constant planewave context and GPU math wrappers.

All references and the shared_ptr must outlive this object.

Parameters
crystal_structureCrystal geometry.
planewave_basisPlanewave basis (G-vectors, FFT grids).
kpoint_gridK-point grid for Brillouin zone sampling.
pseudopotential_quantum_systemPseudopotential data (KB projectors, D-matrix).
gpu_blasGPU BLAS wrapper for matrix/vector operations.
gpu_fft_gridGPU FFT grid for potential application.
device_backendGPU device backend for memory allocation.

Initialize the GPU FFT grid with the wave (smooth) grid dimensions so that cuFFT plans are created before any FFT calls.

Definition at line 66 of file gpu.hpp.

References q3::PlanewaveBasis::fft_wave(), and q3::FFTGrid::init().

Member Function Documentation

◆ apply_batch()

void q3::GPUPlanewaveHamiltonianApplicator::apply_batch ( const Complex *  input_wavefunctions,
Complex *  output_hamiltonian_wavefunctions,
int  number_of_vectors 
)
inlineoverridevirtual

Apply H|ψ⟩ in double precision (FP64) to a batch of vectors.

Uses GPU BLAS for KB projector application (3× ZGEMM) and CPU-side FFT for the local potential application. The kinetic energy is applied element-wise on the host (unified memory).

All input/output pointers must come from GPUDeviceBuffer (unified memory).

Implements q3::PlanewaveHamiltonianApplicator.

Definition at line 258 of file gpu.hpp.

References q3::execution::gpu::device::GPUDeviceBuffer< T >::data(), q3::PlanewaveBasis::fft_wave(), q3::diagonalizer::planewave::gpu::launch_apply_kinetic_energy(), q3::FFTGrid::local_grid_points(), and q3::execution::gpu::device::GPUDeviceBuffer< T >::size().

◆ apply_batch_single_precision()

void q3::GPUPlanewaveHamiltonianApplicator::apply_batch_single_precision ( const ComplexSingle *  input_wavefunctions,
ComplexSingle *  output_hamiltonian_wavefunctions,
int  number_of_vectors 
)
inline

Apply H|ψ⟩ in single precision (FP32) to a batch of vectors.

Identical algorithm to apply_batch() but operates on ComplexSingle arrays and uses FP32 BLAS/FFT calls. Used by the mixed-precision Davidson loop for bulk iterations before switchover.

  1. Local potential via batched FFT in FP32. Scatter all bands → batch inverse FFT → V·ψ for all → batch forward FFT → gather all. This replaces 2×N single FFT calls with 2 batched kernel launches.

Definition at line 313 of file gpu.hpp.

References q3::execution::gpu::device::GPUDeviceBuffer< T >::data(), q3::PlanewaveBasis::fft_wave(), q3::gpu::GPUFFTGrid::forward_single_batch(), q3::gpu::GPUFFTGrid::inverse_raw_single_batch(), q3::PlanewaveBasis::is_gamma_only(), q3::diagonalizer::planewave::gpu::launch_apply_kinetic_energy_single(), q3::diagonalizer::planewave::gpu::launch_gather_fft_grid_to_g_single(), q3::diagonalizer::planewave::gpu::launch_multiply_potential_single(), q3::diagonalizer::planewave::gpu::launch_scatter_g_to_fft_grid_single(), q3::FFTGrid::local_grid_points(), and q3::execution::gpu::device::GPUDeviceBuffer< T >::size().

◆ cached_scaled_potential()

const std::vector< Real > & q3::GPUPlanewaveHamiltonianApplicator::cached_scaled_potential ( ) const
inline

Access the cached scaled potential (for serial fallback or debugging).

Definition at line 406 of file gpu.hpp.

◆ g_to_fft_mapping()

const std::vector< int > & q3::GPUPlanewaveHamiltonianApplicator::g_to_fft_mapping ( ) const
inline

Access the G-to-FFT mapping for the current k-point.

Definition at line 413 of file gpu.hpp.

◆ get_cached_projectors()

const q3::Matrix< Complex > * q3::GPUPlanewaveHamiltonianApplicator::get_cached_projectors ( int  ) const
inlineoverridevirtual

Returns nullptr — GPU applicator manages projectors internally.

Reimplemented from q3::PlanewaveHamiltonianApplicator.

Definition at line 444 of file gpu.hpp.

◆ invalidate_smooth_potential_cache()

void q3::GPUPlanewaveHamiltonianApplicator::invalidate_smooth_potential_cache ( )
inlineoverridevirtual

Invalidate any cached smooth potential. Called when the effective potential changes (e.g., at start of each SCF iteration).

Implements q3::PlanewaveHamiltonianApplicator.

Definition at line 391 of file gpu.hpp.

◆ is_gamma_only_current()

bool q3::GPUPlanewaveHamiltonianApplicator::is_gamma_only_current ( ) const
inlineoverridevirtual

Report whether the current k-point is gamma-only.

This affects dot product computations in the subspace manager: gamma-only uses 2×Re(z·z*) instead of complex zdotc.

Reimplemented from q3::PlanewaveHamiltonianApplicator.

Definition at line 430 of file gpu.hpp.

References q3::PlanewaveBasis::is_gamma_only().

◆ is_smooth_potential_cache_valid()

bool q3::GPUPlanewaveHamiltonianApplicator::is_smooth_potential_cache_valid ( ) const
inlineoverridevirtual

Whether the smooth potential cache is currently valid.

Reimplemented from q3::PlanewaveHamiltonianApplicator.

Definition at line 399 of file gpu.hpp.

◆ minus_g_to_fft_mapping()

const std::vector< int > & q3::GPUPlanewaveHamiltonianApplicator::minus_g_to_fft_mapping ( ) const
inline

Access the minus-G-to-FFT mapping (for gamma-only scatter/gather).

Definition at line 420 of file gpu.hpp.

◆ prepare_kpoint()

void q3::GPUPlanewaveHamiltonianApplicator::prepare_kpoint ( int  kpoint_index,
int  number_of_plane_waves,
const std::vector< int > &  g_vector_indices,
const std::vector< Real > &  kinetic_energy_squared 
)
inlineoverridevirtual

◆ set_cached_projectors()

void q3::GPUPlanewaveHamiltonianApplicator::set_cached_projectors ( int  ,
const q3::Matrix< Complex > *   
)
inlineoverridevirtual

No-op: GPU applicator computes projectors internally in prepare_kpoint().

Reimplemented from q3::PlanewaveHamiltonianApplicator.

Definition at line 437 of file gpu.hpp.

◆ set_use_mixed_precision()

void q3::GPUPlanewaveHamiltonianApplicator::set_use_mixed_precision ( bool  use_mixed_precision)
inline

Enable or disable mixed-precision mode.

When enabled, apply_batch() runs the local potential FFT section in FP32 (scatter FP64→FP32, FFT, V*ψ, FFT, gather FP32→FP64). Kinetic energy and nonlocal projectors remain in FP64. This gives most of the GPU FP32 speedup without restructuring the Davidson loop.

Definition at line 115 of file gpu.hpp.

References q3::log::info().

◆ update_potential()

void q3::GPUPlanewaveHamiltonianApplicator::update_potential ( const std::vector< Real > &  real_space_potential)
inlineoverridevirtual

Update the effective potential for a new SCF iteration.

Computes the smooth-grid potential on CPU (same as serial), then copies the result to a GPUDeviceBuffer for GPU-side V(r)·ψ(r) multiplication.

Implements q3::PlanewaveHamiltonianApplicator.

Definition at line 129 of file gpu.hpp.

References q3::precision::cast_real_double_to_single(), q3::execution::gpu::device::GPUDeviceBuffer< T >::data(), q3::PlanewaveBasis::fft_wave(), q3::FFTGrid::local_grid_points(), and q3::FFTGrid::total_grid_points().


The documentation for this class was generated from the following file: