kn_graph/lib.rs
1#![warn(missing_debug_implementations)]
2#![allow(clippy::new_without_default)]
3#![allow(clippy::len_without_is_empty)]
4#![allow(clippy::let_and_return)]
5
6//! A neural network inference graph intermediate representation, with surrounding utilities.
7//!
8//! The core type of this crate is [Graph](graph::Graph),
9//! see its documentation for how to manually build and compose graphs.
10//!
11//! An example demonstrating some of the features of this crate:
12//! ```no_run
13//! # use kn_graph::dot::graph_to_svg;
14//! # use kn_graph::onnx::load_graph_from_onnx_path;
15//! # use kn_graph::optimizer::optimize_graph;
16//! # use kn_graph::cpu::cpu_eval_graph;
17//! # use ndarray::{IxDyn, Array};
18//! # use kn_graph::dtype::{DTensor, Tensor};
19//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
20//! // load an onnx file
21//! let graph = load_graph_from_onnx_path("test.onnx", false)?;
22//!
23//! // optimize the graph
24//! let graph = optimize_graph(&graph, Default::default());
25//!
26//! // render the graph as an svg file
27//! graph_to_svg("test.svg", &graph, false, false)?;
28//!
29//! // execute the graph on the CPU
30//! let batch_size = 8;
31//! let inputs = [DTensor::F32(Tensor::zeros(IxDyn(&[batch_size, 16])))];
32//! let outputs = cpu_eval_graph(&graph, batch_size, &inputs);
33//! # Ok(())
34//! # }
35//! ```
36//!
37//! This crate is part of the [Kyanite](https://github.com/KarelPeeters/Kyanite) project, see its readme for more information.
38
39// TODO write onnx load, optimize, run example
40
41/// The [ndarray] crate is used for constant storage and CPU execution, and re-exported for convenience.
42pub use ndarray;
43
44/// The [DType](dtype::DType) enum.
45pub mod dtype;
46/// The core graph datastructure.
47pub mod graph;
48/// Graph optimization.
49pub mod optimizer;
50/// The [Shape](shape::Shape) type and utilities.
51pub mod shape;
52
53/// CPU graph execution.
54pub mod cpu;
55/// Graph visualization as a `dot` or `svg` file.
56pub mod dot;
57/// Onnx file loading.
58pub mod onnx;
59/// Hidden activations visualization.
60pub mod visualize;
61
62pub mod wrap_debug;