(
cls,
graph: GraphLowering,
source_code: str,
serialized_extern_kernel_nodes: Optional[str],
cuda: bool,
)
| 1540 | |
| 1541 | @classmethod |
| 1542 | def compile( |
| 1543 | cls, |
| 1544 | graph: GraphLowering, |
| 1545 | source_code: str, |
| 1546 | serialized_extern_kernel_nodes: Optional[str], |
| 1547 | cuda: bool, |
| 1548 | ) -> str: |
| 1549 | picked_vec_isa = pick_vec_isa() |
| 1550 | cpp_command = repr( |
| 1551 | cpp_compile_command( |
| 1552 | "i", "o", vec_isa=picked_vec_isa, cuda=cuda, aot_mode=graph.aot_mode |
| 1553 | ) |
| 1554 | ) |
| 1555 | fbcode_aot_cpu_re = False |
| 1556 | use_absolute_path = False |
| 1557 | if config.is_fbcode(): |
| 1558 | ld_command = build_paths.ld() |
| 1559 | if not cuda and graph.aot_mode: # Meta internal AOTInductor CPU |
| 1560 | objcopy_command = build_paths.objcopy_fallback() |
| 1561 | fbcode_aot_cpu_re = True |
| 1562 | use_absolute_path = True |
| 1563 | else: |
| 1564 | objcopy_command = build_paths.objcopy() |
| 1565 | else: |
| 1566 | ld_command = "ld" |
| 1567 | objcopy_command = "objcopy" |
| 1568 | |
| 1569 | ( |
| 1570 | specified_output_path, |
| 1571 | specified_so_name, |
| 1572 | ) = split_aot_inductor_output_path(config.aot_inductor.output_path) |
| 1573 | key, input_path = write( |
| 1574 | source_code, |
| 1575 | "cpp", |
| 1576 | extra=cpp_command, |
| 1577 | specified_dir=specified_output_path, |
| 1578 | ) |
| 1579 | |
| 1580 | if key not in cls.cache or ( |
| 1581 | specified_output_path |
| 1582 | and os.path.dirname(cls.cache[key]) != specified_output_path |
| 1583 | or specified_so_name |
| 1584 | and os.path.basename(cls.cache[key]) != specified_so_name |
| 1585 | ): |
| 1586 | from filelock import FileLock |
| 1587 | |
| 1588 | lock_dir = get_lock_dir() |
| 1589 | lock = FileLock(os.path.join(lock_dir, key + ".lock"), timeout=LOCK_TIMEOUT) |
| 1590 | with lock: |
| 1591 | # Currently, this only support serializing extern nodes in fbcode |
| 1592 | # Eventually, we should also have a serializer for OSS. |
| 1593 | if config.is_fbcode() and serialized_extern_kernel_nodes: |
| 1594 | output_json = os.path.splitext(input_path)[0] + ".json" |
| 1595 | with open(output_json, "w") as f: |
| 1596 | f.write(serialized_extern_kernel_nodes) |
| 1597 | |
| 1598 | output_so = ( |
| 1599 | config.aot_inductor.output_path |
no test coverage detected