Skip to content

Commit

Permalink
Import version v1.2.1.
Browse files Browse the repository at this point in the history
API is extended.

* struct veo_args *veo_args_alloc(void);
* int veo_args_set_i64(struct veo_args *, int, int64_t);
* int veo_args_set_double(struct veo_args *, int, double);
* int veo_args_set_stack(struct veo_args *, enum veo_args_intent,
                         int, char *, size_t);
* void veo_args_clear(struct veo_args *);
* void veo_args_free(struct veo_args *);
* int veo_args_set_u64(struct veo_args *, int, uint64_t);
* int veo_args_set_i32(struct veo_args *, int, int32_t);
* int veo_args_set_u32(struct veo_args *, int, uint32_t);
* int veo_args_set_float(struct veo_args *, int, float);
* uint64_t veo_async_read_mem(veo_thr_ctxt *ctx, void *dst,
                              uint64_t src, size_t size);
* uint64_t veo_async_write_mem(veo_thr_ctxt *ctx, uint64_t dst,
                               const void *src, size_t size).

These API design was proposed and the first prototype was
implemented by Erich Focht.
  • Loading branch information
teruyukiimai committed Aug 8, 2018
1 parent 0592339 commit 4ec26c2
Show file tree
Hide file tree
Showing 25 changed files with 1,039 additions and 124 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
@@ -1,6 +1,6 @@
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = src include
EXTRA_DIST = veo.spec.in examples patches
EXTRA_DIST = veo.spec.in examples
dist_noinst_DATA = veo.spec
CLEANFILES = veo.spec

