Skip to main content

Tensor Struct

Declaration

struct simaai::neat::Tensor { ... }

Included Headers

#include <TensorCore.h>

Public Member Functions Index

boolis_dense () const
boolis_composite () const
boolis_contiguous () const
const Plane *try_plane (PlaneRole role) const noexcept
boolhas_plane (PlaneRole role) const noexcept
const Plane &plane (PlaneRole role) const
Mappingmap (MapMode mode) const
Mappingmap_read () const
Mappingmap_write () const
Mappingview (MapMode mode=MapMode::Read) const
Mappingview_read () const
template <typename T>
T *data_ptr ()
template <typename T>
const T *data_ptr () const
Tensorcontiguous () const
Tensorclone () const
Tensorto (Device target) const
Tensorcpu () const
Tensorcvu () const
Tensormla (bool force=false) const
Tensorto_cpu_if_needed () const
boolvalidate (std::string *err) const
std::optional< Nv12Mapped >map_nv12_read () const
std::size_tnv12_required_bytes () const
boolcopy_nv12_contiguous_to (uint8_t *dst, std::size_t dst_size) const
std::vector< uint8_t >copy_nv12_contiguous () const
std::optional< I420Mapped >map_i420_read () const
std::size_ti420_required_bytes () const
boolcopy_i420_contiguous_to (uint8_t *dst, std::size_t dst_size) const
std::vector< uint8_t >copy_i420_contiguous () const
std::size_tdense_bytes_tight () const
boolcopy_dense_bytes_tight_to (uint8_t *dst, std::size_t dst_size) const
std::vector< uint8_t >copy_dense_bytes_tight () const
boolcopy_payload_bytes_to (uint8_t *dst, std::size_t dst_size) const
std::vector< uint8_t >copy_payload_bytes () const
intwidth () const
intheight () const
intchannels () const
std::optional< ImageSpec::PixelFormat >image_format () const
boolis_nv12 () const
boolis_i420 () const
std::stringdebug_string () const

Private Member Functions Index

template <typename T>
const T *const_data_ptr () const

Public Member Attributes Index

std::shared_ptr< Storage >storage
simaai::neat::TensorDTypedtype = simaai::neat::TensorDType::UInt8
simaai::neat::TensorLayoutlayout = simaai::neat::TensorLayout::Unknown
std::vector< int64_t >shape
std::vector< int64_t >strides_bytes
int64_tbyte_offset = 0
Devicedevice {}
Semanticsemantic {}
std::vector< Plane >planes
boolread_only = true

Private Static Functions Index

static std::size_tdtype_bytes (simaai::neat::TensorDType dtype)

Definition at line 235 of file TensorCore.h.

Public Member Functions

channels()

int simaai::neat::Tensor::channels ()

Definition at line 368 of file TensorCore.h.

clone()

Tensor simaai::neat::Tensor::clone ()

Definition at line 341 of file TensorCore.h.

contiguous()

Tensor simaai::neat::Tensor::contiguous ()

Definition at line 340 of file TensorCore.h.

copy_dense_bytes_tight()

std::vector<uint8_t> simaai::neat::Tensor::copy_dense_bytes_tight ()

Definition at line 361 of file TensorCore.h.

copy_dense_bytes_tight_to()

bool simaai::neat::Tensor::copy_dense_bytes_tight_to (uint8_t * dst, std::size_t dst_size)

Definition at line 360 of file TensorCore.h.

copy_i420_contiguous()

std::vector<uint8_t> simaai::neat::Tensor::copy_i420_contiguous ()

Definition at line 357 of file TensorCore.h.

copy_i420_contiguous_to()

bool simaai::neat::Tensor::copy_i420_contiguous_to (uint8_t * dst, std::size_t dst_size)

Definition at line 356 of file TensorCore.h.

copy_nv12_contiguous()

std::vector<uint8_t> simaai::neat::Tensor::copy_nv12_contiguous ()

Definition at line 352 of file TensorCore.h.

copy_nv12_contiguous_to()

bool simaai::neat::Tensor::copy_nv12_contiguous_to (uint8_t * dst, std::size_t dst_size)

Definition at line 351 of file TensorCore.h.

copy_payload_bytes()

std::vector<uint8_t> simaai::neat::Tensor::copy_payload_bytes ()

Definition at line 364 of file TensorCore.h.

copy_payload_bytes_to()

bool simaai::neat::Tensor::copy_payload_bytes_to (uint8_t * dst, std::size_t dst_size)

Definition at line 363 of file TensorCore.h.

cpu()

