Eigen::internal::TensorBlockScratchAllocator< Device > Class Template Reference

#include <TensorBlock.h>

Classes

struct  Allocation
 

Public Member Functions

 TensorBlockScratchAllocator (const Device &device)
 
 ~TensorBlockScratchAllocator ()
 
void * allocate (size_t size)
 
void reset ()
 

Private Attributes

const Device & m_device
 
int m_allocation_index
 
std::vector< Allocationm_allocations
 

Constructor & Destructor Documentation

◆ TensorBlockScratchAllocator()

template<typename Device >
Eigen::internal::TensorBlockScratchAllocator< Device >::TensorBlockScratchAllocator ( const Device &  device)
inlineexplicit
477 : m_device(device), m_allocation_index(0) {}
int m_allocation_index
Definition: TensorBlock.h:530
const Device & m_device
Definition: TensorBlock.h:529

◆ ~TensorBlockScratchAllocator()

template<typename Device >
Eigen::internal::TensorBlockScratchAllocator< Device >::~TensorBlockScratchAllocator ( )
inline
479  {
480  for (size_t i = 0; i < m_allocations.size(); ++i) {
481  m_device.deallocate(m_allocations[i].ptr);
482  }
483  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
std::vector< Allocation > m_allocations
Definition: TensorBlock.h:532

References i, Eigen::internal::TensorBlockScratchAllocator< Device >::m_allocations, and Eigen::internal::TensorBlockScratchAllocator< Device >::m_device.

Member Function Documentation

◆ allocate()

template<typename Device >
void* Eigen::internal::TensorBlockScratchAllocator< Device >::allocate ( size_t  size)
inline
485  {
486  // TODO(ezhulenev): Remove when replaced with inlined vector.
487  if (m_allocations.capacity() == 0) m_allocations.reserve(8);
488 
489  // Check if we already have an existing allocation att current index.
490  const int num_allocations = static_cast<int>(m_allocations.size());
491  const bool has_allocation = m_allocation_index < num_allocations;
492 
493  // Allocation index can't be larger than the number of allocations.
494  eigen_assert(m_allocation_index <= num_allocations);
495 
496  // If we have existing allocation, and its size is larger or equal to
497  // requested size, we do nothing.
498 
499  // If current allocation can't fit requested size, we deallocate it, and
500  // replace with a larger allocation.
501  if (has_allocation && m_allocations[m_allocation_index].size < size) {
502  m_device.deallocate(m_allocations[m_allocation_index].ptr);
505  }
506 
507  // Make a new allocation if we don't have and existing one.
508  if (!has_allocation) {
509  Allocation allocation;
510  allocation.ptr = m_device.allocate(size);
511  allocation.size = size;
512  m_allocations.push_back(allocation);
513  }
514 
517 
518  return m_allocations[m_allocation_index++].ptr;
519  }
#define eigen_assert(x)
Definition: Macros.h:910
Scalar Scalar int size
Definition: benchVecAdd.cpp:17

References eigen_assert, Eigen::internal::TensorBlockScratchAllocator< Device >::m_allocation_index, Eigen::internal::TensorBlockScratchAllocator< Device >::m_allocations, Eigen::internal::TensorBlockScratchAllocator< Device >::m_device, Eigen::internal::TensorBlockScratchAllocator< Device >::Allocation::ptr, size, and Eigen::internal::TensorBlockScratchAllocator< Device >::Allocation::size.

Referenced by Eigen::TensorEvaluator< const TensorBroadcastingOp< Broadcast, ArgType >, Device >::BroadcastBlock().

◆ reset()

Member Data Documentation

◆ m_allocation_index

◆ m_allocations

◆ m_device


The documentation for this class was generated from the following file: