deps.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2017 CNRS
  4. * Copyright (C) 2017 Université de Bordeaux
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. #include "../helper.h"
  19. #define N 10
  20. #define LOOPS 4
  21. void null_cpu_func(void *buffers[], void *arg)
  22. {
  23. (void)arg;
  24. (void)buffers;
  25. }
  26. void prod_cpu_func(void *buffers[], void *arg)
  27. {
  28. int *data = (int *)STARPU_VECTOR_GET_PTR(buffers[0]);
  29. int n = STARPU_VECTOR_GET_NX(buffers[0]);
  30. int i;
  31. int factor;
  32. starpu_codelet_unpack_args(arg, &factor);
  33. FPRINTF(stderr, "Multiplying by %d\n", factor);
  34. for(i=0 ; i<n ; i++) data[i] *= factor;
  35. }
  36. static struct starpu_codelet cl_null =
  37. {
  38. .cpu_funcs = {null_cpu_func},
  39. .cpu_funcs_name = {"null_cpu_func"},
  40. .model = &starpu_perfmodel_nop,
  41. .name = "null",
  42. };
  43. static struct starpu_codelet cl_prod =
  44. {
  45. .cpu_funcs = {prod_cpu_func},
  46. .cpu_funcs_name = {"prod_cpu_func"},
  47. .nbuffers = 1,
  48. .modes = {STARPU_RW},
  49. .flags = STARPU_CODELET_SIMGRID_EXECUTE,
  50. .model = &starpu_perfmodel_nop,
  51. .name = "prod",
  52. };
  53. int main(int argc, char **argv)
  54. {
  55. int i, j, ret;
  56. int data[N];
  57. int data2[N];
  58. int factor[LOOPS];
  59. starpu_data_handle_t data_handle;
  60. ret = starpu_initialize(NULL, &argc, &argv);
  61. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  62. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  63. for(i=0 ; i<N ; i++) data[i] = 12;
  64. for(i=0 ; i<N ; i++) data2[i] = 12;
  65. starpu_vector_data_register(&data_handle, STARPU_MAIN_RAM, (uintptr_t) data, N, sizeof(int));
  66. struct starpu_task *motherTask = starpu_task_build(&cl_null, STARPU_NAME, "motherTask", 0);
  67. for (i = 0; i < LOOPS; i++)
  68. {
  69. factor[i] = i+1;
  70. for(j=0 ; j<N ; j++) data2[j] *= factor[i];
  71. ret = starpu_task_insert(&cl_prod,
  72. STARPU_RW, data_handle,
  73. STARPU_VALUE, &factor[i], sizeof(factor[i]),
  74. STARPU_TASK_DEPS_ARRAY, 1, &motherTask,
  75. 0);
  76. if (ret == -ENODEV) goto enodev;
  77. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  78. }
  79. ret = starpu_task_submit(motherTask);
  80. if (ret == -ENODEV) goto enodev;
  81. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  82. starpu_task_wait_for_all();
  83. starpu_data_unregister(data_handle);
  84. for(i=0 ; i<N ; i++)
  85. {
  86. FPRINTF(stderr, "data[%d] = %d ==? %d \n", i, data[i], data2[i]);
  87. STARPU_ASSERT_MSG(data[i] == data2[i], "Incorrect computation\n");
  88. }
  89. starpu_shutdown();
  90. return EXIT_SUCCESS;
  91. enodev:
  92. fprintf(stderr, "WARNING: No one can execute this task\n");
  93. /* yes, we do not perform the computation but we did detect that no one
  94. * could perform the kernel, so this is not an error from StarPU */
  95. starpu_shutdown();
  96. return STARPU_TEST_SKIPPED;
  97. }