Skip to content
Closed
Changes from 5 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
36 changes: 34 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 @@ -32,14 +33,45 @@ static void ggml_graph_compute_helper(std::vector<uint8_t> & buf, ggml_cgraph *
}

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_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_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 (ggml_is_quantized(tensor->type)) {
Comment thread
zhouwg marked this conversation as resolved.
Outdated
std::vector<float> f32out(ggml_nelements(tensor));
ggml_type_traits_t qtype = ggml_internal_get_type_traits(tensor->type);
qtype.to_float((void *)tensor->data, f32out.data(), f32out.size());
for (const float & value : f32out) {
sum += value;
}
}

return sum;
}

Expand Down