99from typing import Dict , List , Mapping , Optional , Sequence
1010
1111PROJECT_ROOT = Path (__file__ ).resolve ().parents [1 ]
12- OPERATOR_SET = PROJECT_ROOT / "scripts/configs/infiniops_ops.txt"
13- LINKED_OPERATORS = (
14- "flash_attn_varlen_func" ,
15- "flash_attn_with_kvcache" ,
16- )
12+ OPERATOR_CONFIG = PROJECT_ROOT / "scripts/configs/infiniops_ops.json"
1713SUBMODULES = {
1814 "InfiniRT" : Path ("submodules/InfiniRT" ),
1915 "InfiniOps" : Path ("submodules/InfiniOps" ),
2016 "InfiniCCL" : Path ("submodules/InfiniCCL" ),
2117}
2218
2319
24- def read_operator_set (path : Path = OPERATOR_SET ) -> List [str ]:
25- operators = [line .strip () for line in path .read_text (encoding = "utf-8" ).splitlines ()]
26- operators = [operator for operator in operators if operator ]
27- if not operators :
28- raise ValueError (f"Operator set is empty: { path } " )
29- if len (operators ) != len (set (operators )):
30- raise ValueError (f"Operator set contains duplicates: { path } " )
31- if operators != sorted (operators ):
32- raise ValueError (f"Operator set must be sorted: { path } " )
33- return operators
20+ def read_operator_config (path : Path = OPERATOR_CONFIG ) -> Dict [str , Dict [str , object ]]:
21+ config = json .loads (path .read_text (encoding = "utf-8" ))
22+ if not isinstance (config , dict ) or not config :
23+ raise ValueError (f"Operator config must be a non-empty object: { path } " )
24+ if list (config ) != sorted (config ):
25+ raise ValueError (f"Operator config must be sorted: { path } " )
26+ for operator , selection in config .items ():
27+ if not isinstance (operator , str ) or not operator :
28+ raise ValueError (f"Operator names must be non-empty strings: { path } " )
29+ if not isinstance (selection , dict ) or set (selection ) != {"implementations" }:
30+ raise ValueError (
31+ f"Operator { operator !r} must define only 'implementations': { path } "
32+ )
33+ implementations = selection ["implementations" ]
34+ if (
35+ not isinstance (implementations , list )
36+ or not implementations
37+ or any (
38+ type (slot ) is not int or not 0 <= slot < 32 for slot in implementations
39+ )
40+ or len (implementations ) != len (set (implementations ))
41+ ):
42+ raise ValueError (
43+ f"Operator { operator !r} implementations must be unique "
44+ f"integers between 0 and 31: { path } "
45+ )
46+ return config
3447
3548
3649def parse_gitlink (output : str , relative_path : Path ) -> str :
@@ -152,7 +165,7 @@ def build_infiniops_commands(
152165 build_type : str ,
153166 jobs : int ,
154167 cuda_arch : Optional [str ],
155- operators : Sequence [ str ] ,
168+ operator_config : Path ,
156169) -> List [List [str ]]:
157170 configure = [
158171 "cmake" ,
@@ -163,14 +176,12 @@ def build_infiniops_commands(
163176 "-DWITH_CPU=ON" ,
164177 "-DWITH_NVIDIA=ON" ,
165178 "-DWITH_LINKED=ON" ,
166- f"-DINFINI_OPS_LINKED_OPS={ ',' .join (LINKED_OPERATORS )} " ,
167179 "-DWITH_TORCH=ON" ,
168- "-DINFINI_OPS_TORCH_OPS=argmax" ,
169180 "-DAUTO_DETECT_DEVICES=OFF" ,
170181 "-DAUTO_DETECT_BACKENDS=OFF" ,
171182 "-DGENERATE_PYTHON_BINDINGS=OFF" ,
172183 f"-DINFINI_RT_ROOT={ prefix } " ,
173- f"-DINFINI_OPS_OPS={ ',' . join ( operators ) } " ,
184+ f"-DINFINI_OPS_OPS={ operator_config } " ,
174185 f"-DCMAKE_BUILD_TYPE={ build_type } " ,
175186 f"-DCMAKE_INSTALL_PREFIX={ prefix } " ,
176187 ]
@@ -263,7 +274,7 @@ def write_manifest(
263274 infinilm_revision : str ,
264275 infinicore_revision : str ,
265276 revisions : Mapping [str , str ],
266- operators : Sequence [str ],
277+ operator_config : Mapping [str , Mapping [ str , object ] ],
267278 prefix : Path ,
268279 build_type : str ,
269280 cuda_arch : Optional [str ],
@@ -278,7 +289,11 @@ def write_manifest(
278289 "infinilm" : infinilm_revision ,
279290 "install_prefix" : str (prefix ),
280291 "jobs" : jobs ,
281- "operators" : list (operators ),
292+ "operators" : list (operator_config ),
293+ "operator_implementations" : {
294+ operator : selection ["implementations" ]
295+ for operator , selection in operator_config .items ()
296+ },
282297 "submodules" : dict (revisions ),
283298 "test" : test ,
284299 }
@@ -362,7 +377,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
362377 build_root = resolve_from_project (args .build_root )
363378 prefix = build_root / "prefix"
364379 manifest_path = build_root / "manifest.json"
365- operators = read_operator_set ()
380+ operator_config = read_operator_config ()
366381 revisions = {
367382 name : validate_submodule (infinicore_root , relative_path )
368383 for name , relative_path in SUBMODULES .items ()
@@ -376,7 +391,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
376391 print (f"InfiniRT: { revisions ['InfiniRT' ]} " )
377392 print (f"InfiniOps: { revisions ['InfiniOps' ]} " )
378393 print (f"InfiniCCL: { revisions ['InfiniCCL' ]} " )
379- print (f"Operators ({ len (operators )} ): { ',' .join (operators )} " )
394+ print (f"Operators ({ len (operator_config )} ): { ',' .join (operator_config )} " )
380395
381396 if not args .dry_run :
382397 manifest_path .unlink (missing_ok = True )
@@ -402,7 +417,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
402417 args .build_type ,
403418 args .jobs ,
404419 args .cuda_arch ,
405- operators ,
420+ OPERATOR_CONFIG ,
406421 ):
407422 run (command , PROJECT_ROOT , integration_env , args .dry_run )
408423
@@ -423,7 +438,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
423438 infinilm_revision ,
424439 infinicore_revision ,
425440 revisions ,
426- operators ,
441+ operator_config ,
427442 prefix ,
428443 args .build_type ,
429444 args .cuda_arch ,
0 commit comments