mirror of
https://github.com/hpcaitech/ColossalAI.git
synced 2025-09-13 05:01:44 +00:00
[Inference/Refactor] Refactor compilation mechanism and unified multi hw (#5613)
* refactor compilation mechanism and unified multi hw * fix file path bug * add init.py to make pybind a module to avoid relative path error caused by softlink * delete duplicated micros * fix micros bug in gcc
This commit is contained in:
4
extensions/pybind/cpu_adam/__init__.py
Normal file
4
extensions/pybind/cpu_adam/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from .cpu_adam_arm import CpuAdamArmExtension
|
||||
from .cpu_adam_x86 import CpuAdamX86Extension
|
||||
|
||||
__all__ = ["CpuAdamArmExtension", "CpuAdamX86Extension"]
|
42
extensions/pybind/cpu_adam/cpu_adam_arm.py
Normal file
42
extensions/pybind/cpu_adam/cpu_adam_arm.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import platform
|
||||
from typing import List
|
||||
|
||||
from ...cpp_extension import _CppExtension
|
||||
|
||||
|
||||
class CpuAdamArmExtension(_CppExtension):
|
||||
def __init__(self):
|
||||
super().__init__(name="cpu_adam_arm")
|
||||
|
||||
def is_available(self) -> bool:
|
||||
# only arm allowed
|
||||
return platform.machine() == "aarch64"
|
||||
|
||||
def assert_compatible(self) -> None:
|
||||
arch = platform.machine()
|
||||
assert (
|
||||
arch == "aarch64"
|
||||
), f"[extension] The {self.name} kernel requires the CPU architecture to be aarch64 but got {arch}"
|
||||
|
||||
# necessary 4 functions
|
||||
def sources_files(self):
|
||||
ret = [
|
||||
self.csrc_abs_path("kernel/arm/cpu_adam_arm.cpp"),
|
||||
]
|
||||
return ret
|
||||
|
||||
def include_dirs(self) -> List[str]:
|
||||
return super().include_dirs()
|
||||
|
||||
def cxx_flags(self):
|
||||
extra_cxx_flags = [
|
||||
"-std=c++14",
|
||||
"-std=c++17",
|
||||
"-g",
|
||||
"-Wno-reorder",
|
||||
"-fopenmp",
|
||||
]
|
||||
return ["-O3"] + self.version_dependent_macros + extra_cxx_flags
|
||||
|
||||
def nvcc_flags(self):
|
||||
return []
|
51
extensions/pybind/cpu_adam/cpu_adam_x86.py
Normal file
51
extensions/pybind/cpu_adam/cpu_adam_x86.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import platform
|
||||
|
||||
from ...cuda_extension import _CudaExtension
|
||||
from ...utils import append_nvcc_threads
|
||||
|
||||
|
||||
class CpuAdamX86Extension(_CudaExtension):
|
||||
def __init__(self):
|
||||
super().__init__(name="cpu_adam_x86")
|
||||
|
||||
def is_available(self) -> bool:
|
||||
return platform.machine() == "x86_64" and super().is_available()
|
||||
|
||||
def assert_compatible(self) -> None:
|
||||
arch = platform.machine()
|
||||
assert (
|
||||
arch == "x86_64"
|
||||
), f"[extension] The {self.name} kernel requires the CPU architecture to be x86_64 but got {arch}"
|
||||
super().assert_compatible()
|
||||
|
||||
# necessary 4 functions
|
||||
def sources_files(self):
|
||||
ret = [
|
||||
self.csrc_abs_path("kernel/x86/cpu_adam.cpp"),
|
||||
]
|
||||
return ret
|
||||
|
||||
def cxx_flags(self):
|
||||
extra_cxx_flags = [
|
||||
"-std=c++14",
|
||||
"-std=c++17",
|
||||
"-lcudart",
|
||||
"-lcublas",
|
||||
"-g",
|
||||
"-Wno-reorder",
|
||||
"-fopenmp",
|
||||
"-march=native",
|
||||
]
|
||||
return ["-O3"] + self.version_dependent_macros + extra_cxx_flags
|
||||
|
||||
def nvcc_flags(self):
|
||||
extra_cuda_flags = [
|
||||
"-std=c++14",
|
||||
"-std=c++17",
|
||||
"-U__CUDA_NO_HALF_OPERATORS__",
|
||||
"-U__CUDA_NO_HALF_CONVERSIONS__",
|
||||
"-U__CUDA_NO_HALF2_OPERATORS__",
|
||||
"-DTHRUST_IGNORE_CUB_VERSION_CHECK",
|
||||
]
|
||||
ret = ["-O3", "--use_fast_math"] + self.version_dependent_macros + extra_cuda_flags + super().nvcc_flags()
|
||||
return append_nvcc_threads(ret)
|
Reference in New Issue
Block a user