From 739387ea42f821d1e16913d9c8e995745c402f93 Mon Sep 17 00:00:00 2001 From: Nikolas Date: Mon, 8 Jul 2024 17:40:26 -0700 Subject: [PATCH] initi --- .gitignore | 3 +++ CHANGELOG.md | 4 +++ c-ray/README.md | 13 ++++++++++ c-ray/cray.py | 61 ++++++++++++++++++++++++++++++++++++++++++++ c-ray/cray_utils.py | 31 ++++++++++++++++++++++ c-ray/manifest.yaml | 5 ++++ licenses/licenses.md | 1 + 7 files changed, 118 insertions(+) create mode 100644 c-ray/README.md create mode 100644 c-ray/cray.py create mode 100644 c-ray/cray_utils.py create mode 100644 c-ray/manifest.yaml diff --git a/.gitignore b/.gitignore index 4a608f9..d460c24 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,9 @@ basegame_no_intro_videos.archive *.blend 0001.png *.msi +c-ray-fast* +sphfract.scn +output.ppm # python __pycache__/ \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e84f76..9481013 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. Changes are grouped by the date they are merged to the main branch of the repository and are ordered from newest to oldest. Dates use the ISO 8601 extended calendar date format, i.e. YYYY-MM-DD. +## 2024-07-08 + +- Add initial c-ray harness. + ## 2024-07-05 - Add initial primesieve harness. diff --git a/c-ray/README.md b/c-ray/README.md new file mode 100644 index 0000000..842d1e9 --- /dev/null +++ b/c-ray/README.md @@ -0,0 +1,13 @@ +# Primesieve + +Wrapper for [c-ray](https://github.com/jtsiomb/c-ray) test which is a simple ray tracer widely used as a benchmark. Good for measuring pure floating point performance. + +## Prerequisites + +- Python 3.10+ + +## Output + +report.json +- `score`: the average duration in seconds +- `version`: the version of c-ray \ No newline at end of file diff --git a/c-ray/cray.py b/c-ray/cray.py new file mode 100644 index 0000000..39178c7 --- /dev/null +++ b/c-ray/cray.py @@ -0,0 +1,61 @@ +"""Test script for primesieve""" +import json +import logging +import os.path +import subprocess +import sys +import re + +sys.path.insert(1, os.path.join(sys.path[0], "..")) + +from cray_utils import current_time_ms, cray_executable_exists, copy_from_network_drive, CRAY_EXECUTABLE + +script_dir = os.path.dirname(os.path.realpath(__file__)) +log_dir = os.path.join(script_dir, "run") +if not os.path.isdir(log_dir): + os.mkdir(log_dir) +LOGGING_FORMAT = '%(asctime)s %(levelname)-s %(message)s' +logging.basicConfig(filename=f'{log_dir}/harness.log', + format=LOGGING_FORMAT, + datefmt='%m-%d %H:%M', + level=logging.DEBUG) +console = logging.StreamHandler() +formatter = logging.Formatter(LOGGING_FORMAT) +console.setFormatter(formatter) +logging.getLogger('').addHandler(console) + +if cray_executable_exists() is False: + logging.info("Copying c-ray from network drive") + copy_from_network_drive() + +ABS_EXECUTABLE_PATH = os.path.join(script_dir, CRAY_EXECUTABLE) + +# omit the first arg which is the script name +command = f'{ABS_EXECUTABLE_PATH}' +command = command.rstrip() +scores = [] +start_time = current_time_ms() +for i in range(3): + output = subprocess.check_output([command, "-s", "5120x2880", "-i", "sphfract.scn", "-o", "output.ppm"], text=True, stderr=subprocess.STDOUT) + SCORE_PATTERN = r'Rendering.* \((\d+) milliseconds\)' + if "seconds" in output: + duration = re.match(SCORE_PATTERN, output).group(1) + scores.append(float(duration)) +end_time = current_time_ms() + +SCORE_SUM = 0 +for score in scores: + SCORE_SUM += score +avg_score = round(SCORE_SUM / len(scores), 2) + +report = { + "start_time": start_time, + "version": "2.0", + "end_time": end_time, + "score": avg_score, + "unit": "milliseconds", + "test": "c-ray 5120x2880" +} + +with open(os.path.join(log_dir, "report.json"), "w", encoding="utf-8") as report_file: + report_file.write(json.dumps(report)) diff --git a/c-ray/cray_utils.py b/c-ray/cray_utils.py new file mode 100644 index 0000000..4f17b2e --- /dev/null +++ b/c-ray/cray_utils.py @@ -0,0 +1,31 @@ +"""collection of functions to assist in running of primesieve test script""" +import os +from pathlib import Path +import time +import shutil + +CRAY_EXECUTABLE = "c-ray-fast_x86_64.exe" +SCRIPT_DIR = Path(os.path.dirname(os.path.realpath(__file__))) + + +def cray_executable_exists() -> bool: + """Check if cray has been downloaded or not""" + return os.path.isfile(os.path.join(SCRIPT_DIR, CRAY_EXECUTABLE)) + + +def copy_from_network_drive(): + """Download cray from network drive""" + source = r"\\Labs\labs\01_Installers_Utilities\C-Ray\c-ray-fast_x86_64.exe" + root_dir = os.path.dirname(os.path.realpath(__file__)) + destination = os.path.join(root_dir, CRAY_EXECUTABLE) + shutil.copyfile(source, destination) + + source = r"\\Labs\labs\01_Installers_Utilities\C-Ray\sphfract.scn" + root_dir = os.path.dirname(os.path.realpath(__file__)) + destination = os.path.join(root_dir, "sphfract.scn") + shutil.copyfile(source, destination) + + +def current_time_ms(): + """Get current timestamp in milliseconds since epoch""" + return int(time.time() * 1000) diff --git a/c-ray/manifest.yaml b/c-ray/manifest.yaml new file mode 100644 index 0000000..d74f5ba --- /dev/null +++ b/c-ray/manifest.yaml @@ -0,0 +1,5 @@ +friendly_name: "C-ray" +executable: "cray.py" +process_name: "c-ray-fast.exe" +disable_presentmon: true +output_dir: "run" diff --git a/licenses/licenses.md b/licenses/licenses.md index 798d4db..90d1b4f 100644 --- a/licenses/licenses.md +++ b/licenses/licenses.md @@ -11,6 +11,7 @@ Links to licenses and repositories of dependencies used throughout MarkBench tes | FLAC Audio Encode | [FLAC](https://xiph.org/flac/index.html) | [BSD](https://xiph.org/flac/license.html) | | y-cruncher | [y-cruncher](http://www.numberworld.org/y-cruncher/) | [Unique](http://www.numberworld.org/y-cruncher/license.html) | | primesieve | [primesieve](https://github.com/kimwalisch/primesieve?tab=BSD-2-Clause-1-ov-file#readme) | [BSD-2](https://github.com/kimwalisch/primesieve?tab=BSD-2-Clause-1-ov-file#readme) | +| C-ray | [c-ray](https://github.com/jtsiomb/c-ray) | [GPL-3.0](https://github.com/jtsiomb/c-ray?tab=GPL-3.0-1-ov-file#readme) ## Required files