1 /*
2  * Copyright (c) 2020-2021, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
17 #pragma once
19 #include <rmm/mr/device/detail/free_list.hpp>
21 #include <cstddef>
22 #include <iostream>
24 namespace rmm::mr::detail {
26 struct fixed_size_free_list : free_list<block_base> {
27  fixed_size_free_list() = default;
28  ~fixed_size_free_list() override = default;
31  fixed_size_free_list& operator=(fixed_size_free_list const&) = delete;
33  fixed_size_free_list& operator=(fixed_size_free_list&&) = delete;
42  template <class InputIt>
43  fixed_size_free_list(InputIt first, InputIt last)
44  {
45  std::for_each(first, last, [this](block_type const& block) { insert(block); });
46  }
54  void insert(block_type const& block) { push_back(block); }
61  void insert(free_list&& other) { splice(cend(), std::move(other)); }
69  block_type get_block(std::size_t size)
70  {
71  if (is_empty()) { return block_type{}; }
72  block_type block = *begin();
73  pop_front();
74  return block;
75  }
76 };
78 } // namespace rmm::mr::detail
void insert(block_type const &block)
Inserts a block into the free_list in the correct order, coalescing it with the preceding and followi...
Definition: fixed_size_free_list.hpp:54
rmm::mr::detail::free_list< block_base >::cend
const_iterator cend() const noexcept
beginning of the free list
Definition: free_list.hpp:93
rmm::mr::detail::free_list< block_base >::begin
iterator begin() noexcept
beginning of the free list
Definition: free_list.hpp:82
Base class defining an interface for a list of free memory blocks.
Definition: free_list.hpp:65
rmm::mr::detail::free_list< block_base >::size
size_type size() const noexcept
The size of the free list in blocks.
Definition: free_list.hpp:100
fixed_size_free_list(InputIt first, InputIt last)
Construct a new free_list from range defined by input iterators.
Definition: fixed_size_free_list.hpp:43
A simple block structure specifying the size and location of a block of memory, with a flag indicatin...
Definition: coalescing_free_list.hpp:36
rmm::mr::detail::free_list< block_base >::push_back
void push_back(const block_type &block)
Appends the given block to the end of the free list.
Definition: free_list.hpp:161
block_type get_block(std::size_t size)
Returns the first block in the free list.
Definition: fixed_size_free_list.hpp:69
rmm::mr::detail::free_list< block_base >::is_empty
bool is_empty() const noexcept
checks whether the free_list is empty.
Definition: free_list.hpp:108
Definition: fixed_size_free_list.hpp:26
rmm::mr::detail::free_list< block_base >::pop_front
void pop_front()
Removes the first element of the free list. If there are no elements in the free list,...
Definition: free_list.hpp:176
void insert(free_list &&other)
Inserts blocks from another free list into this free_list.
Definition: fixed_size_free_list.hpp:61
Definition: free_list.hpp:25
rmm::mr::detail::free_list< block_base >::splice
void splice(const_iterator pos, free_list &&other)
Inserts a list of blocks in the free list before the specified position.
Definition: free_list.hpp:151