Skip to main content

GpuContext

Struct GpuContext 

Source
pub struct GpuContext { /* private fields */ }
Expand description

Device, queue, and compiled recursion pipelines for one GPU adapter.

Implementations§

Source§

impl GpuContext

Source

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.

Source

pub fn describe(&self) -> String

Human-readable adapter name and backend, for logs and benchmarks.

Source

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.

Source

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 in 1/Angstrom, length n_q.
  • k0: vacuum wavenumber per stack in 1/Angstrom, length n_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.

Source

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 in 1/Angstrom, length n_points.
  • stack_of: stack index per point, each < n_stacks.
  • k0: vacuum wavenumber per stack in 1/Angstrom, length n_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.

Source

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 in GpuContext::reflectivity_points.
  • dq: row-major (n_dirs, n_points) tangent of q.
  • 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.

Source

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.

Source

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::F64 needs GpuContext::supports_f64; GeneralPrecision::F32 is a diagnostic build.
  • q: scattering vector per point in 1/Angstrom.
  • stack_of: stack index per point, each < n_stacks.
  • k0: vacuum wavenumber per stack in 1/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.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,