Skip to content

Commit

Permalink
Removed legacy imports and six and changed shebang python3
Browse files Browse the repository at this point in the history
  • Loading branch information
cod3monk committed Dec 6, 2017
1 parent 29c6e88 commit f773da1
Show file tree
Hide file tree
Showing 29 changed files with 76 additions and 272 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: python
python:
- '2.7'
- '3.4'
- '3.5'
- '3.6'
Expand Down
8 changes: 1 addition & 7 deletions kerncraft/cacheprediction.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""Cache prediction interface classes are gathered in this module."""

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import absolute_import
from __future__ import division

from itertools import chain

import sympy
Expand Down
11 changes: 2 additions & 9 deletions kerncraft/cachetile.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
#!/usr/bin/env python

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import absolute_import
from __future__ import division

#!/usr/bin/env python3
import argparse
import sys

import sympy
import six
from ruamel import yaml

from . import models
Expand Down Expand Up @@ -55,7 +48,7 @@ def run(parser, args):
machine = MachineModel(args.machine.name)

# process kernel description
description = six.text_type(args.description_file.read())
description = str(args.description_file.read())
kernel = KernelDescription(yaml.load(description))

# Add constants from define arguments
Expand Down
11 changes: 1 addition & 10 deletions kerncraft/iaca.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""Helper functions to instumentalize assembly code for and analyze with IACA."""
from __future__ import print_function
from __future__ import absolute_import

# Version check
import sys
if sys.version_info[0] == 2 and sys.version_info < (2, 7) or \
sys.version_info[0] == 3 and sys.version_info < (3, 4):
print("Must use python 2.7 or 3.4 and greater.", file=sys.stderr)
sys.exit(1)

import re
import subprocess
import os
from copy import copy

from distutils.spawn import find_executable
from six.moves import input

from kerncraft import iaca_get

Expand Down
6 changes: 1 addition & 5 deletions kerncraft/iaca_get.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function
from __future__ import absolute_import

#!/usr/bin/env python3
import os
import sys
import stat
Expand All @@ -11,7 +8,6 @@
import tempfile
import shutil
import platform
import errno

import requests

Expand Down
2 changes: 1 addition & 1 deletion kerncraft/intervals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""A simple interval implementation."""


Expand Down
51 changes: 20 additions & 31 deletions kerncraft/kerncraft.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""Comand line interface of Kerncraft."""
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import absolute_import
from __future__ import division

# Version check
import sys
if sys.version_info[0] == 2 and sys.version_info < (2, 7) or \
sys.version_info[0] == 3 and sys.version_info < (3, 4):
print("Must use python 2.7 or 3.4 and greater.", file=sys.stderr)
sys.exit(1)
import argparse
import os.path
import pickle
Expand All @@ -20,8 +11,6 @@
import itertools

from .pycparser import clean_code
import six
from six.moves import range
from ruamel import yaml

