用于调用ascendc编写的算子
Project description
1 功能描述
由于在ascendc算子开发过程中运行算子比较复杂,为了简化算子的运行,将运行算子变成可以用python直接调用的函数。所以编写了此代码。
2 安装
pip install l0n0lacl
3 运行算子实例
3.1 先切换到cann环境,比如我的环境是:
source /home/HwHiAiUser/Ascend/ascend-toolkit/set_env.sh
3.2 设置要用到的设备
export ASCEND_VISIBLE_DEVICES=0,1
3.3 运行算子
from l0n0lacl import *
import numpy as np
import ctypes
fn = 算子运行器('Abs')
a = np.random.uniform(-2, -1, (2000,2000))
a_out = np.zeros_like(a)
out = fn(a, a_out)
print(a)
print(out[1])
a = 张量(a).切换到设备(1)
a_out = 张量(a_out).切换到设备(1)
out = fn(a, a_out)
print(a)
print(out[1])
fn = 算子运行器('InplaceAcos')
a = np.random.uniform(-1, 1, (2000,2000)).astype(np.float16)
print(a)
out = fn(a)
print(out[0])
fn = 算子运行器('AdaptiveAvgPool2d')
a = np.random.uniform(0, 100, (2, 100, 100)).astype(np.float32)
out = np.zeros((2, 3, 3), dtype=a.dtype)
a = 张量(a, 格式=张量格式.NCL)
out = 张量(out).变更格式(张量格式.NCL)
output = fn(a, [3, 3], out)
print(output[2])
fn = 算子运行器('Addmv')
s = np.ones(3, dtype=np.float32)
mat = np.random.uniform(-1, 1, (3, 4)).astype(np.float32)
vec = np.random.uniform(-1, 1, 4).astype(np.float32)
alpha = 标量(1.2)
beta = 标量(1.1)
out = np.zeros(3, dtype=np.float32)
output = fn(s, mat, vec, alpha, beta, out, ctypes.c_int8(1))
print(output[-2])
3.3 算子查找顺序
如果 ${NO_VENDORS_OPP} != '1':
查找 ${ASCEND_OPP_PATH}/vendors目录(自己写的算子默认安装目录)
查找 ${ASCEND_HOME_PATH}/lib64/libopapi.so 支持的算子(也就是官方算子包)
NO_VENDORS_OPP如果不需要使用自定义算子, 可以添加此环境变量ASCEND_OPP_PATHcann自带环境变量 在(source /home/HwHiAiUser/Ascend/ascend-toolkit/set_env.sh)时设置ASCEND_HOME_PATHcann自带环境变量在(source /home/HwHiAiUser/Ascend/ascend-toolkit/set_env.sh)时设置
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
l0n0lacl-2.0.2.tar.gz
(18.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
l0n0lacl-2.0.2-py3-none-any.whl
(18.7 kB
view details)
File details
Details for the file l0n0lacl-2.0.2.tar.gz.
File metadata
- Download URL: l0n0lacl-2.0.2.tar.gz
- Upload date:
- Size: 18.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a18a4e8643e65c3eceb1f7a75c575ca7ebe036b6462f3f8ab9dfa79f8e010a5
|
|
| MD5 |
271bdec24b5a8ae0c108f5f341497ac0
|
|
| BLAKE2b-256 |
2c80f0b18109f1562c816c7e67ce48c92040598f057e8311fe3187ef551b02a9
|
File details
Details for the file l0n0lacl-2.0.2-py3-none-any.whl.
File metadata
- Download URL: l0n0lacl-2.0.2-py3-none-any.whl
- Upload date:
- Size: 18.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d98d72dc9c36daf1fb27a14169132a1c2e5365c39d9161bb1ea7c76f623d84e
|
|
| MD5 |
951accc150b4951677330d9b76d0d8b6
|
|
| BLAKE2b-256 |
fd7ca128776ebe0c8a7aa91cf1f0ea4d21b0cd590d501efeac9121268f97831d
|