Skip to content

Commit 5e224b4

Browse files
committed
refactor
Change-Id: I0170451f52c002fc12dcf2f690194c867cff3bde
1 parent df62355 commit 5e224b4

File tree

10 files changed

+99
-46
lines changed

10 files changed

+99
-46
lines changed

IGC/AdaptorOCL/OCL/KernelAnnotations.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,16 @@ struct ExecutionEnivronment
278278
{
279279
DWORD CompiledSIMDSize = 0;
280280
DWORD CompiledSubGroupsNumber = 0;
281-
DWORD PerThreadSpillFillSize = 0;
281+
//legacy design:hold all ScratchSpaceUsage
282+
//new design: hold spillfill+callstack+GTPin
283+
//Todo: rename it to m_PerThreadScratchSpaceSlot0
282284
DWORD PerThreadScratchSpace = 0;
283-
DWORD PerThreadScratchUseGtpin = 0;
285+
//DWORD PerThreadScratchUseGtpin = 0;
286+
//legacy design:not used
287+
//new design: hold private memory used by shader if non-ZERO
288+
DWORD PerThreadScratchSpaceSlot1 = 0;
289+
//legacy design:not used
290+
//new design: hold private memory used by shader if non-ZERO
284291
DWORD SumFixedTGSMSizes = 0;
285292
bool HasDeviceEnqueue = false;
286293
bool HasBarriers = false;

IGC/AdaptorOCL/OCL/Patch/patch_parser.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,24 @@ void DebugPatchList(
707707
}
708708
break;
709709

710+
case iOpenCL::PATCH_TOKEN_MEDIA_VFE_STATE_SLOT1:
711+
{
712+
const iOpenCL::SPatchMediaVFEState* pPatchItem =
713+
(const iOpenCL::SPatchMediaVFEState*)pHeader;
714+
715+
ICBE_DPF_STR(output, GFXDBG_HARDWARE,
716+
"PATCH_TOKEN_MEDIA_VFE_STATE_SLOT1 (%08X) (size = %d)\n",
717+
pPatchItem->Token,
718+
pPatchItem->Size);
719+
ICBE_DPF_STR(output, GFXDBG_HARDWARE,
720+
"\tScratchSpaceOffset = %d\n",
721+
pPatchItem->ScratchSpaceOffset);
722+
ICBE_DPF_STR(output, GFXDBG_HARDWARE,
723+
"\tPerThreadScratchSpaceSlot1 = %d\n",
724+
pPatchItem->PerThreadScratchSpace);
725+
}
726+
break;
727+
710728
case iOpenCL::PATCH_TOKEN_MEDIA_INTERFACE_DESCRIPTOR_LOAD:
711729
{
712730
const iOpenCL::SPatchMediaInterfaceDescriptorLoad* pPatchItem =
@@ -849,6 +867,9 @@ void DebugPatchList(
849867
ICBE_DPF_STR( output, GFXDBG_HARDWARE,
850868
"\tUsesStatelessSpillFill = %s\n",
851869
pPatchItem->UsesStatelessSpillFill ? "true" : "false" );
870+
ICBE_DPF_STR(output, GFXDBG_HARDWARE,
871+
"\tUsesMultiScratchSpaces = %s\n",
872+
pPatchItem->UsesMultiScratchSpaces ? "true" : "false");
852873
ICBE_DPF_STR( output, GFXDBG_HARDWARE,
853874
"\tIsCoherent = %s\n",
854875
pPatchItem->IsCoherent ? "true" : "false" );

IGC/AdaptorOCL/OCL/sp/sp_g8.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,8 +1181,7 @@ RETVAL CGen8OpenCLStateProcessor::CreatePatchList(
11811181
// Patch for MEDIA_VFE_STATE
11821182
if( retValue.Success )
11831183
{
1184-
const DWORD perThreadScratchSpaceSizeInBytes = annotations.m_executionEnivronment.PerThreadSpillFillSize
1185-
+ annotations.m_executionEnivronment.PerThreadScratchSpace + annotations.m_executionEnivronment.PerThreadScratchUseGtpin;
1184+
const DWORD perThreadScratchSpaceSizeInBytes = annotations.m_executionEnivronment.PerThreadScratchSpace;
11861185
if (perThreadScratchSpaceSizeInBytes > 0)
11871186
{
11881187
iOpenCL::SPatchMediaVFEState patch;
@@ -1204,6 +1203,31 @@ RETVAL CGen8OpenCLStateProcessor::CreatePatchList(
12041203
}
12051204
}
12061205

1206+
// Patch for MEDIA_VFE_STATE slot1
1207+
if (retValue.Success)
1208+
{
1209+
const DWORD perThreadScratchSpaceSizeInBytes = annotations.m_executionEnivronment.PerThreadScratchSpaceSlot1;
1210+
if (perThreadScratchSpaceSizeInBytes > 0)
1211+
{
1212+
iOpenCL::SPatchMediaVFEState patch;
1213+
1214+
memset(&patch, 0, sizeof(patch));
1215+
1216+
patch.Token = iOpenCL::PATCH_TOKEN_MEDIA_VFE_STATE_SLOT1;
1217+
patch.Size = sizeof(patch);
1218+
patch.ScratchSpaceOffset = 0;
1219+
1220+
patch.PerThreadScratchSpace =
1221+
iSTD::RoundPower2(
1222+
iSTD::Max(perThreadScratchSpaceSizeInBytes,
1223+
static_cast<DWORD>(sizeof(KILOBYTE))));
1224+
1225+
retValue = AddPatchItem(
1226+
patch,
1227+
membuf);
1228+
}
1229+
}
1230+
12071231
// Patch for MEDIA_INTERFACE_DESCRIPTOR_LOAD
12081232
if( retValue.Success )
12091233
{
@@ -1954,9 +1978,8 @@ RETVAL CGen8OpenCLStateProcessor::CreatePatchList(
19541978
patch.HasBarriers = annotations.m_executionEnivronment.HasBarriers;
19551979
patch.DisableMidThreadPreemption = annotations.m_executionEnivronment.DisableMidThreadPreemption;
19561980

1957-
1958-
patch.UsesStatelessSpillFill = (annotations.m_executionEnivronment.PerThreadSpillFillSize > 0)
1959-
|| (annotations.m_executionEnivronment.PerThreadScratchSpace > 0) || (annotations.m_executionEnivronment.PerThreadScratchUseGtpin > 0);
1981+
patch.UsesStatelessSpillFill = (annotations.m_executionEnivronment.PerThreadScratchSpace > 0);
1982+
patch.UsesMultiScratchSpaces = false;
19601983

19611984
patch.HasDeviceEnqueue = (bool)hasDeviceEnqueue;
19621985

IGC/AdaptorOCL/ocl_igc_shared/executable_format/patch_list.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Abstract: Contains common patch structure definitions
3434
namespace iOpenCL
3535
{
3636

37-
const uint32_t CURRENT_ICBE_VERSION = 1058;
37+
const uint32_t CURRENT_ICBE_VERSION = 1059;
3838

3939
const uint32_t MAGIC_CL = 0x494E5443; // 'I', 'N', 'T', 'C'
4040
const uint32_t INVALID_INDEX = 0xFFFFFFFF;
@@ -150,12 +150,13 @@ enum PATCH_TOKEN
150150
PATCH_TOKEN_GTPIN_INFO, // 52 @SPatchItemHeader@
151151
PATCH_TOKEN_PROGRAM_SYMBOL_TABLE, // 53 @SPatchFunctionTableInfo@
152152
PATCH_TOKEN_PROGRAM_RELOCATION_TABLE, // 54 @SPatchFunctionTableInfo@
153+
PATCH_TOKEN_MEDIA_VFE_STATE_SLOT1, // 55 @SPatchMediaVFEState of slot1@
153154

154155
NUM_PATCH_TOKENS
155156
};
156157

157158
// Update CURRENT_ICBE_VERSION when modifying the patch list
158-
static_assert( NUM_PATCH_TOKENS == 55, "NUM_PATCH_TOKENS has invalid value");
159+
static_assert( NUM_PATCH_TOKENS == 56, "NUM_PATCH_TOKENS has invalid value");
159160

160161
/*****************************************************************************\
161162
ENUM: IMAGE_MEMORY_OBJECT_TYPE

IGC/AdaptorOCL/ocl_igc_shared/executable_format/patch_shared.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ struct SPatchExecutionEnvironment :
199199
uint32_t MayAccessUndeclaredResource;
200200
uint32_t UsesFencesForReadWriteImages;
201201
uint32_t UsesStatelessSpillFill;
202+
uint32_t UsesMultiScratchSpaces;
202203
uint32_t IsCoherent;
203204
uint32_t IsInitializer;
204205
uint32_t IsFinalizer;
@@ -211,7 +212,7 @@ struct SPatchExecutionEnvironment :
211212
};
212213

213214
// Update CURRENT_ICBE_VERSION when modifying the patch list
214-
static_assert(sizeof(SPatchExecutionEnvironment) == (92 + sizeof(SPatchItemHeader)), "The size of SPatchExecutionEnvironment is not what is expected");
215+
static_assert(sizeof(SPatchExecutionEnvironment) == (96 + sizeof(SPatchItemHeader)), "The size of SPatchExecutionEnvironment is not what is expected");
215216

216217
/*****************************************************************************\
217218
STRUCT: SPatchString

IGC/Compiler/CISACodeGen/CISABuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4670,7 +4670,7 @@ void CEncoder::Compile()
46704670
pOutput->m_scratchSpaceUsedBySpills = jitInfo->spillMemUsed;
46714671
}
46724672

4673-
pOutput->setScratchPrivateUsage(m_program->m_ScratchSpaceSize, m_program->m_Platform->maxPerThreadScratchSpace());
4673+
pOutput->setScratchSpaceUsedByShader(m_program->m_ScratchSpaceSize);
46744674

46754675
pOutput->m_scratchSpaceUsedByGtpin = jitInfo->numBytesScratchGtpin;
46764676

IGC/Compiler/CISACodeGen/OpenCLKernelCodeGen.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,9 +1598,8 @@ unsigned int COpenCLKernel::getSumFixedTGSMSizes(Function* F)
15981598

15991599
void COpenCLKernel::FillKernel()
16001600
{
1601-
m_kernelInfo.m_executionEnivronment.PerThreadSpillFillSize = ProgramOutput()->m_scratchSpaceUsedBySpills;
1602-
m_kernelInfo.m_executionEnivronment.PerThreadScratchSpace = ProgramOutput()->m_scratchSpaceUsedByShader;
1603-
m_kernelInfo.m_executionEnivronment.PerThreadScratchUseGtpin = ProgramOutput()->m_scratchSpaceUsedByGtpin;
1601+
m_kernelInfo.m_executionEnivronment.PerThreadScratchSpace = ProgramOutput()->getScratchSpaceUsageInSlot0();
1602+
m_kernelInfo.m_executionEnivronment.PerThreadScratchSpaceSlot1 = ProgramOutput()->getScratchSpaceUsageInSlot1();
16041603
m_kernelInfo.m_kernelProgram.NOSBufferSize = m_NOSBufferSize / getGRFSize(); // in 256 bits
16051604
m_kernelInfo.m_kernelProgram.ConstantBufferLength = m_ConstantBufferLength / getGRFSize(); // in 256 bits
16061605
m_kernelInfo.m_kernelProgram.MaxNumberOfThreads = m_Platform->getMaxGPGPUShaderThreads();
@@ -1904,8 +1903,10 @@ static bool SetKernelProgram(COpenCLKernel* shader, DWORD simdMode)
19041903
{
19051904
if (simdMode == 32)
19061905
{
1907-
shader->m_kernelInfo.m_executionEnivronment.PerThreadSpillFillSize =
1908-
shader->ProgramOutput()->m_scratchSpaceUsedBySpills;
1906+
//why do we need this? we will get all output in GatherDataForDriver(...)
1907+
//remove it to avoid messy logics
1908+
//shader->m_kernelInfo.m_executionEnivronment.PerThreadSpillFillSize =
1909+
// shader->ProgramOutput()->m_scratchSpaceUsedBySpills;
19091910
shader->m_kernelInfo.m_kernelProgram.simd32 = *shader->ProgramOutput();
19101911
}
19111912
else if (simdMode == 16)

IGC/Compiler/CISACodeGen/PixelShaderCodeGen.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,8 +1190,6 @@ namespace IGC
11901190
cps.m_scratchSpaceUsedBySpills + ps.m_scratchSpaceUsedBySpills;
11911191
linked.m_scratchSpaceUsedByGtpin =
11921192
cps.m_scratchSpaceUsedByGtpin + ps.m_scratchSpaceUsedByGtpin;
1193-
linked.m_scratchSpaceUsedByStateless =
1194-
cps.m_scratchSpaceUsedByStateless + ps.m_scratchSpaceUsedByStateless;
11951193
linked.m_programSize = iSTD::Align(linked.m_unpaddedProgramSize, 64);
11961194
linked.m_programBin = IGC::aligned_malloc(linked.m_programSize, 16);
11971195
// Copy coarse phase

IGC/Compiler/CodeGenPublic.h

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ namespace IGC
9393
unsigned int m_unpaddedProgramSize; //<! program size without padding used for binary linking
9494
unsigned int m_startReg; //<! Which GRF to start with
9595
unsigned int m_scratchSpaceUsedBySpills; //<! amount of scratch space needed for shader spilling
96-
unsigned int m_scratchSpaceUsedByShader; //<! amount of scratch space needed by shader if allocated in scratchspace
97-
unsigned int m_scratchSpaceUsedByStateless; //<! amount of scratch space needed by shader if allocated in stateless surface
96+
unsigned int m_scratchSpaceUsedByShader; //<! amount of scratch space needed by shader
9897
unsigned int m_scratchSpaceUsedByGtpin; //<! amount of scratch space used by gtpin
9998
void* m_debugDataVISA; //<! VISA debug data (source -> VISA)
10099
unsigned int m_debugDataVISASize; //<! Number of bytes of VISA debug data
@@ -114,7 +113,8 @@ namespace IGC
114113
//false means all of them are together
115114
bool m_separatePvtSpill = false;
116115
bool m_roundPower2KBytes = false;
117-
116+
unsigned int m_scratchSpaceSizeLimit = 0;
117+
118118
void Destroy()
119119
{
120120
if (m_programBin)
@@ -131,48 +131,48 @@ namespace IGC
131131
}
132132
}
133133

134-
void setSeparatePvtSpill(bool setSeparatePvtSpillT, bool roundPower2KBytes)
134+
void init(bool setSeparatePvtSpillT, bool roundPower2KBytes, unsigned int scratchSpaceSizeLimitT)
135135
{
136136
m_separatePvtSpill = setSeparatePvtSpillT;
137137
m_roundPower2KBytes = roundPower2KBytes;
138+
m_scratchSpaceSizeLimit = scratchSpaceSizeLimitT;
138139
}
139140

140-
unsigned int getScratchSpaceUsage() const
141+
//InSlot0
142+
//Todo: rename later
143+
unsigned int getScratchSpaceUsageInSlot0() const
141144
{
142-
unsigned int size = m_scratchSpaceUsedBySpills + m_scratchSpaceUsedByGtpin + (m_separatePvtSpill ? 0 : m_scratchSpaceUsedByShader);
143-
if (m_roundPower2KBytes)
144-
{
145-
size = roundPower2KBbyte(size);
146-
}
147-
return size;
145+
return roundSize(m_scratchSpaceUsedBySpills + m_scratchSpaceUsedByGtpin + (m_separatePvtSpill ? 0 : m_scratchSpaceUsedByShader));
148146
}
149147

150-
unsigned int getScratchPrivateUsage() const
148+
unsigned int getScratchSpaceUsageInSlot1() const
151149
{
152-
return (m_separatePvtSpill ? m_scratchSpaceUsedByShader : 0);
150+
return roundSize((m_separatePvtSpill && m_scratchSpaceUsedByShader <= m_scratchSpaceSizeLimit) ? m_scratchSpaceUsedByShader : 0);
153151
}
154152

155-
void setScratchPrivateUsage(unsigned int scratchPrivateUsage, unsigned int scratchSpaceSizeLimit)
153+
unsigned int getScratchSpaceUsageInStateless() const
156154
{
157-
if (m_separatePvtSpill && scratchPrivateUsage > scratchSpaceSizeLimit)
158-
{
159-
m_scratchSpaceUsedByStateless = scratchPrivateUsage;
160-
}
161-
else
162-
{
163-
m_scratchSpaceUsedByShader = scratchPrivateUsage;
164-
}
155+
return ((m_separatePvtSpill && m_scratchSpaceUsedByShader > m_scratchSpaceSizeLimit) ? m_scratchSpaceUsedByShader : 0);
165156
}
166157

167-
unsigned int getStatelessPrivateUsage() const
158+
void setScratchSpaceUsedByShader(unsigned int scratchSpaceUsedByShader)
168159
{
169-
return (m_separatePvtSpill ? m_scratchSpaceUsedByStateless : 0);
160+
m_scratchSpaceUsedByShader = scratchSpaceUsedByShader;
170161
}
171-
private:
172-
unsigned int roundPower2KBbyte(unsigned int size) const
162+
private:
163+
unsigned int roundSize(unsigned int size) const
164+
{
165+
if (m_roundPower2KBytes)
173166
{
174-
return (size ? iSTD::RoundPower2(iSTD::Max(int_cast<DWORD>(size), static_cast<DWORD>(sizeof(KILOBYTE)))) : 0);
167+
size = roundPower2KBbyte(size);
175168
}
169+
return size;
170+
}
171+
172+
unsigned int roundPower2KBbyte(unsigned int size) const
173+
{
174+
return (size ? iSTD::RoundPower2(iSTD::Max(int_cast<DWORD>(size), static_cast<DWORD>(sizeof(KILOBYTE)))) : 0);
175+
}
176176

177177
};
178178

IGC/Compiler/Optimizer/OpenCLPasses/PrivateMemory/PrivateMemoryResolution.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,8 @@ bool PrivateMemoryResolution::safeToUseScratchSpace(llvm::Module &M) const
359359
if (modMD.compOpt.OptDisable
360360
|| !Ctx.m_DriverInfo.usesScratchSpacePrivateMemory()
361361
|| (Ctx.type == ShaderType::OPENCL_SHADER
362-
&& !Ctx.platform.useScratchSpaceForOCL()))
362+
&& !Ctx.platform.useScratchSpaceForOCL()
363+
))
363364
{
364365
return false;
365366
}

0 commit comments

Comments
 (0)