TensorCore.h File
Tensor core types and storage/mapping utilities. More...
Included Headers
#include "pipeline/TensorTypes.h"
#include <cstddef>
#include <cstdint>
#include <functional>
#include <memory>
#include <optional>
#include <string>
#include <stdexcept>
#include <utility>
#include <vector>
Namespaces Index
| namespace | simaai |
| namespace | neat |
Classes Index
| struct | Device |
| struct | ImageSpec |
| struct | AudioSpec |
| struct | TokensSpec |
| struct | EncodedSpec |
| struct | QuantSpec |
| struct | TessSpec |
| struct | Semantic |
| struct | Mapping |
| struct | Segment |
| struct | Storage |
| struct | Plane |
| struct | Nv12View |
| struct | Nv12Mapped |
| struct | I420View |
| struct | I420Mapped |
| struct | Tensor |
Description
Tensor core types and storage/mapping utilities.
File Listing
The file content with the documentation metadata removed is:
8#include "pipeline/TensorTypes.h"
24namespace simaai::neat {
26enum class DeviceType {
27 CPU = 0,
28 SIMA_APU,
29 SIMA_CVU,
30 SIMA_MLA,
31 UNKNOWN,
36 int id = 0;
39enum class StorageKind {
40 CpuOwned = 0,
41 CpuExternal,
42 GstSample,
43 DeviceHandle,
44 Unknown,
48 Unknown = 0,
49 Y,
50 U,
51 V,
52 UV,
56 Read = 0,
57 Write,
58 ReadWrite,
62 enum class PixelFormat {
63 RGB = 0,
64 BGR,
65 GRAY8,
66 NV12,
67 I420,
68 UNKNOWN,
72 std::string color_space;
76 int sample_rate = 0;
78 bool interleaved = true;
81struct TokensSpec {
82 int vocab_size = 0;
85struct EncodedSpec {
87 H264 = 0,
88 H265,
89 RTP_H264,
90 RTP_H265,
91 JPEG,
92 UNKNOWN,
100 int32_t zero_point = 0;
103 std::vector<int32_t> zero_points;
107 int tile_width = 0;
108 int tile_height = 0;
109 int tile_channels = 0;
124 std::size_t size_bytes = 0;
136 if (unmap)
137 unmap();
138 data = other.data;
139 size_bytes = other.size_bytes;
140 unmap = std::move(other.unmap);
141 keepalive = std::move(other.keepalive);
150 if (unmap)
151 unmap();
164 std::size_t size_bytes = 0;
170 std::size_t size_bytes = 0;
174 std::uint64_t sima_mem_target_flags = 0;
175 std::uint64_t sima_mem_flags = 0;
176 std::vector<Segment> sima_segments;
179 Mapping mapping;
180 if (map_fn) {
181 mapping = map_fn(mode);
184 mapping.size_bytes = size_bytes;
186 if (!mapping.keepalive) {
193std::shared_ptr<Storage> make_cpu_owned_storage(std::size_t size_bytes);
194std::shared_ptr<Storage> make_cpu_external_storage(void* data, std::size_t size_bytes,
201 std::vector<int64_t> strides_bytes;
202 int64_t byte_offset = 0;
214struct Nv12Mapped {
230struct I420Mapped {
240 std::vector<int64_t> strides_bytes;
241 int64_t byte_offset = 0;
248 return planes.empty();
250 bool is_composite() const {
251 return !planes.empty();
254 bool is_contiguous() const {
255 if (shape.empty())
257 if (strides_bytes.empty())
259 std::size_t elem = dtype_bytes(dtype);
263 for (int i = static_cast<int>(shape.size()) - 1; i >= 0; --i) {
264 if (strides_bytes[static_cast<size_t>(i)] != expected)
266 expected *= shape[static_cast<size_t>(i)];
274 return &plane;
280 return try_plane(role) != nullptr;
291 if (read_only && mode != MapMode::Read) {
294 if (!storage)
297 if (!base.data)
299 Mapping out = std::move(base);
303 if (byte_offset != 0) {
304 out.data = static_cast<uint8_t*>(out.data) + byte_offset;
305 if (out.size_bytes > static_cast<std::size_t>(byte_offset)) {
306 out.size_bytes = out.size_bytes - static_cast<std::size_t>(byte_offset);
311 if (!validate(&err)) {
319 return map(MapMode::Read);
322 return map(MapMode::Write);
324 Mapping view(MapMode mode = MapMode::Read) const;
326 return view(MapMode::Read);
330 if (read_only) {
340 Tensor contiguous() const;
346 Tensor to_cpu_if_needed() const;
349 std::optional<Nv12Mapped> map_nv12_read() const;
350 std::size_t nv12_required_bytes() const;
351 bool copy_nv12_contiguous_to(uint8_t* dst, std::size_t dst_size) const;
352 std::vector<uint8_t> copy_nv12_contiguous() const;
354 std::optional<I420Mapped> map_i420_read() const;
355 std::size_t i420_required_bytes() const;
356 bool copy_i420_contiguous_to(uint8_t* dst, std::size_t dst_size) const;
357 std::vector<uint8_t> copy_i420_contiguous() const;
359 std::size_t dense_bytes_tight() const;
360 bool copy_dense_bytes_tight_to(uint8_t* dst, std::size_t dst_size) const;
361 std::vector<uint8_t> copy_dense_bytes_tight() const;
363 bool copy_payload_bytes_to(uint8_t* dst, std::size_t dst_size) const;
364 std::vector<uint8_t> copy_payload_bytes() const;
369 std::optional<ImageSpec::PixelFormat> image_format() const;
373 std::string debug_string() const;
376 static Tensor from_cv_mat(const cv::Mat& mat,
378 bool read_only = true);
379 std::optional<CvMatView> map_cv_mat_view(ImageSpec::PixelFormat desired) const;
380 cv::Mat to_cv_mat_copy(ImageSpec::PixelFormat desired) const;
385 if (device.type != DeviceType::CPU) {
388 if (!is_dense()) {
391 if (!is_contiguous()) {
397 return reinterpret_cast<const T*>(static_cast<const uint8_t*>(storage->data) + byte_offset);
400 static std::size_t dtype_bytes(simaai::neat::TensorDType dtype) {
401 switch (dtype) {
402 case simaai::neat::TensorDType::UInt8:
403 case simaai::neat::TensorDType::Int8:
405 case simaai::neat::TensorDType::UInt16:
406 case simaai::neat::TensorDType::Int16:
407 case simaai::neat::TensorDType::BFloat16:
409 case simaai::neat::TensorDType::Int32:
410 case simaai::neat::TensorDType::Float32:
412 case simaai::neat::TensorDType::Float64:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.1.