use std::fmt::Display;
use crate::shared::Architecture;
#[derive(Debug)]
pub struct CudaArchitecture {
pub version: u32,
pub tensor_cores: bool,
}
impl CudaArchitecture {
pub fn has_tensor_cores(version: u32, name: &str) -> bool {
match version {
..70 => false,
75 => !name.to_uppercase().contains("GTX"),
_ => true,
}
}
}
impl Display for CudaArchitecture {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.version)
}
}
impl Architecture for CudaArchitecture {
fn warp_size(&self) -> u32 {
32
}
fn is_wmma_capable(&self) -> bool {
self.tensor_cores
}
fn is_mfma_capable(&self) -> bool {
false
}
fn get_version(&self) -> u32 {
self.version
}
}
#[cfg(test)]
mod tests {
use super::CudaArchitecture;
#[test]
fn turing_without_tensor_cores_is_told_apart_from_turing_with_them() {
assert!(!CudaArchitecture::has_tensor_cores(
75,
"NVIDIA GeForce GTX 1660 SUPER"
));
assert!(CudaArchitecture::has_tensor_cores(
75,
"NVIDIA GeForce RTX 2060"
));
}
#[test]
fn the_gtx_exception_applies_only_to_turing() {
assert!(CudaArchitecture::has_tensor_cores(
80,
"NVIDIA A100-GTX-ish"
));
assert!(CudaArchitecture::has_tensor_cores(75, "Tesla T4"));
}
#[test]
fn nothing_before_volta_has_them() {
assert!(!CudaArchitecture::has_tensor_cores(
61,
"NVIDIA GeForce GTX 1080"
));
assert!(!CudaArchitecture::has_tensor_cores(
52,
"NVIDIA GeForce GTX 980"
));
assert!(CudaArchitecture::has_tensor_cores(70, "Tesla V100-SXM2"));
}
#[test]
fn an_unnamed_device_keeps_what_its_version_says() {
assert!(CudaArchitecture::has_tensor_cores(
75,
"unknown CUDA device"
));
}
}