Skip to main content

ExactDdnnfProgram

Struct ExactDdnnfProgram 

Source
pub struct ExactDdnnfProgram { /* private fields */ }

Implementations§

Source§

impl ExactDdnnfProgram

Source

pub fn compile_source(source: &str) -> Result<Self>

Source

pub fn compile_source_with_gpu(source: &str, config: GpuConfig) -> Result<Self>

Source

pub fn compile_from_program( program: &Program, config: GpuConfig, ) -> Result<Self>

Compile an already parsed program with the requested GPU configuration.

Imports must already be resolved and merged. This method does not load unresolved use declarations from the filesystem.

Source

pub fn uses_gpu_production_backend(&self) -> bool

Source

pub fn last_compile_profile(&self) -> Option<&CircuitCompileProfile>

Get the latest circuit compilation profile (populated when XLOG_WARMUP_PROFILE=1).

Source

pub fn prob_var_map(&self) -> Vec<ProbVarInfo>

Materializes a dense vector describing what each CNF variable stands for.

The returned vector’s length is the CNF encoder’s variable capacity (3 * number of PIR nodes at compile time, see compilation/gpu_cnf.rs) — not the number of CNF variables actually in use, and not the number of random variables in the program. Slot v describes CNF variable v directly when v was assigned; slot 0 is always unused padding (CNF variables are 1-indexed), and so is any other slot with no variable assigned to it — those padding slots are indistinguishable from ProbVarInfo::Other. Do not treat len() of the result as a variable count or a random-variable count; use Self::random_var_indices for that (Self::num_vars returns this same capacity, not a count, so it is not a substitute here).

What is guaranteed is alignment with evaluate_gpu_with_grads’s grad_true/grad_false vectors, which are allocated with the same capacity: prob_var_map()[v] and grad_true[v] name and value the same variable v.

Rebuilds the dense vector on every call from the sparse prob_var_entries storage that actually lives for the lifetime of the program.

On the GPU count-lift fast path (count aggregates without evidence or disjunctions — see Self::uses_gpu_native_count_lift), no CNF encoding is ever built, so this returns an empty vector even for programs that do have probabilistic facts. Callers that need to enumerate a program’s probabilistic facts must check uses_gpu_native_count_lift() first and treat an empty map from that path as “mapping unavailable”, not as “no random variables”.

Source

pub fn evaluate(&self) -> Result<ExactResult>

Source

pub fn num_vars(&self) -> usize

Returns the CNF encoder’s variable capacity (max_var + 1), i.e. the same quantity as prob_var_map().len()not the number of CNF variables actually assigned, and not the number of random variables in the program (most CNF variables are auxiliary Tseitin variables with no probabilistic meaning). Use Self::random_var_indices to count or enumerate random variables instead.

Source

pub fn random_var_indices(&self) -> Vec<u32>

Returns the indices of random (probabilistic) variables in order.

Random variables are those with non-trivial weights (not (0.0, 0.0)). These correspond to annotated disjunctions in the source program. The order matches the order variables were assigned during CNF encoding.

Source

pub fn neural_backward_nll_buffers( &self, slots: &GpuWeightSlots, query_idx: usize, probs: &[CudaBuffer], out_grads: &mut [CudaBuffer], cfg: NeuralFastPathConfig, ) -> Result<()>

GPU neural fast-path: compute NLL gradients w.r.t. probability tensors (no host reads).

This implements the design in docs/design/2026-01-22-gpu-native-compilation-design.md §5.3:

  • Fill AD conditional-chain log-weights from device-resident p[label].
  • Run XGCF forward+backward on GPU.
  • Scatter gradients back into probability-space via the correct chain rule (uses both grad_true + grad_false).

The output gradient buffers are updated in-place:

  • Base run: out = dlogZ_base/dp
  • Query-forced run: out -= dlogZ_query/dp Result: out = dL/dp for L = -log P(query | evidence) (NLL).
Source

pub fn neural_backward_nll_buffers_with_device_loss( &self, slots: &GpuWeightSlots, query_idx: usize, probs: &[CudaBuffer], out_grads: &mut [CudaBuffer], cfg: NeuralFastPathConfig, expected_true: bool, ) -> Result<TrackedCudaSlice<f64>>

Same as Self::neural_backward_nll_buffers, but also returns the device-resident scalar NLL loss: L = -log P(query | evidence).

The returned slice has length 1 and is written on GPU (no device->host reads).

Source

pub fn neural_backward_nll_buffers_batch_with_device_loss( &self, slots: &GpuWeightSlots, query_indices: &[usize], probs_batch: &[Vec<CudaBuffer>], out_grads_batch: &mut [Vec<CudaBuffer>], cfg: NeuralFastPathConfig, expected_true: bool, ) -> Result<TrackedCudaSlice<f64>>

Batched variant of Self::neural_backward_nll_buffers_with_device_loss.

Computes NLL gradients for batch queries that share one compiled circuit template and returns a device-resident vector of batch scalar losses.

On circuits that require free-variable correction, this falls back to the existing per-query path for correctness.

Source

pub fn evaluate_gpu_with_grads(&self) -> Result<ExactResultWithGrads>

Trait Implementations§

Source§

impl Clone for ExactDdnnfProgram

Source§

fn clone(&self) -> ExactDdnnfProgram

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.