You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.9 KiB
64 lines
1.9 KiB
10 months ago
|
from myutils.ConfigManager import myCongif
|
||
|
if myCongif.get_data("model_platform") == "acl":
|
||
|
import acl
|
||
|
|
||
|
SUCCESS = 0 # 成功状态值
|
||
|
FAILED = 1 # 失败状态值
|
||
|
|
||
|
class ACLModeManger:
|
||
|
def __init__(self,):
|
||
|
self.acl_ok = False
|
||
|
|
||
|
def __del__(self):
|
||
|
pass
|
||
|
|
||
|
#初始化acl相关资源--一个进程内只能调用一次acl.init接口
|
||
|
@staticmethod
|
||
|
def init_acl(device_id):
|
||
|
# '''acl初始化函数'''
|
||
|
ret = acl.init() # 0-成功,其它失败
|
||
|
if ret:
|
||
|
raise RuntimeError(ret)
|
||
|
|
||
|
ret = acl.rt.set_device(device_id) # 指定当前进程或线程中用于运算的Device。可以进程或线程中指定。*多设备时可以放线程*
|
||
|
# 在某一进程中指定Device,该进程内的多个线程可共用此Device显式创建Context(acl.rt.create_context接口)。
|
||
|
if ret:
|
||
|
raise RuntimeError(ret)
|
||
|
print('ACL init Device Successfully')
|
||
|
|
||
|
return True
|
||
|
|
||
|
#去初始化
|
||
|
@staticmethod
|
||
|
def del_acl(device_id):
|
||
|
'''Device去初始化'''
|
||
|
ret = acl.rt.reset_device(device_id) # 释放Device
|
||
|
if ret:
|
||
|
raise RuntimeError(ret)
|
||
|
|
||
|
ret = acl.finalize() # 去初始化 0-成功,其它失败 --官方文档不建议放析构函数中执行
|
||
|
if ret:
|
||
|
raise RuntimeError(ret)
|
||
|
print('ACL finalize Successfully')
|
||
|
return True
|
||
|
|
||
|
@staticmethod
|
||
|
def th_inti_acl(device_id):
|
||
|
# 线程申请context
|
||
|
context, ret = acl.rt.create_context(device_id) # 显式创建一个Context
|
||
|
if ret:
|
||
|
raise RuntimeError(ret)
|
||
|
print('Init TH-Context Successfully')
|
||
|
return context
|
||
|
|
||
|
@staticmethod
|
||
|
def th_del_acl(context):
|
||
|
#线程释放context
|
||
|
ret = acl.rt.destroy_context(context) # 释放 Context
|
||
|
if ret:
|
||
|
raise RuntimeError(ret)
|
||
|
print('Deinit TH-Context Successfully')
|
||
|
return True
|
||
|
|
||
|
|