Skip to content

Commit b12ccbc

Browse files
fda0web-flow
authored andcommitted
Validate cache control support in EmitVISAPass.cpp
Move platform specific validation of cache controls to a later stage in compilation. (cherry picked from commit 1f95617)
1 parent 3a9ea8e commit b12ccbc

File tree

5 files changed

+390
-88
lines changed

5 files changed

+390
-88
lines changed

IGC/AdaptorOCL/Utils/CacheControlsHelper.h

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ namespace IGC
5454
{
5555
T L1;
5656
T L3;
57-
GFXCORE_FAMILY MinimumSupportedCoreFamily = IGFX_XE_HP_CORE;
5857
};
5958

6059
template<typename T>
@@ -80,9 +79,9 @@ namespace IGC
8079
{ LSC_L1S_L3UC, { LoadCacheControl::Streaming, LoadCacheControl::Uncached } },
8180
{ LSC_L1S_L3C_WB, { LoadCacheControl::Streaming, LoadCacheControl::Cached } },
8281
{ LSC_L1IAR_WB_L3C_WB, { LoadCacheControl::InvalidateAfterRead, LoadCacheControl::Cached } },
83-
{ LSC_L1UC_L3CC, { LoadCacheControl::Uncached, LoadCacheControl::ConstCached, IGFX_XE2_LPG_CORE } },
84-
{ LSC_L1C_L3CC, { LoadCacheControl::Cached, LoadCacheControl::ConstCached, IGFX_XE2_LPG_CORE } },
85-
{ LSC_L1IAR_L3IAR, { LoadCacheControl::InvalidateAfterRead, LoadCacheControl::InvalidateAfterRead, IGFX_XE2_LPG_CORE } },
82+
{ LSC_L1UC_L3CC, { LoadCacheControl::Uncached, LoadCacheControl::ConstCached, } },
83+
{ LSC_L1C_L3CC, { LoadCacheControl::Cached, LoadCacheControl::ConstCached, } },
84+
{ LSC_L1IAR_L3IAR, { LoadCacheControl::InvalidateAfterRead, LoadCacheControl::InvalidateAfterRead } },
8685
};
8786

8887
using CacheLevel = uint64_t;
@@ -132,44 +131,42 @@ namespace IGC
132131
return {};
133132
}
134133

135-
inline LSC_L1_L3_CC mapToLSCCacheControl(CodeGenContext *ctx, StoreCacheControl L1Control, StoreCacheControl L3Control)
134+
inline LSC_L1_L3_CC mapToLSCCacheControl(StoreCacheControl L1Control, StoreCacheControl L3Control)
136135
{
137136
for (auto& [LSCEnum, SPIRVEnum] : supportedStoreConfigs)
138-
if (SPIRVEnum.L1 == L1Control && SPIRVEnum.L3 == L3Control && ctx->platform.isCoreChildOf(SPIRVEnum.MinimumSupportedCoreFamily))
137+
if (SPIRVEnum.L1 == L1Control && SPIRVEnum.L3 == L3Control)
139138
return LSCEnum;
140139

141140
return LSC_CC_INVALID;
142141
}
143142

144-
inline LSC_L1_L3_CC mapToLSCCacheControl(CodeGenContext *ctx, LoadCacheControl L1Control, LoadCacheControl L3Control)
143+
inline LSC_L1_L3_CC mapToLSCCacheControl(LoadCacheControl L1Control, LoadCacheControl L3Control)
145144
{
146145
for (auto& [LSCEnum, SPIRVEnum] : supportedLoadConfigs)
147-
if (SPIRVEnum.L1 == L1Control && SPIRVEnum.L3 == L3Control && ctx->platform.isCoreChildOf(SPIRVEnum.MinimumSupportedCoreFamily))
146+
if (SPIRVEnum.L1 == L1Control && SPIRVEnum.L3 == L3Control)
148147
return LSCEnum;
149148

150149
return LSC_CC_INVALID;
151150
}
152151

