Commit 42d21122 authored by Mohammad Shoeybi's avatar Mohammad Shoeybi
Browse files

Merge branch 'build_fix' into 'main'

Create build directory for fused_kernels before building.

See merge request ADLR/megatron-lm!149
parents 54282071 54ded172
...@@ -26,7 +26,7 @@ from torch.utils import cpp_extension ...@@ -26,7 +26,7 @@ from torch.utils import cpp_extension
os.environ["TORCH_CUDA_ARCH_LIST"] = "" os.environ["TORCH_CUDA_ARCH_LIST"] = ""
def get_cuda_bare_metal_version(cuda_dir): def get_cuda_bare_metal_version(cuda_dir):
raw_output = subprocess.check_output([cuda_dir + "/bin/nvcc", "-V"], raw_output = subprocess.check_output([cuda_dir + "/bin/nvcc", "-V"],
universal_newlines=True) universal_newlines=True)
output = raw_output.split() output = raw_output.split()
release_idx = output.index("release") + 1 release_idx = output.index("release") + 1
...@@ -36,6 +36,12 @@ def get_cuda_bare_metal_version(cuda_dir): ...@@ -36,6 +36,12 @@ def get_cuda_bare_metal_version(cuda_dir):
return raw_output, bare_metal_major, bare_metal_minor return raw_output, bare_metal_major, bare_metal_minor
def create_build_dir(buildpath):
try:
os.mkdir(buildpath)
except OSError:
if not os.path.isdir(buildpath):
print(f"Creation of the build directory {buildpath} failed")
def load_scaled_upper_triang_masked_softmax_fusion_kernel(): def load_scaled_upper_triang_masked_softmax_fusion_kernel():
...@@ -47,11 +53,15 @@ def load_scaled_upper_triang_masked_softmax_fusion_kernel(): ...@@ -47,11 +53,15 @@ def load_scaled_upper_triang_masked_softmax_fusion_kernel():
cc_flag.append('arch=compute_80,code=sm_80') cc_flag.append('arch=compute_80,code=sm_80')
srcpath = pathlib.Path(__file__).parent.absolute() srcpath = pathlib.Path(__file__).parent.absolute()
buildpath = srcpath / 'build'
create_build_dir(buildpath)
scaled_upper_triang_masked_softmax_cuda = cpp_extension.load( scaled_upper_triang_masked_softmax_cuda = cpp_extension.load(
name='scaled_upper_triang_masked_softmax_cuda', name='scaled_upper_triang_masked_softmax_cuda',
sources=[srcpath / 'scaled_upper_triang_masked_softmax.cpp', sources=[srcpath / 'scaled_upper_triang_masked_softmax.cpp',
srcpath / 'scaled_upper_triang_masked_softmax_cuda.cu'], srcpath / 'scaled_upper_triang_masked_softmax_cuda.cu'],
build_directory=srcpath / 'build', build_directory=buildpath,
extra_cflags=['-O3',], extra_cflags=['-O3',],
extra_cuda_cflags=['-O3', extra_cuda_cflags=['-O3',
'-gencode', 'arch=compute_70,code=sm_70', '-gencode', 'arch=compute_70,code=sm_70',
...@@ -72,11 +82,15 @@ def load_scaled_masked_softmax_fusion_kernel(): ...@@ -72,11 +82,15 @@ def load_scaled_masked_softmax_fusion_kernel():
cc_flag.append('arch=compute_80,code=sm_80') cc_flag.append('arch=compute_80,code=sm_80')
srcpath = pathlib.Path(__file__).parent.absolute() srcpath = pathlib.Path(__file__).parent.absolute()
buildpath = srcpath / 'build'
create_build_dir(buildpath)
scaled_upper_triang_masked_softmax_cuda = cpp_extension.load( scaled_upper_triang_masked_softmax_cuda = cpp_extension.load(
name='scaled_masked_softmax_cuda', name='scaled_masked_softmax_cuda',
sources=[srcpath / 'scaled_masked_softmax.cpp', sources=[srcpath / 'scaled_masked_softmax.cpp',
srcpath / 'scaled_masked_softmax_cuda.cu'], srcpath / 'scaled_masked_softmax_cuda.cu'],
build_directory=srcpath / 'build', build_directory=buildpath,
extra_cflags=['-O3',], extra_cflags=['-O3',],
extra_cuda_cflags=['-O3', extra_cuda_cflags=['-O3',
'-gencode', 'arch=compute_70,code=sm_70', '-gencode', 'arch=compute_70,code=sm_70',
......
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