The thesis tested version (needs clean-up)

parent 722a03b9
......@@ -27,13 +27,13 @@ class CallSign:
if len(self.val) > len(other.val):
return False
# for i in range(0, len(self.val)):
i = len(self.val)
while i > 0:
i -= 1
i = 0
while i < len(self.val):
if self.val[i] < other.val[i]:
return True
if self.val[i] > other.val[i]:
return False
i += 1
return False
......
......@@ -89,9 +89,11 @@ class ByteArray:
def from_len(num_of_bytes):
# return bytearray(num_of_bytes)
# return bytearray(String.from_len(num_of_bytes))
# T = rffi.CArray(lltype.Char)
# ca = lltype.malloc(rffi.CCHARP.TO, num_of_bytes, flavor='raw')
ca = bytearray(b'\x00'*num_of_bytes)
return ca
@staticmethod
def from_str(some_str):
return bytearray(some_str)
......
......@@ -5,23 +5,23 @@ def _sort_aircraft_list(ac_list):
lln = len(ac_list)
# new_list = [ac for ac in ac_list]
new_list = []
i = lln
while i > 0:
i -= 1
i = 0
while i < lln:
new_list.append(ac_list[i])
i += 1
# for i in range(lln-1):
i = lln - 1
while i > 0:
i -= 1
i = 0
while i < lln - 1:
# for j in range(lln-1-i):
j = lln-1-i
while j > 0:
j -= 1
j = 0
while j < lln-1-i:
if new_list[j].call_sign.val_str > new_list[j+1].call_sign.val_str:
tmp = new_list[j]
new_list[j] = new_list[j+1]
new_list[j+1] = tmp
j += 1
i += 1
return new_list
......
......@@ -27,15 +27,15 @@ class TransientDetectorScopeEntry:
offset = 0
cur_frm = self.current_frame
# for i in range(0, cur_frm.plane_cnt):
i = cur_frm.plane_cnt
while i > 0:
i -= 1
i = 0
while i < cur_frm.plane_cnt:
cslen = cur_frm.lengths[i]
print_str(prefix + str(cur_frm.callsigns[offset:offset+cslen]) + ' ' +
str(cur_frm.positions[3*i]) + ' ' +
str(cur_frm.positions[3*i+1]) + ' ' +
str(cur_frm.positions[3*i+2]) + ' ')
offset += cslen
i += 1
def reduce_collision_set(self, it, motions):
from rpython.rlib.objectmodel import r_dict
......@@ -46,22 +46,22 @@ class TransientDetectorScopeEntry:
graph_colors = Vector2dSet()
# for motion in motions:
i = len(motions)
while i > 0:
i -= 1
i = 0
while i < len(motions):
motion = motions[i]
it.perform_voxel_hashing(motion, voxel_map, graph_colors)
i += 1
ret = []
# for key in voxel_map.keys():
keys = voxel_map.keys()
i = len(keys)
while i > 0:
i -= 1
i = 0
while i < len(keys):
key = keys[i]
cur_set = voxel_map[key]
if len(cur_set) > 1:
ret.append(cur_set)
i += 1
return ret
......@@ -71,19 +71,20 @@ class TransientDetectorScopeEntry:
ret = []
nom = len(motions)
# for i in range(0, nom-1):
i = nom-1
while i > 0:
i -= 1
i = 0
while i < nom - 1:
one = motions[i]
# for j in range(i+1, nom):
j = nom
while i > i+1:
i -= 1
j = i + 1
while j < nom:
two = motions[j]
vec = one.find_intersection(two)
if vec:
ret.append(
Collision([one.get_aircraft(), two.get_aircraft()], vec))
j += 1
i += 1
return ret
......@@ -110,11 +111,11 @@ class TransientDetectorScopeEntry:
i += 1
# for col in check:
i = len(check)
while i > 0:
i -= 1
i = 0
while i < suspected_size:
col = check[i]
c.add_collisions(self.determine_collisions(col))
i += 1
return c.get_collisions()
......@@ -128,10 +129,10 @@ class TransientDetectorScopeEntry:
length = len(self.cs.val)
b = ByteArray.from_len(length)
# for i in range(0, length):
i = length
while i > 0:
i -= 1
i = 0
while i < length:
b[i] = self.cs.val[i]
i += 1
self.c = CallSign(b)
def mk_callsign_in_persistent_scope(self, r, cs):
......@@ -155,9 +156,8 @@ class TransientDetectorScopeEntry:
pos = 0
# for i in range(0, self.current_frame.plane_cnt):
i = self.current_frame.plane_cnt
while i > 0:
i -= 1
i = 0
while i < self.current_frame.plane_cnt:
x = self.current_frame.positions[3*i]
y = self.current_frame.positions[3*i+1]
z = self.current_frame.positions[3*i+2]
......@@ -166,6 +166,7 @@ class TransientDetectorScopeEntry:
pos += cs_len
craft = AirCraft(cs)
new_pos = Vector3d(x, y, z)
i += 1
# persistent_callsign = self.mk_callsign_in_persistent_scope(r, craft.get_callsign())
old_pos = self.state.get(self.mk_callsign_in_persistent_scope(r, craft.get_callsign()))
......
......@@ -11,23 +11,25 @@ class Constants:
self.SIMULATOR_PRIORITY = 5
self.SIMULATOR_TIME_SCALE = 1
self.SIMULATOR_FPS = 50
# self.SIMULATOR_FPS = 2 # lcol
# self.SIMULATOR_FPS = 100
self.SIMULATOR_FPS = 250
self.DETECTOR_STARTUP_PRIORITY = 20
self.DETECTOR_PRIORITY = self.DETECTOR_STARTUP_PRIORITY + 1
self.PERSISTENT_DETECTOR_SCOPE_SIZE = 100 * 10 * 1024 * 1024
# self.DETECTOR_PERIOD = 500 # lcol
self.DETECTOR_PERIOD = 10 # col
# self.DETECTOR_PERIOD = 2 # noi
# self.DETECTOR_PERIOD = 10 # col
self.DETECTOR_PERIOD = 4 # noi
self.TRANSIENT_DETECTOR_SCOPE_SIZE = 50 * 10 * 1024*1024
# self.MAX_FRAMES = 200 # lcol
self.MAX_FRAMES = 10000 # col
# self.MAX_FRAMES = 25000 # noi
# self.MAX_FRAMES = 10000 # col
self.MAX_FRAMES = 20000 # noi
# self.BUFFER_FRAMES = 200 # lcol
self.BUFFER_FRAMES = 10000 # col
# self.BUFFER_FRAMES = 25000 # noi
# self.BUFFER_FRAMES = 10000 # col
self.BUFFER_FRAMES = 20000 # noi
self.PRESIMULATE = True
self.SIMULATE_ONLY = True
......@@ -36,8 +38,8 @@ class Constants:
self.DETECTOR_RELEASE_STATS = "release.rin"
# self.BIN_DIR = '/tests/test_jit/mu-client-pypy/rpython/dev/dev_CD/input/lcol.bin'
self.BIN_DIR = '/tests/test_jit/mu-client-pypy/rpython/dev/dev_CD/input/col.bin'
# self.BIN_DIR = '/tests/test_jit/mu-client-pypy/rpython/dev/dev_CD/input/noi.bin'
# self.BIN_DIR = '/tests/test_jit/mu-client-pypy/rpython/dev/dev_CD/input/col.bin'
self.BIN_DIR = '/tests/test_jit/mu-client-pypy/rpython/dev/dev_CD/input/noi.bin'
# run a SPEC jvm98 benchmark to generate some noise
self.SPEC_NOISE_ARGS = "-a -b -g -s100 -m10 -M10 -t _213_javac"
......
......@@ -19,20 +19,20 @@ class RawFrame:
pos4 = 0
# for i in range(0, len(lengths_)):
i = len(lengths_)
while i > 0:
i -= 1
i = 0
while i < len(lengths_):
self.lengths.append(lengths_[i])
self.positions.append(positions_[3 * i])
self.positions.append(positions_[3 * i + 1])
self.positions.append(positions_[3 * i + 2])
# for j in range(0, lengths_[i]):
j = lengths_[i]
while j > 0:
j -= 1
j = 0
while j < lengths_[i]:
self.callsigns[pos3] = signs_[pos4 + j]
pos3 += 1
j += 1
pos4 += lengths_[i]
i += 1
self.plane_cnt = len(lengths_)
def to_string(self):
......
......@@ -110,9 +110,8 @@ class Main:
raise err
# for i in range(0, immortal_entry.recorded_runs):
i = immortal_entry.recorded_runs
while i > 0:
i -= 1
i = 0
while i < immortal_entry.recorded_runs:
line = ('%s %s %s %s %s' % (
NanoClock.as_string(immortal_entry.times_before[i]), NanoClock.as_string(immortal_entry.times_after[i]),
NanoClock.as_string(immortal_entry.times_after[i] - immortal_entry.times_before[i]),
......@@ -122,6 +121,7 @@ class Main:
if CONSTANTS.MAIN_PRINT_RESULTS:
print_str(line)
i += 1
if out is not None:
out.close()
......@@ -153,15 +153,15 @@ class Main:
raise err
# for i in range(0, immortal_entry.recorded_detector_release_times):
i = immortal_entry.recorded_detector_release_times
while i > 0:
i -= 1
i = 0
while i < immortal_entry.recorded_detector_release_times:
line = ('%s %s %s\n' % (
NanoClock.as_string(immortal_entry.detector_release_times[i]),
NanoClock.as_string(i * CONSTANTS.DETECTOR_PERIOD * 1000000L),
('1' if immortal_entry.detector_reported_miss[i] else '0')
))
out.write(line)
i += 1
if out is not None:
out.close()
......@@ -174,7 +174,7 @@ class Main:
from rpython.rlib.rrtmu.ll_mem import enter_emm
rtzebu.init_rt_rpython()
enter_emm()
# enter_emm()
NanoClock.init()
......
from rpython.rlib.rrtmu.ll_mem import new_scope, enter_scope, exit_area, delete_region
from rpython.rlib.rrtmu.ll_mem import new_scope, enter_scope, exit_area, delete_region, collect_region
class ScopedMemory:
......@@ -17,8 +17,10 @@ class ScopedMemory:
def reset(self):
scp = self.scope
self.scope = new_scope(self.size)
delete_region(scp)
collect_region(scp)
# scp = self.scope
# self.scope = new_scope(self.size)
# delete_region(scp)
def is_real(self):
return True
......
......@@ -99,29 +99,34 @@ def generate():
raise RuntimeError('Not enough frames in binary dump.')
# for frame_index in range(0, CONSTANTS.MAX_FRAMES):
frame_index = CONSTANTS.MAX_FRAMES
while frame_index > 0:
frame_index -= 1
frame_index = 0
while frame_index < CONSTANTS.MAX_FRAMES:
nplanes = bin_dump.read_int()
# print_str('nplanes: %s\n' % nplanes)
positions = []
# for i in range(0, nplanes):
i = nplanes
while i > 0:
i -= 1
i = 0
while i < nplanes:
positions.append(bin_dump.read_float())
positions.append(bin_dump.read_float())
positions.append(bin_dump.read_float())
i += 1
lengths = []
# for i in range(0, nplanes):
i = nplanes
while i > 0:
i -= 1
i = 0
while i < nplanes:
lengths.append(bin_dump.read_int())
i += 1
callsigns_length = bin_dump.read_int()
callsigns = bin_dump.read(callsigns_length)
immortal_entry.framebuffer.put_frame(positions, lengths, callsigns)
# print_str('positions: %s\n' % positions)
# print_str('lengths: %s\n' % lengths)
# print_str('callsigns: %s\n' % callsigns)
frame_index += 1
bin_dump.close()
except Exception as err:
......
from cd_helpers import ByteArray
class CallSign:
def __init__(self, v):
self.val = v
self.val_str = v.as_string()
def hash_code(self):
return ByteArray.hash(self.val)
def __eq__(self, other):
ByteArray.eq(self.val, other.val)
def __ne__(self, other):
return not self.__eq__(other)
def to_string(self):
from cd_helpers import String
return self.val_str
def __str__(self):
return self.to_string()
class AirCraft:
from rpython.dev.dev_CD_charp.cd_helpers import ByteArray
def __init__(self, call_sign=ByteArray.from_str('none')):
self.call_sign = CallSign(call_sign)
def get_callsign(self):
return self.call_sign
def hash_code(self):
return self.call_sign.hash_code()
def equals(self, other):
if other == self:
return True
else:
try:
return self.call_sign == other.callsign
except Exception as err:
return False
def compare_to(self, other):
if len(self.call_sign) > len(other.callsign):
return 1
if len(self.call_sign) < len(other.callsign):
return -1
if self.call_sign > other.callsign:
return 1
elif self.call_sign < other.callsign:
return -1
return 0
def __str__(self):
return self.call_sign.__str__()
def __eq__(self, other):
return self.call_sign.__eq__(other.call_sign)
def __ne__(self, other):
return not self.__eq__(other)
def to_string(self):
return self.__str__()
import rpython.dev.dev_CD_charp.immortal.constants as c
CONSTANTS = c.Constants()
# MU_ZEBU = '/home/javad/myFiles/Src/mu-impl-fast'
MU_ZEBU = '/home/javad/src/mu-impl-fast'
from rpython.rtyper.lltypesystem import lltype, rffi
class BinDumpFile:
def __init__(self, fpath=''):
if fpath != '':
self.f = open(fpath, 'wb+')
def write_int(self, i):
ba = ByteArray.from_len(4)
ba[3] = i % 256
ba[2] = (i/256) % 256
ba[1] = (i/(256*256)) % 256
ba[0] = (i/(256*256*256)) % 256
self.f.write(ba)
def write_float(self, f):
from rpython.dev.dev_CD_charp.detector.math_helpers import Float
i = Float.float_to_int_bits(f)
self.write_int(i)
def write(self, byte_array):
self.f.write(byte_array)
def close(self):
self.f.close()
class StaticInt:
def __init__(self, some_int=-1):
self.val = some_int
class StaticFloat:
def __init__(self, some_float=-1.0):
self.val = some_float
class StaticLong:
def __init__(self, some_long=-1L):
self.val = some_long
class StaticBool:
def __init__(self, some_bool=False):
self.val = some_bool
class String:
@staticmethod
def from_len(num_of_chars):
from rpython.dev.dev_CD_charp.detector.math_helpers import ilog2
if num_of_chars <= 0:
return ''
ba = ByteArray.from_len(num_of_chars)
res = ba.as_string()
return res
@staticmethod
def from_bytearray(ba):
return ba.as_string()
@staticmethod
def hash(some_str):
h = 0
i = len(some_str)
while i > 0:
i -= 1
h += ord(some_str[i])
return h
@staticmethod
def eq(str1, str2):
return str1 == str2
class ByteArray:
def __init__(self, charr, size):
self.charr = charr
self.size = size
def as_string(self):
return rffi.charpsize2str(self.charr, self.size)
def clone(self):
sz = self.size
chp = self.charr
new_ba = ByteArray.from_len(sz)
rffi.c_memcpy(rffi.cast(rffi.VOIDP, new_ba.charr), rffi.cast(rffi.VOIDP, chp), rffi.cast(rffi.SSIZE_T, sz))
return new_ba
def slice(self, i, j):
sz = j - i
new_ba = ByteArray.from_len(sz)
k = sz
while k > 0:
k -= 1
new_ba.charr[k] = self.charr[i + k]
return new_ba
@staticmethod
def from_len(size):
ca = lltype.malloc(rffi.CCHARP.TO, size, flavor='gc')
return ByteArray(ca, size)
@staticmethod
def from_str(some_str):
return rffi.str2charp(some_str)
@staticmethod
def clone_of(ba):
return ba.clone()
@staticmethod
def hash(some_bytearray):
h = 0
# for i in range(0, len(some_bytearray)):
i = some_bytearray.size
while i > 0:
i -= 1
h += ord(some_bytearray.charr[i])
return h
@staticmethod
def eq(barr1, barr2):
l1 = barr1.size
if l1 != barr2.size:
return False
else:
# for i in range(l1):
i = l1
while i > 0:
i -= 1
if barr1.charr[i] != barr2.charr[i]:
return False
return True
def cstr_to_rpy_strings(charp):
from rpython.rtyper.lltypesystem import rffi
counter = 0
res = ''
if charp != rffi.NULL:
while charp[counter] != rffi.NULL:
res += str(charp[counter])
res += str('\n')
return res.split(' ')
class Vector2dSet:
def __init__(self):
from detector.vector import Vector2d
self.set = [Vector2d()]
self.set.pop()
def contains(self, v2d):
from rpython.rlib.rrtmu.rtzebu import print_str
from detector.vector import Vector2d
# for v in self.set:
i = len(self.set)
while i > 0:
i -= 1
v = self.set[i]
if Vector2d.equals(v, v2d) is True:
return True
return False
def add(self, new_v2d):
self.set.append(new_v2d)
def clear(self):
from detector.vector import Vector2d
if len(self.set) == 0:
return
else:
self.set = [Vector2d()]
self.set.pop()
def size(self):
return len(self.set)
from rpython.dev.dev_CD_charp.immortal.immortal_entry import ImmortalEntry
from rpython.dev.dev_CD_charp.simulator.simulator import Simulator
from rpython.dev.dev_CD_charp.detector.persistent_detector_scope_entry import PersistentDetectorScopeEntry
from rpython.dev.dev_CD_charp.immortal.frame_synchronizer import FrameSynchronizer
class staticIE:
def __init__(self):
self.elem = []
def setobj(self, ieo):
self.elem.append(ieo)
def getobj(self):
return self.elem[0]
IMMORTAL_ENTRY = staticIE()
class staticPDSE:
def __init__(self):
self.elem = []
def setobj(self, ieo):
self.elem.append(ieo)
def getobj(self):
return self.elem[0]
PDSE = staticPDSE()
class staticSim:
def __init__(self):
self.elem = []
def setobj(self, ieo):
self.elem.append(ieo)
def getobj(self):
return self.elem[0]
SIMULATOR = staticSim()
class staticFS:
def __init__(self):
self.elem = []
def setobj(self, ieo):
self.elem.append(ieo)
def getobj(self):