153152
template<typename T>
154-
std::pair<T, T> mapToSPIRVCacheControl(CodeGenContext*, LSC_L1_L3_CC) = delete;
153+
SeparateCacheControlsL1L3<T> mapToSPIRVCacheControl(LSC_L1_L3_CC) = delete;
155154

156155
template <>
157-
inline std::pair<LoadCacheControl, LoadCacheControl> mapToSPIRVCacheControl<LoadCacheControl>(CodeGenContext *ctx, LSC_L1_L3_CC LSCControl)
156+
inline SeparateCacheControlsL1L3<LoadCacheControl> mapToSPIRVCacheControl<LoadCacheControl>(LSC_L1_L3_CC LSCControl)
158157
{
159158
if (auto I = supportedLoadConfigs.find(LSCControl); I != supportedLoadConfigs.end())
160-
if (ctx->platform.isCoreChildOf(I->second.MinimumSupportedCoreFamily))
161-
return { I->second.L1, I->second.L3 };
159+
return I->second;
162160

163161
IGC_ASSERT_MESSAGE(false, "Unsupported cache controls combination!");
164162
return { LoadCacheControl::Invalid, LoadCacheControl::Invalid };
165163
}
166164

167165
template <>
168-
inline std::pair<StoreCacheControl, StoreCacheControl> mapToSPIRVCacheControl<StoreCacheControl>(CodeGenContext *ctx, LSC_L1_L3_CC LSCControl)
166+
inline SeparateCacheControlsL1L3<StoreCacheControl> mapToSPIRVCacheControl<StoreCacheControl>(LSC_L1_L3_CC LSCControl)
169167
{
170168
if (auto I = supportedStoreConfigs.find(LSCControl); I != supportedStoreConfigs.end())
171-
if (ctx->platform.isCoreChildOf(I->second.MinimumSupportedCoreFamily))
172-
return { I->second.L1, I->second.L3 };
169+
return I->second;
173170

174171
IGC_ASSERT_MESSAGE(false, "Unsupported cache controls combination!");
175172
return { StoreCacheControl::Invalid, StoreCacheControl::Invalid };
@@ -261,14 +258,14 @@ namespace IGC
261258
}
262259

263260
LSC_L1_L3_CC defaultLSCCacheControls = static_cast<LSC_L1_L3_CC>(cacheDefault);
264-
auto [L1Default, L3Default] = mapToSPIRVCacheControl<T>(ctx, defaultLSCCacheControls);
265-
IGC_ASSERT(L1Default != T::Invalid && L3Default != T::Invalid);
261+
auto L1L3Default = mapToSPIRVCacheControl<T>(defaultLSCCacheControls);
262+
IGC_ASSERT(L1L3Default.L1 != T::Invalid && L1L3Default.L3 != T::Invalid);
266263

267-
T newL1CacheControl = L1CacheControl ? L1CacheControl.value() : L1Default;
268-
T newL3CacheControl = L3CacheControl ? L3CacheControl.value() : L3Default;
264+
T newL1CacheControl = L1CacheControl ? L1CacheControl.value() : L1L3Default.L1;
265+
T newL3CacheControl = L3CacheControl ? L3CacheControl.value() : L1L3Default.L3;
269266

270267
LSC_L1_L3_CC newLSCCacheControl =
271-
mapToLSCCacheControl(ctx, newL1CacheControl, newL3CacheControl);
268+
mapToLSCCacheControl(newL1CacheControl, newL3CacheControl);
272269

273270
if (newLSCCacheControl == LSC_CC_INVALID)
274271
{

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21700,10 +21700,30 @@ void EmitPass::emitsrnd(llvm::GenIntrinsicInst* GII)
2170021700
}
2170121701
}
2170221702

