memalloc.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2010, 2012-2015 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013 CNRS
  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. #ifndef __MEMALLOC_H__
  18. #define __MEMALLOC_H__
  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. /* the size of the data is only set when calling _starpu_request_mem_chunk_removal(),
  53. * it is needed to estimate how much memory is in mc_cache, and by
  54. * free_memory_on_node() which is called when the handle is no longer
  55. * valid.
  56. * It should not be used otherwise.
  57. */
  58. size_t size;
  59. struct _starpu_data_replicate *replicate;
  60. /* This is set when one keeps a pointer to this mc obtained from the
  61. * mc_list without mc_lock held. We need to clear the pointer if we
  62. * remove this entry from the mc_list, so we know we have to restart
  63. * from zero. This is protected by the corresponding mc_lock. */
  64. struct _starpu_mem_chunk **remove_notify;
  65. )
  66. void _starpu_init_mem_chunk_lists(void);
  67. void _starpu_deinit_mem_chunk_lists(void);
  68. void _starpu_request_mem_chunk_removal(starpu_data_handle_t handle, struct _starpu_data_replicate *replicate, unsigned node, size_t size);
  69. int _starpu_allocate_memory_on_node(starpu_data_handle_t handle, struct _starpu_data_replicate *replicate, unsigned is_prefetch);
  70. size_t _starpu_free_all_automatically_allocated_buffers(unsigned node);
  71. void _starpu_memchunk_recently_used(struct _starpu_mem_chunk *mc, unsigned node);
  72. void _starpu_memchunk_wont_use(struct _starpu_mem_chunk *m, unsigned nodec);
  73. void _starpu_memchunk_dirty(struct _starpu_mem_chunk *mc, unsigned node);
  74. void _starpu_display_memory_stats_by_node(int node);
  75. size_t _starpu_memory_reclaim_generic(unsigned node, unsigned force, size_t reclaim);
  76. int _starpu_is_reclaiming(unsigned node);
  77. #endif