Skip to content

Commit

Permalink
review: modify codes as review suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
zhou.weiguo committed Jun 14, 2024
1 parent 11c7b1e commit 181c0e3
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions examples/benchmark/benchmark-matmult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,10 @@ 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;
float floatvalue = 0;
double sum = 0.0;
float floatvalue = 0.0f;
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++) {
Expand All @@ -53,17 +45,13 @@ static float tensor_sum_elements(const ggml_tensor * tensor) {
sum += floatvalue;
}
}
}

if (tensor->type == GGML_TYPE_F32) {
} else 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];
}
}
}

if (ggml_is_quantized(tensor->type)) {
} else if (ggml_is_quantized(tensor->type)) {
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());
Expand Down

0 comments on commit 181c0e3

Please sign in to comment.