#include #include #include #include #include #include "../helper.h" #include "StreamFMA.max" #include "MaxSLiCInterface.h" #include "StreamFMA.h" #define SIZE 128 static max_engine_t *engine ; static max_actions_t*act; static max_file_t *maxfile; void cpu_func(void *buffers[], void *cl_arg) { int *a = (int*) STARPU_VECTOR_GET_PTR(buffers[0]); int *b = (int*) STARPU_VECTOR_GET_PTR(buffers[1]); int *c = (int*) STARPU_VECTOR_GET_PTR(buffers[2]); int size = STARPU_VECTOR_GET_NX(buffers[0]); (void)buffers; (void)cl_arg; int i; for (i = 0; i < size; i++) c[i] = a[i] + b[i]; } void fpga_mult(void *buffers[], void *cl_arg) { (void)cl_arg; int *a = (int*) STARPU_VECTOR_GET_PTR(buffers[0]); int *b = (int*) STARPU_VECTOR_GET_PTR(buffers[1]); int *c = (int*) STARPU_VECTOR_GET_PTR(buffers[2]); int size = STARPU_VECTOR_GET_NX(buffers[0]); //Actions to run on an engine act = max_actions_init(maxfile, NULL); //set the number of ticks for a kernel max_set_ticks (act, "StreamFMAKernel", size); #if 1 // sera remplacé par le transfert fait par le copy_fpga_to_ram/ram_to_fpga //add data to an input stream //max_set_param_uint64t(act, "address", 0); //max_set_param_uint64t(act, "nbytes", size *sizeof(a[0])); max_queue_input(act, "a", a, size *sizeof(a[0])); max_queue_input(act, "b", b, size*sizeof(b[0])); max_queue_output(act,"output", c, size*sizeof(c[0])); // et à la place, ici on récupère le pointeur dans la mémoire FPGA avec STARPU_VECTOR_GET_PTR(descr[0]), et c'est ça qu'on donne à l'implémentation fpga #endif //run actions on the engine printf("Running on DFE using dynamic interface ...\n"); printf("**** Run actions in non blocking mode **** \n"); //run actions in non_blocking mode max_run_t *run0= max_run_nonblock(engine, act); printf("*** wait for the actions on DFE to complete *** \n"); //wait for the actions to complete max_wait(run0); } static struct starpu_codelet cl = { .cpu_funcs = {cpu_func}, .cpu_funcs_name = {"cpu_func"}, //#ifdef STARPU_USE_FPGA .fpga_funcs = {fpga_mult}, .fpga_funcs_name={"fpga_mult"}, //#endif .nbuffers = 3, .modes = {STARPU_R, STARPU_R, STARPU_W} }; int main(int argc, char **argv) { /* Enable profiling */ starpu_profiling_status_set(1); struct starpu_conf conf; starpu_data_handle_t handle_a, handle_b, handle_c; int ret; int size=1234; starpu_conf_init(&conf); conf.sched_policy_name = "eager"; conf.calibrate = 0; ret = starpu_initialize(&conf, &argc, &argv); if (ret == -ENODEV) return STARPU_TEST_SKIPPED; STARPU_CHECK_RETURN_VALUE(ret, "starpu_init"); //Implementation of a maxfile maxfile = StreamFMA_init(); //Implementation of an engine engine = max_load(maxfile, "*"); int a[SIZE]; int b[SIZE]; int c[SIZE]; int i; for(i = 0; i < SIZE; ++i) { a[i] = random() % 100; b[i] = random() % 100; } starpu_vector_data_register(&handle_a, STARPU_MAIN_RAM, (uintptr_t) &a, SIZE, sizeof(int)); starpu_vector_data_register(&handle_b, STARPU_MAIN_RAM, (uintptr_t) &b, SIZE, sizeof(int)); starpu_vector_data_register(&handle_c, STARPU_MAIN_RAM, (uintptr_t) &c, SIZE, sizeof(int)); struct starpu_task *task = starpu_task_create(); task->cl = &cl; task->handles[0] = handle_a; task->handles[1] = handle_b; task->handles[2] = handle_c; task->synchronous = 1; task->destroy = 0; /* submit the task to StarPU */ //starpu_task_destroy(task); ret = starpu_task_submit(task); fprintf(stderr,"task submitted %d\n", ret); starpu_data_unregister(handle_a); starpu_data_unregister(handle_b); starpu_data_unregister(handle_c); int mysize = SIZE; if (mysize > 10) mysize = 10; for (i = 0; i < mysize; ++i) { printf("%d == %d\n", c[i], a[i] + b[i]); } #if 1 // -> main //deallocate the set of actions max_actions_free(act); //unload and deallocate an engine obtained by way of max_load max_unload(engine); #endif starpu_shutdown(); return EXIT_SUCCESS; }