from . import models
Expand All @@ -34,7 +23,7 @@ def space(start, stop, num, endpoint=True, log=False, base=10):
"""
Return list of evenly spaced integers over an interval.
Numbers can either be evenlty distributed in a linear space (if *log* is False) or in a log
Numbers can either be evenly distributed in a linear space (if *log* is False) or in a log
space (if *log* is True). If *log* is True, base is used to define the log space basis.
If *endpoint* is True, *stop* will be the last retruned value, as long as *num* >= 2.
Expand All @@ -48,16 +37,16 @@ def space(start, stop, num, endpoint=True, log=False, base=10):
stop = math.log(stop, base)

if endpoint:
steplength = float((stop-start))/float(num-1)
step_length = float((stop - start)) / float(num - 1)
else:
steplength = float((stop-start))/float(num)
step_length = float((stop - start)) / float(num)

i = 0
while i < num:
if log:
yield int(round(base**(start + i*steplength)))
yield int(round(base ** (start + i * step_length)))
else:
yield int(round(start + i*steplength))
yield int(round(start + i * step_length))
i += 1


Expand All @@ -73,11 +62,11 @@ class AppendStringRange(argparse.Action):
"""
Argparse Action to append integer range from string.
A range discription must have the following format: start[-stop[:num[log[base]]]]
A range description must have the following format: start[-stop[:num[log[base]]]]
if stop is given, a list of integers is compiled
if num is given, an evently spaced lsit of intergers from start to stop is compiled
if num is given, an evenly spaced list of integers from start to stop is compiled
if log is given, the integers are evenly spaced on a log space
if base is given, the integers are evently spaced on that base (default: 10)
if base is given, the integers are evenly spaced on that base (default: 10)
"""

def __call__(self, parser, namespace, values, option_string=None):
Expand All @@ -94,7 +83,7 @@ def __call__(self, parser, namespace, values, option_string=None):
if gd['stop'] is None:
values[1] = [int(gd['start'])]
elif gd['num'] is None:
values[1] = list(range(int(gd['start']), int(gd['stop'])+1))
values[1] = list(range(int(gd['start']), int(gd['stop']) + 1))
else:
log = gd['log'] is not None
base = int(gd['base']) if gd['base'] is not None else 10
Expand All @@ -116,7 +105,7 @@ def create_parser():
"""Return argparse parser."""
parser = argparse.ArgumentParser(
description='Analytical performance modelling and benchmarking toolkit.',
epilog='For help, examples, documenataion and bug reports go to:\nhttps://github.com'
epilog='For help, examples, documentation and bug reports go to:\nhttps://github.com'
'/RRZE-HPC/kerncraft\nLicense: AGPLv3')
parser.add_argument('--version', action='version', version='%(prog)s {}'.format(__version__))
parser.add_argument('--machine', '-m', type=argparse.FileType('r'), required=True,
Expand Down Expand Up @@ -163,7 +152,7 @@ def create_parser():
'description file (-std=c99 is always added).')

for m in models.__all__:
ag = parser.add_argument_group('arguments for '+m+' model', getattr(models, m).name)
ag = parser.add_argument_group('arguments for ' + m + ' model', getattr(models, m).name)
getattr(models, m).configure_arggroup(ag)

return parser
Expand Down Expand Up @@ -196,11 +185,11 @@ def run(parser, args, output_file=sys.stdout):

# process kernel
if not args.kernel_description:
code = six.text_type(args.code_file.read())
code = str(args.code_file.read())
code = clean_code(code)
kernel = KernelCode(code, filename=args.code_file.name, machine=machine)
else:
description = six.text_type(args.code_file.read())
description = str(args.code_file.read())
kernel = KernelDescription(yaml.load(description, Loader=yaml.Loader), machine=machine)
# if no defines were given, guess suitable defines in-mem
# TODO support in-cache
Expand Down Expand Up @@ -241,11 +230,11 @@ def run(parser, args, output_file=sys.stdout):

for model_name in set(args.pmodel):
# print header
print('{:=^80}'.format(' kerncraft '), file=output_file)
print('{:<40}{:>40}'.format(args.code_file.name, '-m '+args.machine.name),
print('{:^80}'.format(' kerncraft '), file=output_file)
print('{:<40}{:>40}'.format(args.code_file.name, '-m ' + args.machine.name),
file=output_file)
print(' '.join(['-D {} {}'.format(k, v) for k, v in define]), file=output_file)
print('{:-^80}'.format(' '+model_name+' '), file=output_file)
print('{:-^80}'.format(' ' + model_name + ' '), file=output_file)

if args.verbose > 1:
if not args.kernel_description:
Expand Down Expand Up @@ -274,10 +263,10 @@ def run(parser, args, output_file=sys.stdout):

# Save storage to file (if requested)
if args.store:
tempname = args.store.name + '.tmp'
with open(tempname, 'wb+') as f:
temp_name = args.store.name + '.tmp'
with open(temp_name, 'wb+') as f:
pickle.dump(result_storage, f)
shutil.move(tempname, args.store.name)
shutil.move(temp_name, args.store.name)


def main():
Expand Down
20 changes: 5 additions & 15 deletions kerncraft/kernel.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""Representation of computational kernel for performance model analysis and helper functions."""

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import absolute_import
from __future__ import division

from copy import deepcopy
import operator
import tempfile
Expand All @@ -19,16 +13,12 @@
import string
from itertools import chain
from collections import defaultdict
from itertools import zip_longest, lru_cache

import sympy
from sympy.utilities.lambdify import implemented_function
from sympy.parsing.sympy_parser import parse_expr
import numpy
from six.moves import filter
from six.moves import map
from six.moves import zip_longest
import six
from pylru import lrudecorator

