insert_task_array.c 2.4 KB

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