[CUDA] Raise the default PTX level for sm_89, sm_120 and sm_121 (#24976)

Pick the default per architecture: 8.8 for sm_121, 8.7 for sm_120 and
8.4 for sm_89. An explicit --iree-cuda-target-features can still
override this.

The CUDA target always passes an explicit PTX level to the NVPTX backend
and only raised the +ptx76 default to 7.8 for sm_89. That is below what
the backend accepts for Blackwell, so `--iree-cuda-target=sm_120`
(minimum 8.7) and `sm_121` (minimum 8.8) failed for every program, and
below what the FP8 mma.sync intrinsics selected by default on Ada need,
so an f8E4M3FN matmul on sm_89 failed to select
`llvm.nvvm.mma.m16n8k32.row.col.f32.e4m3.e4m3.f32` (PTX 8.4).

Fixes #24959

Assisted-by: Claude Code

Signed-off-by: Samarth Narang <sn2910@nyu.edu>
diff --git a/compiler/plugins/target/CUDA/CUDATarget.cpp b/compiler/plugins/target/CUDA/CUDATarget.cpp
index 97b84f3..50bfa18 100644
--- a/compiler/plugins/target/CUDA/CUDATarget.cpp
+++ b/compiler/plugins/target/CUDA/CUDATarget.cpp
@@ -424,11 +424,20 @@
       return nullptr;
     }
 
-    // Use a PTX level that knows about Ada when sm_89 is selected by default.
+    // Raise the default PTX level where +ptx76 is too low: the NVPTX backend
+    // rejects levels below its per-architecture minimum (8.7 for sm_120, 8.8
+    // for sm_121), and the FP8 mma.sync intrinsics selected by default on Ada
+    // need 8.4.
     std::string targetFeatures = options.clTargetFeatures;
-    if (GPU::normalizeCUDATarget(options.clTarget) == "sm_89" &&
-        targetFeatures == "+ptx76") {
-      targetFeatures = "+ptx78";
+    if (targetFeatures == "+ptx76") {
+      StringRef arch = GPU::normalizeCUDATarget(options.clTarget);
+      if (arch == "sm_121") {
+        targetFeatures = "+ptx88";
+      } else if (arch == "sm_120") {
+        targetFeatures = "+ptx87";
+      } else if (arch == "sm_89") {
+        targetFeatures = "+ptx84";
+      }
     }
 
     if (auto target = GPU::getCUDATargetDetails(options.clTarget,
diff --git a/compiler/plugins/target/CUDA/test/target_device_features.mlir b/compiler/plugins/target/CUDA/test/target_device_features.mlir
index 2fb1072..439d52a 100644
--- a/compiler/plugins/target/CUDA/test/target_device_features.mlir
+++ b/compiler/plugins/target/CUDA/test/target_device_features.mlir
@@ -7,11 +7,15 @@
 // RUN: iree-opt --pass-pipeline='builtin.module(iree-hal-assign-target-devices{targetDevices=cuda},iree-hal-transformation-pipeline{serialize-executables=false})' \
 // RUN:   --iree-cuda-target=sm_89 --iree-cuda-target-features=+ptx80 %s | FileCheck %s --check-prefix=PTX80
 // RUN: iree-opt --pass-pipeline='builtin.module(iree-hal-assign-target-devices{targetDevices=cuda},iree-hal-transformation-pipeline{serialize-executables=false})' \
+// RUN:   --iree-cuda-target=sm_120 %s | FileCheck %s --check-prefix=SM120
+// RUN: iree-opt --pass-pipeline='builtin.module(iree-hal-assign-target-devices{targetDevices=cuda},iree-hal-transformation-pipeline{serialize-executables=false})' \
+// RUN:   --iree-cuda-target=sm_121 %s | FileCheck %s --check-prefix=SM121
+// RUN: iree-opt --pass-pipeline='builtin.module(iree-hal-assign-target-devices{targetDevices=cuda},iree-hal-transformation-pipeline{serialize-executables=false})' \
 // RUN:   --iree-cuda-target=sm_120 --iree-cuda-target-features=+ptx87 %s | FileCheck %s --check-prefix=SM120
 // RUN: iree-opt --pass-pipeline='builtin.module(iree-hal-assign-target-devices{targetDevices=cuda},iree-hal-transformation-pipeline{serialize-executables=false})' \
 // RUN:   --iree-cuda-target=sm_121 --iree-cuda-target-features=+ptx88 %s | FileCheck %s --check-prefix=SM121
 
-// SM89: target_info = #iree_gpu.target<arch = "sm_89", features = "+ptx78",
+// SM89: target_info = #iree_gpu.target<arch = "sm_89", features = "+ptx84",
 // SM89-SAME: wgp = <compute = fp64|fp32|fp16|int64|int32|int16|int8, storage = b64|b32|b16|b8,
 // SM89-SAME:         subgroup = shuffle|arithmetic, dot = dp4xi8toi32,
 // SM89-SAME:         mma = [<NV_MMA_SYNC_F32_16x8x16_F16>, <NV_MMA_SYNC_F16_16x8x16_F16>, <NV_MMA_SYNC_F32_16x8x16_BF16>, <NV_MMA_SYNC_F32_16x8x32_F8E4M3FN>, <NV_MMA_SYNC_F32_16x8x32_F8E5M2>, <NV_WMMA_F32_16x16x16_F16>, <NV_WMMA_F16_16x16x16_F16>],