use fuel_ir::DeviceLocation;
use fuel_ir::probe::BackendId;
use crate::fused::{CostEstimate, PrecisionGuarantee};
use crate::kernel::{KernelCaps, KernelRef, OpParams};
#[derive(Clone, Debug)]
pub struct Candidate {
pub kernel: KernelRef,
pub caps: KernelCaps,
pub backend: BackendId,
pub device: DeviceLocation,
pub precision: PrecisionGuarantee,
pub static_cost: CostEstimate,
pub inbound_transfer_ns: u64,
pub op_params: OpParams,
pub coupling: Vec<CouplingAdjustment>,
pub kernel_source: &'static str,
pub kernel_revision_hash: u64,
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct CouplingAdjustment {
pub condition: String,
pub delta_ns: i64,
}
#[cfg(test)]
mod tests {
use super::*;
use fuel_ir::Layout;
use fuel_ir::Result;
use std::sync::{Arc, RwLock};
use fuel_memory::Storage;
fn noop_kernel(
_inputs: &[Arc<RwLock<Storage>>],
_outputs: &mut [Arc<RwLock<Storage>>],
_layouts: &[Layout],
_params: &OpParams,
) -> Result<()> {
Ok(())
}
#[test]
fn candidate_construction() {
let c = Candidate {
kernel: noop_kernel,
caps: KernelCaps::empty(),
backend: BackendId::Cpu,
device: DeviceLocation::Cpu,
precision: PrecisionGuarantee::PRIMITIVE_DETERMINISTIC_CPU,
static_cost: CostEstimate {
flops: 100,
bytes_moved: 400,
kernel_overhead_ns: 50,
},
inbound_transfer_ns: 0,
op_params: OpParams::None,
coupling: Vec::new(),
kernel_source: "",
kernel_revision_hash: 0,
};
assert_eq!(c.backend, BackendId::Cpu);
assert_eq!(c.static_cost.flops, 100);
assert!(c.coupling.is_empty());
}
#[test]
fn coupling_adjustment_default_is_inert() {
let a = CouplingAdjustment::default();
assert!(a.condition.is_empty());
assert_eq!(a.delta_ns, 0);
}
}