harmony 鸿蒙tensor.h

  • 2025-06-12
  • 浏览 (5)

tensor.h

Overview

Provides tensor-related APIs, which can be used to create tensors and modify tensor information. These APIs are non-thread-safe.

Since

9

Related Modules

MindSpore

Summary

Types

Name Description
OH_AI_TensorHandle Defines the handle of a tensor object.
OH_AI_AllocatorHandle Handle of the memory allocator.

Functions

Name Description
OH_AI_TensorCreate (const char *name, OH_AI_DataType type, const int64_t *shape,
size_t shape_num, const void *data, size_t data_len)
Creates a tensor object.
OH_AI_TensorDestroy (OH_AI_TensorHandle *tensor) Destroys a tensor object.
OH_AI_TensorClone (OH_AI_TensorHandle tensor) Clones a tensor.
OH_AI_TensorSetName (OH_AI_TensorHandle tensor, const char *name) Sets the tensor name.
OH_AI_TensorGetName (const OH_AI_TensorHandle tensor) Obtains the tensor name.
OH_AI_TensorSetDataType (OH_AI_TensorHandle tensor, OH_AI_DataType type) Sets the data type of a tensor.
OH_AI_TensorGetDataType (const OH_AI_TensorHandle tensor) Obtains the tensor type.
OH_AI_TensorSetShape (OH_AI_TensorHandle tensor,
const int64_t *shape, size_t shape_num)
Sets the tensor shape.
OH_AI_TensorGetShape (const OH_AI_TensorHandle tensor, size_t *shape_num) Obtains the tensor shape.
OH_AI_TensorSetFormat (OH_AI_TensorHandle tensor, OH_AI_Format format) Sets the tensor data format.
OH_AI_TensorGetFormat (const OH_AI_TensorHandle tensor) Obtains the tensor data format.
OH_AI_TensorSetData (OH_AI_TensorHandle tensor, void *data) Sets the tensor data.
OH_AI_TensorGetData (const OH_AI_TensorHandle tensor) Obtains the pointer to tensor data.
OH_AI_TensorGetMutableData (const OH_AI_TensorHandle tensor) Obtains the pointer to variable tensor data. If the data is empty, memory will be allocated.
OH_AI_TensorGetElementNum (const OH_AI_TensorHandle tensor) Obtains the number of tensor elements.
OH_AI_TensorGetDataSize (const OH_AI_TensorHandle tensor) Obtains the number of bytes of the tensor data.
OH_AI_TensorSetUserData (OH_AI_TensorHandle tensor, void *data, size_t data_size) Sets the tensor as the user data. This function allows you to reuse user data as the model input, which helps to reduce data copy by one time.
OH_AI_TensorGetAllocator(OH_AI_TensorHandle tensor) Obtains a memory allocator.
OH_AI_TensorSetAllocator(OH_AI_TensorHandle tensor, OH_AI_AllocatorHandle allocator) Sets the memory allocator.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙MindSpore Lite Kit

harmony 鸿蒙MindSpore

harmony 鸿蒙OH_AI_CallBackParam

harmony 鸿蒙OH_AI_ShapeInfo

harmony 鸿蒙OH_AI_TensorHandleArray

harmony 鸿蒙context.h

harmony 鸿蒙data_type.h

harmony 鸿蒙format.h

harmony 鸿蒙@ohos.ai.mindSporeLite (On-device AI Framework)

harmony 鸿蒙model.h

0  赞