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
//! Defines the amount of work to be done by a kernel for each of up to three 
//! dimensions.
// use std::ptr;
// use libc::size_t;

/// Defines the amount of work to be done by a kernel for each of up to three 
/// dimensions.
///
/// [UNSTABLE]: MAY BE CONSOLIDATED WITH `SimpleDims`.
#[derive(PartialEq, Debug, Clone)]
pub enum WorkDims {
    Unspecified,
    OneDim      (usize),
    TwoDims     (usize, usize),
    ThreeDims   (usize, usize, usize),
}

impl WorkDims {
    /// Returns the number of dimensions defined by this `WorkDims`.
    pub fn dim_count(&self) -> u32 {
        match self {
            &WorkDims::ThreeDims(..)        => 3,
            &WorkDims::TwoDims(..)      => 2,
            &WorkDims::OneDim(..)       => 1,
            &WorkDims::Unspecified      => 0,
        }

    }

    // /// Returns the amount work to be done in three dimensional terms.
    // pub fn complete_worksize(&self) -> (usize, usize, usize) {
    //     match self {
    //         &WorkDims::OneDim(x) => (x, 1, 1),
    //         &WorkDims::TwoDims(x, y) => (x, y, 1),
    //         &WorkDims::ThreeDims(x, y, z) => (x, y, z),
    //         _ => (1, 1, 1)
    //     }
    // }

    pub fn as_core(&self) -> Option<[usize; 3]> {
        match self {
            &WorkDims::OneDim(x) => Some([x, 0, 0]),
            &WorkDims::TwoDims(x, y) => Some([x, y, 0]),
            &WorkDims::ThreeDims(x, y, z) => Some([x, y, z]),
            _ => None
        }
    }

    // pub fn as_work_dims(&self) -> Option<[usize; 3]> {
    //     match self {
    //         &WorkDims::OneDim(x) => Some([x, 1, 1]),
    //         &WorkDims::TwoDims(x, y) => Some([x, y, 1]),
    //         &WorkDims::ThreeDims(x, y, z) => Some([x, y, z]),
    //         _ => None
    //     }
    // }

    // /// Returns a core pointer to the enum.
    // pub fn as_ptr(&self) -> *const size_t {
    //     match self {
    //         &WorkDims::OneDim(x) => {
    //             &x as *const usize as *const size_t
    //         },
    //         &WorkDims::TwoDims(x, _) => {
    //             &x as *const usize as *const size_t
    //         },
    //         &WorkDims::ThreeDims(x, _, _) => {
    //             &x as *const usize as *const size_t
    //         },
    //         _ => ptr::null(),
    //     }
    // }
}