Skip to content

Use TmpTensor for MatMul op. #8088

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

Merged
merged 1 commit into from
Feb 6, 2025
Merged
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
13 changes: 10 additions & 3 deletions backends/vulkan/runtime/graph/ops/impl/MatMul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,25 @@ void add_matmul_optimized_node(
/*passthrough = */ true);

// Ensure mat1 is width packed
ValueRef mat1_W_packed = graph.add_tensor_like(mat1, utils::kWidthPacked);
TmpTensor mat1_tmp(
&graph, graph.sizes_of(mat1), graph.dtype_of(mat1), utils::kWidthPacked);
ValueRef mat1_W_packed = mat1;
auto viewFn = VK_GET_OP_FN("aten.view_copy.default");
viewFn(graph, {mat1, graph.add_none(), mat1_W_packed});
if (graph.packed_dim_of(mat1) != WHCN::kWidthDim) {
mat1_W_packed = mat1_tmp;
viewFn(graph, {mat1, graph.add_none(), mat1_W_packed});
}

const bool mat2_is_transposed_val = graph.get_bool(mat2_is_transposed);

// Ensure mat2 to height packed
ValueRef mat2_packed = mat2;
const utils::GPUMemoryLayout mat2_layout =
mat2_is_transposed_val ? utils::kWidthPacked : utils::kHeightPacked;
TmpTensor mat2_tmp(
&graph, graph.sizes_of(mat2), graph.dtype_of(mat2), mat2_layout);
if (graph.estimate_memory_layout_of(mat2) != mat2_layout) {
mat2_packed = graph.add_tensor_like(mat2, mat2_layout);
mat2_packed = mat2_tmp;
viewFn(graph, {mat2, graph.add_none(), mat2_packed});
}

Expand Down
Loading