test_vector_interface.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. /* Prototypes */
  19. static starpu_data_handle register_data(void);
  20. static void test_vector_cpu_func(void *buffers[], void *args);
  21. #ifdef STARPU_USE_CUDA
  22. extern void test_vector_cuda_func(void *buffers[], void *_args);
  23. #endif
  24. #ifdef STARPU_USE_OPENCL
  25. extern void test_vector_opencl_func(void *buffers[], void *args);
  26. #endif
  27. static starpu_data_handle vector_handle;
  28. struct test_config vector_config = {
  29. .cpu_func = test_vector_cpu_func,
  30. #ifdef STARPU_USE_CUDA
  31. .cuda_func = test_vector_cuda_func,
  32. #endif
  33. #ifdef STARPU_USE_OPENCL
  34. .opencl_func = test_vector_opencl_func,
  35. #endif
  36. .register_func = register_data,
  37. .copy_failed = 0,
  38. .name = "vector_interface"
  39. };
  40. #define VECTOR_SIZE 123
  41. static int vector[VECTOR_SIZE];
  42. static starpu_data_handle
  43. register_data(void)
  44. {
  45. if (vector_handle)
  46. return vector_handle;
  47. /* Initializing data */
  48. int i;
  49. for (i = 0; i < VECTOR_SIZE; i++)
  50. vector[i] = i;
  51. /* Registering data */
  52. starpu_vector_data_register(&vector_handle,
  53. 0,
  54. (uintptr_t)vector,
  55. VECTOR_SIZE,
  56. sizeof(int));
  57. return vector_handle;
  58. }
  59. static void test_vector_cpu_func(void *buffers[], void *args)
  60. {
  61. unsigned n = STARPU_VECTOR_GET_NX(buffers[0]);
  62. int *val = (int *) STARPU_VECTOR_GET_PTR(buffers[0]);
  63. int factor = *(int*)args;
  64. unsigned int i;
  65. for (i = 0; i < n; i++) {
  66. if (val[i] != i*factor) {
  67. fprintf(stderr, "HI %d => %d\n", i, val[i]);
  68. vector_config.copy_failed = 1;
  69. return;
  70. }
  71. val[i] = -val[i];
  72. }
  73. }