Crate coaster_nn

Crate coaster_nn 

Source
Expand description

Provides a Coaster Plugin, to extend Coaster with Neural Network related operations such as convolutions, pooling, ReLU, etc. A full list of operations provided by this Plugin, can be found at the provided Operations section.

§Overview

This Coaster Plugin extends Coaster’s Backend with NN related methods/operations. This allows you to run, these operations (and therefore your application) on your local machine as well as on servers, mobiles or any other machine (as if they were written for common CPU execution), while receiving the significant performance increases (usually one-to-two orders of magnitutde), by executing the operations on special purpose hardware such as GPUs - if they are available. Usage examples can be found in the next section.

The architecture of a Plugin is quite easy. It defines one Plugin Trait, in this case the NN trait, which implements basic functionality for initialization and multiple Plugin Operation Traits which define the methods which are going to be available on the Backed, as the Plugin Trait as well as the Plugin Operations Traits are implemented for the Coaster Backends (CUDA, OpenCL, Native). The operations take as arguments one or many SharedTensors, holding the data over which the operation should happen, and none or one Operation Configuration.

§Usage

An example on how to write some data into a SharedTensor and compute the result of the sigmoid function for each value:

extern crate coaster as co;
extern crate coaster_nn as nn;
use co::prelude::*;
use co::frameworks::native::flatbox::FlatBox;
use nn::*;

fn write_to_memory<T: Copy>(mem: &mut FlatBox, data: &[T]) {
    let mut mem_buffer = mem.as_mut_slice::<T>();
    for (index, datum) in data.iter().enumerate() {
        mem_buffer[index] = *datum;
    }
}

use crate::co::frameworks::cuda::get_cuda_backend;
pub fn main() {
    // Initialize a CUDA Backend.
    // Usually you would not use CUDA but let Coaster pick what is available on the machine.
    let backend = get_cuda_backend();

    // Initialize two SharedTensors.
    let mut x = SharedTensor::<f32>::new(&(1, 1, 3));
    let mut result = SharedTensor::<f32>::new(&(1, 1, 3));
    // Fill `x` with some data.
    let payload: &[f32] = &::std::iter::repeat(1f32).take(x.capacity()).collect::<Vec<f32>>();
    let native = Native::new();
    let cpu = native.new_device(native.hardwares()).unwrap();
    write_to_memory(x.write_only(&cpu).unwrap(), payload); // Write to native host memory.
    // Run the sigmoid operation, provided by the NN Plugin, on your CUDA enabled GPU.
    backend.sigmoid(&mut x, &mut result).unwrap();
    // See the result.
    println!("{:?}", result.read(&cpu).unwrap().as_slice::<f64>());
}

§Provided Operations

This Plugins provides the following operations. If not denoted otherwise, this means forward and backward A - means not yet implemented.

OperationCUDAOpenCLNative
SigmoidcuDNN v5 or later-Rust
SigmoidPointwisecuDNN v5 or later-Rust
ReLUcuDNN v5 or later-Rust
ReLUPointwisecuDNN v5 or later-Rust
TanhcuDNN v5 or later-Rust
TanhPointwisecuDNN v5 or later-Rust
Normalization (LRN)cuDNN v5 or later--
DropoutcuDNN v5 or later-Rust
ConvolutioncuDNN v5 or later-Rust(fwd)
SoftmaxcuDNN v5 or later-Rust
LogSoftmaxcuDNN v5 or later-Rust
Pooling MaxcuDNN v5 or later-Rust(fwd)
Pooling AvgcuDNN v5 or later--

Modules§

frameworks
Provides the specific Framework implementations for the Library Operations.

Macros§

impl_ops_log_softmax_for
log softmax impl generation macro
impl_ops_lrn_for
lrn impl generation macro TODO it’s all unimplemented!() right now
impl_ops_relu_for
relu impl generation macro
impl_ops_sigmoid_for
sigmoid impl generation macro
impl_ops_softmax_for
softmax impl generation macro
impl_ops_tanh_for
tanh impl generation macro

Enums§

ConvBackwardDataAlgo
Different algorithms to compute the gradient with respect to the filter.
ConvBackwardFilterAlgo
Different algorithms to compute the gradient with respect to the filter.
ConvForwardAlgo
Different algorithms to compute the convolution forward algorithm.
DirectionMode
Direction Mode for RNN [cudnnDirectionMode_t][1] [1]: https://docs.nvidia.com/deeplearning/sdk/cudnn-api/index.html#cudnnDirectionMode_t
MathType
Indicate if Tensor Core Operations are permitted [cudnnMathType_t][1] [1]: https://docs.nvidia.com/deeplearning/sdk/cudnn-api/index.html#cudnnMathType_t
RnnAlgorithm
Algorithm for RNN [cudnnRNNAlgo_t][1] [1]: https://docs.nvidia.com/deeplearning/sdk/cudnn-api/index.html#cudnnRNNAlgo_t
RnnInputMode
Input Modes for RNN [cudnnRNNInputMode_t][1] [1]: https://docs.nvidia.com/deeplearning/sdk/cudnn-api/index.html#cudnnRNNInputMode_t
RnnNetworkMode
Network Type for RNN Networks [cudnnRNNMOde_t][1] [1]: https://docs.nvidia.com/deeplearning/sdk/cudnn-api/index.html#cudnnRNNMode_t
RnnPaddingMode
Enables/Disables the padded input/output [cudnnRNNPaddingMode_t][1] [1]: https://docs.nvidia.com/deeplearning/sdk/cudnn-api/index.html#cudnnRNNPaddingMode_t

Traits§

Convolution
Provides the functionality for a Backend to support Convolution operations.
ConvolutionConfig
Provides Convolution Config functionality.
Dropout
Provides the functionality for a Backend to support Dropout operations.
LRN
Provides the functionality for a Backend to support Local Response Normalization operations.
LogSoftmax
Provides the functionality for a Backend to support LogSoftmax operations.
NN
Provides the functionality for a backend to support Neural Network related operations.
NNOperationConfig
Provides generic NN Operation Config functionality.
Pooling
Provides the functionality for a Backend to support Pooling operations.
Relu
Provides the functionality for a Backend to support ReLU operations.
ReluPointwise
Provides the functionality for pointwise ReLU operations (overwrites the input with the result of the operation).
Rnn
Provide the functionality for a Backend to support RNN operations
RnnConfig
Provides Rnn Config functionality.
Sigmoid
Provides the functionality for a Backend to support Sigmoid operations.
SigmoidPointwise
Provides the functionality for pointwise Sigmoid operations (overwrites the input with the result of the operation).
Softmax
Provides the functionality for a Backend to support Softmax operations.
Tanh
Provides the functionality for a Backend to support TanH operations.
TanhPointwise
Provides the functionality for pointwise ReLU operations (overwrites the input with the result of the operation).