memalloc.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. struct _starpu_data_replicate;
  26. /** While associated with a handle, the content is protected by the handle lock, except a few fields
  27. */
  28. LIST_TYPE(_starpu_mem_chunk,
  29. /** protected by the mc_lock */
  30. starpu_data_handle_t data;
  31. uint32_t footprint;
  32. /*
  33. * When re-using a memchunk, the footprint of the data is not
  34. * sufficient to determine whether two pieces of data have the same
  35. * layout (there could be collision in the hash function ...) so we
  36. * still keep a copy of the actual layout (ie. the data interface) to
  37. * stay on the safe side while the memchunk is detached from an actual
  38. * data.
  39. */
  40. struct starpu_data_interface_ops *ops;
  41. void *chunk_interface;
  42. size_t size_interface;
  43. /** Whether StarPU automatically allocated this memory, or the application did */
  44. unsigned automatically_allocated:1;
  45. /** A buffer that is used for SCRATCH or reduction cannnot be used with
  46. * filters. */
  47. unsigned relaxed_coherency:2;
  48. /** Whether this is the home chunk, or there is no home chunk (and it is thus always clean) */
  49. unsigned home:1;
  50. /** Whether the memchunk is in the clean part of the mc_list */
  51. unsigned clean:1;
  52. /** Was this chunk used since it got allocated? */
  53. unsigned diduse:1;
  54. /** Was this chunk marked as "won't use"? */
  55. unsigned wontuse:1;
  56. /** the size of the data is only set when calling _starpu_request_mem_chunk_removal(),
  57. * it is needed to estimate how much memory is in mc_cache, and by
  58. * free_memory_on_node() which is called when the handle is no longer
  59. * valid.
  60. * It should not be used otherwise.
  61. */
  62. size_t size;
  63. struct _starpu_data_replicate *replicate;
  64. /** This is set when one keeps a pointer to this mc obtained from the
  65. * mc_list without mc_lock held. We need to clear the pointer if we
  66. * remove this entry from the mc_list, so we know we have to restart
  67. * from zero. This is protected by the corresponding mc_lock. */
  68. struct _starpu_mem_chunk **remove_notify;
  69. )
  70. void _starpu_init_mem_chunk_lists(void);
  71. void _starpu_deinit_mem_chunk_lists(void);
  72. void _starpu_mem_chunk_init_last(void);
  73. void _starpu_request_mem_chunk_removal(starpu_data_handle_t handle, struct _starpu_data_replicate *replicate, unsigned node, size_t size);
  74. int _starpu_allocate_memory_on_node(starpu_data_handle_t handle, struct _starpu_data_replicate *replicate, unsigned is_prefetch);
  75. size_t _starpu_free_all_automatically_allocated_buffers(unsigned node);
  76. void _starpu_memchunk_recently_used(struct _starpu_mem_chunk *mc, unsigned node);
  77. void _starpu_memchunk_wont_use(struct _starpu_mem_chunk *m, unsigned nodec);
  78. void _starpu_memchunk_dirty(struct _starpu_mem_chunk *mc, unsigned node);
  79. void _starpu_display_memory_stats_by_node(int node);
  80. size_t _starpu_memory_reclaim_generic(unsigned node, unsigned force, size_t reclaim);
  81. int _starpu_is_reclaiming(unsigned node);
  82. void _starpu_mem_chunk_disk_register(unsigned disk_memnode);
  83. #endif