matrixlt/onnx/session does not have a README file

    RuntimeError

    pub(all) suberror RuntimeError {
    ModelErr(String)
    IrErr(String)
    TensorErr(String)
    MissingTensor(String)
    UnsupportedOp(String)
    } derive(Eq,
    Debug
    )

    推理会话构建与执行阶段可能抛出的结构化错误。

    BackendKind

    pub(all) enum BackendKind {
    Scalar
    Simd
    } derive(Eq,
    Debug
    )

    推理计算后端选择:
    • Scalar:100% 纯 MoonBit 标量参考实现
    • Simd :基于 matrixlt/ml_kernels 的 MoonBit V128 SIMD 向量化内核 + 静态权重预打包缓存
    impl Show for BackendKind

    OpTiming

    pub(all) struct OpTiming {
    node_name : String
    op_type : String
    output_shape : Array[Int]
    elapsed_us : Double
    }

    单个节点的逐算子耗时剖析记录。

    RunProfile

    pub(all) struct RunProfile {
    backend : BackendKind
    total_us : Double
    ops : Array[OpTiming]
    }

    单次推理的完整剖析报告,包含总耗时与每个节点的耗时分布。

    RunProfile::format_table

    fn RunProfile::format_table(self : RunProfile) -> String

    将剖析报告格式化为人类易读的对齐表格(供 CLI profile 与性能诊断使用)。

    Session

    pub struct Session {
    graph :
    IrGraph

    backend : BackendKind
    packed_weights : Map[String,
    PackedMatrixB
    ]
    packed_conv_weights : Map[String,
    PackedConvWeight
    ]
    release_plan : Array[Array[String]]
    pinned_outputs : Array[Bool]
    pool :
    BufferPool

    }

    ONNX 推理会话(Session): 持有已完成 Lowering、可选图优化与拓扑排序的计算图、所选后端、 SIMD 静态权重预打包缓存(覆盖 MatMul / Gemm / Conv)以及基于静态生命周期分析的 BufferPool 复用池。

    Session::backend

    fn Session::backend(self : Session) -> BackendKind

    返回当前会话使用的计算后端类型。

    Session::clear_pool

    fn Session::clear_pool(self : Session) -> Unit

    清空当前会话的 BufferPool 缓存缓冲区以主动释放峰值内存。

    Session::from_bytes

    fn Session::from_bytes(bytes : Bytes, backend? : BackendKind, optimize? : Bool) -> Session raise RuntimeError

    从内存 .onnx 字节流直接构建推理会话(全平台通用)。

    Session::from_file

    fn Session::from_file(path : String, backend? : BackendKind, optimize? : Bool) -> Session raise RuntimeError

    从本地 .onnx 文件路径构建推理会话(Native 入口)。

    Session::from_graph

    fn Session::from_graph(graph :
    IrGraph
    , backend? : BackendKind) -> Session

    从已构建的 IrGraph 直接创建推理会话。

    Session::from_model

    fn Session::from_model(m :
    OnnxModel
    , backend? : BackendKind, optimize? : Bool) -> Session raise RuntimeError

    从已解析的 OnnxModel 构建推理会话(默认启用图优化 Pass、SIMD 权重预打包缓存与 BufferPool 复用)。

    Session::graph

    返回当前会话的计算图。

    Session::packed_conv_weight_count

    fn Session::packed_conv_weight_count(self : Session) -> Int

    返回当前会话中已完成预打包的静态 2D 卷积权重数量。

    Session::packed_weight_count

    fn Session::packed_weight_count(self : Session) -> Int

    返回当前会话中已完成预打包的静态权重总数量(含 MatMul / Gemm 与 Conv 静态权重)。

    Session::pool_stats

    返回当前会话内部 BufferPool 的缓存命中率与滞留缓冲统计信息。

    Session::run

    执行一次完整的前向推理(零计时开销热路径,自动复用 BufferPool)。

    Session::run_profiled

    fn Session::run_profiled(self : Session, feeds : Map[String,
    Tensor
    ]) -> (Map[String,
    Tensor
    ], RunProfile) raise RuntimeError

    执行带逐算子计时剖析的前向推理,返回输出张量字典与 RunProfile 报告。

    Session::run_single

    面向单输入、单输出模型的便捷前向推理接口。

    Session::run_single_profiled

    面向单输入、单输出模型的带剖析前向推理接口。

    load_f32_file

    fn load_f32_file(path : String, shape : Array[Int]) ->
    Tensor
    raise RuntimeError

    从原始小端序 float32 二进制文件(.f32)加载张量。

    max_abs_diff_f32

    fn max_abs_diff_f32(actual :
    Tensor
    , expected :
    Tensor
    ) -> Float raise RuntimeError

    计算两个同形状 Float32 张量之间的最大绝对误差(max_abs_diff)。

    Source Files