Skip to content

Commit

Permalink
Add SPIRV Capabilities error in build log (#746)
Browse files Browse the repository at this point in the history
* Add SPIRV Capabilities error in build logging

Ref #743

* Update src/program.cpp

Co-authored-by: Kévin Petit <[email protected]>

* Update src/program.cpp

---------

Co-authored-by: Kévin Petit <[email protected]>
  • Loading branch information
rjodinchr and kpet authored Dec 1, 2024
1 parent a75d0a2 commit 04d4282
Show file tree
Hide file tree
Showing 4 changed files with 32 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
16 changes: 11 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,16 @@ 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
) {
std::stringstream error_message;
error_message << "Device does not support SPIR-V capability " << c
<< " (" << spirv_capability_to_string(c) << ").";
cvk_error_fn("%s", error_message.str().c_str());
m_build_log += error_message.str();
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 04d4282

Please sign in to comment.