use crate::Precision;
use rlx_ir::OpKind;
use rlx_ir::logical_kernel::{KernelDispatchConfig, KernelDispatchPolicy};
use rlx_opt::{FusionOptions, FusionTarget, PrecisionPolicy};
#[derive(Debug, Clone)]
pub struct CompileOptions {
pub precision: Precision,
pub policy: Option<PrecisionPolicy>,
pub dce: bool,
pub constant_folding: bool,
pub verbose: bool,
pub fusion_target: Option<FusionTarget>,
pub fusion_opts: FusionOptions,
pub arena_alignment: usize,
pub assert_fusion_clean: bool,
pub supported_ops: Option<&'static [OpKind]>,
pub dim_binding: Option<rlx_ir::DimBinding>,
pub kernel_dispatch: KernelDispatchConfig,
}
impl Default for CompileOptions {
fn default() -> Self {
Self {
precision: Precision::F32,
policy: None,
dce: true,
constant_folding: true,
verbose: false,
fusion_target: None,
fusion_opts: FusionOptions::default(),
arena_alignment: 64,
assert_fusion_clean: false,
supported_ops: None,
dim_binding: None,
kernel_dispatch: KernelDispatchConfig::from_env(),
}
}
}
impl CompileOptions {
pub fn new() -> Self {
Self::default()
}
pub fn precision(mut self, p: Precision) -> Self {
self.precision = p;
self
}
pub fn policy(mut self, p: PrecisionPolicy) -> Self {
self.policy = Some(p);
self
}
pub fn no_policy(mut self) -> Self {
self.policy = None;
self
}
pub fn with_dce(mut self, on: bool) -> Self {
self.dce = on;
self
}
pub fn with_constant_folding(mut self, on: bool) -> Self {
self.constant_folding = on;
self
}
pub fn with_verbose(mut self, on: bool) -> Self {
self.verbose = on;
self
}
pub fn fusion_target(mut self, target: FusionTarget) -> Self {
self.fusion_target = Some(target);
self
}
pub fn fusion_opts(mut self, opts: FusionOptions) -> Self {
self.fusion_opts = opts;
self
}
pub fn arena_alignment(mut self, bytes: usize) -> Self {
self.arena_alignment = bytes;
self
}
pub fn supported_ops(mut self, ops: &'static [OpKind]) -> Self {
self.supported_ops = Some(ops);
self
}
pub fn assert_fusion_clean(mut self, on: bool) -> Self {
self.assert_fusion_clean = on;
self
}
pub fn dim_binding(mut self, binding: rlx_ir::DimBinding) -> Self {
self.dim_binding = Some(binding);
self
}
pub fn kernel_dispatch(mut self, policy: KernelDispatchPolicy) -> Self {
self.kernel_dispatch.policy = policy;
self
}
pub fn kernel_dispatch_config(mut self, config: KernelDispatchConfig) -> Self {
self.kernel_dispatch = config;
self
}
pub fn force_common_kinds(mut self, kinds: &'static [OpKind]) -> Self {
self.kernel_dispatch.force_common_kinds = kinds;
self
}
pub fn force_native_kinds(mut self, kinds: &'static [OpKind]) -> Self {
self.kernel_dispatch.force_native_kinds = kinds;
self
}
}