copy_interfaces.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012,2013 Inria
  4. * Copyright (C) 2012,2015,2017 CNRS
  5. * Copyright (C) 2013,2016,2017 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu.h>
  19. #include "../../helper.h"
  20. #include <datawizard/coherency.h>
  21. static int check_copy(starpu_data_handle_t handle, char *header)
  22. {
  23. void *old_interface, *new_interface;
  24. starpu_data_handle_t new_handle;
  25. int ret=0;
  26. starpu_data_register_same(&new_handle, handle);
  27. if (!getenv("STARPU_SSILENT") && new_handle->ops->display)
  28. {
  29. fprintf(stderr, "%s: ", header);
  30. new_handle->ops->display(new_handle, stderr);
  31. fprintf(stderr, "\n");
  32. }
  33. old_interface = starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  34. new_interface = starpu_data_get_interface_on_node(new_handle, STARPU_MAIN_RAM);
  35. if (new_handle->ops->compare(old_interface, new_interface) == 0)
  36. {
  37. FPRINTF(stderr, "Error when copying %s data\n", header);
  38. ret = 1;
  39. }
  40. starpu_data_unregister(handle);
  41. starpu_data_unregister(new_handle);
  42. return ret;
  43. }
  44. int main(int argc, char **argv)
  45. {
  46. int ret;
  47. starpu_data_handle_t handle;
  48. ret = starpu_initialize(NULL, &argc, &argv);
  49. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  50. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  51. {
  52. int x=42;
  53. starpu_variable_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)&x, sizeof(x));
  54. ret = check_copy(handle, "variable");
  55. }
  56. if (ret == 0)
  57. {
  58. int xx[] = {12, 23, 45};
  59. starpu_vector_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)xx, 3, sizeof(xx[0]));
  60. ret = check_copy(handle, "vector");
  61. }
  62. if (ret == 0)
  63. {
  64. int NX=3;
  65. int NY=2;
  66. int matrix[NX][NY];
  67. starpu_matrix_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)matrix, NX, NX, NY, sizeof(matrix[0][0]));
  68. ret = check_copy(handle, "matrix");
  69. }
  70. if (ret == 0)
  71. {
  72. int NX=3;
  73. int NY=2;
  74. int NZ=4;
  75. int block[NX*NY*NZ];
  76. starpu_block_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)block, NX, NX*NY, NX, NY, NZ, sizeof(block[0]));
  77. ret = check_copy(handle, "block");
  78. }
  79. if (ret == 0)
  80. {
  81. uint32_t nnz = 2;
  82. unsigned nrow = 5;
  83. float nzvalA[nnz];
  84. uint32_t colind[nnz];
  85. uint32_t rowptr[nrow+1];
  86. starpu_csr_data_register(&handle, STARPU_MAIN_RAM, nnz, nrow, (uintptr_t)nzvalA, colind, rowptr, 0, sizeof(float));
  87. ret = check_copy(handle, "csr");
  88. }
  89. starpu_shutdown();
  90. return ret;
  91. }