Beatmup
Internal::Copy Class Reference

Copies data from multidimensional strided tensor to a continuous memory space. More...

Public Member Functions

 Copy (const pybind11::buffer_info &info, void *outputBuffer, size_t limit)
 
size_t remaining () const
 

Private Member Functions

size_t discover (int dim=0)
 
void copy (const uint8_t *inPtr, int dim=0)
 

Private Attributes

const pybind11::buffer_info & info
 
int firstStridedDim
 first non-dense dimension More...
 
size_t packetSize
 largest continuous packet size More...
 
uint8_t * outPtr
 output pointer More...
 
size_t limit
 number of bytes remaining to copy More...
 

Detailed Description

Copies data from multidimensional strided tensor to a continuous memory space.

Makes use of densely packed dimensions for a faster copy.

Definition at line 31 of file chunk_collection.cpp.

Constructor & Destructor Documentation

◆ Copy()

Internal::Copy::Copy ( const pybind11::buffer_info &  info,
void *  outputBuffer,
size_t  limit 
)
inline

Definition at line 92 of file chunk_collection.cpp.

92  :
93  info(info), outPtr(static_cast<uint8_t*>(outputBuffer)), limit(limit)
94  {
95  discover();
96  copy(static_cast<const uint8_t*>(info.ptr));
97  }
uint8_t * outPtr
output pointer
const pybind11::buffer_info & info
void copy(const uint8_t *inPtr, int dim=0)
size_t discover(int dim=0)
size_t limit
number of bytes remaining to copy

Member Function Documentation

◆ discover()

size_t Internal::Copy::discover ( int  dim = 0)
inlineprivate

Definition at line 44 of file chunk_collection.cpp.

44  {
45  size_t entrySize;
46  if (dim + 1 < info.ndim) {
47  entrySize = discover(dim + 1);
48  if (entrySize == 0)
49  return 0;
50  }
51  else
52  entrySize = info.itemsize;
53 
54  // check if densely packed
55  if (info.strides[dim] == entrySize) {
56  if (dim == 0) {
57  // all dimensions are densely packed
58  firstStridedDim = -1;
59  packetSize = info.size * info.itemsize;
60  return 0;
61  }
62  else
63  // just return dimension size
64  return entrySize * info.shape[dim];
65  }
66 
67  // not densely packed, so copy by pieces
68  firstStridedDim = dim;
69  packetSize = entrySize;
70  return 0;
71  }
int firstStridedDim
first non-dense dimension
size_t packetSize
largest continuous packet size

◆ copy()

void Internal::Copy::copy ( const uint8_t *  inPtr,
int  dim = 0 
)
inlineprivate

Definition at line 78 of file chunk_collection.cpp.

78  {
79  if (dim > firstStridedDim) {
80  // densely packed dimensions follow
81  size_t size = std::min(limit, packetSize);
82  memcpy(outPtr, inPtr, size);
83  outPtr += size;
84  limit -= size;
85  }
86  else
87  for (size_t i = 0; i < info.shape[dim]; ++i)
88  copy(inPtr + i * info.strides[dim], dim + 1);
89  }
CustomPoint< numeric > min(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
Definition: geometry.h:724
jlong jobject size

◆ remaining()

size_t Internal::Copy::remaining ( ) const
inline

Definition at line 99 of file chunk_collection.cpp.

99 { return limit; }

Member Data Documentation

◆ info

const pybind11::buffer_info& Internal::Copy::info
private

Definition at line 33 of file chunk_collection.cpp.

◆ firstStridedDim

int Internal::Copy::firstStridedDim
private

first non-dense dimension

Definition at line 34 of file chunk_collection.cpp.

◆ packetSize

size_t Internal::Copy::packetSize
private

largest continuous packet size

Definition at line 35 of file chunk_collection.cpp.

◆ outPtr

uint8_t* Internal::Copy::outPtr
private

output pointer

Definition at line 36 of file chunk_collection.cpp.

◆ limit

size_t Internal::Copy::limit
private

number of bytes remaining to copy

Definition at line 37 of file chunk_collection.cpp.


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