4 stable releases

1.8.0 Nov 21, 2021
1.7.0 Jun 11, 2020
1.6.0 Oct 29, 2017
1.5.0 Jun 12, 2017

#69 in Machine learning

Download history 11/week @ 2023-12-11 3/week @ 2023-12-18 1/week @ 2023-12-25 4/week @ 2024-01-08 4/week @ 2024-01-15 4/week @ 2024-02-05 11/week @ 2024-02-12 42/week @ 2024-02-26 18/week @ 2024-03-04 31/week @ 2024-03-11 22/week @ 2024-03-18 29/week @ 2024-03-25

103 downloads per month
Used in 6 crates (3 directly)

MIT/Apache

1MB
26K SLoC

rust-cuDNN • Join the chat at https://gitter.im/spearow/juice Build Status Crates.io License

rust-cuDNN provides safe wrapper for CUDA's cuDNN library, so you can use it comfortably and safely in your Rust application.

As cuDNN relies on CUDA to allocate memory on the GPU, you might also look into rust-cuda.

rust-cudnn was developed at now defunct Autumnai for the Rust Machine Intelligence Framework Leaf.

rust-cudnn is part of the High-Performance Computation Framework Coaster. For an easy, unified interface for NN operations, such as those provided by cuDNN, you might check out Coaster.

For more information,

Getting Started

If you're using Cargo, just add rust-cuDNN to your Cargo.toml:

[dependencies]
cudnn = "1.5.0"

If you're using Cargo Edit, you can call:

$ cargo add cudnn

Example

Using the high-level Cudnn interface.

extern crate rcudnn as cudnn;
extern crate libc;
use cudnn::{Cudnn, TensorDescriptor};
use cudnn::utils::{ScalParams, DataType};
fn main() {
    // Initialize a new cuDNN context and allocates resources.
    let cudnn = Cudnn::new().unwrap();
    // Create a cuDNN Tensor Descriptor for `src` and `dest` memory.
    let src_desc = TensorDescriptor::new(&[2, 2, 2], &[4, 2, 1], DataType::Float).unwrap();
    let dest_desc = TensorDescriptor::new(&[2, 2, 2], &[4, 2, 1], DataType::Float).unwrap();
    let acti = cudnn.init_activation().unwrap();
    // Obtain the `src` and memory pointer on the GPU.
    // NOTE: You wouldn't do it like that. You need to really allocate memory on the GPU with e.g. CUDA or Collenchyma.
    let src_data: *const ::libc::c_void = ::std::ptr::null();
    let dest_data: *mut ::libc::c_void = ::std::ptr::null_mut();
    // Now you can compute the forward sigmoid activation on your GPU.
    cudnn.sigmoid_forward::<f32>(&acti, &src_desc, src_data, &dest_desc, dest_data, ScalParams::default());
}

Building

rust-cudnn depends on the cuDNN runtime libraries, which can be obtained from NVIDIA.

Manual Configuration

rust-cudnn's build script will by default attempt to locate cudnn via pkg-config. This will not work in some situations, for example,

  • on systems that don't have pkg-config,
  • when cross compiling, or
  • when cuDNN is not installed in the default system library directory (e.g. /usr/lib).

Therefore the build script can be configured by exporting the following environment variables:

  • CUDNN_LIB_DIR
    If specified, a directory that will be used to find cuDNN runtime libraries. e.g. /opt/cuda/lib

  • CUDNN_STATIC
    If specified, cuDNN libraries will be statically rather than dynamically linked.

  • CUDNN_LIBS
    If specified, will be used to find cuDNN libraries under a different name.

If either CUDNN_LIB_DIR or CUDNN_INCLUDE_DIR are specified, then the build script will skip the pkg-config step.

If your also need to run the compiled binaries yourself, make sure that they are available:

# Linux; for other platforms consult the instructions that come with cuDNN
cd <cudnn_installpath>
export LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH

Contributing

Want to contribute? Awesome! We have instructions to help you get started contributing code or documentation. And high priority issues, that we could need your help with.

We have a mostly real-time collaboration culture and happens here on Github and on the Gitter Channel.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as below, without any additional terms or conditions.

License

Licensed under either of

at your option.

Dependencies

~0.7–1.3MB
~29K SLoC