2022-03-10 08:44:22 +08:00
|
|
|
#!/bin/bash
|
|
|
|
# Updates auto-generated shape library files for the `torch` dialect.
|
2022-06-14 05:51:30 +08:00
|
|
|
#
|
|
|
|
# Environment variables:
|
|
|
|
# TORCH_MLIR_EXT_MODULES: comma-separated list of python module names
|
|
|
|
# which register custom PyTorch operators upon being imported.
|
|
|
|
# TORCH_MLIR_EXT_PYTHONPATH: colon-separated list of paths necessary
|
|
|
|
# for importing PyTorch extensions specified in TORCH_MLIR_EXT_MODULES.
|
|
|
|
# For more information on supporting custom operators, see:
|
|
|
|
# ${TORCH_MLIR}/python/torch_mlir/_torch_mlir_custom_op_example/README.md
|
|
|
|
|
2022-07-07 05:39:30 +08:00
|
|
|
set -euo pipefail
|
2022-03-10 08:44:22 +08:00
|
|
|
|
2022-07-07 05:39:30 +08:00
|
|
|
src_dir="$(realpath "$(dirname "$0")"/..)"
|
2022-03-10 08:44:22 +08:00
|
|
|
build_dir="$(realpath "${TORCH_MLIR_BUILD_DIR:-$src_dir/build}")"
|
|
|
|
torch_transforms_cpp_dir="${src_dir}/lib/Dialect/Torch/Transforms"
|
|
|
|
python_packages_dir="${build_dir}/tools/torch-mlir/python_packages"
|
|
|
|
|
2022-08-03 04:35:56 +08:00
|
|
|
TORCH_MLIR_EXT_PYTHONPATH="${TORCH_MLIR_EXT_PYTHONPATH:-""}"
|
2022-06-14 05:51:30 +08:00
|
|
|
pypath="${python_packages_dir}/torch_mlir"
|
2022-08-03 04:35:56 +08:00
|
|
|
if [ ! -z ${TORCH_MLIR_EXT_PYTHONPATH} ]; then
|
|
|
|
pypath="${pypath}:${TORCH_MLIR_EXT_PYTHONPATH}"
|
|
|
|
fi
|
|
|
|
TORCH_MLIR_EXT_MODULES="${TORCH_MLIR_EXT_MODULES:-""}"
|
|
|
|
if [ ! -z ${TORCH_MLIR_EXT_MODULES} ]; then
|
|
|
|
ext_module="${TORCH_MLIR_EXT_MODULES} "
|
|
|
|
fi
|
2022-06-14 05:51:30 +08:00
|
|
|
|
|
|
|
PYTHONPATH="${pypath}" python \
|
2022-03-10 08:44:22 +08:00
|
|
|
-m torch_mlir.dialects.torch.importer.jit_ir.build_tools.shape_lib_gen \
|
2022-08-17 12:11:04 +08:00
|
|
|
--pytorch_op_extensions=${ext_module:-""} \
|
2022-03-10 08:44:22 +08:00
|
|
|
--torch_transforms_cpp_dir="${torch_transforms_cpp_dir}"
|