14
14
15
15
import numpy as np
16
16
17
- # try:
18
- # import qaicrt
19
- # except ImportError:
20
- # import platform
21
- # import sys
22
-
23
- # sys.path.append(f"/opt/qti-aic/dev/lib/{platform.machine()}")
24
- # import qaicrt
25
-
26
17
27
18
class QAICInferenceSession :
28
19
_qaicrt = None
@@ -135,14 +126,25 @@ def output_names(self) -> List[str]:
135
126
return [binding .name for binding in self .bindings if binding .dir == self .aicapi .BUFFER_IO_TYPE_OUTPUT ]
136
127
137
128
def activate (self ):
129
+ """Activate qpc"""
130
+
138
131
self .program .activate ()
139
132
self .execObj = self .qaicrt .ExecObj (self .context , self .program )
140
133
141
134
def deactivate (self ):
135
+ """Deactivate qpc"""
136
+
142
137
del self .execObj
143
138
self .program .deactivate ()
144
139
145
140
def set_buffers (self , buffers : Dict [str , np .ndarray ]):
141
+ """
142
+ Provide buffer mapping for input and output
143
+
144
+ Args:
145
+ :buffer (Dict[str, np.ndarray]): Parameter for buffer mapping.
146
+ """
147
+
146
148
for buffer_name , buffer in buffers .items ():
147
149
if buffer_name not in self .binding_index_map :
148
150
warn (f'Buffer: "{ buffer_name } " not found' )
@@ -155,9 +157,26 @@ def set_buffers(self, buffers: Dict[str, np.ndarray]):
155
157
)
156
158
157
159
def skip_buffers (self , skipped_buffer_names : List [str ]):
160
+ """
161
+ skip buffer mapping for given list of buffer names
162
+
163
+ Args:
164
+ :skipped_buffer_name: List[str]. List of buffer name to be skipped.
165
+ """
166
+
158
167
self .set_buffers ({k : np .array ([]) for k in skipped_buffer_names })
159
168
160
169
def run (self , inputs : Dict [str , np .ndarray ]) -> Dict [str , np .ndarray ]:
170
+ """
171
+ Execute on cloud AI 100
172
+
173
+ Args:
174
+ :inputs (Dict[str, np.ndarray]): Processed numpy inputs for the model.
175
+
176
+ Return:
177
+ :Dict[str, np.ndarray]:
178
+ """
179
+
161
180
self .set_buffers (inputs )
162
181
if self .execObj .setData (self .qbuffers , self .buf_dims ) != self .qaicrt .QStatus .QS_SUCCESS :
163
182
raise MemoryError ("Failed to setData" )
0 commit comments