|
27 | 27 | QcomChipset,
|
28 | 28 | )
|
29 | 29 | from executorch.backends.qualcomm.utils.utils import capture_program
|
30 |
| -from executorch.examples.qualcomm.scripts.utils import SimpleADB |
| 30 | +from executorch.examples.qualcomm.scripts.utils import ( |
| 31 | + generate_inputs, |
| 32 | + make_output_dir, |
| 33 | + SimpleADB, |
| 34 | +) |
31 | 35 |
|
32 | 36 | from executorch.exir.backend.backend_api import to_backend
|
33 | 37 | from executorch.exir.backend.compile_spec_schema import CompileSpec
|
@@ -133,6 +137,7 @@ class TestQNN(unittest.TestCase):
|
133 | 137 | use_16a16w: str = "16a16w"
|
134 | 138 | use_16a4w: str = "16a4w"
|
135 | 139 | shared_buffer: bool = False
|
| 140 | + enable_x86_64: bool = False |
136 | 141 |
|
137 | 142 | def _assert_outputs_equal(self, model_output, ref_output):
|
138 | 143 | self.assertTrue(len(ref_output) == len(model_output))
|
@@ -201,40 +206,75 @@ def verify_output(
|
201 | 206 | tmp_dir,
|
202 | 207 | )
|
203 | 208 |
|
204 |
| - device_output_dir = f"{tmp_dir}/outputs" |
205 |
| - device_outputs = [] |
| 209 | + output_dir = f"{tmp_dir}/outputs" |
| 210 | + outputs = [] |
206 | 211 | etdump_path = f"{tmp_dir}/etdump.etdp"
|
207 | 212 |
|
208 | 213 | def post_process():
|
209 |
| - for i, f in enumerate(sorted(os.listdir(device_output_dir))): |
210 |
| - filename = os.path.join(device_output_dir, f) |
| 214 | + for i, f in enumerate(sorted(os.listdir(output_dir))): |
| 215 | + filename = os.path.join(output_dir, f) |
211 | 216 | output = np.fromfile(filename, dtype=ref_outputs[i].numpy().dtype)
|
212 | 217 | output = torch.from_numpy(output).reshape(ref_outputs[i].shape)
|
213 |
| - device_outputs.append(output) |
| 218 | + outputs.append(output) |
214 | 219 |
|
215 | 220 | def validate_profile():
|
216 | 221 | inspector = Inspector(etdump_path=etdump_path, etrecord=etrecord_path)
|
217 | 222 | self.assertTrue(
|
218 | 223 | len(inspector.to_dataframe().index) == expected_profile_events
|
219 | 224 | )
|
220 | 225 |
|
221 |
| - adb = SimpleADB( |
222 |
| - qnn_sdk=os.getenv("QNN_SDK_ROOT"), |
223 |
| - build_path=self.build_folder, |
224 |
| - pte_path=pte_fname, |
225 |
| - workspace="/data/local/tmp/qnn_executorch_test", |
226 |
| - device_id=self.device, |
227 |
| - host_id=self.host, |
228 |
| - soc_model=self.model, |
229 |
| - error_only=self.error_only, |
230 |
| - ) |
231 |
| - adb.push(inputs=[sample_inputs], input_list=input_list) |
232 |
| - adb.execute() |
233 |
| - adb.pull(output_path=tmp_dir, callback=post_process) |
234 |
| - self._assert_outputs_equal(device_outputs, ref_outputs) |
| 226 | + if self.enable_x86_64: |
| 227 | + generate_inputs(tmp_dir, "input_list.txt", [sample_inputs], input_list) |
| 228 | + make_output_dir(output_dir) |
| 229 | + |
| 230 | + target = "x86_64-linux-clang" |
| 231 | + qnn_sdk = os.environ.get("QNN_SDK_ROOT", None) |
| 232 | + assert qnn_sdk, "QNN_SDK_ROOT was not found in environment variable" |
| 233 | + |
| 234 | + build_path = "build_x86_64" |
| 235 | + cmds = [ |
| 236 | + # export LD_LIBRARY_PATH to QNN_SDK_ROOT |
| 237 | + f"export LD_LIBRARY_PATH={qnn_sdk}/lib/{target}/:{self.executorch_root}/{build_path}/lib && " |
| 238 | + # qnn_executor_runner |
| 239 | + f"{self.executorch_root}/{build_path}/examples/qualcomm/qnn_executor_runner", |
| 240 | + f"--model_path {pte_fname}", |
| 241 | + f"--input_list_path {tmp_dir}/input_list.txt", |
| 242 | + f"--output_folder_path {output_dir}", |
| 243 | + ] |
| 244 | + |
| 245 | + subprocess.run( |
| 246 | + " ".join(cmds), |
| 247 | + shell=True, |
| 248 | + executable="/bin/bash", |
| 249 | + capture_output=True, |
| 250 | + cwd=tmp_dir, |
| 251 | + ) |
| 252 | + |
| 253 | + # Verify the outputs |
| 254 | + post_process() |
| 255 | + self._assert_outputs_equal(outputs, ref_outputs) |
| 256 | + |
| 257 | + # Verify the etdump |
| 258 | + if expected_profile_events != -1: |
| 259 | + validate_profile() |
| 260 | + else: |
| 261 | + adb = SimpleADB( |
| 262 | + qnn_sdk=os.getenv("QNN_SDK_ROOT"), |
| 263 | + build_path=self.build_folder, |
| 264 | + pte_path=pte_fname, |
| 265 | + workspace="/data/local/tmp/qnn_executorch_test", |
| 266 | + device_id=self.device, |
| 267 | + host_id=self.host, |
| 268 | + soc_model=self.model, |
| 269 | + error_only=self.error_only, |
| 270 | + ) |
| 271 | + adb.push(inputs=[sample_inputs], input_list=input_list) |
| 272 | + adb.execute() |
| 273 | + adb.pull(output_path=tmp_dir, callback=post_process) |
| 274 | + self._assert_outputs_equal(outputs, ref_outputs) |
235 | 275 |
|
236 |
| - if expected_profile_events != -1: |
237 |
| - adb.pull_etdump(etdump_path, callback=validate_profile) |
| 276 | + if expected_profile_events != -1: |
| 277 | + adb.pull_etdump(etdump_path, callback=validate_profile) |
238 | 278 |
|
239 | 279 | def lower_module_and_test_output(
|
240 | 280 | self,
|
@@ -362,6 +402,8 @@ def _insert_clone(
|
362 | 402 | (node,),
|
363 | 403 | )
|
364 | 404 | inserted_node.meta["val"] = node.meta["val"]
|
| 405 | + if "quant_attrs" in node.meta: |
| 406 | + inserted_node.meta["quant_attrs"] = node.meta["quant_attrs"] |
365 | 407 | for user in users:
|
366 | 408 | user.replace_input_with(node, inserted_node)
|
367 | 409 |
|
|
0 commit comments