pub struct GpuContext { /* private fields */ }Expand description
Device, queue, and compiled recursion pipelines for one GPU adapter.
Implementations§
Source§impl GpuContext
impl GpuContext
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Acquires the highest-performance adapter available and compiles the shaders.
Backend selection honors the WGPU_BACKEND environment variable
(for example vulkan, metal, dx12) through wgpu’s defaults.
§Errors
RefloxideError::Gpu when no adapter or device can be obtained.
Sourcepub fn describe(&self) -> String
pub fn describe(&self) -> String
Human-readable adapter name and backend, for logs and benchmarks.
Sourcepub fn supports_f64(&self) -> bool
pub fn supports_f64(&self) -> bool
Whether the adapter provides native f64 shader arithmetic.
true on Vulkan and DX12 adapters that report shaderFloat64;
false on Metal. Gates GeneralPrecision::F64.
Sourcepub fn reflectivity_flat(
&self,
q: &[f32],
k0: &[f32],
layers: &[LayerCoeffs<f32>],
n_layers: usize,
) -> Result<Vec<[f32; 2]>>
pub fn reflectivity_flat( &self, q: &[f32], k0: &[f32], layers: &[LayerCoeffs<f32>], n_layers: usize, ) -> Result<Vec<[f32; 2]>>
Single-precision reflectance for many equal-depth stacks on a shared q-grid.
§Parameters
q: scattering vectors in1/Angstrom, lengthn_q.k0: vacuum wavenumber per stack in1/Angstrom, lengthn_stacks.layers: row-major(n_stacks, n_layers)layer records.n_layers: depth of every stack, at least two.
§Returns
Row-major (n_stacks, n_q) pairs [R_pp, R_ss], matching the
(0, 0) and (1, 1) entries of refloxide_tmm::kernel::PointResult.
§Errors
As for GpuContext::reflectivity_points.
Sourcepub fn reflectivity_points(
&self,
q: &[f32],
stack_of: &[u32],
k0: &[f32],
layers: &[LayerCoeffs<f32>],
n_layers: usize,
) -> Result<Vec<[f32; 2]>>
pub fn reflectivity_points( &self, q: &[f32], stack_of: &[u32], k0: &[f32], layers: &[LayerCoeffs<f32>], n_layers: usize, ) -> Result<Vec<[f32; 2]>>
Single-precision reflectance for independent (q, stack) points.
Each point carries its own stack index, so stacks (for example one per photon energy) may be paired with ragged q-grids in one dispatch.
§Parameters
q: scattering vector per point in1/Angstrom, lengthn_points.stack_of: stack index per point, each< n_stacks.k0: vacuum wavenumber per stack in1/Angstrom, lengthn_stacks.layers: row-major(n_stacks, n_layers)layer records.n_layers: depth of every stack, at least two.
§Returns
One [R_pp, R_ss] pair per point, in input order.
§Errors
RefloxideError::InvalidShape for inconsistent buffer lengths, an
out-of-range stack index, or a batch exceeding device buffer limits;
RefloxideError::Gpu when the readback fails.
Sourcepub fn reflectivity_points_jvp(
&self,
q: &[f32],
stack_of: &[u32],
k0: &[f32],
layers: &[LayerCoeffs<f32>],
n_layers: usize,
dq: &[f32],
dlayers: &[LayerCoeffs<f32>],
) -> Result<Vec<[f32; 4]>>
pub fn reflectivity_points_jvp( &self, q: &[f32], stack_of: &[u32], k0: &[f32], layers: &[LayerCoeffs<f32>], n_layers: usize, dq: &[f32], dlayers: &[LayerCoeffs<f32>], ) -> Result<Vec<[f32; 4]>>
Single-precision reflectance and directional derivatives for (q, stack) points.
Evaluates refloxide_tmm::kernel::solve_point_recursive_jvp for every
(direction, point) pair in one dispatch. Direction k perturbs the
layer records by dlayers[k] and the scattering vectors by dq[k].
§Parameters
q,stack_of,k0,layers,n_layers: as inGpuContext::reflectivity_points.dq: row-major(n_dirs, n_points)tangent ofq.dlayers: row-major(n_dirs, n_stacks, n_layers)tangent records.
§Returns
Row-major (n_dirs, n_points) entries [R_pp, R_ss, dR_pp, dR_ss];
the value columns repeat for every direction.
§Errors
As for GpuContext::reflectivity_points, plus
RefloxideError::InvalidShape when the tangent buffers do not match.
Sourcepub fn reflectivity_points_df64(
&self,
q: &[f64],
stack_of: &[u32],
k0: &[f64],
layers: &[LayerCoeffs<f64>],
n_layers: usize,
) -> Result<Vec<[f64; 2]>>
pub fn reflectivity_points_df64( &self, q: &[f64], stack_of: &[u32], k0: &[f64], layers: &[LayerCoeffs<f64>], n_layers: usize, ) -> Result<Vec<[f64; 2]>>
Double-single (df64) reflectance for independent (q, stack) points.
Same contract as GpuContext::reflectivity_points, but inputs stay
in f64 and the recursion runs in df64 arithmetic (~48 mantissa
bits, f32 exponent range), so reflectance tracks the CPU f64
recursion instead of carrying single-precision error. For devices
without native f64 shaders (Metal); roughly an order of magnitude
more ALU work per point than the f32 kernel.
§Errors
As for GpuContext::reflectivity_points.
Sourcepub fn reflectivity_points_general(
&self,
precision: GeneralPrecision,
q: &[f64],
stack_of: &[u32],
k0: &[f64],
layers: &[GeneralLayer<f64>],
n_layers: usize,
) -> Result<Vec<[[f64; 2]; 2]>>
pub fn reflectivity_points_general( &self, precision: GeneralPrecision, q: &[f64], stack_of: &[u32], k0: &[f64], layers: &[GeneralLayer<f64>], n_layers: usize, ) -> Result<Vec<[[f64; 2]; 2]>>
Reflectance of general dielectric-tensor stacks at independent (q, stack) points.
Runs the shader port of refloxide_tmm::kernel::solve_point_general:
Berreman eigenmodes of each layer’s full susceptibility tensor and the
4x4 reflection-matrix recursion with Nevot-Croce roughness. Tilted,
rotated, and biaxial layers produce cross-polarized reflectance.
One invocation evaluates one point; inputs and outputs are f64 on
the host and are narrowed only for GeneralPrecision::F32.
§Parameters
precision: shader arithmetic.GeneralPrecision::F64needsGpuContext::supports_f64;GeneralPrecision::F32is a diagnostic build.q: scattering vector per point in1/Angstrom.stack_of: stack index per point, each< n_stacks.k0: vacuum wavenumber per stack in1/Angstrom, positive.layers: row-major(n_stacks, n_layers); row 0 of a stack is the isotropic fronting and the last row the backing.n_layers: depth of every stack, at least two.
§Returns
One [[R_pp, R_sp], [R_ps, R_ss]] per point (the CPU packing), in
input order.
§Errors
RefloxideError::Gpu when F64 is requested on an adapter without
SHADER_F64; RefloxideError::InvalidShape for inconsistent
buffers or a batch exceeding device limits;
RefloxideError::SingularDynamicMatrix (with the point’s index
and stack as energy_index) when a layer’s mode matrix or the
recursion denominator is singular.
Sourcepub fn df64_selftest(
&self,
a: &[f64],
b: &[f64],
op: Df64Op,
) -> Result<Vec<f64>>
pub fn df64_selftest( &self, a: &[f64], b: &[f64], op: Df64Op, ) -> Result<Vec<f64>>
Evaluates one df64 operation elementwise on the device.
Diagnostic for new adapters: compares against f64 on the host to
confirm that the shader compiler preserves the error-free
transformations df64 relies on. Inputs are split into (hi, lo)
pairs; results are recombined as hi + lo.
§Errors
RefloxideError::InvalidShape when a and b differ in length;
RefloxideError::Gpu for device failures.
Auto Trait Implementations§
impl !Freeze for GpuContext
impl !RefUnwindSafe for GpuContext
impl !UnwindSafe for GpuContext
impl Send for GpuContext
impl Sync for GpuContext
impl Unpin for GpuContext
impl UnsafeUnpin for GpuContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.