@@ -140,6 +140,14 @@ GraphConfig get_graph_config(ArrayRef<CompileSpec>& compile_specs) {
140140
141141      config.set_memory_layout_override (memory_layout);
142142    }
143+     if  (strcmp (spec.key , " require_dynamic_shapes" 0 ) {
144+       ET_CHECK_MSG (value_size == sizeof (uint8_t ), " Unexpected value size!" 
145+       bool  value = getBool (value_data);
146+ 
147+       if  (value) {
148+         config.expect_dynamic_shapes  = true ;
149+       }
150+     }
143151  }
144152#ifdef  ET_EVENT_TRACER_ENABLED
145153  config.enable_querypool  = true ;
@@ -500,9 +508,12 @@ class VulkanBackend final : public ::executorch::runtime::BackendInterface {
500508    compute_graph->encode_prepack ();
501509    compute_graph->prepack ();
502510
503-     //  TODO(ssjia): remove this once we can batch compile compute pipelines
504-     //  during prepare().
505-     compute_graph->encode_execute ();
511+     //  If dynamic shapes are not expected, then the command buffer only needs to
512+     //  be encoded once. Otherwise, wait until the first inference to encode the
513+     //  the command buffer, when actual input shapes are known.
514+     if  (!compute_graph->graphconfig ().expect_dynamic_shapes ) {
515+       compute_graph->encode_execute ();
516+     }
506517
507518    return  Error::Ok;
508519  }
@@ -574,7 +585,9 @@ class VulkanBackend final : public ::executorch::runtime::BackendInterface {
574585    //  constants are updated and DynamicDispatchNode can update the compute
575586    //  shader, global workgroup size, and local workgroup size to perform the
576587    //  model inference.
577-     if  (should_propagate_resize) {
588+     if  (should_propagate_resize ||
589+         (compute_graph->graphconfig ().expect_dynamic_shapes  &&
590+          compute_graph->execute_count () == 0u )) {
578591      compute_graph->propagate_resize ();
579592    }
580593
0 commit comments