2020from executorch .exir .backend .compile_spec_schema import CompileSpec
2121
2222SKIP_COMPILE_SPEC_KEYS = {"ImportForever" }
23+ REQUIRED_COMPILE_SPEC_KEYS = {"platform-config" }
24+ SUPPORTED_PLATFORM_CONFIGS = {"mt6989" , "mt6991" }
2325
2426
2527def assert_default_dim_order (edge_graph_module : torch .fx .GraphModule ) -> None :
@@ -47,6 +49,28 @@ def preprocess(
4749 cls , edge_program : ExportedProgram , module_compile_spec : List [CompileSpec ]
4850 ) -> PreprocessResult :
4951
52+ # Validate CompileSpec settings
53+ compile_spec_keys = [spec .key for spec in module_compile_spec ]
54+ if len (compile_spec_keys ) != len (set (compile_spec_keys )):
55+ raise RuntimeError (
56+ "Unsupported duplicated keys in the CompileSpec settings."
57+ )
58+ if not REQUIRED_COMPILE_SPEC_KEYS .issubset (set (compile_spec_keys )):
59+ raise RuntimeError (
60+ "Following keys are required in the CompileSpec settings: {}."
61+ "" .format (REQUIRED_COMPILE_SPEC_KEYS )
62+ )
63+ platform = [
64+ spec .value .decode ("utf-8" )
65+ for spec in module_compile_spec
66+ if spec .key == "platform-config"
67+ ][0 ]
68+ if platform not in SUPPORTED_PLATFORM_CONFIGS :
69+ raise ValueError (
70+ "Unsupported value of platform-config CompileSpec. Given {} but expected to be one "
71+ "of {}." .format (platform , SUPPORTED_PLATFORM_CONFIGS )
72+ )
73+
5074 # Make sure all inputs are contiguous_format or NCHW or default dim order
5175 assert_default_dim_order (edge_program .graph_module )
5276
@@ -64,8 +88,7 @@ def preprocess(
6488 if name_to_node_mappings [name ].meta ["val" ].dtype == torch .float32
6589 ]
6690
67- # This default compile options are only for mt6989 SOC
68- compile_options = ["--arch=mdla5.1,edpa1.0" , "--relax-fp32" , "--opt=3" ]
91+ compile_options = ["--relax-fp32" , "--opt=3" ]
6992 for spec in module_compile_spec :
7093 if spec .key in SKIP_COMPILE_SPEC_KEYS :
7194 continue
0 commit comments