Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable initial build for rocm for fp6_llm #1

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 36 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ def read_version(file_path="version.txt"):
CUDAExtension,
BuildExtension,
CUDA_HOME,
ROCM_HOME,
IS_WINDOWS
)

IS_ROCM = (torch.version.hip is not None) and (ROCM_HOME is not None)

def get_extensions():
debug_mode = os.getenv('DEBUG', '0') == '1'
Expand All @@ -57,11 +59,11 @@ def get_extensions():

if not torch.cuda.is_available():
print("PyTorch GPU support is not available. Skipping compilation of CUDA extensions")
if CUDA_HOME is None and torch.cuda.is_available():
print("CUDA toolkit is not available. Skipping compilation of CUDA extensions")
if CUDA_HOME is None or not IS_ROCM and torch.cuda.is_available():
print("CUDA toolkit or ROCm is not available. Skipping compilation of CUDA extensions")
print("If you'd like to compile CUDA extensions locally please install the cudatoolkit from https://anaconda.org/nvidia/cuda-toolkit")

use_cuda = torch.cuda.is_available() and CUDA_HOME is not None
use_cuda = torch.cuda.is_available() and (CUDA_HOME is not None or ROCM_HOME is not None)
extension = CUDAExtension if use_cuda else CppExtension

if not IS_WINDOWS:
Expand All @@ -71,15 +73,14 @@ def get_extensions():
"-O3" if not debug_mode else "-O0",
"-fdiagnostics-color=always",
],
"nvcc": [
"-O3" if not debug_mode else "-O0",
"-t=0",
]
}
if use_cuda and not IS_ROCM:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the compile flags for rocm?

extra_compile_args["nvcc"] = ["-O3" if not debug_mode else "-O0", "-t=0",]

if debug_mode:
extra_compile_args["cxx"].append("-g")
extra_compile_args["nvcc"].append("-g")
if "nvcc" in extra_compile_args:
extra_compile_args["nvcc"].append("-g")
extra_link_args.extend(["-O0", "-g"])

else:
Expand Down Expand Up @@ -107,17 +108,35 @@ def get_extensions():
extensions_cuda_dir = os.path.join(extensions_dir, "cuda")
cuda_sources = list(glob.glob(os.path.join(extensions_cuda_dir, "**/*.cu"), recursive=True))

if use_cuda:
extensions_hip_dir = os.path.join(extensions_dir, "cuda", "fp6_llm")
hip_sources = list(glob.glob(os.path.join(extensions_hip_dir, "*.cu"), recursive=True))
Copy link
Owner

@petrex petrex Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems fine for now, but we might have other extensions other than ".cu" later?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, once we enable all the extensions - we can remove hip_sources and start using cuda_sources directly.


if not IS_ROCM and use_cuda:
sources += cuda_sources

ext_modules = [
extension(
"torchao._C",
sources,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
)
]
# TOOD: Remove this and use what CUDA has once we fix all the builds.
if IS_ROCM and use_cuda:
sources += hip_sources

## TODO: remove this condition and use what we have in CUDA once we fix the individual builds.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

understand we are wip, might be able to consolidate the code later?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

if not IS_ROCM:
ext_modules = [
extension(
"torchao._C",
sources,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
)
]
else:
ext_modules = [
extension(
"torchao._C",
sources,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
)
]

return ext_modules

Expand Down
Loading