Unverified Commit 2c7dbb7c authored by Johnny's avatar Johnny Committed by GitHub
Browse files

[FEATURE] Enhance platform compatibility for ARM (#5746)

parent 9a62191b
...@@ -5,6 +5,9 @@ PYTHON_VERSION=$1 ...@@ -5,6 +5,9 @@ PYTHON_VERSION=$1
CUDA_VERSION=$2 CUDA_VERSION=$2
PYTHON_ROOT_PATH=/opt/python/cp${PYTHON_VERSION//.}-cp${PYTHON_VERSION//.} PYTHON_ROOT_PATH=/opt/python/cp${PYTHON_VERSION//.}-cp${PYTHON_VERSION//.}
ARCH=$(uname -i)
echo "ARCH: $ARCH"
if [ ${CUDA_VERSION} = "12.8" ]; then if [ ${CUDA_VERSION} = "12.8" ]; then
DOCKER_IMAGE="pytorch/manylinux2_28-builder:cuda${CUDA_VERSION}" DOCKER_IMAGE="pytorch/manylinux2_28-builder:cuda${CUDA_VERSION}"
TORCH_INSTALL="pip install --no-cache-dir --pre torch --index-url https://download.pytorch.org/whl/nightly/cu${CUDA_VERSION//.}" TORCH_INSTALL="pip install --no-cache-dir --pre torch --index-url https://download.pytorch.org/whl/nightly/cu${CUDA_VERSION//.}"
...@@ -20,10 +23,10 @@ docker run --rm \ ...@@ -20,10 +23,10 @@ docker run --rm \
# Install CMake (version >= 3.26) - Robust Installation # Install CMake (version >= 3.26) - Robust Installation
export CMAKE_VERSION_MAJOR=3.31 export CMAKE_VERSION_MAJOR=3.31
export CMAKE_VERSION_MINOR=1 export CMAKE_VERSION_MINOR=1
echo \"Downloading CMake from: https://cmake.org/files/v\${CMAKE_VERSION_MAJOR}/cmake-\${CMAKE_VERSION_MAJOR}.\${CMAKE_VERSION_MINOR}-linux-x86_64.tar.gz\" echo \"Downloading CMake from: https://cmake.org/files/v\${CMAKE_VERSION_MAJOR}/cmake-\${CMAKE_VERSION_MAJOR}.\${CMAKE_VERSION_MINOR}-linux-${ARCH}.tar.gz\"
wget https://cmake.org/files/v\${CMAKE_VERSION_MAJOR}/cmake-\${CMAKE_VERSION_MAJOR}.\${CMAKE_VERSION_MINOR}-linux-x86_64.tar.gz wget https://cmake.org/files/v\${CMAKE_VERSION_MAJOR}/cmake-\${CMAKE_VERSION_MAJOR}.\${CMAKE_VERSION_MINOR}-linux-${ARCH}.tar.gz
tar -xzf cmake-\${CMAKE_VERSION_MAJOR}.\${CMAKE_VERSION_MINOR}-linux-x86_64.tar.gz tar -xzf cmake-\${CMAKE_VERSION_MAJOR}.\${CMAKE_VERSION_MINOR}-linux-${ARCH}.tar.gz
mv cmake-\${CMAKE_VERSION_MAJOR}.\${CMAKE_VERSION_MINOR}-linux-x86_64 /opt/cmake mv cmake-\${CMAKE_VERSION_MAJOR}.\${CMAKE_VERSION_MINOR}-linux-${ARCH} /opt/cmake
export PATH=/opt/cmake/bin:\$PATH export PATH=/opt/cmake/bin:\$PATH
# Debugging CMake # Debugging CMake
...@@ -35,8 +38,9 @@ docker run --rm \ ...@@ -35,8 +38,9 @@ docker run --rm \
${PYTHON_ROOT_PATH}/bin/pip install --no-cache-dir ninja setuptools==75.0.0 wheel==0.41.0 numpy uv scikit-build-core && \ ${PYTHON_ROOT_PATH}/bin/pip install --no-cache-dir ninja setuptools==75.0.0 wheel==0.41.0 numpy uv scikit-build-core && \
export TORCH_CUDA_ARCH_LIST='7.5 8.0 8.9 9.0+PTX' && \ export TORCH_CUDA_ARCH_LIST='7.5 8.0 8.9 9.0+PTX' && \
export CUDA_VERSION=${CUDA_VERSION} && \ export CUDA_VERSION=${CUDA_VERSION} && \
mkdir -p /usr/lib/x86_64-linux-gnu/ && \ mkdir -p /usr/lib/${ARCH}-linux-gnu/ && \
ln -s /usr/local/cuda-${CUDA_VERSION}/targets/x86_64-linux/lib/stubs/libcuda.so /usr/lib/x86_64-linux-gnu/libcuda.so && \ ln -s /usr/local/cuda-${CUDA_VERSION}/targets/x86_64-linux/lib/stubs/libcuda.so /usr/lib/${ARCH}-linux-gnu/libcuda.so && \
cd /sgl-kernel && \ cd /sgl-kernel && \
ls -la ${PYTHON_ROOT_PATH}/lib/python${PYTHON_VERSION}/site-packages/wheel/ && \ ls -la ${PYTHON_ROOT_PATH}/lib/python${PYTHON_VERSION}/site-packages/wheel/ && \
PYTHONPATH=${PYTHON_ROOT_PATH}/lib/python${PYTHON_VERSION}/site-packages ${PYTHON_ROOT_PATH}/bin/python -m uv build --wheel -Cbuild-dir=build . --color=always --no-build-isolation && \ PYTHONPATH=${PYTHON_ROOT_PATH}/lib/python${PYTHON_VERSION}/site-packages ${PYTHON_ROOT_PATH}/bin/python -m uv build --wheel -Cbuild-dir=build . --color=always --no-build-isolation && \
......
import ctypes import ctypes
import os import os
import platform
import torch import torch
if os.path.exists("/usr/local/cuda/targets/x86_64-linux/lib/libcudart.so.12"): SYSTEM_ARCH = platform.machine()
ctypes.CDLL(
"/usr/local/cuda/targets/x86_64-linux/lib/libcudart.so.12", cuda_path = f"/usr/local/cuda/targets/{SYSTEM_ARCH}-linux/lib/libcudart.so.12"
mode=ctypes.RTLD_GLOBAL, if os.path.exists(cuda_path):
) ctypes.CDLL(cuda_path, mode=ctypes.RTLD_GLOBAL)
from sgl_kernel import common_ops from sgl_kernel import common_ops
from sgl_kernel.allreduce import * from sgl_kernel.allreduce import *
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
# ============================================================================== # ==============================================================================
import os import os
import platform
import shutil import shutil
import sys import sys
from pathlib import Path from pathlib import Path
...@@ -24,9 +25,19 @@ from setuptools.command.build_py import build_py ...@@ -24,9 +25,19 @@ from setuptools.command.build_py import build_py
from torch.utils.cpp_extension import BuildExtension, CppExtension from torch.utils.cpp_extension import BuildExtension, CppExtension
root = Path(__file__).parent.resolve() root = Path(__file__).parent.resolve()
arch = platform.machine().lower()
if arch in ("x86_64", "amd64"):
plat_name = "manylinux2014_x86_64"
elif arch in ("aarch64", "arm64"):
plat_name = "manylinux2014_aarch64"
elif arch.startswith("ppc"):
plat_name = "manylinux2014_ppc64le"
else:
plat_name = f"manylinux2014_{arch}"
if "bdist_wheel" in sys.argv and "--plat-name" not in sys.argv: if "bdist_wheel" in sys.argv and "--plat-name" not in sys.argv:
sys.argv.extend(["--plat-name", "manylinux2014_x86_64"]) sys.argv.extend(["--plat-name", plat_name])
def _get_version(): def _get_version():
...@@ -70,7 +81,7 @@ cmdclass = { ...@@ -70,7 +81,7 @@ cmdclass = {
} }
Extension = CppExtension Extension = CppExtension
extra_link_args = ["-Wl,-rpath,$ORIGIN/../../torch/lib", "-L/usr/lib/x86_64-linux-gnu"] extra_link_args = ["-Wl,-rpath,$ORIGIN/../../torch/lib", f"-L/usr/lib/{arch}-linux-gnu"]
ext_modules = [ ext_modules = [
Extension( Extension(
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
# limitations under the License. # limitations under the License.
# ============================================================================== # ==============================================================================
import platform
import sys import sys
from pathlib import Path from pathlib import Path
...@@ -20,6 +21,7 @@ from setuptools import find_packages, setup ...@@ -20,6 +21,7 @@ from setuptools import find_packages, setup
from torch.utils.cpp_extension import BuildExtension, CUDAExtension from torch.utils.cpp_extension import BuildExtension, CUDAExtension
root = Path(__file__).parent.resolve() root = Path(__file__).parent.resolve()
arch = platform.machine().lower()
def _get_version(): def _get_version():
...@@ -45,7 +47,7 @@ sources = [ ...@@ -45,7 +47,7 @@ sources = [
cxx_flags = ["-O3"] cxx_flags = ["-O3"]
libraries = ["hiprtc", "amdhip64", "c10", "torch", "torch_python"] libraries = ["hiprtc", "amdhip64", "c10", "torch", "torch_python"]
extra_link_args = ["-Wl,-rpath,$ORIGIN/../../torch/lib", "-L/usr/lib/x86_64-linux-gnu"] extra_link_args = ["-Wl,-rpath,$ORIGIN/../../torch/lib", f"-L/usr/lib/{arch}-linux-gnu"]
hipcc_flags = [ hipcc_flags = [
"-DNDEBUG", "-DNDEBUG",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment