| 192 | |
| 193 | |
| 194 | class QnnTool: |
| 195 | def __init__( |
| 196 | self, |
| 197 | tmp_dir, |
| 198 | sample_input, |
| 199 | soc_id, |
| 200 | adb, |
| 201 | build_folder, |
| 202 | workspace="/data/local/tmp/qnn_executorch_test", |
| 203 | ): |
| 204 | self.qnn_sdk = os.environ.get("QNN_SDK_ROOT", None) |
| 205 | self.ndk = os.environ.get("ANDROID_NDK_ROOT", None) |
| 206 | assert self.qnn_sdk, "QNN_SDK_ROOT was not found in environment variable" |
| 207 | assert self.ndk, "ANDROID_NDK_ROOT was not found in environment variable" |
| 208 | |
| 209 | self.tmp_dir = tmp_dir |
| 210 | self.workspace = workspace |
| 211 | self.adb = adb |
| 212 | self.sample_input = sample_input |
| 213 | self.build_folder = build_folder |
| 214 | self.root = str(Path(__file__).resolve().parents[3]) |
| 215 | self.config = { |
| 216 | "backend_extension_config": { |
| 217 | "backend_extensions": { |
| 218 | "config_file_path": "config.json", |
| 219 | }, |
| 220 | }, |
| 221 | "config": { |
| 222 | "devices": [ |
| 223 | { |
| 224 | "profiling_level": "linting", |
| 225 | "cores": [ |
| 226 | {"perf_profile": "burst", "rpc_control_latency": 100} |
| 227 | ], |
| 228 | "soc_id": int(soc_id), |
| 229 | } |
| 230 | ] |
| 231 | }, |
| 232 | } |
| 233 | |
| 234 | def qnn_context_binary_generator( |
| 235 | self, |
| 236 | qnn_binary_file="forward_0.dlc", |
| 237 | binary_name="forward.serialized", |
| 238 | ): |
| 239 | for file_name, data in self.config.items(): |
| 240 | with open(f"{self.tmp_dir}/{file_name}.json", "w") as json_file: |
| 241 | json.dump(data, json_file, indent=4) |
| 242 | |
| 243 | target = "x86_64-linux-clang" |
| 244 | cmds = [ |
| 245 | f"{self.qnn_sdk}/bin/{target}/qnn-context-binary-generator", |
| 246 | "--backend", |
| 247 | f"{self.qnn_sdk}/lib/{target}/libQnnHtp.so", |
| 248 | "--model", |
| 249 | f"{self.qnn_sdk}/lib/{target}/libQnnModelDlc.so", |
| 250 | "--dlc_path", |
| 251 | f"{self.tmp_dir}/{qnn_binary_file}", |