deps.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2017-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. #define N 10
  19. #define LOOPS 4
  20. void null_cpu_func(void *buffers[], void *arg)
  21. {
  22. (void)arg;
  23. (void)buffers;
  24. }
  25. void prod_cpu_func(void *buffers[], void *arg)
  26. {
  27. int *data = (int *)STARPU_VECTOR_GET_PTR(buffers[0]);
  28. int n = STARPU_VECTOR_GET_NX(buffers[0]);
  29. int i;
  30. int factor;
  31. starpu_codelet_unpack_args(arg, &factor);
  32. FPRINTF(stderr, "Multiplying by %d\n", factor);
  33. for(i=0 ; i<n ; i++) data[i] *= factor;
  34. }
  35. static struct starpu_codelet cl_null =
  36. {
  37. .cpu_funcs = {null_cpu_func},
  38. .cpu_funcs_name = {"null_cpu_func"},
  39. .model = &starpu_perfmodel_nop,
  40. .name = "null",
  41. };
  42. static struct starpu_codelet cl_prod =
  43. {
  44. .cpu_funcs = {prod_cpu_func},
  45. .cpu_funcs_name = {"prod_cpu_func"},
  46. .nbuffers = 1,
  47. .modes = {STARPU_RW},
  48. .flags = STARPU_CODELET_SIMGRID_EXECUTE,
  49. .model = &starpu_perfmodel_nop,
  50. .name = "prod",
  51. };
  52. int main(int argc, char **argv)
  53. {
  54. int i, j, ret;
  55. int data[N];
  56. int data2[N];
  57. int factor[LOOPS];
  58. starpu_data_handle_t data_handle;
  59. ret = starpu_initialize(NULL, &argc, &argv);
  60. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  61. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  62. for(i=0 ; i<N ; i++) data[i] = 12;
  63. for(i=0 ; i<N ; i++) data2[i] = 12;
  64. starpu_vector_data_register(&data_handle, STARPU_MAIN_RAM, (uintptr_t) data, N, sizeof(int));
  65. struct starpu_task *motherTask = starpu_task_build(&cl_null, STARPU_NAME, "motherTask", 0);
  66. for (i = 0; i < LOOPS; i++)
  67. {
  68. factor[i] = i+1;
  69. for(j=0 ; j<N ; j++) data2[j] *= factor[i];
  70. ret = starpu_task_insert(&cl_prod,
  71. STARPU_RW, data_handle,
  72. STARPU_VALUE, &factor[i], sizeof(factor[i]),
  73. STARPU_TASK_DEPS_ARRAY, 1, &motherTask,
  74. 0);
  75. if (ret == -ENODEV) goto enodev;
  76. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  77. }
  78. ret = starpu_task_submit(motherTask);
  79. if (ret == -ENODEV) goto enodev;
  80. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  81. starpu_task_wait_for_all();
  82. starpu_data_unregister(data_handle);
  83. for(i=0 ; i<N ; i++)
  84. {
  85. FPRINTF(stderr, "data[%d] = %d ==? %d \n", i, data[i], data2[i]);
  86. STARPU_ASSERT_MSG(data[i] == data2[i], "Incorrect computation\n");
  87. }
  88. starpu_shutdown();
  89. return EXIT_SUCCESS;
  90. enodev:
  91. fprintf(stderr, "WARNING: No one can execute this task\n");
  92. /* yes, we do not perform the computation but we did detect that no one
  93. * could perform the kernel, so this is not an error from StarPU */
  94. starpu_shutdown();
  95. return STARPU_TEST_SKIPPED;
  96. }