[mlir][Target] Make nvptxcompiler passed options high priority to keep consistent with ptxas behavior (#121036)

When using `ptxas` to do ptx->cubin, the options passed (via `cmd`) have
higher priority than the gpuModule target (such as `opt-level`). When
using `nvptxcompiler`, it is the opposite and we need to be consistent.
This commit is contained in:
Zichen Lu 2026-07-28 19:52:33 +08:00 committed by GitHub
parent abd3b3a144
commit 391d298c2a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View file

@ -587,7 +587,8 @@ NVPTXSerializer::compileToBinaryNVPTX(StringRef ptxCode) {
std::string optLevel = std::to_string(this->optLevel);
std::pair<llvm::BumpPtrAllocator, SmallVector<const char *>> cmdOpts =
targetOptions.tokenizeCmdOptions();
cmdOpts.second.append(
cmdOpts.second.insert(
cmdOpts.second.begin(),
{"-arch", getTarget().getChip().data(), "--opt-level", optLevel.c_str()});
// Set optional command line arguments

View file

@ -1,5 +1,5 @@
// RUN: mlir-opt %s \
// RUN: | mlir-opt -gpu-lower-to-nvvm-pipeline="cubin-chip=sm_80 ptxas-cmd-options='-v --register-usage-level=8' allow-pattern-rollback=0" -debug-only=serialize-to-binary \
// RUN: | mlir-opt -gpu-lower-to-nvvm-pipeline="cubin-chip=sm_80 opt-level=3 ptxas-cmd-options='-v --opt-level=2 --register-usage-level=8' allow-pattern-rollback=0" -debug-only=serialize-to-binary \
// RUN: 2>&1 | FileCheck %s
func.func @host_function(%arg0 : f32, %arg1 : memref<?xf32>) {
@ -16,6 +16,8 @@ func.func @host_function(%arg0 : f32, %arg1 : memref<?xf32>) {
return
}
// CHECK: ptxas -arch sm_80
// CHECK-SAME: -v
// CHECK: {{ptxas args: ptxas|Arguments:}} -arch sm_80
// CHECK-SAME: --opt-level 3
// CHECK-SAME: -v
// CHECK-SAME: --opt-level=2
// CHECK-SAME: --register-usage-level=8