Skip to content

Commit ca63ea5

Browse files
authored
Fix validation of BFloat16 FP types (KhronosGroup#6092)
These should not require the Float16/Float16Buffer capabilities. Change-Id: I3b50260ba634502befb36b6a67dac5961f102fa3 Signed-off-by: Kevin Petit <kevin.petit@arm.com>
1 parent 096bb07 commit ca63ea5

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

source/val/validate_type.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ spv_result_t ValidateTypeFloat(ValidationState_t& _, const Instruction* inst) {
112112
// Int8, Int16, and Int64 capabilities allow using 8-bit, 16-bit, and 64-bit
113113
// integers, respectively.
114114
auto num_bits = inst->GetOperandAs<const uint32_t>(1);
115+
const bool has_encoding = inst->operands().size() > 2;
115116
if (num_bits == 32) {
116117
return SPV_SUCCESS;
117118
}
@@ -125,7 +126,9 @@ spv_result_t ValidateTypeFloat(ValidationState_t& _, const Instruction* inst) {
125126
}
126127

127128
if (num_bits == 16) {
128-
if (_.features().declare_float16_type) {
129+
// An absence of FP encoding implies IEEE 754. The Float16 and Float16Buffer
130+
// capabilities only enable IEEE 754 binary 16
131+
if (has_encoding || _.features().declare_float16_type) {
129132
return SPV_SUCCESS;
130133
}
131134
return _.diag(SPV_ERROR_INVALID_DATA, inst)

test/val/val_data_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,12 @@ TEST_F(ValidateData, dot_bfloat16_bad) {
416416
HasSubstr("requires BFloat16DotProductKHR be declared."));
417417
}
418418

419+
TEST_F(ValidateData, bfloat16_without_float16_capability_good) {
420+
std::string str = header_with_bfloat16 + "%2 = OpTypeFloat 16 BFloat16KHR";
421+
CompileSuccessfully(str.c_str());
422+
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
423+
}
424+
419425
TEST_F(ValidateData, float64_good) {
420426
std::string str = header_with_float64 + "%2 = OpTypeFloat 64";
421427

0 commit comments

Comments
 (0)