ggml : use simpler ggml_bytes() implementation

This commit is contained in:
Georgi Gerganov 2023-09-13 11:39:09 +03:00
parent 3074a7ff14
commit 905c944143
No known key found for this signature in database
GPG Key ID: 449E073F9DC10735
2 changed files with 13 additions and 33 deletions

40
ggml.c
View File

@ -4303,41 +4303,19 @@ int64_t ggml_nrows(const struct ggml_tensor * tensor) {
}
size_t ggml_nbytes(const struct ggml_tensor * tensor) {
// original:
//size_t nbytes = tensor->ne[0]*tensor->nb[0]/ggml_blck_size(tensor->type);
//for (int i = 1; i < GGML_MAX_DIMS; ++i) {
// nbytes += (tensor->ne[i] - 1)*tensor->nb[i];
//}
//return nbytes;
// TODO: the imlpementation below is stupid - need something better
// sort ne and nb
int64_t sne[GGML_MAX_DIMS];
size_t snb[GGML_MAX_DIMS];
size_t nbytes;
size_t blck_size = ggml_blck_size(tensor->type);
if (blck_size == 1) {
nbytes = ggml_type_size(tensor->type);
for (int i = 0; i < GGML_MAX_DIMS; ++i) {
sne[i] = tensor->ne[i];
snb[i] = tensor->nb[i];
}
for (int i = 0; i < GGML_MAX_DIMS; ++i) {
for (int j = i + 1; j < GGML_MAX_DIMS; ++j) {
if ((snb[i] > snb[j]) || (snb[i] == snb[j] && sne[i] < sne[j])) {
size_t tmp = snb[i];
snb[i] = snb[j];
snb[j] = tmp;
int64_t tmp2 = sne[i];
sne[i] = sne[j];
sne[j] = tmp2;
nbytes += (tensor->ne[i] - 1)*tensor->nb[i];
}
}
}
size_t nbytes = (sne[0]/ggml_blck_size(tensor->type))*snb[0];
else {
nbytes = tensor->ne[0]*tensor->nb[0]/blck_size;
for (int i = 1; i < GGML_MAX_DIMS; ++i) {
nbytes += (sne[i] - 1)*snb[i];
nbytes += (tensor->ne[i] - 1)*tensor->nb[i];
}
}
return nbytes;

View File

@ -1406,6 +1406,8 @@ static bool whisper_model_load(struct whisper_model_loader * loader, whisper_con
}
static bool whisper_encode_external(const whisper_state & wstate) {
GGML_UNUSED(wstate);
#ifndef WHISPER_USE_COREML
const bool use_coreml = false;
#else