From c961cb5448c0e53e9826e223030d36d6a7af40e3 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 15 Feb 2023 20:19:53 -0500 Subject: [PATCH 1/4] build docker Signed-off-by: Jinzhe Zeng --- .github/workflows/build_wheel.yml | 33 +++++++++++++++++++++++++++++++ source/install/docker/Dockerhub | 15 ++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 source/install/docker/Dockerhub diff --git a/.github/workflows/build_wheel.yml b/.github/workflows/build_wheel.yml index 669a0219fb..bb34fe0bf6 100644 --- a/.github/workflows/build_wheel.yml +++ b/.github/workflows/build_wheel.yml @@ -36,6 +36,8 @@ jobs: - uses: actions/checkout@v2 with: submodules: true + # https://github.com/pypa/setuptools_scm/issues/480 + fetch-depth: 0 - uses: docker/setup-qemu-action@v2 name: Setup QEMU if: matrix.platform_id == 'manylinux_aarch64' @@ -82,6 +84,37 @@ jobs: user: __token__ password: ${{ secrets.pypi_password }} + build_docker: + # use the already built wheels to build docker + needs: [build_wheels] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/download-artifact@v3 + with: + name: artifact + path: source/install/docker/dist + - name: Log in to the Container registry + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ghcr.io/deepmodeling/deepmd-kit + + - name: Build and push Docker image + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + with: + context: source/install/docker + push: ${{ github.repository_owner == 'deepmodeling' && github.event_name == 'push' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + pass: name: Pass testing build wheels needs: [build_wheels, build_sdist] diff --git a/source/install/docker/Dockerhub b/source/install/docker/Dockerhub new file mode 100644 index 0000000000..f2c774f4ea --- /dev/null +++ b/source/install/docker/Dockerhub @@ -0,0 +1,15 @@ +FROM python:3.10 AS compile-image +RUN python -m venv /opt/deepmd-kit +# Make sure we use the virtualenv +ENV PATH="/opt/deepmd-kit/bin:$PATH" +# Install package +COPY dist /dist +RUN pip install "$(ls /dist/deepmd_kit-*_x86_64.whl)[gpu,cu11,lmp,ipi]" \ + && dp -h \ + && lmp -h \ + && dp_ipi -h + +FROM python:3.10 AS build-image +COPY --from=compile-image /opt/deepmd-kit /opt/deepmd-kit +ENV PATH="/opt/deepmd-kit/bin:$PATH" +CMD ["/bin/bash"] From 19bee0e1a4db3be61a2ec01a17461d0d94d7a1c6 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 16 Feb 2023 00:56:52 -0500 Subject: [PATCH 2/4] Rename Dockerhub to Dockerfile Signed-off-by: Jinzhe Zeng --- source/install/docker/{Dockerhub => Dockerfile} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename source/install/docker/{Dockerhub => Dockerfile} (100%) diff --git a/source/install/docker/Dockerhub b/source/install/docker/Dockerfile similarity index 100% rename from source/install/docker/Dockerhub rename to source/install/docker/Dockerfile From 67b36d91202565a8d0d8b47b1eed73050afec36b Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 15 Feb 2023 20:47:54 -0500 Subject: [PATCH 3/4] manylinux --- source/install/docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/install/docker/Dockerfile b/source/install/docker/Dockerfile index f2c774f4ea..8be578386d 100644 --- a/source/install/docker/Dockerfile +++ b/source/install/docker/Dockerfile @@ -4,7 +4,7 @@ RUN python -m venv /opt/deepmd-kit ENV PATH="/opt/deepmd-kit/bin:$PATH" # Install package COPY dist /dist -RUN pip install "$(ls /dist/deepmd_kit-*_x86_64.whl)[gpu,cu11,lmp,ipi]" \ +RUN pip install "$(ls /dist/deepmd_kit-*manylinux*_x86_64.whl)[gpu,cu11,lmp,ipi]" \ && dp -h \ && lmp -h \ && dp_ipi -h From 8cb903a9ca940dafaea47ffa12d348ede04b72cb Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 15 Feb 2023 21:48:53 -0500 Subject: [PATCH 4/4] fix docker test; add cuda path to LD_LIBRARY_PATH Signed-off-by: Jinzhe Zeng --- deepmd/lmp.py | 42 ++++++++++++++++++++++++++++++++ source/install/docker/Dockerfile | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/deepmd/lmp.py b/deepmd/lmp.py index 2d4c235220..225b9b2d65 100644 --- a/deepmd/lmp.py +++ b/deepmd/lmp.py @@ -1,6 +1,9 @@ """Register entry points for lammps-wheel.""" import os import platform +from importlib import ( + import_module, +) from pathlib import ( Path, ) @@ -23,6 +26,27 @@ def get_env(paths: List[Optional[str]]) -> str: return ":".join((p for p in paths if p is not None)) +def get_library_path(module: str) -> List[str]: + """Get library path from a module. + + Parameters + ---------- + module : str + The module name. + + Returns + ------- + list[str] + The library path. + """ + try: + m = import_module(module) + except ModuleNotFoundError: + return [] + else: + return [str(Path(m.__file__).parent)] + + if platform.system() == "Linux": lib_env = "LD_LIBRARY_PATH" elif platform.system() == "Darwin": @@ -32,6 +56,23 @@ def get_env(paths: List[Optional[str]]) -> str: tf_dir = tf.sysconfig.get_lib() op_dir = str((Path(__file__).parent / "op").absolute()) + + +cuda_library_paths = [] +if platform.system() == "Linux": + cuda_library_paths.extend( + [ + *get_library_path("nvidia.cuda_runtime.lib"), + *get_library_path("nvidia.cublas.lib"), + *get_library_path("nvidia.cublas.lib"), + *get_library_path("nvidia.cufft.lib"), + *get_library_path("nvidia.curand.lib"), + *get_library_path("nvidia.cusolver.lib"), + *get_library_path("nvidia.cusparse.lib"), + *get_library_path("nvidia.cudnn.lib"), + ] + ) + # set LD_LIBRARY_PATH os.environ[lib_env] = get_env( [ @@ -39,6 +80,7 @@ def get_env(paths: List[Optional[str]]) -> str: tf_dir, os.path.join(tf_dir, "python"), op_dir, + *cuda_library_paths, ] ) diff --git a/source/install/docker/Dockerfile b/source/install/docker/Dockerfile index 8be578386d..217f76058b 100644 --- a/source/install/docker/Dockerfile +++ b/source/install/docker/Dockerfile @@ -7,7 +7,7 @@ COPY dist /dist RUN pip install "$(ls /dist/deepmd_kit-*manylinux*_x86_64.whl)[gpu,cu11,lmp,ipi]" \ && dp -h \ && lmp -h \ - && dp_ipi -h + && dp_ipi FROM python:3.10 AS build-image COPY --from=compile-image /opt/deepmd-kit /opt/deepmd-kit