-
Notifications
You must be signed in to change notification settings - Fork 4
Performance studies #142
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
Merged
Merged
Performance studies #142
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
d43b18d
docs: update README
plexoos c22acd1
move code from esi-g4ox and rename files
plexoos 752f10a
build: add new executable simg4oxmt
plexoos 7940314
add run_performance.py script
plexoos 22ee1ae
add geom file pfrich_min_FINAL.gdml from esi-g4ox
plexoos 9ac2772
fix paths in performance script
plexoos a017d95
make run_performance to executable
plexoos 234bff2
Apply suggestions from code review
plexoos efe9b80
set output dir to /tmp
plexoos 0ef017d
refactor(run_performance): use argparse and pathlib for I/O path conf…
plexoos eb82acd
Update tests/geom/pfrich_min_FINAL.gdml
plexoos e4ef18b
Update src/simg4oxmt.cpp
plexoos f3f7a16
Update src/simg4oxmt.cpp
plexoos 7aa127d
Update README
plexoos 472b72b
Add OPTICKS_EVENT_MODE environment variable
ggalgoczi ab81134
Make run_performance.py use OPTICKS_HOME environment variable so it r…
ggalgoczi f3d977e
Move particle gun to create photons in raindrop geom
ggalgoczi 3a4bc9c
Reduce number of beamOn events from 50000 to 500 to be sure to make i…
ggalgoczi 4096e4e
Add log file for performance run outputs
ggalgoczi 0c4da79
Update README with user-defined inputs
ggalgoczi 22bf1e0
Update README with setStackPhotons and GDML details
ggalgoczi 5e4b12b
Change default GDML path raindrop in run_performance.py
ggalgoczi 13729f3
Enhance README with performance studies details
ggalgoczi a76e557
Merge branch 'main' into performance-studies
plexoos 96e1e8d
docs(README): fix formatting/line-wrapping
plexoos ff34c93
style(opticks_raindrop.gdml): whitespace and indentation cleanup only
plexoos 04f4d4a
workaround for incorrect ray intersections with open cones
plexoos 8be5074
Revert "Move particle gun to create photons in raindrop geom"
plexoos 6e16acb
Revert "workaround for incorrect ray intersections with open cones"
plexoos 8936907
workaround for incorrect ray intersections with open cones - 2
plexoos a4bb33f
Revert "workaround for incorrect ray intersections with open cones - 2"
plexoos 683cf3a
Update position in GeneratePrimaries method
ggalgoczi 4101e08
Reorder physvolref elements in opticks_raindrop.gdml
ggalgoczi 7fd2968
Log number of PhotonHits at end of event
ggalgoczi 1715f2e
Change kinetic energy of particle from 5 GeV to 0.005 GeV
ggalgoczi b327ff2
Revert "Change kinetic energy of particle from 5 GeV to 0.005 GeV"
plexoos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,5 +119,3 @@ void intersect_leaf_newcone( bool& valid_isect, float4& isect, const quad& q0, c | |
| isect.w = t_cand ; | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import argparse | ||
| import subprocess | ||
| import re | ||
| import os | ||
| from pathlib import Path | ||
|
|
||
| run_mac_template = """ | ||
| /run/numberOfThreads {threads} | ||
| /run/verbose 1 | ||
| /process/optical/cerenkov/setStackPhotons {flag} | ||
| /run/initialize | ||
| /run/beamOn 500 | ||
| """ | ||
|
|
||
| os.environ["OPTICKS_EVENT_MODE"] = "Minimal" | ||
|
|
||
| def get_opticks_home(): | ||
| """Get OPTICKS_HOME from environment, warn if not set.""" | ||
| opticks_home = os.environ.get("OPTICKS_HOME") | ||
| if opticks_home is None: | ||
| print("Warning: $OPTICKS_HOME is not defined, so this script should be called from the eic-opticks directory.") | ||
| return Path(".") | ||
| return Path(opticks_home) | ||
|
|
||
| def parse_real_time(time_str): | ||
| # Parses 'real\t0m41.149s' to seconds | ||
| match = re.search(r'real\s+(\d+)m([\d.]+)s', time_str) | ||
| if match: | ||
| minutes = int(match.group(1)) | ||
| seconds = float(match.group(2)) | ||
| return minutes * 60 + seconds | ||
| return None | ||
|
|
||
| def parse_sim_time(output): | ||
| match = re.search(r"Simulation time:\s*([\d.]+)\s*seconds", output) | ||
| if match: | ||
| return float(match.group(1)) | ||
| return None | ||
|
|
||
| def main(): | ||
| opticks_home = get_opticks_home() | ||
|
|
||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument('-g', '--gdml', type=Path, default=None, help="Path to a custom GDML geometry file (relative to current directory)") | ||
| parser.add_argument('-o', '--outpath', type=Path, default=Path('./'), help="Path where the output file will be saved") | ||
| args = parser.parse_args() | ||
|
|
||
| # If gdml not provided, use default path relative to OPTICKS_HOME | ||
| if args.gdml is None: | ||
| gdml_path = opticks_home / 'tests/geom/opticks_raindrop.gdml' | ||
| else: | ||
| # User-provided path is used as-is (relative to current directory or absolute) | ||
| gdml_path = args.gdml | ||
|
|
||
| # run.mac is created in OPTICKS_HOME | ||
| run_mac_path = opticks_home / "run.mac" | ||
|
|
||
| geant_file = args.outpath / "timing_geant.txt" | ||
| optix_file = args.outpath / "timing_optix.txt" | ||
| log_file = args.outpath / "g4logs.txt" | ||
|
|
||
| with open(geant_file, "w") as gfile, open(optix_file, "w") as ofile, open(log_file, "w") as logfile: | ||
| for threads in range(50, 0, -1): | ||
| times = {} | ||
| sim_time_true = None | ||
| for flag in ['true', 'false']: | ||
| # Write run.mac with current flag | ||
| with open(run_mac_path, "w") as rm: | ||
| rm.write(run_mac_template.format(threads=threads, flag=flag)) | ||
|
|
||
| # Run with time in bash to capture real/user/sys | ||
| cmd = f"time simg4oxmt -g {gdml_path} -m {run_mac_path}" | ||
| print(f"Running {threads} threads: {cmd}") | ||
| result = subprocess.run( | ||
| ["bash", "-c", cmd], | ||
| capture_output=True, text=True | ||
| ) | ||
| stdout = result.stdout | ||
| stderr = result.stderr | ||
| # Save full output to log file | ||
| logfile.write(f"\n{'='*60}\n") | ||
| logfile.write(f"Threads: {threads}, StackPhotons: {flag}\n") | ||
| logfile.write(f"{'='*60}\n") | ||
| logfile.write(f"--- STDOUT ---\n{stdout}\n") | ||
| logfile.write(f"--- STDERR ---\n{stderr}\n") | ||
| logfile.flush() | ||
|
|
||
| # Save simulation time for true run only | ||
| if flag == 'true': | ||
| sim_time_true = parse_sim_time(stdout + stderr) | ||
| if sim_time_true is not None: | ||
| ofile.write(f"{threads} {sim_time_true}\n") | ||
| ofile.flush() | ||
|
|
||
| # Extract real time | ||
| real_match = re.search(r"real\s+\d+m[\d.]+s", stderr) | ||
| if real_match: | ||
| real_sec = parse_real_time(real_match.group()) | ||
| times[flag] = real_sec | ||
| else: | ||
| print(f"[!] Could not find 'real' time for threads={threads} flag={flag}") | ||
|
|
||
| # Write the difference to timing_geant.txt (true - false) | ||
| if 'true' in times and 'false' in times: | ||
| diff = times['true'] - times['false'] | ||
| gfile.write(f"{threads} {diff}\n") | ||
| gfile.flush() | ||
| else: | ||
| print(f"[!] Missing times for threads={threads}") | ||
|
|
||
| print("Done.") | ||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this number reduced? What small GPU RAM are you referring to? For consistency, we should be able to reproduce the published results using the same number of events.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this repository, the event count is set to a conservative default because the goal of this example is to help users get a first successful run with EIC-Opticks and understand the workflow, not to serve as a paper quality reproduction test. Since users run on a wide range of hardware, a high default can fail on GPUs with limited VRAM and lead to crashes/segfaults that are frustrating to debug as a first step.
Also, because we swapped the geometry, the performance and scaling will not match the paper one-to-one anyway, the achievable speedup depends on geometry and workload characteristics.
To keep things consistent and reproducible, the README explicitly notes that users should set the event count themselves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, what kind of speedup do you see with this geometry? Is it far from the public numbers?
If I use pfrich_min_FINAL.gdml and the patch for open cones, should I expect to reproduce the numbers in the paper?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not check. Can you check how much speedup you get?
Yes. I tested it and sent you the example result Dec 8. 3:58 PM in mattermost chat.