5 changed files with 99 additions and 11 deletions
@ -0,0 +1,9 @@ |
|||
# Function Shipping Example |
|||
|
|||
The purpose is to foster discussion of capabilities. |
|||
|
|||
The library in ./emulation provides a development kit for function shipping. |
|||
In test/ there is test code showing |
|||
- how a reduction happens traditionally in the client. |
|||
- how reduction could be executed on the server (that uses the emulation/dev kit) |
|||
The run.sh script contains everything to build and run the both test applications. |
@ -1,5 +1,33 @@ |
|||
#include <ngi.h> |
|||
#include <assert.h> |
|||
#include <float.h> |
|||
#include <math.h> |
|||
|
|||
void server_reduce(FILE * file, size_t off, size_t size){ |
|||
|
|||
int server_reduce(FILE * file, ngi_op_t op, ngi_type_t type, void * out_buff, size_t off, size_t size){ |
|||
fseek(file, off, SEEK_SET); |
|||
|
|||
assert(type == NGI_TYPE_FLOAT); |
|||
assert(op == NGI_OP_MAX); |
|||
|
|||
float * data = malloc(size); |
|||
fread(data, size, 1, file); |
|||
|
|||
float mx = -INFINITY; |
|||
for(size_t i=0; i < size/sizeof(float); i++){ |
|||
mx = data[i] > mx ? data[i]: mx; |
|||
} |
|||
*(float*) out_buff = mx; |
|||
|
|||
free(data); |
|||
return 0; |
|||
} |
|||
|
|||
int server_reduce_any_func(FILE * file, void (*func)(int8_t * data, void * out_buff, size_t off, size_t size), void * out_buff, size_t max_out_data_size, size_t off, size_t size){ |
|||
fseek(file, off, SEEK_SET); |
|||
|
|||
int8_t * data = malloc(size); |
|||
fread(data, size, 1, file); |
|||
func(data, out_buff, off, size); |
|||
free(data); |
|||
return 0; |
|||
} |
|||
|
Loading…
Reference in new issue