use super::{DriverKind, GpuArch};
#[cfg_attr(
not(test),
expect(dead_code, reason = "exercised in workarounds::tests")
)]
pub(crate) const NVK_MAX_SAFE_ALLOCATION_BYTES: u64 = 1_200_000_000;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Workaround {
NvkExpF64Crash,
NvkLogF64Crash,
NvvmAdaF64Transcendentals,
NvkLargeBufferLimit,
NvkSinCosF64Imprecise,
Df64SpirVPoisoning,
VoltaNoPmuFirmware,
}
#[cfg_attr(
not(test),
expect(dead_code, reason = "exercised in workarounds::tests")
)]
pub(crate) fn detect_workarounds(driver: DriverKind, arch: GpuArch) -> Vec<Workaround> {
let mut w = Vec::new();
if driver == DriverKind::Nvk {
w.push(Workaround::NvkExpF64Crash);
w.push(Workaround::NvkLogF64Crash);
w.push(Workaround::NvkLargeBufferLimit);
w.push(Workaround::NvkSinCosF64Imprecise);
}
if driver == DriverKind::NvidiaProprietary && arch == GpuArch::Ada {
w.push(Workaround::NvvmAdaF64Transcendentals);
}
w.push(Workaround::Df64SpirVPoisoning);
if driver == DriverKind::Nvk && arch == GpuArch::Volta {
w.push(Workaround::VoltaNoPmuFirmware);
}
w
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn nvk_ampere_has_exp_log_sincos_buffer_limit() {
let w = detect_workarounds(DriverKind::Nvk, GpuArch::Ampere);
assert!(w.contains(&Workaround::NvkExpF64Crash));
assert!(w.contains(&Workaround::NvkLogF64Crash));
assert!(w.contains(&Workaround::NvkLargeBufferLimit));
assert!(w.contains(&Workaround::NvkSinCosF64Imprecise));
assert!(w.contains(&Workaround::Df64SpirVPoisoning));
assert!(!w.contains(&Workaround::NvvmAdaF64Transcendentals));
}
#[test]
fn nvk_volta_includes_pmu_workaround() {
let w = detect_workarounds(DriverKind::Nvk, GpuArch::Volta);
assert!(w.contains(&Workaround::VoltaNoPmuFirmware));
assert!(w.contains(&Workaround::NvkExpF64Crash));
}
#[test]
fn nvidia_proprietary_ada_gets_nvvm_transcendentals() {
let w = detect_workarounds(DriverKind::NvidiaProprietary, GpuArch::Ada);
assert!(w.contains(&Workaround::NvvmAdaF64Transcendentals));
assert!(w.contains(&Workaround::Df64SpirVPoisoning));
assert!(!w.contains(&Workaround::NvkExpF64Crash));
}
#[test]
fn nvidia_proprietary_ampere_no_ada_workaround() {
let w = detect_workarounds(DriverKind::NvidiaProprietary, GpuArch::Ampere);
assert!(!w.contains(&Workaround::NvvmAdaF64Transcendentals));
assert!(w.contains(&Workaround::Df64SpirVPoisoning));
}
#[test]
fn radv_only_gets_spirv_poisoning() {
let w = detect_workarounds(DriverKind::Radv, GpuArch::Rdna2);
assert_eq!(w, vec![Workaround::Df64SpirVPoisoning]);
}
#[test]
fn intel_only_gets_spirv_poisoning() {
let w = detect_workarounds(DriverKind::Intel, GpuArch::Unknown);
assert_eq!(w, vec![Workaround::Df64SpirVPoisoning]);
}
#[test]
fn software_only_gets_spirv_poisoning() {
let w = detect_workarounds(DriverKind::Software, GpuArch::Unknown);
assert_eq!(w, vec![Workaround::Df64SpirVPoisoning]);
}
#[test]
fn nvk_safe_allocation_constant() {
const {
assert!(NVK_MAX_SAFE_ALLOCATION_BYTES < 1_500_000_000);
assert!(NVK_MAX_SAFE_ALLOCATION_BYTES > 1_000_000_000);
}
}
}