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

[compute/cker] Optimize BatchMatMul for x86 #14305

Merged
merged 3 commits into from
Nov 8, 2024

Conversation

tomdol
Copy link
Contributor

@tomdol tomdol commented Nov 5, 2024

This commit adds an optimized version of the BatchMatMul kernel. The optimization targets the x86 architecture, in all other cases the code is compiled with existing reference kernel.

The new kernel calls the optimized::Gemm function which uses Eigen internally.

Additionally to avoid code duplication a new BatchMatMulParams struct is introduced and reused in both reference and optimized kernels.

ONE-DCO-1.0-Signed-off-by: Tomasz Dolbniak [email protected]

This commit adds an optimized version of the BatchMatMul kernel. The optimization targets the x86 architecture, in all other cases the code is compiled with existing reference kernel.

The new kernel calls the optimized::Gemm function which uses Eigen internally.

Additionally to avoid code duplication a new BatchMatMulParams struct is introduced and reused in both reference and optimized kernels.

ONE-DCO-1.0-Signed-off-by: Tomasz Dolbniak <[email protected]>
@tomdol
Copy link
Contributor Author

tomdol commented Nov 5, 2024

This PR is a follow-up of this draft #14238 and was submitted to (partially) solve this issue #12140

@glistening
Copy link
Contributor

@tomdol Just for your information, our main target is arm, not x64. I guess you're already aware of it since you used (partially) solve. Also, for LLM, we will use GGML kernel which provides the quantized type kernel for lower than 8 bit.

@glistening
Copy link
Contributor

In addition, this PR does not have test. How did you test this kernel?

@tomdol
Copy link
Contributor Author

tomdol commented Nov 6, 2024

@glistening

How did you test this kernel?

There are existing tests for this kernel. I was thinking if I should add any but it seems that all use cases are covered.

[ RUN      ] GeneratedTests.batch_matmul_ex_dynamic_nnfw
[       OK ] GeneratedTests.batch_matmul_ex_dynamic_nnfw (1 ms)
[ RUN      ] GeneratedTests.batch_matmul_ex_float_simple
[       OK ] GeneratedTests.batch_matmul_ex_float_simple (1 ms)
[ RUN      ] GeneratedTests.batch_matmul_ex_float_adj_y
[       OK ] GeneratedTests.batch_matmul_ex_float_adj_y (1 ms)
[ RUN      ] GeneratedTests.batch_matmul_ex_float_adj_x
[       OK ] GeneratedTests.batch_matmul_ex_float_adj_x (1 ms)
[ RUN      ] GeneratedTests.batch_matmul_ex_float_batch2
[       OK ] GeneratedTests.batch_matmul_ex_float_batch2 (1 ms)
[ RUN      ] GeneratedTests.batch_matmul_ex_float_broadcast
[       OK ] GeneratedTests.batch_matmul_ex_float_broadcast (1 ms)
[ RUN      ] GeneratedTests.batch_matmul_ex_float_broadcast_adj_x
[       OK ] GeneratedTests.batch_matmul_ex_float_broadcast_adj_x (1 ms)
[ RUN      ] GeneratedTests.batch_matmul_ex_float_broadcast2_adj_xy
[       OK ] GeneratedTests.batch_matmul_ex_float_broadcast2_adj_xy (1 ms)

Regarding the GGML kernel - is someone already working on it? I was going to attempt to write an optimized version for ARM too in the next step, I would just like to know if I should proceed.

@glistening
Copy link
Contributor

glistening commented Nov 7, 2024

@tomdol Thank you for answer. Test was done via nnap tests.

Regarding the GGML kernel - is someone already working on it?

I checked out model. For our model, BatchMatMul f32 (both lhs, rhs) is necessary.

Copy link
Contributor

@glistening glistening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@glistening glistening requested a review from a team November 7, 2024 03:29
@glistening
Copy link
Contributor

@tomdol For arm optimized kernel, I am thinking of using ggml mul_mat, which is already in our repo. It supports multithread and use neon optimized code. What kernel are you thinking of?

Copy link
Contributor

@zetwhite zetwhite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@glistening glistening merged commit 1e09707 into Samsung:master Nov 8, 2024
9 checks passed
@tomdol
Copy link
Contributor Author

tomdol commented Nov 12, 2024

@tomdol For arm optimized kernel, I am thinking of using ggml mul_mat, which is already in our repo. It supports multithread and use neon optimized code. What kernel are you thinking of?

@glistening sorry about the delay in replying. I didn't think about any particular kernel yet except that there was a need for an ARM-targetting optimized version too. I was hoping to figure out more by discussing it in #12140

I would appreciate some guidelines and would like to offer to help with this part of the BatchMatMul optimization work. Unless of course someone is already taking care of it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants