123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- #include <stdio.h>
- #include <unistd.h>
- #include <errno.h>
- #include <starpu.h>
- #include <stdlib.h>
- #include <pthread.h>
- #define N 1000
- #define VECTORSIZE 1024
- static pthread_mutex_t mutex;
- static pthread_cond_t cond;
- static unsigned finished = 0;
- static unsigned cnt;
- starpu_data_handle v_handle;
- static unsigned *v;
- static void callback(void *arg)
- {
- unsigned res = STARPU_ATOMIC_ADD(&cnt, -1);
-
-
- if (res == 0)
- {
- pthread_mutex_lock(&mutex);
- finished = 1;
- pthread_cond_signal(&cond);
- pthread_mutex_unlock(&mutex);
- }
- }
- static void codelet_null(void *descr[], __attribute__ ((unused)) void *_args)
- {
- }
- static starpu_access_mode select_random_mode(void)
- {
- int r = rand();
- switch (r % 3) {
- case 0:
- return STARPU_R;
- case 1:
- return STARPU_RW;
-
- case 2:
- return STARPU_RW;
- };
- }
- static starpu_codelet cl = {
- .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL,
- .cpu_func = codelet_null,
- .cuda_func = codelet_null,
- .opencl_func = codelet_null,
- .nbuffers = 1
- };
- int main(int argc, char **argv)
- {
- starpu_init(NULL);
- starpu_data_malloc_pinned_if_possible((void **)&v, VECTORSIZE*sizeof(unsigned));
- starpu_vector_data_register(&v_handle, 0, (uintptr_t)v, VECTORSIZE, sizeof(unsigned));
- unsigned nworker = starpu_worker_get_count();
- cnt = nworker*N;
- unsigned iter, worker;
- for (iter = 0; iter < N; iter++)
- {
- for (worker = 0; worker < nworker; worker++)
- {
-
- unsigned node = starpu_worker_get_memory_node(worker);
- starpu_data_prefetch_on_node(v_handle, node, 0);
-
- struct starpu_task *task = starpu_task_create();
- task->cl = &cl;
- task->buffers[0].handle = v_handle;
- task->buffers[0].mode = select_random_mode();
- task->callback_func = callback;
- task->callback_arg = NULL;
- task->synchronous = 1;
- int ret = starpu_task_submit(task);
- if (ret == -ENODEV)
- goto enodev;
- }
- }
- pthread_mutex_lock(&mutex);
- if (!finished)
- pthread_cond_wait(&cond, &mutex);
- pthread_mutex_unlock(&mutex);
- starpu_shutdown();
- return 0;
- enodev:
- fprintf(stderr, "WARNING: No one can execute this task\n");
-
- return 0;
- }
|