Skip to content

Commit

Permalink
Update translator for new Fast Composite extension
Browse files Browse the repository at this point in the history
SPV_INTEL_fast_composite extension specification separated some
decorations and execution modes from SPV_INTEL_vector_compute
  • Loading branch information
DmitryBushev authored and AlexeySotkin committed Feb 20, 2021
1 parent d593a5d commit 791d407
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 13 deletions.
8 changes: 6 additions & 2 deletions lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2373,6 +2373,12 @@ bool SPIRVToLLVM::transMetadata() {
transOCLMetadata(BF);
transVectorComputeMetadata(BF);

if (BF->hasDecorate(DecorationCallableFunctionINTEL))
F->addFnAttr(kVCMetadata::VCCallable);
if (isKernel(BF) &&
BF->getExecutionMode(ExecutionModeFastCompositeKernelINTEL))
F->addFnAttr(kVCMetadata::VCFCEntry);

if (F->getCallingConv() != CallingConv::SPIR_KERNEL)
continue;

Expand Down Expand Up @@ -2509,8 +2515,6 @@ bool SPIRVToLLVM::transVectorComputeMetadata(SPIRVFunction *BF) {
SPIRVWord SIMTMode = 0;
if (BF->hasDecorate(DecorationSIMTCallINTEL, 0, &SIMTMode))
F->addFnAttr(kVCMetadata::VCSIMTCall, std::to_string(SIMTMode));
if (BF->hasDecorate(DecorationVectorComputeCallableFunctionINTEL))
F->addFnAttr(kVCMetadata::VCCallable);

for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E;
++I) {
Expand Down
11 changes: 7 additions & 4 deletions lib/SPIRV/SPIRVWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,9 @@ SPIRVFunction *LLVMToSPIRV::transFunctionDecl(Function *F) {
if (Attrs.hasAttribute(AttributeList::ReturnIndex, Attribute::SExt))
BF->addDecorate(DecorationFuncParamAttr, FunctionParameterAttributeSext);

if (Attrs.hasFnAttribute(kVCMetadata::VCCallable))
BF->addDecorate(DecorationCallableFunctionINTEL);

transVectorComputeMetadata(F);

SPIRVDBG(dbgs() << "[transFunction] " << *F << " => ";
Expand Down Expand Up @@ -565,10 +568,6 @@ void LLVMToSPIRV::transVectorComputeMetadata(Function *F) {
BF->addDecorate(DecorationSIMTCallINTEL, SIMTMode);
}

if (Attrs.hasFnAttribute(kVCMetadata::VCCallable)) {
BF->addDecorate(DecorationVectorComputeCallableFunctionINTEL);
}

for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E;
++I) {
auto ArgNo = I->getArgNo();
Expand Down Expand Up @@ -1637,6 +1636,10 @@ bool LLVMToSPIRV::transExecutionMode() {
BF->addExecutionMode(BM->add(new SPIRVExecutionMode(
BF, static_cast<ExecutionMode>(EMode), TargetWidth)));
} break;
case spv::ExecutionModeFastCompositeKernelINTEL: {
BF->addExecutionMode(BM->add(
new SPIRVExecutionMode(BF, static_cast<ExecutionMode>(EMode))));
} break;
default:
llvm_unreachable("invalid execution mode");
}
Expand Down
3 changes: 3 additions & 0 deletions lib/SPIRV/TransOCLMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ void TransOCLMD::preprocessVectorComputeMetadata(Module *M, SPIRVMDBuilder *B,
.add(SLMSize)
.done();
}
if (Attrs.hasFnAttribute(kVCMetadata::VCFCEntry)) {
EM.addOp().add(&F).add(spv::ExecutionModeFastCompositeKernelINTEL).done();
}
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/SPIRV/VectorComputeUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ const static char VCVolatile[] = "VCVolatile";
const static char VCByteOffset[] = "VCByteOffset";
const static char VCSIMTCall[] = "VCSIMTCall";
const static char VCCallable[] = "VCCallable";
const static char VCFCEntry[] = "VCFCEntry";
} // namespace kVCMetadata

namespace kVCType {
Expand Down
5 changes: 3 additions & 2 deletions lib/SPIRV/libSPIRV/SPIRVEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ template <> inline void SPIRVMap<SPIRVExecutionModeKind, SPIRVCapVec>::init() {
{CapabilityFloatingPointModeINTEL});
ADD_VEC_INIT(ExecutionModeSharedLocalMemorySizeINTEL,
{CapabilityVectorComputeINTEL});
ADD_VEC_INIT(ExecutionModeFastCompositeKernelINTEL,
{CapabilityFastCompositeINTEL});
}

template <> inline void SPIRVMap<SPIRVMemoryModelKind, SPIRVCapVec>::init() {
Expand Down Expand Up @@ -374,8 +376,7 @@ template <> inline void SPIRVMap<Decoration, SPIRVCapVec>::init() {
{CapabilityFunctionFloatControlINTEL});
ADD_VEC_INIT(DecorationFunctionFloatingPointModeINTEL,
{CapabilityFunctionFloatControlINTEL});
ADD_VEC_INIT(DecorationVectorComputeCallableFunctionINTEL,
{CapabilityVectorComputeINTEL});
ADD_VEC_INIT(DecorationCallableFunctionINTEL, {CapabilityFastCompositeINTEL});
}

template <> inline void SPIRVMap<BuiltIn, SPIRVCapVec>::init() {
Expand Down
2 changes: 1 addition & 1 deletion lib/SPIRV/libSPIRV/SPIRVIsValidEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ inline bool isValid(spv::Decoration V) {
case DecorationFunctionRoundingModeINTEL:
case DecorationFunctionDenormModeINTEL:
case DecorationFunctionFloatingPointModeINTEL:
case DecorationVectorComputeCallableFunctionINTEL:
case DecorationCallableFunctionINTEL:
return true;
default:
return false;
Expand Down
4 changes: 2 additions & 2 deletions lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,7 @@ template <> inline void SPIRVMap<Decoration, std::string>::init() {
add(DecorationFunctionDenormModeINTEL, "FunctionDenormModeINTEL");
add(DecorationFunctionFloatingPointModeINTEL,
"FunctionFloatingPointModeINTEL");
add(DecorationVectorComputeCallableFunctionINTEL,
"VectorComputeCallableFunctionINTEL");
add(DecorationCallableFunctionINTEL, "CallableFunctionINTEL");
}
SPIRV_DEF_NAMEMAP(Decoration, SPIRVDecorationNameMap)

Expand Down Expand Up @@ -510,6 +509,7 @@ template <> inline void SPIRVMap<Capability, std::string>::init() {
add(CapabilitySubgroupAvcMotionEstimationChromaINTEL,
"SubgroupAvcMotionEstimationChromaINTEL");
add(CapabilityFunctionFloatControlINTEL, "FunctionFloatControlINTEL");
add(CapabilityFastCompositeINTEL, "FastCompositeINTEL");
}
SPIRV_DEF_NAMEMAP(Capability, SPIRVCapabilityNameMap)

Expand Down
4 changes: 3 additions & 1 deletion lib/SPIRV/libSPIRV/spirv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ enum ExecutionMode {
ExecutionModeRoundingModeRTNINTEL = 5621,
ExecutionModeFloatingPointModeALTINTEL = 5622,
ExecutionModeFloatingPointModeIEEEINTEL = 5623,
ExecutionModeFastCompositeKernelINTEL = 6088,
ExecutionModeMax = 0x7fffffff,
};

Expand Down Expand Up @@ -416,7 +417,7 @@ enum Decoration {
DecorationFunctionRoundingModeINTEL = 5822,
DecorationFunctionDenormModeINTEL = 5823,
DecorationFunctionFloatingPointModeINTEL = 6080,
DecorationVectorComputeCallableFunctionINTEL = 6087,
DecorationCallableFunctionINTEL = 6087,
DecorationMax = 0x7fffffff,
};

Expand Down Expand Up @@ -696,6 +697,7 @@ enum Capability {
CapabilityRoundToInfinityINTEL = 5582,
CapabilityFloatingPointModeINTEL = 5583,
CapabilityFunctionFloatControlINTEL = 5821,
CapabilityFastCompositeINTEL = 6093,
CapabilityMax = 0x7fffffff,
};

Expand Down
2 changes: 1 addition & 1 deletion test/callable-attribute-decoration.ll
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ define dso_local <4 x i32> @foo(<4 x i32> %a, <4 x i32> %b) #0 {
entry:
ret <4 x i32> %a
}
; CHECK-SPIRV: 3 Decorate {{[0-9]+}} VectorComputeCallableFunctionINTEL
; CHECK-SPIRV: 3 Decorate {{[0-9]+}} CallableFunctionINTEL
; CHECK-LLVM: attributes
; CHECK-LLVM-SAME: "VCCallable"

Expand Down
40 changes: 40 additions & 0 deletions test/fast-composit-entry.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
; RUN: llvm-as %s -o %t.bc
; RUN: llvm-spirv %t.bc -o %t.spv
; RUN: llvm-spirv %t.spv -o %t.spt --to-text
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
; RUN: llvm-spirv %t.spv -o %t.bc -r
; RUN: llvm-dis %t.bc -o %t.ll
; RUN: FileCheck < %t.ll %s --check-prefix=CHECK-LLVM

target triple = "spir64-unknown-unknown"


; CHECK-SPIRV: {{[0-9]+}} EntryPoint {{[0-9]+}} [[FOO_ID:[0-9]+]] "foo"
; CHECK-SPIRV: {{[0-9]+}} EntryPoint {{[0-9]+}} [[BAR_ID:[0-9]+]] "bar"
; CHECK-SPIRV: 3 ExecutionMode [[FOO_ID]] 6088
; CHECK-SPIRV-NOT: 3 ExecutionMode [[BAR_ID]] 6088

; CHECK-LLVM: define spir_kernel void @foo
; CHECK-LLVM-SAME: #[[FOO_ATTR_ID:[0-9]+]]
; CHECK-LLVM: define spir_kernel void @bar
; CHECK-LLVM-SAME: #[[BAR_ATTR_ID:[0-9]+]]

; CHECK-LLVM: attributes #[[FOO_ATTR_ID]]
; CHECK-LLVM-SAME: "VCFCEntry"
; CHECK-LLVM: attributes #[[BAR_ATTR_ID]]
; CHECK-LLVM-NOT: "VCFCEntry"


define spir_kernel void @foo(<4 x i32> %a, <4 x i32> %b) #0 {
entry:
ret void
}

define spir_kernel void @bar(<4 x i32> %a, <4 x i32> %b) #1 {
entry:
ret void
}

attributes #0 = { noinline nounwind "VCFCEntry" "VCFloatControl"="0" "VCFunction" }
attributes #1 = { noinline nounwind "VCFloatControl"="48" "VCFunction" }

0 comments on commit 791d407

Please sign in to comment.