Skip to content

Commit f8fc9be

Browse files
committed
GPU: Add converter scripts for CSV parameter file to JSON and vice versa
1 parent 414ba09 commit f8fc9be

File tree

3 files changed

+97
-1
lines changed

3 files changed

+97
-1
lines changed

GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ int32_t GPUReconstructionCUDA::InitDevice_Runtime()
189189
bestDeviceSpeed = deviceSpeed;
190190
} else {
191191
if (GetProcessingSettings().debugLevel >= 2 && GetProcessingSettings().deviceNum < 0) {
192-
GPUInfo("Skipping: Speed %f < %f\n", deviceSpeed, bestDeviceSpeed);
192+
GPUInfo("Skipping: Speed %f <= %f\n", deviceSpeed, bestDeviceSpeed);
193193
}
194194
}
195195
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
3+
[[ -z $1 ]] && { echo "Usage: csv_to_json.sh CSV_FILE"; exit 1; }
4+
5+
awk -vFPAT='([^,]*)|(\"([^\"]|\"\")*\")' \
6+
'BEGIN {
7+
print "{"
8+
} {
9+
if (count == 0) {
10+
for (i = 1; i <= NF; i++) {
11+
names[i] = $i
12+
}
13+
} else if ($1 == "CORE:" || $1 == "LB:" || $1 == "PAR:") {
14+
if (paramprinted) print "\n }"
15+
else if (lineprinted) print ""
16+
if (catprinted) print " },"
17+
lineprinted = 0
18+
paramprinted = 0
19+
catprinted = 1
20+
gsub(/:$/, "", $1)
21+
print " \""$1"\": {";
22+
} else if ($1 != "") {
23+
if (lineprinted) print ""
24+
if (paramprinted) print " },"
25+
lineprinted = 0
26+
paramprinted = 1
27+
print " \""$1"\": {";
28+
lineprinted = 0
29+
for (i=2; i<=NF; i++) {
30+
if ($i != "") {
31+
gsub(/^"/, "", $i)
32+
gsub(/"$/, "", $i)
33+
gsub(/""/, "\"", $i)
34+
if (lineprinted) print ","
35+
lineprinted = 1
36+
printf(" \"%s\": %s", names[i], $i)
37+
}
38+
}
39+
}
40+
count++;
41+
} END {
42+
if (paramprinted) print "\n }"
43+
if (catprinted) print " }"
44+
print "}"
45+
}' \
46+
$1
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python3
2+
import sys, json, csv, string
3+
4+
if len(sys.argv) != 3:
5+
sys.exit("usage: json2csv.py input.json output.csv")
6+
7+
try:
8+
data = json.load(open(sys.argv[1]))
9+
except Exception:
10+
sys.exit("invalid json")
11+
12+
if set(data) != {"CORE", "LB", "PAR"}:
13+
sys.exit("invalid categories")
14+
15+
arches = []
16+
seen = set()
17+
for cat in data.values():
18+
if not isinstance(cat, dict):
19+
sys.exit("data not 2-dimensional")
20+
for param in cat.values():
21+
if not isinstance(param, dict):
22+
sys.exit("data not 2-dimensional")
23+
for a in param.keys():
24+
if a not in seen:
25+
seen.add(a)
26+
arches.append(a)
27+
28+
cols = 1 + len(arches)
29+
empty = [""] * cols
30+
31+
with open(sys.argv[2], "w", newline="") as f:
32+
w = csv.writer(f, lineterminator="\n")
33+
w.writerow(["Architecture", *arches])
34+
w.writerow(empty)
35+
cats = list(data.items())
36+
for ci, (cname, cat) in enumerate(cats):
37+
w.writerow([f"{cname}:"] + [""] * (cols - 1))
38+
for pname, param in cat.items():
39+
row = [pname]
40+
for a in arches:
41+
v = param.get(a, "")
42+
if isinstance(v, list):
43+
row.append(json.dumps(v))
44+
elif isinstance(v, str) and not v == "":
45+
row.append('"' + v + '"')
46+
else:
47+
row.append(v)
48+
w.writerow(row)
49+
if ci != len(cats) - 1:
50+
w.writerow(empty)

0 commit comments

Comments
 (0)