SPVM-Resource-Eigen
view release on metacpan or search on metacpan
lib/SPVM/Resource/Eigen.native/include/Eigen/src/Core/arch/SYCL/SyclMemoryModel.h view on Meta::CPAN
*/
virtual_pointer_t(const void *ptr)
: m_contents(reinterpret_cast<base_ptr_t>(ptr)){};
/**
* Creates a virtual_pointer_t from the given integer
* number
*/
virtual_pointer_t(base_ptr_t u) : m_contents(u){};
};
/* Definition of a null pointer
*/
const virtual_pointer_t null_virtual_ptr = nullptr;
/**
* Whether if a pointer is null or not.
* A pointer is nullptr if the value is of null_virtual_ptr
*/
static inline bool is_nullptr(virtual_pointer_t ptr) {
return (static_cast<void *>(ptr) == nullptr);
}
/* basic type for all buffers
*/
using buffer_t = cl::sycl::buffer_mem;
/**
* Node that stores information about a device allocation.
* Nodes are sorted by size to organise a free list of nodes
* that can be recovered.
*/
struct pMapNode_t {
buffer_t m_buffer;
size_t m_size;
bool m_free;
pMapNode_t(buffer_t b, size_t size, bool f)
: m_buffer{b}, m_size{size}, m_free{f} {
m_buffer.set_final_data(nullptr);
}
bool operator<=(const pMapNode_t &rhs) { return (m_size <= rhs.m_size); }
};
/** Storage of the pointer / buffer tree
*/
using pointerMap_t = std::map<virtual_pointer_t, pMapNode_t>;
/**
* Obtain the insertion point in the pointer map for
* a pointer of the given size.
* \param requiredSize Size attemted to reclaim
*/
typename pointerMap_t::iterator get_insertion_point(size_t requiredSize) {
typename pointerMap_t::iterator retVal;
bool reuse = false;
if (!m_freeList.empty()) {
// try to re-use an existing block
for (auto freeElem : m_freeList) {
if (freeElem->second.m_size >= requiredSize) {
retVal = freeElem;
reuse = true;
// Element is not going to be free anymore
m_freeList.erase(freeElem);
break;
}
}
}
if (!reuse) {
retVal = std::prev(m_pointerMap.end());
}
return retVal;
}
/**
* Returns an iterator to the node that stores the information
* of the given virtual pointer from the given pointer map structure.
* If pointer is not found, throws std::out_of_range.
* If the pointer map structure is empty, throws std::out_of_range
*
* \param pMap the pointerMap_t structure storing all the pointers
* \param virtual_pointer_ptr The virtual pointer to obtain the node of
* \throws std::out:of_range if the pointer is not found or pMap is empty
*/
typename pointerMap_t::iterator get_node(const virtual_pointer_t ptr) {
if (this->count() == 0) {
m_pointerMap.clear();
EIGEN_THROW_X(std::out_of_range("There are no pointers allocated\n"));
}
if (is_nullptr(ptr)) {
m_pointerMap.clear();
EIGEN_THROW_X(std::out_of_range("Cannot access null pointer\n"));
}
// The previous element to the lower bound is the node that
// holds this memory address
auto node = m_pointerMap.lower_bound(ptr);
// If the value of the pointer is not the one of the node
// then we return the previous one
if (node == std::end(m_pointerMap)) {
--node;
} else if (node->first != ptr) {
if (node == std::begin(m_pointerMap)) {
m_pointerMap.clear();
EIGEN_THROW_X(
std::out_of_range("The pointer is not registered in the map\n"));
}
--node;
}
return node;
}
/* get_buffer.
* Returns a buffer from the map using the pointer address
*/
template <typename buffer_data_type = buffer_data_type_t>
cl::sycl::buffer<buffer_data_type, 1> get_buffer(
const virtual_pointer_t ptr) {
( run in 2.617 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )