Skip to content

Fix zero size tensors #3702

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

Closed
wants to merge 1 commit into from
Closed
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
27 changes: 18 additions & 9 deletions backends/vulkan/runtime/api/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,25 @@ void Context::register_shader_dispatch(
const ShaderInfo& shader_descriptor,
const utils::uvec3& global_workgroup_size) {
// Adjust the global workgroup size based on the output tile size
uint32_t global_wg_w = utils::div_up(
global_workgroup_size.data[0u], shader_descriptor.out_tile_size.data[0u]);
uint32_t global_wg_h = utils::div_up(
global_workgroup_size.data[1u], shader_descriptor.out_tile_size.data[1u]);
uint32_t global_wg_d = utils::div_up(
global_workgroup_size.data[2u], shader_descriptor.out_tile_size.data[2u]);

// Submitting a global work group size of 0 is undefined behaviour. If this is
// detected then submit a single workgroup instead.
if (global_wg_w == 0u || global_wg_h == 0u || global_wg_d == 0u) {
global_wg_w = 1u;
global_wg_h = 1u;
global_wg_d = 1u;
}

const utils::uvec3 effective_global_wg = {
utils::div_up(
global_workgroup_size.data[0u],
shader_descriptor.out_tile_size.data[0u]),
utils::div_up(
global_workgroup_size.data[1u],
shader_descriptor.out_tile_size.data[1u]),
utils::div_up(
global_workgroup_size.data[2u],
shader_descriptor.out_tile_size.data[2u]),
global_wg_w,
global_wg_h,
global_wg_d,
};

cmd_.bind_descriptors(descriptors.get_bind_handle());
Expand Down
8 changes: 6 additions & 2 deletions backends/vulkan/test/op_tests/utils/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,11 @@ def gen_graph_build_code(self) -> str:

return graph_build

def gen_graph_exec_code(self) -> str:
def gen_graph_exec_code(self, loop_range: int = 1) -> str:
graph_exec = ""
if loop_range > 1:
graph_exec += f"for (int i = 0; i < {loop_range} ; ++i) "
graph_exec += "{\n"
for aten_arg in self.args:
ref = self.refs[aten_arg.name]
if ref.is_in:
Expand All @@ -544,6 +547,8 @@ def gen_graph_exec_code(self) -> str:

graph_exec += self.declare_vk_out_for(self.refs["out"])
graph_exec += self.copy_from_staging(self.refs["out"])
graph_exec += self.check_graph_out(self.refs["out"])
graph_exec += "}\n"

return graph_exec

Expand All @@ -564,7 +569,6 @@ def gen_op_check_fn(self) -> str:
op_check_fn_body += self.gen_conditional_skips()
op_check_fn_body += self.gen_graph_build_code()
op_check_fn_body += self.gen_graph_exec_code()
op_check_fn_body += self.check_graph_out(self.refs["out"])

# Add two level of indent for readability
op_check_fn_body = re.sub(r"^", " ", op_check_fn_body, flags=re.M)
Expand Down
Loading