pack.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2014-2018 CNRS
  4. * Copyright (C) 2016 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. /*
  20. * Test starpu_codelet_pack_args and starpu_codelet_unpack_args
  21. */
  22. void func_cpu(void *descr[], void *_args)
  23. {
  24. int factor;
  25. char c;
  26. int x;
  27. (void)descr;
  28. starpu_codelet_unpack_args(_args, &factor, &c, &x);
  29. FPRINTF(stderr, "[codelet] values: %d %c %d\n", factor, c, x);
  30. assert(factor == 12 && c == 'n' && x == 42);
  31. }
  32. struct starpu_codelet mycodelet =
  33. {
  34. .cpu_funcs = {func_cpu},
  35. .cpu_funcs_name = {"func_cpu"},
  36. .nbuffers = 0
  37. };
  38. int main(void)
  39. {
  40. int ret;
  41. int x=42;
  42. int factor=12;
  43. char c='n';
  44. struct starpu_task *task, *task2;
  45. ret = starpu_init(NULL);
  46. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  47. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  48. FPRINTF(stderr, "[init] values: %d %c %d\n", factor, c, x);
  49. task = starpu_task_create();
  50. task->synchronous = 1;
  51. task->cl = &mycodelet;
  52. task->cl_arg_free = 1;
  53. starpu_codelet_pack_args(&task->cl_arg, &task->cl_arg_size,
  54. STARPU_VALUE, &factor, sizeof(factor),
  55. STARPU_VALUE, &c, sizeof(c),
  56. STARPU_VALUE, &x, sizeof(x),
  57. 0);
  58. ret = starpu_task_submit(task);
  59. if (ret != -ENODEV)
  60. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  61. task2 = starpu_task_create();
  62. task2->synchronous = 1;
  63. task2->cl = &mycodelet;
  64. task2->cl_arg_free = 1;
  65. {
  66. struct starpu_codelet_pack_arg_data state;
  67. starpu_codelet_pack_arg_init(&state);
  68. starpu_codelet_pack_arg(&state, &factor, sizeof(factor));
  69. starpu_codelet_pack_arg(&state, &c, sizeof(c));
  70. starpu_codelet_pack_arg(&state, &x, sizeof(x));
  71. starpu_codelet_pack_arg_fini(&state, &task2->cl_arg, &task2->cl_arg_size);
  72. }
  73. ret = starpu_task_submit(task2);
  74. if (ret != -ENODEV)
  75. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  76. starpu_shutdown();
  77. if (ret == -ENODEV)
  78. {
  79. fprintf(stderr, "WARNING: No one can execute this task\n");
  80. /* yes, we do not perform the computation but we did detect that no one
  81. * could perform the kernel, so this is not an error from StarPU */
  82. return STARPU_TEST_SKIPPED;
  83. }
  84. else
  85. return 0;
  86. }