133 #include "../../Shared/funcannotations.h"
144 addr +=
sizeof(int64_t) - 1;
145 return (int64_t)(((uint64_t)addr >> 3) << 3);
190 static_cast<FlatBufferFormat>(((int64_t*)buffer)[VarlenArrayHeader::FORMAT_ID]);
192 int64_t flatbuffer_size = ((int64_t*)buffer)[VarlenArrayHeader::FLATBUFFER_SIZE];
193 if (flatbuffer_size > 0) {
195 ((int64_t*)buffer)[flatbuffer_size /
sizeof(int64_t) - 1]);
196 return footer_format == header_format;
206 return ((
const int64_t*)(buffer))[VarlenArrayHeader::FLATBUFFER_SIZE];
215 ((int64_t*)
buffer)[VarlenArrayHeader::FORMAT_ID]);
220 return ((
const int64_t*)(
buffer))[VarlenArrayHeader::FLATBUFFER_SIZE];
242 case DTypeMetadataKind::SIZE:
244 case DTypeMetadataKind::SIZE_DICTID:
253 ((int64_t*)
buffer)[VarlenArrayHeader::DTYPE_METADATA_KIND]);
257 return buffer + ((int64_t*)
buffer)[VarlenArrayHeader::DTYPE_METADATA_BUFFER_OFFSET];
262 ((
const int64_t*)
buffer)[VarlenArrayHeader::DTYPE_METADATA_BUFFER_OFFSET];
268 case DTypeMetadataKind::SIZE: {
271 metadata->
size = size;
273 case DTypeMetadataKind::SIZE_DICTID: {
276 metadata->
size = size;
284 case DTypeMetadataKind::SIZE: {
287 return metadata->
size;
289 case DTypeMetadataKind::SIZE_DICTID: {
292 return metadata->
size;
302 case DTypeMetadataKind::SIZE:
304 case DTypeMetadataKind::SIZE_DICTID: {
307 metadata->
db_id = db_id;
316 case DTypeMetadataKind::SIZE:
318 case DTypeMetadataKind::SIZE_DICTID: {
321 return metadata->
db_id;
330 case DTypeMetadataKind::SIZE:
332 case DTypeMetadataKind::SIZE_DICTID: {
344 int64_t max_nof_values,
347 const int64_t VarlenArray_buffer_header_size =
348 VarlenArrayHeader::EOFHEADER *
sizeof(int64_t);
349 const int64_t dtype_metadata_buffer_size =
351 const int64_t values_buffer_size =
_align_to_int64(dtype_size * max_nof_values);
352 return (VarlenArray_buffer_header_size
353 + dtype_metadata_buffer_size
359 ) *
sizeof(int64_t));
364 int64_t max_nof_values,
367 const int64_t VarlenArray_buffer_header_size =
368 VarlenArrayHeader::EOFHEADER *
sizeof(int64_t);
369 const int64_t values_buffer_size =
_align_to_int64(dtype_size * max_nof_values);
370 const int64_t compressed_indices_buffer_size = (items_count + 1) *
sizeof(int64_t);
371 const int64_t dtype_metadata_buffer_size =
374 items_count, max_nof_values, dtype_size, dtype_metadata_kind);
375 ((int64_t*)
buffer)[VarlenArrayHeader::FORMAT_ID] =
377 ((int64_t*)
buffer)[VarlenArrayHeader::FLATBUFFER_SIZE] = flatbuffer_size;
378 ((int64_t*)
buffer)[VarlenArrayHeader::ITEMS_COUNT] = items_count;
379 ((int64_t*)
buffer)[VarlenArrayHeader::MAX_NOF_VALUES] = max_nof_values;
380 ((int64_t*)
buffer)[VarlenArrayHeader::DTYPE_METADATA_KIND] =
381 static_cast<int64_t
>(dtype_metadata_kind);
382 ((int64_t*)
buffer)[VarlenArrayHeader::DTYPE_METADATA_BUFFER_SIZE] =
383 dtype_metadata_buffer_size;
384 ((int64_t*)
buffer)[VarlenArrayHeader::STORAGE_COUNT] = 0;
385 ((int64_t*)
buffer)[VarlenArrayHeader::DTYPE_METADATA_BUFFER_OFFSET] =
386 VarlenArray_buffer_header_size;
387 ((int64_t*)
buffer)[VarlenArrayHeader::VALUES_OFFSET] =
388 ((
const int64_t*)
buffer)[VarlenArrayHeader::DTYPE_METADATA_BUFFER_OFFSET] +
389 dtype_metadata_buffer_size;
390 ((int64_t*)
buffer)[VarlenArrayHeader::COMPRESSED_INDICES_OFFSET] =
391 ((
const int64_t*)
buffer)[VarlenArrayHeader::VALUES_OFFSET] + values_buffer_size;
392 ((int64_t*)
buffer)[VarlenArrayHeader::STORAGE_INDICES_OFFSET] =
393 ((
const int64_t*)
buffer)[VarlenArrayHeader::COMPRESSED_INDICES_OFFSET] +
394 compressed_indices_buffer_size;
401 for (
int i = 0; i < items_count; i++) {
402 compressed_indices[i] = 0;
403 storage_indices[i] = -1;
405 compressed_indices[items_count] = 0;
407 ((int64_t*)
buffer)[flatbuffer_size /
sizeof(int64_t) - 1] =
414 return ((int64_t*)
buffer)[VarlenArrayHeader::ITEMS_COUNT];
424 return ((int64_t*)
buffer)[VarlenArrayHeader::MAX_NOF_VALUES];
431 return compressed_indices[storage_count];
441 return ((int64_t*)
buffer)[VarlenArrayHeader::STORAGE_COUNT];
445 return ((int64_t*)
buffer)[VarlenArrayHeader::STORAGE_COUNT];
450 return buffer + ((
const int64_t*)
buffer)[VarlenArrayHeader::VALUES_OFFSET];
454 return buffer + ((
const int64_t*)
buffer)[VarlenArrayHeader::VALUES_OFFSET];
459 return reinterpret_cast<int64_t*
>(
460 buffer + ((
const int64_t*)
buffer)[VarlenArrayHeader::COMPRESSED_INDICES_OFFSET]);
463 return reinterpret_cast<const int64_t*
>(
464 buffer + ((
const int64_t*)
buffer)[VarlenArrayHeader::COMPRESSED_INDICES_OFFSET]);
469 return reinterpret_cast<int64_t*
>(
470 buffer + ((
const int64_t*)
buffer)[VarlenArrayHeader::STORAGE_INDICES_OFFSET]);
473 return reinterpret_cast<const int64_t*
>(
474 buffer + ((
const int64_t*)
buffer)[VarlenArrayHeader::STORAGE_INDICES_OFFSET]);
484 int8_t**
dest =
nullptr) {
493 if (size % itemsize != 0) {
497 if (storage_indices[index] >= 0) {
500 const int64_t cindex = compressed_indices[storage_count];
502 const int64_t csize = cindex * itemsize;
503 if (csize + size > values_buffer_size) {
521 const int64_t values_count = size / itemsize;
522 const int64_t cindex = compressed_indices[storage_count];
523 const int64_t csize = cindex * itemsize;
524 storage_indices[index] = storage_count;
525 compressed_indices[storage_count + 1] = cindex + values_count;
526 if (size > 0 && src !=
nullptr && memcpy(values + csize, src, size) ==
nullptr) {
529 if (dest !=
nullptr) {
530 *dest = values + csize;
549 int64_t storage_count = next_storage_count - 1;
554 int64_t storage_index = storage_indices[index];
556 if (storage_index == -1) {
557 return setItem(index, src, size,
nullptr);
559 if (size % itemsize != 0) {
562 if (storage_index != storage_count) {
567 if (compressed_indices[storage_index] < 0) {
570 int64_t values_count =
571 compressed_indices[next_storage_count] - compressed_indices[storage_index];
572 int64_t extra_values_count = size / itemsize;
573 compressed_indices[next_storage_count] += extra_values_count;
574 int8_t* ptr = values + compressed_indices[storage_index] * itemsize;
575 if (size > 0 && src !=
nullptr &&
576 memcpy(ptr + values_count * itemsize, src, size) ==
nullptr) {
591 if (storage_indices[index] >= 0) {
604 const int64_t cindex = compressed_indices[storage_count];
605 storage_indices[index] = storage_count;
606 compressed_indices[storage_count] = -(cindex + 1);
607 compressed_indices[storage_count + 1] = cindex;
620 const int64_t storage_index = storage_indices[index];
621 if (storage_index < 0) {
624 is_null = (compressed_indices[storage_index] < 0);
641 const int64_t storage_index = storage_indices[index];
642 if (storage_index < 0) {
645 const int64_t cindex = compressed_indices[storage_index];
653 const int64_t next_cindex = compressed_indices[storage_index + 1];
654 const int64_t length =
655 (next_cindex < 0 ? -(next_cindex + 1) - cindex : next_cindex - cindex);
656 size = length * dtypesize;
657 dest = values + cindex * dtypesize;
685 const int64_t* buf =
reinterpret_cast<const int64_t*
>(
buffer);
686 std::vector<int64_t> header(buf, buf + 11);
689 const int64_t* metadata_buf =
692 std::vector<int64_t> metadata(metadata_buf, metadata_buf + metadata_buf_size);
693 result +=
", metadata=" +
::toString(metadata);
695 result +=
", values=";
699 std::vector<int8_t> values(values_buf, values_buf + numvalues);
703 const int16_t* values_buf =
705 std::vector<int16_t> values(values_buf, values_buf + numvalues);
709 const int32_t* values_buf =
711 std::vector<int32_t> values(values_buf, values_buf + numvalues);
715 const int64_t* values_buf =
717 std::vector<int64_t> values(values_buf, values_buf + numvalues);
721 result +=
"[UNEXPECTED ITEMSIZE:" +
std::to_string(itemsize) +
"]";
725 std::vector<int64_t> compressed_indices(compressed_indices_buf,
726 compressed_indices_buf + numitems + 1);
727 result +=
", compressed_indices=" +
::toString(compressed_indices);
730 std::vector<int64_t> storage_indices(storage_indices_buf,
731 storage_indices_buf + numitems);
732 result +=
", storage_indices=" +
::toString(storage_indices);
745 inline std::ostream&
operator<<(std::ostream& os,
758 os <<
"ItemAlreadySpecifiedError";
761 os <<
"ItemUnspecifiedError";
764 os <<
"ValuesBufferTooSmallError";
770 os <<
"UnknownFormatError";
773 os <<
"NotImplemnentedError";
776 os <<
"[Unknown FlatBufferManager::Status value]";
782 std::ostringstream ss;
void initializeVarlenArray(int64_t items_count, int64_t max_nof_values, int64_t dtype_size, DTypeMetadataKind dtype_metadata_kind)
int32_t getDTypeMetadataDictDbId() const
HOST DEVICE int64_t getDTypeMetadataSize() const
HOST DEVICE int64_t dtypeSize() const
int32_t getDTypeMetadataDictId() const
Status isNull(int64_t index, bool &is_null) const
Status concatItem(int64_t index, const int8_t *src, int64_t size)
std::ostream & operator<<(std::ostream &os, const SessionInfo &session_info)
Status setItem(int64_t index, const int8_t *src, int64_t size, int8_t **dest=nullptr)
static int64_t get_VarlenArray_flatbuffer_size(int64_t items_count, int64_t max_nof_values, int64_t dtype_size, DTypeMetadataKind dtype_metadata_kind)
HOST DEVICE FlatBufferFormat format() const
const int64_t * VarlenArray_storage_indices() const
HOST DEVICE Status getItem(int64_t index, int64_t &size, int8_t *&dest, bool &is_null)
int64_t & VarlenArray_storage_count()
CONSTEXPR DEVICE bool is_null(const T &value)
HOST DEVICE Status getItem(int64_t index, size_t &size, int8_t *&dest, bool &is_null)
HOST DEVICE const int8_t * getDTypeMetadataBuffer() const
const int64_t * VarlenArray_compressed_indices() const
int64_t VarlenArray_max_nof_values() const
int64_t VarlenArray_values_buffer_size() const
std::string toString(const ExecutorDeviceType &device_type)
HOST DEVICE int64_t itemsCount() const
int8_t * getDTypeMetadataBuffer()
Status setNull(int64_t index)
Status setEmptyItemNoValidation(int64_t index, int64_t size, int8_t **dest)
int64_t & VarlenArray_storage_count() const
HOST DEVICE int64_t * VarlenArray_compressed_indices()
int64_t VarlenArray_nof_values() const
std::string typeName(const T *v)
HOST DEVICE int64_t * VarlenArray_storage_indices()
int64_t flatbufferSize() const
int64_t _align_to_int64(int64_t addr)
void setDTypeMetadataDictKey(int32_t db_id, int32_t dict_id)
HOST DEVICE int8_t * VarlenArray_values()
HOST static DEVICE bool isFlatBuffer(const void *buffer)
static int64_t getDTypeMetadataBufferSize(DTypeMetadataKind kind)
Status setNullNoValidation(int64_t index)
void setDTypeMetadataSize(int64_t size)
HOST DEVICE DTypeMetadataKind getDTypeMetadataKind() const
const int8_t * VarlenArray_values() const
Status setItemNoValidation(int64_t index, const int8_t *src, int64_t size, int8_t **dest)
static int64_t getBufferSize(const void *buffer)