-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[HIP][SPIRV] Enable the SPIRV backend instead of the translator through an experimental flag. #162282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[HIP][SPIRV] Enable the SPIRV backend instead of the translator through an experimental flag. #162282
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,15 +175,33 @@ void AMDGCN::Linker::constructLinkAndEmitSpirvCommand( | |
|
||
constructLlvmLinkCommand(C, JA, Inputs, LinkedBCFile, Args); | ||
|
||
// Emit SPIR-V binary. | ||
llvm::opt::ArgStringList TrArgs{ | ||
"--spirv-max-version=1.6", | ||
"--spirv-ext=+all", | ||
"--spirv-allow-unknown-intrinsics", | ||
"--spirv-lower-const-expr", | ||
"--spirv-preserve-auxdata", | ||
"--spirv-debug-info-version=nonsemantic-shader-200"}; | ||
SPIRV::constructTranslateCommand(C, *this, JA, Output, LinkedBCFile, TrArgs); | ||
bool UseSPIRVBackend = Args.hasFlag( | ||
options::OPT_use_experimental_spirv_backend, | ||
options::OPT_no_use_experimental_spirv_backend, /*Default=*/false); | ||
|
||
// Emit SPIR-V binary either using the SPIRV backend or the translator. | ||
if (UseSPIRVBackend) { | ||
llvm::opt::ArgStringList CmdArgs; | ||
const char *Triple = | ||
C.getArgs().MakeArgString("-triple=spirv64-amd-amdhsa"); | ||
CmdArgs.append({"-cc1", Triple, "-emit-obj", LinkedBCFile.getFilename(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should consider invoking There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, using llc is vetoed. The correct way to codegen is to use cc1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also seems to be reinventing driver infrastructure it shouldn't need to? There should be some function to call for this. In particular I'm worried about the hardcoded -emit-obj here, probably breaks -save-temps? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we use the backend I don't know why we'd need special handling here. Right now this target stops at LLVM-IR, just make it emit object instead of emit IR. This flag should likely just disable this behavior entirely. Note how |
||
"-o", Output.getFilename()}); | ||
const char *Exec = getToolChain().getDriver().getClangProgramPath(); | ||
C.addCommand(std::make_unique<Command>(JA, *this, | ||
ResponseFileSupport::None(), Exec, | ||
CmdArgs, LinkedBCFile, Output)); | ||
} else { | ||
// Use the SPIRV translator for code gen. | ||
llvm::opt::ArgStringList TrArgs{ | ||
"--spirv-max-version=1.6", | ||
"--spirv-ext=+all", | ||
"--spirv-allow-unknown-intrinsics", | ||
"--spirv-lower-const-expr", | ||
"--spirv-preserve-auxdata", | ||
"--spirv-debug-info-version=nonsemantic-shader-200"}; | ||
SPIRV::constructTranslateCommand(C, *this, JA, Output, LinkedBCFile, | ||
TrArgs); | ||
} | ||
} | ||
|
||
// For amdgcn the inputs of the linker job are device bitcode and output is | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// This test case validates the behavior of -use-experimental-spirv-backend | ||
|
||
// Test that -use-experimental-spirv-backend calls clang -cc1 with the SPIRV triple. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need special handling because we do not invoke the BE in its default state, with its default flags. The vanilla target working "as you would expect" is not quite surprising, given that it's meant to work with said defaults. |
||
// RUN: %clang -x hip %s --cuda-device-only --offload-arch=amdgcnspirv -use-experimental-spirv-backend -nogpuinc -nogpulib -### 2>&1 | FileCheck %s --check-prefix=CHECK-SPIRV-BACKEND | ||
// CHECK-SPIRV-BACKEND: "{{.*}}clang{{.*}}" "-cc1" "{{.*-triple=spirv64-amd-amdhsa}}" | ||
|
||
// Test that -no-use-experimental-spirv-backend calls the SPIRV translator | ||
// RUN: %clang -x hip %s --cuda-device-only --offload-arch=amdgcnspirv -no-use-experimental-spirv-backend -nogpuinc -nogpulib -### 2>&1 | FileCheck %s --check-prefix=CHECK-SPIRV-TRANSLATOR | ||
// CHECK-SPIRV-TRANSLATOR: "{{.*llvm-spirv.*}}" "{{--spirv-max-version=[0-9]+\.[0-9]}}" | ||
|
||
// Test that by default we use the translator | ||
// RUN: %clang -x hip %s --cuda-device-only --offload-arch=amdgcnspirv -nogpuinc -nogpulib -### 2>&1 | FileCheck %s --check-prefix=CHECK-SPIRV-TRANSLATOR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a
defm
helper forno
variants right?