data_register.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2020-2021 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 *my_interface = starpu_data_get_interface_on_node(handle, STARPU_MAIN_RAM);
  40. return my_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. .peek_data = NULL,
  61. .unpack_data = NULL,
  62. .describe = NULL,
  63. };
  64. #define N 42
  65. int main(void)
  66. {
  67. int ret;
  68. int x;
  69. starpu_data_handle_t handles[N];
  70. ret = starpu_init(NULL);
  71. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  72. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  73. for (x = 0; x < N; x++)
  74. {
  75. starpu_interface_my_ops.interfaceid = starpu_data_interface_get_next_id();
  76. struct my_interface my_interface =
  77. {
  78. .id = starpu_interface_my_ops.interfaceid,
  79. };
  80. starpu_data_register(&handles[x], -1, &my_interface, &starpu_interface_my_ops);
  81. STARPU_ASSERT(_starpu_data_interface_get_ops(my_interface.id) == &starpu_interface_my_ops);
  82. }
  83. for (x = 0; x < N; x++)
  84. starpu_data_unregister(handles[x]);
  85. starpu_shutdown();
  86. return EXIT_SUCCESS;
  87. }