Skip to content

Commit 82a03f3

Browse files
vsemenov368igcbot
authored andcommitted
Make VRT GRF sizes backward-compatible in VC
If VRT GRF size is not supported for given platform, VC will look for closest largest value, e.g. on Xe2: 64->128, 96->128, 192->256.
1 parent d45ee23 commit 82a03f3

File tree

4 files changed

+62
-10
lines changed

4 files changed

+62
-10
lines changed

IGC/VectorCompiler/include/GenXSubtarget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,8 @@ class GenXSubtarget final : public GenXGenSubtargetInfo {
463463
PreDefined_Surface stackSurface() const { return StackSurf; }
464464

465465
bool isIntrinsicSupported(unsigned ID) const;
466+
467+
ArrayRef<unsigned> getSupportedGRFSizes() const;
466468
bool isValidGRFSize(unsigned Size) const;
467469
};
468470

IGC/VectorCompiler/lib/GenXCodeGen/GenXCisaBuilder.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,8 +960,15 @@ static void addKernelAttrsFromMetadata(VISAKernel &Kernel,
960960
// Set by compile option.
961961
if (BC->isAutoLargeGRFMode())
962962
NumGRF = 0;
963-
if (BC->getGRFSize())
963+
if (BC->getGRFSize()) {
964964
NumGRF = BC->getGRFSize();
965+
if (!Subtarget->isValidGRFSize(NumGRF)) {
966+
// looking for closest largest value
967+
const auto GrfSizes = Subtarget->getSupportedGRFSizes();
968+
auto It = std::upper_bound(GrfSizes.begin(), GrfSizes.end(), NumGRF);
969+
NumGRF = It != GrfSizes.end() ? *It : *(It - 1);
970+
}
971+
}
965972
// Set by kernel metadata.
966973
if (KM.getGRFSize()) {
967974
unsigned NumGRFPerKernel = *KM.getGRFSize();

IGC/VectorCompiler/lib/GenXCodeGen/GenXSubtarget.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ SPDX-License-Identifier: MIT
2727
#include "Probe/Assertion.h"
2828
#include "common/StringMacros.hpp"
2929

30-
#include <unordered_set>
30+
#include <algorithm>
3131

3232
using namespace llvm;
3333

@@ -296,22 +296,30 @@ bool GenXSubtarget::isInternalIntrinsicSupported(unsigned ID) const {
296296
return true;
297297
}
298298

299-
bool GenXSubtarget::isValidGRFSize(unsigned Size) const {
299+
ArrayRef<unsigned> GenXSubtarget::getSupportedGRFSizes() const {
300300
switch (TargetId) {
301301
case GenXSubtarget::XeHP:
302302
case GenXSubtarget::XeHPG:
303303
case GenXSubtarget::XeLPG:
304304
case GenXSubtarget::XeLPGPlus:
305305
case GenXSubtarget::XeHPC:
306306
case GenXSubtarget::XeHPCVG:
307-
case GenXSubtarget::Xe2:
308-
return Size == 128 || Size == 256;
307+
case GenXSubtarget::Xe2: {
308+
static const unsigned Supported[] = {128, 256};
309+
return Supported;
310+
}
309311
case GenXSubtarget::Xe3: {
310-
static const std::unordered_set<unsigned> Supported = {32, 64, 96, 128,
311-
160, 192, 256};
312-
return Supported.count(Size);
312+
static const unsigned Supported[] = {32, 64, 96, 128, 160, 192, 256};
313+
return Supported;
313314
}
314-
default:
315-
return Size == 128; // platforms <= TGL
315+
default: {
316+
static const unsigned Supported[] = {128}; // platforms <= TGL
317+
return Supported;
316318
}
319+
}
320+
}
321+
322+
bool GenXSubtarget::isValidGRFSize(unsigned Size) const {
323+
const auto GrfSizes = getSupportedGRFSizes();
324+
return std::binary_search(GrfSizes.begin(), GrfSizes.end(), Size);
317325
}

IGC/ocloc_tests/VC/vrt.ll

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2025 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
;
9+
; REQUIRES: regkeys, bmg-supported
10+
; RUN: llvm-as %s -opaque-pointers=0 -o %t.bc
11+
; RUN: ocloc -device bmg -llvm_input -options "-ze-exp-register-file-size=64 -vc-codegen -igc_opts 'ShaderDumpEnable=1, DumpToCustomDir=%t_opt_64'" -output_no_suffix -file %t.bc -output %t_opt_64
12+
; RUN: FileCheck %s --check-prefixes CHECK,CHECK-128 --input-file %t_opt_64/*.zeinfo
13+
; RUN: ocloc -device bmg -llvm_input -options "-ze-exp-register-file-size=128 -vc-codegen -igc_opts 'ShaderDumpEnable=1, DumpToCustomDir=%t_opt_128'" -output_no_suffix -file %t.bc -output %t_opt_128
14+
; RUN: FileCheck %s --check-prefixes CHECK,CHECK-128 --input-file %t_opt_128/*.zeinfo
15+
; RUN: ocloc -device bmg -llvm_input -options "-ze-exp-register-file-size=160 -vc-codegen -igc_opts 'ShaderDumpEnable=1, DumpToCustomDir=%t_opt_160'" -output_no_suffix -file %t.bc -output %t_opt_160
16+
; RUN: FileCheck %s --check-prefixes CHECK,CHECK-256 --input-file %t_opt_160/*.zeinfo
17+
; RUN: ocloc -device bmg -llvm_input -options "-ze-exp-register-file-size=256 -vc-codegen -igc_opts 'ShaderDumpEnable=1, DumpToCustomDir=%t_opt_256'" -output_no_suffix -file %t.bc -output %t_opt_256
18+
; RUN: FileCheck %s --check-prefixes CHECK,CHECK-256 --input-file %t_opt_256/*.zeinfo
19+
20+
declare void @llvm.vc.internal.lsc.store.ugm.v8i1.v2i8.v8i64.v8i32(<8 x i1>, i8, i8, i8, <2 x i8>, i64, <8 x i64>, i16, i32, <8 x i32>)
21+
22+
; CHECK-LABEL: - name: test
23+
; CHECK: execution_env:
24+
; CHECK-128: grf_count: 128
25+
; CHECK-256: grf_count: 256
26+
27+
define dllexport spir_kernel void @test() #0 {
28+
tail call void @llvm.vc.internal.lsc.store.ugm.v8i1.v2i8.v8i64.v8i32(<8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, i8 3, i8 3, i8 1, <2 x i8> zeroinitializer, i64 0, <8 x i64> zeroinitializer, i16 1, i32 0, <8 x i32> zeroinitializer)
29+
ret void
30+
}
31+
attributes #0 = { noinline "VCFunction" }
32+
33+
!spirv.Source = !{!0}
34+
35+
!0 = !{i32 0, i32 100000}

0 commit comments

Comments
 (0)