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

Timing for build #1048

Merged
merged 8 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
5 changes: 5 additions & 0 deletions build_tools/build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sys
import sysconfig
import copy
import time

from pathlib import Path
from subprocess import CalledProcessError
Expand Down Expand Up @@ -81,13 +82,17 @@ def _build_cmake(self, build_dir: Path, install_dir: Path) -> None:
build_command.append(str(max_jobs))

# Run CMake commands
start_time = time.perf_counter()
for command in [configure_command, build_command, install_command]:
print(f"Running command {' '.join(command)}")
try:
subprocess.run(command, cwd=build_dir, check=True)
except (CalledProcessError, OSError) as e:
raise RuntimeError(f"Error when running CMake: {e}")

total_time = time.perf_counter() - start_time
print(f"Time for build_ext: {total_time:.2f} seconds")


def get_build_ext(extension_cls: Type[setuptools.Extension]):
class _CMakeBuildExtension(extension_cls):
Expand Down
22 changes: 21 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
"""Installation script."""

import os
import time
from pathlib import Path
from typing import List, Tuple

import setuptools
from wheel.bdist_wheel import bdist_wheel

from build_tools.build_ext import CMakeExtension, get_build_ext
from build_tools.utils import (
Expand Down Expand Up @@ -39,10 +41,23 @@
install_and_import("pybind11[global]")
from pybind11.setup_helpers import build_ext as BuildExtension

# Start timing
start_time = time.perf_counter()


CMakeBuildExtension = get_build_ext(BuildExtension)


class TimedBdist(bdist_wheel):
"""Helper class to measure build time"""

def run(self):
start_time = time.perf_counter()
super().run()
total_time = time.perf_counter() - start_time
print(f"Time for bdist_wheel: {total_time:.2f} seconds")


def setup_common_extension() -> CMakeExtension:
"""Setup CMake extension for common library"""
# Project directory root
Expand Down Expand Up @@ -141,7 +156,7 @@ def setup_requirements() -> Tuple[List[str], List[str], List[str]]:
},
description="Transformer acceleration library",
ext_modules=ext_modules,
cmdclass={"build_ext": CMakeBuildExtension},
cmdclass={"build_ext": CMakeBuildExtension, "bdist_wheel": TimedBdist},
python_requires=">=3.8, <3.13",
classifiers=[
"Programming Language :: Python :: 3.8",
Expand All @@ -156,3 +171,8 @@ def setup_requirements() -> Tuple[List[str], List[str], List[str]]:
include_package_data=True,
package_data={"": ["VERSION.txt"]},
)

# End timing
end_time = time.perf_counter()
total_time = end_time - start_time
print(f"Total build time: {total_time:.2f} seconds")
phu0ngng marked this conversation as resolved.
Show resolved Hide resolved
Loading