123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- /* StarPU --- Runtime system for heterogeneous multicore architectures.
- *
- * Copyright (C) 2011-2013,2015,2017 CNRS
- * Copyright (C) 2010,2011,2013,2014,2016-2018 Université de Bordeaux
- * Copyright (C) 2012,2017 Inria
- *
- * StarPU is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * StarPU is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * See the GNU Lesser General Public License in COPYING.LGPL for more details.
- */
- /*
- * Test using the specific_nodes field by forcing the data to main memory
- * even if the task is run on a GPU (and actually doing the computation from
- * the CPU driving the GPU). It mixes such accesses and normal accesses from
- * the GPU
- */
- #include <starpu.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <errno.h>
- #include <stdio.h>
- #include <starpu_scheduler.h>
- #include "../helper.h"
- #include "StreamFMA.h"
- #include "MaxSLiCInterface.h"
- #define SIZE 128
- static max_engine_t *engine ;
- static max_actions_t*act;
- static max_file_t *maxfile;
- void specific_kernel(void *descr[], void *arg)
- {
- (void)arg;
- int *a = (int*) STARPU_VECTOR_GET_PTR(descr[0]);
- int *b = (int*) STARPU_VECTOR_GET_PTR(descr[1]);
- int *c = (int*) STARPU_VECTOR_GET_PTR(descr[2]);
- int node = starpu_task_get_current_data_node(0);
- STARPU_ASSERT(node >= 0);
- STARPU_ASSERT(starpu_node_get_kind(node) == STARPU_CPU_RAM);
- unsigned *dataptr = (unsigned*) STARPU_VARIABLE_GET_PTR(descr[0]);
- // int i;
- // for (i = 0; i < size; i++)
- // c[i] = a[i]+b[i];
- if (node == STARPU_MAIN_RAM)
- STARPU_ASSERT(dataptr == &c);
- (*dataptr)++;
- }
- void fpga_mult(void *descr[], void *arg)
- {
- (void)arg;
- int *a = (int*) STARPU_VECTOR_GET_PTR(descr[0]);
- int *b = (int*) STARPU_VECTOR_GET_PTR(descr[1]);
- int *c = (int*) STARPU_VECTOR_GET_PTR(descr[2]);
- int size = STARPU_VECTOR_GET_NX(descr[0]);
- int node = starpu_task_get_current_data_node(2);
-
- if (node == STARPU_MAIN_RAM)
- {
- printf("hellooooo ...\n");
- }
- else {
- printf("byeee....\n");
- }
- //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);
- 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]));
- //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 specific_cl =
- {
- .cpu_funcs = {specific_kernel},
- .fpga_funcs = {fpga_mult},
- .nbuffers = 3,
- .modes = {STARPU_R,STARPU_R, STARPU_W},
- .specific_nodes = 1,
- .nodes = {STARPU_SPECIFIC_NODE_CPU, STARPU_SPECIFIC_NODE_CPU, STARPU_SPECIFIC_NODE_LOCAL_OR_CPU},
- };
- 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 = &specific_cl;
- task->handles[0] = handle_a;
- task->handles[1] = handle_b;
- task->handles[2] = handle_c;
-
- task->synchronous = 1;
- task->destroy = 0;
- 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]);
- }
- max_actions_free(act);
- //unload and deallocate an engine obtained by way of max_load
- max_unload(engine);
- starpu_shutdown();
- return EXIT_SUCCESS;
- }
|