Skip to content

Commit

Permalink
Timing for build (NVIDIA#1048)
Browse files Browse the repository at this point in the history
* add timing for build

* using perf_counter

---------

Signed-off-by: Phuong Nguyen <[email protected]>
  • Loading branch information
phu0ngng authored and mgoldfarb-nvidia committed Aug 14, 2024
1 parent 302cc22 commit 172dd51
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
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")

0 comments on commit 172dd51

Please sign in to comment.