138 #include <string_view>
140 #include "../base/bytes.h"
161 static constexpr uint8_t kMaxRank{8};
166 enum DataType : uint8_t {
186 enum Device : uint8_t {
252 bool operator>>(Bytes& bytes)
const noexcept;
260 [[nodiscard]]
static bool check_valid(
const Bytes& bytes) noexcept;
274 [[nodiscard]]
bool is_valid()
const noexcept;
282 bool shallow_copy(
const Tensor& target) noexcept;
290 bool deep_copy(
const Tensor& target) noexcept;
298 bool move_copy(
Tensor& target) noexcept;
310 bool create(
size_t size) noexcept;
315 void clear() noexcept;
324 bool shallow_copy(uint8_t* data,
size_t size) noexcept;
333 bool deep_copy(uint8_t* data,
size_t size) noexcept;
342 bool fill_data(uint8_t* data,
size_t size) noexcept;
349 [[nodiscard]] uint64_t update_time_ns()
const noexcept;
356 [[nodiscard]] uint64_t num_elements()
const noexcept;
363 [[nodiscard]] std::string_view name()
const noexcept;
370 [[nodiscard]] std::string_view model_id()
const noexcept;
377 [[nodiscard]] std::string_view layout()
const noexcept;
384 [[nodiscard]]
const uint32_t* shape()
const noexcept;
392 [[nodiscard]] uint32_t shape_at(uint8_t dim)
const noexcept;
399 [[nodiscard]]
const uint32_t* strides()
const noexcept;
407 [[nodiscard]] uint32_t stride_at(uint8_t dim)
const noexcept;
414 [[nodiscard]] uint32_t channel()
const noexcept;
421 [[nodiscard]] uint32_t freq()
const noexcept;
428 [[nodiscard]] uint32_t batch_size()
const noexcept;
435 [[nodiscard]]
float quant_scale()
const noexcept;
442 [[nodiscard]] int32_t quant_zero_point()
const noexcept;
449 [[nodiscard]] DataType dtype()
const noexcept;
456 [[nodiscard]] uint8_t rank()
const noexcept;
463 [[nodiscard]] Device device()
const noexcept;
470 [[nodiscard]] uint8_t element_size()
const noexcept;
477 [[nodiscard]]
const uint8_t* data()
const noexcept;
484 [[nodiscard]]
size_t size()
const noexcept;
491 [[nodiscard]]
bool is_owner()
const noexcept;
498 void set_update_time_ns(uint64_t update_time_ns) noexcept;
505 void set_name(std::string_view name) noexcept;
512 void set_model_id(std::string_view model_id) noexcept;
519 void set_layout(std::string_view layout) noexcept;
532 void set_shape(
const uint32_t* shape, uint8_t rank) noexcept;
540 void set_shape_at(uint8_t dim, uint32_t value) noexcept;
548 void set_stride_at(uint8_t dim, uint32_t value) noexcept;
555 void set_channel(uint32_t channel) noexcept;
562 void set_freq(uint32_t freq) noexcept;
569 void set_batch_size(uint32_t batch_size) noexcept;
576 void set_quant_scale(
float quant_scale) noexcept;
583 void set_quant_zero_point(int32_t quant_zero_point) noexcept;
590 void set_dtype(DataType dtype) noexcept;
597 void set_device(Device device) noexcept;
605 [[nodiscard]]
static uint8_t element_size_of(DataType dtype) noexcept;
612 uint8_t& get_reserved() noexcept {
return reserved_buf_; }
619 uint16_t& get_reserved2() noexcept {
return reserved_buf2_; }
626 uint32_t& get_reserved3() noexcept {
return reserved_buf3_; }
630 static constexpr
bool kZerocopyTypes{
true};
633 uint8_t* data_{
nullptr};
635 uint64_t update_time_ns_{0};
636 uint64_t num_elements_{0};
638 char model_id_[32]{0};
640 uint32_t shape_[kMaxRank]{0};
641 uint32_t strides_[kMaxRank]{0};
642 uint32_t channel_{0};
644 uint32_t batch_size_{0};
645 float quant_scale_{0};
646 int32_t quant_zero_point_{0};
647 DataType dtype_{kDataUnknown};
649 Device device_{kDeviceCpu};
650 bool is_owner_{
false};
651 uint8_t element_size_{0};
652 uint8_t reserved_buf_{0};
653 uint16_t reserved_buf2_{0};
654 uint32_t reserved_buf3_{0};
656 static constexpr uint32_t kMagicNumberBegin{0x98B7F19A};
657 static constexpr uint32_t kMagicNumberEnd{0x98B7F19F};
constexpr bool is_valid() noexcept
Definition: name_detector.h:382
size_t get_serialized_size(const T &src) noexcept
Returns a serialised-size hint for src with explicit codec tag.
Definition: serializer-inl.h:298
VLINK_EXPORT std::ostream & operator<<(std::ostream &ostream, const BasePtr &status) noexcept
Writes the human-readable description of status to ostream.
struct VLINK_EXPORT_AND_ALIGNED(8) AudioFrame final
Definition: audio_frame.h:140
248-byte POD container holding a dense N-D tensor plus shape / dtype / device metadata.