Skip to content

Commit

Permalink
pre-commit: add check-ast and fix Python-3 syntax errors where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-zero committed May 16, 2019
1 parent 787eb39 commit b8129c3
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 41 deletions.
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ repos:
hooks:
- id: check-yaml
- id: check-added-large-files
- id: check-ast
exclude: >-
(?x)^(
tools/autotune_grid/xyz_to_vab/pyratemp.py|
)$
- repo: local
hooks:
- id: prettify
Expand Down
74 changes: 37 additions & 37 deletions tools/autotune_grid/xyz_to_vab/template_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Generate unrolled version of the xyz_to_vab routine
# for the most common la_max_local and lb_max_local combinations.
# For those combinations whose unrolled code would be larger but
# still some optimisation is needed, an additional template
# still some optimisation is needed, an additional template
# with less agressive loop unrolling can be specified
#
# Usage:
Expand All @@ -20,6 +20,9 @@


# Range of values to generate the routine variants
from __future__ import absolute_import
from __future__ import print_function

la_max_local_init = 0
la_max_local_end = 4
lb_max_local_init = 0
Expand All @@ -32,46 +35,43 @@
import sys

def load_template(template_filename):
""" Load the routine template string from a file and return the object """
# template_str = "\n".join([e.rstrip() for e in open(template_filename).readlines()])
return pyratemp.Template(filename = template_filename)
""" Load the routine template string from a file and return the object """
# template_str = "\n".join([e.rstrip() for e in open(template_filename).readlines()])
return pyratemp.Template(filename = template_filename)


def create_ordered_pairs():
""" Create an ordered list with the most common combinations to the
XYZ_TO_VAB routine at the beggining.
Most common values are:
(1, 0)--4275300
(1, 1)--4217600
(0, 0)--3878400
(0, 1)--3750300
"""
# Order the most common cases
l = [ (1,0) , (1,1), (0,0), (0,1) ]
# The rest are appended as is
for i in range(0,la_max_local_end+1):
for j in range(0,lb_max_local_end+1):
if not (i,j) in l:
l.append((i,j,))
return l
""" Create an ordered list with the most common combinations to the
XYZ_TO_VAB routine at the beggining.
Most common values are:
(1, 0)--4275300
(1, 1)--4217600
(0, 0)--3878400
(0, 1)--3750300
"""
# Order the most common cases
l = [ (1,0) , (1,1), (0,0), (0,1) ]
# The rest are appended as is
for i in range(0,la_max_local_end+1):
for j in range(0,lb_max_local_end+1):
if not (i,j) in l:
l.append((i,j,))
return l

if __name__ == "__main__":
if len(sys.argv) != 3:
print " Incorrect number of parameters "
print " Usage: " + str(sys.argv[0]) + " <template_file> " + " <destination_file>"
sys.exit(1)
if len(sys.argv) != 3:
print(" Incorrect number of parameters ")
print(" Usage: " + str(sys.argv[0]) + " <template_file> " + " <destination_file>")
sys.exit(1)

template_file_name = sys.argv[1]
output_file_name = sys.argv[2]
# Create a list of pairs ordered by probability
l = create_ordered_pairs()
# Initialize the templates
module_template = load_template(template_file_name)
source_str = module_template(cray_tracing = False,
la_max_local=la_max_local_end,
lb_max_local=lb_max_local_end,
pairs = l)
source_file = open(output_file_name,'w+')
print >>source_file, source_str
template_file_name = sys.argv[1]
output_file_name = sys.argv[2]
# Create a list of pairs ordered by probability
l = create_ordered_pairs()
# Initialize the templates
module_template = load_template(template_file_name)
source_str = module_template(cray_tracing = False, la_max_local=la_max_local_end, lb_max_local=lb_max_local_end, pairs = l)
source_file = open(output_file_name,'w+')
print(source_str, file=source_file)

source_file.close()
source_file.close()
6 changes: 4 additions & 2 deletions tools/benchmark_plots/plot_benchmark.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Make a plot of CP2K benchmark data.
"""
from __future__ import absolute_import
from __future__ import print_function
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker
Expand Down Expand Up @@ -33,8 +35,8 @@ def makePlot(benchmarkName, machineName, shift, showPlot):
+ benchmarkName \
+ '_besttimes.txt'

print 'Processing benchmark results for %s from file:' % machineName
print fileName
print('Processing benchmark results for %s from file:' % machineName)
print(fileName)

# Load data from file
data = np.loadtxt(fileName, dtype={'names': ('nodes', 'time', 'label'), \
Expand Down
6 changes: 4 additions & 2 deletions tools/benchmark_plots/plot_comparison.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Make a plot of CP2K benchmark data.
"""
from __future__ import absolute_import
from __future__ import print_function
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker
Expand Down Expand Up @@ -43,8 +45,8 @@ def makePlot(benchmarkName, machineNames, shifts, showPlot):
+ '/' \
+ benchmarkName \
+ '_besttimes.txt'
print 'Processing benchmark results from file:'
print fileName
print('Processing benchmark results from file:')
print(fileName)
data = np.loadtxt(fileName,
dtype={'names': ('nodes', 'time', 'label'), \
'formats': ('i4', 'f4', 'a5')})
Expand Down

0 comments on commit b8129c3

Please sign in to comment.