Skip to content

Commit e28b968

Browse files
wanglushengkalcohol
wanglusheng
authored andcommitted
fix cffi life cycle issue
1 parent 3dd8d86 commit e28b968

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

axengine/_axe.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -216,32 +216,39 @@ def __init__(
216216
_inputs= engine_cffi.new(
217217
"AX_ENGINE_IO_BUFFER_T[{}]".format(self._io[0].nInputSize)
218218
)
219-
self._io[0].pInputs = _inputs
220219
_outputs = engine_cffi.new(
221220
"AX_ENGINE_IO_BUFFER_T[{}]".format(self._io[0].nOutputSize)
222221
)
222+
self._io_buffers = (_inputs, _outputs)
223+
self._io[0].pInputs = _inputs
223224
self._io[0].pOutputs = _outputs
225+
226+
self._io_inputs_pool = []
224227
for i in range(len(self.get_inputs())):
225228
max_buf = 0
226229
for j in range(self._shape_count):
227230
max_buf = max(max_buf, self._info[j][0].pInputs[i].nSize)
228231
self._io[0].pInputs[i].nSize = max_buf
229232
phy = engine_cffi.new("AX_U64*")
230233
vir = engine_cffi.new("AX_VOID**")
234+
self._io_inputs_pool.append((phy, vir))
231235
ret = sys_lib.AX_SYS_MemAllocCached(
232236
phy, vir, self._io[0].pInputs[i].nSize, self._align, self._cmm_token
233237
)
234238
if 0 != ret:
235239
raise RuntimeError("Failed to allocate memory for input.")
236240
self._io[0].pInputs[i].phyAddr = phy[0]
237241
self._io[0].pInputs[i].pVirAddr = vir[0]
242+
243+
self._io_outputs_pool = []
238244
for i in range(len(self.get_outputs())):
239245
max_buf = 0
240246
for j in range(self._shape_count):
241247
max_buf = max(max_buf, self._info[j][0].pOutputs[i].nSize)
242248
self._io[0].pOutputs[i].nSize = max_buf
243249
phy = engine_cffi.new("AX_U64*")
244250
vir = engine_cffi.new("AX_VOID**")
251+
self._io_outputs_pool.append((phy, vir))
245252
ret = sys_lib.AX_SYS_MemAllocCached(
246253
phy, vir, self._io[0].pOutputs[i].nSize, self._align, self._cmm_token
247254
)

0 commit comments

Comments
 (0)