Tensor simaai::neat::Tensor::cpu ()

Definition at line 343 of file TensorCore.h.

cvu()

Tensor simaai::neat::Tensor::cvu ()

Definition at line 344 of file TensorCore.h.

data_ptr()

template <typename T>
T* simaai::neat::Tensor::data_ptr ()
inline

Definition at line 329 of file TensorCore.h.

329 template <typename T> T* data_ptr() {
330 if (read_only) {
331 throw std::runtime_error("Tensor::data_ptr: tensor is read-only");
332 }
333 return const_cast<T*>(const_data_ptr<T>());
334 }

data_ptr()

template <typename T>
const T* simaai::neat::Tensor::data_ptr ()
inline

Definition at line 336 of file TensorCore.h.

336 template <typename T> const T* data_ptr() const {
337 return const_data_ptr<T>();
338 }

debug_string()

std::string simaai::neat::Tensor::debug_string ()

Definition at line 373 of file TensorCore.h.

dense_bytes_tight()

std::size_t simaai::neat::Tensor::dense_bytes_tight ()

Definition at line 359 of file TensorCore.h.

has_plane()

bool simaai::neat::Tensor::has_plane (PlaneRole role)
inline noexcept

Definition at line 279 of file TensorCore.h.

279 bool has_plane(PlaneRole role) const noexcept {
280 return try_plane(role) != nullptr;
281 }

height()

int simaai::neat::Tensor::height ()

Definition at line 367 of file TensorCore.h.

i420_required_bytes()

std::size_t simaai::neat::Tensor::i420_required_bytes ()

Definition at line 355 of file TensorCore.h.

image_format()

std::optional<ImageSpec::PixelFormat> simaai::neat::Tensor::image_format ()

Definition at line 369 of file TensorCore.h.

is_composite()

bool simaai::neat::Tensor::is_composite ()
inline

Definition at line 250 of file TensorCore.h.

250 bool is_composite() const {
251 return !planes.empty();
252 }

is_contiguous()

bool simaai::neat::Tensor::is_contiguous ()
inline

Definition at line 254 of file TensorCore.h.

254 bool is_contiguous() const {
255 if (shape.empty())
256 return true;
257 if (strides_bytes.empty())
258 return true;
259 std::size_t elem = dtype_bytes(dtype);
260 if (elem == 0)
261 return false;
262 std::int64_t expected = static_cast<std::int64_t>(elem);
263 for (int i = static_cast<int>(shape.size()) - 1; i >= 0; --i) {
264 if (strides_bytes[static_cast<size_t>(i)] != expected)
265 return false;
266 expected *= shape[static_cast<size_t>(i)];
267 }
268 return true;
269 }

is_dense()

bool simaai::neat::Tensor::is_dense ()
inline

Definition at line 247 of file TensorCore.h.

247 bool is_dense() const {
248 return planes.empty();
249 }

is_i420()

bool simaai::neat::Tensor::is_i420 ()

Definition at line 371 of file TensorCore.h.

is_nv12()

bool simaai::neat::Tensor::is_nv12 ()

Definition at line 370 of file TensorCore.h.

map()

Mapping simaai::neat::Tensor::map (MapMode mode)
inline

Definition at line 290 of file TensorCore.h.

290 Mapping map(MapMode mode) const {
291 if (read_only && mode != MapMode::Read) {
292 throw std::runtime_error("Tensor::map: tensor is read-only");
293 }
294 if (!storage)
295 return {};
296 Mapping base = storage->map(mode);
297 if (!base.data)
298 return base;
299 Mapping out = std::move(base);
300 if (!out.keepalive && storage) {
301 out.keepalive = std::static_pointer_cast<void>(storage);
302 }
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);
307 }
308 }
309#if defined(NEAT_VALIDATE_ON_MAP)
310 std::string err;
311 if (!validate(&err)) {
312 throw std::runtime_error("Tensor::map: " + err);
313 }
314#endif
315 return out;
316 }

map_i420_read()

std::optional<I420Mapped> simaai::neat::Tensor::map_i420_read ()

Definition at line 354 of file TensorCore.h.

map_nv12_read()

std::optional<Nv12Mapped> simaai::neat::Tensor::map_nv12_read ()

Definition at line 349 of file TensorCore.h.

map_read()

Mapping simaai::neat::Tensor::map_read ()
inline

Definition at line 318 of file TensorCore.h.

318 Mapping map_read() const {
319 return map(MapMode::Read);
320 }

map_write()

Mapping simaai::neat::Tensor::map_write ()
inline

Definition at line 321 of file TensorCore.h.

