Skip to content

Commit

Permalink
[Backport] Add infrastructure for SPV_INTEL_float_controls2 extension
Browse files Browse the repository at this point in the history
Extension is published at intel/llvm#1611
  • Loading branch information
NikitaRudenkoIntel authored and AlexeySotkin committed Jul 8, 2020
1 parent 97586fd commit 8712c96
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 5 deletions.
9 changes: 9 additions & 0 deletions lib/SPIRV/SPIRVWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,15 @@ bool LLVMToSPIRV::transExecutionMode() {
BF->addExecutionMode(BM->add(new SPIRVExecutionMode(
BF, static_cast<ExecutionMode>(EMode), TargetWidth)));
} break;
case spv::ExecutionModeRoundingModeRTPINTEL:
case spv::ExecutionModeRoundingModeRTNINTEL:
case spv::ExecutionModeFloatingPointModeALTINTEL:
case spv::ExecutionModeFloatingPointModeIEEEINTEL: {
unsigned TargetWidth;
N.get(TargetWidth);
BF->addExecutionMode(BM->add(new SPIRVExecutionMode(
BF, static_cast<ExecutionMode>(EMode), TargetWidth)));
} break;
default:
llvm_unreachable("invalid execution mode");
}
Expand Down
4 changes: 4 additions & 0 deletions lib/SPIRV/libSPIRV/SPIRVEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,10 @@ void SPIRVExecutionMode::decode(std::istream &I) {
case ExecutionModeSignedZeroInfNanPreserve:
case ExecutionModeRoundingModeRTE:
case ExecutionModeRoundingModeRTZ:
case ExecutionModeRoundingModeRTPINTEL:
case ExecutionModeRoundingModeRTNINTEL:
case ExecutionModeFloatingPointModeALTINTEL:
case ExecutionModeFloatingPointModeIEEEINTEL:
case ExecutionModeSubgroupSize:
WordLiterals.resize(1);
break;
Expand Down
19 changes: 15 additions & 4 deletions lib/SPIRV/libSPIRV/SPIRVEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -670,21 +670,28 @@ class SPIRVComponentExecutionModes {
public:
void addExecutionMode(SPIRVExecutionMode *ExecMode) {
// There should not be more than 1 execution mode kind except the ones
// mentioned in SPV_KHR_float_controls.
// mentioned in SPV_KHR_float_controls and SPV_INTEL_float_controls2.
#ifndef NDEBUG
auto IsDenorm = [](ExecutionMode EMK) {
return EMK == ExecutionModeDenormPreserve ||
EMK == ExecutionModeDenormFlushToZero;
};
auto IsRoundingMode = [](ExecutionMode EMK) {
return EMK == ExecutionModeRoundingModeRTE ||
EMK == ExecutionModeRoundingModeRTZ;
EMK == ExecutionModeRoundingModeRTZ ||
EMK == ExecutionModeRoundingModeRTPINTEL ||
EMK == ExecutionModeRoundingModeRTNINTEL;
};
auto IsFPMode = [](ExecutionMode EMK) {
return EMK == ExecutionModeFloatingPointModeALTINTEL ||
EMK == ExecutionModeFloatingPointModeIEEEINTEL;
};
auto IsOtherFP = [](ExecutionMode EMK) {
return EMK == ExecutionModeSignedZeroInfNanPreserve;
};
auto IsFloatControl = [&](ExecutionMode EMK) {
return IsDenorm(EMK) || IsRoundingMode(EMK) || IsOtherFP(EMK);
return IsDenorm(EMK) || IsRoundingMode(EMK) || IsFPMode(EMK) ||
IsOtherFP(EMK);
};
auto IsCompatible = [&](SPIRVExecutionMode *EM0, SPIRVExecutionMode *EM1) {
if (EM0->getTargetId() != EM1->getTargetId())
Expand All @@ -698,7 +705,8 @@ class SPIRVComponentExecutionModes {
if (TW0 != TW1)
return true;
return !(IsDenorm(EMK0) && IsDenorm(EMK1)) &&
!(IsRoundingMode(EMK0) && IsRoundingMode(EMK1));
!(IsRoundingMode(EMK0) && IsRoundingMode(EMK1)) &&
!(IsFPMode(EMK0) && IsFPMode(EMK1));
};
for (auto I = ExecModes.begin(); I != ExecModes.end(); ++I) {
assert(IsCompatible(ExecMode, (*I).second) &&
Expand Down Expand Up @@ -798,6 +806,9 @@ class SPIRVCapability : public SPIRVEntryNoId<OpCapability> {
case CapabilityRoundingModeRTE:
case CapabilityRoundingModeRTZ:
return getSet(SPV_KHR_float_controls);
case CapabilityRoundToInfinityINTEL:
case CapabilityFloatingPointModeINTEL:
return getSet(SPV_INTEL_float_controls2);
default:
return SPIRVExtSet();
}
Expand Down
12 changes: 11 additions & 1 deletion lib/SPIRV/libSPIRV/SPIRVEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ enum SPIRVExtensionKind {
SPV_INTEL_media_block_io,
SPV_KHR_no_integer_wrap_decoration,
SPV_INTEL_inline_assembly,
SPV_KHR_float_controls
SPV_KHR_float_controls,
SPV_INTEL_float_controls2
};

typedef std::set<SPIRVExtensionKind> SPIRVExtSet;
Expand All @@ -125,6 +126,7 @@ template <> inline void SPIRVMap<SPIRVExtensionKind, std::string>::init() {
add(SPV_KHR_no_integer_wrap_decoration, "SPV_KHR_no_integer_wrap_decoration");
add(SPV_INTEL_inline_assembly, "SPV_INTEL_inline_assembly");
add(SPV_KHR_float_controls, "SPV_KHR_float_controls");
add(SPV_INTEL_float_controls2, "SPV_INTEL_float_controls2");
};

template <> inline void SPIRVMap<SPIRVExtInstSetKind, std::string>::init() {
Expand Down Expand Up @@ -249,6 +251,14 @@ template <> inline void SPIRVMap<SPIRVExecutionModeKind, SPIRVCapVec>::init() {
{CapabilitySignedZeroInfNanPreserve});
ADD_VEC_INIT(ExecutionModeRoundingModeRTE, {CapabilityRoundingModeRTE});
ADD_VEC_INIT(ExecutionModeRoundingModeRTZ, {CapabilityRoundingModeRTZ});
ADD_VEC_INIT(ExecutionModeRoundingModeRTPINTEL,
{CapabilityRoundToInfinityINTEL});
ADD_VEC_INIT(ExecutionModeRoundingModeRTNINTEL,
{CapabilityRoundToInfinityINTEL});
ADD_VEC_INIT(ExecutionModeFloatingPointModeALTINTEL,
{CapabilityFloatingPointModeINTEL});
ADD_VEC_INIT(ExecutionModeFloatingPointModeIEEEINTEL,
{CapabilityFloatingPointModeINTEL});
}

template <> inline void SPIRVMap<SPIRVMemoryModelKind, SPIRVCapVec>::init() {
Expand Down
11 changes: 11 additions & 0 deletions lib/SPIRV/libSPIRV/SPIRVIsValidEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ inline bool isValid(spv::ExecutionMode V) {
case ExecutionModeSignedZeroInfNanPreserve:
case ExecutionModeRoundingModeRTE:
case ExecutionModeRoundingModeRTZ:
case ExecutionModeRoundingModeRTPINTEL:
case ExecutionModeRoundingModeRTNINTEL:
case ExecutionModeFloatingPointModeALTINTEL:
case ExecutionModeFloatingPointModeIEEEINTEL:
return true;
default:
return false;
Expand Down Expand Up @@ -554,6 +558,13 @@ inline bool isValid(spv::Capability V) {
case CapabilitySubgroupDispatch:
case CapabilityNamedBarrier:
case CapabilityPipeStorage:
case CapabilityDenormPreserve:
case CapabilityDenormFlushToZero:
case CapabilitySignedZeroInfNanPreserve:
case CapabilityRoundingModeRTE:
case CapabilityRoundingModeRTZ:
case CapabilityRoundToInfinityINTEL:
case CapabilityFloatingPointModeINTEL:
return true;
default:
return false;
Expand Down
6 changes: 6 additions & 0 deletions lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ template <> inline void SPIRVMap<ExecutionMode, std::string>::init() {
add(ExecutionModeSignedZeroInfNanPreserve, "SignedZeroInfNanPreserve");
add(ExecutionModeRoundingModeRTE, "RoundingModeRTE");
add(ExecutionModeRoundingModeRTZ, "RoundingModeRTZ");
add(ExecutionModeRoundingModeRTPINTEL, "RoundingModeRTPINTEL");
add(ExecutionModeRoundingModeRTNINTEL, "RoundingModeRTNINTEL");
add(ExecutionModeFloatingPointModeALTINTEL, "FloatingPointModeALTINTEL");
add(ExecutionModeFloatingPointModeIEEEINTEL, "FloatingPointModeIEEEINTEL");
}
SPIRV_DEF_NAMEMAP(ExecutionMode, SPIRVExecutionModeNameMap)

Expand Down Expand Up @@ -485,6 +489,8 @@ template <> inline void SPIRVMap<Capability, std::string>::init() {
add(CapabilitySubgroupImageMediaBlockIOINTEL,
"SubgroupImageMediaBlockIOINTEL");
add(CapabilityAsmINTEL, "AsmINTEL");
add(CapabilityRoundToInfinityINTEL, "RoundToInfinityINTEL");
add(CapabilityFloatingPointModeINTEL, "FloatingPointModeINTEL");
add(CapabilitySubgroupAvcMotionEstimationINTEL,
"SubgroupAvcMotionEstimationINTEL");
add(CapabilitySubgroupAvcMotionEstimationIntraINTEL,
Expand Down
6 changes: 6 additions & 0 deletions lib/SPIRV/libSPIRV/spirv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ enum ExecutionMode {
ExecutionModeSignedZeroInfNanPreserve = 4461,
ExecutionModeRoundingModeRTE = 4462,
ExecutionModeRoundingModeRTZ = 4463,
ExecutionModeRoundingModeRTPINTEL = 5620,
ExecutionModeRoundingModeRTNINTEL = 5621,
ExecutionModeFloatingPointModeALTINTEL = 5622,
ExecutionModeFloatingPointModeIEEEINTEL = 5623,
ExecutionModeMax = 0x7fffffff,
};

Expand Down Expand Up @@ -675,6 +679,8 @@ enum Capability {
CapabilitySubgroupAvcMotionEstimationINTEL = 5696,
CapabilitySubgroupAvcMotionEstimationIntraINTEL = 5697,
CapabilitySubgroupAvcMotionEstimationChromaINTEL = 5698,
CapabilityRoundToInfinityINTEL = 5582,
CapabilityFloatingPointModeINTEL = 5583,
CapabilityMax = 0x7fffffff,
};

Expand Down
80 changes: 80 additions & 0 deletions test/exec_mode_float_control_intel.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
; 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 %s --input-file %t.spt -check-prefix=SPV

; ModuleID = 'float_control.bc'
source_filename = "float_control.cpp"
target datalayout = "e-p:64:64-i64:64-n8:16:32"
target triple = "spir"

; Function Attrs: noinline norecurse nounwind readnone
define dso_local dllexport spir_kernel void @k_float_controls_0(i32 %ibuf, i32 %obuf) local_unnamed_addr {
entry:
ret void
}

; Function Attrs: noinline norecurse nounwind readnone
define dso_local dllexport spir_kernel void @k_float_controls_1(i32 %ibuf, i32 %obuf) local_unnamed_addr {
entry:
ret void
}

; Function Attrs: noinline norecurse nounwind readnone
define dso_local dllexport spir_kernel void @k_float_controls_2(i32 %ibuf, i32 %obuf) local_unnamed_addr {
entry:
ret void
}

; Function Attrs: noinline norecurse nounwind readnone
define dso_local dllexport spir_kernel void @k_float_controls_3(i32 %ibuf, i32 %obuf) local_unnamed_addr {
entry:
ret void
}


!llvm.module.flags = !{!12}
!llvm.ident = !{!13}
!spirv.EntryPoint = !{}
!spirv.ExecutionMode = !{!15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26}

; SPV-DAG: EntryPoint {{[0-9]+}} [[KERNEL0:[0-9]+]] "k_float_controls_0"
; SPV-DAG: EntryPoint {{[0-9]+}} [[KERNEL1:[0-9]+]] "k_float_controls_1"
; SPV-DAG: EntryPoint {{[0-9]+}} [[KERNEL2:[0-9]+]] "k_float_controls_2"
; SPV-DAG: EntryPoint {{[0-9]+}} [[KERNEL3:[0-9]+]] "k_float_controls_3"
!0 = !{void (i32, i32)* @k_float_controls_0, !"k_float_controls_0", !1, i32 0, !2, !3, !4, i32 0, i32 0}
!1 = !{i32 2, i32 2}
!2 = !{i32 32, i32 36}
!3 = !{i32 0, i32 0}
!4 = !{!"", !""}
!12 = !{i32 1, !"wchar_size", i32 4}
!13 = !{!"clang version 8.0.1"}
!14 = !{i32 1, i32 0}

; SPV-DAG: ExecutionMode [[KERNEL0]] 5620 64
!15 = !{void (i32, i32)* @k_float_controls_0, i32 5620, i32 64}
; SPV-DAG: ExecutionMode [[KERNEL0]] 5620 32
!16 = !{void (i32, i32)* @k_float_controls_0, i32 5620, i32 32}
; SPV-DAG: ExecutionMode [[KERNEL0]] 5620 16
!17 = !{void (i32, i32)* @k_float_controls_0, i32 5620, i32 16}

; SPV-DAG: ExecutionMode [[KERNEL1]] 5621 64
!18 = !{void (i32, i32)* @k_float_controls_1, i32 5621, i32 64}
; SPV-DAG: ExecutionMode [[KERNEL1]] 5621 32
!19 = !{void (i32, i32)* @k_float_controls_1, i32 5621, i32 32}
; SPV-DAG: ExecutionMode [[KERNEL1]] 5621 16
!20 = !{void (i32, i32)* @k_float_controls_1, i32 5621, i32 16}

; SPV-DAG: ExecutionMode [[KERNEL2]] 5622 64
!21 = !{void (i32, i32)* @k_float_controls_2, i32 5622, i32 64}
; SPV-DAG: ExecutionMode [[KERNEL2]] 5622 32
!22 = !{void (i32, i32)* @k_float_controls_2, i32 5622, i32 32}
; SPV-DAG: ExecutionMode [[KERNEL2]] 5622 16
!23 = !{void (i32, i32)* @k_float_controls_2, i32 5622, i32 16}

; SPV-DAG: ExecutionMode [[KERNEL3]] 5623 64
!24 = !{void (i32, i32)* @k_float_controls_3, i32 5623, i32 64}
; SPV-DAG: ExecutionMode [[KERNEL3]] 5623 32
!25 = !{void (i32, i32)* @k_float_controls_3, i32 5623, i32 32}
; SPV-DAG: ExecutionMode [[KERNEL3]] 5623 16
!26 = !{void (i32, i32)* @k_float_controls_3, i32 5623, i32 16}

0 comments on commit 8712c96

Please sign in to comment.