From d5ac66d120f1cd88c4b197a2d268eed40ae4822c Mon Sep 17 00:00:00 2001 From: He Sichao <1310722434@qq.com> Date: Mon, 9 Sep 2024 19:08:23 +0800 Subject: [PATCH] Update --- .github/workflows/Publish.yml | 4 +- ci/linux/gpu/prepare_build_wheel_on_cuda.sh | 90 +++++++++++++++++++++ ci/linux/gpu/pyproject.toml | 70 ++++++++++++++++ copy_so_linux.py | 40 +++++++++ copy_so_linux.sh | 15 ++++ pyproject.toml | 2 +- 6 files changed, 218 insertions(+), 3 deletions(-) create mode 100644 ci/linux/gpu/prepare_build_wheel_on_cuda.sh create mode 100644 ci/linux/gpu/pyproject.toml create mode 100644 copy_so_linux.py create mode 100644 copy_so_linux.sh diff --git a/.github/workflows/Publish.yml b/.github/workflows/Publish.yml index d52f769..43f20fd 100644 --- a/.github/workflows/Publish.yml +++ b/.github/workflows/Publish.yml @@ -13,7 +13,7 @@ on: jobs: # Define test jobs as part of the publish workflow test_linux: - name: Build and Test on Linux + name: Test on Linux runs-on: ubuntu-latest strategy: fail-fast: false @@ -100,7 +100,7 @@ jobs: # path: dist/*.whl # retention-days: 20 build_and_test_macos_arm: - name: Build and Test on macOS + name: Build and Test on macOS(ARM) runs-on: macos-latest strategy: fail-fast: false diff --git a/ci/linux/gpu/prepare_build_wheel_on_cuda.sh b/ci/linux/gpu/prepare_build_wheel_on_cuda.sh new file mode 100644 index 0000000..bf42882 --- /dev/null +++ b/ci/linux/gpu/prepare_build_wheel_on_cuda.sh @@ -0,0 +1,90 @@ +#! /bin/sh + +set -e +set -x + +#pip install "cmake==3.22.*" +rm setup.py +mv setup_cuda.py setup.py +# mv setup_cpu.py setup.py + +# https://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/ + +# Install CUDA 11.2, see: +# * https://gitlab.com/nvidia/container-images/cuda/-/blob/master/dist/11.2.2/centos7-x86_64/base/Dockerfile +# * https://gitlab.com/nvidia/container-images/cuda/-/blob/master/dist/11.2.2/centos7-x86_64/devel/Dockerfile +#yum-config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-rhel7.repo +#yum install --setopt=obsoletes=0 -y \ +# cuda-nvcc-11-2-11.2.152-1 \ +# cuda-cudart-devel-11-2-11.2.152-1 \ +# libcurand-devel-11-2-10.2.3.152-1 \ +# libcudnn8-devel-8.1.1.33-1.cuda11.2 \ +# libcublas-devel-11-2-11.4.1.1043-1 +#ln -s cuda-11.2 /usr/local/cuda +# +#yum install -y python3-devel.x86_64 + + +# Install CUDA 11.4 +#yum-config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-rhel7.repo +#yum install --setopt=obsoletes=0 -y \ +# cuda-nvcc-11-4-11.4.152-1 \ +# cuda-cudart-devel-11-4-11.4.148-1 \ +# libcurand-devel-11-4-10.2.5.120-1 \ +# libcudnn8-devel-8.2.4.15-1.cuda11.4 \ +# libcublas-devel-11-4-11.6.5.2-1 +#ln -s cuda-11.4 /usr/local/cuda +# +#yum install -y python3-devel.x86_64 + + +# Install CUDA 11.6 +# sed -i 's/enabled=1/enabled=0/' /etc/yum/pluginconf.d/fastestmirror.conf +#yum-config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-rhel7.repo +#yum install --setopt=obsoletes=0 -y \ +# cuda-nvcc-11-6-11.6.124-1 \ +# cuda-cudart-devel-11-6-11.6.55-1 \ +# libcurand-devel-11-6-10.2.9.124-1 \ +# libcudnn8-devel-8.4.1.50-1.cuda11.6 \ +# libcublas-devel-11-6-11.9.2.110-1 +#ln -s cuda-11.6 /usr/local/cuda + + +# Install CUDA 11.8 +# yum-config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-rhel7.repo +# yum install --setopt=obsoletes=0 -y \ +# cuda-nvcc-11-8-11.8.89-1 \ +# cuda-cudart-devel-11-8-11.8.89-1 \ +# libcurand-devel-11-8-10.3.0.86-1\ +# libcudnn8-devel-8.8.0.121-1.cuda11.8 \ +# libcublas-devel-11-8-11.11.3.6-1 +# ln -s cuda-11.8 /usr/local/cuda + +# yum install -y python3-devel.x86_64 + +# Install CUDA 12.0 +yum-config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-rhel7.repo +yum install --setopt=obsoletes=0 -y \ + cuda-drivers-525.147.05-1.x86_64 \ + cuda-nvcc-12-0-12.0.140-1 \ + cuda-cudart-devel-12-0-12.0.146-1 +ln -s cuda-12.0 /usr/local/cuda + +yum install glibc-devel + +yum install --disableplugin=fastmirror -y python3-devel.x86_64 + +pip_config_dir="${HOME}/.pip" +pip_config_file="${pip_config_dir}/pip.conf" + +mkdir -p "${pip_config_dir}" + +if [[ ! -f "${pip_config_file}" ]]; then + touch "${pip_config_file}" +fi + +echo "[global]" >> "${pip_config_file}" +# echo "index-url = https://mirrors.aliyun.com/pypi/simple/" >> "${pip_config_file}" +echo "index-url = https://pypi.org/simple" >> "${pip_config_file}" + +echo "Pip mirror sources have been set!" \ No newline at end of file diff --git a/ci/linux/gpu/pyproject.toml b/ci/linux/gpu/pyproject.toml new file mode 100644 index 0000000..a53cdbd --- /dev/null +++ b/ci/linux/gpu/pyproject.toml @@ -0,0 +1,70 @@ +[tool.cibuildwheel] +build = "*" +skip = "" +test-skip = "" + +archs = ["auto"] +build-frontend = "pip" +config-settings = {} +dependency-versions = "pinned" +environment = {} +environment-pass = [] +build-verbosity = 1 + +before-all = "" +repair-wheel-command = "" + +test-command = "" +before-test = "" +test-requires = [] +test-extras = [] + +container-engine = "docker" + +manylinux-x86_64-image = "manylinux2014" + +[build-system] +requires = [ + "setuptools==68.2.0", + "wheel", + "Cython", + "pybind11", + "setuptools_scm[toml]>=3.4", + "cmake", + "taichi", +] + +build-backend = "setuptools.build_meta" + +[project] +requires-python = ">=3.8, <=3.12" +name = "braintaichi" +version = "0.0.1" + +[tool.cibuildwheel.linux] +before-all = "sh prepare_build_wheel_on_cuda.sh" +before-build = "sh copy_so_linux.sh" +#before-build = "pip install -r requirements-test.txt" +archs = ["x86_64"] +skip = ["pp*", "*-musllinux_x86_64"] +repair-wheel-command = """ + export LD_LIBRARY_PATH=/project/braintaichi:$LD_LIBRARY_PATH && + auditwheel repair -w {dest_dir} {wheel} +""" + +[tool.cibuildwheel.macos] +before-build = "sh copy_so_macOS.sh" +archs = ["x86_64", "arm64"] +skip = ["pp*"] +repair-wheel-command = """ + export LD_LIBRARY_PATH=/project/braintaichi:$LD_LIBRARY_PATH && + delocate-wheel -w {dest_dir} -v {wheel} +""" + +[tool.cibuildwheel.windows] +before-build = "copy_dll_windows.bat" +archs = ["AMD64", "x86"] +repair-wheel-command = """ + set PATH=braintaichi;%PATH% && delvewheel repair -w {dest_dir} {wheel} +""" +skip = ["pp*", "*-win32"] diff --git a/copy_so_linux.py b/copy_so_linux.py new file mode 100644 index 0000000..93f8821 --- /dev/null +++ b/copy_so_linux.py @@ -0,0 +1,40 @@ +import taichi as ti +import glob +import shutil +import subprocess +import os + +taichi_path = ti.__path__[0] +taichi_c_api_install_dir = os.path.join(taichi_path, '_lib', 'c_api') + +taichi_runtime_lib = os.path.join(taichi_c_api_install_dir, 'lib') + +taichi_runtime_lib = os.path.realpath(taichi_runtime_lib) +if not os.path.exists(taichi_runtime_lib): + taichi_runtime_lib = os.path.join(taichi_c_api_install_dir, 'lib64') + taichi_runtime_lib = os.path.realpath(taichi_runtime_lib) +if not os.path.exists(taichi_runtime_lib): + taichi_runtime_lib = os.path.join(taichi_c_api_install_dir, 'bin') + taichi_runtime_lib = os.path.realpath(taichi_runtime_lib) + + +taichi_lib_target_dir ='project/brainpylib' + +env_script_path = '/project/set_env.sh' +# if not os.path.isfile(env_script_path): +# os.mknod(env_script_path) + +with open(env_script_path, 'w') as env_script: + env_script.write(f'export taichi_lib_target_dir="{taichi_lib_target_dir}"\n') + env_script.write(f'export taichi_runtime_lib_dir="{taichi_runtime_lib}"\n') + +print(f"Environment setup script created at {env_script_path}") + +# so_files = glob.glob(os.path.join(taichi_runtime_lib, '*.so')) +# for so_file in so_files: +# subprocess.check_call(['cp', '-v', so_file, taichi_lib_target_dir]) + +# for lib in glob.glob(os.path.join(taichi_runtime_lib, '*.so')): +# shutil.copy(lib, taichi_lib_target_dir) +# print('cp {} {}'.format(lib, taichi_lib_target_dir)) + diff --git a/copy_so_linux.sh b/copy_so_linux.sh new file mode 100644 index 0000000..11f78fb --- /dev/null +++ b/copy_so_linux.sh @@ -0,0 +1,15 @@ +#! /bin/sh + +pip install taichi +chmod +x ./copy_so_linux.py +python copy_so_linux.py + +# Ensure the set_env.sh script is actually created and is not empty +dir /project +if [ -s set_env.sh ]; then + source /project/set_env.sh + cp "$taichi_runtime_lib_dir"/libtaichi_c_api.so /project/brainpylib/ +else + echo "Environment setup script 'set_env.sh' is missing or empty." + exit 1 +fi diff --git a/pyproject.toml b/pyproject.toml index a53cdbd..bcf5d98 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,7 +42,7 @@ name = "braintaichi" version = "0.0.1" [tool.cibuildwheel.linux] -before-all = "sh prepare_build_wheel_on_cuda.sh" +# before-all = "sh prepare_build_wheel_on_cuda.sh" before-build = "sh copy_so_linux.sh" #before-build = "pip install -r requirements-test.txt" archs = ["x86_64"]