kn_cuda_eval/
lib.rs

1#![warn(missing_debug_implementations)]
2
3//! A Cuda CPU executor for neural network graphs from the `kn_graph` crate. The core type is [CudaExecutor](executor::CudaExecutor).
4//!
5//! This crate is part of the [Kyanite](https://github.com/KarelPeeters/Kyanite) project, see its readme for more information.
6//! See [system-requirements](https://github.com/KarelPeeters/Kyanite#system-requirements) for how to set up the cuda libraries.
7//!
8//! # Quick demo
9//!
10//! ```no_run
11//! # use kn_cuda_eval::executor::CudaExecutor;
12//! # use kn_cuda_sys::wrapper::handle::CudaDevice;
13//! # use kn_graph::dtype::{DTensor, Tensor};
14//! # use kn_graph::ndarray::{Array, IxDyn};
15//! # use kn_graph::onnx::load_graph_from_onnx_path;
16//! # use kn_graph::optimizer::optimize_graph;
17//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
18//! // load and optimize the graph
19//! let graph = load_graph_from_onnx_path("test.onnx", false)?;
20//! let graph = optimize_graph(&graph, Default::default());
21//!
22//! // select a device
23//! let device = CudaDevice::new(0).unwrap();
24//!
25//! // build an executor
26//! let batch_size = 8;
27//! let mut executor = CudaExecutor::new(device, &graph, batch_size);
28//!
29//! // evaluate the graph with some inputs, get the outputs back
30//! let inputs = [DTensor::F32(Tensor::zeros(vec![batch_size, 16]))];
31//! let outputs: &[DTensor] = executor.evaluate(&inputs);
32//! # Ok(())
33//! # }
34//! ```
35
36/// Export the [CudaDevice] type for convenience: often an explicit dependency on the `kn_cuda_sys` crate is not needed.
37pub use kn_cuda_sys::wrapper::handle::CudaDevice;
38
39/// The autokernel infrastructure and specific kernels.
40pub mod autokernel;
41/// On-device tensor data structure.
42pub mod device_tensor;
43/// The main executor type and the compiler for it.
44pub mod executor;
45/// Tensor utility.
46pub mod offset_tensor;
47/// Shape utilities.
48pub mod shape;
49/// Testing and debugging infrastructure.
50pub mod tester;
51/// Miscellaneous utilities.
52pub mod util;
53
54mod planner;
55mod step;