memstats.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-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 <datawizard/memstats.h>
  18. #include <common/config.h>
  19. #include <datawizard/coherency.h>
  20. void _starpu_memory_stats_init(starpu_data_handle_t handle STARPU_ATTRIBUTE_UNUSED)
  21. {
  22. #ifdef STARPU_MEMORY_STATS
  23. _STARPU_CALLOC(handle->memory_stats, 1, sizeof(struct _starpu_memory_stats));
  24. #endif
  25. }
  26. void _starpu_memory_stats_init_per_node(starpu_data_handle_t handle STARPU_ATTRIBUTE_UNUSED, unsigned node STARPU_ATTRIBUTE_UNUSED)
  27. {
  28. #ifdef STARPU_MEMORY_STATS
  29. /* Stats initilization */
  30. //handle->memory_stats->direct_access[node]=0;
  31. //handle->memory_stats->loaded_shared[node]=0;
  32. //handle->memory_stats->shared_to_owner[node]=0;
  33. //handle->memory_stats->loaded_owner[node]=0;
  34. //handle->memory_stats->invalidated[node]=0;
  35. #endif
  36. }
  37. void _starpu_memory_stats_free(starpu_data_handle_t handle STARPU_ATTRIBUTE_UNUSED)
  38. {
  39. #ifdef STARPU_MEMORY_STATS
  40. free(handle->memory_stats);
  41. #endif
  42. }
  43. #ifdef STARPU_MEMORY_STATS
  44. void _starpu_memory_display_handle_stats(FILE *stream, starpu_data_handle_t handle)
  45. {
  46. unsigned node;
  47. fprintf(stream, "#-----\n");
  48. fprintf(stream, "Data : %p\n", handle);
  49. fprintf(stream, "Size : %d\n", (int)handle->ops->get_size(handle));
  50. fprintf(stream, "\n");
  51. fprintf(stream, "#--\n");
  52. fprintf(stream, "Data access stats\n");
  53. fprintf(stream, "/!\\ Work Underway\n");
  54. for (node = 0; node < STARPU_MAXNODES; node++)
  55. {
  56. if (handle->memory_stats->direct_access[node]+handle->memory_stats->loaded_shared[node]
  57. +handle->memory_stats->invalidated[node]+handle->memory_stats->loaded_owner[node])
  58. {
  59. fprintf(stream, "Node #%u\n", node);
  60. fprintf(stream, "\tDirect access : %u\n", handle->memory_stats->direct_access[node]);
  61. /* XXX Not Working yet. */
  62. if (handle->memory_stats->shared_to_owner[node])
  63. fprintf(stream, "\t\tShared to Owner : %u\n", handle->memory_stats->shared_to_owner[node]);
  64. fprintf(stream, "\tLoaded (Owner) : %u\n", handle->memory_stats->loaded_owner[node]);
  65. fprintf(stream, "\tLoaded (Shared) : %u\n", handle->memory_stats->loaded_shared[node]);
  66. fprintf(stream, "\tInvalidated (was Owner) : %u\n\n", handle->memory_stats->invalidated[node]);
  67. }
  68. }
  69. }
  70. void _starpu_memory_handle_stats_cache_hit(starpu_data_handle_t handle, unsigned node)
  71. {
  72. handle->memory_stats->direct_access[node]++;
  73. }
  74. void _starpu_memory_handle_stats_loaded_shared(starpu_data_handle_t handle, unsigned node)
  75. {
  76. handle->memory_stats->loaded_shared[node]++;
  77. }
  78. void _starpu_memory_handle_stats_loaded_owner(starpu_data_handle_t handle, unsigned node)
  79. {
  80. handle->memory_stats->loaded_owner[node]++;
  81. }
  82. void _starpu_memory_handle_stats_shared_to_owner(starpu_data_handle_t handle, unsigned node)
  83. {
  84. handle->memory_stats->shared_to_owner[node]++;
  85. }
  86. void _starpu_memory_handle_stats_invalidated(starpu_data_handle_t handle, unsigned node)
  87. {
  88. handle->memory_stats->invalidated[node]++;
  89. }
  90. #endif