# HTP Parallel Graph Execution Parallel graph execution enables more than one graph to run concurrently on a single HTP core, allowing them to simultaneously share core resources such as VTCM, HMX, and HVX. Warning This feature’s performance is heavily tied to the nature of the two graphs. How much they use resources, whether they can share VTCM, and other factors. For best performance, it is recommended to merge them into a super graph. This allows the optimizer to schedule them more effectively, improving resource utilization and throughput. Graphs participating in Parallel Graph Execution must: 1. Be the same `Qnn_PriorityLevel_t`. 2. Graphs must be able to coexist in VTCM. 3. Both graphs must be in the same process. Warning This feature is not compatible with multicore, shared spill/fill buffer, nor VTCM backup sharing features. ## VTCM Coexistence VTCM allocation is always done with 2 numbers: 1. **Page Size:** (must be a power of 4. i.e. 1,4,16). On an 8MB chip a 16MB TLB entry is created, but only 8MB is actually usable. 2. **Addressable Size:** What portion of the page is accessible to the program. The remaining overmap region is available to other VTCM clients (see VTCM sharing in QNN SDK docs).  In parallel graph, both graphs must share VTCM meaning a layout would look like the following. Notice that both graphs must be configured to fit side-by-side in VTCM.  QNN Priority Mapping | Setting No | Setting | Graph 1 (purple) | Graph 2 (green) | | --- | --- | --- | --- | | 1 | VTCM Page Size | not configurable, always hardware size. | not configurable, always hardware size. | | 2 | Addressable Size | 7 | 7 | | 3 | Graph Offset | 0 | 4 | | 4 | Graph Size | 4 | 3 | ### Executing Graphs in Parallel To execute graphs in parallel they must first be compatible and meet all requirements above. In addition, calls to execute must be made separately. That means calling synchronous execute from two different threads, or calling async execute in rapid succession. Parallel execution graphs won’t wait. They only share resources if it is possible to do so. If they are unable to execute the graph gets queued immediately. 1/** 2 * Graph 1 (purple) 3 */ 4QnnHtpGraph_CustomConfig_t pgeConfig1; 5pgeConfig1.option = QNN_HTP_GRAPH_CONFIG_OPTION_PARALLEL_GRAPH_EXECUTION_CONFIG; 6// Enable concurrency 7pgeConfig1.parallelGraphExecutionConfig.concurrency = QNN_HTP_GRAPH_CONCURRENCY_OPTION_ALL_SHARED; 8// Set VTCM Parameters 9pgeConfig1.parallelGraphExecutionConfig.vtcmConfig.sizeInBytes = 4 * 1024 * 1024; 10pgeConfig1.parallelGraphExecutionConfig.vtcmConfig.offsetInBytes = 0; 11pgeConfig1.parallelGraphExecutionConfig.vtcmConfig.sizeTotalInBytes = 7 * 1024 * 1024; 12 13 14QnnGraph_Config_t graphConfig; 15graphConfig.option = QNN_GRAPH_CONFIG_OPTION_CUSTOM; 16graphConfig.customConfig = &pgeConfig1; 17 18const QnnGraph_Config_t* pGraphConfig[] = {&graphConfig, NULL}; 19 20/** 21 * Graph 2 (green) 22 */ 23QnnHtpGraph_CustomConfig_t pgeConfig2; 24pgeConfig2.option = QNN_HTP_GRAPH_CONFIG_OPTION_PARALLEL_GRAPH_EXECUTION_CONFIG; 25// Set VTCM Parameters 26pgeConfig2.parallelGraphExecutionConfig.vtcmConfig.sizeInBytes = 3 * 1024 * 1024; 27pgeConfig2.parallelGraphExecutionConfig.vtcmConfig.offsetInBytes = 4 * 1024 * 1024; 28pgeConfig2.parallelGraphExecutionConfig.vtcmConfig.sizeTotalInBytes = 7 * 1024 * 1024; 29 30QnnGraph_Config_t graphConfig; 31graphConfig.option = QNN_GRAPH_CONFIG_OPTION_CUSTOM; 32graphConfig.customConfig = &pgeConfig2; 33 34const QnnGraph_Config_t* pGraphConfig[] = {&graphConfig, NULL}; Copy to clipboard Notice that graph VTCM size is part of the parallel graph config. It will override other values (i.e. context vtcm size or `QNN_HTP_GRAPH_CONFIG_OPTION_VTCM_SIZE`) Note These settings must be applied before the graph is either prepared or loaded from a context binary. It is not possible to change these values afterwards and any attempts to change the value will be rejected. ## Visualisation You may use this tool to visualize how graph sizes will affect VTCM layout. Warning Tool is for demonstration only. May contain bugs in implementation.