Skip to content

Commit

Permalink
Update decorations for global variables (#2174)
Browse files Browse the repository at this point in the history
This change is basically an update of #1389 for spec changes.

Implementation of the feature was based on Intel extension which was not officially published to Khronos.
Now it has been split, updated, and published to Khronos by KhronosGroup/SPIRV-Registry#205

Summary of the things that have changed:

Capability names and a new capability was added
Values for decorations have been updated to enums
Decoration names and IDs have been changed
Specs:
https://github.com/KhronosGroup/SPIRV-Registry/blob/main/extensions/INTEL/SPV_INTEL_global_variable_fpga_decorations.asciidoc https://github.com/KhronosGroup/SPIRV-Registry/blob/main/extensions/INTEL/SPV_INTEL_global_variable_host_access.asciidoc
  • Loading branch information
vmaksimo authored Oct 16, 2023
1 parent d009cd4 commit 538005a
Show file tree
Hide file tree
Showing 15 changed files with 300 additions and 130 deletions.
3 changes: 2 additions & 1 deletion include/LLVMSPIRVExtensions.inc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ EXT(SPV_INTEL_arithmetic_fence)
EXT(SPV_INTEL_bfloat16_conversion)
EXT(SPV_INTEL_joint_matrix)
EXT(SPV_INTEL_hw_thread_queries)
EXT(SPV_INTEL_global_variable_decorations)
EXT(SPV_INTEL_global_variable_host_access)
EXT(SPV_INTEL_global_variable_fpga_decorations)
EXT(SPV_INTEL_complex_float_mul_div)
EXT(SPV_INTEL_split_barrier)
EXT(SPV_INTEL_masked_gather_scatter)
Expand Down
2 changes: 1 addition & 1 deletion lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3863,7 +3863,7 @@ transDecorationsToMetadataList(llvm::LLVMContext *Context,
OPs.push_back(LinkTypeMD);
break;
}
case spv::internal::DecorationHostAccessINTEL: {
case DecorationHostAccessINTEL: {
const auto *const HostAccDeco =
static_cast<const SPIRVDecorateHostAccessINTEL *>(Deco);
auto *const AccModeMD = ConstantAsMetadata::get(ConstantInt::get(
Expand Down
44 changes: 27 additions & 17 deletions lib/SPIRV/SPIRVWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2572,7 +2572,8 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) {
Target, Name->getString().str(), TypeKind));
break;
}
case spv::internal::DecorationHostAccessINTEL: {

case DecorationHostAccessINTEL: {
checkIsGlobalVar(Target, DecoKind);

ErrLog.checkError(NumOperands == 3, SPIRVEC_InvalidLlvmModule,
Expand All @@ -2583,16 +2584,20 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) {
ErrLog.checkError(
AccessMode, SPIRVEC_InvalidLlvmModule,
"HostAccessINTEL requires first extra operand to be an int");

HostAccessQualifier Q =
static_cast<HostAccessQualifier>(AccessMode->getZExtValue());
auto *Name = dyn_cast<MDString>(DecoMD->getOperand(2));
ErrLog.checkError(
Name, SPIRVEC_InvalidLlvmModule,
"HostAccessINTEL requires second extra operand to be a string");

Target->addDecorate(new SPIRVDecorateHostAccessINTEL(
Target, AccessMode->getZExtValue(), Name->getString().str()));
Target->addDecorate(
new SPIRVDecorateHostAccessINTEL(Target, Q, Name->getString().str()));
break;
}
case spv::internal::DecorationInitModeINTEL: {

case DecorationInitModeINTEL: {
checkIsGlobalVar(Target, DecoKind);
ErrLog.checkError(static_cast<SPIRVVariable *>(Target)->getInitializer(),
SPIRVEC_InvalidLlvmModule,
Expand All @@ -2602,27 +2607,32 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) {
ErrLog.checkError(NumOperands == 2, SPIRVEC_InvalidLlvmModule,
"InitModeINTEL requires exactly 1 extra operand");
auto *Trigger = mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand(1));
ErrLog.checkError(
Trigger, SPIRVEC_InvalidLlvmModule,
"InitModeINTEL requires extra operand to be an integer");
ErrLog.checkError(Trigger, SPIRVEC_InvalidLlvmModule,
"InitModeINTEL requires extra operand to be an int");

InitializationModeQualifier Q =
static_cast<InitializationModeQualifier>(Trigger->getZExtValue());

Target->addDecorate(new SPIRVDecorateInitModeINTEL(Target, Q));

Target->addDecorate(
new SPIRVDecorateInitModeINTEL(Target, Trigger->getZExtValue()));
break;
}
case spv::internal::DecorationImplementInCSRINTEL: {
case DecorationImplementInRegisterMapINTEL: {
checkIsGlobalVar(Target, DecoKind);
ErrLog.checkError(NumOperands == 2, SPIRVEC_InvalidLlvmModule,
"ImplementInCSRINTEL requires exactly 1 extra operand");
auto *Value = mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand(1));
ErrLog.checkError(
Value, SPIRVEC_InvalidLlvmModule,
"ImplementInCSRINTEL requires extra operand to be an integer");
NumOperands == 2, SPIRVEC_InvalidLlvmModule,
"ImplementInRegisterMapINTEL requires exactly 1 extra operand");
auto *Value = mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand(1));
ErrLog.checkError(Value, SPIRVEC_InvalidLlvmModule,
"ImplementInRegisterMapINTEL requires extra operand to "
"be an integer");

Target->addDecorate(new SPIRVDecorateImplementInRegisterMapINTEL(
Target, Value->getZExtValue()));

Target->addDecorate(
new SPIRVDecorateImplementInCSRINTEL(Target, Value->getZExtValue()));
break;
}

case spv::internal::DecorationCacheControlLoadINTEL: {
ErrLog.checkError(
NumOperands == 3, SPIRVEC_InvalidLlvmModule,
Expand Down
7 changes: 5 additions & 2 deletions lib/SPIRV/libSPIRV/SPIRVDecorate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,12 @@ void SPIRVDecorate::encode(spv_ostream &O) const {
case DecorationUserSemantic:
SPIRVDecorateUserSemanticAttr::encodeLiterals(Encoder, Literals);
break;
case spv::internal::DecorationHostAccessINTEL:
case DecorationHostAccessINTEL:
SPIRVDecorateHostAccessINTEL::encodeLiterals(Encoder, Literals);
break;
case DecorationInitModeINTEL:
SPIRVDecorateInitModeINTEL::encodeLiterals(Encoder, Literals);
break;
default:
Encoder << Literals;
}
Expand All @@ -153,7 +156,7 @@ void SPIRVDecorate::decode(std::istream &I) {
case DecorationUserSemantic:
SPIRVDecorateUserSemanticAttr::decodeLiterals(Decoder, Literals);
break;
case spv::internal::DecorationHostAccessINTEL:
case DecorationHostAccessINTEL:
SPIRVDecorateHostAccessINTEL::decodeLiterals(Decoder, Literals);
break;
default:
Expand Down
58 changes: 43 additions & 15 deletions lib/SPIRV/libSPIRV/SPIRVDecorate.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,12 @@ class SPIRVDecorate : public SPIRVDecorateGeneric {
return ExtensionID::SPV_INTEL_fpga_invocation_pipelining_attributes;
case internal::DecorationRuntimeAlignedINTEL:
return ExtensionID::SPV_INTEL_runtime_aligned;
case internal::DecorationHostAccessINTEL:
case internal::DecorationInitModeINTEL:
case internal::DecorationImplementInCSRINTEL:
return ExtensionID::SPV_INTEL_global_variable_decorations;
case DecorationInitModeINTEL:
case DecorationImplementInRegisterMapINTEL:
return ExtensionID::SPV_INTEL_global_variable_fpga_decorations;
case DecorationHostAccessINTEL:
return ExtensionID::SPV_INTEL_global_variable_host_access;

case DecorationConduitKernelArgumentINTEL:
case DecorationRegisterMapKernelArgumentINTEL:
case DecorationStableKernelArgumentINTEL:
Expand Down Expand Up @@ -730,9 +732,10 @@ class SPIRVDecoratePipelineEnableINTEL : public SPIRVDecorate {
class SPIRVDecorateHostAccessINTEL : public SPIRVDecorate {
public:
// Complete constructor for SPIRVHostAccessINTEL
SPIRVDecorateHostAccessINTEL(SPIRVEntry *TheTarget, SPIRVWord AccessMode,
SPIRVDecorateHostAccessINTEL(SPIRVEntry *TheTarget,
HostAccessQualifier AccessMode,
const std::string &VarName)
: SPIRVDecorate(spv::internal::DecorationHostAccessINTEL, TheTarget) {
: SPIRVDecorate(DecorationHostAccessINTEL, TheTarget) {
Literals.push_back(AccessMode);
for (auto &I : getVec(VarName))
Literals.push_back(I);
Expand All @@ -748,7 +751,7 @@ class SPIRVDecorateHostAccessINTEL : public SPIRVDecorate {
const std::vector<SPIRVWord> &Literals) {
#ifdef _SPIRV_SUPPORT_TEXT_FMT
if (SPIRVUseTextFormat) {
Encoder << Literals.front();
Encoder << (HostAccessQualifier)Literals.front();
std::string Name = getString(Literals.cbegin() + 1, Literals.cend());
Encoder << Name;
} else
Expand All @@ -760,7 +763,7 @@ class SPIRVDecorateHostAccessINTEL : public SPIRVDecorate {
std::vector<SPIRVWord> &Literals) {
#ifdef _SPIRV_SUPPORT_TEXT_FMT
if (SPIRVUseTextFormat) {
SPIRVWord Mode;
HostAccessQualifier Mode;
Decoder >> Mode;
std::string Name;
Decoder >> Name;
Expand All @@ -777,17 +780,42 @@ class SPIRVDecorateHostAccessINTEL : public SPIRVDecorate {
class SPIRVDecorateInitModeINTEL : public SPIRVDecorate {
public:
// Complete constructor for SPIRVInitModeINTEL
SPIRVDecorateInitModeINTEL(SPIRVEntry *TheTarget, SPIRVWord Trigger)
: SPIRVDecorate(spv::internal::DecorationInitModeINTEL, TheTarget,
Trigger) {}
SPIRVDecorateInitModeINTEL(SPIRVEntry *TheTarget,
InitializationModeQualifier Trigger)
: SPIRVDecorate(DecorationInitModeINTEL, TheTarget) {
Literals.push_back(Trigger);
WordCount += Literals.size();
}
static void encodeLiterals(SPIRVEncoder &Encoder,
const std::vector<SPIRVWord> &Literals) {
#ifdef _SPIRV_SUPPORT_TEXT_FMT
if (SPIRVUseTextFormat) {
Encoder << (InitializationModeQualifier)Literals.back();
} else
#endif
Encoder << Literals;
}

static void decodeLiterals(SPIRVDecoder &Decoder,
std::vector<SPIRVWord> &Literals) {
#ifdef _SPIRV_SUPPORT_TEXT_FMT
if (SPIRVUseTextFormat) {
InitializationModeQualifier Q;
Decoder >> Q;
Literals.back() = Q;
} else
#endif
Decoder >> Literals;
}
};

class SPIRVDecorateImplementInCSRINTEL : public SPIRVDecorate {
class SPIRVDecorateImplementInRegisterMapINTEL : public SPIRVDecorate {
public:
// Complete constructor for SPIRVImplementInCSRINTEL
SPIRVDecorateImplementInCSRINTEL(SPIRVEntry *TheTarget, SPIRVWord Value)
: SPIRVDecorate(spv::internal::DecorationImplementInCSRINTEL, TheTarget,
Value) {}
SPIRVDecorateImplementInRegisterMapINTEL(SPIRVEntry *TheTarget,
SPIRVWord Value)
: SPIRVDecorate(DecorationImplementInRegisterMapINTEL, TheTarget, Value) {
}
};

class SPIRVDecorateCacheControlLoadINTEL : public SPIRVDecorate {
Expand Down
12 changes: 6 additions & 6 deletions lib/SPIRV/libSPIRV/SPIRVEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,12 @@ template <> inline void SPIRVMap<Decoration, SPIRVCapVec>::init() {
{CapabilityFPGAInvocationPipeliningAttributesINTEL});
ADD_VEC_INIT(internal::DecorationRuntimeAlignedINTEL,
{CapabilityRuntimeAlignedAttributeINTEL});
ADD_VEC_INIT(internal::DecorationHostAccessINTEL,
{internal::CapabilityGlobalVariableDecorationsINTEL});
ADD_VEC_INIT(internal::DecorationInitModeINTEL,
{internal::CapabilityGlobalVariableDecorationsINTEL});
ADD_VEC_INIT(internal::DecorationImplementInCSRINTEL,
{internal::CapabilityGlobalVariableDecorationsINTEL});
ADD_VEC_INIT(DecorationHostAccessINTEL,
{CapabilityGlobalVariableHostAccessINTEL});
ADD_VEC_INIT(DecorationInitModeINTEL,
{CapabilityGlobalVariableFPGADecorationsINTEL});
ADD_VEC_INIT(DecorationImplementInRegisterMapINTEL,
{CapabilityGlobalVariableFPGADecorationsINTEL});
ADD_VEC_INIT(internal::DecorationArgumentAttributeINTEL,
{CapabilityFunctionPointersINTEL});
ADD_VEC_INIT(internal::DecorationCacheControlLoadINTEL,
Expand Down
32 changes: 27 additions & 5 deletions lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,13 @@ template <> inline void SPIRVMap<Decoration, std::string>::init() {
add(DecorationLatencyControlConstraintINTEL, "LatencyControlConstraintINTEL");
add(DecorationFPMaxErrorDecorationINTEL, "FPMaxErrorDecorationINTEL");

add(DecorationHostAccessINTEL, "HostAccessINTEL");
add(DecorationInitModeINTEL, "InitModeINTEL");
add(DecorationImplementInRegisterMapINTEL, "ImplementInRegisterMapINTEL");

// From spirv_internal.hpp
add(internal::DecorationCallableFunctionINTEL, "CallableFunctionINTEL");
add(internal::DecorationRuntimeAlignedINTEL, "RuntimeAlignedINTEL");
add(internal::DecorationHostAccessINTEL, "HostAccessINTEL");
add(internal::DecorationInitModeINTEL, "InitModeINTEL");
add(internal::DecorationImplementInCSRINTEL, "ImplementInCSRINTEL");
add(internal::DecorationArgumentAttributeINTEL, "ArgumentAttributeINTEL");
add(internal::DecorationCacheControlLoadINTEL, "CacheControlLoadINTEL");
add(internal::DecorationCacheControlStoreINTEL, "CacheControlStoreINTEL");
Expand Down Expand Up @@ -616,6 +617,9 @@ template <> inline void SPIRVMap<Capability, std::string>::init() {
add(CapabilityAtomicFloat16AddEXT, "AtomicFloat16AddEXT");
add(CapabilityDebugInfoModuleINTEL, "DebugInfoModuleINTEL");
add(CapabilitySplitBarrierINTEL, "SplitBarrierINTEL");
add(CapabilityGlobalVariableFPGADecorationsINTEL,
"GlobalVariableFPGADecorationsINTEL");
add(CapabilityGlobalVariableHostAccessINTEL, "GlobalVariableHostAccessINTEL");
add(CapabilityGroupUniformArithmeticKHR, "GroupUniformArithmeticKHR");
add(CapabilityFPGADSPControlINTEL, "FPGADSPControlINTEL");
add(CapabilityFPGAInvocationPipeliningAttributesINTEL,
Expand All @@ -633,8 +637,6 @@ template <> inline void SPIRVMap<Capability, std::string>::init() {
add(internal::CapabilityBfloat16ConversionINTEL, "Bfloat16ConversionINTEL");
add(internal::CapabilityJointMatrixINTEL, "JointMatrixINTEL");
add(internal::CapabilityHWThreadQueryINTEL, "HWThreadQueryINTEL");
add(internal::CapabilityGlobalVariableDecorationsINTEL,
"GlobalVariableDecorationsINTEL");
add(internal::CapabilityComplexFloatMulDivINTEL, "ComplexFloatMulDivINTEL");
add(internal::CapabilityMaskedGatherScatterINTEL, "MaskedGatherScatterINTEL");
add(internal::CapabilityTensorFloat32RoundingINTEL,
Expand All @@ -653,6 +655,26 @@ template <> inline void SPIRVMap<Capability, std::string>::init() {
}
SPIRV_DEF_NAMEMAP(Capability, SPIRVCapabilityNameMap)

template <>
inline void SPIRVMap<InitializationModeQualifier, std::string>::init() {
add(InitializationModeQualifierInitOnDeviceReprogramINTEL,
"InitOnDeviceReprogramINTEL");
add(InitializationModeQualifierInitOnDeviceResetINTEL,
"InitOnDeviceResetINTEL");
add(InitializationModeQualifierMax, "Max");
}
SPIRV_DEF_NAMEMAP(InitializationModeQualifier,
SPIRVInitializationModeQualifierNameMap)

template <> inline void SPIRVMap<HostAccessQualifier, std::string>::init() {
add(HostAccessQualifierNoneINTEL, "NoneINTEL");
add(HostAccessQualifierReadINTEL, "ReadINTEL");
add(HostAccessQualifierWriteINTEL, "WriteINTEL");
add(HostAccessQualifierReadWriteINTEL, "ReadWriteINTEL");
add(HostAccessQualifierMax, "Max");
}
SPIRV_DEF_NAMEMAP(HostAccessQualifier, SPIRVHostAccessQualifierNameMap)

} /* namespace SPIRV */

#endif // SPIRV_LIBSPIRV_SPIRVNAMEMAPENUM_H
2 changes: 2 additions & 0 deletions lib/SPIRV/libSPIRV/SPIRVStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ SPIRV_DEF_ENCDEC(Decoration)
SPIRV_DEF_ENCDEC(OCLExtOpKind)
SPIRV_DEF_ENCDEC(SPIRVDebugExtOpKind)
SPIRV_DEF_ENCDEC(NonSemanticAuxDataOpKind)
SPIRV_DEF_ENCDEC(InitializationModeQualifier)
SPIRV_DEF_ENCDEC(HostAccessQualifier)
SPIRV_DEF_ENCDEC(LinkageType)

// Read a string with padded 0's at the end so that they form a stream of
Expand Down
2 changes: 2 additions & 0 deletions lib/SPIRV/libSPIRV/SPIRVStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ SPIRV_DEC_ENCDEC(Decoration)
SPIRV_DEC_ENCDEC(OCLExtOpKind)
SPIRV_DEC_ENCDEC(SPIRVDebugExtOpKind)
SPIRV_DEC_ENCDEC(NonSemanticAuxDataOpKind)
SPIRV_DEC_ENCDEC(InitializationModeQualifier)
SPIRV_DEC_ENCDEC(HostAccessQualifier)
SPIRV_DEC_ENCDEC(LinkageType)

const SPIRVEncoder &operator<<(const SPIRVEncoder &O, const std::string &Str);
Expand Down
9 changes: 0 additions & 9 deletions lib/SPIRV/libSPIRV/spirv_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ enum InternalOp {
enum InternalDecoration {
IDecRuntimeAlignedINTEL = 5940,
IDecCallableFunctionINTEL = 6087,
IDecHostAccessINTEL = 6147,
IDecInitModeINTEL = 6148,
IDecImplementInCSRINTEL = 6149,
IDecArgumentAttributeINTEL = 6409,
IDecCacheControlLoadINTEL = 6442,
IDecCacheControlStoreINTEL = 6443
Expand Down Expand Up @@ -245,12 +242,6 @@ constexpr Decoration DecorationCallableFunctionINTEL =
static_cast<Decoration>(IDecCallableFunctionINTEL);
constexpr Decoration DecorationRuntimeAlignedINTEL =
static_cast<Decoration>(IDecRuntimeAlignedINTEL);
constexpr Decoration DecorationHostAccessINTEL =
static_cast<Decoration>(IDecHostAccessINTEL);
constexpr Decoration DecorationInitModeINTEL =
static_cast<Decoration>(IDecInitModeINTEL);
constexpr Decoration DecorationImplementInCSRINTEL =
static_cast<Decoration>(IDecImplementInCSRINTEL);
constexpr Decoration DecorationArgumentAttributeINTEL =
static_cast<Decoration>(IDecArgumentAttributeINTEL);
constexpr Decoration DecorationCacheControlLoadINTEL =
Expand Down
2 changes: 1 addition & 1 deletion spirv-headers-tag.conf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
51b106461707f46d962554efe1bf56dee28958a3
b8b9eb8640c8c0107ba580fbcb10f969022ca32c
Loading

0 comments on commit 538005a

Please sign in to comment.