pack.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2014-2017 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, "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;
  45. ret = starpu_init(NULL);
  46. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  47. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  48. FPRINTF(stderr, "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. starpu_shutdown();
  62. if (ret == -ENODEV)
  63. {
  64. fprintf(stderr, "WARNING: No one can execute this task\n");
  65. /* yes, we do not perform the computation but we did detect that no one
  66. * could perform the kernel, so this is not an error from StarPU */
  67. return STARPU_TEST_SKIPPED;
  68. }
  69. else
  70. return 0;
  71. }