21703-
static LSC_CACHE_OPTS translateLSCCacheControlsEnum(
21704-
LSC_L1_L3_CC l1l3cc, bool isLoad
21705-
)
21703+
bool EmitPass::isSupportedLSCCacheControlsEnum(LSC_L1_L3_CC l1l3cc, bool isLoad) const
21704+
{
21705+
if (isLoad)
21706+
{
21707+
switch (l1l3cc)
21708+
{
21709+
default: break;
21710+
case LSC_L1UC_L3CC:
21711+
case LSC_L1C_L3CC:
21712+
case LSC_L1IAR_L3IAR:
21713+
return (m_pCtx->platform.isCoreChildOf(IGFX_XE2_LPG_CORE));
21714+
}
21715+
}
21716+
return true;
21717+
}
21718+
21719+
LSC_CACHE_OPTS EmitPass::translateLSCCacheControlsEnum(
21720+
LSC_L1_L3_CC l1l3cc, bool isLoad, const Value* warningContextValue) const
2170621721
{
21722+
if (!isSupportedLSCCacheControlsEnum(l1l3cc, isLoad)) {
21723+
m_pCtx->EmitWarning("Unsupported cache controls configuration requested. Applying default configuration.", warningContextValue);
21724+
l1l3cc = LSC_L1DEF_L3DEF;
21725+
}
21726+
2170721727
LSC_CACHE_OPTS cacheOpts {LSC_CACHING_DEFAULT, LSC_CACHING_DEFAULT};
2170821728
switch (l1l3cc)
2170921729
{
@@ -21775,15 +21795,13 @@ LSC_CACHE_OPTS EmitPass::translateLSCCacheControlsFromValue(
2177521795
{
2177621796
return translateLSCCacheControlsEnum(
2177721797
static_cast<LSC_L1_L3_CC>(cast<ConstantInt>(value)->getSExtValue()),
21778-
isLoad
21779-
);
21798+
isLoad, value);
2178021799
}
2178121800

21782-
static Optional<LSC_CACHE_OPTS>
21783-
setCacheOptionsForConstantBufferLoads(Instruction& inst, LSC_L1_L3_CC Ctrl
21784-
)
21801+
Optional<LSC_CACHE_OPTS>
21802+
EmitPass::cacheOptionsForConstantBufferLoads(Instruction* inst, LSC_L1_L3_CC Ctrl) const
2178521803
{
21786-
if (const Value* resourcePointer = GetBufferOperand(&inst))
21804+
if (const Value* resourcePointer = GetBufferOperand(inst))
2178721805
{
2178821806
uint addressSpace = resourcePointer->getType()->getPointerAddressSpace();
2178921807
BufferType bufferType = GetBufferType(addressSpace);
@@ -21792,37 +21810,34 @@ setCacheOptionsForConstantBufferLoads(Instruction& inst, LSC_L1_L3_CC Ctrl
2179221810
(bufferType == BINDLESS_CONSTANT_BUFFER) ||
2179321811
(bufferType == SSH_BINDLESS_CONSTANT_BUFFER))
2179421812
{
21795-
return translateLSCCacheControlsEnum(Ctrl, true
21796-
);
21813+
return translateLSCCacheControlsEnum(Ctrl, true, inst);
2179721814
}
2179821815
}
2179921816
return None;
2180021817
}
2180121818

2180221819
Optional<LSC_CACHE_OPTS>
21803-
EmitPass::setCacheOptionsForConstantBufferLoads(Instruction& inst) const
21820+
EmitPass::cacheOptionsForConstantBufferLoads(Instruction* inst) const
2180421821
{
2180521822
Optional<LSC_CACHE_OPTS> cacheOpts;
2180621823
if (IGC_IS_FLAG_DISABLED(DisableSystemMemoryCachingInGPUForConstantBuffers) &&
2180721824
m_currShader->m_Platform->isCoreChildOf(IGFX_XE2_LPG_CORE))
2180821825
{
21809-
if (auto Opts = ::setCacheOptionsForConstantBufferLoads(inst, LSC_L1C_L3CC
21810-
))
21826+
if (auto Opts = cacheOptionsForConstantBufferLoads(inst, LSC_L1C_L3CC))
2181121827
cacheOpts = *Opts;
2181221828
}
2181321829
if (m_pCtx->type == ShaderType::RAYTRACING_SHADER &&
2181421830
IGC_IS_FLAG_ENABLED(ForceRTConstantBufferCacheCtrl))
2181521831
{
2181621832
auto Ctrl = (LSC_L1_L3_CC)IGC_GET_FLAG_VALUE(RTConstantBufferCacheCtrl);
21817-
if (auto Opts = ::setCacheOptionsForConstantBufferLoads(inst, Ctrl
21818-
))
21833+
if (auto Opts = cacheOptionsForConstantBufferLoads(inst, Ctrl))
2181921834
cacheOpts = *Opts;
2182021835
}
2182121836
return cacheOpts;
2182221837
}
2182321838

21824-
static bool tryOverrideCacheOpts(LSC_CACHE_OPTS& cacheOpts, bool isLoad, bool isTGM
21825-
)
21839+
bool EmitPass::tryOverrideCacheOpts(LSC_CACHE_OPTS& cacheOpts, bool isLoad, bool isTGM,
21840+
const Value* warningContextValue) const
2182621841
{
2182721842
uint32_t l1l3CacheVal = 0;
2182821843

@@ -21841,9 +21856,7 @@ static bool tryOverrideCacheOpts(LSC_CACHE_OPTS& cacheOpts, bool isLoad, bool is
2184121856

2184221857
if (l1l3CacheVal != 0)
2184321858
{
21844-
cacheOpts = translateLSCCacheControlsEnum(
21845-
static_cast<LSC_L1_L3_CC>(l1l3CacheVal), isLoad
21846-
);
21859+
cacheOpts = translateLSCCacheControlsEnum(static_cast<LSC_L1_L3_CC>(l1l3CacheVal), isLoad, warningContextValue);
2184721860
}
2184821861
return l1l3CacheVal != 0;
2184921862
}
@@ -21871,8 +21884,7 @@ LSC_CACHE_OPTS EmitPass::translateLSCCacheControlsFromMetadata(
2187121884
{
2187221885
if (m_pCtx->platform.supportsNonDefaultLSCCacheSetting())
2187321886
{
21874-
if (tryOverrideCacheOpts(cacheOpts, isLoad, isTGM
21875-
))
21887+
if (tryOverrideCacheOpts(cacheOpts, isLoad, isTGM, inst))
2187621888
{
2187721889
// global override cache settings have highest priority
2187821890
return cacheOpts;
@@ -21898,14 +21910,12 @@ LSC_CACHE_OPTS EmitPass::translateLSCCacheControlsFromMetadata(
2189821910
if (isLoad && m_pCtx->getModuleMetaData()->compOpt.LoadCacheDefault != -1)
2189921911
{ // load
2190021912
LSC_L1_L3_CC L1L3Val = static_cast<LSC_L1_L3_CC>(m_pCtx->getModuleMetaData()->compOpt.LoadCacheDefault);
21901-
cacheOpts = translateLSCCacheControlsEnum(L1L3Val, true
21902-
);
21913+
cacheOpts = translateLSCCacheControlsEnum(L1L3Val, true, inst);
2190321914
}
2190421915
else if (!isLoad && m_pCtx->getModuleMetaData()->compOpt.StoreCacheDefault != -1)
2190521916
{ // store
2190621917
LSC_L1_L3_CC L1L3Val = static_cast<LSC_L1_L3_CC>(m_pCtx->getModuleMetaData()->compOpt.StoreCacheDefault);
21907-
cacheOpts = translateLSCCacheControlsEnum(L1L3Val, false
21908-
);
21918+
cacheOpts = translateLSCCacheControlsEnum(L1L3Val, false, inst);
2190921919
}
2191021920
}
2191121921

@@ -21928,8 +21938,7 @@ LSC_CACHE_OPTS EmitPass::translateLSCCacheControlsFromMetadata(
2192821938
}
2192921939
}
2193021940

21931-
if (tryOverrideCacheOpts(cacheOpts, isLoad, isTGM
21932-
))
21941+
if (tryOverrideCacheOpts(cacheOpts, isLoad, isTGM, inst))
2193321942
{
2193421943
// global override cache settings have highest priority
2193521944
return cacheOpts;
@@ -21960,7 +21969,7 @@ LSC_CACHE_OPTS EmitPass::translateLSCCacheControlsFromMetadata(
2196021969

2196121970
if (inst && isLoad)
2196221971
{
21963-
if (auto Opts = setCacheOptionsForConstantBufferLoads(*inst))
21972+
if (auto Opts = cacheOptionsForConstantBufferLoads(inst))
2196421973
cacheOpts = *Opts;
2196521974
}
2196621975

@@ -22169,7 +22178,7 @@ void EmitPass::emitLscIntrinsicLoad(llvm::GenIntrinsicInst* inst)
2216922178
LSC_CACHE_OPTS cacheOpts = translateLSCCacheControlsFromValue(inst->getOperand(4), true);
2217022179
LSC_DOC_ADDR_SPACE addrSpace = m_pCtx->getUserAddrSpaceMD().Get(inst);
2217122180

22172-
if (auto Opts = setCacheOptionsForConstantBufferLoads(*inst))
22181+
if (auto Opts = cacheOptionsForConstantBufferLoads(inst))
2217322182
cacheOpts = *Opts;
2217422183

2217522184
emitLscIntrinsicFragments(m_destination, dataSize, dataElems, immOffset,
@@ -23163,8 +23172,7 @@ LSC_CACHE_OPTS EmitPass::getDefaultRaytracingCachePolicy(bool isLoad) const
2316323172
LSC_L1IAR_WB_L3C_WB;
2316423173
}
2316523174

23166-
return translateLSCCacheControlsEnum(Opts, isLoad
23167-
);
23175+
return translateLSCCacheControlsEnum(Opts, isLoad, nullptr);
2316823176
}
2316923177

2317023178
void EmitPass::emitAsyncStackID(llvm::GenIntrinsicInst *I)

IGC/Compiler/CISACodeGen/EmitVISAPass.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,9 @@ class EmitPass : public llvm::FunctionPass
356356
void emitFastClearSend(llvm::Instruction* pInst);
357357
void setRovCacheCtrl(llvm::GenIntrinsicInst* inst);
358358
llvm::Optional<LSC_CACHE_OPTS>
359-
setCacheOptionsForConstantBufferLoads(Instruction& inst) const;
359+
cacheOptionsForConstantBufferLoads(Instruction* inst, LSC_L1_L3_CC Ctrl) const;
360+
llvm::Optional<LSC_CACHE_OPTS>
361+
cacheOptionsForConstantBufferLoads(Instruction* inst) const;
360362
bool useRasterizerOrderedByteAddressBuffer(llvm::GenIntrinsicInst* inst);
361363
void emitUniformAtomicCounter(llvm::GenIntrinsicInst* pInst);
362364

@@ -539,6 +541,9 @@ class EmitPass : public llvm::FunctionPass
539541
void emitHDCuncompressedwrite(llvm::GenIntrinsicInst* I);
540542
////////////////////////////////////////////////////////////////////
541543
// LSC related functions
544+
bool tryOverrideCacheOpts(LSC_CACHE_OPTS& cacheOpts, bool isLoad, bool isTGM, const llvm::Value* warningContextValue) const;
545+
bool isSupportedLSCCacheControlsEnum(LSC_L1_L3_CC l1l3cc, bool isLoad) const;
546+
LSC_CACHE_OPTS translateLSCCacheControlsEnum(LSC_L1_L3_CC l1l3cc, bool isLoad, const llvm::Value* warningContextValue) const;
542547
LSC_CACHE_OPTS translateLSCCacheControlsFromValue(
543548
llvm::Value *value, bool isLoad) const;
544549
LSC_CACHE_OPTS translateLSCCacheControlsFromMetadata(

0 commit comments

Comments
 (0)