This repository was archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathgen_param.py
More file actions
75 lines (64 loc) · 2.58 KB
/
gen_param.py
File metadata and controls
75 lines (64 loc) · 2.58 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
#!/usr/bin/env python3
# /***************************************************************************
# *
# * @license
# * Copyright (C) Codeplay Software Limited
# * Licensed under the Apache License, Version 2.0 (the "License");
# * you may not use this file except in compliance with the License.
# * You may obtain a copy of the License at
# *
# * http://www.apache.org/licenses/LICENSE-2.0
# *
# * For your convenience, a copy of the License has been included in this
# * repository.
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
# *
# * portBLAS: BLAS implementation using SYCL
# *
# * @filename gen_param.py
# *
# **************************************************************************/
"""This tool generates CSV parameter files for the BLAS benchmarks, based on
expressions written in a domain-specific language.
See the documentation in README.md for more information.
"""
import itertools
import argparse
def main(args):
"""Generate the csv file according to the given arguments
"""
# Match DSL to Python names
nd_range = itertools.product
value_range = lambda *v: list(v)
def size_range(low, high, mult):
val = low
while val <= high:
yield val
val *= mult
concat_ranges = itertools.chain
gen_machine = eval(args.expr)
with open(args.output_file, "w") as f_write:
for line in gen_machine:
f_write.write(",".join(map(str, line)) + "\n")
def get_args(args_str=""):
"""Parse the command line arguments (displays information if the -h or
--help option is used)
"""
description = ("Tool to generate a csv file containing the parameters for "
" the benchmarks")
parser = argparse.ArgumentParser(description=description)
parser.add_argument("-o", dest="output_file",
default="params.csv", metavar="filepath",
help="Specify the name of the resulting CSV file")
parser.add_argument("-e", dest="expr", metavar="expression", required=True,
help="Expression used to generate the file, in a"
" domain-specific language (see README.md)")
args = parser.parse_args(args_str) if args_str else parser.parse_args()
return args
if __name__ == "__main__":
main(args=get_args())