Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ root@ax650:~/samples# python3 classification.py -m /opt/data/npu/models/mobilene

- [zylo117](https://github.com/zylo117): 提供了基于 cffi 的 AXCL Runtime Python API 实现
- [nnn](https://github.com/nnn112358),[HongJie Li](https://github.com/techshoww) 和 [Shinichi Tanaka](https://github.com/s1tnk) 报告 cffi 的使用问题,[Shinichi Tanaka](https://github.com/s1tnk) 提供了解决方案

- [yuyun](https://github.com/yuyun2000): 修复了加载模型时会在系统内存重复占用内存的bug

## 关联项目

Expand Down
11 changes: 7 additions & 4 deletions axengine/_axe.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,16 @@ def __init__(
self._context = engine_cffi.new("uint64_t **")
self._io = engine_cffi.new("AX_ENGINE_IO_T *")

# model buffer, almost copied from onnx runtime
import mmap

if isinstance(path_or_bytes, (str, os.PathLike)):
self._model_name = os.path.splitext(os.path.basename(path_or_bytes))[0]
with open(path_or_bytes, "rb") as f:
data = f.read()
self._model_buffer = engine_cffi.new("char[]", data)
self._model_buffer_size = len(data)
# Use memory mapping without actually loading into memory
mmapped_file = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
self._model_buffer = engine_cffi.from_buffer("char[]", mmapped_file)
self._model_buffer_size = len(mmapped_file)
self._mmapped_file = mmapped_file # keep
elif isinstance(path_or_bytes, bytes):
self._model_buffer = engine_cffi.new("char[]", path_or_bytes)
self._model_buffer_size = len(path_or_bytes)
Expand Down