-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8800ff1
commit e2c4df5
Showing
4 changed files
with
85 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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 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 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,30 @@ | ||
[ | ||
{ | ||
"filename": "allreduce_allpairs_packet.py", | ||
"args": ["8", "8"] | ||
}, | ||
{ | ||
"filename": "allreduce_allpairs_get.py", | ||
"args": ["8", "8"] | ||
}, | ||
{ | ||
"filename": "allreduce_allpairs.py", | ||
"args": ["8", "8"] | ||
}, | ||
{ | ||
"filename": "allreduce_ring.py", | ||
"args": ["8", "8"] | ||
}, | ||
{ | ||
"filename": "send_recv_packet.py", | ||
"args": ["2"] | ||
}, | ||
{ | ||
"filename": "send_recv_proxy.py", | ||
"args": ["2"] | ||
}, | ||
{ | ||
"filename": "allreduce_nvls.py", | ||
"args": ["8", "2"] | ||
} | ||
] |
This file contains 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,47 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
import argparse | ||
import json | ||
from pathlib import Path | ||
import subprocess | ||
|
||
|
||
def run_examples(input_folder, configs, output_folder): | ||
for config in configs: | ||
file_name = config["filename"] | ||
args = config["args"] | ||
|
||
input_file_path = Path(input_folder) / file_name | ||
# Strip the ".py" from the filename and add ".output" | ||
base_file_name = file_name[:-3] if file_name.endswith(".py") else file_name | ||
base_file_name = base_file_name.replace("/", "_") | ||
output_file_path = Path(output_folder) / f"{base_file_name}.output" | ||
|
||
# Construct the command to run the Python script | ||
command = ["python3", str(input_file_path)] + args | ||
|
||
# Run the command and capture output | ||
with open(output_file_path, "w") as output_file: | ||
result = subprocess.run(command, stdout=output_file, stderr=subprocess.STDOUT, text=True) | ||
|
||
# Optional: Check the return code to handle errors | ||
if result.returncode != 0: | ||
print(f"Error running {file_name}. See {output_file_path} for details.") | ||
|
||
|
||
def main(input_folder, config_path, output_folder): | ||
with open(config_path, "r") as f: | ||
config = json.load(f) | ||
|
||
Path(output_folder).mkdir(parents=True, exist_ok=True) | ||
run_examples(input_folder, config, output_folder) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description="Process files according to a configuration and save the results.") | ||
parser.add_argument("input_folder", type=str, help="Path to the folder containing the input files.") | ||
parser.add_argument("config", type=str, help="Path to the configuration file.") | ||
parser.add_argument("output_folder", type=str, help="Path to the folder where the processed files will be saved.") | ||
args = parser.parse_args() | ||
main(args.input_folder, args.config, args.output_folder) |