Skip to content

Commit

Permalink
add gpu enablement flag and improve pull action
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Wu committed Apr 23, 2023
1 parent f5c49ed commit 8bf3ba2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
uses: actions/cache@v2
with:
path: llvm-project
key: ${{ runner.os }}-llvm-install-${{ env.LLVM_COMMIT }}
key: ${{ runner.os }}-llvm-install-${{ env.LLVM_COMMIT }} # TODO: need to make sure LLVM_COMMIT is always a hash (not a branch name or tag name)
- name: Get LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
uses: actions/checkout@v2
Expand Down
21 changes: 16 additions & 5 deletions .github/workflows/manual_build_this_repo_and_llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,34 @@ def manual_clone_llvm_project(llvm_dir, git_ref):



def manual_build_llvm_project(git_ref, enable_mlir_python_bindings):
# TODO: add an option to choose whether to build python bindings
def manual_build_llvm_project(git_ref, enable_mlir_python_bindings, enable_cuda_backend):
# To build python bindings, add the two flags specified in the documentation to the cmake command, e.g.:
# -DMLIR_ENABLE_BINDINGS_PYTHON=ON -DMLIR_INCLUDE_TESTS=ON -DPython3_EXECUTABLE=/home/kwu/anaconda3/envs/dev_mlir/bin/python3
# Notice that Python3_EXECUTABLE needs to be the same as the one used in run time. Otherwise ImportError (unknown location) will be thrown.
# https://mlir.llvm.org/docs/Bindings/Python/#building

if enable_cuda_backend and not enable_mlir_python_bindings:
enable_mlir_python_bindings = True
print("enable_mlir_python_bindings is set to True because enable_cuda_backend is True")

os.system("mkdir llvm-project/build")
os.system("mkdir llvm-project/prefix")
os.chdir("llvm-project/build")
cmake_configure_command = "cmake ../llvm -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_BUILD_EXAMPLES=OFF -DLLVM_TARGETS_TO_BUILD=\"host\" -DCMAKE_INSTALL_PREFIX=../prefix -DLLVM_ENABLE_PROJECTS='mlir' -DLLVM_OPTIMIZED_TABLEGEN=ON -DLLVM_ENABLE_OCAMLDOC=OFF -DLLVM_ENABLE_BINDINGS=OFF -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_LLD=ON"

cmake_configure_command = "cmake ../llvm -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=../prefix -DLLVM_ENABLE_PROJECTS='mlir' -DLLVM_OPTIMIZED_TABLEGEN=ON -DLLVM_ENABLE_OCAMLDOC=OFF -DLLVM_INSTALL_UTILS=ON -DLLVM_ENABLE_LLD=ON"
if enable_cuda_backend:
# reference: https://github.com/llvm/llvm-zorg/blob/9185b9aa01f1230dd9e2da9401ae49a43ed56b13/buildbot/osuosl/master/config/builders.py#L1448-L1476
cuda_compiler_path = os.popen("which nvcc").read().strip()
cmake_configure_command+=" -DLLVM_TARGETS_TO_BUILD=\"host;NVPTX\" -DMLIR_ENABLE_CUDA_RUNNER=1 -DMLIR_INCLUDE_INTEGRATION_TESTS=ON -DMLIR_ENABLE_VULKAN_RUNNER=1 -DBUILD_SHARED_LIBS=ON -DLLVM_CCACHE_BUILD=ON -DMLIR_RUN_CUDA_TENSOR_CORE_TESTS=ON -DLLVM_LIT_ARGS=-v -vv -DCMAKE_CUDA_COMPILER={cuda_compiler_path}".format(cuda_compiler_path=cuda_compiler_path)
else:
cmake_configure_command+=" -DLLVM_TARGETS_TO_BUILD=\"host\""
if enable_mlir_python_bindings:
# get python3 executable path by executing which python3
python3_executable_path = os.popen("which python3").read().strip()

cmake_configure_command += " -DMLIR_ENABLE_BINDINGS_PYTHON=ON -DMLIR_INCLUDE_TESTS=ON -DPython3_EXECUTABLE={python3_executable_path}".format(python3_executable_path=python3_executable_path)
else:
cmake_configure_command+=" -DLLVM_ENABLE_BINDINGS=OFF"

