memstats.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010, 2012 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. #include <datawizard/memstats.h>
  19. #include <common/config.h>
  20. #include <datawizard/coherency.h>
  21. void _starpu_memory_stats_init(starpu_data_handle_t handle STARPU_ATTRIBUTE_UNUSED)
  22. {
  23. #ifdef STARPU_MEMORY_STATS
  24. handle->memory_stats = calloc(1, sizeof(struct _starpu_memory_stats));
  25. #endif
  26. }
  27. void _starpu_memory_stats_init_per_node(starpu_data_handle_t handle STARPU_ATTRIBUTE_UNUSED, unsigned node STARPU_ATTRIBUTE_UNUSED)
  28. {
  29. #ifdef STARPU_MEMORY_STATS
  30. /* Stats initilization */
  31. handle->memory_stats->direct_access[node]=0;
  32. handle->memory_stats->loaded_shared[node]=0;
  33. handle->memory_stats->shared_to_owner[node]=0;
  34. handle->memory_stats->loaded_owner[node]=0;
  35. handle->memory_stats->invalidated[node]=0;
  36. #endif
  37. }
  38. void _starpu_memory_stats_free(starpu_data_handle_t handle STARPU_ATTRIBUTE_UNUSED)
  39. {
  40. #ifdef STARPU_MEMORY_STATS
  41. free(handle->memory_stats);
  42. #endif
  43. }
  44. #ifdef STARPU_MEMORY_STATS
  45. void _starpu_memory_display_handle_stats(starpu_data_handle_t handle)
  46. {
  47. unsigned node;
  48. fprintf(stderr, "#-----\n");
  49. fprintf(stderr, "Data : %p\n", handle);
  50. fprintf(stderr, "Size : %d\n", (int)handle->ops->get_size(handle));
  51. fprintf(stderr, "\n");
  52. fprintf(stderr, "#--\n");
  53. fprintf(stderr, "Data access stats\n");
  54. fprintf(stderr, "/!\\ Work Underway\n");
  55. for (node = 0; node < STARPU_MAXNODES; node++)
  56. {
  57. if (handle->memory_stats->direct_access[node]+handle->memory_stats->loaded_shared[node]
  58. +handle->memory_stats->invalidated[node]+handle->memory_stats->loaded_owner[node])
  59. {
  60. fprintf(stderr, "Node #%d\n", node);
  61. fprintf(stderr, "\tDirect access : %d\n", handle->memory_stats->direct_access[node]);
  62. /* XXX Not Working yet. */
  63. if (handle->memory_stats->shared_to_owner[node])
  64. fprintf(stderr, "\t\tShared to Owner : %d\n", handle->memory_stats->shared_to_owner[node]);
  65. fprintf(stderr, "\tLoaded (Owner) : %d\n", handle->memory_stats->loaded_owner[node]);
  66. fprintf(stderr, "\tLoaded (Shared) : %d\n", handle->memory_stats->loaded_shared[node]);
  67. fprintf(stderr, "\tInvalidated (was Owner) : %d\n\n", handle->memory_stats->invalidated[node]);
  68. }
  69. }
  70. }
  71. void _starpu_memory_handle_stats_cache_hit(starpu_data_handle_t handle, unsigned node)
  72. {
  73. handle->memory_stats->direct_access[node]++;
  74. }
  75. void _starpu_memory_handle_stats_loaded_shared(starpu_data_handle_t handle, unsigned node)
  76. {
  77. handle->memory_stats->loaded_shared[node]++;
  78. }
  79. void _starpu_memory_handle_stats_loaded_owner(starpu_data_handle_t handle, unsigned node)
  80. {
  81. handle->memory_stats->loaded_owner[node]++;
  82. }
  83. void _starpu_memory_handle_stats_shared_to_owner(starpu_data_handle_t handle, unsigned node)
  84. {
  85. handle->memory_stats->shared_to_owner[node]++;
  86. }
  87. void _starpu_memory_handle_stats_invalidated(starpu_data_handle_t handle, unsigned node)
  88. {
  89. handle->memory_stats->invalidated[node]++;
  90. }
  91. #endif