Skip to content

Commit ef930f4

Browse files
committed
Fix VCE and add test
1 parent e01695b commit ef930f4

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ void ScalarType::getExtensions(SPIRVType::ExtensionArrayRefVector &extensions,
537537
[[fallthrough]];
538538
case StorageClass::Input:
539539
case StorageClass::Output:
540-
if (getIntOrFloatBitWidth() == 16 && !isa<BFloat16Type>(*this)) {
540+
if (getIntOrFloatBitWidth() == 16) {
541541
static const Extension exts[] = {Extension::SPV_KHR_16bit_storage};
542542
ArrayRef<Extension> ref(exts, std::size(exts));
543543
extensions.push_back(ref);

mlir/test/Dialect/SPIRV/Transforms/vce-deduction.mlir

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,17 @@ spirv.module Logical GLSL450 attributes {
217217
spirv.GlobalVariable @data : !spirv.ptr<!spirv.struct<(i8 [0], f16 [2], i64 [4])>, Uniform>
218218
spirv.GlobalVariable @img : !spirv.ptr<!spirv.image<f32, Buffer, NoDepth, NonArrayed, SingleSampled, SamplerUnknown, Rg32f>, UniformConstant>
219219
}
220+
221+
// Using bfloat16 requires BFloat16TypeKHR capability and SPV_KHR_bfloat16 extension.
222+
// CHECK: requires #spirv.vce<v1.0, [StorageBuffer16BitAccess, Shader, BFloat16TypeKHR], [SPV_KHR_bfloat16, SPV_KHR_16bit_storage, SPV_KHR_storage_buffer_storage_class]>
223+
spirv.module Logical GLSL450 attributes {
224+
spirv.target_env = #spirv.target_env<
225+
#spirv.vce<v1.0, [Shader, StorageBuffer16BitAccess, BFloat16TypeKHR], [SPV_KHR_bfloat16, SPV_KHR_16bit_storage, SPV_KHR_storage_buffer_storage_class]>,
226+
#spirv.resource_limits<>
227+
>
228+
} {
229+
spirv.func @load_bf16(%ptr : !spirv.ptr<bf16, StorageBuffer>) -> bf16 "None" {
230+
%val = spirv.Load "StorageBuffer" %ptr : bf16
231+
spirv.ReturnValue %val : bf16
232+
}
233+
}

0 commit comments

Comments
 (0)