memalloc.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2008-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. #ifndef __MEMALLOC_H__
  17. #define __MEMALLOC_H__
  18. /** @file */
  19. #include <starpu.h>
  20. #include <common/config.h>
  21. #include <common/list.h>
  22. #include <datawizard/interfaces/data_interface.h>
  23. #include <datawizard/coherency.h>
  24. #include <datawizard/copy_driver.h>
  25. #include <datawizard/data_request.h>
  26. struct _starpu_data_replicate;
  27. /** While associated with a handle, the content is protected by the handle lock, except a few fields
  28. */
  29. LIST_TYPE(_starpu_mem_chunk,
  30. /** protected by the mc_lock */
  31. starpu_data_handle_t data;
  32. uint32_t footprint;
  33. /*
  34. * When re-using a memchunk, the footprint of the data is not
  35. * sufficient to determine whether two pieces of data have the same
  36. * layout (there could be collision in the hash function ...) so we
  37. * still keep a copy of the actual layout (ie. the data interface) to
  38. * stay on the safe side while the memchunk is detached from an actual
  39. * data.
  40. */
  41. struct starpu_data_interface_ops *ops;
  42. void *chunk_interface;
  43. size_t size_interface;
  44. /** Whether StarPU automatically allocated this memory, or the application did */
  45. unsigned automatically_allocated:1;
  46. /** A buffer that is used for SCRATCH or reduction cannnot be used with
  47. * filters. */
  48. unsigned relaxed_coherency:2;
  49. /** Whether this is the home chunk, or there is no home chunk (and it is thus always clean) */
  50. unsigned home:1;
  51. /** Whether the memchunk is in the clean part of the mc_list */
  52. unsigned clean:1;
  53. /** Was this chunk used since it got allocated?
  54. FIXME: probably useless now with nb_tasks_prefetch */
  55. unsigned diduse:1;
  56. /** Was this chunk marked as "won't use"? */
  57. unsigned wontuse:1;
  58. /** The number of prefetches that we made for this mc for various tasks
  59. * This is also the number of tasks that we will wait to see use this mc before
  60. * we attempt to evict it.
  61. */
  62. unsigned nb_tasks_prefetch;
  63. /** the size of the data is only set when calling _starpu_request_mem_chunk_removal(),
  64. * it is needed to estimate how much memory is in mc_cache, and by
  65. * free_memory_on_node() which is called when the handle is no longer
  66. * valid.
  67. * It should not be used otherwise.
  68. */
  69. size_t size;
  70. struct _starpu_data_replicate *replicate;
  71. /** This is set when one keeps a pointer to this mc obtained from the
  72. * mc_list without mc_lock held. We need to clear the pointer if we
  73. * remove this entry from the mc_list, so we know we have to restart
  74. * from zero. This is protected by the corresponding mc_lock. */
  75. struct _starpu_mem_chunk **remove_notify;
  76. )
  77. void _starpu_init_mem_chunk_lists(void);
  78. void _starpu_deinit_mem_chunk_lists(void);
  79. void _starpu_mem_chunk_init_last(void);
  80. void _starpu_request_mem_chunk_removal(starpu_data_handle_t handle, struct _starpu_data_replicate *replicate, unsigned node, size_t size);
  81. int _starpu_allocate_memory_on_node(starpu_data_handle_t handle, struct _starpu_data_replicate *replicate, enum _starpu_is_prefetch is_prefetch);
  82. size_t _starpu_free_all_automatically_allocated_buffers(unsigned node);
  83. void _starpu_memchunk_recently_used(struct _starpu_mem_chunk *mc, unsigned node);
  84. void _starpu_memchunk_wont_use(struct _starpu_mem_chunk *m, unsigned nodec);
  85. void _starpu_memchunk_dirty(struct _starpu_mem_chunk *mc, unsigned node);
  86. void _starpu_display_memory_stats_by_node(int node);
  87. size_t _starpu_memory_reclaim_generic(unsigned node, unsigned force, size_t reclaim);
  88. int _starpu_is_reclaiming(unsigned node);
  89. void _starpu_mem_chunk_disk_register(unsigned disk_memnode);
  90. #endif