Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 0 additions & 2 deletions source/val/validate_invalid_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ spv_result_t InvalidTypePass(ValidationState_t& _, const Instruction* inst) {
const spv::Op opcode = inst->opcode();

switch (opcode) {
// OpExtInst
case spv::Op::OpExtInst:
// Arithmetic Instructions
case spv::Op::OpFAdd:
case spv::Op::OpFSub:
Expand Down
79 changes: 79 additions & 0 deletions test/val/val_invalid_type_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,41 @@ TEST_F(ValidateInvalidType, Bfloat16InvalidGroupNonUniformShuffle) {
HasSubstr("GroupNonUniformShuffle doesn't support BFloat16 type."));
}

TEST_F(ValidateInvalidType, Bfloat16ValidExtInstruction) {
const std::string body = R"(
%15 = OpExtInst %bfloat16 %1 FClamp %bf16_1 %bf16_1 %bf16_1
)";

CompileSuccessfully(GenerateBFloatCode(body).c_str(), SPV_ENV_VULKAN_1_3);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_6));
}

TEST_F(ValidateInvalidType, Bfloat16ExtInstructionRequiresExtension) {
const std::string spirv = R"(
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
%void = OpTypeVoid
%func = OpTypeFunction %void
%bfloat16 = OpTypeFloat 16 BFloat16KHR
%bf16_1 = OpConstant %bfloat16 1
%main = OpFunction %void None %func
%entry = OpLabel
%15 = OpExtInst %bfloat16 %1 FClamp %bf16_1 %bf16_1 %bf16_1
OpReturn
OpFunctionEnd
)";

CompileSuccessfully(spirv.c_str(), SPV_ENV_VULKAN_1_3);
EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
ValidateInstructions(SPV_ENV_UNIVERSAL_1_6));
EXPECT_THAT(getDiagnosticString(),
HasSubstr("Operand 3 of TypeFloat requires one of these "
"capabilities: BFloat16TypeKHR"));
}

std::string GenerateFP8Code(const std::string& main_body) {
const std::string prefix =
R"(
Expand Down Expand Up @@ -401,6 +436,50 @@ TEST_F(ValidateInvalidType, FP8E5M2InvalidGroupNonUniformShuffle) {
HasSubstr("GroupNonUniformShuffle doesn't support FP8 E4M3/E5M2 types."));
}

TEST_F(ValidateInvalidType, FP8E4M3ValidExtInstruction) {
const std::string body = R"(
%15 = OpExtInst %fp8e4m3 %1 FClamp %fp8e4m3_1 %fp8e4m3_1 %fp8e4m3_1
Comment thread
alan-baker marked this conversation as resolved.
)";

CompileSuccessfully(GenerateFP8Code(body).c_str(), SPV_ENV_VULKAN_1_3);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_6));
}

TEST_F(ValidateInvalidType, FP8E5M2ValidExtInstruction) {
const std::string body = R"(
%15 = OpExtInst %fp8e5m2 %1 FClamp %fp8e5m2_1 %fp8e5m2_1 %fp8e5m2_1
)";

CompileSuccessfully(GenerateFP8Code(body).c_str(), SPV_ENV_VULKAN_1_3);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_6));
}

TEST_F(ValidateInvalidType, FP8ExtInstructionRequiresExtension) {
const std::string spirv = R"(
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
%void = OpTypeVoid
%func = OpTypeFunction %void
%fp8e4m3 = OpTypeFloat 8 Float8E4M3EXT
%fp8e4m3_1 = OpConstant %fp8e4m3 1
%main = OpFunction %void None %func
%entry = OpLabel
%15 = OpExtInst %fp8e4m3 %1 FClamp %fp8e4m3_1 %fp8e4m3_1 %fp8e4m3_1
OpReturn
OpFunctionEnd
)";

CompileSuccessfully(spirv.c_str(), SPV_ENV_VULKAN_1_3);
EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
ValidateInstructions(SPV_ENV_UNIVERSAL_1_6));
EXPECT_THAT(getDiagnosticString(),
HasSubstr("Operand 3 of TypeFloat requires one of these "
"capabilities: Float8EXT"));
}

} // namespace
} // namespace val
} // namespace spvtools
Loading