Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fe05266

Browse files
Revert "[reland][inductor] Add an AOT compilation mode for Inductor CPP backend (#95985)"
This reverts commit deaf9e5. Reverted #95985 on behalf of https://github.com/huydhn due to Sorry for reverting this. It increased the test time significantly for ASAN (and may be other test shards). ASAN tests on PR passed but it was barely not timing out. I have updated my initial findings in #96378
1 parent 44d8e6c commit fe05266

File tree

13 files changed

+51
-316
lines changed

13 files changed

+51
-316
lines changed

test/inductor/aot/cpp/CMakeLists.txt

Lines changed: 0 additions & 23 deletions
This file was deleted.

test/inductor/aot/cpp/test.cpp

Lines changed: 0 additions & 41 deletions
This file was deleted.

test/inductor/aot/cpp/test.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

test/inductor/aot/cpp/test.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.

torch/_inductor/__init__.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,6 @@ def compile(
2727
return compile_fx(gm, example_inputs, config_patches=options)
2828

2929

30-
def aot_compile(
31-
gm: torch.fx.GraphModule,
32-
example_inputs: List[torch.Tensor],
33-
options: Optional[Dict[str, Any]] = None,
34-
) -> str:
35-
"""
36-
Ahead-of-time compile a given FX graph with TorchInductor into a shared library.
37-
38-
Args:
39-
gm: The FX graph to compile.
40-
example_inputs: List of tensor inputs.
41-
options: Optional dict of config options. See `torch._inductor.config`.
42-
43-
Returns:
44-
Path to the generated shared library
45-
"""
46-
from .compile_fx import compile_fx
47-
48-
return compile_fx(gm, example_inputs, config_patches=options, aot_mode=True)()
49-
50-
5130
def list_mode_options(mode: str = None) -> Dict[str, Any]:
5231
r"""Returns a dictionary describing the optimizations that each of the available
5332
modes passed to `torch.compile()` performs.

torch/_inductor/codecache.py

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -534,52 +534,6 @@ def cpp_compile_command(
534534
).strip()
535535

536536

537-
class AotCodeCache:
538-
cache = dict()
539-
clear = staticmethod(cache.clear)
540-
541-
@classmethod
542-
def compile(cls, source_code):
543-
from .codegen.wrapper import CppWrapperCodeGen
544-
545-
# TODO: update cpp_compile_command for different platforms
546-
picked_vec_isa = pick_vec_isa()
547-
key, input_path = write(
548-
source_code,
549-
"cpp",
550-
code_hash(repr(cpp_compile_command("i", "o", vec_isa=picked_vec_isa))),
551-
)
552-
if key not in cls.cache:
553-
from filelock import FileLock
554-
555-
lock_dir = get_lock_dir()
556-
lock = FileLock(os.path.join(lock_dir, key + ".lock"), timeout=LOCK_TIMEOUT)
557-
with lock:
558-
output_so = (
559-
os.path.join(os.getcwd(), f"{config.aot_codegen_output_prefix}.so")
560-
if config.aot_codegen_output_prefix
561-
else f"{input_path[:-3]}.so"
562-
)
563-
564-
output_header = f"{output_so[:-3]}.h"
565-
with open(output_header, "w") as header_file:
566-
header_file.writelines("#include <torch/torch.h>\n\n")
567-
header_file.writelines(f"{CppWrapperCodeGen.decl_str};\n")
568-
569-
log.info(f"AOT-Inductor compiles code into: {output_so}")
570-
if not os.path.exists(output_so):
571-
cmd = cpp_compile_command(
572-
input=input_path, output=output_so, vec_isa=picked_vec_isa
573-
).split(" ")
574-
try:
575-
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
576-
except subprocess.CalledProcessError as e:
577-
raise exc.CppCompileError(cmd, e.output) from e
578-
579-
cls.cache[key] = output_so
580-
return cls.cache[key]
581-
582-
583537
class CppCodeCache:
584538
cache = dict()
585539
clear = staticmethod(cache.clear)

torch/_inductor/codegen/cpp.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,12 +2050,7 @@ def codegen_define_and_call(self, wrapper):
20502050
)
20512051
if enable_kernel_profile:
20522052
code.writelines(["#include <ATen/record_function.h>"])
2053-
kernel_decl_name = kernel_name if V.graph.aot_mode else "kernel"
2054-
2055-
if not V.graph.aot_mode or self.count == 1:
2056-
code.writeline(cpp_prefix())
2057-
2058-
code.writeline(f'extern "C" void {kernel_decl_name}({arg_defs})')
2053+
code.writelines([cpp_prefix(), "" f'extern "C" void kernel({arg_defs})'])
20592054
with code.indent():
20602055
if enable_kernel_profile:
20612056
graph_id = V.graph.graph_id
@@ -2070,12 +2065,9 @@ def codegen_define_and_call(self, wrapper):
20702065
code.splice(self.loops_code)
20712066

20722067
codecache_def = IndentedBuffer()
2073-
if V.graph.aot_mode:
2074-
codecache_def.splice(code)
2075-
else:
2076-
codecache_def.writeline("async_compile.cpp('''")
2077-
codecache_def.splice(code)
2078-
codecache_def.writeline("''')")
2068+
codecache_def.writeline("async_compile.cpp('''")
2069+
codecache_def.splice(code)
2070+
codecache_def.writeline("''')")
20792071

20802072
codecache_str = codecache_def.getvalue()
20812073
# TODO(voz): Ostensibly, we should not need this. But there are cases where C++ codegen does

torch/_inductor/codegen/cpp_prefix.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <limits>
66
#include <omp.h>
77

8-
#include <ATen/ATen.h>
98
#include <ATen/core/PhiloxRNGEngine.h>
109
#if defined(CPU_CAPABILITY_AVX512) || defined(CPU_CAPABILITY_AVX2)
1110
#include <ATen/cpu/vec/functional.h>

0 commit comments

Comments
 (0)