pub struct ExactDdnnfProgram { /* private fields */ }Implementations§
Source§impl ExactDdnnfProgram
impl ExactDdnnfProgram
pub fn compile_source(source: &str) -> Result<Self>
pub fn compile_source_with_gpu(source: &str, config: GpuConfig) -> Result<Self>
Sourcepub fn compile_from_program(
program: &Program,
config: GpuConfig,
) -> Result<Self>
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.
pub fn uses_gpu_production_backend(&self) -> bool
Sourcepub fn last_compile_profile(&self) -> Option<&CircuitCompileProfile>
pub fn last_compile_profile(&self) -> Option<&CircuitCompileProfile>
Get the latest circuit compilation profile (populated when XLOG_WARMUP_PROFILE=1).
Sourcepub fn prob_var_map(&self) -> Vec<ProbVarInfo>
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”.
pub fn evaluate(&self) -> Result<ExactResult>
Sourcepub fn num_vars(&self) -> usize
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.
Sourcepub fn random_var_indices(&self) -> Vec<u32>
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.
Sourcepub fn neural_backward_nll_buffers(
&self,
slots: &GpuWeightSlots,
query_idx: usize,
probs: &[CudaBuffer],
out_grads: &mut [CudaBuffer],
cfg: NeuralFastPathConfig,
) -> Result<()>
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/dpResult:out = dL/dpforL = -log P(query | evidence)(NLL).
Sourcepub 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>>
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).
Sourcepub 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>>
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.
pub fn evaluate_gpu_with_grads(&self) -> Result<ExactResultWithGrads>
Trait Implementations§
Source§impl Clone for ExactDdnnfProgram
impl Clone for ExactDdnnfProgram
Source§fn clone(&self) -> ExactDdnnfProgram
fn clone(&self) -> ExactDdnnfProgram
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more