Skip to content

Commit 4c0d9b1

Browse files
scottp101igcbot
authored andcommitted
Use getThreadGroupSize() in more places.
Have COpenCLKernel use CComputeShaderBase.
1 parent 75c47de commit 4c0d9b1

File tree

11 files changed

+78
-63
lines changed

11 files changed

+78
-63
lines changed

IGC/AdaptorOCL/ocl_igc_shared/executable_format/patch_list.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Abstract: Contains common patch structure definitions
3232

3333
namespace iOpenCL
3434
{
35-
const uint32_t CURRENT_ICBE_VERSION = 1070;
35+
const uint32_t CURRENT_ICBE_VERSION = 1071;
3636
const uint32_t MAGIC_CL = 0x494E5443; // 'I', 'N', 'T', 'C'
3737
const uint32_t INVALID_INDEX = 0xFFFFFFFF;
3838

IGC/Compiler/CISACodeGen/ComputeShaderBase.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,24 @@ namespace IGC
5151
uint threadGroupSize_Z)
5252
{
5353
const CodeGenContext* pCtx = GetContext();
54+
const ModuleMetaData* MMD = pCtx->getModuleMetaData();
5455

55-
if (pCtx->getModuleMetaData()->csInfo.neededThreadIdLayout == ThreadIDLayout::QuadTile)
56+
if (MMD->csInfo.neededThreadIdLayout == ThreadIDLayout::QuadTile)
5657
{
5758
m_ThreadIDLayout = ThreadIDLayout::QuadTile;
5859
return;
5960
}
6061

6162
if ((numberOfTypedAccess >= numberOfUntypedAccess) &&
6263
threadGroupSize_Y % 4 == 0 &&
63-
!pCtx->getModuleMetaData()->csInfo.disableLocalIdOrderOptimizations &&
64+
!MMD->csInfo.disableLocalIdOrderOptimizations &&
6465
IGC_IS_FLAG_ENABLED(UseTiledCSThreadOrder)) {
6566
m_ThreadIDLayout = ThreadIDLayout::TileY;
6667
m_walkOrder = WO_YXZ;
6768
}
6869

6970
bool needsLinearWalk =
70-
pCtx->getModuleMetaData()->csInfo.neededThreadIdLayout == ThreadIDLayout::X;
71+
MMD->csInfo.neededThreadIdLayout == ThreadIDLayout::X;
7172
if (needsLinearWalk)
7273
{
7374
m_ThreadIDLayout = ThreadIDLayout::X;

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13647,14 +13647,9 @@ void EmitPass::emitThreadGroupBarrier(llvm::Instruction* inst)
1364713647
else if (m_currShader->GetShaderType() == ShaderType::OPENCL_SHADER) {
1364813648
Function* F = inst->getParent()->getParent();
1364913649
MetaDataUtils* pMdUtils = getAnalysis<MetaDataUtilsWrapper>().getMetaDataUtils();
13650-
FunctionInfoMetaDataHandle funcInfoMD = pMdUtils->getFunctionsInfoItem(F);
13651-
ThreadGroupSizeMetaDataHandle threadGroupSize = funcInfoMD->getThreadGroupSize();
13652-
if (threadGroupSize->hasValue())
13653-
{
13654-
int32_t sz = threadGroupSize->getXDim() * threadGroupSize->getYDim() * threadGroupSize->getZDim();
13655-
if (sz <= (int32_t)numLanes(m_SimdMode)) {
13656-
skipBarrierInstructionInCS = true;
13657-
}
13650+
uint32_t sz = IGCMetaDataHelper::getThreadGroupSize(*pMdUtils, F);
13651+
if (sz != 0 && sz <= numLanes(m_SimdMode)) {
13652+
skipBarrierInstructionInCS = true;
1365813653
}
1365913654
}
1366013655

IGC/Compiler/CISACodeGen/FoldKnownWorkGroupSizes.cpp

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,27 +95,16 @@ void FoldKnownWorkGroupSizes::visitCallInst(llvm::CallInst& I)
9595
}
9696
else if (funcName.equals(WIFuncsAnalysis::GET_ENQUEUED_LOCAL_SIZE))
9797
{
98-
auto itr = ctx->getMetaDataUtils()->findFunctionsInfoItem(I.getFunction());
98+
auto Dims = IGCMetaDataHelper::getThreadGroupDims(
99+
*ctx->getMetaDataUtils(),
100+
I.getFunction());
99101

100-
//Check function exists in the metadata
101-
if (itr == ctx->getMetaDataUtils()->end_FunctionsInfo())
102-
return;
103-
104-
FunctionInfoMetaDataHandle funcMDHandle = itr->second;
105-
ThreadGroupSizeMetaDataHandle tgMD = funcMDHandle->getThreadGroupSize();
106-
//Check threadGroup has value
107-
if (!tgMD->hasValue())
102+
if (!Dims)
108103
return;
109104

110105
IRBuilder<> IRB(&I);
111106

112-
uint32_t Dims[] =
113-
{
114-
(uint32_t)tgMD->getXDim(),
115-
(uint32_t)tgMD->getYDim(),
116-
(uint32_t)tgMD->getZDim(),
117-
};
118-
auto* CV = ConstantDataVector::get(I.getContext(), Dims);
107+
auto* CV = ConstantDataVector::get(I.getContext(), *Dims);
119108

120109
auto* Dim = I.getArgOperand(0);
121110
auto* EE = IRB.CreateExtractElement(CV, Dim, "enqueuedLocalSize");

IGC/Compiler/CISACodeGen/OpenCLKernelCodeGen.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace IGC
6060
{
6161

6262
COpenCLKernel::COpenCLKernel(const OpenCLProgramContext* ctx, Function* pFunc, CShaderProgram* pProgram) :
63-
CShader(pFunc, pProgram)
63+
CComputeShaderBase(pFunc, pProgram)
6464
{
6565
m_HasTID = false;
6666
m_HasGlobalSize = false;
@@ -140,6 +140,21 @@ namespace IGC
140140
}
141141
}
142142

143+
bool COpenCLKernel::hasWorkGroupWalkOrder()
144+
{
145+
const CodeGenContext* pCtx = GetContext();
146+
const ModuleMetaData* MMD = pCtx->getModuleMetaData();
147+
if (auto I = MMD->FuncMD.find(entry); I != MMD->FuncMD.end())
148+
{
149+
auto& FMD = I->second;
150+
auto& Order = FMD.workGroupWalkOrder;
151+
if (Order.dim0 != 0 || Order.dim1 != 0 || Order.dim2 != 0)
152+
return true;
153+
}
154+
155+
return false;
156+
}
157+
143158
SOpenCLKernelInfo::SResourceInfo COpenCLKernel::getResourceInfo(int argNo)
144159
{
145160
CodeGenContext* pCtx = GetContext();

IGC/Compiler/CISACodeGen/OpenCLKernelCodeGen.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ IN THE SOFTWARE.
2323
============================= end_copyright_notice ===========================*/
2424

2525
#pragma once
26-
#include "Compiler/CISACodeGen/ShaderCodeGen.hpp"
26+
#include "Compiler/CISACodeGen/ComputeShaderBase.hpp"
2727

2828
namespace IGC
2929
{
@@ -33,7 +33,7 @@ namespace IGC
3333
namespace IGC
3434
{
3535

36-
class COpenCLKernel : public CShader
36+
class COpenCLKernel : public CComputeShaderBase
3737
{
3838
public:
3939
friend class CShaderProgram;
@@ -129,6 +129,8 @@ namespace IGC
129129
OpenCLProgramContext* m_Context;
130130

131131
void ClearKernelInfo();
132+
private:
133+
bool hasWorkGroupWalkOrder();
132134
};
133135

134136
}

IGC/Compiler/MetaDataApi/IGCMetaDataHelper.cpp

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,42 @@ void IGCMetaDataHelper::removeFunction(
7878
}
7979
}
8080

81+
llvm::Optional<std::array<uint32_t, 3>>
82+
IGCMetaDataHelper::getThreadGroupDims(
83+
MetaDataUtils& mdUtils,
84+
llvm::Function* pKernelFunc)
85+
{
86+
auto finfo = mdUtils.findFunctionsInfoItem(pKernelFunc);
87+
if (finfo == mdUtils.end_FunctionsInfo())
88+
return llvm::None;
89+
90+
auto& FI = finfo->second;
91+
92+
if (!FI->getThreadGroupSize()->hasValue())
93+
return llvm::None;
94+
95+
auto Dims = FI->getThreadGroupSize();
96+
97+
std::array<uint32_t, 3> A {
98+
(uint32_t)Dims->getXDim(),
99+
(uint32_t)Dims->getYDim(),
100+
(uint32_t)Dims->getZDim()
101+
};
102+
103+
return A;
104+
}
105+
106+
uint32_t IGCMetaDataHelper::getThreadGroupSize(MetaDataUtils& mdUtils, llvm::Function* pKernelFunc)
107+
{
108+
auto Dims = IGCMD::IGCMetaDataHelper::getThreadGroupDims(mdUtils, pKernelFunc);
109+
if (!Dims)
110+
return 0;
111+
112+
auto& Vals = *Dims;
113+
114+
return Vals[0] * Vals[1] * Vals[2];
115+
}
116+
81117
uint32_t IGCMetaDataHelper::getThreadGroupSizeHint(MetaDataUtils& mdUtils, llvm::Function* pKernelFunc)
82118
{
83119
FunctionInfoMetaDataHandle finfo = mdUtils.getFunctionsInfoItem(pKernelFunc);
@@ -89,17 +125,4 @@ uint32_t IGCMetaDataHelper::getThreadGroupSizeHint(MetaDataUtils& mdUtils, llvm:
89125
finfo->getThreadGroupSizeHint()->getZDim();
90126
}
91127
return size;
92-
}
93-
94-
uint32_t IGCMetaDataHelper::getThreadGroupSize(MetaDataUtils& mdUtils, llvm::Function* pKernelFunc)
95-
{
96-
FunctionInfoMetaDataHandle finfo = mdUtils.getFunctionsInfoItem(pKernelFunc);
97-
uint32_t size = 0;
98-
if (finfo->getThreadGroupSize()->hasValue())
99-
{
100-
size = finfo->getThreadGroupSize()->getXDim() *
101-
finfo->getThreadGroupSize()->getYDim() *
102-
finfo->getThreadGroupSize()->getZDim();
103-
}
104-
return size;
105128
}

IGC/Compiler/MetaDataApi/IGCMetaDataHelper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ namespace IGC {
4141

4242
// In OCL, thread group size (hint) is given by kernel attributes reqd_work_group_size and work_group_size_hint.
4343
// Return thread group size (hint) if present; return 0 otherwise.
44+
static llvm::Optional<std::array<uint32_t, 3>>
45+
getThreadGroupDims(MetaDataUtils& mdUtils, llvm::Function* pKernelFunc);
4446
static uint32_t getThreadGroupSize(MetaDataUtils& mdUtils, llvm::Function* pKernelFunc);
4547
static uint32_t getThreadGroupSizeHint(MetaDataUtils& mdUtils, llvm::Function* pKernelFunc);
4648
};

IGC/Compiler/Optimizer/OpenCLPasses/WIFuncs/WIFuncResolution.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,11 @@ WIFuncResolution::WIFuncResolution() : FunctionPass(ID), m_implicitArgs()
5656
Constant* WIFuncResolution::getKnownWorkGroupSize(
5757
IGCMD::MetaDataUtils* MDUtils, llvm::Function& F) const
5858
{
59-
auto finfo = MDUtils->findFunctionsInfoItem(&F);
60-
if (finfo == MDUtils->end_FunctionsInfo())
59+
auto Dims = IGCMD::IGCMetaDataHelper::getThreadGroupDims(*MDUtils, &F);
60+
if (!Dims)
6161
return nullptr;
6262

63-
auto& FI = finfo->second;
64-
if (FI->getThreadGroupSize()->hasValue())
65-
{
66-
uint32_t Dims[] =
67-
{
68-
(uint32_t)FI->getThreadGroupSize()->getXDim(),
69-
(uint32_t)FI->getThreadGroupSize()->getYDim(),
70-
(uint32_t)FI->getThreadGroupSize()->getZDim(),
71-
};
72-
return ConstantDataVector::get(F.getContext(), Dims);
73-
}
74-
75-
return nullptr;
63+
return ConstantDataVector::get(F.getContext(), *Dims);
7664
}
7765

7866
bool WIFuncResolution::runOnFunction(Function& F)

IGC/common/MDFrameWork.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ namespace IGC
175175

176176
struct WorkGroupWalkOrderMD
177177
{
178-
int dim0 = 0;
179-
int dim1 = 0;
180-
int dim2 = 0;
178+
int dim0 = 0;
179+
int dim1 = 0;
180+
int dim2 = 0;
181181
};
182182

183183
struct FuncArgMD

visa/BinaryEncodingIGA.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ void BinaryEncodingIGA::Encode()
853853
auto secondBB = *(std::next(kernel.fg.begin()));
854854
auto iter = std::find_if(secondBB->begin(), secondBB->end(),
855855
[](G4_INST* inst) { return !inst->isLabel();});
856-
assert(iter != secondBB->end() && "execpt at least one non-label inst in second BB");
856+
assert(iter != secondBB->end() && "expect at least one non-label inst in second BB");
857857
kernel.fg.builder->getJitInfo()->offsetToSkipPerThreadDataLoad =
858858
(uint32_t)(*iter)->getGenOffset();
859859
}

0 commit comments

Comments
 (0)