rcudnn/lib.rs
1//! Provides a safe and convenient wrapper for the [CUDA cuDNN][cudnn] API.
2//!
3//! This crate (1.0.0) was developed against cuDNN v3.
4//!
5//! ## Architecture
6//!
7//! This crate provides three levels of entrace.
8//!
9//! **FFI**<br>
10//! The `ffi` module exposes the foreign function interface and cuDNN specific types. Usually,
11//! there should be no use to touch it if you only want to use cuDNN in you application. The ffi
12//! is provided by the `rust-cudnn-sys` crate and gets reexported here.
13//!
14//! **Low-Level**<br>
15//! The `api` module exposes already a complete and safe wrapper for the cuDNN API, including proper
16//! Rust Errors. Usually there should be not need to use the `API` directly though, as the `Cudnn` module,
17//! as described in the next block, provides all the API functionality but provides a more convenient interface.
18//!
19//! **High-Level**<br>
20//! The `cudnn` module exposes the `Cudnn` struct, which provides a very convenient, easy-to-understand interface
21//! for the cuDNN API. There should be not much need to obtain and read the cuDNN manual. Initialize the Cudnn
22//! struct and you can call the available methods wich are representing all the available cuDNN operations.
23//!
24//! ## Examples
25//!
26//! ```
27//! extern crate rcudnn as cudnn;
28//! extern crate libc;
29//! use cudnn::{Cudnn, TensorDescriptor};
30//! use cudnn::utils::{ScalParams, DataType};
31//! fn main() {
32//! // Initialize a new cuDNN context and allocates resources.
33//! let cudnn = Cudnn::new().unwrap();
34//! // Create a cuDNN Tensor Descriptor for `src` and `dest` memory.
35//! let src_desc = TensorDescriptor::new(&[2, 2, 2], &[4, 2, 1], DataType::Float).unwrap();
36//! let dest_desc = TensorDescriptor::new(&[2, 2, 2], &[4, 2, 1], DataType::Float).unwrap();
37//! let acti = cudnn.init_activation().unwrap();
38//! // Obtain the `src` and memory pointer on the GPU.
39//! // NOTE: You wouldn't do it like that. You need to really allocate memory on the GPU with e.g. CUDA or Collenchyma.
40//! let src_data: *const ::libc::c_void = ::std::ptr::null();
41//! let dest_data: *mut ::libc::c_void = ::std::ptr::null_mut();
42//! // Now you can compute the forward sigmoid activation on your GPU.
43//! cudnn.sigmoid_forward::<f32>(&acti, &src_desc, src_data, &dest_desc, dest_data, ScalParams::default());
44//! }
45//! ```
46//!
47//! ## Notes
48//!
49//! rust-cudnn was developed at [Autumn][autumn] for the Rust Machine Intelligence Framework [Leaf][leaf].
50//!
51//! rust-cudnn is part of the High-Performance Computation Framework [Collenchyma][collenchyma], for the
52//! [Neural Network Plugin][nn]. Rust CUDNN is now maintained by [Juice][juice]
53//!
54//! [cudnn]: https://developer.nvidia.com/cudnn
55//! [autumn]: https://www.crunchbase.com/organization/autumn-ai
56//! [leaf]: https://github.com/autumnai/leaf
57//! [collenchyma]: https://github.com/autumnai/collenchyma
58//! [nn]: https://github.com/autumnai/collenchyma-nn
59//! [juice]: https://github.com/spearow/juice
60#![allow(dead_code)]
61#![deny(
62 clippy::missing_docs,
63 clippy::missing_debug_implementations,
64 clippy::missing_copy_implementations,
65 clippy::trivial_casts,
66 clippy::trivial_numeric_casts,
67 clippy::unsafe_code,
68 clippy::unused_import_braces,
69 clippy::unused_qualifications,
70 clippy::complexity
71)]
72
73extern crate libc;
74extern crate num;
75extern crate rcudnn_sys as ffi;
76
77pub use self::activation_descriptor::ActivationDescriptor;
78pub use self::convolution_descriptor::ConvolutionDescriptor;
79pub use self::cudnn::Cudnn;
80pub use self::dropout_descriptor::DropoutDescriptor;
81pub use self::error::Error;
82pub use self::filter_descriptor::FilterDescriptor;
83pub use self::normalization_descriptor::NormalizationDescriptor;
84pub use self::pooling_descriptor::PoolingDescriptor;
85pub use self::rnn_descriptor::RnnDescriptor;
86pub use self::tensor_descriptor::{tensor_vec_id_c, TensorDescriptor};
87pub use crate::ffi::*;
88
89#[derive(Debug, Copy, Clone)]
90/// Defines the Cuda cuDNN API.
91pub struct API;
92
93mod activation_descriptor;
94mod api;
95mod convolution_descriptor;
96pub mod cuda;
97mod cudnn;
98mod dropout_descriptor;
99mod error;
100mod filter_descriptor;
101mod normalization_descriptor;
102mod pooling_descriptor;
103mod rnn_descriptor;
104mod tensor_descriptor;
105pub mod utils;