coaster/
plugin.rs

1//! Provides helpers for explicit implementations of Backend [Operations][operation].
2//! [operation]: ../operation/index.html
3//!
4//! A Backend is a Rust struct like any other, therefore you probably would like to implement
5//! certain methods for the Backend. As the whole purpose of a Backend is to provide an
6//! abstraction over various computation devices and computation languages, these implemented
7//! methods will than be able to excute on different devices and use the full power of the machine's
8//! underlying hardware.
9//!
10//! So extending the Backend with operations is easy. In Coaster we call crates, which provide
11//! operations for the Backend, Plugins. Plugins are usually a group of related operations of a common
12//! field. Two examples for Coaster Plugins are [BLAS][coaster-blas] and [NN][coaster-nn].
13//!
14//! A Plugin does roughly two important things. It provides generic traits and the explicit implementation
15//! of these traits for one or (even better) all available Coaster Frameworks - common host CPU, OpenCL,
16//! CUDA.
17//!
18//! The structure of Plugin is pretty simple with as little overhead as possible. Macros make implementations
19//! even easier. If you would like to use specific Plugins for you Backend, all you need to do is
20//! set them as dependencies in your Cargo file in addition to the Coaster crate. The Plugin
21//! then automatically extends the Backend provided by Coaster.
22//!
23//! Extending the Backend with your own Plugin is a straight forward process.
24//! For now we recommend that you take a look at the general code structure of [Coaster-BLAS][coaster-blas]
25//! or its documentation. Let us now about your Plugin on the Gitter chat, we are happy to feature
26//! your Coaster Plugin on the README.
27//!
28//! [program]: ../program/index.html
29//! [coaster-blas]: https://github.com/spearow/coaster-blas
30//! [coaster-nn]: https://github.com/spearow/coaster-nn
31
32pub use self::numeric_helpers::Float;
33use crate::tensor;
34
35/// Describes numeric types and traits for a Plugin.
36pub mod numeric_helpers {
37    pub use num::traits::*;
38}
39
40#[derive(Debug, thiserror::Error)]
41/// Defines a high-level Plugin Error.
42pub enum Error {
43    /// Failure related to `SharedTensor`: use of uninitialized memory,
44    /// synchronization error or memory allocation failure.
45    #[error("SharedTensor error")]
46    SharedTensor(#[from] tensor::Error),
47    /// Failure at the execution of the Operation.
48    #[error("Operation error")]
49    Operation(&'static str),
50
51    #[error("Plugin error: {0}")]
52    Plugin(&'static str),
53
54    /// Failure at the Plugin with an inner error type.
55    #[error(transparent)]
56    PluginInner(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),
57}