Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SPIRV Capabilities error in build log #746

Merged
merged 3 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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