Skip to content
Closed
Changes from 3 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
48 changes: 46 additions & 2 deletions examples/benchmark/benchmark-matmult.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "common.h"
#include "ggml.h"
#include "ggml-impl.h"

#include <locale.h>
#include <assert.h>
Expand Down Expand Up @@ -31,15 +32,58 @@ static void ggml_graph_compute_helper(std::vector<uint8_t> & buf, ggml_cgraph *
ggml_graph_compute(graph, &plan);
}

#define QK8_0 32

typedef struct {
uint16_t d; // delta
int8_t qs[QK8_0]; // quants
} block_q8_0;

static float tensor_sum_elements(const ggml_tensor * tensor) {
double sum = 0;
double sum = 0;
float floatvalue = 0;
unsigned short shortvalue = 0;

if (tensor->type == GGML_TYPE_F32) {
for (int j = 0; j < tensor->ne[1]; j++) {
for (int k = 0; k < tensor->ne[0]; k++) {
sum += ((float *) tensor->data)[j*tensor->ne[0] + k];
sum += ((float *) tensor->data)[j * tensor->ne[0] + k];
}
}
}

if (tensor->type == GGML_TYPE_I8) {
for (int j = 0; j < tensor->ne[1]; j++) {
for (int k = 0; k < tensor->ne[0]; k++) {
sum += ((int8_t *) tensor->data)[j * tensor->ne[0] + k];
}
}
}

if (tensor->type == GGML_TYPE_F16) {
for (int j = 0; j < tensor->ne[1]; j++) {
for (int k = 0; k < tensor->ne[0]; k++) {
shortvalue = ((unsigned short *) tensor->data)[j * tensor->ne[0] + k];
floatvalue = GGML_FP16_TO_FP32(shortvalue);
sum += floatvalue;
}
}
}

if (tensor->type == GGML_TYPE_Q8_0) {
int blocks = 0;
block_q8_0 * quant_datas = (block_q8_0 *)tensor->data;
for (int j = 0; j < tensor->ne[1]; j++) {
blocks = tensor->ne[0] / QK8_0;
for (int i = 0; i < blocks; i++) {
floatvalue = GGML_FP16_TO_FP32(quant_datas[j * blocks + i].d);
Comment thread
zhouwg marked this conversation as resolved.
Outdated
for (int k = 0; k < QK8_0; k++) {
sum += (quant_datas[j * blocks + i].qs[k] * floatvalue);
}
}
}
}

return sum;
}

Expand Down