|
16 | 16 |
|
17 | 17 | #pragma once |
18 | 18 |
|
19 | | -rmm::mr::detail |
| 19 | +#include <rmm/detail/export.hpp> |
20 | 20 | #include <rmm/mr/device/detail/free_list.hpp> |
21 | 21 |
|
22 | 22 | #include <cstddef> |
23 | 23 | #include <iostream> |
24 | 24 |
|
25 | | - namespace RMM_EXPORT rmm::mr::detail |
26 | | -{ |
27 | | - struct fixed_size_free_list : free_list<block_base> { |
28 | | - fixed_size_free_list() = default; |
29 | | - ~fixed_size_free_list() override = default; |
| 25 | +namespace RMM_EXPORT rmm { |
| 26 | +namespace mr::detail { |
30 | 27 |
|
31 | | - fixed_size_free_list(fixed_size_free_list const&) = delete; |
32 | | - fixed_size_free_list& operator=(fixed_size_free_list const&) = delete; |
33 | | - fixed_size_free_list(fixed_size_free_list&&) = delete; |
34 | | - fixed_size_free_list& operator=(fixed_size_free_list&&) = delete; |
| 28 | +struct fixed_size_free_list : free_list<block_base> { |
| 29 | + fixed_size_free_list() = default; |
| 30 | + ~fixed_size_free_list() override = default; |
35 | 31 |
|
36 | | - /** |
37 | | - * @brief Construct a new free_list from range defined by input iterators |
38 | | - * |
39 | | - * @tparam InputIt Input iterator |
40 | | - * @param first The start of the range to insert into the free_list |
41 | | - * @param last The end of the range to insert into the free_list |
42 | | - */ |
43 | | - template <class InputIt> |
44 | | - fixed_size_free_list(InputIt first, InputIt last) |
45 | | - { |
46 | | - std::for_each(first, last, [this](block_type const& block) { insert(block); }); |
47 | | - } |
| 32 | + fixed_size_free_list(fixed_size_free_list const&) = delete; |
| 33 | + fixed_size_free_list& operator=(fixed_size_free_list const&) = delete; |
| 34 | + fixed_size_free_list(fixed_size_free_list&&) = delete; |
| 35 | + fixed_size_free_list& operator=(fixed_size_free_list&&) = delete; |
48 | 36 |
|
49 | | - /** |
50 | | - * @brief Inserts a block into the `free_list` in the correct order, coalescing it with the |
51 | | - * preceding and following blocks if either is contiguous. |
52 | | - * |
53 | | - * @param block The block to insert. |
54 | | - */ |
55 | | - void insert(block_type const& block) { push_back(block); } |
| 37 | + /** |
| 38 | + * @brief Construct a new free_list from range defined by input iterators |
| 39 | + * |
| 40 | + * @tparam InputIt Input iterator |
| 41 | + * @param first The start of the range to insert into the free_list |
| 42 | + * @param last The end of the range to insert into the free_list |
| 43 | + */ |
| 44 | + template <class InputIt> |
| 45 | + fixed_size_free_list(InputIt first, InputIt last) |
| 46 | + { |
| 47 | + std::for_each(first, last, [this](block_type const& block) { insert(block); }); |
| 48 | + } |
56 | 49 |
|
57 | | - /** |
58 | | - * @brief Inserts blocks from another free list into this free_list. |
59 | | - * |
60 | | - * @param other The free_list to insert into this free_list. |
61 | | - */ |
62 | | - void insert(free_list&& other) { splice(cend(), std::move(other)); } |
| 50 | + /** |
| 51 | + * @brief Inserts a block into the `free_list` in the correct order, coalescing it with the |
| 52 | + * preceding and following blocks if either is contiguous. |
| 53 | + * |
| 54 | + * @param block The block to insert. |
| 55 | + */ |
| 56 | + void insert(block_type const& block) { push_back(block); } |
63 | 57 |
|
64 | | - /** |
65 | | - * @brief Returns the first block in the free list. |
66 | | - * |
67 | | - * @param size The size in bytes of the desired block (unused). |
68 | | - * @return A block large enough to store `size` bytes. |
69 | | - */ |
70 | | - block_type get_block(std::size_t size) |
71 | | - { |
72 | | - if (is_empty()) { return block_type{}; } |
73 | | - block_type block = *begin(); |
74 | | - pop_front(); |
75 | | - return block; |
76 | | - } |
77 | | - }; |
| 58 | + /** |
| 59 | + * @brief Inserts blocks from another free list into this free_list. |
| 60 | + * |
| 61 | + * @param other The free_list to insert into this free_list. |
| 62 | + */ |
| 63 | + void insert(free_list&& other) { splice(cend(), std::move(other)); } |
78 | 64 |
|
79 | | -} // namespace RMM_EXPORT rmm::mr::detail |
| 65 | + /** |
| 66 | + * @brief Returns the first block in the free list. |
| 67 | + * |
| 68 | + * @param size The size in bytes of the desired block (unused). |
| 69 | + * @return A block large enough to store `size` bytes. |
| 70 | + */ |
| 71 | + block_type get_block(std::size_t size) |
| 72 | + { |
| 73 | + if (is_empty()) { return block_type{}; } |
| 74 | + block_type block = *begin(); |
| 75 | + pop_front(); |
| 76 | + return block; |
| 77 | + } |
| 78 | +}; |
| 79 | + |
| 80 | +} // namespace mr::detail |
| 81 | +} // namespace RMM_EXPORT rmm |
0 commit comments