Skip to content
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
10 changes: 6 additions & 4 deletions ggml/src/ggml-spacemit/ime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,11 @@ template <typename BLOC_TYPE, int64_t INTER_SIZE, int64_t NB_COLS> class tensor_
size = GGML_PAD(size, sizeof(int64_t));

const int64_t ne02 = op->src[0]->ne[2]; // n_as, n_expert
const int64_t ne12 = op->src[1]->ne[2]; // n_tokens
// An expert may appear more than once in a token's IDs.
const int64_t row_capacity = ggml_nelements(op->src[2]);

const size_t sizeof_mmid_row_mapping = sizeof(int64_t);
size += sizeof_mmid_row_mapping * ne02 * (ne12 + 1) + (ne02 + 1) * sizeof(int64_t);
size += sizeof_mmid_row_mapping * ne02 * (row_capacity + 1) + (ne02 + 1) * sizeof(int64_t);

size = GGML_PAD(size, sizeof(int64_t));

Expand Down Expand Up @@ -859,7 +860,8 @@ template <typename BLOC_TYPE, int64_t INTER_SIZE, int64_t NB_COLS> class tensor_
}
}

#define MMID_MATRIX_ROW(row_id, i1) matrix_rows[(row_id) *ne12 + (i1)]
const int64_t row_capacity = (int64_t) n_ids * ids->ne[1];
#define MMID_MATRIX_ROW(row_id, i1) matrix_rows[(row_id) * row_capacity + (i1)]

int64_t * matrix_row_counts = (int64_t *) (ws_ptr + gemm_workspace_size);
int32_t * valid_ep_count = (int32_t *) (matrix_row_counts + n_as);
Expand All @@ -876,7 +878,7 @@ template <typename BLOC_TYPE, int64_t INTER_SIZE, int64_t NB_COLS> class tensor_
const int64_t n_rows_all = (int64_t) n_ids * ids->ne[1];
auto align64 = [](uintptr_t p) { return (p + 63) & ~(uintptr_t) 63; };
const size_t nbw1_m4 = hp_aligned() ? a_k_blks * spacemit_kernels::q8_hp_al_row_blk_size : nbw1;
uintptr_t m4_ptr = align64(reinterpret_cast<uintptr_t>(matrix_rows + n_as * ne12));
uintptr_t m4_ptr = align64(reinterpret_cast<uintptr_t>(matrix_rows + n_as * row_capacity));
if (hp_aligned()) {
m4_ptr = (m4_ptr + spacemit_kernels::q8_hp_al_align - 1) & ~(uintptr_t) (spacemit_kernels::q8_hp_al_align - 1);
}
Expand Down
Loading