yasfpy.functions.cuda_numba#
CUDA kernels accelerated with Numba.
This module contains GPU implementations of inner loops used for coupling and field/polarization calculations.
Functions#
|
Dense coupling kernel using atomics. |
|
Dense coupling matvec for a single wavelength channel. |
|
Dense coupling matvec for a single wavelength using block-per-row reduction. |
Dense coupling matvec for a single wavelength using compact nmax lookup tables. |
|
|
Block-per-row single wavelength matvec using compact nmax lookup tables. |
Single-wavelength LUT matvec for a contiguous chunk of output rows. |
|
|
Block-per-row LUT matvec for a contiguous output chunk. |
|
Compute the scattering cross section on the GPU using CUDA. |
Compute the radial independent scattered field using GPU acceleration. |
|
|
Compute the electric field angle components on the GPU. |
Compute the polarization components using GPU acceleration. |
|
|
Compute incident plane-wave E/H fields at points (CELES PVWF_components). |
|
Compute the field on the GPU using CUDA. |
Module Contents#
- yasfpy.functions.cuda_numba.particle_interaction_gpu(lmax, particle_number, idx, x, wx_real, wx_imag, translation_table, plm, sph_h, e_j_dm_phi)#
Dense coupling kernel using atomics.
This kernel launches one thread per (j1, j2, w) contribution and accumulates into wx_* using atomic adds. It is simple but can be slow due to the huge number of threads and atomic contention.
For the solver’s single-wavelength matvec path, prefer particle_interaction_gpu_single_wavelength().
- yasfpy.functions.cuda_numba.particle_interaction_gpu_single_wavelength(lmax, particle_number, w_idx, idx, x, wx, translation_table, plm, sph_h, e_j_dm_phi)#
Dense coupling matvec for a single wavelength channel.
This is the baseline GPU kernel: one thread computes one output row.
For small/moderate problems this can underutilize the GPU, so we also provide a block-per-row reduction kernel: particle_interaction_gpu_single_wavelength_block_row().
- yasfpy.functions.cuda_numba.particle_interaction_gpu_single_wavelength_block_row_256(lmax, particle_number, w_idx, idx, x, wx, translation_table, plm, sph_h, e_j_dm_phi)#
Dense coupling matvec for a single wavelength using block-per-row reduction.
Mapping: - Each CUDA block computes one output row j1. - Threads in the block iterate over j2 in a strided loop and accumulate partial sums. - Partial sums are reduced in shared memory and written once.
This generally improves GPU occupancy for small/moderate jmax by increasing parallelism per row.
Notes
Requires blocks of exactly 256 threads.
- yasfpy.functions.cuda_numba.particle_interaction_gpu_single_wavelength_lut(lmax, particle_number, w_idx, tau_lut, l_lut, m_lut, x, wx, translation_table, plm, sph_h, e_j_dm_phi)#
Dense coupling matvec for a single wavelength using compact nmax lookup tables.
Compared to particle_interaction_gpu_single_wavelength, this avoids loading a large idx matrix from global memory. Instead we compute (s, n) from the flattened index j and use small lookup tables of size nmax for (tau, l, m).
Mapping: one thread computes one output row.
- yasfpy.functions.cuda_numba.particle_interaction_gpu_single_wavelength_block_row_256_lut(lmax, particle_number, w_idx, tau_lut, l_lut, m_lut, x, wx, translation_table, plm, sph_h, e_j_dm_phi)#
Block-per-row single wavelength matvec using compact nmax lookup tables.
This is the LUT-based counterpart to particle_interaction_gpu_single_wavelength_block_row_256.
Notes
Requires blocks of exactly 256 threads.
- yasfpy.functions.cuda_numba.particle_interaction_gpu_single_wavelength_lut_chunk(lmax, particle_number, w_idx, j1_offset, j1_count, tau_lut, l_lut, m_lut, x, wx, translation_table, plm, sph_h, e_j_dm_phi)#
Single-wavelength LUT matvec for a contiguous chunk of output rows.
Computes rows [j1_offset, j1_offset + j1_count) and stores them into wx[0:j1_count].
Intended for pipelining kernels and host transfers across chunks.
- yasfpy.functions.cuda_numba.particle_interaction_gpu_single_wavelength_block_row_256_lut_chunk(lmax, particle_number, w_idx, j1_offset, j1_count, tau_lut, l_lut, m_lut, x, wx, translation_table, plm, sph_h, e_j_dm_phi)#
Block-per-row LUT matvec for a contiguous output chunk.
Notes
Requires blocks of exactly 256 threads.
Launch with blocks_per_grid = j1_count.
- yasfpy.functions.cuda_numba.compute_scattering_cross_section_gpu(lmax, particle_number, idx, sfc, translation_table, plm, sph_h, e_j_dm_phi, c_sca_real, c_sca_imag)#
Compute the scattering cross section on the GPU using CUDA.
- Parameters:
lmax (int) – The maximum degree of the spherical harmonics expansion.
particle_number (int) – The number of particles.
idx (np.ndarray) – The index array.
sfc (np.ndarray) – The scattering form factor array.
translation_table (np.ndarray) – The translation table array.
plm (np.ndarray) – The associated Legendre polynomials array.
sph_h (np.ndarray) – The spherical harmonics array.
e_j_dm_phi (np.ndarray) – The phase factor array.
c_sca_real (np.ndarray) – The real part of the scattering cross section array.
c_sca_imag (np.ndarray) – The imaginary part of the scattering cross section array.
- yasfpy.functions.cuda_numba.compute_radial_independent_scattered_field_gpu(lmax, particles_position, idx, sfc, k_medium, azimuthal_angles, e_r, e_phi, e_theta, pilm, taulm, e_1_sca_real, e_1_sca_imag)#
Compute the radial independent scattered field using GPU acceleration.
- Parameters:
lmax (int) – The maximum degree of the spherical harmonics expansion.
particles_position (np.ndarray) – Array of particle positions.
idx (np.ndarray) – Array of indices for particle properties.
sfc (np.ndarray) – Array of scattering form factors.
k_medium (np.ndarray) – Array of wave numbers in the medium.
azimuthal_angles (np.ndarray) – Array of azimuthal angles.
e_r (np.ndarray) – Array of radial electric field components.
e_phi (np.ndarray) – Array of azimuthal electric field components.
e_theta (np.ndarray) – Array of polar electric field components.
pilm (np.ndarray) – Array of associated Legendre polynomials.
taulm (np.ndarray) – Array of tau coefficients.
e_1_sca_real (np.ndarray) – Array of real parts of the scattered electric field.
e_1_sca_imag (np.ndarray) – Array of imaginary parts of the scattered electric field.
- yasfpy.functions.cuda_numba.compute_electric_field_angle_components_gpu(lmax, particles_position, idx, sfc, k_medium, azimuthal_angles, e_r, pilm, taulm, e_field_theta_real, e_field_theta_imag, e_field_phi_real, e_field_phi_imag)#
Compute the electric field angle components on the GPU.
- Parameters:
lmax (int) – The maximum angular momentum quantum number.
particles_position (np.ndarray) – Array of particle positions.
idx (np.ndarray) – Array of indices.
sfc (np.ndarray) – Array of scattering form factors.
k_medium (np.ndarray) – Array of medium wavevectors.
azimuthal_angles (np.ndarray) – Array of azimuthal angles.
e_r (np.ndarray) – Array of radial unit vectors.
pilm (np.ndarray) – Array of associated Legendre polynomials.
taulm (np.ndarray) – Array of tau coefficients.
e_field_theta_real (np.ndarray) – Array of real parts of electric field theta component.
e_field_theta_imag (np.ndarray) – Array of imaginary parts of electric field theta component.
e_field_phi_real (np.ndarray) – Array of real parts of electric field phi component.
e_field_phi_imag (np.ndarray) – Array of imaginary parts of electric field phi component.
- yasfpy.functions.cuda_numba.compute_polarization_components_gpu(number_of_wavelengths, number_of_angles, e_field_theta_real, e_field_theta_imag, e_field_phi_real, e_field_phi_imag, intensity, degree_of_polarization, degree_of_linear_polarization, degree_of_linear_polarization_q, degree_of_linear_polarization_u, degree_of_circular_polarization)#
Compute the polarization components using GPU acceleration.
- Parameters:
number_of_wavelengths (int) – Number of wavelengths.
number_of_angles (int) – Number of angles.
e_field_theta_real (np.ndarray) – Real part of the electric field in the theta direction.
e_field_theta_imag (np.ndarray) – Imaginary part of the electric field in the theta direction.
e_field_phi_real (np.ndarray) – Real part of the electric field in the phi direction.
e_field_phi_imag (np.ndarray) – Imaginary part of the electric field in the phi direction.
intensity (np.ndarray) – Array to store the intensity component.
degree_of_polarization (np.ndarray) – Array to store the degree of polarization component.
degree_of_linear_polarization (np.ndarray) – Array to store the degree of linear polarization component.
degree_of_linear_polarization_q (np.ndarray) – Array to store the degree of linear polarization (Q) component.
degree_of_linear_polarization_u (np.ndarray) – Array to store the degree of linear polarization (U) component.
degree_of_circular_polarization (np.ndarray) – Array to store the degree of circular polarization component.
- yasfpy.functions.cuda_numba.compute_plane_wave_field_gpu(points, focal_point, direction, k_medium, n_medium_real, n_medium_imag, pol, amplitude, sin_alpha, cos_alpha, sin_beta, cos_beta, E_real, E_imag, H_real, H_imag)#
Compute incident plane-wave E/H fields at points (CELES PVWF_components).
- yasfpy.functions.cuda_numba.compute_field_gpu(lmax, idx, size_parameter, sph_h, derivative, e_j_dm_phi, p_lm, pi_lm, tau_lm, e_r, e_theta, e_phi, scattered_field_coefficients, field_real, field_imag)#
Compute the field on the GPU using CUDA.
- Parameters:
lmax (int) – Maximum degree of the spherical harmonics.
idx (np.ndarray) – Array of indices.
size_parameter (np.ndarray) – Array of size parameters.
sph_h (np.ndarray) – Array of spherical harmonics.
derivative (np.ndarray) – Array of derivatives.
e_j_dm_phi (np.ndarray) – Array of phi-dependent terms.
p_lm (np.ndarray) – Array of Legendre polynomials.
pi_lm (np.ndarray) – Array of pi-dependent terms.
tau_lm (np.ndarray) – Array of tau-dependent terms.
e_r (np.ndarray) – Array of r-dependent terms.
e_theta (np.ndarray) – Array of theta-dependent terms.
e_phi (np.ndarray) – Array of phi-dependent terms.
scattered_field_coefficients (np.ndarray) – Array of scattered field coefficients.
field_real (np.ndarray) – Array to store the real part of the field.
field_imag (np.ndarray) – Array to store the imaginary part of the field.