insert_task.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 Centre National de la Recherche Scientifique
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <starpu.h>
  17. void func_cpu(void *descr[], void *_args)
  18. {
  19. int *x0 = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  20. float *x1 = (float *)STARPU_VARIABLE_GET_PTR(descr[1]);
  21. int ifactor;
  22. float ffactor;
  23. starpu_unpack_cl_args(_args, &ifactor, &ffactor);
  24. *x0 = *x0 * ifactor;
  25. *x1 = *x1 * ffactor;
  26. }
  27. starpu_codelet mycodelet = {
  28. .where = STARPU_CPU,
  29. .cpu_func = func_cpu,
  30. .nbuffers = 2
  31. };
  32. int main(int argc, char **argv)
  33. {
  34. int x; float f;
  35. int i;
  36. int ifactor=12;
  37. float ffactor=10.0;
  38. starpu_data_handle data_handles[2];
  39. starpu_init(NULL);
  40. x = 1;
  41. starpu_variable_data_register(&data_handles[0], 0, (uintptr_t)&x, sizeof(x));
  42. f = 2.0;
  43. starpu_variable_data_register(&data_handles[1], 0, (uintptr_t)&f, sizeof(f));
  44. fprintf(stderr, "VALUES: %d (%d) %f (%f)\n", x, ifactor, f, ffactor);
  45. starpu_insert_task(&mycodelet,
  46. STARPU_VALUE, &ifactor, sizeof(ifactor),
  47. STARPU_VALUE, &ffactor, sizeof(ffactor),
  48. STARPU_RW, data_handles[0], STARPU_RW, data_handles[1],
  49. 0);
  50. starpu_task_wait_for_all();
  51. for(i=0 ; i<2 ; i++) {
  52. starpu_data_acquire(data_handles[i], STARPU_R);
  53. }
  54. fprintf(stderr, "VALUES: %d %f\n", x, f);
  55. for(i=0 ; i<2 ; i++) {
  56. starpu_data_release(data_handles[i]);
  57. }
  58. struct starpu_task *task = starpu_task_create();
  59. task->cl = &mycodelet;
  60. task->buffers[0].handle = data_handles[0];
  61. task->buffers[0].mode = STARPU_RW;
  62. task->buffers[1].handle = data_handles[1];
  63. task->buffers[1].mode = STARPU_RW;
  64. char *arg_buffer;
  65. size_t arg_buffer_size;
  66. starpu_pack_cl_args(&arg_buffer, &arg_buffer_size,
  67. STARPU_VALUE, &ifactor, sizeof(ifactor),
  68. STARPU_VALUE, &ffactor, sizeof(ffactor),
  69. 0);
  70. task->cl_arg = arg_buffer;
  71. task->cl_arg_size = arg_buffer_size;
  72. starpu_task_submit(task);
  73. starpu_task_wait_for_all();
  74. for(i=0 ; i<2 ; i++) {
  75. starpu_data_acquire(data_handles[i], STARPU_R);
  76. }
  77. fprintf(stderr, "VALUES: %d %f\n", x, f);
  78. starpu_shutdown();
  79. return 0;
  80. }