pack.c 2.7 KB

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