test_vector_interface.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. int n = 16;
  41. int *vector;
  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. vector = malloc(n * sizeof(*vector));
  50. if (!vector)
  51. return NULL;
  52. for (i = 0; i < n; i++)
  53. vector[i] = i;
  54. /* Registering data */
  55. vector_handle = malloc(sizeof(*vector_handle));
  56. if (!vector_handle)
  57. return NULL;
  58. starpu_vector_data_register(vector_handle,
  59. 0,
  60. (uintptr_t)vector,
  61. n,
  62. sizeof(int));
  63. return vector_handle;
  64. }
  65. static void test_vector_cpu_func(void *buffers[], void *args)
  66. {
  67. unsigned n = STARPU_VECTOR_GET_NX(buffers[0]);
  68. int *val = (int *) STARPU_VECTOR_GET_PTR(buffers[0]);
  69. int factor = *(int*)args;
  70. unsigned int i;
  71. for (i = 0; i < n; i++) {
  72. if (val[i] != i*factor) {
  73. fprintf(stderr, "HI %d => %d\n", i, val[i]);
  74. vector_config.copy_failed = 1;
  75. return;
  76. }
  77. val[i] = -val[i];
  78. }
  79. }