Expand Down
6 changes: 1 addition & 5 deletions configure.ac
@@ -1,5 +1,5 @@
AC_PREREQ([2.69])
AC_INIT([veoffload], [1.0.2])
AC_INIT([veoffload], [1.2.1])
AM_INIT_AUTOMAKE([foreign -Wall])
AC_CONFIG_SRCDIR([src/libveo/api.cpp])
AC_CONFIG_MACRO_DIR([m4])
Expand Down Expand Up @@ -36,10 +36,6 @@ AC_ARG_WITH([veorun], [AS_HELP_STRING([--with-veorun],
VEORUN_BIN="${with_veorun}"
AC_SUBST(VEORUN_BIN)

AC_ARG_WITH([veos-src], [AS_HELP_STRING([--with-veos-src],
[VE OS source tree])], [VEOS_SRC=${with_veos_src}],
[AC_MSG_ERROR([Specify VE OS source tree.])])
AC_SUBST(VEOS_SRC)
CPPFLAGS="$CPPFLAGS -I${includedir}"
LDFLAGS="$LDFLAGS -L${libdir}"
# make configurable if necessary.
Expand Down
23 changes: 23 additions & 0 deletions examples/README
Expand Up @@ -37,3 +37,26 @@ gcc -std=gnu99 -o test_nb_static test_nb_static.c -I/opt/nec/ve/veos/include \

VEORUN_BIN=`pwd`/veorun_vesleep ./test_nb_static

#--------------------

# Example for usage of async memory transfers

/opt/nec/ve/bin/ncc -shared -fpic -o libveasyncmem.so libveasyncmem.c

gcc -o test_async_mem test_async_mem.c -I/opt/nec/ve/veos/include \
-L/opt/nec/ve/veos/lib64 -Wl,-rpath=/opt/nec/ve/veos/lib64 -lveo

./test_async_mem

#--------------------

# Example for using "call by reference" with variables on the stack.

/opt/nec/ve/bin/ncc -shared -fpic -pthread -o libvestackargs.so libvestackargs.c

gcc -std=gnu99 -o test_stackargs test_stackargs.c -I/opt/nec/ve/veos/include \
-pthread -L/opt/nec/ve/veos/lib64 -Wl,-rpath=/opt/nec/ve/veos/lib64 -lveo

./test_stackargs

#-------------------
9 changes: 5 additions & 4 deletions examples/hello.c
Expand Up @@ -16,9 +16,9 @@ main()

struct veo_thr_ctxt *ctx = veo_context_open(proc);
printf("VEO context = %p\n", ctx);
struct veo_call_args arg;
arg.arguments[0] = 42;
uint64_t id = veo_call_async(ctx, sym, &arg);
struct veo_args *argp = veo_args_alloc();
veo_args_set_i64(argp, 0, 42);
uint64_t id = veo_call_async(ctx, sym, argp);
printf("VEO request ID = 0x%lx\n", id);
uint64_t buffer = 0;
uint64_t bufptr = veo_get_sym(proc, handle, "buffer");
Expand All @@ -30,12 +30,13 @@ main()
ret = veo_write_mem(proc, bufptr, &buffer, sizeof(buffer));
printf("veo_write_mem() returned %d\n", ret);
uint64_t sym2 = veo_get_sym(proc, handle, "print_buffer");
uint64_t id2 = veo_call_async(ctx, sym2, &arg);
uint64_t id2 = veo_call_async(ctx, sym2, argp);
uint64_t retval;
ret = veo_call_wait_result(ctx, id, &retval);
printf("0x%lx: %d, %lu\n", id, ret, retval);
ret = veo_call_wait_result(ctx, id2, &retval);
printf("0x%lx: %d, %lu\n", id2, ret, retval);
veo_args_free(argp);
int close_status = veo_context_close(ctx);
printf("close status = %d\n", close_status);
return 0;
Expand Down
11 changes: 11 additions & 0 deletions examples/libveasyncmem.c
@@ -0,0 +1,11 @@
#include <stdio.h>
#include <stdint.h>

int64_t buffer = 0xdeadbeefdeadbeef;

uint64_t print_buffer()
{
printf("0x%016lx\n", buffer);
fflush(stdout);
return 1;
}
52 changes: 52 additions & 0 deletions examples/libvestackargs.c
@@ -0,0 +1,52 @@
//
// /opt/nec/ve/bin/ncc -shared -fpic -pthread -o libvestackargs.so libvestackargs.c
//
#include <stdio.h>

void ftest(double *d, char *t, int *i)
{
int a;
printf("VE: sp = %p\n", (void *)&a);
printf("VE: arguments passed: %p, %p, %p\n", (void *)d, (void *)t, (void *)i);
printf("VE: arguments passed by reference: %f, %s, %d\n", *d, t, *i);
}

long test_many_args(double d0, double d1, double d2, double d3, double d4,
double d5, double d6, double d7, double d8, double d9)
{
double result;
result = d0 + d1 + d2 + d3 + d4 + d5 + d6 + d7 + d8 + d9;
printf("VE: %f + %f + %f + %f + %f + %f + %f + %f + %f + %f = %f\n",
d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, result);
union {
double d;
long l;
} u;
u.d = result;
return u.l;
}

int test_32(int i32, unsigned int u32, float f32)
{
union {
float f;
int i;
} u;
u.f = f32;
int i = u.i;
printf("VE: argument passed: %d, %u, %f (%#08x) \n", i32, u32, f32, i);
return 0;
}

int test_many_inout(char *in0, int *inout1, float *out2, double d3, double d4,
double d5, double d6, double d7, char *out8, int i9)
{
printf("VE: %s\n", in0);
printf("VE: %d\n", *inout1);
++*inout1;
double s = d3 + d4 + d5 + d6 + d7;
printf("VE: %f + %f + %f + %f + %f = %f\n", d3, d4, d5, d6, d7, s);
*out2 = (float)s;
strncpy(out8, "Hello, 89abcdef", i9 - 1);
return 1;
}
52 changes: 52 additions & 0 deletions examples/test_async_mem.c
@@ -0,0 +1,52 @@
#include <stdio.h>
#include <stdlib.h>
#include <ve_offload.h>
int
main()
{
uint64_t retval;
int ret;

struct veo_proc_handle *proc = veo_proc_create(0);
if (proc == NULL) {
perror("veo_proc_create");
exit(1);
}
uint64_t handle = veo_load_library(proc, "./libveasyncmem.so");
printf("handle = %p\n", (void *)handle);

struct veo_thr_ctxt *ctx = veo_context_open(proc);
printf("VEO context = %p\n", ctx);
struct veo_args *argp = veo_args_alloc();

uint64_t buffer = 0;
uint64_t bufptr = veo_get_sym(proc, handle, "buffer");
uint64_t sym = veo_get_sym(proc, handle, "print_buffer");

uint64_t req;
req = veo_async_read_mem(ctx, &buffer, bufptr, sizeof(buffer));
printf("veo_async_read_mem() returned %ld\n", req);
veo_call_wait_result(ctx, req, &retval);

printf("%016lx\n", buffer);

uint64_t id = veo_call_async(ctx, sym, argp);
printf("veo_call_async() returned %ld\n", id);
ret = veo_call_wait_result(ctx, id, &retval);
printf("0x%lx: %d, %lu\n", id, ret, retval);

buffer = 0xc0ffee;
req = veo_async_write_mem(ctx, bufptr, &buffer, sizeof(buffer));
printf("veo_async_write_mem() returned %ld\n", req);

id = veo_call_async(ctx, sym, argp);
printf("veo_call_async() returned %ld\n", id);
ret = veo_call_wait_result(ctx, id, &retval);
printf("0x%lx: %d, %lu\n", id, ret, retval);
ret = veo_call_wait_result(ctx, req, &retval);
printf("0x%lx: %d, %lu\n", req, ret, retval);

int close_status = veo_context_close(ctx);
printf("close status = %d\n", close_status);
return 0;
}
7 changes: 4 additions & 3 deletions examples/test_nb_static.c
Expand Up @@ -22,9 +22,9 @@ int main()
printf("VEO context1 = %p\n", ctx1);

uint64_t reqs[2];
struct veo_call_args arg;
arg.arguments[0] = 5;
reqs[0] = veo_call_async(ctx1, sym, &arg);
struct veo_args *arg = veo_args_alloc();
veo_args_set_i64(arg, 0, 5);
reqs[0] = veo_call_async(ctx1, sym, arg);
printf("VEO request ID1 = 0x%lx\n", reqs[0]);

uint64_t retval;
Expand All @@ -33,6 +33,7 @@ int main()
printf("sleep 1...\n");
sleep(1);
}
veo_args_free(arg);

int close_status = veo_context_close(ctx1);
printf("close status 1 = %d\n", close_status);
Expand Down
9 changes: 5 additions & 4 deletions examples/test_nonblock.c
Expand Up @@ -24,9 +24,9 @@ int main()
printf("VEO context1 = %p\n", ctx1);

uint64_t reqs[2];
struct veo_call_args arg;
arg.arguments[0] = 5;
reqs[0] = veo_call_async(ctx1, sym, &arg);
struct veo_args *arg = veo_args_alloc();
veo_args_set_i64(arg, 0, 5);
reqs[0] = veo_call_async(ctx1, sym, arg);
printf("VEO request ID1 = 0x%lx\n", reqs[0]);

uint64_t retval;
Expand All @@ -35,7 +35,8 @@ int main()
printf("sleep 1...\n");
sleep(1);
}

veo_args_free(arg);

int close_status = veo_context_close(ctx1);
printf("close status 1 = %d\n", close_status);
return 0;
Expand Down
106 changes: 106 additions & 0 deletions examples/test_stackargs.c
@@ -0,0 +1,106 @@
//
// gcc -std=gnu99 -o test_stackargs test_stackargs.c -I/opt/nec/ve/veos/include -pthread -L/opt/nec/ve/veos/lib64 -Wl,-rpath=/opt/nec/ve/veos/lib64 -lveo
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ve_offload.h>

int main()
{
int ret;
struct veo_proc_handle *proc = veo_proc_create(0);
if (proc == NULL) {
printf("veo_proc_create() failed!\n");
exit(1);
}
uint64_t handle = veo_load_library(proc, "./libvestackargs.so");
printf("handle = %p\n", (void *)handle);
uint64_t sym = veo_get_sym(proc, handle, "ftest");
printf("symbol address = %p\n", (void *)sym);

struct veo_thr_ctxt *ctx = veo_context_open(proc);
printf("VEO context = %p\n", ctx);

struct veo_args *arg = veo_args_alloc();
double ad = -1.876;
char *at = "hello stack!\0";
int ai = 19181716;

veo_args_set_stack(arg, VEO_INTENT_IN, 0, (char *)&ad, sizeof(ad));
veo_args_set_stack(arg, VEO_INTENT_IN, 1, at, strlen(at) + 1);
veo_args_set_stack(arg, VEO_INTENT_IN, 2, (char *)&ai, sizeof(ai));

uint64_t req = veo_call_async(ctx, sym, arg);
long retval;
ret = veo_call_wait_result(ctx, req, &retval),

veo_args_free(arg);

arg = veo_args_alloc();
veo_args_set_double(arg, 0, 1.0);
veo_args_set_double(arg, 1, 2.0);
veo_args_set_double(arg, 2, 3.0);
veo_args_set_double(arg, 3, 4.0);
veo_args_set_double(arg, 4, 5.0);
veo_args_set_double(arg, 5, 6.0);
veo_args_set_double(arg, 6, 7.0);
veo_args_set_double(arg, 7, 8.0);
veo_args_set_double(arg, 8, 9.0);
veo_args_set_double(arg, 9, 10.0);
uint64_t sym_test_many_args = veo_get_sym(proc, handle,
"test_many_args");
printf("symbol address (test_many_args) = %p\n",
(void *)sym_test_many_args);
uint64_t req_args = veo_call_async(ctx, sym_test_many_args, arg);
ret = veo_call_wait_result(ctx, req_args, &retval);
veo_args_free(arg);

arg = veo_args_alloc();
veo_args_set_i32(arg, 0, -2);
veo_args_set_u32(arg, 1, 0xa0a0a0a0);
veo_args_set_float(arg, 2, 1.0f);
uint64_t sym_32 = veo_get_sym(proc, handle, "test_32");

printf("symbol address (test_32) = %p\n", sym_32);
uint64_t req_32 = veo_call_async(ctx, sym_32, arg);
ret = veo_call_wait_result(ctx, req_32, &retval);
veo_args_free(arg);

uint64_t sym_many_io = veo_get_sym(proc, handle, "test_many_inout");
printf("symbol address (test_many_inout) = %p\n", (void *)sym_many_io);
arg = veo_args_alloc();
char in0[] = "Hello, world.";
veo_args_set_stack(arg, VEO_INTENT_IN, 0, in0, sizeof(in0));
int inout1 = 42;
veo_args_set_stack(arg, VEO_INTENT_INOUT, 1, &inout1, sizeof(inout1));
printf("VH: inout1 = %d\n", inout1);
float out2;
veo_args_set_stack(arg, VEO_INTENT_OUT, 2, &out2, sizeof(out2));
veo_args_set_double(arg, 3, 1.0);
veo_args_set_double(arg, 4, 2.0);
veo_args_set_double(arg, 5, 3.0);
veo_args_set_double(arg, 6, 4.0);
veo_args_set_double(arg, 7, 5.0);
char out8[10];
veo_args_set_stack(arg, VEO_INTENT_OUT, 8, out8, sizeof(out8));
veo_args_set_u32(arg, 9, sizeof(out8));

uint64_t req_many_io = veo_call_async(ctx, sym_many_io, arg);
ret = veo_call_wait_result(ctx, req_many_io, &retval);
veo_args_free(arg);
printf("VH: inout1 = %d\n", inout1);
union {
float f;
uint64_t x;
} u;
u.f = out2;
printf("VH: out2 = %f (%#08x)\n", (double)out2, u.x);
printf("VH: out8 = %s\n", out8);

veo_context_close(ctx);
return 0;
}

0 comments on commit 4ec26c2

Please sign in to comment.