Skip to content

Commit

Permalink
Add SPIRV Capabilities error in build logging
Browse files Browse the repository at this point in the history
  • Loading branch information
rjodinchr committed Nov 27, 2024
1 parent adba303 commit 3af087d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/config.def
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,6 @@ OPTION(std::string, perfetto_trace_dest, "clvk.perfetto-trace")
//
#if CLVK_UNIT_TESTING_ENABLED
OPTION(bool, force_descriptor_set_allocation_failure, false)
OPTION(bool, force_check_capabilities_error, false)
OPTION(bool, early_flush_enabled, true)
#endif
21 changes: 16 additions & 5 deletions src/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1492,7 +1492,7 @@ void cvk_program::prepare_push_constant_range() {
max_offset + max_offset_size};
}

bool cvk_program::check_capabilities(const cvk_device* device) const {
bool cvk_program::check_capabilities(const cvk_device* device) {
// Get list of required SPIR-V capabilities.
std::vector<spv::Capability> capabilities;
if (!m_binary.get_capabilities(capabilities)) {
Expand All @@ -1504,10 +1504,21 @@ bool cvk_program::check_capabilities(const cvk_device* device) const {
for (auto c : capabilities) {
cvk_info_fn("Program requires SPIR-V capability %d (%s).", c,
spirv_capability_to_string(c));
if (!device->supports_capability(c)) {
// TODO: propagate this message to the build log
cvk_error_fn("Device does not support SPIR-V capability %d (%s).",
c, spirv_capability_to_string(c));
if (!device->supports_capability(c)
#ifdef CLVK_UNIT_TESTING_ENABLED
|| config.force_check_capabilities_error()
#endif
) {
const uint32_t max_message_size = 256;
std::string error_message;
error_message.resize(max_message_size);
if (snprintf(error_message.data(), max_message_size,
"Device does not support SPIR-V capability %d (%s).",
c, spirv_capability_to_string(c)) <= 0) {
return false;
}
cvk_error_fn("%s", error_message.data());
m_build_log += error_message;
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ struct cvk_program : public _cl_program, api_object<object_magic::program> {

/// Check if all of the capabilities required by the SPIR-V module are
/// supported by `device`.
CHECK_RETURN bool check_capabilities(const cvk_device* device) const;
CHECK_RETURN bool check_capabilities(const cvk_device* device);

uint32_t m_num_devices;
cl_uint m_num_input_programs;
Expand Down
19 changes: 19 additions & 0 deletions tests/api/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,22 @@ TEST_F(WithContext, SetUnusedSamplerArgWithInvalidObject) {
cl_int err = clSetKernelArg(kernel, 0, sizeof(cl_sampler), &kern);
ASSERT_EQ(err, CL_INVALID_SAMPLER);
}

#if CLVK_UNIT_TESTING_ENABLED
TEST_F(WithContext, UnsupportedCapabilities) {
static const char* source = R"(
kernel void foo() {}
)";

auto cfg = CLVK_CONFIG_SCOPED_OVERRIDE(force_check_capabilities_error, bool,
true, true);
auto program = CreateProgram(source);
cl_int err =
clBuildProgram(program, 1, &gDevice, nullptr, nullptr, nullptr);
ASSERT_EQ(err, CL_BUILD_PROGRAM_FAILURE);
auto build_log = GetProgramBuildLog(program);

ASSERT_TRUE(build_log.find("Device does not support SPIR-V capability") !=
std::string::npos);
}
#endif

0 comments on commit 3af087d

Please sign in to comment.