from .pycparser import CParser, c_ast, plyparser
from .pycparser.c_generator import CGenerator
Expand Down Expand Up @@ -186,7 +176,7 @@ def set_constant(self, name, value):
:param name: may be a str or a sympy.Symbol
:param value: must be an int
"""
assert isinstance(name, six.string_types) or isinstance(name, sympy.Symbol), \
assert isinstance(name, str) or isinstance(name, sympy.Symbol), \
"constant name needs to be of type str, unicode or a sympy.Symbol"
assert type(value) is int, "constant value needs to be of type int"
if isinstance(name, sympy.Symbol):
Expand Down Expand Up @@ -214,7 +204,7 @@ def clear_state(self):
self.constants = {}
self.subs_consts.clear() # clear LRU cache of function

@lrudecorator(40)
@lru_cache(40)
def subs_consts(self, expr):
"""Substitute constants in expression unless it is already a number."""
if isinstance(expr, numbers.Number):
Expand Down Expand Up @@ -711,7 +701,7 @@ def _get_basename(cls, aref):
"""
if isinstance(aref.name, c_ast.ArrayRef):
return cls._get_basename(aref.name)
elif isinstance(aref.name, six.string_types):
elif isinstance(aref.name, str):
return aref.name
else:
return aref.name.name
Expand Down
14 changes: 1 addition & 13 deletions kerncraft/likwid_bench_auto.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function
from __future__ import absolute_import
from __future__ import unicode_literals
from __future__ import division

# Version check
#!/usr/bin/env python3
import sys
if sys.version_info[0] == 2 and sys.version_info < (2, 6) or \
sys.version_info[0] == 3 and sys.version_info < (3, 4):
print("Must use python 2.6 or 3.4 and greater.", file=sys.stderr)
sys.exit(1)

import subprocess
import re
from copy import copy
Expand All @@ -19,7 +8,6 @@
from ruamel import yaml

from .prefixedunit import PrefixedUnit
from six.moves import range


def get_match_or_break(regex, haystack, flags=re.MULTILINE):
Expand Down
6 changes: 1 addition & 5 deletions kerncraft/machinemodel.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""Machine model and helper functions."""

from __future__ import absolute_import
from __future__ import division

from distutils.spawn import find_executable
import re
import sys
Expand Down
20 changes: 4 additions & 16 deletions kerncraft/models/benchmark.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/usr/bin/env python3
"""Benchmark model and helper functions."""
from __future__ import print_function
from __future__ import division
from __future__ import unicode_literals
from __future__ import absolute_import

import subprocess
from functools import reduce
import operator
Expand All @@ -12,16 +8,8 @@
import re
from collections import defaultdict
import string
try:
# Python 3
from itertools import zip_longest
except ImportError:
from itertools import izip_longest as zip_longest
from pprint import pprint

import six
import sympy

from kerncraft.prefixedunit import PrefixedUnit


Expand Down Expand Up @@ -276,7 +264,7 @@ def analyze(self):
element_size = self.kernel.datatypes_size[self.kernel.datatype]

# Build arguments to pass to command:
args = [bench] + [six.text_type(s) for s in list(self.kernel.constants.values())]
args = [bench] + [str(s) for s in list(self.kernel.constants.values())]

# Determine base runtime with 100 iterations
runtime = 0.0
Expand All @@ -289,7 +277,7 @@ def analyze(self):
else:
repetitions *= 10

mem_results = self.perfctr(args+[six.text_type(repetitions)], group="MEM")
mem_results = self.perfctr(args+[str(repetitions)], group="MEM")
runtime = mem_results['Runtime (RDTSC) [s]']
time_per_repetition = runtime/float(repetitions)
raw_results = [mem_results]
Expand All @@ -315,7 +303,7 @@ def analyze(self):
measured_ctrs = {}
for run in minimal_runs:
ctrs = ','.join([eventstr(e) for e in run])
r = self.perfctr(args+[six.text_type(repetitions)], group=ctrs)
r = self.perfctr(args+[str(repetitions)], group=ctrs)
raw_results.append(r)
measured_ctrs.update(r)
# Match measured counters to symbols
Expand Down
Loading

0 comments on commit f773da1

Please sign in to comment.