From d91125723e9bc924a0736a8600b45f8ae0517944 Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Sun, 27 Apr 2025 17:34:01 +0800 Subject: [PATCH 1/3] tools/x264_perf_O3: support to disable loop vectorize optimization for `get_ref` --- pyproject.toml | 4 +++- tools/x264_perf_O3.py | 28 ++++++++++++++++++++++++---- uv.lock | 16 ++++++++++++++++ 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d9c9b93..9ba829f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,9 @@ version = "0.1.0" description = "Scripts that helps debugging SPEC CPU benchmark suite." readme = "README.md" requires-python = ">=3.12" -dependencies = [] +dependencies = [ + "click>=8.1.8", +] [tool.setuptools] packages = { find = { where = ["src"] } } diff --git a/tools/x264_perf_O3.py b/tools/x264_perf_O3.py index d4e7fe4..6f3c06b 100644 --- a/tools/x264_perf_O3.py +++ b/tools/x264_perf_O3.py @@ -1,19 +1,38 @@ from pathlib import Path from subprocess import run -from speccpu import get_benchspec_dir, x264 +import click + +from speccpu import create_spec_env, get_benchspec_dir, x264 from speccpu.flaglib.perf import record as recordflags -def main(): +@click.command() +@click.option( + "--disable-get-ref-vectorize", + type=bool, + default=False, + help="Enable or disable MC vectorization", +) +@click.option( + "--spec", + type=Path, + help="Path to SPEC CPU directory", +) +def main(disable_get_ref_vectorize: bool, spec: Path): x264_run_id = "c56635a4-9f49-4d2b-be79-38d9e08097c5" x264_outputroot = Path("/home/lyc/work-ts/local/specOutput") / x264_run_id - x264_dir = get_benchspec_dir(x264_outputroot) / "625.x264_s" x264_run = x264_dir / "run" / "run_base_refspeed_mytest-m64.0000" + x264_exe = x264_run / "x264_s_base.mytest-m64" + if disable_get_ref_vectorize: + mc_src = x264.MCBuilder().with_disabled_vectorize_get_ref().build() + x264_exe = x264.recompile_mc_src( + mc_src, x264_dir / "build", create_spec_env(spec) + ) run( [ @@ -21,7 +40,7 @@ def main(): "record", *recordflags( [ - str(x264_run / "x264_s_base.mytest-m64"), + str(x264_exe), *x264.specinvoke_args["ref"], ], output=str(Path.cwd() / f"x264-{x264_run_id}perf"), @@ -31,5 +50,6 @@ def main(): cwd=x264_run, ) + if __name__ == "__main__": main() diff --git a/uv.lock b/uv.lock index 0596e5d..f07ce00 100644 --- a/uv.lock +++ b/uv.lock @@ -2,6 +2,18 @@ version = 1 revision = 1 requires-python = ">=3.12" +[[package]] +name = "click" +version = "8.1.8" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "colorama", marker = "sys_platform == 'win32'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/b9/2e/0090cbf739cee7d23781ad4b89a9894a41538e4fcf4c31dcdd705b78eb8b/click-8.1.8.tar.gz", hash = "sha256:ed53c9d8990d83c2a27deae68e4ee337473f6330c040a31d4225c9574d16096a", size = 226593 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/7e/d4/7ebdbd03970677812aac39c869717059dbb71a4cfc033ca6e5221787892c/click-8.1.8-py3-none-any.whl", hash = "sha256:63c132bbbed01578a06712a2d1f497bb62d9c1c0d329b7903a866228027263b2", size = 98188 }, +] + [[package]] name = "colorama" version = "0.4.6" @@ -57,6 +69,9 @@ wheels = [ name = "speccpulib" version = "0.1.0" source = { virtual = "." } +dependencies = [ + { name = "click" }, +] [package.dev-dependencies] dev = [ @@ -64,6 +79,7 @@ dev = [ ] [package.metadata] +requires-dist = [{ name = "click", specifier = ">=8.1.8" }] [package.metadata.requires-dev] dev = [{ name = "pytest", specifier = ">=8.3.5" }] -- 2.51.0 From db474163ea3da78ce76851f9817077f0e56f1d30 Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Sun, 27 Apr 2025 19:14:41 +0800 Subject: [PATCH 2/3] fixup options --- tools/x264_perf_O3.py | 48 +++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/tools/x264_perf_O3.py b/tools/x264_perf_O3.py index 6f3c06b..a84f4c5 100644 --- a/tools/x264_perf_O3.py +++ b/tools/x264_perf_O3.py @@ -3,37 +3,55 @@ from subprocess import run import click -from speccpu import create_spec_env, get_benchspec_dir, x264 +from speccpu import create_spec_env, find_build, get_benchspec_dir, x264 from speccpu.flaglib.perf import record as recordflags @click.command() @click.option( - "--disable-get-ref-vectorize", - type=bool, - default=False, + "--get-ref-vectorize/--no-get-ref-vectorize", + default=True, help="Enable or disable MC vectorization", ) @click.option( "--spec", - type=Path, + type=click.Path(), help="Path to SPEC CPU directory", + required=True, ) -def main(disable_get_ref_vectorize: bool, spec: Path): - x264_run_id = "c56635a4-9f49-4d2b-be79-38d9e08097c5" - x264_outputroot = Path("/home/lyc/work-ts/local/specOutput") / x264_run_id - - x264_dir = get_benchspec_dir(x264_outputroot) / "625.x264_s" +@click.option( + "--x264-run-id", + type=str, + required=True, +) +@click.option( + "--outputroot", + type=click.Path(), + required=True, +) +def main( + get_ref_vectorize: bool, + spec, + x264_run_id: str, + outputroot, +): + outputroot = Path(outputroot) + spec = Path(spec) + x264_dir = get_benchspec_dir(outputroot / x264_run_id) / "625.x264_s" x264_run = x264_dir / "run" / "run_base_refspeed_mytest-m64.0000" x264_exe = x264_run / "x264_s_base.mytest-m64" - if disable_get_ref_vectorize: - mc_src = x264.MCBuilder().with_disabled_vectorize_get_ref().build() - x264_exe = x264.recompile_mc_src( - mc_src, x264_dir / "build", create_spec_env(spec) - ) + mc_builder = x264.MCBuilder() + if not get_ref_vectorize: + mc_builder.with_disabled_vectorize_get_ref() + + x264_exe = x264.recompile_mc_src( + mc_builder.build(), + find_build(x264_dir / "build"), + create_spec_env(spec), + ) run( [ "perf", -- 2.51.0 From ed5c2efab8611e9b6618cf88e0e145e9499d057b Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Sun, 27 Apr 2025 19:17:12 +0800 Subject: [PATCH 3/3] tools/x264_perf_O3: fixup help message --- tools/x264_perf_O3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/x264_perf_O3.py b/tools/x264_perf_O3.py index a84f4c5..d637c7d 100644 --- a/tools/x264_perf_O3.py +++ b/tools/x264_perf_O3.py @@ -11,7 +11,7 @@ from speccpu.flaglib.perf import record as recordflags @click.option( "--get-ref-vectorize/--no-get-ref-vectorize", default=True, - help="Enable or disable MC vectorization", + help="Enable or disable mc.c `get_ref` vectorization", ) @click.option( "--spec", -- 2.51.0