@@ -50,6 +50,7 @@ def __init__(self):
5050 self .use_neutron_for_format_conversion = True
5151 self .fetch_constants_to_sram = False
5252 self .dump_kernel_selection_code = False
53+ self .use_new_flow_neutron_c = False
5354
5455 def _replace_colons (self , operator : str ) -> str :
5556 """
@@ -65,20 +66,21 @@ def neutron_compile_spec(
6566 use_neutron_for_format_conversion : bool = True ,
6667 fetch_constants_to_sram : bool = False ,
6768 dump_kernel_selection_code : bool = False ,
68- ):
69- """
70- Generate compile spec for Neutron NPU
71-
72- Args:
73- config: Neutron accelerator configuration, e.g. "imxrt700"
74- extra_flags: Extra flags for the Neutron compiler
75- operators_not_to_delegate: List of operators that should not be delegated
76- use_neutron_for_format_conversion: If True, the EdgeProgramToIRConverter will insert `Transpose` ops to
69+ use_new_flow_neutron_c : bool = False ,
70+ ) -> "NeutronCompileSpecBuilder" :
71+ """Generate compile spec for Neutron NPU
72+
73+ :param config: Neutron accelerator configuration, e.g. "imxrt700"
74+ :param extra_flags: Extra flags for the Neutron compiler
75+ :param operators_not_to_delegate: List of operators that should not be delegated
76+ :param use_neutron_for_format_conversion: If True, the EdgeProgramToIRConverter will insert `Transpose` ops to
7777 ensure that the IO matches the executorch partition, which will be
7878 delegated to Neutron.
79- fetch_constants_to_sram: If True, the Neutron Converter will insert microinstructions to prefetch weights
79+ :param fetch_constants_to_sram: If True, the Neutron Converter will insert microinstructions to prefetch weights
8080 from FLASH to SRAM. This should be used when the whole model does not fit into SRAM.
81- dump_kernel_selection_code: Whether Neutron converter dumps kernel selection code.
81+ :param dump_kernel_selection_code: Whether Neutron converter dumps kernel selection code.
82+ :param use_new_flow_neutron_c: Enable experimental MLIR-based flow for Neutron-C with improves INT8 operator support.
83+ :return: self for method chaining
8284 """
8385
8486 self .config = NeutronTargetSpec (config )
@@ -100,6 +102,7 @@ def neutron_compile_spec(
100102 self .use_neutron_for_format_conversion = use_neutron_for_format_conversion
101103 self .fetch_constants_to_sram = fetch_constants_to_sram
102104 self .dump_kernel_selection_code = dump_kernel_selection_code
105+ self .use_new_flow_neutron_c = use_new_flow_neutron_c
103106
104107 return self
105108
@@ -128,6 +131,10 @@ def build(self):
128131 "dump_kernel_selection_code" ,
129132 f"{ self .dump_kernel_selection_code } " .encode (),
130133 ),
134+ CompileSpec (
135+ "use_new_flow_neutron_c" ,
136+ f"{ self .use_new_flow_neutron_c } " .encode (),
137+ ),
131138 ]
132139
133140 return self .compile_spec
@@ -141,6 +148,7 @@ def generate_neutron_compile_spec(
141148 use_neutron_for_format_conversion : bool = True ,
142149 fetch_constants_to_sram : bool = False ,
143150 dump_kernel_selection_code : bool = False ,
151+ use_new_flow_neutron_c : bool = False ,
144152) -> List [CompileSpec ]:
145153 return (
146154 NeutronCompileSpecBuilder ()
@@ -151,6 +159,7 @@ def generate_neutron_compile_spec(
151159 use_neutron_for_format_conversion = use_neutron_for_format_conversion ,
152160 fetch_constants_to_sram = fetch_constants_to_sram ,
153161 dump_kernel_selection_code = dump_kernel_selection_code ,
162+ use_new_flow_neutron_c = use_new_flow_neutron_c ,
154163 )
155164 .build ()
156165 )
@@ -175,6 +184,7 @@ def preprocess( # noqa C901
175184 use_neutron_for_format_conversion = None
176185 fetch_constants_to_sram = False
177186 dump_kernel_selection_code = None
187+ use_new_flow_neutron_c = False
178188 for spec in compile_spec :
179189 if spec .key == "output_format" :
180190 output_format = spec .value .decode ()
@@ -188,6 +198,8 @@ def preprocess( # noqa C901
188198 fetch_constants_to_sram = spec .value .decode () == "True"
189199 if spec .key == "dump_kernel_selection_code" :
190200 dump_kernel_selection_code = spec .value .decode () == "True"
201+ if spec .key == "use_new_flow_neutron_c" :
202+ use_new_flow_neutron_c = spec .value .decode () == "True"
191203
192204 # Check that the output format is set in the compile spec
193205 if not output_format :
@@ -220,7 +232,11 @@ def preprocess( # noqa C901
220232 )
221233
222234 neutron_model = NeutronConverterManager (dump_kernel_selection_code ).convert (
223- tflite_model , target , delegation_tag , fetch_constants_to_sram
235+ tflite_model ,
236+ target ,
237+ delegation_tag ,
238+ fetch_constants_to_sram ,
239+ use_new_flow_neutron_c ,
224240 )
225241
226242 # Dump the tflite file if logging level is enabled
0 commit comments