-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgo_fish.py
More file actions
executable file
·119 lines (98 loc) · 3.71 KB
/
Copy pathgo_fish.py
File metadata and controls
executable file
·119 lines (98 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env python3
###############################################################################
#
# MIT License
#
# Copyright (c) 2022 Advanced Micro Devices, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
###############################################################################
"""! @brief Script to launch tuning jobs, or execute commands on available machines"""
import os
import argparse
import sys
import logging
from typing import Dict, List, Any, Union
from tuna.utils.logger import setup_logger
from tuna.libraries import Library
from tuna.lib_utils import get_library
from tuna.miopen.miopen_lib import MIOpen
from tuna.example.example_lib import Example
from tuna.yaml_parser import parse_yaml
from tuna.parse_args import clean_args
# Setup logging
LOGGER: logging.Logger = setup_logger('go_fish')
def parse_args() -> Dict[str, Any]:
"""Function to parse arguments"""
args: argparse.Namespace
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('lib',
nargs='?',
default=Library.MIOPEN,
type=Library,
help="Specify library to run",
choices=Library)
parser.add_argument('--yaml',
dest='yaml',
default=None,
help='Path to yaml input file')
args, _ = parser.parse_known_args()
if '--yaml' in sys.argv and len(sys.argv) > 4:
parser.error('Command line arguments not accepted with yaml file')
return vars(args)
def main() -> bool:
"""Main function to start Tuna"""
args: Dict[str, Any]
args = parse_args()
clean_args()
#case no yaml file
library: Union[Example, MIOpen]
yaml_files: List[str]
library = get_library(args)
yaml_files = [args['yaml']]
#case with yaml file
if args['yaml']:
yaml_files = parse_yaml(args['yaml'], args['lib'])
job_batch_size = 1000
if 'TUNA_CELERY_JOB_BATCH_SIZE' in os.environ:
job_batch_size = int(os.environ['TUNA_CELERY_JOB_BATCH_SIZE'])
try:
for yaml_file in yaml_files:
args['yaml_file'] = yaml_file
if args['yaml_file']:
sys.argv[2] = yaml_file
LOGGER.info("Executing with yaml file: %s", yaml_file)
if library.has_tunable_operation():
#Celery operations
library.tune(job_batch_size=job_batch_size)
else:
#non-celery operations
#returns a list of workers/processes it started
worker_lst = library.run()
if worker_lst is None:
continue
for worker in worker_lst:
worker.join()
LOGGER.warning('Process finished')
except KeyboardInterrupt:
LOGGER.warning('Interrupt signal caught')
return True
if __name__ == '__main__':
main()