| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- #include <starpu.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <fpga.h>
- #include <starpu_scheduler.h>
- #include "../helper.h"
- void cpu_func(void *buffers[], void *cl_arg)
- {
- (void)buffers;
- (void)cl_arg;
- printf("Hello world\n");
- }
- void fpga_mult(void *d[])
- {
- /* Ask Fpga for a channel, or
- * equivalently for a hardware task
- */
- int chnl = fpga_reserve_a_chanel();
- /* Get inputs from STARPU */
- int* subA = STARPU_MATRIX_GET_PTR(d[0]);
- int* subB = STARPU_MATRIX_GET_PTR(d[1]);
- int* subC = STARPU_MATRIX_GET_PTR(d[2]);
- /* Get info on which part of the
- * inputs the task must operate
- */
- uint32_t nyA= STARPU_MATRIX_GET_NY(d[0]);
- uint32_t ldA= STARPU_MATRIX_GET_LD(d[0]);
- uint32_t nyB= STARPU_MATRIX_GET_NY(d[1]);
- uint32_t ldB= STARPU_MATRIX_GET_LD(d[1]);
- uint32_t nyC= STARPU_MATRIX_GET_NY(d[2]);
- uint32_t ldC= STARPU_MATRIX_GET_LD(d[2]);
- uint32_t nxC= STARPU_MATRIX_GET_NX(d[2]);
- /* Send A and B */
- int buf_s[nyA], buf_r[nxC*nyC];
- fpga_trans sent, recv;
- for (uint32_t j = 0; j < nxC; j++)
- {
- for (uint32_t k = 0; k < nyA; k++)
- buf_s[k] = subA[j+k*ldA];
- fpga_data_send(chnl, buf_s, nyA);
- }
- for (uint32_t i = 0; i < nyC; i++)
- {
- for (uint32_t k = 0; k < nyA; k++)
- buf_s[k] = subB[k+i*ldB];
- fpga_data_send(chnl, buf_s, nyA);
- }
- /* Receive C. This is blocking */
- fpga_data_recv(chnl, buf_r, nxC*nyC);
- for (uint32_t i = 0; i < nxC; i++)
- {
- for (uint32_t j = 0; j < nyC; j++)
- subC[j + i*ldC] = buf_r[i*nyC+j];
- }
- fpga_release_chanel(chnl);
- }
- static struct starpu_codelet cl =
- {
- .cpu_funcs = {cpu_func},
- .cpu_funcs_name = {"cpu_func"},
- //.fpga_funcs = {fpga_mult},
- .fpga_funcs = {fpga_mult},
- .fpga_funcs_name={"fpga_mult"},
- .nbuffers = 3,
- .modes = {STARPU_R, STARPU_R, STARPU_W}
- };
- int main(int argc, char **argv)
- {
- starpu_profiling_status_set(1);
- struct starpu_conf conf;
- starpu_data_handle_t A_handle, B_handle, C_handle;
- int ret;
- starpu_conf_init(&conf);
- ret = starpu_initialize(&conf, &argc, &argv);
- if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
- STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
- /* initialize StarPU */
- starpu_init(NULL);
- for (uint32_t x = 0; x < 9; x++)
- {
- for (uint32_t y = 0; y < 9; y++)
- {
- struct starpu_task *task = starpu_task_create();
- task->cl = &cl; /* Pointer to the codelet defined above */
- /* Get handlers for each block */
- task->handles[0] = starpu_data_get_sub_data( A_handle, 1, y);
- task->handles[1] = starpu_data_get_sub_data( B_handle, 1, x);
- task->handles[2] = starpu_data_get_sub_data( C_handle, 2, x, y);
- /* submit the task to StarPU */
- starpu_task_submit(task);
- }
- }
- starpu_data_unregister(A_handle);
- starpu_data_unregister(B_handle);
- starpu_data_unregister(C_handle);
- starpu_task_wait_for_all();
- /* terminate StarPU */
- starpu_shutdown();
- return 0;
- }
|