copy_interfaces.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  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, STARPU_MAIN_RAM);
  32. new_interface = starpu_data_get_interface_on_node(new_handle, STARPU_MAIN_RAM);
  33. if (new_handle->ops->compare(old_interface, new_interface) == 0)
  34. {
  35. FPRINTF(stderr, "Error when copying %s data\n", header);
  36. ret = 1;
  37. }
  38. starpu_data_unregister(handle);
  39. starpu_data_unregister(new_handle);
  40. return ret;
  41. }
  42. int main(int argc, char **argv)
  43. {
  44. int ret;
  45. starpu_data_handle_t handle;
  46. ret = starpu_initialize(NULL, &argc, &argv);
  47. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  48. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  49. {
  50. int x=42;
  51. starpu_variable_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)&x, sizeof(x));
  52. ret = check_copy(handle, "variable");
  53. }
  54. if (ret == 0)
  55. {
  56. int xx[] = {12, 23, 45};
  57. starpu_vector_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)xx, 3, sizeof(xx[0]));
  58. ret = check_copy(handle, "vector");
  59. }
  60. if (ret == 0)
  61. {
  62. int NX=3;
  63. int NY=2;
  64. int matrix[NX][NY];
  65. starpu_matrix_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)matrix, NX, NX, NY, sizeof(matrix[0][0]));
  66. ret = check_copy(handle, "matrix");
  67. }
  68. if (ret == 0)
  69. {
  70. int NX=3;
  71. int NY=2;
  72. int NZ=4;
  73. int block[NX*NY*NZ];
  74. starpu_block_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)block, NX, NX*NY, NX, NY, NZ, sizeof(block[0]));
  75. ret = check_copy(handle, "block");
  76. }
  77. if (ret == 0)
  78. {
  79. int NX=3;
  80. int NY=2;
  81. int NZ=4;
  82. int NT=3;
  83. int tensor[NX*NY*NZ*NT];
  84. starpu_tensor_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)tensor, NX, NX*NY, NX*NY*NZ, NX, NY, NZ, NT, sizeof(tensor[0]));
  85. ret = check_copy(handle, "tensor");
  86. }
  87. if (ret == 0)
  88. {
  89. uint32_t nnz = 2;
  90. unsigned nrow = 5;
  91. float nzvalA[nnz];
  92. uint32_t colind[nnz];
  93. uint32_t rowptr[nrow+1];
  94. starpu_csr_data_register(&handle, STARPU_MAIN_RAM, nnz, nrow, (uintptr_t)nzvalA, colind, rowptr, 0, sizeof(float));
  95. ret = check_copy(handle, "csr");
  96. }
  97. starpu_shutdown();
  98. return ret;
  99. }