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

cpu: x64: matmul: fixes correctness issue about tags #2362

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

xuxinzen
Copy link
Contributor

@xuxinzen xuxinzen commented Jan 9, 2025

Fixes # (MFDNN-12707, MFDNN-12625)

When one tag can be treated as plain or adbc, some offsets should be updated.
WIP: checking if additional test cases are needed

@xuxinzen xuxinzen added bug A confirmed library bug platform:cpu-x64 Intel64/AMD64 processors. Codeowner: @oneapi-src/onednn-cpu-x64 labels Jan 9, 2025
@xuxinzen xuxinzen requested a review from a team as a code owner January 9, 2025 16:47
@xuxinzen xuxinzen changed the title cpu: x64: matmul: fixes correctness issue on tags cpu: x64: matmul: fixes correctness issue about tags Jan 9, 2025
@xuxinzen
Copy link
Contributor Author

xuxinzen commented Jan 9, 2025

make test
enable benchdnn_nightly
disable benchdnn_all
enable benchdnn_matmul

@@ -1798,9 +1800,13 @@ void init_aux_values(brgemm_matmul_conf_t &bgmmc,
const dim_t src_stride = src_d.matches_tag(acbd)
? bgmmc.A_strides[1]
: bgmmc.A_strides[0];
const dim_t copy_A_src_stride = src_d.matches_tag(dabc)
Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand it right, when src can be treated as plain (i.e. treat_transposed_A_as_plain is true) then we don't copy A so this stride won't be used, if so why do we need to adjust it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case, dabc can be treated as adbc which should be transpose format and treat_transposed_A_as_plain is false. We need to use copy_A.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we use bgmmc.transposed_A (as it already accounts for treating transposed as plain) instead of matching tag?

It seems less error prone for all code paths to rely on uniquely set variable than to retest specific tags.

@xuxinzen xuxinzen force-pushed the xzeng/fixup_matmul_tag branch from 1279bfd to ffda84d Compare January 10, 2025 09:44
@xuxinzen xuxinzen requested a review from a team as a code owner January 10, 2025 09:44
@github-actions github-actions bot added the component:tests Codeowner: @oneapi-src/onednn-arch label Jan 10, 2025
@xuxinzen
Copy link
Contributor Author

make test
enable benchdnn_nightly
disable benchdnn_all
enable benchdnn_matmul

@xuxinzen xuxinzen force-pushed the xzeng/fixup_matmul_tag branch from ffda84d to f09eb76 Compare January 10, 2025 09:48
@xuxinzen
Copy link
Contributor Author

make test
enable benchdnn_nightly
disable benchdnn_all
enable benchdnn_matmul

Copy link
Contributor

@mgouicem mgouicem left a comment

Choose a reason for hiding this comment

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

My 2 cents: it seems that when unit dimension are present, trying to match tags is bug prone as:

  • we have to match the whole set of tags that are equivalent when a unit dimension is present. And if we miss one, that would go to a different code path.
  • the order in which tags are matched would lead to weird behaviors.

I guess a more robust path would be to normalize the descriptor first and then match to "canonical" tags. What do you think?

@@ -1798,9 +1800,13 @@ void init_aux_values(brgemm_matmul_conf_t &bgmmc,
const dim_t src_stride = src_d.matches_tag(acbd)
? bgmmc.A_strides[1]
: bgmmc.A_strides[0];
const dim_t copy_A_src_stride = src_d.matches_tag(dabc)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we use bgmmc.transposed_A (as it already accounts for treating transposed as plain) instead of matching tag?

It seems less error prone for all code paths to rely on uniquely set variable than to retest specific tags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A confirmed library bug component:tests Codeowner: @oneapi-src/onednn-arch platform:cpu-x64 Intel64/AMD64 processors. Codeowner: @oneapi-src/onednn-cpu-x64
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants