yasfpy.functions.cuda_numba =========================== .. py:module:: yasfpy.functions.cuda_numba .. autoapi-nested-parse:: CUDA kernels accelerated with Numba. This module contains GPU implementations of inner loops used for coupling and field/polarization calculations. Functions --------- .. autoapisummary:: yasfpy.functions.cuda_numba.particle_interaction_gpu yasfpy.functions.cuda_numba.particle_interaction_gpu_single_wavelength yasfpy.functions.cuda_numba.particle_interaction_gpu_single_wavelength_block_row_256 yasfpy.functions.cuda_numba.particle_interaction_gpu_single_wavelength_lut yasfpy.functions.cuda_numba.particle_interaction_gpu_single_wavelength_block_row_256_lut yasfpy.functions.cuda_numba.particle_interaction_gpu_single_wavelength_lut_chunk yasfpy.functions.cuda_numba.particle_interaction_gpu_single_wavelength_block_row_256_lut_chunk yasfpy.functions.cuda_numba.compute_scattering_cross_section_gpu yasfpy.functions.cuda_numba.compute_radial_independent_scattered_field_gpu yasfpy.functions.cuda_numba.compute_electric_field_angle_components_gpu yasfpy.functions.cuda_numba.compute_polarization_components_gpu yasfpy.functions.cuda_numba.compute_plane_wave_field_gpu yasfpy.functions.cuda_numba.compute_field_gpu Module Contents --------------- .. py:function:: 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()`. .. py:function:: 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()`. .. py:function:: 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. .. rubric:: Notes - Requires blocks of exactly 256 threads. .. py:function:: 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. .. py:function:: 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`. .. rubric:: Notes - Requires blocks of exactly 256 threads. .. py:function:: 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. .. py:function:: 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. .. rubric:: Notes - Requires blocks of exactly 256 threads. - Launch with `blocks_per_grid = j1_count`. .. py:function:: 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. :param lmax: The maximum degree of the spherical harmonics expansion. :type lmax: int :param particle_number: The number of particles. :type particle_number: int :param idx: The index array. :type idx: np.ndarray :param sfc: The scattering form factor array. :type sfc: np.ndarray :param translation_table: The translation table array. :type translation_table: np.ndarray :param plm: The associated Legendre polynomials array. :type plm: np.ndarray :param sph_h: The spherical harmonics array. :type sph_h: np.ndarray :param e_j_dm_phi: The phase factor array. :type e_j_dm_phi: np.ndarray :param c_sca_real: The real part of the scattering cross section array. :type c_sca_real: np.ndarray :param c_sca_imag: The imaginary part of the scattering cross section array. :type c_sca_imag: np.ndarray .. py:function:: 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. :param lmax: The maximum degree of the spherical harmonics expansion. :type lmax: int :param particles_position: Array of particle positions. :type particles_position: np.ndarray :param idx: Array of indices for particle properties. :type idx: np.ndarray :param sfc: Array of scattering form factors. :type sfc: np.ndarray :param k_medium: Array of wave numbers in the medium. :type k_medium: np.ndarray :param azimuthal_angles: Array of azimuthal angles. :type azimuthal_angles: np.ndarray :param e_r: Array of radial electric field components. :type e_r: np.ndarray :param e_phi: Array of azimuthal electric field components. :type e_phi: np.ndarray :param e_theta: Array of polar electric field components. :type e_theta: np.ndarray :param pilm: Array of associated Legendre polynomials. :type pilm: np.ndarray :param taulm: Array of tau coefficients. :type taulm: np.ndarray :param e_1_sca_real: Array of real parts of the scattered electric field. :type e_1_sca_real: np.ndarray :param e_1_sca_imag: Array of imaginary parts of the scattered electric field. :type e_1_sca_imag: np.ndarray .. py:function:: 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. :param lmax: The maximum angular momentum quantum number. :type lmax: int :param particles_position: Array of particle positions. :type particles_position: np.ndarray :param idx: Array of indices. :type idx: np.ndarray :param sfc: Array of scattering form factors. :type sfc: np.ndarray :param k_medium: Array of medium wavevectors. :type k_medium: np.ndarray :param azimuthal_angles: Array of azimuthal angles. :type azimuthal_angles: np.ndarray :param e_r: Array of radial unit vectors. :type e_r: np.ndarray :param pilm: Array of associated Legendre polynomials. :type pilm: np.ndarray :param taulm: Array of tau coefficients. :type taulm: np.ndarray :param e_field_theta_real: Array of real parts of electric field theta component. :type e_field_theta_real: np.ndarray :param e_field_theta_imag: Array of imaginary parts of electric field theta component. :type e_field_theta_imag: np.ndarray :param e_field_phi_real: Array of real parts of electric field phi component. :type e_field_phi_real: np.ndarray :param e_field_phi_imag: Array of imaginary parts of electric field phi component. :type e_field_phi_imag: np.ndarray .. py:function:: 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. :param number_of_wavelengths: Number of wavelengths. :type number_of_wavelengths: int :param number_of_angles: Number of angles. :type number_of_angles: int :param e_field_theta_real: Real part of the electric field in the theta direction. :type e_field_theta_real: np.ndarray :param e_field_theta_imag: Imaginary part of the electric field in the theta direction. :type e_field_theta_imag: np.ndarray :param e_field_phi_real: Real part of the electric field in the phi direction. :type e_field_phi_real: np.ndarray :param e_field_phi_imag: Imaginary part of the electric field in the phi direction. :type e_field_phi_imag: np.ndarray :param intensity: Array to store the intensity component. :type intensity: np.ndarray :param degree_of_polarization: Array to store the degree of polarization component. :type degree_of_polarization: np.ndarray :param degree_of_linear_polarization: Array to store the degree of linear polarization component. :type degree_of_linear_polarization: np.ndarray :param degree_of_linear_polarization_q: Array to store the degree of linear polarization (Q) component. :type degree_of_linear_polarization_q: np.ndarray :param degree_of_linear_polarization_u: Array to store the degree of linear polarization (U) component. :type degree_of_linear_polarization_u: np.ndarray :param degree_of_circular_polarization: Array to store the degree of circular polarization component. :type degree_of_circular_polarization: np.ndarray .. py:function:: 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). .. py:function:: 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. :param lmax: Maximum degree of the spherical harmonics. :type lmax: int :param idx: Array of indices. :type idx: np.ndarray :param size_parameter: Array of size parameters. :type size_parameter: np.ndarray :param sph_h: Array of spherical harmonics. :type sph_h: np.ndarray :param derivative: Array of derivatives. :type derivative: np.ndarray :param e_j_dm_phi: Array of phi-dependent terms. :type e_j_dm_phi: np.ndarray :param p_lm: Array of Legendre polynomials. :type p_lm: np.ndarray :param pi_lm: Array of pi-dependent terms. :type pi_lm: np.ndarray :param tau_lm: Array of tau-dependent terms. :type tau_lm: np.ndarray :param e_r: Array of r-dependent terms. :type e_r: np.ndarray :param e_theta: Array of theta-dependent terms. :type e_theta: np.ndarray :param e_phi: Array of phi-dependent terms. :type e_phi: np.ndarray :param scattered_field_coefficients: Array of scattered field coefficients. :type scattered_field_coefficients: np.ndarray :param field_real: Array to store the real part of the field. :type field_real: np.ndarray :param field_imag: Array to store the imaginary part of the field. :type field_imag: np.ndarray