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

matint/matfp vs mac16/fma*/fms*, and how to do multiply-only (without accumulating/subtracting) using matint #8

Open
dgazzoni opened this issue Jul 3, 2023 · 1 comment

Comments

@dgazzoni
Copy link

dgazzoni commented Jul 3, 2023

This is a question rather than an issue.

First of all, thanks for the huge effort spent on reverse engineering AMX and documenting it. It is really appreciated. I've been able to try out AMX for an application of mine and that would have been impossible without your extensive documentation.

I just wanted to confirm a few things, and I was hoping with the experience acquired with your reverse engineering effort, you could confirm a few things. Perhaps even add some pointers to enhance your already excellent documentation.

  1. Am I understanding correctly that there is some redundancy between matint/matfp and mac16/fm[as][16,32,64] when you only need to do outer products? Essentially, by choosing ALU mode 0 or 1 in matint/matfp, it appears to me you can emulate almost all functionality of mac16/fm[as][16,32,64]. Is that right or do you see any particular advantage to mac16/fm[as][16,32,64] vs matint/matfp? I'm just trying to understand the thought process of the AMX designers, and why would they have separate instructions when they could just merge them together.
  2. With that said, one functionality I was unable to find in matint/matfp was the ability to do a multiply-only operation x*y rather than accumulating/subtracting with z. With mac16/fm[as][16,32,64] this can be done by setting bit 27 to 1. This is important e.g. for the first loop iteration in a matrix multiply, when z may already have non-zero values. Is there a combination of bits I can use to do an outer product without accumulating/subtracting from z?
@corsix
Copy link
Owner

corsix commented Jul 3, 2023

RE 1, my assumption is that we're seeing ISA evolution; there was an AMX on iPhone hardware before AMX on M1, and my guess is that mac16/fm[as][16,32,64] were in the first iteration of AMX, and then matint /matfp were added later. If this were the case, then if you had a zoo of old iPhones, you could probably find the point in history when the new instructions were added.

RE 2, rather than peeling one loop iteration and having that iteration skip the z input, issue some instruction to initialise the relevant part of z to zero (e.g. fma16 with 27=1, 28=1, 29=1, 62=1 to set all of z to zero).

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

No branches or pull requests

2 participants