Skip to content

Commit dafcd41

Browse files
iwwuigcbot
authored andcommitted
Update the implementation for GetUpperBoundGRF
Use #define macros to store the upperBoundGRF entries Support the tables in MaxGRFTables.* files
1 parent ba77388 commit dafcd41

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed

IGC/Compiler/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ set(IGC_BUILD__SRC__Compiler
3737
"${CMAKE_CURRENT_SOURCE_DIR}/CodeGenContext.cpp"
3838
"${CMAKE_CURRENT_SOURCE_DIR}/CodeGenContextWrapper.cpp"
3939
"${CMAKE_CURRENT_SOURCE_DIR}/compiler_caps.cpp"
40+
"${CMAKE_CURRENT_SOURCE_DIR}/MaxGRFTables.cpp"
4041
"${CMAKE_CURRENT_SOURCE_DIR}/CustomSafeOptPass.cpp"
4142
"${CMAKE_CURRENT_SOURCE_DIR}/CustomUnsafeOptPass.cpp"
4243
"${CMAKE_CURRENT_SOURCE_DIR}/CustomLoopOpt.cpp"
@@ -141,6 +142,7 @@ set(IGC_BUILD__HDR__Compiler
141142
"${CMAKE_CURRENT_SOURCE_DIR}/CodeGenPublic.h"
142143
"${CMAKE_CURRENT_SOURCE_DIR}/CodeGenPublicEnums.h"
143144
"${CMAKE_CURRENT_SOURCE_DIR}/compiler_caps.h"
145+
"${CMAKE_CURRENT_SOURCE_DIR}/MaxGRFTables.h"
144146
"${CMAKE_CURRENT_SOURCE_DIR}/CustomSafeOptPass.hpp"
145147
"${CMAKE_CURRENT_SOURCE_DIR}/CustomUnsafeOptPass.hpp"
146148
"${CMAKE_CURRENT_SOURCE_DIR}/CustomLoopOpt.hpp"

IGC/Compiler/MaxGRFTables.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*========================== begin_copyright_notice ============================
2+
3+
Copyright (C) 2025 Intel Corporation
4+
5+
SPDX-License-Identifier: MIT
6+
7+
============================= end_copyright_notice ===========================*/
8+
9+
#include "MaxGRFTables.h"
10+
#include "Compiler/CISACodeGen/Platform.hpp"
11+
12+
namespace IGC
13+
{
14+
bool MaxGRFTable::MatchHWLocalID(HWLocalId fromTable, HWLocalId target)
15+
{
16+
// If target = '0', table entries with '0 or 1' and '0' are matched
17+
// If target = '1', table entries with '0 or 1' and '1' are matched
18+
if (fromTable == HWLocalId::EITHER ||
19+
fromTable == target)
20+
return true;
21+
else
22+
return false;
23+
}
24+
25+
uint16_t MaxGRFTable::LookupMaxGRF(
26+
SIMDMode simt, HWLocalId hwlid, unsigned int witems,
27+
const vector<MaxGRFEntry>& table)
28+
{
29+
MaxGRFEntry entry;
30+
// Reverse order intentionally
31+
// GRF column is accessed in descening order
32+
for (auto it = table.rbegin(); it != table.rend(); ++it)
33+
{
34+
entry = (*it);
35+
if (simt != entry.SIMT)
36+
continue;
37+
38+
if (MatchHWLocalID(entry.HWLID, hwlid) && witems <= entry.Workitems)
39+
{
40+
return entry.GRF;
41+
}
42+
}
43+
44+
return 0;
45+
}
46+
47+
void MaxGRFTable::LoadTable(const CPlatform& platform)
48+
{
49+
{
50+
#define GRF_SIMT_LID_WITEMS(a, b, c, d) table.push_back({a, b, c, d});
51+
XE3_GRF
52+
#undef GRF_SIMT_LID_WITEMS
53+
}
54+
}
55+
56+
uint16_t MaxGRFTable::GetMaxGRF(SIMDMode simt, HWLocalId hwlid,
57+
uint16_t witems, const CPlatform& platform)
58+
{
59+
if (table.empty())
60+
LoadTable(platform);
61+
62+
return LookupMaxGRF(simt, hwlid, witems, table);
63+
}
64+
65+
} //namespace IGC

IGC/Compiler/MaxGRFTables.h

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*========================== begin_copyright_notice ============================
2+
3+
Copyright (C) 2025 Intel Corporation
4+
5+
SPDX-License-Identifier: MIT
6+
7+
============================= end_copyright_notice ===========================*/
8+
9+
#pragma once
10+
11+
#include "../common/Types.hpp"
12+
#include <stdint.h>
13+
#include <vector>
14+
15+
using namespace std;
16+
using namespace IGC;
17+
18+
namespace IGC
19+
{
20+
class CPlatform;
21+
22+
enum class HWLocalId : unsigned char
23+
{
24+
VALUE0 = 0,
25+
VALUE1,
26+
EITHER
27+
};
28+
29+
// Define a struct to represent each row
30+
struct MaxGRFEntry
31+
{
32+
uint16_t GRF;
33+
SIMDMode SIMT;
34+
HWLocalId HWLID; // HW loal-id generation
35+
uint16_t Workitems;
36+
};
37+
38+
#define XE3_GRF \
39+
GRF_SIMT_LID_WITEMS(128, SIMDMode::SIMD16, HWLocalId::EITHER, 1024) \
40+
GRF_SIMT_LID_WITEMS(128, SIMDMode::SIMD32, HWLocalId::VALUE1, 1024) \
41+
GRF_SIMT_LID_WITEMS(128, SIMDMode::SIMD32, HWLocalId::VALUE0, 2048) \
42+
GRF_SIMT_LID_WITEMS(160, SIMDMode::SIMD16, HWLocalId::EITHER, 768) \
43+
GRF_SIMT_LID_WITEMS(160, SIMDMode::SIMD32, HWLocalId::VALUE1, 1024) \
44+
GRF_SIMT_LID_WITEMS(160, SIMDMode::SIMD32, HWLocalId::VALUE0, 1536) \
45+
GRF_SIMT_LID_WITEMS(192, SIMDMode::SIMD16, HWLocalId::EITHER, 640) \
46+
GRF_SIMT_LID_WITEMS(192, SIMDMode::SIMD32, HWLocalId::VALUE1, 1024) \
47+
GRF_SIMT_LID_WITEMS(192, SIMDMode::SIMD32, HWLocalId::VALUE0, 1280) \
48+
GRF_SIMT_LID_WITEMS(256, SIMDMode::SIMD16, HWLocalId::EITHER, 512) \
49+
GRF_SIMT_LID_WITEMS(256, SIMDMode::SIMD32, HWLocalId::EITHER, 1024)
50+
51+
52+
53+
// Singleton class to create only one instance
54+
class MaxGRFTable
55+
{
56+
private:
57+
MaxGRFTable() { }
58+
MaxGRFTable(const MaxGRFTable&) = delete;
59+
MaxGRFTable& operator=(const MaxGRFTable&) = delete;
60+
vector<MaxGRFEntry> table;
61+
void LoadTable(const CPlatform& platform);
62+
bool MatchHWLocalID(HWLocalId fromTable, HWLocalId target);
63+
uint16_t LookupMaxGRF(
64+
SIMDMode simt, HWLocalId hwlid, unsigned int witems,
65+
const vector<MaxGRFEntry>& table);
66+
67+
public:
68+
// Static method to access the singleton instance
69+
static MaxGRFTable& GetInstance()
70+
{
71+
static MaxGRFTable grfTable;
72+
return grfTable;
73+
}
74+
75+
uint16_t GetMaxGRF(SIMDMode simt, HWLocalId hwlid,
76+
uint16_t witems, const CPlatform& platform);
77+
};
78+
}

0 commit comments

Comments
 (0)