Skip to content

Commit 91a6c71

Browse files
MrSidimsvmaksimo
authored andcommitted
Implement SPV_INTEL_fpga_cluster_attributes extension
This extension adds a decoration, applicable on functions, that statically-scheduled clusters should handle stalls using a stall-enable signal to freeze computation within the cluster. Spec: KhronosGroup/SPIRV-Registry#85 Signed-off-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
1 parent bbbc98a commit 91a6c71

File tree

11 files changed

+53
-8
lines changed

11 files changed

+53
-8
lines changed

llvm-spirv/include/LLVMSPIRVExtensions.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ EXT(SPV_INTEL_arbitrary_precision_fixed_point)
2929
EXT(SPV_INTEL_arbitrary_precision_floating_point)
3030
EXT(SPV_INTEL_variable_length_array)
3131
EXT(SPV_INTEL_fp_fast_math_mode)
32+
EXT(SPV_INTEL_fpga_cluster_attributes)

llvm-spirv/lib/SPIRV/SPIRVInternal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ const static char MaxWGSize[] = "max_work_group_size";
398398
const static char NoGlobalOffset[] = "no_global_work_offset";
399399
const static char MaxWGDim[] = "max_global_work_dim";
400400
const static char NumSIMD[] = "num_simd_work_items";
401+
const static char StallEnable[] = "stall_enable";
401402
} // namespace kSPIR2MD
402403