322 return map(MapMode::Write);
323 }

mla()

Tensor simaai::neat::Tensor::mla (bool force=false)

Definition at line 345 of file TensorCore.h.

nv12_required_bytes()

std::size_t simaai::neat::Tensor::nv12_required_bytes ()

Definition at line 350 of file TensorCore.h.

plane()

const Plane& simaai::neat::Tensor::plane (PlaneRole role)
inline

Definition at line 283 of file TensorCore.h.

283 const Plane& plane(PlaneRole role) const {
284 const Plane* found = try_plane(role);
285 if (!found)
286 throw std::runtime_error("Tensor::plane: plane not found");
287 return *found;
288 }

to()

Tensor simaai::neat::Tensor::to (Device target)

Definition at line 342 of file TensorCore.h.

to_cpu_if_needed()

Tensor simaai::neat::Tensor::to_cpu_if_needed ()

Definition at line 346 of file TensorCore.h.

try_plane()

const Plane* simaai::neat::Tensor::try_plane (PlaneRole role)
inline noexcept

Definition at line 271 of file TensorCore.h.

271 const Plane* try_plane(PlaneRole role) const noexcept {
272 for (const auto& plane : planes) {
273 if (plane.role == role)
274 return &plane;
275 }
276 return nullptr;
277 }

validate()

bool simaai::neat::Tensor::validate (std::string * err)

Definition at line 347 of file TensorCore.h.

view()

Mapping simaai::neat::Tensor::view (MapMode mode=MapMode::Read)

Definition at line 324 of file TensorCore.h.

view_read()

Mapping simaai::neat::Tensor::view_read ()
inline

Definition at line 325 of file TensorCore.h.

326 return view(MapMode::Read);
327 }

width()

int simaai::neat::Tensor::width ()

Definition at line 366 of file TensorCore.h.

Private Member Functions

const_data_ptr()

template <typename T>
const T* simaai::neat::Tensor::const_data_ptr ()
inline

Definition at line 384 of file TensorCore.h.

384 template <typename T> const T* const_data_ptr() const {
386 throw std::runtime_error("Tensor::data_ptr: tensor is not on CPU");
387 }
388 if (!is_dense()) {
389 throw std::runtime_error("Tensor::data_ptr: tensor is composite");
390 }
391 if (!is_contiguous()) {
392 throw std::runtime_error("Tensor::data_ptr: call cpu().contiguous() first");
393 }
394 if (!storage || !storage->data) {
395 throw std::runtime_error("Tensor::data_ptr: tensor storage is not mappable");
396 }
397 return reinterpret_cast<const T*>(static_cast<const uint8_t*>(storage->data) + byte_offset);
398 }

Public Member Attributes

byte_offset

int64_t simaai::neat::Tensor::byte_offset = 0

Definition at line 241 of file TensorCore.h.

241 int64_t byte_offset = 0;

device

Device simaai::neat::Tensor::device {}

Definition at line 242 of file TensorCore.h.

dtype

simaai::neat::TensorDType simaai::neat::Tensor::dtype = simaai::neat::TensorDType::UInt8

layout

simaai::neat::TensorLayout simaai::neat::Tensor::layout = simaai::neat::TensorLayout::Unknown

planes

std::vector<Plane> simaai::neat::Tensor::planes

Definition at line 244 of file TensorCore.h.

244 std::vector<Plane> planes;

read_only

bool simaai::neat::Tensor::read_only = true

Definition at line 245 of file TensorCore.h.

245 bool read_only = true;

semantic

Semantic simaai::neat::Tensor::semantic {}

Definition at line 243 of file TensorCore.h.

shape

std::vector<int64_t> simaai::neat::Tensor::shape

Definition at line 239 of file TensorCore.h.

239 std::vector<int64_t> shape;

storage

std::shared_ptr<Storage> simaai::neat::Tensor::storage

Definition at line 236 of file TensorCore.h.

236 std::shared_ptr<Storage> storage;

strides_bytes

std::vector<int64_t> simaai::neat::Tensor::strides_bytes

Definition at line 240 of file TensorCore.h.

240 std::vector<int64_t> strides_bytes;

Private Static Functions

dtype_bytes()

std::size_t simaai::neat::Tensor::dtype_bytes (simaai::neat::TensorDType dtype)
inline static

Definition at line 400 of file TensorCore.h.

400 static std::size_t dtype_bytes(simaai::neat::TensorDType dtype) {
401 switch (dtype) {
404 return 1;
408 return 2;
411 return 4;
413 return 8;
414 }
415 return 0;
416 }

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.1.