123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- #include <stdio.h>
- #include <stdint.h>
- #include <starpu.h>
- #include <sc_hypervisor.h>
- #define NTASKS 1000
- #define NINCR 10
- #define FPRINTF(ofile, fmt, ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ## __VA_ARGS__); }} while(0)
- struct params
- {
- unsigned sched_ctx;
- int task_tag;
- };
- unsigned val[2];
- pthread_mutex_t mut[2];
- void cpu_func(__attribute__((unused))void *buffers[], void *cl_arg)
- {
- struct params *params = (struct params *) cl_arg;
- int i;
- for(i = 0; i < NINCR; i++)
- {
- pthread_mutex_lock(&mut[params->sched_ctx - 1]);
- val[params->sched_ctx - 1]++;
- pthread_mutex_unlock(&mut[params->sched_ctx - 1]);
- }
- if(params->task_tag != 0)
- FPRINTF(stdout, "Task with tag %d executed in ctx = %d %d counter_tests\n", params->task_tag, params->sched_ctx, val[params->sched_ctx - 1]);
- }
- struct starpu_codelet cl = {0};
- int tag = 1;
- void* submit_tasks_thread(void *arg)
- {
- unsigned sched_ctx = *((unsigned*)arg);
- starpu_sched_ctx_set_context(&sched_ctx);
- struct starpu_task *task[NTASKS];
- struct params params[NTASKS];
- int i;
- for(i = 0; i < NTASKS; i++)
- {
- task[i] = starpu_task_create();
- cl.cpu_funcs[0] = cpu_func;
- cl.nbuffers = 0;
- task[i]->cl = &cl;
- if(sched_ctx == 1 && i == 5)
- {
-
- task[i]->hypervisor_tag = tag;
-
- sc_hypervisor_ctl(sched_ctx,
- SC_HYPERVISOR_TIME_TO_APPLY, tag,
- SC_HYPERVISOR_MIN_WORKERS, 2,
- SC_HYPERVISOR_MAX_WORKERS, 12,
- SC_HYPERVISOR_NULL);
- printf("require resize for sched_ctx %d at tag %d\n", sched_ctx, tag);
-
- sc_hypervisor_post_resize_request(sched_ctx, tag);
- }
- params[i].sched_ctx = sched_ctx;
- params[i].task_tag = task[i]->hypervisor_tag;
- task[i]->cl_arg = ¶ms[i];
- task[i]->cl_arg_size = sizeof(params);
- int ret = starpu_task_submit(task[i]);
- STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
- }
- starpu_task_wait_for_all();
- return NULL;
- }
- int main()
- {
- int ret = starpu_init(NULL);
- if (ret == -ENODEV)
- return 77;
- int nres1 = 6;
- int nres2 = 6;
- int ressources1[nres1];
- int ressources2[nres2];
- int i;
- for(i = 0; i < nres1; i++)
- ressources1[i] = i;
- for(i = 0; i < nres2; i++)
- ressources2[i] = nres1+i;
-
- unsigned sched_ctx1 = starpu_sched_ctx_create(ressources1, nres1, "sched_ctx1", STARPU_SCHED_CTX_POLICY_NAME, "dmda", 0);
- unsigned sched_ctx2 = starpu_sched_ctx_create(ressources2, nres2, "sched_ctx2", STARPU_SCHED_CTX_POLICY_NAME, "dmda", 0);
-
- struct sc_hypervisor_policy policy;
- policy.custom = 0;
-
- policy.name = "app_driven";
- void *perf_counters = sc_hypervisor_init(&policy);
-
- starpu_sched_ctx_set_perf_counters(sched_ctx1, perf_counters);
- starpu_sched_ctx_set_perf_counters(sched_ctx2, perf_counters);
-
- sc_hypervisor_register_ctx(sched_ctx1, 0.0);
- sc_hypervisor_register_ctx(sched_ctx2, 0.0);
- starpu_pthread_t tid[2];
- val[0] = 0;
- val[1] = 0;
- pthread_mutex_init(&mut[0], NULL);
- pthread_mutex_init(&mut[1], NULL);
-
- starpu_pthread_create(&tid[0], NULL, submit_tasks_thread, (void*)&sched_ctx1);
- starpu_pthread_create(&tid[1], NULL, submit_tasks_thread, (void*)&sched_ctx2);
- starpu_pthread_join(tid[0], NULL);
- starpu_pthread_join(tid[1], NULL);
-
- starpu_shutdown();
- sc_hypervisor_shutdown();
- FPRINTF(stdout, "ctx = %d executed %d counter_tests out of %d \n", sched_ctx1, val[0], NTASKS*NINCR);
- FPRINTF(stdout, "ctx = %d executed %d counter_tests out of %d \n", sched_ctx2, val[1], NTASKS*NINCR);
- return 0;
- }
|