MCPcopy Create free account
hub / github.com/pytorch/executorch / compile

Function compile

examples/qualcomm/qaihub_scripts/utils/export.py:219–288  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

217
218
219def compile(args):
220 logger = get_logger()
221 logger.info("prepare compiler spec for qualcomm backend")
222
223 # setup compiler spec dedicated to QNN HTP backend
224 backend_options = generate_htp_compiler_spec(use_fp16=False)
225 # setup general compiler spec for QNN
226 compiler_specs = generate_qnn_executorch_compiler_spec(
227 soc_model=getattr(QcomChipset, args.soc_model),
228 backend_options=backend_options,
229 is_from_context_binary=True,
230 )
231 # setup memory planning
232 memory_planning_pass = MemoryPlanningPass(
233 alloc_graph_input=args.allocate_graph_io,
234 alloc_graph_output=args.allocate_graph_io,
235 )
236
237 # dictionary for avoiding name collision when creating custom ops
238 name_map = {}
239 num_bins = len(args.artifacts)
240 for i, ctx_bin in enumerate(args.artifacts):
241 index = i + 1
242 binary_name = Path(ctx_bin).stem
243 output_dir = f"{args.output_pte_folder}/{binary_name}"
244 make_output_dir(output_dir)
245 # conversion model library into context binary if required
246 ctx_bin = to_context_binary(
247 model_lib=ctx_bin,
248 soc_model=args.soc_model,
249 device=args.device,
250 host=args.host,
251 target=args.target,
252 build_folder=args.build_folder,
253 output_folder=output_dir,
254 logger=logger,
255 )
256 # step 0: check if name collision happens for context binaries
257 logger.info(f"({index}/{num_bins}) checking custom op name of {ctx_bin}")
258 custom_op_name = f"ctx_loader_{binary_name}"
259 postfix = name_map.get(custom_op_name, 0)
260 if postfix > 0:
261 postfix += 1
262 custom_op_name = f"{custom_op_name}_{postfix}"
263 name_map[custom_op_name] = postfix
264 # step 1: generate ExportedProgram with custom op as binary loader & lower to QnnBackend
265 logger.info(f"({index}/{num_bins}) exporting program for {ctx_bin}")
266 prog_info = from_context_binary(
267 ctx_bin, custom_op_name, getattr(QcomChipset, args.soc_model)
268 )
269 # step 2: write pte files and IO information
270 logger.info(f"({index}/{num_bins}) exporting {binary_name}.pte")
271 with open(f"{output_dir}/{binary_name}.pte", "wb") as f:
272 prog_info["edge_program_manager"].to_executorch(
273 config=ExecutorchBackendConfig(
274 memory_planning_pass=memory_planning_pass
275 )
276 ).write_to_file(f)

Callers

nothing calls this directly

Calls 15

MemoryPlanningPassClass · 0.90
make_output_dirFunction · 0.90
from_context_binaryFunction · 0.90
draw_graphFunction · 0.90
to_context_binaryFunction · 0.85
infoMethod · 0.80
dumpMethod · 0.80
get_loggerFunction · 0.70
get_io_infoFunction · 0.70

Tested by

no test coverage detected