Skip to content
Snippets Groups Projects
Commit 7159ab99 authored by Yifan Zhao's avatar Yifan Zhao
Browse files

Make approxhpvm.py an installable package (hpvmpy)

parent 8d8e7abe
No related branches found
No related tags found
No related merge requests found
# This file is very tightly coupled with main.py.in. # This file is very tightly coupled with main.py.in.
# Watch out and keep them in sync. # Watch out and keep them in sync.
# main.py.in (to become approxhpvm.py) requires the following variables:
# CMake fills in some variables in main.py.in and generate it into a python package:
# `hpvmpy`, which is the main entry point and Python API for HPVM.
# ---[ Define variables for main.py.in
# main.py.in requires the following variables:
# LLVM_PROJECT_DIR, LLVM_BUILD_DIR # LLVM_PROJECT_DIR, LLVM_BUILD_DIR
# TRT_PATH, TRT_INCLUDE_DIRS, TRT_LINK_DIRS, TRT_LINK_LIBS # TRT_PATH, TRT_INCLUDE_DIRS, TRT_LINK_DIRS, TRT_LINK_LIBS
# DIRECT_LINK_LIBS # DIRECT_LINK_LIBS
...@@ -34,21 +39,37 @@ set( ...@@ -34,21 +39,37 @@ set(
LLVMGenHPVM LLVMGenHPVM
) )
# ---[ Create package folder structure
# This sounds crazy but since main.py.in is generated into another file under build/ dir,
# to make a python package around it, we'll have to generate the whole package structure
# in build/ as well.
# Target dir structure:
# ${CMAKE_CURRENT_BINARY_DIR}
# hpvmpy/
# __init__.py <- generated from main.py.in
# setup.py <- copied from setup.py
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/hpvmpy)
file(COPY setup.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
# ---[ Generate main.py.in to hpvmpy/__init__.py
set(init_path ${CMAKE_CURRENT_BINARY_DIR}/hpvmpy/__init__.py)
# First resolve all `@symbol@` by configuring the file # First resolve all `@symbol@` by configuring the file
configure_file(main.py.in ${CMAKE_CURRENT_BINARY_DIR}/main.py.conf) configure_file(main.py.in ${CMAKE_CURRENT_BINARY_DIR}/main.py.conf)
# Then resolve all generator expressions we configured into the previous file # Then resolve all generator expressions we configured into the previous file
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/main.py INPUT ${CMAKE_CURRENT_BINARY_DIR}/main.py.conf) file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/main.py INPUT ${CMAKE_CURRENT_BINARY_DIR}/main.py.conf)
# Delibrately create an extra step of moving file # Delibrately create an extra step of moving file
# which is carried out at build time (as a target) # which is carried out at build time (as a target)
# so we can set these dependencies on it # so we can set these dependencies on it.
set( set(DEPS tensor_runtime hpvm-rt-bc clang opt llvm-link ${AVAILABLE_PASSES})
DEPS
tensor_runtime hpvm-rt-bc clang opt llvm-link ${AVAILABLE_PASSES}
)
add_custom_command( add_custom_command(
OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/approxhpvm.py OUTPUT ${init_path}
COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/main.py ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/approxhpvm.py COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/main.py ${init_path}
COMMAND chmod +x ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/approxhpvm.py
DEPENDS ${DEPS} ${CMAKE_CURRENT_BINARY_DIR}/main.py DEPENDS ${DEPS} ${CMAKE_CURRENT_BINARY_DIR}/main.py
) )
add_custom_target(approxhpvm.py ALL DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/approxhpvm.py)
# ---[ Call python3 -m pip to install this package.
add_custom_target(
hpvmpy
COMMAND python3 -m pip install ./
DEPENDS ${init_path} setup.py
)
...@@ -183,5 +183,9 @@ def parse_args(): ...@@ -183,5 +183,9 @@ def parse_args():
return args return args
if __name__ == "__main__": def main():
compile_hpvm_c(**vars(parse_args())) compile_hpvm_c(**vars(parse_args()))
if __name__ == "__main__":
main()
import setuptools
setuptools.setup(
name="hpvmpy",
version="1.0",
author="Yifan Zhao",
author_email="yifanz16@illinois.edu",
description="HPVM Python API",
packages=["hpvmpy"],
entry_points={
"console_scripts": [
"hpvm-clang = hpvmpy:main",
],
},
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment