-
Notifications
You must be signed in to change notification settings - Fork 3
/
exec_generic.c
63 lines (53 loc) · 1.38 KB
/
exec_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
// SPDX-License-Identifier: Apache-2.0
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <vaccel.h>
int main(int argc, char **argv)
{
int ret;
struct vaccel_session sess;
int input;
int output = 0;
char *func = "mytestfunc";
if (argc < 3) {
vaccel_error(
"You must specify path to shared object and the number of iterations");
return 1;
}
ret = vaccel_session_init(&sess, 0);
if (ret != VACCEL_OK) {
vaccel_error("Could not initialize session");
return 1;
}
printf("Initialized session with id: %" PRId64 "\n", sess.id);
input = 10; /* some random input value */
enum vaccel_op_type op_type = VACCEL_EXEC;
struct vaccel_arg read[4] = {
{ .size = sizeof(uint8_t), .buf = &op_type },
{ .size = strlen(argv[1]) + 1, .buf = argv[1] },
{ .size = strlen(func) + 1, .buf = func },
{ .size = sizeof(input), .buf = &input }
};
struct vaccel_arg write[1] = {
{ .size = sizeof(output), .buf = &output },
};
for (int i = 0; i < atoi(argv[2]); ++i) {
ret = vaccel_genop(&sess, read, 4, write, 1);
if (ret) {
vaccel_error("Could not run op: %d", ret);
goto close_session;
}
}
printf("output(2x%d): %d\n", input, output);
close_session:
if (vaccel_session_release(&sess) != VACCEL_OK) {
vaccel_error("Could not clear session");
return 1;
}
return ret;
}