insert_task_array.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  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. #include "../helper.h"
  18. /*
  19. * Test STARPU_DATA_ARRAY
  20. */
  21. void func_cpu(void *descr[], void *_args)
  22. {
  23. int *x0 = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  24. float *x1 = (float *)STARPU_VARIABLE_GET_PTR(descr[1]);
  25. int factor;
  26. starpu_codelet_unpack_args(_args, &factor);
  27. *x0 = *x0 * factor;
  28. *x1 = *x1 * (float)factor;
  29. }
  30. struct starpu_codelet mycodelet =
  31. {
  32. .modes = { STARPU_RW, STARPU_RW },
  33. .cpu_funcs = {func_cpu},
  34. .cpu_funcs_name = {"func_cpu"},
  35. .nbuffers = 2
  36. };
  37. int main(void)
  38. {
  39. int x; float f;
  40. int factor=12;
  41. int i, ret;
  42. starpu_data_handle_t data_handles[2];
  43. ret = starpu_init(NULL);
  44. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  45. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  46. x = 1;
  47. starpu_variable_data_register(&data_handles[0], STARPU_MAIN_RAM, (uintptr_t)&x, sizeof(x));
  48. f = 2.0;
  49. starpu_variable_data_register(&data_handles[1], STARPU_MAIN_RAM, (uintptr_t)&f, sizeof(f));
  50. ret = starpu_task_insert(&mycodelet,
  51. STARPU_DATA_ARRAY, data_handles, 2,
  52. STARPU_VALUE, &factor, sizeof(factor),
  53. STARPU_PRIORITY, 1,
  54. 0);
  55. if (ret == -ENODEV) goto enodev;
  56. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  57. ret = starpu_task_wait_for_all();
  58. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  59. enodev:
  60. for(i=0 ; i<2 ; i++)
  61. {
  62. starpu_data_unregister(data_handles[i]);
  63. }
  64. starpu_shutdown();
  65. if (ret == -ENODEV)
  66. {
  67. fprintf(stderr, "WARNING: No one can execute this task\n");
  68. /* yes, we do not perform the computation but we did detect that no one
  69. * could perform the kernel, so this is not an error from StarPU */
  70. return STARPU_TEST_SKIPPED;
  71. }
  72. else
  73. {
  74. FPRINTF(stderr, "VALUES: %d %f\n", x, f);
  75. ret = !(x == 12 && f == 24.0);
  76. return ret;
  77. }
  78. }