insert_task_value.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2015 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 passing values to tasks in different ways
  21. */
  22. #define IFACTOR 42
  23. #define FFACTOR 12.0
  24. void func_cpu(void *descr[], void *_args)
  25. {
  26. int ifactor[2048];
  27. float ffactor;
  28. starpu_codelet_unpack_args(_args, ifactor, &ffactor);
  29. FPRINTF(stderr, "Values %d - %3.2f\n", ifactor[0], ffactor);
  30. assert(ifactor[0] == IFACTOR && ffactor == FFACTOR);
  31. }
  32. void func_cpu2(void *descr[], void *_args)
  33. {
  34. int ifactor[2048];
  35. float ffactor;
  36. starpu_codelet_unpack_args(_args, &ffactor, ifactor);
  37. FPRINTF(stderr, "Values %d - %3.2f\n", ifactor[0], ffactor);
  38. assert(ifactor[0] == IFACTOR && ffactor == FFACTOR);
  39. }
  40. struct starpu_codelet mycodelet =
  41. {
  42. .cpu_funcs = {func_cpu},
  43. .cpu_funcs_name = {"func_cpu"},
  44. };
  45. struct starpu_codelet mycodelet2 =
  46. {
  47. .cpu_funcs = {func_cpu2},
  48. .cpu_funcs_name = {"func_cpu2"},
  49. };
  50. int main(int argc, char **argv)
  51. {
  52. int ret;
  53. int ifactor[2048];
  54. float ffactor=FFACTOR;
  55. struct starpu_task *task;
  56. ret = starpu_init(NULL);
  57. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  58. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  59. ifactor[0] = IFACTOR;
  60. ret = starpu_task_insert(&mycodelet,
  61. STARPU_VALUE, ifactor, 2048*sizeof(ifactor[0]),
  62. STARPU_VALUE, &ffactor, sizeof(ffactor),
  63. 0);
  64. if (ret == -ENODEV) goto enodev;
  65. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  66. ret = starpu_task_insert(&mycodelet2,
  67. STARPU_VALUE, &ffactor, sizeof(ffactor),
  68. STARPU_VALUE, ifactor, 2048*sizeof(ifactor[0]),
  69. 0);
  70. if (ret == -ENODEV) goto enodev;
  71. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  72. task = starpu_task_create();
  73. task->synchronous = 1;
  74. task->cl = &mycodelet;
  75. task->cl_arg_free = 1;
  76. starpu_codelet_pack_args(&task->cl_arg, &task->cl_arg_size,
  77. STARPU_VALUE, ifactor, 2048*sizeof(ifactor[0]),
  78. STARPU_VALUE, &ffactor, sizeof(ffactor),
  79. 0);
  80. ret = starpu_task_submit(task);
  81. if (ret != -ENODEV)
  82. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  83. task = starpu_task_create();
  84. task->synchronous = 1;
  85. task->cl = &mycodelet2;
  86. task->cl_arg_free = 1;
  87. starpu_codelet_pack_args(&task->cl_arg, &task->cl_arg_size,
  88. STARPU_VALUE, &ffactor, sizeof(ffactor),
  89. STARPU_VALUE, ifactor, 2048*sizeof(ifactor[0]),
  90. 0);
  91. ret = starpu_task_submit(task);
  92. if (ret != -ENODEV)
  93. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  94. starpu_shutdown();
  95. return 0;
  96. enodev:
  97. starpu_shutdown();
  98. fprintf(stderr, "WARNING: No one can execute this task\n");
  99. /* yes, we do not perform the computation but we did detect that no one
  100. * could perform the kernel, so this is not an error from StarPU */
  101. return STARPU_TEST_SKIPPED;
  102. }