data_register.c 2.8 KB

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