modify: docs sail api

This commit is contained in:
2025-10-17 16:30:24 +08:00
parent c947bf5b52
commit 34b74a8825
9 changed files with 582 additions and 25 deletions
+75
View File
@@ -0,0 +1,75 @@
# sail 基础函数
## get_available_tpu_num
获取当前设备中可用的TPU数量
**接口形式:**
```python
def get_available_tpu_num() -> int
```
**返回值说明**:
返回当前设备中可用 TPU的数量
## set_print_flag
设置是否打印程序的计算耗时信息
**接口形式:**
```python
def set_print_flag(print_flag: bool) -> None
```
**参数说明**
- print_flag:bool
print_flag 为 True 时,打印程序的计算主要的耗时信息,否则不打印
## set_dump_io_flag
设置是否存储输入时间和输出时间。
**接口形式:**
```python
def set_dump_io_flag(dump_io_flag: bool) -> None
```
**参数说明**
- dump_io_flag: bool
dump_io_flag为True时,存储输入数据和输出数据,否则不存储。
## set_decoder_env
设置Decoder的环境变量,必须在Decoder构造前设置,否则使用默认值。
**接口形式:**
```python
def set_decoder_env(env_name: str, env_value: str) -> None
```
**参数说明:**
- env_name: str
选择设置Decoder的属性名称,可选的属性名称有:
- ‘refcounted_frames’ 设置为1时,解码出来的图像需要程序手动释放,为0时由Decoder自动释放。
- ‘extra_frame_buffer_num’ 设置Decoder的最大缓存帧数
- ‘rtsp_transport’ 设置RTSP采用的传输协议
- ‘stimeout’ 设置阻塞超时时间
- ‘rtsp_flags’ 设置RTSP是否自定义IO
- ‘buffer_size’ 设置缓存大小
- ‘max_delay’ 设置最大时延
- ‘probesize’ 解析文件时读取的最大字节数
- ‘analyzeduration’ 解析文件时读取的最大时长
- env_value: str
+21
View File
@@ -0,0 +1,21 @@
# sail 数据类型
定义sophon环境中常用的数据类型
**接口形式**
```python
sail.Dtype.BM_FLOAT32
sail.Dtype.BM_INT8
sail.Dtype.BM_UINT8
sail.Dtype.BM_INT32
sail.Dtype.BM_UINT32
```
**参数说明**
- sail.Dtype.BM_FLOAT32 数据类型为float32
- sail.Dtype.BM_INT8 数据类型为int8
- sail.Dtype.BM_UINT8 数据类型为uint8
- sail.Dtype.BM_INT32 数据类型为int32
- sail.Dtype.BM_UINT32 数据类型为uint32
+156
View File
@@ -0,0 +1,156 @@
# 填充属性
PaddingAtrr中存储了数据padding的各项属性,可通过配置PaddingAtrr进行数据填充
## \_\_init\_\_
初始化 PaddingAtrr
**接口形式:**
```python
def __init__(self)
def __init__(self, stx: int, sty: int, width: int, height: int, r: int, g: int, b: int)
```
**参数说明:**
- stx: int
原图像相对于目标图像在x方向上的偏移量
- sty: int
原图像相对于目标图像在y方向上的偏移量
- width: int
在 padding 的同时可对原图像进行 resize,width 为原图像 resize 后的宽,若不进行 resize,则 width 为原图像的宽
- height: int
在 padding 的同时对原图像进行 resize,height 为原图像 resize 后的高,若不进行 resize,则 height 为原图像的高
- r: int
padding 时在 R 通道上填充的像素值
- g: int
padding 时在 G 通道上填充的像素值
- b: int
padding 时在B通道上填充的像素值
## set_stx
设置原图像相对于目标图像在 x 方向上的偏移量
**接口形式**
```python
def set_stx(self, stx: int) -> None
```
**参数说明**
- stx: int
原图像相对于目标图像在x方向上的偏移量
## set_sty
设置原图像相对于目标图像在y方向上的偏移量
**接口形式:**
```python
def set_sty(self, sty: int) -> None
```
**参数说明:**
- sty: int
原图像相对于目标图像在y方向上的偏移量
## set_w
设置原图像resize后的width
**接口形式:**
```python
def set_w(self, width: int) -> None
```
**参数说明:**
- width: int
在padding的同时可对原图像进行resize,width为原图像resize后的宽,若不进行resize,则width为原图像的宽
## set_h
设置原图像resize后的height
**接口形式:**
```python
def set_h(self, height: int) -> None
```
**参数说明:**
- height: int
在padding的同时可对原图像进行resize,height为原图像resize后的高,若不进行resize,则height为原图像的高
## set_r
设置R通道上的padding值
**接口形式:**
```python
def set_r(self, r: int) -> None
```
**参数说明**
- r: int
R通道上的padding值
## set_g
设置G通道上的padding值
**接口形式:**
```python
def set_g(self, g: int) -> None
```
**参数说明**
- g: int
G通道上的padding值
## set_b
设置B通道上的padding值
**接口形式:**
```python
def set_b(self, b: int) -> None
```
**参数说明**
- b: int
B通道上的padding值
+51
View File
@@ -0,0 +1,51 @@
# 设备句柄
Handle是设备句柄的包装类,在程序中用于设备的标识。
## \_\_init\_\_
初始化 Handle
**接口形式:**
```python
def __init__(self, tpu_id: int)
```
**参数说明:**
- tpu_id: int
创建 Handle 使用的TPU的id号
## get_device_id
获取 Handle 中 TPU的id
**接口形式:**
```python
def get_device_id(self) -> int
```
**返回值说明:**
- tpu_id: int
Handle 中的 TPU 的 id 号
## get_sn
获取 Handle 中标识设备的序列码
**接口形式:**
```python
def get_sn(self) -> str
```
**返回值说明**
- serial_number: str
返回 Handle 中设备的序列码
+17
View File
@@ -0,0 +1,17 @@
# resize 插值策略(sail.bmcv_resize_algorithm)
定义图像resize中常见的插值策略
**接口形式**
```python
sail.bmcv_resize_algorithm.BMCV_INTER_NEAREST
sail.bmcv_resize_algorithm.BMCV_INTER_LINEAR
sail.bmcv_resize_algorithm.BMCV_INTER_BICUBIC
```
**参数说明**
- sail.bmcv_resize_algorithm.BMCV_INTER_NEAREST 最近邻插值算法
- sail.bmcv_resize_algorithm.BMCV_INTER_LINEAR 双线性插值算法
- sail.bmcv_resize_algorithm.BMCV_INTER_BICUBIC 双三次插值算法
+240
View File
@@ -0,0 +1,240 @@
# Tensor 张量
Tensor 是模型推理的输入输出类型,包含了数据信息,实现内容管理
## \_\_init\_\_
初始化 Tensor,并为 Tensor 分配内存
**接口形式1**
```python
def __init__(self, handle: Handle, data: np.arrat, own_sys_data=True)
```
**参数说明1**
- handle: sail.Handle
设备标识 Handle
- array_data: numpy.array
利用 numpy.array 类型初始化 Tensor,其数据类型可以是 np.float32,np.int8,np.uint8
- own_sys_data:bool
指示该 Tensor 是否拥有 system memory,如果为 False,则直接将数据复制到 device memory
**接口形式2**
```python
def __init__(self, handle: Handle, shape: tuple, dtype: Dtype, own_sys_data: bool, own_dev_data: bool)
```
**参数说明2**
- handle: sail.Handle
设备标识 Handle
- shape: tuple
设置 Tensor 的 shape
- dtype: sail.Dtype
Tensor 的数据类型
- own_sys_data: bool
指示 Tensor 是否拥有 system memory
- own_dev_data: bool
指示 Tensor 是否拥有 device memory
## shape
获取 Tensor 的 shape
**接口形式:**
```python
def shape(self) -> list :
```
**返回值说明:**
- tensor_shape : list
返回Tensor的shape的列表。
## asnumpy
获取Tensor中系统内存的数据,返回numpy.array类型。
**接口形式:**
```python
def asnumpy(self) -> numpy.array
def asnumpy(self, shape: tuple) -> numpy.array
```
**参数说明:**
- shape: tuple
可对Tensor中的数据reshape,返回形状为shape的numpy.array
**返回值说明**
返回Tensor中系统内存的数据,返回类型为numpy.array。
## update_data
更新Tensor中系统内存的数据
**接口形式:**
```python
def update_data(self, data: numpy.array) -> None
```
**参数说明:**
- data: numpy.array
更新的数据,数据size不能超过Tensor的size,Tensor的shape将保持不变。
## scale_from
先对data按比例缩放,再将数据更新到Tensor的系统内存。
**接口形式:**
```python
def scale_from(self, data: numpy.array, scale: float32)->None
```
**参数说明:**
- data: numpy.array
对data进行scale,再将数据更新到Tensor的系统内存。
- scale: float32
等比例缩放时的尺度。
## scale_to
先对Tensor进行等比例缩放,再将数据返回到系统内存。
**接口形式:**
```python
def scale_to(self, scale: float32)->numpy.array
def scale_to(self, scale: float32, shape: tuple)->numpy.array
```
**参数说明:**
- scale: float32
等比例缩放时的尺度。
- shape: tuple
数据返回前可进行reshape,返回shape形状的数据。
**返回值说明:**
- data: numpy.array
将处理后的数据返回至系统内存,返回numpy.array
## reshape
对Tensor进行reshape
**接口形式:**
```python
def reshape(self, shape: list)->None
```
**参数说明:**
- shape: list
设置期望得到的新shape。
# own_sys_data
查询该Tensor是否拥有系统内存的数据指针。
**接口形式:**
```python
def own_sys_data(self)->bool
```
**返回值说明:**
- judge_ret: bool
如果拥有系统内存的数据指针则返回True,否则False。
## own_dev_data
查询该Tensor是否拥有设备内存的数据
**接口形式:**
```python
def own_dev_data(self)->bool
```
**返回值说明:**
- judge_ret : bool
如果拥有设备内存中的数据则返回True,否则False。
## sync_s2d
将Tensor中的数据从系统内存拷贝到设备内存。
**接口形式:**
```python
def sync_s2d(self)->None
def sync_s2d(self, size)->None
```
**参数说明:**
- size: int
将特定size字节的数据从系统内存拷贝到设备内存。
## sync_d2s
将Tensor中的数据从设备内存拷贝到系统内存。
**接口形式:**
```python
def sync_d2s(self)->None
def sync_d2s(self, size: int)->None
```
**参数说明:**
- size: int
将特定size字节的数据从设备内存拷贝到系统内存。