teeny_compiler/compiler/target/
cuda.rs1use std::collections::HashMap;
18
19use crate::errors::{Error, Result};
20use teeny_core::compiler::Capability;
21
22pub struct Target {
24 pub capability: Capability,
26}
27
28impl Target {
29 pub fn new(capability: Capability) -> Self {
31 Self { capability }
32 }
33}
34
35impl teeny_core::compiler::Target for Target {
36 fn target_cpu(&self) -> Option<String> {
37 Some(self.capability.to_string())
38 }
39}
40
41impl TryFrom<(i32, i32)> for Target {
42 type Error = anyhow::Error;
43
44 fn try_from((major, minor): (i32, i32)) -> Result<Self> {
45 let capabilities: HashMap<i32, Capability> = vec![
46 (75, Capability::Sm75),
47 (80, Capability::Sm80),
48 (86, Capability::Sm86),
49 (87, Capability::Sm87),
50 (89, Capability::Sm89),
51 (90, Capability::Sm90),
52 (100, Capability::Sm100),
53 (120, Capability::Sm120),
54 ]
55 .into_iter()
56 .collect();
57 let capability = capabilities
58 .get(&(major * 10 + minor))
59 .cloned()
60 .ok_or_else(|| {
61 Error::UnknownCapability(format!("Capability not found: {major}.{minor}"))
62 })?;
63
64 Ok(Self { capability })
65 }
66}