copy_interfaces.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012 Centre National de la Recherche Scientifique
  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 "../../helper.h"
  18. #include <datawizard/coherency.h>
  19. static int check_copy(starpu_data_handle_t handle, char *header)
  20. {
  21. void *old_interface, *new_interface;
  22. starpu_data_handle_t new_handle;
  23. int ret=0;
  24. starpu_data_register_same(&new_handle, handle);
  25. if (!getenv("STARPU_SSILENT") && new_handle->ops->display)
  26. {
  27. fprintf(stderr, "%s: ", header);
  28. new_handle->ops->display(new_handle, stderr);
  29. fprintf(stderr, "\n");
  30. }
  31. old_interface = starpu_data_get_interface_on_node(handle, 0);
  32. new_interface = starpu_data_get_interface_on_node(new_handle, 0);
  33. if (new_handle->ops->compare(old_interface, new_interface) == 0)
  34. {
  35. FPRINTF(stderr, "Error when copying %s data\n", header);
  36. assert(0);
  37. ret = 1;
  38. }
  39. starpu_data_unregister(handle);
  40. starpu_data_unregister(new_handle);
  41. return ret;
  42. }
  43. int main(int argc, char **argv)
  44. {
  45. int ret;
  46. starpu_data_handle_t handle;
  47. ret = starpu_init(NULL);
  48. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  49. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  50. {
  51. int x=42;
  52. starpu_variable_data_register(&handle, 0, (uintptr_t)&x, sizeof(x));
  53. ret = check_copy(handle, "variable");
  54. }
  55. if (ret == 0)
  56. {
  57. int xx[] = {12, 23, 45};
  58. starpu_vector_data_register(&handle, 0, (uintptr_t)xx, 3, sizeof(xx[0]));
  59. ret = check_copy(handle, "vector");
  60. }
  61. if (ret == 0)
  62. {
  63. int NX=3;
  64. int NY=2;
  65. int matrix[NX][NY];
  66. starpu_matrix_data_register(&handle, 0, (uintptr_t)matrix, NX, NX, NY, sizeof(matrix[0]));
  67. ret = check_copy(handle, "matrix");
  68. }
  69. if (ret == 0)
  70. {
  71. int NX=3;
  72. int NY=2;
  73. int NZ=4;
  74. int block[NX*NY*NZ];
  75. starpu_block_data_register(&handle, 0, (uintptr_t)block, NX, NX*NY, NX, NY, NZ, sizeof(block[0]));
  76. ret = check_copy(handle, "block");
  77. }
  78. if (ret == 0)
  79. {
  80. uint32_t nnz = 2;
  81. unsigned nrow = 5;
  82. float nzvalA[20];
  83. uint32_t colind[1];
  84. uint32_t rowptr[2];
  85. starpu_csr_data_register(&handle, 0, nnz, nrow, (uintptr_t)nzvalA, colind, rowptr, 0, sizeof(float));
  86. ret = check_copy(handle, "csr");
  87. }
  88. starpu_shutdown();
  89. return ret;
  90. }