-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include
torch-mlir-opt
in Python wheels (#3964)
This adds the `torch-mlir-opt` tool to the Python wheels, which allows to use the commandline tool via a pip installed package instead of having to compile the torch-mlir project yourself. The executable is still installed to the deault location and copied over via the `setup.py` to be included in the Python wheel. This could be refactored and handled within CMake in a follow-up.
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# Also available under a BSD-style license. See LICENSE. | ||
|
||
"""Torch-MLIR modular optimizer driver | ||
Typically, when installed from a wheel, this can be invoked as: | ||
torch-mlir-opt [options] <input file> | ||
To see available passes, dialects, and options, run: | ||
torch-mlir-opt --help | ||
""" | ||
import os | ||
import platform | ||
import subprocess | ||
import sys | ||
|
||
from typing import Optional | ||
|
||
|
||
def _get_builtin_tool(exe_name: str) -> Optional[str]: | ||
if platform.system() == "Windows": | ||
exe_name = exe_name + ".exe" | ||
this_path = os.path.dirname(__file__) | ||
tool_path = os.path.join(this_path, "..", "..", "_mlir_libs", exe_name) | ||
return tool_path | ||
|
||
|
||
def main(args=None): | ||
if args is None: | ||
args = sys.argv[1:] | ||
exe = _get_builtin_tool("torch-mlir-opt") | ||
return subprocess.call(args=[exe] + args) | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters