2023-01-06 12:50:26 +00:00
|
|
|
from .builder import Builder
|
|
|
|
from .utils import append_nvcc_threads, get_cuda_cc_flag
|
2023-01-04 03:38:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MultiHeadAttnBuilder(Builder):
|
2023-01-06 12:50:26 +00:00
|
|
|
NAME = "multihead_attention"
|
|
|
|
PREBUILT_IMPORT_PATH = "colossalai._C.multihead_attention"
|
2023-01-04 03:38:42 +00:00
|
|
|
|
2023-01-06 12:50:26 +00:00
|
|
|
def __init__(self):
|
2023-09-19 06:20:26 +00:00
|
|
|
super().__init__(name=MultiHeadAttnBuilder.NAME, prebuilt_import_path=MultiHeadAttnBuilder.PREBUILT_IMPORT_PATH)
|
2023-01-04 03:38:42 +00:00
|
|
|
|
|
|
|
def include_dirs(self):
|
2023-01-06 12:50:26 +00:00
|
|
|
ret = [self.csrc_abs_path("kernels/include"), self.get_cuda_home_include()]
|
|
|
|
return ret
|
2023-01-04 03:38:42 +00:00
|
|
|
|
|
|
|
def sources_files(self):
|
|
|
|
ret = [
|
2023-09-19 06:20:26 +00:00
|
|
|
self.csrc_abs_path(fname)
|
|
|
|
for fname in [
|
|
|
|
"multihead_attention_1d.cpp",
|
|
|
|
"kernels/cublas_wrappers.cu",
|
|
|
|
"kernels/transform_kernels.cu",
|
|
|
|
"kernels/dropout_kernels.cu",
|
|
|
|
"kernels/normalize_kernels.cu",
|
|
|
|
"kernels/softmax_kernels.cu",
|
|
|
|
"kernels/general_kernels.cu",
|
|
|
|
"kernels/cuda_util.cu",
|
2023-01-04 03:38:42 +00:00
|
|
|
]
|
|
|
|
]
|
2023-01-06 12:50:26 +00:00
|
|
|
return ret
|
2023-01-04 03:38:42 +00:00
|
|
|
|
|
|
|
def cxx_flags(self):
|
2023-09-19 06:20:26 +00:00
|
|
|
return ["-O3"] + self.version_dependent_macros
|
2023-01-04 03:38:42 +00:00
|
|
|
|
|
|
|
def nvcc_flags(self):
|
|
|
|
extra_cuda_flags = [
|
2023-09-19 06:20:26 +00:00
|
|
|
"-std=c++14",
|
|
|
|
"-U__CUDA_NO_HALF_OPERATORS__",
|
|
|
|
"-U__CUDA_NO_HALF_CONVERSIONS__",
|
|
|
|
"-U__CUDA_NO_HALF2_OPERATORS__",
|
|
|
|
"-DTHRUST_IGNORE_CUB_VERSION_CHECK",
|
2023-01-04 03:38:42 +00:00
|
|
|
]
|
|
|
|
extra_cuda_flags.extend(get_cuda_cc_flag())
|
2023-09-19 06:20:26 +00:00
|
|
|
ret = ["-O3", "--use_fast_math"] + self.version_dependent_macros + extra_cuda_flags
|
2023-01-06 12:50:26 +00:00
|
|
|
return append_nvcc_threads(ret)
|