forked from veos-sxarr-NEC/veoffload
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
0592339
commit 4ec26c2
Showing
25 changed files
with
1,039 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
Oops, something went wrong.