Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/LLVMSPIRVExtensions.inc
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,4 @@ EXT(SPV_INTEL_sigmoid)
EXT(SPV_INTEL_float4)
EXT(SPV_INTEL_fp_conversions)
EXT(SPV_INTEL_rounded_divide_sqrt)
EXT(SPV_EXT_long_vector)
31 changes: 31 additions & 0 deletions lib/SPIRV/SPIRVWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,20 @@ SPIRVType *LLVMToSPIRVBase::transType(Type *T) {
}

if (auto *VecTy = dyn_cast<FixedVectorType>(T)) {
unsigned NumElements = VecTy->getNumElements();
bool IsNonStandardCount =
!(NumElements == 2 || NumElements == 3 || NumElements == 4 ||
NumElements == 8 || NumElements == 16);
if (IsNonStandardCount &&
!BM->isAllowedToUseExtension(ExtensionID::SPV_EXT_long_vector) &&
!BM->isAllowedToUseExtension(ExtensionID::SPV_INTEL_vector_compute)) {
BM->getErrorLog().checkError(
false, SPIRVEC_RequiresExtension,
"SPV_EXT_long_vector or SPV_INTEL_vector_compute\n"
"NOTE: LLVM module contains a vector with an unsupported number of "
"components, translation of which requires one of these extensions");
return nullptr;
}
if (VecTy->getElementType()->isPointerTy()) {
// SPV_INTEL_masked_gather_scatter extension changes 2.16.1. Universal
// Validation Rules:
Expand Down Expand Up @@ -5091,12 +5105,29 @@ bool isEmptyLLVMModule(Module *M) {
M->global_empty(); // No global variables
}

// A module is VectorCompute when any function or global variable carries
// VectorCompute metadata.
static bool hasVectorComputeMetadata(Module *M) {
return any_of(*M,
[](const Function &F) {
return F.hasFnAttribute(kVCMetadata::VCFunction);
}) ||
any_of(M->globals(), [](const GlobalVariable &GV) {
return GV.hasAttribute(kVCMetadata::VCGlobalVariable);
});
}

bool LLVMToSPIRVBase::translate() {
BM->setGeneratorVer(KTranslatorVer);

if (isEmptyLLVMModule(M))
BM->addCapability(CapabilityLinkage);

// Check before type translation so that SPIRVTypeVector can choose the
// matching capability.
if (BM->isAllowedToUseExtension(ExtensionID::SPV_INTEL_vector_compute))
BM->setVectorCompute(hasVectorComputeMetadata(M));

// Use the type scavenger to recover pointer element types.
Scavenger = std::make_unique<SPIRVTypeScavenger>(*M);

Expand Down
2 changes: 2 additions & 0 deletions lib/SPIRV/libSPIRV/SPIRVEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,8 @@ class SPIRVCapability : public SPIRVEntryNoId<OpCapability> {
return ExtensionID::SPV_INTEL_rounded_divide_sqrt;
case internal::CapabilityDeviceBarrierINTEL:
return ExtensionID::SPV_INTEL_device_barrier;
case CapabilityLongVectorEXT:
return ExtensionID::SPV_EXT_long_vector;
default:
return {};
}
Expand Down
3 changes: 3 additions & 0 deletions lib/SPIRV/libSPIRV/SPIRVModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ class SPIRVModule {
const std::string &) = 0;
void setInvalid() { IsValid = false; }
bool isModuleValid() { return IsValid; }
void setVectorCompute(bool E) { IsVectorCompute = E; }
bool isVectorCompute() const { return IsVectorCompute; }

// Module query functions
virtual SPIRVAddressingModelKind getAddressingModel() = 0;
Expand Down Expand Up @@ -648,6 +650,7 @@ class SPIRVModule {

private:
bool IsValid;
bool IsVectorCompute = false;
};

#ifdef _SPIRV_SUPPORT_TEXT_FMT
Expand Down
1 change: 1 addition & 0 deletions lib/SPIRV/libSPIRV/SPIRVNameMapEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ template <> inline void SPIRVMap<Capability, std::string>::init() {
add(CapabilityLongCompositesINTEL, "LongCompositesINTEL");
add(CapabilityOptNoneEXT, "OptNoneEXT");
add(CapabilityAtomicFloat16AddEXT, "AtomicFloat16AddEXT");
add(CapabilityLongVectorEXT, "LongVectorEXT");
add(CapabilityDebugInfoModuleINTEL, "DebugInfoModuleINTEL");
add(CapabilitySplitBarrierINTEL, "SplitBarrierINTEL");
add(CapabilityGlobalVariableFPGADecorationsINTEL,
Expand Down
16 changes: 12 additions & 4 deletions lib/SPIRV/libSPIRV/SPIRVType.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,17 @@ class SPIRVTypeVector : public SPIRVType {
if (CompCount == 8 || CompCount == 16)
V.push_back(CapabilityVector16);

if (Module->isAllowedToUseExtension(ExtensionID::SPV_INTEL_vector_compute))
if (CompCount == 1 || (CompCount > 4 && CompCount < 8) ||
(CompCount > 8 && CompCount < 16) || CompCount > 16)
if (CompCount == 1 || (CompCount > 4 && CompCount < 8) ||
(CompCount > 8 && CompCount < 16) || CompCount > 16) {
// A VectorCompute module keeps using CapabilityVectorAnyINTEL;
// otherwise use multi-vendor LongVectorEXT
if (!Module->isVectorCompute() &&
Module->isAllowedToUseExtension(ExtensionID::SPV_EXT_long_vector))
V.push_back(CapabilityLongVectorEXT);
else if (Module->isAllowedToUseExtension(
ExtensionID::SPV_INTEL_vector_compute))
V.push_back(CapabilityVectorAnyINTEL);
}
return V;
}

Expand All @@ -400,7 +407,8 @@ class SPIRVTypeVector : public SPIRVType {
SPIRVEntry::validate();
CompType->validate();
#ifndef NDEBUG
if (!(Module->isAllowedToUseExtension(
if (!Module->isAllowedToUseExtension(ExtensionID::SPV_EXT_long_vector) &&
!(Module->isAllowedToUseExtension(
ExtensionID::SPV_INTEL_vector_compute))) {
assert(CompCount == 2 || CompCount == 3 || CompCount == 4 ||
CompCount == 8 || CompCount == 16);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; RUN: llvm-as %s -o %t.bc
; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_EXT_long_vector,+SPV_INTEL_vector_compute -o %t.spv
; RUN: llvm-spirv %t.spv -to-text -o - | FileCheck %s --implicit-check-not="Capability VectorAnyINTEL"
; TODO: re-enable spirv-val once it can recognize LongVectorEXT capability (5425).
; RUNx: spirv-val %t.spv

; CHECK-DAG: Capability LongVectorEXT
; CHECK-DAG: Extension "SPV_EXT_long_vector"

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir64-unknown-unknown"

define spir_func void @test_vec1(<1 x float> %v) {
entry:
ret void
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; RUN: llvm-as %s -o %t.bc
; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_EXT_long_vector,+SPV_INTEL_vector_compute -o %t.spv
; RUN: llvm-spirv %t.spv -to-text -o - | FileCheck %s --implicit-check-not="Capability VectorAnyINTEL"
; TODO: re-enable spirv-val once it can recognize LongVectorEXT capability (5425).
; RUNx: spirv-val %t.spv

; CHECK-DAG: Capability LongVectorEXT
; CHECK-DAG: Extension "SPV_EXT_long_vector"

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir64-unknown-unknown"

define spir_func void @test_vec5(<5 x float> %v) {
entry:
ret void
}
29 changes: 29 additions & 0 deletions test/extensions/EXT/SPV_EXT_long_vector/vector_size_1.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
; RUN: llvm-as %s -o %t.bc
; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_EXT_long_vector -o %t.spv
; TODO: re-enable spirv-val once it can recognize LongVectorEXT capability (5425).
; RUNx: spirv-val %t.spv
; RUN: llvm-spirv %t.spv -to-text -o - | FileCheck %s

; RUN: llvm-as %s -o %t.bc
; RUN: not llvm-spirv %t.bc 2>&1 | FileCheck %s --check-prefix=ERROR

; CHECK-DAG: Capability LongVectorEXT
; CHECK-DAG: Extension "SPV_EXT_long_vector"
; CHECK-DAG: TypeFloat [[#F32:]] 32
; CHECK-DAG: TypeVector [[#]] [[#F32]] 1

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir64-unknown-unknown"

define spir_func void @test_vec1(<1 x float> %v1) {
entry:
ret void
}

; ERROR: RequiresExtension: Feature requires the following SPIR-V extension:
; ERROR-NEXT: SPV_EXT_long_vector or SPV_INTEL_vector_compute

define spir_func void @test_no_ext(<1 x float> %v) {
entry:
ret void
}
29 changes: 29 additions & 0 deletions test/extensions/EXT/SPV_EXT_long_vector/vector_size_5.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
; RUN: llvm-as %s -o %t.bc
; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_EXT_long_vector -o %t.spv
; TODO: re-enable spirv-val once it can recognize LongVectorEXT capability (5425).
; RUNx: spirv-val %t.spv
; RUN: llvm-spirv %t.spv -to-text -o - | FileCheck %s

; RUN: llvm-as %s -o %t.bc
; RUN: not llvm-spirv %t.bc 2>&1 | FileCheck %s --check-prefix=ERROR

; CHECK-DAG: Capability LongVectorEXT
; CHECK-DAG: Extension "SPV_EXT_long_vector"
; CHECK-DAG: TypeFloat [[#F32:]] 32
; CHECK-DAG: TypeVector [[#]] [[#F32]] 5

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir64-unknown-unknown"

define spir_func void @test_vec5(<5 x float> %v) {
entry:
ret void
}

; ERROR: RequiresExtension: Feature requires the following SPIR-V extension:
; ERROR-NEXT: SPV_EXT_long_vector or SPV_INTEL_vector_compute

define spir_func void @test_no_ext(<5 x float> %v) {
entry:
ret void
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
; A VectorCompute module (detected via VCFunction metadata) keeps using
; VectorAnyINTEL and SPV_INTEL_vector_compute for a non-standard vector size,
; even when SPV_EXT_long_vector is also enabled.

; RUN: llvm-as %s -o %t.bc
; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_EXT_long_vector,+SPV_INTEL_vector_compute -o %t.spv
; RUN: llvm-spirv %t.spv -to-text -o - | FileCheck %s --implicit-check-not="Capability LongVectorEXT" --implicit-check-not='Extension "SPV_EXT_long_vector"'

; CHECK-DAG: Capability VectorAnyINTEL
; CHECK-DAG: Extension "SPV_INTEL_vector_compute"
; CHECK-DAG: TypeFloat [[#F32:]] 32
; CHECK-DAG: TypeVector [[#]] [[#F32]] 5

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir64-unknown-unknown"

define spir_func void @test_vc(<5 x float> %v) #0 {
entry:
ret void
}

attributes #0 = { "VCFunction" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
; A VectorCompute module (detected via VCGlobalVariable metadata) keeps using
; VectorAnyINTEL and SPV_INTEL_vector_compute for a non-standard vector size,
; even when SPV_EXT_long_vector is also enabled.

; RUN: llvm-as %s -o %t.bc
; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_EXT_long_vector,+SPV_INTEL_vector_compute -o %t.spv
; RUN: llvm-spirv %t.spv -to-text -o - | FileCheck %s --implicit-check-not="Capability LongVectorEXT" --implicit-check-not='Extension "SPV_EXT_long_vector"'

; CHECK-DAG: Capability VectorAnyINTEL
; CHECK-DAG: Extension "SPV_INTEL_vector_compute"
; CHECK-DAG: TypeFloat [[#F32:]] 32
; CHECK-DAG: TypeVector [[#]] [[#F32]] 5

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir64-unknown-unknown"

@gv = internal addrspace(1) global <5 x float> zeroinitializer #0

attributes #0 = { "VCGlobalVariable" }
Loading