diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile deleted file mode 100644 index acc2b84..0000000 --- a/.devcontainer/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM ghcr.io/tensor-array/tensor-array:master - -# [Optional] Uncomment this section to install additional vcpkg ports. -# RUN su vscode -c "${VCPKG_ROOT}/vcpkg install " - -# [Optional] Uncomment this section to install additional packages. -# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ -# && apt-get -y install --no-install-recommends diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json deleted file mode 100644 index 3884093..0000000 --- a/.devcontainer/devcontainer.json +++ /dev/null @@ -1,40 +0,0 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the -// README at: https://github.com/devcontainers/templates/tree/main/src/cpp -{ - "name": "C++", - "build": { - "dockerfile": "Dockerfile" - }, - - "features": { - "ghcr.io/devcontainers/features/github-cli:1": {}, - "ghcr.io/devcontainers/features/python:1": {} - }, - - "customizations": { - "vscode": { - "extensions": [ - "ms-vscode.cpptools-extension-pack", - "ms-vscode.cmake-tools" - ] - } - }, - - "hostRequirements": { - "gpu": "optional" - } - // Features to add to the dev container. More info: https://containers.dev/features. - // "features": {}, - - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], - - // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "gcc -v", - - // Configure tool-specific properties. - // "customizations": {}, - - // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. - // "remoteUser": "root" -} diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 1588e87..14e6402 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -17,8 +17,16 @@ permissions: jobs: release-build: - runs-on: ubuntu-latest - + strategy: + matrix: + # macos-13 is an intel runner, macos-14 is apple silicon + os: [ "ubuntu-22.04", "ubuntu-22.04-arm" ] + arch: ["auto"] + include: + - os: ubuntu-22.04 + arch: ppc64le + + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 @@ -31,15 +39,26 @@ jobs: - uses: actions/setup-python@v5 with: python-version: "3.x" - - - name: Install Build - run: | - # NOTE: put your own distribution build steps here. - python -m pip install build + + - name: Set up QEMU + if: ${{ matrix.arch != 'auto' }} + uses: docker/setup-qemu-action@v3 + with: + platforms: all - name: Build wheels + if: ${{ matrix.arch == 'auto' }} uses: pypa/cibuildwheel@v3.0.1 - # env: + with: + package-dir: . + output-dir: wheelhouse + config-file: "{package}/pyproject.toml" + + - name: Build wheels + if: ${{ matrix.arch != 'auto' }} + uses: pypa/cibuildwheel@v3.0.1 + env: + CIBW_ARCHS: ${{ matrix.arch }} with: package-dir: . output-dir: wheelhouse @@ -48,7 +67,7 @@ jobs: - name: Upload distributions uses: actions/upload-artifact@v4 with: - name: release-dists + name: release-dists-${{ runner.os }}-${{ runner.arch }}-${{ matrix.arch }} path: wheelhouse/ pypi-publish: @@ -75,7 +94,8 @@ jobs: - name: Retrieve release distributions uses: actions/download-artifact@v4 with: - name: release-dists + pattern: release-dists-* + merge-multiple: true path: wheelhouse/ - name: Publish release distributions to PyPI @@ -107,7 +127,8 @@ jobs: - name: Retrieve release distributions uses: actions/download-artifact@v4 with: - name: release-dists + pattern: release-dists-* + merge-multiple: true path: wheelhouse/ - name: Publish release distributions to TestPyPI @@ -116,3 +137,4 @@ jobs: repository-url: https://test.pypi.org/legacy/ packages-dir: wheelhouse/ + diff --git a/cpp/tensor_bind.cc b/cpp/tensor_bind.cc index 20d4f5b..3de6407 100644 --- a/cpp/tensor_bind.cc +++ b/cpp/tensor_bind.cc @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #include #include diff --git a/pyproject.toml b/pyproject.toml index 3e1f43a..e9f9bf4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,6 @@ requires = [ "setuptools>=42", "pybind11>=2.6.0", - "cmake>=3.18,<3.29", ] build-backend = "setuptools.build_meta" @@ -29,10 +28,14 @@ before-all = [ "chmod +x scripts/build-env/manylinux.sh", "scripts/build-env/manylinux.sh" ] +repair-wheel-command = [ + "auditwheel repair -w {dest_dir} --exclude libcudart.so.* --exclude libcublas.so.* --exclude libcublasLt.so.* {wheel}" +] [tool.cibuildwheel.linux.environment] -cuda = "12.9" +cuda = "12.4" temp = "/tmp/cuda-temp" +TENSOR_ARRAY_INSTALL_PATH = "/tmp/tensor-array-temp" CUDA_PATH = "/usr/local/cuda-${cuda}" PATH = "${PATH}:${CUDA_PATH}/bin" -LD_LIBRARY_PATH = "${LD_LIBRARY_PATH}:${CUDA_PATH}/lib:${CUDA_PATH}/lib64" +LD_LIBRARY_PATH = "${LD_LIBRARY_PATH}:${CUDA_PATH}/lib:${CUDA_PATH}/lib64:${TENSOR_ARRAY_INSTALL_PATH}/lib/tensor-array:${TENSOR_ARRAY_INSTALL_PATH}/lib64/tensor-array" diff --git a/scripts/build-env/manylinux.sh b/scripts/build-env/manylinux.sh index 487689f..df2554d 100644 --- a/scripts/build-env/manylinux.sh +++ b/scripts/build-env/manylinux.sh @@ -1,10 +1,12 @@ #!/bin/bash # Decide if we can proceed or not (root or sudo is required) and if so store whether sudo should be used or not. -if [ "$is_root" = false ] && [ "$has_sudo" = false ]; then +if [ "$is_root" = false ] && [ "$has_sudo" = false ] +then echo "Root or sudo is required. Aborting." exit 1 -elif [ "$is_root" = false ] ; then +elif [ "$is_root" = false ] +then USE_SUDO=sudo else USE_SUDO= @@ -38,7 +40,8 @@ echo # Check if nvcc is available echo "Checking for nvcc..." -if ! command -v nvcc &> /dev/null; then +if ! command -v nvcc &> /dev/null +then echo "nvcc could not be found. Please ensure CUDA is installed correctly." exit 1 fi @@ -47,32 +50,23 @@ echo "nvcc is available. Proceeding with the build environment setup." cd tensor-array-repo/Tensor-Array # Create build directory if it doesn't exist -if [ ! -d "build" ]; then +if [ ! -d "build" ] +then echo "Creating build directory..." mkdir build else echo "Build directory already exists." fi + # Change to the build directory cd build # Configure the build with CMake echo "Configuring the build with CMake..." -cmake .. +cmake .. -DCMAKE_CUDA_HOST_COMPILER="/usr/bin/gcc" -DCMAKE_INSTALL_PREFIX=${TENSOR_ARRAY_INSTALL_PATH} cmake --build . cmake --install . cd .. rm -rf build -# Create symbolic link for lib64 to lib if it doesn't exist -echo "Checking for symbolic link from lib64 to lib..." -if [ ! -L "lib" ] && [ -d "lib64" ]; then - echo "Creating symbolic link for lib64 to lib..." - ln -s lib64 lib -else - echo "Symbolic link for lib64 to lib already exists or lib64 does not exist." -fi - cd ../.. - -patchelf --set-rpath "\$ORIGIN/../lib" ./lib/*.so diff --git a/setup.py b/setup.py index d0c8707..9837ec0 100644 --- a/setup.py +++ b/setup.py @@ -7,19 +7,21 @@ from setuptools import setup, find_packages from pybind11.setup_helpers import Pybind11Extension, build_ext -__version__ = "0.0.5" +__version__ = "0.0.9" def main(): cwd = os.path.dirname(os.path.abspath(__file__)) with open(os.path.join(cwd, "README.md"), encoding="utf-8") as f: long_description = f.read() + tensor_array_lib_path = os.environ['TENSOR_ARRAY_INSTALL_PATH'] + ext_modules = [ Pybind11Extension( - "tensor_array._ext", + "tensor_array.tensor2", sources = glob.glob(os.path.join("cpp", "*.cc")), - include_dirs=["tensor-array-repo/Tensor-Array/include"], - library_dirs=["tensor-array-repo/Tensor-Array/lib"], + include_dirs=[tensor_array_lib_path + "/include"], + library_dirs=[tensor_array_lib_path + "/lib/tensor-array", tensor_array_lib_path + "/lib64/tensor-array"], libraries=["tensorarray_core", "tensorarray_layers"], define_macros=[("VERSION_INFO", __version__)], ), diff --git a/src/tensor_array/core/constants.py b/src/tensor_array/core/constants.py index 9d01931..3731977 100644 --- a/src/tensor_array/core/constants.py +++ b/src/tensor_array/core/constants.py @@ -17,7 +17,7 @@ def zeros(shape : tuple, dtype : DataTypes = DataTypes.S_INT_32) -> Tensor: Tensor: A tensor filled with zeros. """ - from .._ext.tensor2 import zeros as _zeros + from ..tensor2 import zeros as _zeros return _zeros(shape, dtype) def rand(shape : tuple, seed: int = 0) -> Tensor: @@ -32,5 +32,5 @@ def rand(shape : tuple, seed: int = 0) -> Tensor: Tensor: A tensor filled with random values. """ - from .._ext.tensor2 import rand as _rand + from ..tensor2 import rand as _rand return _rand(shape, seed) diff --git a/src/tensor_array/core/datatypes.py b/src/tensor_array/core/datatypes.py index 228f250..3b9261e 100644 --- a/src/tensor_array/core/datatypes.py +++ b/src/tensor_array/core/datatypes.py @@ -4,7 +4,7 @@ # The DataTypes enum includes types such as BOOL, INT, FLOAT, DOUBLE, and others, which correspond to the data types used in tensors. """ -from .._ext.tensor2 import DataType as _DataType +from ..tensor2 import DataType as _DataType from enum import Enum class DataTypes(Enum): diff --git a/src/tensor_array/core/operator.py b/src/tensor_array/core/operator.py index 9797f48..07e6a68 100644 --- a/src/tensor_array/core/operator.py +++ b/src/tensor_array/core/operator.py @@ -15,7 +15,7 @@ def add(value_1 : Tensor, value_2 : Tensor) -> Tensor: Returns: Tensor: A tensor that is the element-wise sum of value_1 and value_2 """ - from .tensor2 import add as _add + from ..tensor2 import add as _add return _add(value_1, value_2) def divide(value_1 : Tensor, value_2 : Tensor) -> Tensor: @@ -27,7 +27,7 @@ def divide(value_1 : Tensor, value_2 : Tensor) -> Tensor: Returns: Tensor: A tensor that is the element-wise division of value_1 by value_2 """ - from .tensor2 import divide as _divide + from ..tensor2 import divide as _divide return _divide(value_1, value_2) def multiply(value_1 : Tensor, value_2 : Tensor) -> Tensor: @@ -39,7 +39,7 @@ def multiply(value_1 : Tensor, value_2 : Tensor) -> Tensor: Returns: Tensor: A tensor that is the element-wise product of value_1 and value_2 """ - from .tensor2 import multiply as _multiply + from ..tensor2 import multiply as _multiply return _multiply(value_1, value_2) def power(value_1 : Tensor, value_2 : Tensor) -> Tensor: @@ -51,7 +51,7 @@ def power(value_1 : Tensor, value_2 : Tensor) -> Tensor: Returns: Tensor: A tensor that is the element-wise result of value_1 raised to the power of value_2 """ - from .tensor2 import power as _power + from ..tensor2 import power as _power return _power(value_1, value_2) def matmul(value_1 : Tensor, value_2 : Tensor) -> Tensor: @@ -63,7 +63,7 @@ def matmul(value_1 : Tensor, value_2 : Tensor) -> Tensor: Returns: Tensor: A tensor that is the result of matrix multiplication between value_1 and value_2 """ - from .._ext.tensor2 import matmul as _matmul + from ..tensor2 import matmul as _matmul return _matmul(value_1, value_2) def condition(condition_value : Tensor, value_if_true : Tensor, value_if_false : Tensor) -> Tensor: @@ -76,5 +76,5 @@ def condition(condition_value : Tensor, value_if_true : Tensor, value_if_false : Returns: Tensor: A tensor that is either value_if_true or value_if_false, depending on the condition. """ - from .._ext.tensor2 import condition as _condition + from ..tensor2 import condition as _condition return _condition(condition_value, value_if_true, value_if_false) diff --git a/src/tensor_array/core/tensor.py b/src/tensor_array/core/tensor.py index fdab2bb..453637a 100644 --- a/src/tensor_array/core/tensor.py +++ b/src/tensor_array/core/tensor.py @@ -4,9 +4,9 @@ # The Tensor class is designed to be used in a computational graph for automatic differentiation. """ -from .._ext.tensor2 import Tensor as _Tensor -from .datatypes import DataTypes from __future__ import annotations +from ..tensor2 import Tensor as _Tensor +from .datatypes import DataTypes class Tensor(_Tensor): """ diff --git a/tensor-array-repo/Tensor-Array b/tensor-array-repo/Tensor-Array index 04e4819..4b2222c 160000 --- a/tensor-array-repo/Tensor-Array +++ b/tensor-array-repo/Tensor-Array @@ -1 +1 @@ -Subproject commit 04e4819da358b83818a3e1fc312a284fb9248c64 +Subproject commit 4b2222cbb431c2b776357a18a9dcdb95ead82dc3