data_register.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 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/interfaces/data_interface.h>
  19. struct my_interface
  20. {
  21. enum starpu_data_interface_id id;
  22. /* Just a integer */
  23. int x;
  24. };
  25. static struct starpu_data_interface_ops starpu_interface_my_ops;
  26. static void register_my(starpu_data_handle_t handle, unsigned home_node, void *data_interface)
  27. {
  28. struct my_interface *my_interface = data_interface;
  29. unsigned node;
  30. for (node = 0; node < STARPU_MAXNODES; node++)
  31. {
  32. struct my_interface *local_interface = starpu_data_get_interface_on_node(handle, node);
  33. local_interface->x = my_interface->x;
  34. local_interface->id = my_interface->id;
  35. }
  36. }
  37. static size_t my_get_size(starpu_data_handle_t handle)
  38. {
  39. struct my_interface *interface = starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  40. return interface->x;
  41. }
  42. static uint32_t my_footprint(starpu_data_handle_t handle)
  43. {
  44. return starpu_hash_crc32c_be(my_get_size(handle), 0);
  45. }
  46. static struct starpu_data_interface_ops starpu_interface_my_ops =
  47. {
  48. .register_data_handle = register_my,
  49. .allocate_data_on_node = NULL,
  50. .free_data_on_node = NULL,
  51. .copy_methods = NULL,
  52. .get_size = my_get_size,
  53. .get_max_size = NULL,
  54. .footprint = my_footprint,
  55. .compare = NULL,
  56. .interfaceid = STARPU_UNKNOWN_INTERFACE_ID,
  57. .interface_size = sizeof(struct my_interface),
  58. .display = NULL,
  59. .pack_data = NULL,
  60. .unpack_data = NULL,
  61. .describe = NULL,
  62. };
  63. #define N 42
  64. int main(void)
  65. {
  66. int ret;
  67. int x;
  68. starpu_data_handle_t handles[N];
  69. ret = starpu_init(NULL);
  70. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  71. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  72. for (x = 0; x < N; x++)
  73. {
  74. starpu_interface_my_ops.interfaceid = starpu_data_interface_get_next_id();
  75. struct my_interface interface =
  76. {
  77. .id = starpu_interface_my_ops.interfaceid,
  78. };
  79. starpu_data_register(&handles[x], -1, &interface, &starpu_interface_my_ops);
  80. STARPU_ASSERT(_starpu_data_interface_get_ops(interface.id) == &starpu_interface_my_ops);
  81. }
  82. for (x = 0; x < N; x++)
  83. starpu_data_unregister(handles[x]);
  84. starpu_shutdown();
  85. return EXIT_SUCCESS;
  86. }