Skip to content

Reference "Software Emulation" implementation of GGML_OP_MUL_MAT #6171

Answered by wilderfield
wilderfield asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks @ggerganov. I found a bug in that example, and filed a PR: ggml-org/ggml#770

However, it worked as the perfect testbench for me to fool around until I understood something.

GGML mul_mat computes:

$$ A * B^T = C^T $$

$$ (m x k) * (n x k) = (n x m) $$

Here is my functioning emulation code:

    // Compute C^T
    // The input matricies A and B have the same width for cache performance
    // For some reason, the result of the computation is C^T
    for (int i3 = 0; i3 < ne3; ++i3) {
        for (int i2 = 0; i2 < ne2; ++i2) {
            for (int i1 = 0; i1 < ne1; ++i1) { // rows of C, rows of B
                for (int i0 = 0; i0 < ne0; ++i0) { // cols of C, rows of A
                …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@wilderfield
Comment options

Answer selected by wilderfield
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants