insert_task_array.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012,2013 Inria
  4. * Copyright (C) 2011-2013,2015,2017 CNRS
  5. * Copyright (C) 2014-2016 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu.h>
  19. #include "../helper.h"
  20. /*
  21. * Test STARPU_DATA_ARRAY
  22. */
  23. void func_cpu(void *descr[], void *_args)
  24. {
  25. int *x0 = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  26. float *x1 = (float *)STARPU_VARIABLE_GET_PTR(descr[1]);
  27. int factor;
  28. starpu_codelet_unpack_args(_args, &factor);
  29. *x0 = *x0 * factor;
  30. *x1 = *x1 * (float)factor;
  31. }
  32. struct starpu_codelet mycodelet =
  33. {
  34. .modes = { STARPU_RW, STARPU_RW },
  35. .cpu_funcs = {func_cpu},
  36. .cpu_funcs_name = {"func_cpu"},
  37. .nbuffers = 2
  38. };
  39. int main(void)
  40. {
  41. int x; float f;
  42. int factor=12;
  43. int i, ret;
  44. starpu_data_handle_t data_handles[2];
  45. ret = starpu_init(NULL);
  46. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  47. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  48. x = 1;
  49. starpu_variable_data_register(&data_handles[0], STARPU_MAIN_RAM, (uintptr_t)&x, sizeof(x));
  50. f = 2.0;
  51. starpu_variable_data_register(&data_handles[1], STARPU_MAIN_RAM, (uintptr_t)&f, sizeof(f));
  52. ret = starpu_task_insert(&mycodelet,
  53. STARPU_DATA_ARRAY, data_handles, 2,
  54. STARPU_VALUE, &factor, sizeof(factor),
  55. STARPU_PRIORITY, 1,
  56. 0);
  57. if (ret == -ENODEV) goto enodev;
  58. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  59. ret = starpu_task_wait_for_all();
  60. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  61. enodev:
  62. for(i=0 ; i<2 ; i++)
  63. {
  64. starpu_data_unregister(data_handles[i]);
  65. }
  66. starpu_shutdown();
  67. if (ret == -ENODEV)
  68. {
  69. fprintf(stderr, "WARNING: No one can execute this task\n");
  70. /* yes, we do not perform the computation but we did detect that no one
  71. * could perform the kernel, so this is not an error from StarPU */
  72. return STARPU_TEST_SKIPPED;
  73. }
  74. else
  75. {
  76. FPRINTF(stderr, "VALUES: %d %f\n", x, f);
  77. ret = !(x == 12 && f == 24.0);
  78. return ret;
  79. }
  80. }