Skip to content

Commit 4f43ac7

Browse files
aratajewigcbot
authored andcommitted
cl_intel_subgroup_2d_block_io extension support
This change implements support for `cl_intel_subgroup_2d_block_io` extension.
1 parent 4f35166 commit 4f43ac7

File tree

16 files changed

+2158
-4
lines changed

16 files changed

+2158
-4
lines changed

IGC/AdaptorOCL/preprocess_spvir/HandleSPIRVDecorations/HandleSpirvDecorationMetadata.cpp

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ SPDX-License-Identifier: MIT
1919
#include <llvm/IR/Instructions.h>
2020
#include <llvm/Demangle/Demangle.h>
2121
#include <llvm/IR/Mangler.h>
22+
#include <llvm/Support/Regex.h>
2223
#include "common/LLVMWarningsPop.hpp"
2324
#include <iostream>
25+
2426
using namespace llvm;
2527
using namespace IGC;
2628

@@ -124,6 +126,65 @@ void HandleSpirvDecorationMetadata::visitStoreInst(StoreInst& I)
124126
}
125127
}
126128

129+
void HandleSpirvDecorationMetadata::visit2DBlockReadCallInst(CallInst& I, StringRef unmangledName)
130+
{
131+
Value* ptr = I.getArgOperand(0);
132+
auto spirvDecorations = parseSPIRVDecorationsFromMD(ptr);
133+
for (auto& [DecorationId, MDNodes] : spirvDecorations)
134+
{
135+
switch (DecorationId)
136+
{
137+
// IDecCacheControlLoadINTEL
138+
case DecorationIdCacheControlLoad:
139+
{
140+
handleCacheControlINTELFor2DBlockIO<LoadCacheControl>(I, MDNodes, unmangledName);
141+
break;
142+
}
143+
}
144+
}
145+
}
146+
147+
void HandleSpirvDecorationMetadata::visit2DBlockWriteCallInst(CallInst& I, StringRef unmangledName)
148+
{
149+
Value* ptr = I.getArgOperand(0);
150+
auto spirvDecorations = parseSPIRVDecorationsFromMD(ptr);
151+
for (auto& [DecorationId, MDNodes] : spirvDecorations)
152+
{
153+
switch (DecorationId)
154+
{
155+
// IDecCacheControlStoreINTEL
156+
case DecorationIdCacheControlStore:
157+
{
158+
handleCacheControlINTELFor2DBlockIO<StoreCacheControl>(I, MDNodes, unmangledName);
159+
break;
160+
}
161+
}
162+
}
163+
}
164+
165+
void HandleSpirvDecorationMetadata::visitCallInst(CallInst& I)
166+
{
167+
Function* F = I.getCalledFunction();
168+
if (!F) return;
169+
170+
Regex pattern2DBlockRead(
171+
"_Z[0-9]+(intel_sub_group_2d_block_(prefetch|read|read_transform|read_transpose)_[0-9]+b_[0-9]+r[0-9]+x[0-9]+c)");
172+
Regex pattern2DBlockWrite(
173+
"_Z[0-9]+(intel_sub_group_2d_block_write_[0-9]+b_[0-9]+r[0-9]+x[0-9]+c)");
174+
175+
SmallVector<StringRef, 4> Matches;
176+
StringRef funcName = F->getName();
177+
178+
if (pattern2DBlockRead.match(funcName, &Matches))
179+
{
180+
visit2DBlockReadCallInst(I, Matches[1]);
181+
}
182+
else if (pattern2DBlockWrite.match(funcName, &Matches))
183+
{
184+
visit2DBlockWriteCallInst(I, Matches[1]);
185+
}
186+
}
187+
127188
template<typename T>
128189
void HandleSpirvDecorationMetadata::handleCacheControlINTEL(Instruction& I, SmallPtrSetImpl<MDNode*>& MDNodes)
129190
{
@@ -141,3 +202,38 @@ void HandleSpirvDecorationMetadata::handleCacheControlINTEL(Instruction& I, Smal
141202
I.setMetadata("lsc.cache.ctrl", CacheCtrlNode);
142203
m_changed = true;
143204
}
205+
206+
template<typename T>
207+
void HandleSpirvDecorationMetadata::handleCacheControlINTELFor2DBlockIO(CallInst& I, SmallPtrSetImpl<MDNode*>& MDNodes, StringRef unmangledName)
208+
{
209+
static_assert(std::is_same_v<T, LoadCacheControl> || std::is_same_v<T, StoreCacheControl>);
210+
CacheControlFromMDNodes cacheControl = resolveCacheControlFromMDNodes<T>(m_pCtx, MDNodes);
211+
if (cacheControl.isEmpty) return;
212+
if (cacheControl.isInvalid)
213+
{
214+
m_pCtx->EmitWarning("Unsupported cache controls configuration requested. Applying default configuration.");
215+
return;
216+
}
217+
218+
Function* F = I.getCalledFunction();
219+
IGC_ASSERT(F);
220+
221+
SmallVector<Value*, 4> args(I.args());
222+
args.push_back(ConstantInt::get(Type::getInt32Ty(I.getContext()), cacheControl.value));
223+
224+
SmallVector<Type*, 4> argTypes;
225+
for (const auto& arg : args)
226+
argTypes.push_back(arg->getType());
227+
228+
FunctionType* FT = FunctionType::get(I.getType(), argTypes, false);
229+
std::string newFuncName = "__internal_" + unmangledName.str() + "_cache_controls";
230+
auto newFunction = m_Module->getOrInsertFunction(newFuncName, FT);
231+
232+
auto newCall = CallInst::Create(newFunction, args, "", &I);
233+
I.replaceAllUsesWith(newCall);
234+
I.eraseFromParent();
235+
236+
// Cleanup unused function if all calls have been replaced with the internal version
237+
if (F->getNumUses() == 0)
238+
F->eraseFromParent();
239+
}

IGC/AdaptorOCL/preprocess_spvir/HandleSPIRVDecorations/HandleSpirvDecorationMetadata.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ namespace IGC
4646

4747
void visitLoadInst(llvm::LoadInst& I);
4848
void visitStoreInst(llvm::StoreInst& I);
49+
void visitCallInst(llvm::CallInst& I);
50+
void visit2DBlockReadCallInst(llvm::CallInst& I, llvm::StringRef unmangledName);
51+
void visit2DBlockWriteCallInst(llvm::CallInst& I, llvm::StringRef unmangledName);
4952

5053
private:
5154
llvm::Module* m_Module = nullptr;
@@ -59,5 +62,7 @@ namespace IGC
5962
void handleHostAccessIntel(llvm::GlobalVariable& globalVariable, llvm::MDNode* node);
6063
template<typename T>
6164
void handleCacheControlINTEL(llvm::Instruction& I, llvm::SmallPtrSetImpl<llvm::MDNode*>& MDNodes);
65+
template<typename T>
66+
void handleCacheControlINTELFor2DBlockIO(llvm::CallInst& I, llvm::SmallPtrSetImpl<llvm::MDNode*>& MDNodes, llvm::StringRef unmangledName);
6267
};
6368
}

IGC/BiFModule/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ set(KHR_DEFINES ${KHR_DEFINES} "cl_intel_subgroup_extended_block_read")
488488
set(KHR_DEFINES ${KHR_DEFINES} "cl_intel_pvc_lsc_validation")
489489
set(KHR_DEFINES ${KHR_DEFINES} "cl_intel_subgroup_extended_block_read_cacheopts")
490490
set(KHR_DEFINES ${KHR_DEFINES} "cl_intel_subgroup_extended_block_write_cacheopts")
491+
set(KHR_DEFINES ${KHR_DEFINES} "cl_intel_subgroup_2d_block_io")
491492

492493
igc_bif_build_bc(
493494
OUTPUT "${IGC_BUILD__BIF_DIR}/IBiF_Impl_int.bc"

0 commit comments

Comments
 (0)