8 #ifndef BC_CORE_CONTEXT_MEMORY_MANAGER_POLYMORPHIC_ALLOCATOR_H_ 9 #define BC_CORE_CONTEXT_MEMORY_MANAGER_POLYMORPHIC_ALLOCATOR_H_ 14 namespace allocators {
26 template<
class ValueType,
class SystemTag>
41 return !((*this) == other);
46 template<
class Allocator>
49 typename bc::allocator_traits<Allocator>::value_type,
50 typename bc::allocator_traits<Allocator>::system_tag>
69 typename traits_type::template rebind_alloc<altT>>;
89 return __PRETTY_FUNCTION__ ;
93 using hash_t = std::conditional_t<
94 std::is_same<value_type, bc::allocators::Byte>::value,
97 return hash_t::static_hash();
101 return m_allocator.allocate(sz);
105 m_allocator.deallocate(data, sz);
112 if (traits_type::is_always_equal::value)
115 auto& cast_other =
static_cast<const self_type&
>(other);
116 return m_allocator == cast_other.m_allocator;
126 template<
class ValueType,
class SystemTag>
134 template<
class... Args>
137 template<
class... Args>
141 using allocator_pointer_type = std::unique_ptr<allocator_type>;
144 allocator_pointer_type m_allocator;
148 template<
class Allocator>
150 m_allocator(allocator_pointer_type(
151 new Derived_Allocator<
Allocator>(alloc))) {}
154 m_allocator(allocator_pointer_type(
158 m_allocator(pa.m_allocator->
clone()) {}
161 this->set_allocator(other.m_allocator->clone());
166 this->m_allocator = std::move(other.m_allocator);
171 return m_allocator->allocate(sz);
175 m_allocator->deallocate(data, sz);
178 template<
class Allocator>
182 using alloc_rb_t =
typename traits::template rebind_alloc<value_type>;
184 auto alloc_rebound = alloc_rb_t(alloc);
186 m_allocator = allocator_pointer_type(
193 return *m_allocator == *(other.m_allocator);
199 return !(*
this == other);
virtual std::string rebound_to_byte_hash() const final
Definition: polymorphic_allocator.h:92
virtual Allocator_Base * clone() const =0
virtual void deallocate(value_type *data, std::size_t sz)=0
Allocator_Base< value_type, system_tag > * clone() const override
Definition: polymorphic_allocator.h:72
bc::allocator_traits< Allocator >::system_tag system_tag
Definition: polymorphic_allocator.h:29
system_tag system_tag
Definition: polymorphic_allocator.h:129
Polymorphic_Allocator(const Polymorphic_Allocator &pa)
Definition: polymorphic_allocator.h:157
Derived_Allocator(Allocator &&alloc)
Definition: polymorphic_allocator.h:81
virtual ~Derived_Allocator() override
Definition: polymorphic_allocator.h:84
static std::string static_hash()
Definition: polymorphic_allocator.h:87
bc::traits::conditional_detected_t< bc::traits::query_system_tag, Allocator, host_tag > system_tag
Definition: allocator_traits.h:23
typename traits_type::value_type value_type
Definition: polymorphic_allocator.h:54
void set_allocator(const Allocator &alloc)
Definition: polymorphic_allocator.h:179
virtual value_type * allocate(std::size_t sz)=0
typename traits_type::system_tag system_tag
Definition: polymorphic_allocator.h:53
bc::allocator_traits< Allocator >::value_type value_type
Definition: polymorphic_allocator.h:30
BCHOT self_type & operator=(const Expression_Base< Xpr > ¶m)
Definition: tensor_operations.h:19
Polymorphic_Allocator(const Allocator &alloc)
Definition: polymorphic_allocator.h:149
Definition: polymorphic_allocator.h:127
Definition: allocator_traits.h:20
int size_t
Definition: common.h:283
Definition: allocators.h:20
Definition: polymorphic_allocator.h:47
Derived_Allocator()
Definition: polymorphic_allocator.h:76
virtual ~Allocator_Base()
Definition: polymorphic_allocator.h:37
virtual bool operator!=(const Allocator_Base &other) const
Definition: polymorphic_allocator.h:40
Derived_Allocator(const Allocator &alloc)
Definition: polymorphic_allocator.h:78
value_type value_type
Definition: polymorphic_allocator.h:130
Polymorphic_Allocator()
Definition: polymorphic_allocator.h:153
void deallocate(value_type *data, std::size_t sz)
Definition: polymorphic_allocator.h:174
virtual void deallocate(value_type *data, std::size_t sz) override final
Definition: polymorphic_allocator.h:104
value_type * allocate(std::size_t sz)
Definition: polymorphic_allocator.h:170
Definition: polymorphic_allocator.h:27
virtual bool operator==(const Allocator_Base &other) const =0
Definition: polymorphic_allocator.h:66
virtual std::string rebound_to_byte_hash() const =0
virtual value_type * allocate(std::size_t sz) override final
Definition: polymorphic_allocator.h:100
The Evaluator determines if an expression needs to be greedily optimized.
Definition: algorithms.h:22