Skip to content

Commit c28dc3d

Browse files
committed
Use SPV_EXT_long_vector extension for vector size=1
Keep using SPV_INTEL_vector_compute for other non-standard vector size.
1 parent 2668200 commit c28dc3d

7 files changed

Lines changed: 60 additions & 5 deletions

File tree

include/LLVMSPIRVExtensions.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,4 @@ EXT(SPV_INTEL_fp_conversions)
9797
EXT(SPV_KHR_float_controls2)
9898
EXT(SPV_AMD_weak_linkage)
9999
EXT(SPV_NV_shader_atomic_fp16_vector)
100+
EXT(SPV_EXT_long_vector)

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,15 @@ SPIRVType *LLVMToSPIRVBase::transType(Type *T) {
428428
}
429429

430430
if (auto *VecTy = dyn_cast<FixedVectorType>(T)) {
431+
if (VecTy->getNumElements() == 1 &&
432+
!BM->isAllowedToUseExtension(ExtensionID::SPV_EXT_long_vector)) {
433+
BM->getErrorLog().checkError(false, SPIRVEC_RequiresExtension,
434+
"SPV_EXT_long_vector\n"
435+
"NOTE: LLVM module contains a 1-element "
436+
"vector, translation of which requires "
437+
"this extension");
438+
return nullptr;
439+
}
431440
if (VecTy->getElementType()->isPointerTy() ||
432441
isa<TypedPointerType>(VecTy->getElementType())) {
433442
// SPV_INTEL_masked_gather_scatter extension changes 2.16.1. Universal

lib/SPIRV/libSPIRV/SPIRVEntry.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,8 @@ class SPIRVCapability : public SPIRVEntryNoId<OpCapability> {
953953
return ExtensionID::SPV_INTEL_device_barrier;
954954
case CapabilityFloatControls2:
955955
return ExtensionID::SPV_KHR_float_controls2;
956+
case CapabilityLongVectorEXT:
957+
return ExtensionID::SPV_EXT_long_vector;
956958
default:
957959
return {};
958960
}

lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ template <> inline void SPIRVMap<Capability, std::string>::init() {
631631
add(CapabilityOptNoneEXT, "OptNoneEXT");
632632
add(CapabilityAtomicFloat16AddEXT, "AtomicFloat16AddEXT");
633633
add(CapabilityAtomicFloat16VectorNV, "AtomicFloat16VectorNV");
634+
add(CapabilityLongVectorEXT, "LongVectorEXT");
634635
add(internal::CapabilityAtomicBFloat16AddINTEL, "AtomicBFloat16AddINTEL");
635636
add(internal::CapabilityAtomicBFloat16MinMaxINTEL,
636637
"AtomicBFloat16MinMaxINTEL");

lib/SPIRV/libSPIRV/SPIRVType.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,12 @@ class SPIRVTypeVector : public SPIRVType {
438438
if (CompCount == 8 || CompCount == 16)
439439
V.push_back(CapabilityVector16);
440440

441+
if (CompCount == 1 &&
442+
Module->isAllowedToUseExtension(ExtensionID::SPV_EXT_long_vector))
443+
V.push_back(CapabilityLongVectorEXT);
444+
441445
if (Module->isAllowedToUseExtension(ExtensionID::SPV_INTEL_vector_compute))
442-
if (CompCount == 1 || (CompCount > 4 && CompCount < 8) ||
446+
if ((CompCount > 4 && CompCount < 8) ||
443447
(CompCount > 8 && CompCount < 16) || CompCount > 16)
444448
V.push_back(CapabilityVectorAnyINTEL);
445449
return V;
@@ -455,10 +459,17 @@ class SPIRVTypeVector : public SPIRVType {
455459
SPIRVEntry::validate();
456460
CompType->validate();
457461
#ifndef NDEBUG
458-
if (!(Module->isAllowedToUseExtension(
459-
ExtensionID::SPV_INTEL_vector_compute))) {
460-
assert(CompCount == 2 || CompCount == 3 || CompCount == 4 ||
461-
CompCount == 8 || CompCount == 16);
462+
bool IsNonStandardCount =
463+
!(CompCount == 2 || CompCount == 3 || CompCount == 4 ||
464+
CompCount == 8 || CompCount == 16);
465+
if (IsNonStandardCount) {
466+
bool AllowedByVC = Module->isAllowedToUseExtension(
467+
ExtensionID::SPV_INTEL_vector_compute) &&
468+
CompCount != 1;
469+
bool AllowedByLongVector =
470+
Module->isAllowedToUseExtension(ExtensionID::SPV_EXT_long_vector) &&
471+
CompCount == 1;
472+
assert(AllowedByVC || AllowedByLongVector);
462473
}
463474
#endif // !NDEBUG
464475
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: not llvm-spirv %t.bc 2>&1 | FileCheck %s
3+
4+
; Without SPV_EXT_long_vector, a vector of size 1 cannot be translated.
5+
6+
; CHECK: RequiresExtension: Feature requires the following SPIR-V extension:
7+
; CHECK-NEXT: SPV_EXT_long_vector
8+
9+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
10+
target triple = "spir64-unknown-unknown"
11+
12+
define spir_func void @test_no_ext(<1 x float> %v1) {
13+
entry:
14+
ret void
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; RUN: llvm-spirv %s --spirv-ext=+SPV_EXT_long_vector -o %t.spv
2+
; RUN: spirv-val %t.spv
3+
; RUN: llvm-spirv %t.spv -to-text -o - | FileCheck %s
4+
5+
; CHECK-DAG: Capability LongVectorEXT
6+
; CHECK-DAG: Extension "SPV_EXT_long_vector"
7+
; CHECK-DAG: TypeFloat [[#F32:]] 32
8+
; CHECK-DAG: TypeVector [[#]] [[#F32]] 1
9+
10+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
11+
target triple = "spir64-unknown-unknown"
12+
13+
define spir_func void @test_vec1(<1 x float> %v1) {
14+
entry:
15+
ret void
16+
}

0 commit comments

Comments
 (0)