variable_interface.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 Institut National de Recherche en Informatique et Automatique
  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 "../test_interfaces.h"
  18. static int variable;
  19. static starpu_data_handle_t variable_handle;
  20. /* Codelets */
  21. #ifdef STARPU_USE_CPU
  22. static void test_variable_cpu_func(void *buffers[], void *args);
  23. #endif
  24. #ifdef STARPU_USE_CUDA
  25. static void test_variable_cuda_func(void *buffers[], void *args);
  26. #endif
  27. #ifdef STARPU_USE_OPENCL
  28. static void test_variable_opencl_func(void *buffers[], void *args);
  29. #endif
  30. struct test_config variable_config =
  31. {
  32. #ifdef STARPU_USE_CPU
  33. .cpu_func = test_variable_cpu_func,
  34. #endif
  35. #ifdef STARPU_USE_CUDA
  36. .cuda_func = test_variable_cuda_func,
  37. #endif
  38. #ifdef STARPU_USE_OPENCL
  39. .opencl_func = test_variable_opencl_func,
  40. #endif
  41. .handle = &variable_handle,
  42. .copy_failed = 0,
  43. .name = "variable_interface"
  44. };
  45. static void
  46. test_variable_cpu_func(void *buffers[], void *args)
  47. {
  48. int *val;
  49. int factor;
  50. val = (int *) STARPU_VARIABLE_GET_PTR(buffers[0]);
  51. factor = *(int *)args;
  52. if (*val != 42 * factor)
  53. variable_config.copy_failed = 1;
  54. else
  55. *val *= -1;
  56. }
  57. static
  58. void register_data(void)
  59. {
  60. variable = 42;
  61. starpu_variable_data_register(&variable_handle, 0,
  62. (uintptr_t) &variable, sizeof(variable));
  63. }
  64. static
  65. void unregister_data(void)
  66. {
  67. starpu_data_unregister(variable_handle);
  68. }
  69. int
  70. main(void)
  71. {
  72. data_interface_test_summary *summary;
  73. struct starpu_conf conf =
  74. {
  75. .ncpus = -1,
  76. .ncuda = 2,
  77. .nopencl = 1
  78. };
  79. starpu_init(&conf);
  80. register_data();
  81. summary = run_tests(&variable_config);
  82. if (!summary)
  83. exit(EXIT_FAILURE);
  84. unregister_data();
  85. starpu_shutdown();
  86. data_interface_test_summary_print(stderr, summary);
  87. return data_interface_test_summary_success(summary);
  88. }