-
Notifications
You must be signed in to change notification settings - Fork 738
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCL][ESIMD] Rework -O0 behavior (#12612)
Let me first say I don't like this change and I wish we didn't have to do this, and it should only be temporary. The root need is that the IGC VC backend does not support O0 code. It gets miscompiled and produces wrong answers and crashes. The team acknowledges this issue but does not have the resources to fix this at the moment. From the ESIMD user POV, this is really frustrating. We decided it would be okay if they lost debuggability of device code (but retained it for host code) as long as their program runs and they get the right answer. So the overall approach is to optimize ESIMD(Not SYCL!!) code even in O0 mode. We are actually already doing this, but this change extends it a bit. So there are a few main changes in this PR: 1) Don't pass `-O0` to `sycl-post-link`. Note this option has absolutely no effect on SYCL code today, it is only checked in the ESIMD lowering code in `sycl-post-link`. 2) Add a new pass to remove `optnone`/`noinline` early for ESIMD code in `O0`. 3) Remove `optnone`/`noinline` from all functions if we split out ESIMD/SYCL code, and if we don't don't touch it. All three of these steps are required to fix the tests failing with `O0`, if we remove any one of them we see many failures. When running all ESIMD tests with `O0`, we see the following improvements: ``` Linux: Today: 97 failures With this change: 23 failures, with ~3 root causes. There are no regressions. I'll look into these later. ``` ``` Windows: Today: 38 failures With this change: 10 failures. There are no regressions. I'll look into these later. ``` Once IGC VC can actually correctly compile non-optimized code, we should revert this change. --------- Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
- Loading branch information
Showing
16 changed files
with
123 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//=-- ESIMDRemoveOptnoneNoinline.cpp - remove optnone/noinline for ESIMD --=// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//=------------------------------------------------------------------------=// | ||
// The GPU backend for ESIMD does not support debugging and we often see crashes | ||
// or wrong answers if we do not optimize. Remove optnone and noinline from | ||
// ESIMD functions so users at least can run their programs and get the | ||
// right answer. | ||
//=------------------------------------------------------------------------=// | ||
|
||
#include "llvm/IR/Function.h" | ||
#include "llvm/IR/Module.h" | ||
#include "llvm/Pass.h" | ||
#include "llvm/SYCLLowerIR/ESIMD/ESIMDUtils.h" | ||
#include "llvm/SYCLLowerIR/ESIMD/LowerESIMD.h" | ||
#include "llvm/Support/Debug.h" | ||
|
||
using namespace llvm; | ||
using namespace llvm::esimd; | ||
|
||
cl::opt<bool> AllowOptnoneNoinline( | ||
"esimd-allow-optnone-noinline", llvm::cl::Optional, llvm::cl::Hidden, | ||
llvm::cl::desc("Allow optnone and noinline."), llvm::cl::init(false)); | ||
|
||
PreservedAnalyses ESIMDRemoveOptnoneNoinlinePass::run(Module &M, | ||
ModuleAnalysisManager &) { | ||
if (AllowOptnoneNoinline) | ||
return PreservedAnalyses::all(); | ||
|
||
// TODO: Remove this pass once VC supports debugging. | ||
bool Modified = false; | ||
for (auto &F : M.functions()) { | ||
if (!isESIMD(F) || F.hasFnAttribute("CMGenxSIMT")) | ||
continue; | ||
F.removeFnAttr(Attribute::OptimizeNone); | ||
F.removeFnAttr(Attribute::NoInline); | ||
Modified = true; | ||
} | ||
return Modified ? PreservedAnalyses::none() : PreservedAnalyses::all(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
; This ensures we remove optnone from ESIMD functions unless they are SIMT or we didn't split ESIMD code out. | ||
; RUN: sycl-post-link -split-esimd -lower-esimd -S < %s -o %t.table | ||
; RUN: FileCheck %s -input-file=%t_esimd_0.ll --check-prefixes CHECK,CHECK-ESIMD-SPLIT | ||
|
||
; RUN: sycl-post-link -lower-esimd -S < %s -o %t1.table | ||
; RUN: FileCheck %s -input-file=%t1_esimd_0.ll --check-prefixes CHECK,CHECK-NO-ESIMD-SPLIT | ||
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64" | ||
target triple = "spir64-unknown-unknown" | ||
|
||
define dso_local spir_func void @esimd() #0 !sycl_explicit_simd !0 { | ||
; CHECK: void @esimd() #[[#ESIMDAttr:]] | ||
ret void | ||
} | ||
|
||
define dso_local spir_func void @esimd_simt() #1 !sycl_explicit_simd !0 { | ||
; CHECK: void @esimd_simt() #[[#ESIMDSIMTAttr:]] | ||
ret void | ||
} | ||
|
||
define dso_local spir_func void @sycl() #0 { | ||
; CHECK: spir_func void @sycl() #[[#ESIMDAttr]] | ||
ret void | ||
} | ||
; CHECK-ESIMD-SPLIT: attributes #[[#ESIMDAttr]] = | ||
; CHECK-ESIMD-SPLIT-NOT: optnone | ||
; CHECK-NO-ESIMD-SPLIT: attributes #[[#ESIMDAttr]] = {{{.*}}optnone{{.*}}} | ||
; CHECK: attributes #[[#ESIMDSIMTAttr]] = {{{.*}}optnone | ||
; CHECK-SAME: "CMGenxSIMT" | ||
; CHECK-SAME: } | ||
attributes #0 = { noinline optnone convergent } | ||
attributes #1 = { noinline optnone convergent "CMGenxSIMT"} | ||
!0 = !{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import platform | ||
|
||
config.substitutions.append(("%clang_O0", "-O0 -mllvm -esimd-allow-optnone-noinline")) |