Compare commits

...

3 Commits

Author SHA1 Message Date
99bb4c696c fix lint 2025-11-13 13:06:25 -05:00
ef23b4e90e add unittest 2025-11-13 12:54:25 -05:00
f3a6e23b0b Add aot_inductor.link_openmp config 2025-11-13 12:36:56 -05:00
3 changed files with 61 additions and 1 deletions

View File

@ -7491,6 +7491,60 @@ class AOTInductorTestsTemplate:
for lib in torch_libs:
self.assertTrue(lib not in line)
@unittest.skipIf(not IS_MACOS, "Mac only test")
def test_openmp_free_dylib(self):
class Model(torch.nn.Module):
def __init__(self) -> None:
super().__init__()
self.linear = torch.nn.Linear(10, 10)
def forward(self, x, y):
return x + self.linear(y)
example_inputs = (
torch.randn(10, 10, device=self.device),
torch.randn(10, 10, device=self.device),
)
model = Model().to(self.device)
ep = torch.export.export(model, example_inputs)
package_path = torch._inductor.aoti_compile_and_package(
ep,
inductor_configs={
"aot_inductor.link_openmp": False,
},
)
openmp_libs = {
"libomp",
"libgomp",
"libiomp",
"libiomp5",
}
with tempfile.TemporaryDirectory() as tmpdir:
# Unpack
with zipfile.ZipFile(package_path, "r") as zf:
zf.extractall(tmpdir)
dylib_files = list(pathlib.Path(tmpdir).rglob("*.dylib"))
self.assertTrue(len(dylib_files) > 0)
for dylib_file in dylib_files:
dylib_copy = pathlib.Path(tmpdir) / f"{dylib_file.name}.checkcopy"
dylib_copy.write_bytes(dylib_file.read_bytes())
result = subprocess.run(
["otool", "-L", str(dylib_copy)],
check=True,
capture_output=True,
text=True,
)
for line in result.stdout.splitlines():
for lib in openmp_libs:
self.assertNotIn(lib, line)
def test_unbounded_expr_substitutions(self):
class Model(torch.nn.Module):
def forward(self, x, y, a, b):

View File

@ -1780,6 +1780,9 @@ class aot_inductor:
# Whether the compiled .so should link to libtorch
link_libtorch: bool = True
# Whether the compiled .so should link to OpenMP
link_openmp: bool = True
# Currently the only valid option is "windows".
# We'll use x86_64-w64-mingw32-gcc to cross-compile a .dll file
# If using cuda, you also need to set WINDOWS_CUDA_HOME env var

View File

@ -1310,7 +1310,10 @@ def _get_openmp_args(
libs: list[str] = []
passthrough_args: list[str] = []
if config.aot_inductor.cross_target_platform == "windows":
if (
config.aot_inductor.cross_target_platform == "windows"
or not config.aot_inductor.link_openmp
):
return cflags, ldflags, include_dir_paths, lib_dir_paths, libs, passthrough_args
if _IS_MACOS:
# Per https://mac.r-project.org/openmp/ right way to pass `openmp` flags to MacOS is via `-Xclang`