| 1 |
/*========================== begin_copyright_notice ============================ |
| 2 |
|
| 3 |
Copyright (C) 2017-2021 Intel Corporation |
| 4 |
|
| 5 |
SPDX-License-Identifier: MIT |
| 6 |
|
| 7 |
============================= end_copyright_notice ===========================*/ |
| 8 |
|
| 9 |
#ifndef _IGA_REGDEPS_HPP |
| 10 |
#define _IGA_REGDEPS_HPP |
| 11 |
|
| 12 |
#include "BitSet.hpp" |
| 13 |
#include "Instruction.hpp" |
| 14 |
#include "Kernel.hpp" // BlockList TODO: move to Blocks.hpp (elide Encoder def) |
| 15 |
|
| 16 |
#include <map> |
| 17 |
#include <memory> |
| 18 |
#include <ostream> |
| 19 |
#include <set> |
| 20 |
#include <vector> |
| 21 |
|
| 22 |
namespace iga { |
| 23 |
|
| 24 |
enum class DEP_TYPE { |
| 25 |
NONE, |
| 26 |
READ, |
| 27 |
WRITE, |
| 28 |
WRITE_ALWAYS_INTERFERE, |
| 29 |
READ_ALWAYS_INTERFERE |
| 30 |
}; |
| 31 |
|
| 32 |
enum class DEP_PIPE { |
| 33 |
NONE, |
| 34 |
// TGL |
| 35 |
SHORT, |
| 36 |
LONG, |
| 37 |
CONTROL_FLOW, // TGL only |
| 38 |
SEND, |
| 39 |
MATH, |
| 40 |
// XeHP+ |
| 41 |
FLOAT, |
| 42 |
INTEGER, |
| 43 |
LONG64, |
| 44 |
DPAS, |
| 45 |
// XeHPG+ |
| 46 |
SEND_SLM, // LSC SLM message |
| 47 |
SEND_UNKNOWN, // LSC desc is indirect, not sure if it's SLM |
| 48 |
// XeHPC+ |
| 49 |
MATH_INORDER, |
| 50 |
SCALAR // XE3+ |
| 51 |
}; |
| 52 |
|
| 53 |
enum class DEP_CLASS { NONE, IN_ORDER, OUT_OF_ORDER, OTHER }; |
| 54 |
struct SBID { |
| 55 |
uint32_t sbid = 0; |
| 56 |
DEP_TYPE dType = DEP_TYPE::NONE; |
| 57 |
bool isFree = true; |
| 58 |
|
| 59 |
SBID() {} |
| 60 |
|
| 61 |
SBID(uint32_t id, bool isfree, DEP_TYPE type) |
| 62 |
: sbid(id), dType(type), isFree(isfree) {} |
| 63 |
|
| 64 |
void reset() { |
| 65 |
sbid = 0; |
| 66 |
dType = DEP_TYPE::NONE; |
| 67 |
isFree = true; |
| 68 |
} |
| 69 |
}; |
| 70 |
|
| 71 |
class DepSetBuilder; |
| 72 |
|
| 73 |
// A sort of bit set for representing |
| 74 |
// BITs per 32-byte GRF register |
| 75 |
// 1 would be register granularity only |
| 76 |
// 8 would be DWORD granularity |
| 77 |
class DepSet { |
| 78 |
friend DepSetBuilder; |
| 79 |
|
| 80 |
public: |
| 81 |
struct InstIDs { |
| 82 |
public: |
| 83 |
InstIDs() {} |
| 84 |
InstIDs(uint32_t global_id, uint32_t in_order_id) |
| 85 |
: global(global_id), inOrder(in_order_id) {} |
| 86 |
|
| 87 |
InstIDs(uint32_t global_id, uint32_t in_order_id, uint32_t float_pipe_id, |
| 88 |
uint32_t int_pipe_id, uint32_t long_pipe_id, uint32_t math_pipe_id, |
| 89 |
uint32_t scalar_pipe_id) |
| 90 |
: global(global_id), inOrder(in_order_id), floatPipe(float_pipe_id), |
| 91 |
intPipe(int_pipe_id), longPipe(long_pipe_id), mathPipe(math_pipe_id), |
| 92 |
scalarPipe(scalar_pipe_id) {} |
| 93 |
|
| 94 |
// set all pipe ids to 1 |
| 95 |
void init() { |
| 96 |
global = 1; |
| 97 |
inOrder = 1; |
| 98 |
floatPipe = 1; |
| 99 |
intPipe = 1; |
| 100 |
longPipe = 1; |
| 101 |
mathPipe = 1; |
| 102 |
scalarPipe = 1; |
| 103 |
} |
| 104 |
|
| 105 |
// unique id for all instructions |
| 106 |
uint32_t global = 0; |
| 107 |
// id counter for all in-order instructions |
| 108 |
uint32_t inOrder = 0; |
| 109 |
// id coutner for float pipe |
| 110 |
uint32_t floatPipe = 0; |
| 111 |
// id counter for short pipe |
| 112 |
uint32_t intPipe = 0; |
| 113 |
// id counter for Long pipe |
| 114 |
uint32_t longPipe = 0; |
| 115 |
// id counter for in-order math pipe |
| 116 |
uint32_t mathPipe = 0; |
| 117 |
// id counter for in-order scalar pipe |
| 118 |
uint32_t scalarPipe = 0; |
| 119 |
}; |
| 120 |
|
| 121 |
typedef std::pair<uint32_t, uint32_t> RegRangeType; |
| 122 |
typedef std::vector<RegRangeType> RegRangeListType; |
| 123 |
|
| 124 |
private: |
| 125 |
DepSet(const InstIDs &inst_id_counter, const DepSetBuilder &dsb); |
| 126 |
~DepSet() { delete bits; } |
| 127 |
DepSet(const DepSet &ds) = delete; |
| 128 |
DepSet &operator=(DepSet const &) = delete; |
| 129 |
|
| 130 |
public: |
| 131 |
// FIXME: shold be moved to DepSetBuilder |
| 132 |
uint32_t addressOf(RegName rn, const RegRef &rr, |
| 133 |
uint32_t typeSizeBytes) const; |
| 134 |
bool isRegTracked(RegName rn) const; |
| 135 |
|
| 136 |
void setDepType(DEP_TYPE type) { m_dType = type; } |
| 137 |
void setHasIndirect() { m_hasIndirect = true; } |
| 138 |
void setHasSR() { m_hasSR = true; } |
| 139 |
|
| 140 |
void addGrf(size_t reg); |
| 141 |
void addGrfBytes(size_t reg, size_t subRegBytes, size_t bytes); |
| 142 |
void addABytesAndBukets(size_t reg); |
| 143 |
void addFBytes(size_t fByteOff, size_t bytes); |
| 144 |
void addToBucket(size_t regNum) { m_bucketList.push_back(regNum); } |
| 145 |
void setDepPipe(DEP_PIPE pipe) { m_dPipe = pipe; } |
| 146 |
void setDepClass(DEP_CLASS cls) { m_dClass = cls; } |
| 147 |
void setSBID(SBID &sw) { m_sbid = sw; } |
| 148 |
|
| 149 |
bool empty() const { return bits->empty(); } |
| 150 |
void reset() { bits->reset(); } |
| 151 |
bool intersects(const DepSet &rhs) const { |
| 152 |
return bits->intersects(*rhs.bits); |
| 153 |
} |
| 154 |
DEP_TYPE getDepType() const { return m_dType; } |
| 155 |
bool hasIndirect() const { return m_hasIndirect; } |
| 156 |
bool hasSR() const { return m_hasSR; } |
| 157 |
const Instruction *getInstruction() const { return m_instruction; } |
| 158 |
Instruction *getInstruction() { return m_instruction; } |
| 159 |
const InstIDs &getInstIDs() const { return m_InstIDs; } |
| 160 |
size_t getInstGlobalID() const { return m_InstIDs.global; } |
| 161 |
|
| 162 |
DEP_PIPE getDepPipe() const { return m_dPipe; } |
| 163 |
DEP_CLASS getDepClass() const { return m_dClass; } |
| 164 |
SBID getSBID() const { return m_sbid; } |
| 165 |
void str(std::ostream &os) const; |
| 166 |
std::string str() const; |
| 167 |
bool destructiveSubtract(const DepSet &rhs); |
| 168 |
|
| 169 |
const std::vector<size_t> &getBuckets() const { return m_bucketList; } |
| 170 |
const BitSet<> &getBitSet() const { return *bits; } |
| 171 |
BitSet<> &getBitSetVol() { return *bits; } |
| 172 |
|
| 173 |
const DepSet *getCompanion() const { return m_companion; } |
| 174 |
DepSet *getCompanion() { return m_companion; } |
| 175 |
|
| 176 |
void setCompanion(DepSet *companion) { m_companion = companion; } |
| 177 |
|
| 178 |
std::vector<Instruction*> getSrcDepInsts() { return m_SrcDepInsts; } |
| 179 |
void addSrcDepInsts(Instruction* inst) { m_SrcDepInsts.push_back(inst); } |
| 180 |
|
| 181 |
private: |
| 182 |
void setInputsFlagDep(); |
| 183 |
void setInputsSrcDep(); |
| 184 |
void setInputsSendDescDep(); |
| 185 |
|
| 186 |
void setOutputsFlagDep(); |
| 187 |
void setOutputsDstDep(); |
| 188 |
// set the register footprint on full registers for all registers |
| 189 |
// the given dst has touched. For example, consider the entire r2 as |
| 190 |
// its footprint for a dst register "r2.2:d" |
| 191 |
// This is a helper setter for some Workarounds |
| 192 |
void setOutputsDstDepFullGrf(); |
| 193 |
|
| 194 |
void setDstRegion(RegName rn, RegRef rr, Region r, uint32_t execSize, |
| 195 |
uint32_t typeSizeBits); |
| 196 |
|
| 197 |
// Set DepSet::bits according to the given register information |
| 198 |
// Return the start bucket number and number of buckets touched in pair, |
| 199 |
// when the given register is a tracked register (DepSet::isRegTracked). |
| 200 |
// Otherwise, return bucket size (getTOTAL_BUCKETS) as an invalid number. |
| 201 |
// The bucket number is equal to GRF number when the register is GRF. |
| 202 |
// This information can be used by the caller to check if the instruction |
| 203 |
// has intra read suppression. |
| 204 |
std::pair<uint32_t, uint32_t> setSrcRegion( |
| 205 |
RegName rn, RegRef rr, Region r, uint32_t execSize, uint32_t typeSizeBits); |
| 206 |
|
| 207 |
// Set DepSet::bits for the send src with scalar register. |
| 208 |
// rr: start offset of the scalar register |
| 209 |
// numBytes: number of bytes read from this scalar register |
| 210 |
void setSendSrcScalarRegRegion(const RegRef &rr, uint32_t numBytes); |
| 211 |
|
| 212 |
// Set the bits to this DepSet with the given reg_range |
| 213 |
void addDependency(const RegRangeType ®_range); |
| 214 |
void addDependency(const RegRangeListType ®_range); |
| 215 |
|
| 216 |
// get the used src registers of given dpas inst |
| 217 |
// Return: in reg_range each pair denotes start and upper grf reg number of |
| 218 |
// each src extra_regs - the extra register footprint required by HW |
| 219 |
// workaround: treat Src2 as dpas.8x8 |
| 220 |
// when calculating register footpring. extra_regs only affect |
| 221 |
// external dependency and will not apply to calculating |
| 222 |
// dpas/macro internal dependency |
| 223 |
void getDpasSrcDependency(const Instruction &inst, |
| 224 |
RegRangeListType ®_range, |
| 225 |
RegRangeListType &extra_regs, const Model &model); |
| 226 |
|
| 227 |
// get the used dst registers of given dpas inst |
| 228 |
// Return: in reg_range denotes the start and upper grf reg number |
| 229 |
void getDpasDstDependency(const Instruction &inst, RegRangeType ®_range); |
| 230 |
|
| 231 |
// helper function to get dpas src register footpring upper bound |
| 232 |
uint32_t getDPASSrcDepUpBound(unsigned idx, Type srcType, uint32_t execSize, |
| 233 |
uint32_t lowBound, uint32_t systolicDepth, |
| 234 |
uint32_t repeatCount, uint32_t opsPerChan); |
| 235 |
// helper function to get dpas OPS_PER_CHAN |
| 236 |
uint32_t getDPASOpsPerChan(Type src1_ty, Type src2_ty, bool isDF); |
| 237 |
|
| 238 |
private: |
| 239 |
Instruction *m_instruction = nullptr; |
| 240 |
|
| 241 |
// track the inst id counters when it reach to this instruction |
| 242 |
const InstIDs m_InstIDs; |
| 243 |
|
| 244 |
const DepSetBuilder &m_DB; |
| 245 |
|
| 246 |
DEP_TYPE m_dType = DEP_TYPE::NONE; |
| 247 |
DEP_PIPE m_dPipe = DEP_PIPE::NONE; |
| 248 |
DEP_CLASS m_dClass = DEP_CLASS::NONE; |
| 249 |
BitSet<> *bits; |
| 250 |
std::vector<size_t> m_bucketList; |
| 251 |
SBID m_sbid; |
| 252 |
bool m_hasIndirect = false; |
| 253 |
// set true if the instruction has access the special registers: CR, CE, SR |
| 254 |
// In this case we cannot be sure which register it is actually affect, |
| 255 |
// will need to sync all pipes |
| 256 |
bool m_hasSR = false; |
| 257 |
void formatShortReg(std::ostream &os, bool &first, const char *reg_name, |
| 258 |
size_t reg_num, size_t reg_start, size_t reg_len) const; |
| 259 |
|
| 260 |
// There are always two DepSet (input and output) for an instruction. Here |
| 261 |
// record the compnion DepSet that create for the same instruction with this |
| 262 |
// DepSet. This is for the use of when we clear an in-order instruction's |
| 263 |
// dependency, we'd like to clear its both input and output DepSets |
| 264 |
DepSet *m_companion = nullptr; |
| 265 |
|
| 266 |
// A list of instructions those having sbid.src dependency to this DepSet |
| 267 |
// This is needed for updating their sbid if when SWSBAnalyzer::trySBIDCounter |
| 268 |
std::vector<Instruction*> m_SrcDepInsts; |
| 269 |
}; |
| 270 |
|
| 271 |
/// DepSetBuilder - create the DepSet, also keep track of Model dependend |
| 272 |
/// register info |
| 273 |
class DepSetBuilder { |
| 274 |
public: |
| 275 |
typedef DepSet::InstIDs InstIDs; |
| 276 |
|
| 277 |
DepSetBuilder(const Model &model) |
| 278 |
: GRF_REGS(model.getNumGRF()), GRF_BYTES_PER_REG(model.getGRFByteSize()), |
| 279 |
ARF_A_BYTES_PER_REG(model.getBytesPerReg(RegName::ARF_A)), |
| 280 |
ARF_A_REGS(model.getRegCount(RegName::ARF_A)), |
| 281 |
ARF_F_REGS(model.getNumFlagReg()), mPlatformModel(model) { |
| 282 |
if (model.platform >= Platform::XE3) { |
| 283 |
ARF_SCALAR_REGS = model.getRegCount(RegName::ARF_S); |
| 284 |
ARF_SCALAR_BYTES_PER_REG = model.getBytesPerReg(RegName::ARF_S); |
| 285 |
} |
| 286 |
} |
| 287 |
|
| 288 |
~DepSetBuilder() { |
| 289 |
for (auto ds : mAllDepSet) |
| 290 |
delete ds; |
| 291 |
} |
| 292 |
|
| 293 |
DepSetBuilder(const DepSetBuilder &) = delete; |
| 294 |
DepSetBuilder &operator=(const DepSetBuilder &) = delete; |
| 295 |
|
| 296 |
public: |
| 297 |
// DepSet creater |
| 298 |
/// createSrcDepSet - create DepSet for src operands of instruction i |
| 299 |
DepSet *createSrcDepSet(Instruction &i, const InstIDs &inst_id_counter, |
| 300 |
SWSB_ENCODE_MODE enc_mode); |
| 301 |
/// createDstDepSet - create DepSet for dst operands of instruction i |
| 302 |
DepSet *createDstDepSet(Instruction &i, const InstIDs &inst_id_counter, |
| 303 |
SWSB_ENCODE_MODE enc_mode); |
| 304 |
|
| 305 |
/// createSrcDstDepSetForDpas - Find the DPAS macro and set the dependency for |
| 306 |
/// input and output return the created DepSets for input(src) and output(dst) |
| 307 |
std::pair<DepSet *, DepSet *> |
| 308 |
createDPASSrcDstDepSet(const InstList &insList, InstListIterator instIt, |
| 309 |
const InstIDs &inst_id_counter, size_t &dpasCnt, |
| 310 |
SWSB_ENCODE_MODE enc_mode); |
| 311 |
|
| 312 |
/// mathDstWA - this will return the DepSet with math's dst region, and force |
| 313 |
/// to occupy the entire registers no matter what the region and channel are. |
| 314 |
/// e.g. if dst is r1.3, it'll occupy the entire r1 |
| 315 |
/// @input setFlagDep - True if this is a full DepSet creation and would like |
| 316 |
/// to set the dep |
| 317 |
/// for flag registers. False if the DepSet is an |
| 318 |
/// additional dependecny for an instruction which already |
| 319 |
/// has DepSet created (e.g. for MathWA) |
| 320 |
/// This is the WA to fix the HW read suppression issue |
| 321 |
DepSet *createDstDepSetFullGrf(Instruction &i, |
| 322 |
const InstIDs &inst_id_counter, |
| 323 |
SWSB_ENCODE_MODE enc_mode, bool setFlagDep); |
| 324 |
|
| 325 |
uint32_t getBYTES_PER_BUCKET() const { return getGRF_BYTES_PER_REG(); } |
| 326 |
|
| 327 |
// Register File Size Info |
| 328 |
uint32_t getGRF_REGS() const { return GRF_REGS; } |
| 329 |
uint32_t getGRF_BYTES_PER_REG() const { return GRF_BYTES_PER_REG; } |
| 330 |
uint32_t getGRF_LEN() const { return GRF_REGS * GRF_BYTES_PER_REG; } |
| 331 |
|
| 332 |
uint32_t getARF_A_BYTES_PER_REG() const { return ARF_A_BYTES_PER_REG; } |
| 333 |
uint32_t getARF_A_REGS() const { return ARF_A_REGS; } |
| 334 |
uint32_t getARF_A_LEN() const { return ARF_A_REGS * ARF_A_BYTES_PER_REG; } |
| 335 |
|
| 336 |
uint32_t getARF_ACC_REGS() const { return ARF_ACC_REGS; } |
| 337 |
uint32_t getARF_ACC_BYTES_PER_REG() const { return ARF_ACC_BYTES_PER_REG; } |
| 338 |
uint32_t getARF_ACC_LEN() const { |
| 339 |
return ARF_ACC_REGS * ARF_ACC_BYTES_PER_REG; |
| 340 |
} |
| 341 |
|
| 342 |
uint32_t getARF_F_REGS() const { return ARF_F_REGS; } |
| 343 |
uint32_t getARF_F_BYTES_PER_REG() const { return ARF_F_BYTES_PER_REG; } |
| 344 |
uint32_t getARF_F_LEN() const { return ARF_F_REGS * ARF_F_BYTES_PER_REG; } |
| 345 |
|
| 346 |
uint32_t getARF_SPECIAL_REGS() const { return ARF_SPECIAL_REGS; } |
| 347 |
uint32_t getARF_SPECIAL_BYTES_PER_REG() const { |
| 348 |
return ARF_SPECIAL_BYTES_PER_REG; |
| 349 |
} |
| 350 |
uint32_t getARF_SPECIAL_LEN() const { |
| 351 |
return ARF_SPECIAL_REGS * ARF_SPECIAL_BYTES_PER_REG; |
| 352 |
} |
| 353 |
|
| 354 |
uint32_t getARF_SCALAR_REGS() const { return ARF_SCALAR_REGS; } |
| 355 |
uint32_t getARF_SCALAR_BYTES_PER_REG() const { |
| 356 |
return ARF_SCALAR_BYTES_PER_REG; |
| 357 |
} |
| 358 |
uint32_t getARF_SCALAR_LEN() const { |
| 359 |
return ARF_SCALAR_REGS * ARF_SCALAR_BYTES_PER_REG; |
| 360 |
} |
| 361 |
|
| 362 |
// align each register files to bucket size so the different register files |
| 363 |
// fall into different bucket |
| 364 |
uint32_t getGRF_START() const { return 0; } |
| 365 |
uint32_t getARF_A_START() const { |
| 366 |
return ALIGN_UP_TO(getBYTES_PER_BUCKET(), getGRF_START() + getGRF_LEN()); |
| 367 |
} |
| 368 |
uint32_t getARF_ACC_START() const { |
| 369 |
return ALIGN_UP_TO(getBYTES_PER_BUCKET(), |
| 370 |
getARF_A_START() + getARF_A_LEN()); |
| 371 |
} |
| 372 |
uint32_t getARF_F_START() const { |
| 373 |
return ALIGN_UP_TO(getBYTES_PER_BUCKET(), |
| 374 |
getARF_ACC_START() + getARF_ACC_LEN()); |
| 375 |
} |
| 376 |
uint32_t getARF_SPECIAL_START() const { |
| 377 |
return ALIGN_UP_TO(getBYTES_PER_BUCKET(), |
| 378 |
getARF_F_START() + getARF_F_LEN()); |
| 379 |
} |
| 380 |
uint32_t getARF_SCALAR_START() const { |
| 381 |
return ALIGN_UP_TO(getBYTES_PER_BUCKET(), |
| 382 |
getARF_SPECIAL_START() + getARF_SPECIAL_LEN()); |
| 383 |
} |
| 384 |
uint32_t getTOTAL_END() const { |
| 385 |
return ALIGN_UP_TO(getBYTES_PER_BUCKET(), |
| 386 |
getARF_SCALAR_START() + getARF_SCALAR_LEN()); |
| 387 |
} |
| 388 |
|
| 389 |
uint32_t getTOTAL_BITS() const { return getTOTAL_END(); } |
| 390 |
uint32_t getTOTAL_BUCKETS() const { |
| 391 |
return getTOTAL_BITS() / getBYTES_PER_BUCKET() + 1; |
| 392 |
} |
| 393 |
|
| 394 |
uint32_t getBucketStart(RegName regname) const; |
| 395 |
|
| 396 |
/// ------------ HW Workaround Information ------------ /// |
| 397 |
// When double precision or Math instructions write a register, and the same |
| 398 |
// register is reused by following instructions going to any pipe, the |
| 399 |
// instruction is considered to occupy the full register irrespective of sub |
| 400 |
// register number |
| 401 |
bool needDstReadSuppressionWA(const Instruction &inst) const; |
| 402 |
|
| 403 |
// Src1 always have 8 register footpring |
| 404 |
bool needDPASSrc1WA() const |
| 405 |
{ return mPlatformModel.platform == Platform::XE_HP; } |
| 406 |
|
| 407 |
// Treat Dpas Src2 as dpas.8x8 when calculating register footpring |
| 408 |
// (always read 4 registers) |
| 409 |
bool needDPASSrc2WA() const |
| 410 |
{ return mPlatformModel.platform == Platform::XE_HPC; } |
| 411 |
|
| 412 |
// When an instruction have inter-read suppression on a operand, and the same |
| 413 |
// GRF register is used for intra-read suppression with another operand, then |
| 414 |
// compiler must evaluate RAW dependency for the whole GRF irrespective of |
| 415 |
// subregister numbers. |
| 416 |
bool needIntraReadSuppressionWA() const |
| 417 |
{ return mPlatformModel.platform == Platform::XE; } |
| 418 |
|
| 419 |
// This affects the dst size of call/calla instructions. For call/calla, the |
| 420 |
// dst data type is implicit DW, but it actually accesses "IP address size + |
| 421 |
// 1 dw (CallMask)". Hence when IP size is 64b, the dst register footprint |
| 422 |
// should be 3 DWs. |
| 423 |
bool has64bitIPAddress() const |
| 424 |
{ return mPlatformModel.platform > Platform::XE3; } |
| 425 |
|
| 426 |
// Need to insert swsb right after fence to force sync with it in case that |
| 427 |
// there is implicit dependency to the fence from the following barrier |
| 428 |
// instructions |
| 429 |
bool needSyncAfterFence() const |
| 430 |
{ return mPlatformModel.platform > Platform::XE3; } |
| 431 |
|
| 432 |
// check if the given sendg instruction is a fence. |
| 433 |
// The given Instruction must be in sendg format |
| 434 |
bool isSendgFence(const Instruction &sendg) const; |
| 435 |
|
| 436 |
private: |
| 437 |
// ASSUMES: byte-level tracking for all elements |
| 438 |
|
| 439 |
// FIXME: Some info taken from model, some are hardcoded |
| 440 |
const uint32_t GRF_REGS; |
| 441 |
const uint32_t GRF_BYTES_PER_REG; |
| 442 |
|
| 443 |
const uint32_t ARF_A_BYTES_PER_REG; |
| 444 |
const uint32_t ARF_A_REGS; |
| 445 |
|
| 446 |
const uint32_t ARF_ACC_REGS = 12; |
| 447 |
const uint32_t ARF_ACC_BYTES_PER_REG = 32; |
| 448 |
|
| 449 |
const uint32_t ARF_F_REGS; |
| 450 |
const uint32_t ARF_F_BYTES_PER_REG = 4; |
| 451 |
|
| 452 |
// for registers that migh thave indirect dependence like CR and SR |
| 453 |
const uint32_t ARF_SPECIAL_REGS = 2; |
| 454 |
const uint32_t ARF_SPECIAL_BYTES_PER_REG = 4; |
| 455 |
|
| 456 |
uint32_t ARF_SCALAR_REGS = 0; |
| 457 |
uint32_t ARF_SCALAR_BYTES_PER_REG = 0; |
| 458 |
|
| 459 |
private: |
| 460 |
// DpasMacroBuilder - a helper class for building dpas macro |
| 461 |
|
| 462 |
// DPAS sequence can form a macro by setting {Atomic} to all DPAS in the same |
| 463 |
// macro, except the last one DPAS can form a macro when: |
| 464 |
// 1. consecutive DPAS instructions of the same opcode |
| 465 |
// 2. same datatype of the same operand across all instructions |
| 466 |
// 3. same execution mask across all instructions |
| 467 |
// 4. depth is 8 |
| 468 |
// 5. has no internal dependency within each instruction |
| 469 |
// - with an exception that for depth 8 dpas, src0 and dst dependency is |
| 470 |
// allowed if they are completely the same |
| 471 |
// 6. no producer-consumer relationships (RAW) within the macro |
| 472 |
// - WAW and WAR are allowed since dpas are in ordered within the dpas pipe |
| 473 |
// 7. For a DPAS 8xN sequence, where N !=8, a macro has to have at least two |
| 474 |
// dpas b2b instructions that share the same |
| 475 |
// src1 and that the sum of the number of either Src0 or Src2 registers |
| 476 |
// they read is 8 or more after the same macro can change to another |
| 477 |
// sequence of dpas instructions with different Src1 |
| 478 |
// (** Note that violating this rule causes functional issue) |
| 479 |
// 8. One of below conditions is met: |
| 480 |
// a) for src1 read suppression |
| 481 |
// b) for src2 read suppression |
| 482 |
// c) Fwd is set |
| 483 |
|
| 484 |
// Details of 8: |
| 485 |
// a) for src1 suppression: |
| 486 |
// - A read can be suppressed only when its register footprint is |
| 487 |
// completely overlapped with the |
| 488 |
// register group in the suppression buffer |
| 489 |
// - no producer-consumer relationships within the macro |
| 490 |
// - src1 reused the registers in the src1 suppression buffer. Buffer size: |
| 491 |
// * PreXE3P: 1 group of 8 consecutive registers |
| 492 |
// * XE3P+: 4 groups of 8 consecutive registers |
| 493 |
// b) for src2 suppression: |
| 494 |
// - A read can be suppressed only when its register footprint is |
| 495 |
// completely overlapped with the |
| 496 |
// register group in the suppression buffer |
| 497 |
// - no producer-consumer relationships within the macro |
| 498 |
// - repcount is 8 for non-dp dpas, or 4 for dp dpas |
| 499 |
// - src2 reused the registers in the src2 suppression buffer. Buffer size: |
| 500 |
// * prePVC: no src2 suppression |
| 501 |
// * PVC+: 4 groups of 4 consecutive registers |
| 502 |
// * XE3P+: 16 groups of 4 consecutive registers |
| 503 |
// c) Fwd is set |
| 504 |
// - current and next dpas are both dpas8x8 |
| 505 |
// - next DPAS's src0and dst are both identical to current DPAS's dst |
| 506 |
// - src0, dst types are fp32 or int32(type size is 32) |
| 507 |
// - next DPAS's src1 and src2 should not have dependency to the current |
| 508 |
// DPAS's dst |
| 509 |
|
| 510 |
// The entry point to form a dpas macro is DpasMacroBuilder::formMacro |
| 511 |
// To simplify the implementation, we do not emulate the FIFO behavior in HW |
| 512 |
// of read suppression buffer. The number of instructions found in the formed |
| 513 |
// macro is the maximum of block we found for a), b) and c). |
| 514 |
class DpasMacroBuilder { |
| 515 |
public: |
| 516 |
DpasMacroBuilder(const DepSetBuilder &dsBuilder, const Model &model, |
| 517 |
const InstList &instList, InstListIterator dpasIt, |
| 518 |
DepSet &in, DepSet &out, SWSB_ENCODE_MODE enc_mode) |
| 519 |
: m_dsBuilder(dsBuilder), m_model(model), m_instList(instList), |
| 520 |
m_firstDpasIt(dpasIt), m_inps(in), m_oups(out), m_encMode(enc_mode) {} |
| 521 |
|
| 522 |
// form a macro start from dpasIt, and set the register footprint of all |
| 523 |
// instruction in the macro into the given input and output DepSet |
| 524 |
// - dpasCnt is the output of number of instructions in the macro |
| 525 |
// - return the last intruction in the formed macro |
| 526 |
Instruction &formMacro(size_t &dpasCnt); |
| 527 |
|
| 528 |
private: |
| 529 |
typedef DepSet::RegRangeListType RegRangeListType; |
| 530 |
typedef RegRangeListType SrcRegRangeType; |
| 531 |
typedef DepSet::RegRangeType RegRangeType; |
| 532 |
typedef RegRangeType DstRegRangeType; |
| 533 |
|
| 534 |
// check if the given next_inst can be the candidate within current macro |
| 535 |
// return true if it can't |
| 536 |
bool nextIsNotMacroCandidate(const Instruction &dpas, |
| 537 |
const Instruction &next_inst) const; |
| 538 |
|
| 539 |
// A helper function to check if the given types are valid mixed types to |
| 540 |
// form a macro |
| 541 |
bool isValidMixedTypes(Type curType, Type nextType) const; |
| 542 |
|
| 543 |
// set register range from start_reg to upper_reg into bit_set |
| 544 |
void setBits(BitSet<> &bit_set, uint32_t start_reg, |
| 545 |
uint32_t upper_reg) const; |
| 546 |
|
| 547 |
// set dst_range to dst_bits and src_range to src_bits |
| 548 |
void setDstSrcBits(const SrcRegRangeType &src_range, |
| 549 |
const DstRegRangeType &dst_range, BitSet<> &src_bits, |
| 550 |
BitSet<> &dst_bits) const; |
| 551 |
|
| 552 |
// check if the given register ranges having intersection |
| 553 |
bool hasIntersect(const DepSet::RegRangeType &rr1, |
| 554 |
const DepSet::RegRangeType &rr2) const; |
| 555 |
|
| 556 |
// If rr1 and rr2 footprint are all the same, return true. |
| 557 |
bool hasEntireOverlap(const DepSet::RegRangeType &rr1, |
| 558 |
const DepSet::RegRangeType &rr2) const; |
| 559 |
|
| 560 |
// check if the instruction having internal dependency |
| 561 |
// Instruction having internal dependency on dst to src is not allowed |
| 562 |
// to be in a macro. Only for dpas8x8, insternal dep on dst and src0 is |
| 563 |
// allowed, but only when src0 and dst memory footprint is entirely the |
| 564 |
// same |
| 565 |
bool hasInternalDep(const Instruction &cur, const DstRegRangeType &dst_range, |
| 566 |
const SrcRegRangeType &src_range, bool isDepth8) const; |
| 567 |
|
| 568 |
// check if the dst_range/src_range have producer-consumer (RAW) |
| 569 |
// dependency to target_dst_bits/target_src_bits |
| 570 |
bool hasProducerConsumerDep(const DstRegRangeType &dst_range, |
| 571 |
const SrcRegRangeType &src_range, |
| 572 |
const BitSet<> &target_dst_bits) const; |
| 573 |
|
| 574 |
// Check if this dpas can have {Fwd} set with the next dpas. |
| 575 |
// If can Fwd, treat this and the next instruction as one instruction to |
| 576 |
// go through the following checks |
| 577 |
bool canFwd(const Instruction &cur, const Instruction &next, |
| 578 |
const DstRegRangeType &cur_dst_range, |
| 579 |
const SrcRegRangeType &cur_src_range, |
| 580 |
const DstRegRangeType &next_dst_range, |
| 581 |
const SrcRegRangeType &next_src_range, |
| 582 |
const BitSet<> &prev_dst_bits, |
| 583 |
const BitSet<> &prev_src_bits) const; |
| 584 |
|
| 585 |
// form the Fwd block of dpas those have the same dst and src0 forward. |
| 586 |
// Return the number of dpas found in this fwd block. |
| 587 |
size_t formFwdBlock(InstListIterator first); |
| 588 |
|
| 589 |
void updateRegFootprintsToDepSets(SrcRegRangeType &src_range, |
| 590 |
SrcRegRangeType &extra_src_range, |
| 591 |
DstRegRangeType &dst_range); |
| 592 |
void updateRegFootprintsToDepSets(RegRangeListType &src_range, |
| 593 |
RegRangeListType &extra_src_range, |
| 594 |
RegRangeListType &dst_range); |
| 595 |
|
| 596 |
private: |
| 597 |
struct SuppressBlock { |
| 598 |
public: |
| 599 |
// Keep tarck of the src and dst register footprints of all instructions |
| 600 |
// those are in this suppressBlcok. This will be used to set to DepSet |
| 601 |
// when the block is decided to be added into the macro, for avoiding |
| 602 |
// re-calculating the dependency |
| 603 |
RegRangeListType allSrcRange, allExtraSrcRange; |
| 604 |
RegRangeListType allDstRange; |
| 605 |
|
| 606 |
public: |
| 607 |
SuppressBlock() {} |
| 608 |
|
| 609 |
void addRegRanges(SrcRegRangeType &srcRange, |
| 610 |
SrcRegRangeType &extraSrcRange, |
| 611 |
DstRegRangeType &dstRange) { |
| 612 |
allSrcRange.insert(allSrcRange.end(), srcRange.begin(), srcRange.end()); |
| 613 |
allExtraSrcRange.insert(allExtraSrcRange.end(), extraSrcRange.begin(), |
| 614 |
extraSrcRange.end()); |
| 615 |
allDstRange.push_back(dstRange); |
| 616 |
} |
| 617 |
|
| 618 |
}; // SuppressionBlock |
| 619 |
|
| 620 |
// get the max number of suppression groups according to srcIdx and platform |
| 621 |
[[maybe_unused]] |
| 622 |
size_t getNumberOfSuppresionGroups(uint32_t srcIdx) const; |
| 623 |
|
| 624 |
// check from startIt, find the number of consecutive dpas those can be |
| 625 |
// grouped in a macro. Return number of instructions found |
| 626 |
size_t formSrcSuppressionBlock(InstListIterator startIt); |
| 627 |
|
| 628 |
private: |
| 629 |
const DepSetBuilder &m_dsBuilder; |
| 630 |
const Model &m_model; |
| 631 |
|
| 632 |
const InstList &m_instList; |
| 633 |
InstListIterator m_firstDpasIt; |
| 634 |
|
| 635 |
DepSet &m_inps; |
| 636 |
DepSet &m_oups; |
| 637 |
|
| 638 |
SWSB_ENCODE_MODE m_encMode; |
| 639 |
}; // DpasMacroBuilder |
| 640 |
|
| 641 |
private: |
| 642 |
// Track all the created DepSet for deletion |
| 643 |
std::vector<DepSet *> mAllDepSet; |
| 644 |
const Model &mPlatformModel; |
| 645 |
}; |
| 646 |
|
| 647 |
} // namespace iga |
| 648 |
#endif // _IGA_REGDEPS_HPP |