Skip to content

Commit 7e4294b

Browse files
author
zhouwg
committed
tests: a simple backend ut
1 parent 16ce36b commit 7e4294b

File tree

1 file changed

+17
-27
lines changed

1 file changed

+17
-27
lines changed

tests/simple-backend-ut.cpp

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,6 @@ static void show_usage() {
169169

170170

171171
int main(int argc, char * argv[]) {
172-
int64_t n_begin_time = 0LL;
173-
int64_t n_end_time = 0LL;
174-
int64_t n_duration = 0LL;
175172
size_t ctx_size = 0;
176173
int sizey = 4;
177174
int sizex = 4;
@@ -211,27 +208,27 @@ int main(int argc, char * argv[]) {
211208

212209
printf("Testing %zu devices\n\n", ggml_backend_dev_count());
213210
for (size_t i = 0; i < ggml_backend_dev_count(); i++) {
214-
ggml_backend_dev_t dev = ggml_backend_dev_get(i);
211+
ggml_backend_dev_t dev = ggml_backend_dev_get(i);
215212

216-
printf("Backend %zu/%zu: %s\n", i + 1, ggml_backend_dev_count(),
217-
ggml_backend_dev_name(dev));
213+
printf("Backend %zu/%zu: %s\n", i + 1, ggml_backend_dev_count(),
214+
ggml_backend_dev_name(dev));
218215

219-
if (ggml_backend_dev_type(dev) == GGML_BACKEND_DEVICE_TYPE_CPU) {
220-
printf(" Skipping CPU backend\n");
221-
continue;
222-
}
216+
if (ggml_backend_dev_type(dev) == GGML_BACKEND_DEVICE_TYPE_CPU) {
217+
printf(" Skipping CPU backend\n");
218+
continue;
219+
}
223220

224-
backend = ggml_backend_dev_init(dev, reinterpret_cast<const char *>(i));
225-
GGML_ASSERT(backend != NULL);
226-
if (backend != nullptr) {
227-
printf("%s: initialize %s backend\n", __func__, ggml_backend_dev_name(dev));
228-
}
221+
backend = ggml_backend_dev_init(dev, reinterpret_cast<const char *>(i));
222+
GGML_ASSERT(backend != NULL);
223+
if (backend != nullptr) {
224+
printf("%s: initialize %s backend\n", __func__, ggml_backend_dev_name(dev));
225+
}
229226

230-
printf(" Device description: %s\n", ggml_backend_dev_description(dev));
231-
size_t free, total;
232-
ggml_backend_dev_memory(dev, &free, &total);
233-
printf(" Device memory: %zu MB (%zu MB free)\n", total / 1024 / 1024, free / 1024 / 1024);
234-
printf("\n");
227+
printf(" Device description: %s\n", ggml_backend_dev_description(dev));
228+
size_t free, total;
229+
ggml_backend_dev_memory(dev, &free, &total);
230+
printf(" Device memory: %zu MB (%zu MB free)\n", total / 1024 / 1024, free / 1024 / 1024);
231+
printf("\n");
235232
}
236233

237234
ggml_backend_t backend_cpu = nullptr;
@@ -245,9 +242,6 @@ int main(int argc, char * argv[]) {
245242

246243
printf("ggml op:%d(%s)", n_ggml_op_type, ggml_op_name((enum ggml_op) n_ggml_op_type));
247244

248-
n_begin_time = ggml_time_us();
249-
srand(time(NULL));
250-
251245
ctx_size += 1024 * 1024 * 32;
252246
printf("allocating Memory of size %zi bytes, %zi MB\n", ctx_size,
253247
(ctx_size / 1024 / 1024));
@@ -332,9 +326,5 @@ int main(int argc, char * argv[]) {
332326
ggml_backend_free(backend);
333327
ggml_backend_free(backend_cpu);
334328

335-
n_end_time = ggml_time_us();
336-
n_duration = (n_end_time - n_begin_time) / 1000;
337-
printf("duration of ut GGML_OP_%s: %lld milliseconds\n", ggml_op_name((enum ggml_op)n_ggml_op_type), n_duration);
338-
339329
return 0;
340330
}

0 commit comments

Comments
 (0)