os.system(cmake_configure_command)
os.system("cmake --build . --target install")
os.chdir("../..")
Expand Down Expand Up @@ -81,5 +92,5 @@ def get_hash(llvm_dir):
os.system("mv llvm-project2 llvm-project")
else:
manual_clone_llvm_project("llvm-project", git_ref)
manual_build_llvm_project(git_ref, enable_mlir_python_bindings=False)
manual_build_llvm_project(git_ref, enable_mlir_python_bindings=True, enable_cuda_backend=True)
manual_release_build()
8 changes: 4 additions & 4 deletions .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ jobs:
path: 'llvm-project'
ref: ${{ github.event.inputs.ref }}
- name: Set environment variable llvm commit hash in llvm-project/mlir/examples/standalone/
run: |
run: | # hash of the latest commit to pull
echo "MLIR_EXAMPLE_HASH=$(cd llvm-project && git log --pretty=tformat:"%H" -n1 ./mlir/examples/standalone/)" >> $GITHUB_ENV
- name: Get template code commit hash by using .github/workflows/get_commit_hash_from_yml.py
run: |
run: | # branch/tag name or hash of the commit of this current repo
cd $GITHUB_WORKSPACE/mlir-standalone-template
echo "TEMPLATE_COMMIT_HASH=$(python ./.github/workflows/get_commit_hash_from_yml.py)" >> $GITHUB_ENV
- name: Update if the two strings TEMPLATE_COMMIT_HASH and MLIR_EXAMPLE_HASH are different. push to the TEMPLATE_COMMIT_HASH branch. create pull request
if: env.TEMPLATE_COMMIT_HASH != env.MLIR_EXAMPLE_HASH
if: env.TEMPLATE_COMMIT_HASH != env.MLIR_EXAMPLE_HASH # TODO: check if the case where TEMPLATE_COMMIT_HASH is branch name can be correctly handled (tag name is fine now)
run: |
cd $GITHUB_WORKSPACE/mlir-standalone-template
cp -r $GITHUB_WORKSPACE/llvm-project/mlir/examples/standalone/* .
python .github/workflows/replace_commit_hash_in_yml.py ${{ github.event.inputs.ref }}
python .github/workflows/replace_commit_hash_in_yml.py ${{ github.event.inputs.ref }} ${{ env.MLIR_EXAMPLE_HASH }}
git config --local user.email "[email protected]"
git config --local user.name "github-actions"
git checkout -b "gh_latest_llvm${{ env.MLIR_EXAMPLE_HASH }}"
Expand Down
16 changes: 14 additions & 2 deletions .github/workflows/replace_commit_hash_in_yml.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys

if __name__=="__main__":
# usage: python3 .github/workflows/replace_commit_hash_in_yml.py <input_ref> <commit_hash_to_be_pulled>
ensure_executed_in_git_root()
# for filename in [".github/workflows/build-and-test.yml", ".github/workflows/pull.yml"]:
# with open(filename, "r") as f:
Expand All @@ -17,8 +18,19 @@
with open(".env", "r") as f:
lines = f.readlines()
with open(".env", "w") as f:
met_llvm_commit = False
met_llvm_ref = False
for line in lines:
if line.startswith("LLVM_COMMIT="):
f.write("LLVM_COMMIT=" + sys.argv[1] + "\n")
# TODO: always write down commit hash in LLVM_COMMIT and write down sys.argv[1] additionally in LLVM_REF so that when sys.argv[1] is a branch name (tag name is fine now), we can still see the commit hash
f.write("LLVM_COMMIT=" + sys.argv[2] + "\n")
met_llvm_commit = True
elif line.startswith("LLVM_REF="):
f.write("LLVM_REF=" + sys.argv[1] + "\n")
met_llvm_ref = True
else:
f.write(line)
f.write(line)
if not met_llvm_commit:
f.write("LLVM_COMMIT=" + sys.argv[2] + "\n")
if not met_llvm_ref:
f.write("LLVM_REF=" + sys.argv[1] + "\n")

0 comments on commit 8bf3ba2

Please sign in to comment.