Skip to content

Commit 8cda5c9

Browse files
authored
fix whitespace (abetlen#944)
1 parent ec29272 commit 8cda5c9

File tree

2 files changed

+56
-56
lines changed

2 files changed

+56
-56
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,15 @@ embedding: examples/embedding/embedding.cpp ggml.o llama.o common.o
171171

172172
libllama.so: llama.o ggml.o
173173
$(CXX) $(CXXFLAGS) -shared -fPIC -o libllama.so llama.o ggml.o $(LDFLAGS)
174-
174+
175175
#
176176
# Tests
177177
#
178178

179179
benchmark: ggml.o
180-
$(CXX) $(CXXFLAGS) examples/benchmark/benchmark-q4_0-matmult.c ggml.o -o benchmark-q4_0-matmult $(LDFLAGS)
180+
$(CXX) $(CXXFLAGS) examples/benchmark/benchmark-q4_0-matmult.c ggml.o -o benchmark-q4_0-matmult $(LDFLAGS)
181181
./benchmark-q4_0-matmult
182-
182+
183183
.PHONY: tests
184184
tests:
185185
bash ./tests/run-tests.sh

examples/benchmark/benchmark-q4_0-matmult.c

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424

2525
float tensor_sum_elements(struct ggml_tensor * tensor) {
2626
float sum = 0;
27-
if (tensor->type==6) {
28-
for (int j = 0; j < tensor->ne[1]; j++) {
29-
for (int k = 0; k < tensor->ne[0]; k++) {
30-
sum += ((float *) tensor->data)[j*tensor->ne[0]+k];
31-
}
32-
}
27+
if (tensor->type==6) {
28+
for (int j = 0; j < tensor->ne[1]; j++) {
29+
for (int k = 0; k < tensor->ne[0]; k++) {
30+
sum += ((float *) tensor->data)[j*tensor->ne[0]+k];
31+
}
32+
}
3333
}
3434
return sum;
3535
}
@@ -39,7 +39,7 @@ float tensor_sum_elements(struct ggml_tensor * tensor) {
3939
These are mapping to unknown
4040
GGML_TYPE_I8,
4141
GGML_TYPE_I16,
42-
GGML_TYPE_I32,
42+
GGML_TYPE_I32,
4343
GGML_TYPE_COUNT,
4444
*/
4545

@@ -50,7 +50,7 @@ float tensor_sum_elements(struct ggml_tensor * tensor) {
5050
TENSOR->ne[0], TENSOR->ne[1], TENSOR->ne[2], TENSOR->nb[0], TENSOR->nb[1], TENSOR->nb[2]); \
5151
{ float sum = tensor_sum_elements(TENSOR); printf("Sum of tensor %s is %6.2f\n",#TENSOR, sum); }
5252

53-
struct benchmark_params_struct {
53+
struct benchmark_params_struct {
5454
int32_t n_threads = 1;
5555
int32_t n_iterations = 10;
5656
};
@@ -67,7 +67,7 @@ void print_usage(int /*argc*/, char ** argv, struct benchmark_params_struct para
6767

6868
int main(int argc, char ** argv) {
6969

70-
70+
7171
struct benchmark_params_struct benchmark_params;
7272

7373
bool invalid_param = false;
@@ -90,7 +90,7 @@ int main(int argc, char ** argv) {
9090
} else if (arg == "-h" || arg == "--help") {
9191
print_usage(argc, argv, benchmark_params);
9292
exit(0);
93-
}
93+
}
9494
if (invalid_param) {
9595
fprintf(stderr, "error: invalid parameter for argument: %s\n", arg.c_str());
9696
print_usage(argc, argv, benchmark_params);
@@ -101,41 +101,41 @@ int main(int argc, char ** argv) {
101101

102102
// create the ggml context
103103
printf("Starting Test\n");
104-
105104

106-
105+
106+
107107
struct ggml_context * ctx;
108108
//const int sizex = 4096;
109109
//const int sizey = 11008;
110110

111111
#undef VERBOSE_DEBUGGING
112112
#ifndef VERBOSE_DEBUGGING
113113
const int sizey = 4096;
114-
const int sizex = 11008;
114+
const int sizex = 11008;
115115
const int sizez = 128;
116116
#else
117117
/* Working - let's increase size */
118118
const int sizey = 1;
119-
const int sizex = (8*32);
119+
const int sizex = (8*32);
120120
const int sizez = 1;
121121

122122
/*const int sizey = 1;
123-
const int sizex = 3*(8*32);
123+
const int sizex = 3*(8*32);
124124
const int sizez = 1;*/
125125
#endif
126126

127127
//printf("Memsize required = %i\n", sizex*sizex);
128-
ggml_type wtype = GGML_TYPE_F32;
129-
128+
ggml_type wtype = GGML_TYPE_F32;
129+
130130
size_t ctx_size = 0;
131131
ctx_size += sizex*sizey*ggml_type_sizef(wtype);
132132
ctx_size += sizex*sizey*ggml_type_sizef(wtype);
133133
ctx_size += sizex*sizey*ggml_type_sizef(GGML_TYPE_F32);
134134
ctx_size += sizex*sizeof(float);
135-
ctx_size += 1024*1024*100;
136-
135+
ctx_size += 1024*1024*100;
136+
137137
printf("Allocating Memory of size %li byes, %li MB\n",ctx_size, (ctx_size/1024/1024));
138-
138+
139139
struct ggml_init_params params = {
140140
/*.mem_size =*/ ctx_size,
141141
/*.mem_buffer =*/ NULL,
@@ -147,88 +147,88 @@ int main(int argc, char ** argv) {
147147
fprintf(stderr, "%s: ggml_init() failed\n", __func__);
148148
return false;
149149
}
150-
151-
150+
151+
152152
printf("Creating new tensors\n");
153153
// printf("Creating new tensor m1\n");
154154
struct ggml_tensor * m11 = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, sizex, sizey);
155155
ggml_set_f32(m11, 1.0f);
156-
156+
157157
// printf("Creating new tensor m1\n");
158158
struct ggml_tensor * m12 = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, sizex, sizey);
159159
ggml_set_f32(m12, 1.5f);
160-
160+
161161
// printf("Creating new tensor m2\n");
162162
struct ggml_tensor * m2 = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, sizex, sizez);
163163
ggml_set_f32(m2, 2.0f);
164-
164+
165165
printf("\n------ Test 1 - Matrix Mult via F32 code ------------------------------------------------------------------------------\n");
166166
// printf("Creating new tensor m11xm2\n");
167167
struct ggml_tensor * m11xm2 = ggml_mul_mat(ctx, m11, m2);
168-
168+
169169
// printf("Creating compute graph\n");
170170
struct ggml_cgraph gf = ggml_build_forward(m11xm2);
171-
171+
172172
gf.n_threads=benchmark_params.n_threads;
173-
printf("cgraph->n_threads=%i\n",gf.n_threads);
174-
173+
printf("cgraph->n_threads=%i\n",gf.n_threads);
174+
175175
TENSOR_DUMP(m11);
176176
TENSOR_DUMP(m2);
177-
177+
178178
ggml_graph_compute(ctx, &gf);
179179

180180
TENSOR_DUMP(gf.nodes[0]);
181-
181+
182182
printf("\n------ Test 2 - Matrix Mult via Q4_0 code ------------------------------------------------------------------------------\n");
183-
183+
184184
int32_t nelements = sizex*sizey;
185185
int32_t ne[2] = { sizex, sizey };
186-
187-
std::vector<int64_t> hist_cur(1 << 4, 0);
186+
187+
std::vector<int64_t> hist_cur(1 << 4, 0);
188188

189189
// Set up a the benchmark matrices
190190
// printf("Creating new tensor q11 & Running quantize\n");
191191
struct ggml_tensor * q11 = ggml_new_tensor_2d(ctx, GGML_TYPE_Q4_0, sizex, sizey);
192192
ggml_quantize_q4_0((const float *) m11->data, q11->data, nelements, ne[0], hist_cur.data());
193-
193+
194194
// Set up a the compute graph
195195
// printf("Creating new tensor q31\n");
196196
struct ggml_tensor * q31 = ggml_mul_mat(ctx, q11, m2);
197-
197+
198198
// printf("Creating compute graph\n");
199199
struct ggml_cgraph gf31 = ggml_build_forward(q31);
200200
gf31.n_threads=benchmark_params.n_threads;
201-
202-
// Set up a second graph computation to make sure we override the CPU cache lines
201+
202+
// Set up a second graph computation to make sure we override the CPU cache lines
203203
// printf("Creating new tensor q12 & Running quantize\n");
204204
struct ggml_tensor * q12 = ggml_new_tensor_2d(ctx, GGML_TYPE_Q4_0, sizex, sizey);
205205
ggml_quantize_q4_0((const float *) m12->data, q12->data, nelements, ne[0], hist_cur.data());
206206

207207
// printf("Creating new tensor q32\n");
208208
struct ggml_tensor * q32 = ggml_mul_mat(ctx, q12, m2);
209-
209+
210210
//printf("Creating compute graph\n");
211211
struct ggml_cgraph gf32 = ggml_build_forward(q32);
212212
gf32.n_threads=benchmark_params.n_threads;
213-
printf("cgraph->n_threads=%i\n",gf31.n_threads);
214-
213+
printf("cgraph->n_threads=%i\n",gf31.n_threads);
214+
215215
const int dimx = sizex;
216216
const int dimy = sizey;
217217
const int dimz = sizez;
218218
long long int flops_per_dot_product = dimy + dimy;
219219
long long int flops_per_matrix = flops_per_dot_product * dimx * dimz; ;
220220
printf("Matrix Multiplication of (%i,%i,%i) x (%i,%i,%i) - aboout %6.2f gFLOPS\n\n", sizex, sizey, 1, sizex, sizez, 1, 1.0f*flops_per_matrix / 1000 / 1000 / 1000);
221-
221+
222222

223223
// Let's use the F32 result from above as a reference for the q4_0 multiplication
224224
float sum_of_F32_reference = tensor_sum_elements(gf.nodes[0]);
225-
225+
226226

227227
printf("Iteration;NThreads; SizeX; SizeY; SizeZ; Required_FLOPS; Elapsed_u_Seconds; FLOPS_per_u_Second\n");
228228
printf("==============================================================================================\n");
229-
229+
230230
for (int i=0;i<benchmark_params.n_iterations ;i++) {
231-
231+
232232
long long int start = ggml_time_us();
233233
//printf("Running ggml_graph_compute\n");
234234
ggml_graph_compute(ctx, &gf31);
@@ -238,33 +238,33 @@ int main(int argc, char ** argv) {
238238
float flops_per_usec = (1.0f*flops_per_matrix)/usec;
239239
printf("%9i;%8i;%6i;%6i;%6i;%15lli;%18lli;%19.2f\n",
240240
i,
241-
gf31.n_threads,
242-
sizex, sizey, sizez, flops_per_matrix,
241+
gf31.n_threads,
242+
sizex, sizey, sizez, flops_per_matrix,
243243
usec,flops_per_usec);
244244

245245
#ifdef VERBOSE_DEBUGGING
246246
TENSOR_DUMP("res",gf31.nodes[0])
247247
#endif
248248

249-
// Check that the matrix multiplication result is in the right ballpark
249+
// Check that the matrix multiplication result is in the right ballpark
250250
// We cannot use the exact value from the F32 multiplication because the quantizuation will be slightly different
251251
float sum_of_Q4_result = tensor_sum_elements(gf31.nodes[0]);
252252
float delta = abs(sum_of_Q4_result - sum_of_F32_reference);
253253
float allowed_delta = (sum_of_F32_reference) / 1000 / 1000; // Let's accept an epsilon of 10^-6
254254

255255
if (delta > allowed_delta) {
256256
printf("\nABORT - ERROR in Matrix Multiplication result - expected %6.2f, got %6.2f (delta %6.2f > allowed_delta %6.2f)\n",
257-
sum_of_F32_reference,
257+
sum_of_F32_reference,
258258
sum_of_Q4_result,
259259
delta,
260260
allowed_delta
261261
);
262262
exit(0);
263263
}
264-
265-
// Running a different graph computation to make sure we override the CPU cache lines
264+
265+
// Running a different graph computation to make sure we override the CPU cache lines
266266
ggml_graph_compute(ctx, &gf32);
267-
267+
268268
}
269-
269+
270270
}

0 commit comments

Comments
 (0)