-
Notifications
You must be signed in to change notification settings - Fork 3
/
classify_generic.c
67 lines (55 loc) · 1.47 KB
/
classify_generic.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// SPDX-License-Identifier: Apache-2.0
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "../src/utils/fs.h"
#include <vaccel.h>
int main(int argc, char *argv[])
{
int ret;
char *image;
size_t image_size;
char out_text[512];
char out_imagename[512];
struct vaccel_session sess;
if (argc != 3) {
fprintf(stderr, "Usage: %s filename #iterations\n", argv[0]);
return 0;
}
ret = vaccel_session_init(&sess, 0);
if (ret != VACCEL_OK) {
fprintf(stderr, "Could not initialize session\n");
return 1;
}
printf("Initialized session with id: %" PRId64 "\n", sess.id);
ret = fs_file_read(argv[1], (void **)&image, &image_size);
if (ret)
goto close_session;
enum vaccel_op_type op_type = VACCEL_IMG_CLASS;
struct vaccel_arg read[2] = { { .size = sizeof(enum vaccel_op_type),
.buf = &op_type },
{ .size = image_size, .buf = image } };
struct vaccel_arg write[2] = {
{ .size = sizeof(out_text), .buf = out_text },
{ .size = sizeof(out_imagename), .buf = out_imagename },
};
for (int i = 0; i < atoi(argv[2]); ++i) {
ret = vaccel_genop(&sess, read, 2, write, 2);
if (ret) {
fprintf(stderr, "Could not run op: %d\n", ret);
goto close_session;
}
if (i == 0)
printf("classification tags: %s\n", out_text);
}
close_session:
free(image);
if (vaccel_session_release(&sess) != VACCEL_OK) {
fprintf(stderr, "Could not clear session\n");
return 1;
}
return ret;
}