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

use serde::{Serialize, Deserialize, };

#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub enum Platform {
  Unix,
  Windows,

  Hsa(self::hsa::Device),
  /// Present, but ATM completely unsupported.
  Cuda,
  Vulkan(self::vk::ExeModel),
}

pub mod hsa {
  use serde::{Serialize, Deserialize, };
  use std::str::FromStr;

  /// These are taken from the AMDGPU LLVM target machine.
  /// TODO do we care about pre-GFX8 GPUs?
  #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
  pub enum AmdGpu {
    //===----------------------------------------------------------------------===//
    // GCN GFX8 (Volcanic Islands (VI)).
    //===----------------------------------------------------------------------===//
    Gfx801,
    Carrizo,
    Gfx802,
    Iceland,
    Tonga,
    Gfx803,
    Fiji,
    Polaris10,
    Polaris11,
    Gfx810,
    Stoney,

    //===----------------------------------------------------------------------===//
    // GCN GFX9.
    //===----------------------------------------------------------------------===//

    Gfx900,
    Gfx902,
    Gfx904,
    Gfx906,
    Gfx909,
  }
  impl FromStr for AmdGpu {
    type Err = ();
    fn from_str(s: &str) -> Result<Self, ()> {
      use self::AmdGpu::*;

      let v = match s {
        "gfx801" => Gfx801,
        "carrizo" => Carrizo,
        "gfx802" => Gfx802,
        "iceland" => Iceland,
        "tonga" => Tonga,
        "gfx803" => Gfx803,
        "fiji" => Fiji,
        "polaris10" => Polaris10,
        "polaris11" => Polaris11,
        "gfx810" => Gfx810,
        "stoney" => Stoney,

        "gfx900" => Gfx900,
        "gfx902" => Gfx902,
        "gfx904" => Gfx904,
        "gfx906" => Gfx906,
        "gfx909" => Gfx909,

        _ => { return Err(()); },
      };

      Ok(v)
    }
  }

  #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
  pub enum Device {
    AmdGcn(AmdGpu)
  }
}
pub mod vk {
  use std::str::FromStr;

  use serde::{Serialize, Deserialize, };

  #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
  #[repr(u32)]
  pub enum ExeModel {
    Vertex,
    TessellationControl,
    TessellationEval,
    Geometry,
    Fragment,
    GLCompute,
    /// Present for completeness, not actually used.
    Kernel,
  }
  impl FromStr for ExeModel {
    type Err = ();
    fn from_str(s: &str) -> Result<Self, ()> {
      let r = match s {
        "Vertex" => ExeModel::Vertex,
        "TessellationControl" => ExeModel::TessellationControl,
        "TessellationEval" => ExeModel::TessellationEval,
        "Geometry" => ExeModel::Geometry,
        "Fragment" => ExeModel::Fragment,
        "GLCompute" => ExeModel::GLCompute,
        "Kernel" => ExeModel::Kernel,
        _ => { return Err(()); },
      };

      Ok(r)
    }
  }
}

#[cfg(unix)]
#[inline(always)]
pub const fn host_platform() -> Platform {
  Platform::Unix
}
#[cfg(windows)]
#[inline(always)]
pub const fn host_platform() -> Platform {
  Platform::Windows
}