403404
enum Spir2SamplerKind {

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3876,6 +3876,7 @@ bool SPIRVToLLVM::transMetadata() {
38763876

38773877
transOCLMetadata(BF);
38783878
transVectorComputeMetadata(BF);
3879+
transFPGAFunctionMetadata(BF, F);
38793880

38803881
if (F->getCallingConv() != CallingConv::SPIR_KERNEL)
38813882
continue;
@@ -4195,6 +4196,15 @@ bool SPIRVToLLVM::transVectorComputeMetadata(SPIRVFunction *BF) {
41954196
return true;
41964197
}
41974198

4199+
bool SPIRVToLLVM::transFPGAFunctionMetadata(SPIRVFunction *BF, Function *F) {
4200+
if (BF->hasDecorate(DecorationStallEnableINTEL)) {
4201+
std::vector<Metadata *> MetadataVec;
4202+
MetadataVec.push_back(ConstantAsMetadata::get(getInt32(M, 1)));
4203+
F->setMetadata(kSPIR2MD::StallEnable, MDNode::get(*Context, MetadataVec));
4204+
}
4205+
return true;
4206+
}
4207+
41984208
bool SPIRVToLLVM::transAlign(SPIRVValue *BV, Value *V) {
41994209
if (auto AL = dyn_cast<AllocaInst>(V)) {
42004210
SPIRVWord Align = 0;

llvm-spirv/lib/SPIRV/SPIRVReader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class SPIRVToLLVM {
107107
bool transMetadata();
108108
bool transOCLMetadata(SPIRVFunction *BF);
109109
bool transVectorComputeMetadata(SPIRVFunction *BF);
110+
bool transFPGAFunctionMetadata(SPIRVFunction *BF, Function *F);
110111
Value *transAsmINTEL(SPIRVAsmINTEL *BA);
111112
CallInst *transAsmCallINTEL(SPIRVAsmCallINTEL *BI, Function *F,
112113
BasicBlock *BB);

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,10 @@ SPIRVFunction *LLVMToSPIRV::transFunctionDecl(Function *F) {
593593
if (BM->isAllowedToUseExtension(ExtensionID::SPV_INTEL_vector_compute))
594594
transVectorComputeMetadata(F);
595595

596+
if (BM->isAllowedToUseExtension(
597+
ExtensionID::SPV_INTEL_fpga_cluster_attributes))
598+
transFPGAFunctionMetadata(BF, F);
599+
596600
SPIRVDBG(dbgs() << "[transFunction] " << *F << " => ";
597601
spvdbgs() << *BF << '\n';)
598602
return BF;
@@ -689,6 +693,15 @@ void LLVMToSPIRV::transVectorComputeMetadata(Function *F) {
689693
}
690694
}
691695

696+
void LLVMToSPIRV::transFPGAFunctionMetadata(SPIRVFunction *BF, Function *F) {
697+
if (MDNode *StallEnable = F->getMetadata(kSPIR2MD::StallEnable)) {
698+
if (getMDOperandAsInt(StallEnable, 0)) {
699+
BM->addCapability(CapabilityFPGAClusterAttributesINTEL);
700+
BF->addDecorate(new SPIRVDecorateStallEnableINTEL(BF));
701+
}
702+
}
703+
}
704+
692705
SPIRVValue *LLVMToSPIRV::transConstant(Value *V) {
693706
if (auto CPNull = dyn_cast<ConstantPointerNull>(V))
694707
return BM->addNullConstant(

llvm-spirv/lib/SPIRV/SPIRVWriter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class LLVMToSPIRV : public ModulePass {
115115
SPIRVWord transFunctionControlMask(Function *);
116116
SPIRVFunction *transFunctionDecl(Function *F);
117117
void transVectorComputeMetadata(Function *F);
118+
void transFPGAFunctionMetadata(SPIRVFunction *BF, Function *F);
118119
bool transGlobalVariables();
119120

120121
Op transBoolOpCode(SPIRVValue *Opn, Op OC);

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVDecorate.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ class SPIRVDecorate : public SPIRVDecorateGeneric {
177177
case DecorationFunctionRoundingModeINTEL:
178178
case DecorationFunctionDenormModeINTEL:
179179
return ExtensionID::SPV_INTEL_float_controls2;
180+
case DecorationStallEnableINTEL:
181+
return ExtensionID::SPV_INTEL_fpga_cluster_attributes;
180182
default:
181183
return {};
182184
}
@@ -610,6 +612,13 @@ class SPIRVDecorateFunctionFloatingPointModeINTEL : public SPIRVDecorate {
610612
};
611613
};
612614

615+
class SPIRVDecorateStallEnableINTEL : public SPIRVDecorate {
616+
public:
617+
// Complete constructor for SPIRVDecorateStallEnableINTEL
618+
SPIRVDecorateStallEnableINTEL(SPIRVEntry *TheTarget)
619+
: SPIRVDecorate(spv::DecorationStallEnableINTEL, TheTarget){};
620+
};
621+
613622
} // namespace SPIRV
614623

615624
#endif // SPIRV_LIBSPIRV_SPIRVDECORATE_H

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVEnum.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ template <> inline void SPIRVMap<Decoration, SPIRVCapVec>::init() {
418418
{CapabilityVectorComputeINTEL});
419419
ADD_VEC_INIT(DecorationVectorComputeCallableFunctionINTEL,
420420
{CapabilityVectorComputeINTEL});
421+
ADD_VEC_INIT(DecorationStallEnableINTEL,
422+
{CapabilityFPGAClusterAttributesINTEL});
421423
}
422424

423425
template <> inline void SPIRVMap<BuiltIn, SPIRVCapVec>::init() {

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ template <> inline void SPIRVMap<Decoration, std::string>::init() {
167167
add(DecorationSingleElementVectorINTEL, "SingleElementVectorINTEL");
168168
add(DecorationVectorComputeCallableFunctionINTEL,
169169
"VectorComputeCallableFunctionINTEL");
170+
add(DecorationStallEnableINTEL, "StallEnableINTEL");
170171
add(DecorationMax, "Max");
171172
}
172173
SPIRV_DEF_NAMEMAP(Decoration, SPIRVDecorationNameMap)
@@ -507,6 +508,7 @@ template <> inline void SPIRVMap<Capability, std::string>::init() {
507508
add(CapabilityUSMStorageClassesINTEL, "USMStorageClassesINTEL");
508509
add(CapabilityFPGAMemoryAccessesINTEL, "FPGAMemoryAccessesINTEL");
509510
add(CapabilityIOPipeINTEL, "IOPipeINTEL");
511+
add(CapabilityFPGAClusterAttributesINTEL, "FPGAClusterAttributesINTEL");
510512
add(CapabilityMax, "Max");
511513
}
512514
SPIRV_DEF_NAMEMAP(Capability, SPIRVCapabilityNameMap)

llvm-spirv/lib/SPIRV/libSPIRV/spirv.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ enum Decoration {
523523
DecorationCacheSizeINTEL = 5900,
524524
DecorationDontStaticallyCoalesceINTEL = 5901,
525525
DecorationPrefetchINTEL = 5902,
526+
DecorationStallEnableINTEL = 5905,
526527
DecorationBufferLocationINTEL = 5921,
527528
DecorationIOPipeStorageINTEL = 5944,
528529
DecorationFunctionFloatingPointModeINTEL = 6080,
@@ -985,6 +986,7 @@ enum Capability {
985986
CapabilityFPGARegINTEL = 5948,
986987
CapabilityKernelAttributesINTEL = 5892,
987988
CapabilityFPGAKernelAttributesINTEL = 5897,
989+
CapabilityFPGAClusterAttributesINTEL = 5904,
988990
CapabilityFPGABufferLocationINTEL = 5920,
989991
CapabilityArbitraryPrecisionFixedPointINTEL = 5922,
990992
CapabilityUSMStorageClassesINTEL = 5935,

0 commit comments

Comments
 (0)