Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 35 additions & 43 deletions crates/nvvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,7 @@ pub enum NvvmArch {

impl Display for NvvmArch {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let raw = format!("{self:?}").to_ascii_lowercase();
// Handle architectures with suffixes (e.g., Compute90a -> compute_90a)
if let Some(pos) = raw.find(|c: char| c.is_ascii_digit()) {
let (prefix, rest) = raw.split_at(pos);
write!(f, "{prefix}_{rest}")
} else {
// Fallback for unexpected format
f.write_str(&raw)
}
f.write_str(self.target_feature())
}
}

Expand Down Expand Up @@ -396,40 +388,40 @@ impl NvvmArch {
}

/// Get the target feature string (e.g., "compute_35" for Compute35, "compute_90a" for Compute90a)
pub fn target_feature(&self) -> String {
pub fn target_feature(&self) -> &'static str {
match self {
Self::Compute35 => "compute_35".to_string(),
Self::Compute37 => "compute_37".to_string(),
Self::Compute50 => "compute_50".to_string(),
Self::Compute52 => "compute_52".to_string(),
Self::Compute53 => "compute_53".to_string(),
Self::Compute60 => "compute_60".to_string(),
Self::Compute61 => "compute_61".to_string(),
Self::Compute62 => "compute_62".to_string(),
Self::Compute70 => "compute_70".to_string(),
Self::Compute72 => "compute_72".to_string(),
Self::Compute75 => "compute_75".to_string(),
Self::Compute80 => "compute_80".to_string(),
Self::Compute86 => "compute_86".to_string(),
Self::Compute87 => "compute_87".to_string(),
Self::Compute89 => "compute_89".to_string(),
Self::Compute90 => "compute_90".to_string(),
Self::Compute90a => "compute_90a".to_string(),
Self::Compute100 => "compute_100".to_string(),
Self::Compute100f => "compute_100f".to_string(),
Self::Compute100a => "compute_100a".to_string(),
Self::Compute101 => "compute_101".to_string(),
Self::Compute101f => "compute_101f".to_string(),
Self::Compute101a => "compute_101a".to_string(),
Self::Compute103 => "compute_103".to_string(),
Self::Compute103f => "compute_103f".to_string(),
Self::Compute103a => "compute_103a".to_string(),
Self::Compute120 => "compute_120".to_string(),
Self::Compute120f => "compute_120f".to_string(),
Self::Compute120a => "compute_120a".to_string(),
Self::Compute121 => "compute_121".to_string(),
Self::Compute121f => "compute_121f".to_string(),
Self::Compute121a => "compute_121a".to_string(),
Self::Compute35 => "compute_35",
Self::Compute37 => "compute_37",
Self::Compute50 => "compute_50",
Self::Compute52 => "compute_52",
Self::Compute53 => "compute_53",
Self::Compute60 => "compute_60",
Self::Compute61 => "compute_61",
Self::Compute62 => "compute_62",
Self::Compute70 => "compute_70",
Self::Compute72 => "compute_72",
Self::Compute75 => "compute_75",
Self::Compute80 => "compute_80",
Self::Compute86 => "compute_86",
Self::Compute87 => "compute_87",
Self::Compute89 => "compute_89",
Self::Compute90 => "compute_90",
Self::Compute90a => "compute_90a",
Self::Compute100 => "compute_100",
Self::Compute100f => "compute_100f",
Self::Compute100a => "compute_100a",
Self::Compute101 => "compute_101",
Self::Compute101f => "compute_101f",
Self::Compute101a => "compute_101a",
Self::Compute103 => "compute_103",
Self::Compute103f => "compute_103f",
Self::Compute103a => "compute_103a",
Self::Compute120 => "compute_120",
Self::Compute120f => "compute_120f",
Self::Compute120a => "compute_120a",
Self::Compute121 => "compute_121",
Self::Compute121f => "compute_121f",
Self::Compute121a => "compute_121a",
}
}

Expand All @@ -451,7 +443,7 @@ impl NvvmArch {
///
/// For more details on family and architecture-specific features, see:
/// <https://developer.nvidia.com/blog/nvidia-blackwell-and-nvidia-cuda-12-9-introduce-family-specific-architecture-features/>
pub fn all_target_features(&self) -> Vec<String> {
pub fn all_target_features(&self) -> Vec<&'static str> {
// All lower-or-equal baseline features are included.
let included_baseline = |arch: &NvvmArch| {
arch.is_base_variant() && arch.capability_value() <= self.capability_value()
Expand Down
6 changes: 5 additions & 1 deletion crates/rustc_codegen_nvvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ impl CodegenBackend for NvvmCodegenBackend {
for opt in &args.nvvm_options {
if let ::nvvm::NvvmOption::Arch(arch) = opt {
// Add all features up to and including the current architecture
features.extend(arch.all_target_features());
features.extend(
arch.all_target_features()
.into_iter()
.map(|s| s.to_string()),
);
break;
}
}
Expand Down
Loading