1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//! Various error types

use std::error::Error;
use std::fmt;

use derive_more::Display;

// TOOD maybe there is a better approach to errors...

/// An error for when there is no device to complete a certain operation
pub struct NoDeviceError;

impl Error for NoDeviceError {}

impl fmt::Debug for NoDeviceError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "no device could be found")
    }
}

impl fmt::Display for NoDeviceError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "no device could be found")
    }
}

/// An error when a device is there but not available for use
pub struct UnavailableDeviceError;

impl Error for UnavailableDeviceError {}

impl fmt::Debug for UnavailableDeviceError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(
            f,
            "currently selected device is already taken and unavailable"
        )
    }
}

impl fmt::Display for UnavailableDeviceError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(
            f,
            "currently selected device is already taken and unavailable"
        )
    }
}

/// An error for compilation failures
pub struct CompileError;

impl Error for CompileError {}

impl fmt::Debug for CompileError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "failed to compile")
    }
}

impl fmt::Display for CompileError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "failed to compile")
    }
}

/// An error for failure to complete data movement or computation
pub struct CompletionError;

impl Error for CompletionError {}

impl fmt::Debug for CompletionError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(
            f,
            "failed to successfully complete memory creation/transfer/computation"
        )
    }
}

impl fmt::Display for CompletionError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(
            f,
            "failed to successfully complete memory creation/transfer/computation"
        )
    }
}

/// An error that occurs when you attempt to initialize an already initialized pool of devices
pub struct PoolAlreadyInitializedError;

impl Error for PoolAlreadyInitializedError {}

impl fmt::Debug for PoolAlreadyInitializedError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "pool of devices is already initialized")
    }
}

impl fmt::Display for PoolAlreadyInitializedError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "pool of devices is already initialized")
    }
}

/// An error in getting data stored in a `DeviceBox`
#[derive(Debug, Display)]
pub enum GetError {
    Completion,
    NoDevice,
}

impl Error for GetError {}

/// An error for capturing compilation fails or no device present
#[derive(Debug, Display)]
pub enum CompileOrNoDeviceError {
    Compile,
    NoDevice,
}

impl Error for CompileOrNoDeviceError {}

/// A runtime error that occurs on the device
pub struct RuntimeError;

impl Error for RuntimeError {}

impl fmt::Debug for RuntimeError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "runtime error occurred")
    }
}

impl fmt::Display for RuntimeError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "runtime error occurred")
    }
}

/// An error in launching kernels
#[derive(Debug, Display)]
pub enum LaunchError {
    NoDevice,
    Runtime,
}

impl Error for LaunchError {}