| 1 |
# Copyright © Advanced Micro Devices, Inc., or its affiliates. |
| 2 |
# SPDX-License-Identifier: MIT |
| 3 |
|
| 4 |
import glob |
| 5 |
import os |
| 6 |
import shutil |
| 7 |
import sys |
| 8 |
import subprocess |
| 9 |
from setuptools import setup, Extension |
| 10 |
from setuptools.command.build_ext import build_ext |
| 11 |
|
| 12 |
class CMakeBuild(build_ext): |
| 13 |
def run(self): |
| 14 |
try: |
| 15 |
os.makedirs(self.build_temp, exist_ok=True) |
| 16 |
os.makedirs(self.build_lib, exist_ok=True) |
| 17 |
source_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', '..') |
| 18 |
rocm_path = os.environ.get('ROCM_PATH', '/opt/rocm') |
| 19 |
compilerpath = os.path.join(rocm_path, 'bin/amdclang++') |
| 20 |
cmakeargs = [ |
| 21 |
"cmake", |
| 22 |
"--preset rocisa", |
| 23 |
f"-S{source_dir}", |
| 24 |
f"-B{self.build_temp}", |
| 25 |
f"-DCMAKE_CXX_COMPILER={compilerpath}", |
| 26 |
"-DCMAKE_BUILD_TYPE=Release", |
| 27 |
f"-DPython_EXECUTABLE={sys.executable}", |
| 28 |
] |
| 29 |
if sys.platform == "win32": |
| 30 |
cmakeargs.extend(["-A", "x64"]) |
| 31 |
subprocess.check_call(cmakeargs) |
| 32 |
make_args = [ |
| 33 |
"cmake", |
| 34 |
"--build", |
| 35 |
self.build_temp, |
| 36 |
"--config", |
| 37 |
"Release", |
| 38 |
"-j", |
| 39 |
"8", |
| 40 |
] |
| 41 |
subprocess.check_call(make_args) |
| 42 |
ext_suffix = ".so" if sys.platform != "win32" else ".pyd" |
| 43 |
build_module = glob.glob(os.path.join(self.build_temp, 'tensilelite', 'rocisa', "lib", f"rocisa*{ext_suffix}"))[0] |
| 44 |
target_module = os.path.join(self.build_lib, os.path.basename(build_module)) |
| 45 |
shutil.copy2(build_module, target_module) |
| 46 |
except subprocess.CalledProcessError as e: |
| 47 |
print(f"An error occurred while building with CMake: {e}") |
| 48 |
assert 0 |
| 49 |
|
| 50 |
setup( |
| 51 |
name='rocisa', |
| 52 |
version="0.1.0", |
| 53 |
packages=["rocisa"], |
| 54 |
ext_modules=[Extension("rocisa", sources=[])], |
| 55 |
install_requires=["nanobind"], |
| 56 |
cmdclass={"build_ext": CMakeBuild}, |
| 57 |
author='YangWen Huang', |
| 58 |
author_email='[email protected]', |
| 59 |
description='A C++ code generator for ROCm ISA', |
| 60 |
long_description=open('README.md').read(), |
| 61 |
url='https://github.com/ROCm/hipBLASLt', |
| 62 |
classifiers=[ |
| 63 |
'Programming Language :: Python :: 3', |
| 64 |
'License :: OSI Approved :: MIT License', |
| 65 |
'Operating System :: OS Independent', |
| 66 |
], |
| 67 |
python_requires='>=3.8', |
| 68 |
) |