...
 
This diff is collapsed.
......@@ -119,12 +119,14 @@ class Bookkeeper(object):
try:
self.annotator.translator.graphs.pop(self.annotator.LAST_GRAPH)
except Exception as er:
logger.info('graph already deleted: %s' % er.message)
pass
# logger.info('graph already deleted: %s' % er.message)
try:
self.annotator.annotated.remove(self.annotator.LAST_BLOCK)
except Exception as er:
logger.info('block already deleted? %s' % er.message)
pass
# logger.info('block already deleted? %s' % er.message)
# else:
# raise exp
......@@ -534,9 +536,9 @@ class Bookkeeper(object):
results = []
for desc in pbc.descriptions:
results.append(desc.pycall(whence, args, s_previous_result, op))
logger.info('pbc_call.results = %s' % results)
# logger.info('pbc_call.results = %s' % results)
s_result = unionof(*results)
logger.info('pbc_call.s_result = %s' % s_result)
# logger.info('pbc_call.s_result = %s' % s_result)
return s_result
def emulate_pbc_call(self, unique_key, pbc, args_s, replace=[], callback=None):
......
......@@ -222,6 +222,8 @@ class FunctionDesc(Desc):
self._cache = {} # convenience for the specializer
def buildgraph(self, alt_name=None, builder=None):
from rpython.rlib.rrtmu.rtzebu import tune_type_name
translator = self.bookkeeper.annotator.translator
logger.info("buildgraph for %s" % self.name)
# assert self.name != 'll_arraycopy'
......@@ -231,6 +233,8 @@ class FunctionDesc(Desc):
graph = translator.buildflowgraph(self.pyobj)
if alt_name:
graph.name = alt_name
graph.name = tune_type_name(graph.name)
return graph
def getgraphs(self):
......@@ -321,19 +325,19 @@ class FunctionDesc(Desc):
def pycall(self, whence, args, s_previous_result, op=None):
# assert self.name != 'll_math_isfinite'
logger.info('pycall( \n%s, \n%s,\n %s,\n %s,\n %s)' % (self, whence, args, s_previous_result, op))
# logger.info('pycall( \n%s, \n%s,\n %s,\n %s,\n %s)' % (self, whence, args, s_previous_result, op))
inputcells = self.parse_arguments(args)
logger.info('pycall.inputcells = %s' % inputcells)
# logger.info('pycall.inputcells = %s' % inputcells)
result = self.specialize(inputcells, op)
logger.info('pycall.result = \n%s \n%s\n' % (result, type(result)))
# logger.info('pycall.result = \n%s \n%s\n' % (result, type(result)))
if isinstance(result, FunctionGraph):
graph = result # common case
logger.info('graph.func.func_code: \n %s' % graph.func.func_code)
# logger.info('graph.func.func_code: \n %s' % graph.func.func_code)
# # RTMU
# self.create_rtmu_copies(graph)
......@@ -343,11 +347,11 @@ class FunctionDesc(Desc):
# the arguments.
# recreate the args object because inputcells may have been changed
new_args = args.unmatch_signature(self.signature, inputcells)
logger.info('pycall.new_args: %s' % new_args)
# logger.info('pycall.new_args: %s' % new_args)
inputcells = self.parse_arguments(new_args, graph)
logger.info('pycall.inputcells: %s' % inputcells)
# logger.info('pycall.inputcells: %s' % inputcells)
result = annotator.recursivecall(graph, whence, inputcells)
logger.info('pycall.result.rec: %s' % result)
# logger.info('pycall.result.rec: %s' % result)
signature = getattr(self.pyobj, '_signature_', None)
# logger.info('pycall.sig: %s' % signature)
if signature:
......@@ -356,13 +360,13 @@ class FunctionDesc(Desc):
annotator.addpendingblock(
graph, graph.returnblock, [sigresult])
result = sigresult
logger.info('pycall.result.final = %s' % result)
# logger.info('pycall.result.final = %s' % result)
# Some specializations may break the invariant of returning
# annotations that are always more general than the previous time.
# We restore it here:
from rpython.annotator.model import unionof
result = unionof(result, s_previous_result)
logger.info('pycall.result.unionof: %s' % result)
# logger.info('pycall.result.unionof: %s' % result)
return result
def get_graph(self, args, op):
......
......@@ -13,7 +13,7 @@ from rpython.tool.ansi_print import AnsiLogger
logger = AnsiLogger('ann.specialize')
def flatten_star_args(funcdesc, args_s):
logger.info('flatten_star_args( \n%s, \n%s' % (funcdesc, args_s))
# logger.info('flatten_star_args( \n%s, \n%s' % (funcdesc, args_s))
argnames, vararg, kwarg = funcdesc.signature
assert not kwarg, "functions with ** arguments are not supported"
if vararg:
......@@ -54,11 +54,11 @@ def flatten_star_args(funcdesc, args_s):
return graph
key = ('star', nb_extra_args)
logger.info('flatten_star_args.returning:\n%s,\n%s, \n%s' % (flattened_s, key, builder))
# logger.info('flatten_star_args.returning:\n%s,\n%s, \n%s' % (flattened_s, key, builder))
return flattened_s, key, builder
else:
logger.info('flatten_star_args.2ndreturn: %s' % args_s)
# logger.info('flatten_star_args.2ndreturn: %s' % args_s)
return args_s, None, None
def default_specialize(funcdesc, args_s):
......
......@@ -56,7 +56,7 @@ translation_optiondescription = OptionDescription(
("translation.backendopt.remove_asserts", True),
("translation.backendopt.really_remove_asserts", True),
("translation.backendopt.inline", False),
("translation.backendopt.mallocs", False)]
("translation.backendopt.mallocs", True)]
},
cmdline="-b --backend"),
......@@ -70,7 +70,7 @@ translation_optiondescription = OptionDescription(
ChoiceOption("gc", "Garbage Collection Strategy",
["boehm", "ref", "semispace", "statistics",
"generation", "hybrid", "minimark",'incminimark', "none", "mu"],
"ref", requires={
default="generation", requires={ # RTMU rpyc
"ref": [("translation.rweakref", False), # XXX
("translation.gctransformer", "ref")],
"none": [("translation.rweakref", False), # XXX
......@@ -88,7 +88,7 @@ translation_optiondescription = OptionDescription(
cmdline="--gc"),
ChoiceOption("gctransformer", "GC transformer that is used - internal",
["boehm", "ref", "framework", "none"],
default="ref", cmdline=None,
default="framework", cmdline=None, # RTMU rpyc
requires={
"boehm": [("translation.gcrootfinder", "n/a"),
("translation.gcremovetypeptr", False)],
......@@ -257,11 +257,11 @@ translation_optiondescription = OptionDescription(
BoolOption("remove_asserts",
"Remove operations that look like 'raise AssertionError', "
"which lets the C optimizer remove the asserts",
default=False),
default=True),
BoolOption("really_remove_asserts",
"Really remove operations that look like 'raise AssertionError', "
"without relying on the C compiler",
default=False),
default=True),
BoolOption("stack_optimization",
"Tranform graphs in SSI form into graphs tailored for "
......@@ -270,7 +270,7 @@ translation_optiondescription = OptionDescription(
BoolOption("storesink", "Perform store sinking", default=True),
BoolOption("replace_we_are_jitted",
"Replace we_are_jitted() calls by False",
default=False, cmdline=None),
default=True, cmdline=None), # RTMU
BoolOption("none",
"Do not run any backend optimizations",
requires=[('translation.backendopt.inline', False),
......@@ -435,4 +435,3 @@ def get_translation_config():
""" Return the translation config when translating. When running
un-translated returns None """
return _GLOBAL_TRANSLATIONCONFIG
class CallSign:
def __init__(self, v):
self.val = v
self.val_str = str(v)
def hash_code(self):
h = 0
# for i in range(0, len(self.val)):
i = len(self.val)
while i > 0:
i -= 1
h += self.val[i]
return h
def __eq__(self, other):
try:
return self.val_str == other.val_str
except Exception:
return False
def __ne__(self, other):
return not self.__eq__(other)
def __lt__(self, other):
if len(self.val) < len(other.val):
return True
if len(self.val) > len(other.val):
return False
# for i in range(0, len(self.val)):
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
def __gt__(self, other):
return not (self.__eq__(other) or self.__lt__(other))\
def to_string(self):
from cd_helpers import String
# return str(self.val)
return self.val_str
def __str__(self):
return self.to_string()
class AirCraft:
from rpython.dev.dev_CD.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):
h = 0
# for i in range(0, len(self.call_sign.val)):
i = len(self.call_sign.val)
while i > 0:
i -= 1
h += self.call_sign.val[i]
return h
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.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.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.detector.math_helpers import ilog2
if num_of_chars <= 0:
return ''
res = '0'*num_of_chars
return res
@staticmethod
def from_bytearray(ba):
res = ''
# for i in range(len(ba)):
i = len(ba)
while i > 0:
i -= 1
res += chr(ba[i])
return res
@staticmethod
def hash(some_str):
h = 0
# ba = bytearray(some_str)
# for i in range(0, len(some_str)):
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:
@staticmethod
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)
@staticmethod
def clone_of(ba):
return bytearray(String.from_bytearray(ba))
# @staticmethod
# def deepcopy(ba):
# size = len(ba)
# T = lltype.GcArray(lltype.Char)
# raw = lltype.malloc(T, size)
# i = size
# while i > 0:
# i -= 1
#
@staticmethod
def hash(some_bytearray):
h = 0
# for i in range(0, len(some_bytearray)):
i = len(some_bytearray)
while i > 0:
i -= 1
h += some_bytearray[i]
return h
@staticmethod
def eq(barr1, barr2):
l1 = len(barr1)
if l1 != len(barr2):
return False
else:
# for i in range(l1):
i = l1
while i > 0:
i -= 1
if barr1[i] != barr2[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.immortal.immortal_entry import ImmortalEntry
from rpython.dev.dev_CD.simulator.simulator import Simulator
from rpython.dev.dev_CD.detector.persistent_detector_scope_entry import PersistentDetectorScopeEntry
from rpython.dev.dev_CD.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):
return self.elem[0]
FRAME_SYNCHRONIZER = staticFS()
# from rpython.dev.dev_CD.radar_frame import *
import math
def calc_distance_3d(ac1, ac2):
dx = ac2.x - ac1.x
dy = ac2.y - ac1.y
dz = ac2.z - ac1.z
return math.sqrt((dx*dx)+(dy*dy)+(dz*dz))
def check_rdr_frame(rf):
ap1 = rf[0]
ap2 = rf[1]
res = calc_distance_3d(ap1, ap2)
return res
from rpython.dev.dev_CD.aircraft import AirCraft
def _sort_aircraft_list(ac_list):
lln = len(ac_list)
# new_list = [ac for ac in ac_list]
new_list = []
i = 0
while i < lln:
new_list.append(ac_list[i])
i += 1
# for i in range(lln-1):
i = 0
while i < lln - 1:
# for j in range(lln-1-i):
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
class Collision:
def __init__(self, ac_list, loc):
self.aircrafts = _sort_aircraft_list(ac_list)
self.location = loc
def hash_code(self):
ret = 0
# for ac in self.aircrafts:
i = len(self.aircrafts)
while i > 0:
i -= 1
ret += ac.hash_code()
return ret
def equals(self, other):
if other == self:
return True
acs1 = self.aircrafts
try:
acs2 = other.aircrafts
except Exception:
return False
if len(acs1) != len(acs2):
return False
# for ac1, ac2 in zip(acs1, acs2):
# if ac1.__ne__(ac2):
# return False
i = len(acs1)
while i > 0:
i -= 1
if acs1[i].__ne__(acs2[i]):
return False
return True
def to_string(self):
buf = 'Collision between '
first = True
# for ac in self.aircrafts:
i = len(self.aircrafts)
while i > 0:
i -= 1
ac = self.aircrafts[i]
if first:
first = False
else:
buf += ', '
buf += ac.to_string()
buf += ' at '
buf += self.location.to_string()
return buf
def __str__(self):
self.to_string()
def get_aircraft_involved(self):
return self.aircrafts
def get_location(self):
return self.location
def collection_eq(col_one, col_two):
if col_one == col_two:
return True
acs1 = col_one.aircrafts
try:
acs2 = col_two.aircrafts
except Exception:
return False
if len(acs1) != len(acs2):
return False
# for i in range(len(acs2)):
i = len(acs2)
while i > 0:
i -= 1
# ac1 = acs1[i]
# ac2 = acs2[i]
if acs1[i].__ne__(acs2[i]):
return False
return True
def collection_hash(col):
ret = 0
# for ac in col.aircrafts:
i = len(col.aircrafts)
while i > 0:
i -= 1
ac = col.aircrafts[i]
ret += ac.hash_code()
return ret
from rpython.rlib.objectmodel import r_dict
from rpython.dev.dev_CD.detector.collision import Collision, collection_eq, collection_hash
from rpython.dev.dev_CD.detector.vector import Vector3d
class CollisionSet:
def __init__(self):
self.colls = r_dict(collection_eq, collection_hash)
def add(self, collision):
self.colls[collision] = None
def union(self, other):
self.colls.update(other.colls)
@staticmethod
def from_list(col_list):
res = CollisionSet()
# for col in col_list:
i = len(col_list)
while i > 0:
i -= 1
col = col_list[i]
res.add(col)
return res
def as_list(self):
return list(self.colls.keys())
def to_string(self):
res = ('CollisionSet Object with %s elements:\n' % len(self.colls.keys()))
# for key in self.colls.keys():
# res += ''
class CollisionCollector:
def __init__(self):
self.collisions = CollisionSet()
def add_collisions(self, col_list):
self.collisions.union(CollisionSet.from_list(col_list))
def get_collisions(self):
return self.collisions.as_list()
import ctypes
class Float:
@staticmethod
def float_to_int_bits(flt):
from rpython.rtyper.lltypesystem import rffi
from rpython.rlib import longlong2float
from rpython.rlib.rarithmetic import intmask
return intmask(longlong2float.singlefloat2uint(rffi.cast(rffi.FLOAT, flt)))
@staticmethod
def int_bits_to_float(val):
from rpython.rtyper.lltypesystem import rffi
from rpython.rlib import longlong2float
return float(longlong2float.uint2singlefloat(rffi.cast(rffi.UINT, val)))
class Int:
@staticmethod
def u_rshift(i, n):
ui = i if i >= 0 else (0xAAAAAAAA + i)
r = ui >> n
return r
def ilog2(some_int):
res = 0
counter = 1
while counter < some_int:
res += 1
counter *= 2
return res
from rpython.dev.dev_CD.detector.vector import Vector3d
import math
class Motion:
def __init__(self, aircraft, pos_one, pos_two=None):
self.aircraft = aircraft
self.pos_one = pos_one
self.pos_two = pos_two if pos_two else pos_one
def find_intersection(self, other):
from rpython.dev.dev_CD.cd_consts import CONSTANTS
i1 = self.pos_one.copy()
f1 = self.pos_two.copy()
i2 = other.pos_one.copy()
f2 = other.pos_two.copy()
r = CONSTANTS.PROXIMITY_RADIUS
vx1 = f1.x - i1.x
vx2 = f2.x - i2.x
vy1 = f1.y - i1.y
vy2 = f2.y - i2.y
vz1 = f1.z - i1.z
vz2 = f2.z - i2.z
a = (vx2 - vx1) * (vx2 - vx1) + (vy2 - vy1) * (vy2 - vy1) + (vz2 - vz1) * (vz2 - vz1)
if a != 0.0:
b = 2.0 * (i2.x * vx2 - i2.x * vx1 - i1.x * vx2 + i1.x * vx1 +
i2.y * vy2 - i2.y * vy1 - i1.y * vy2 + i1.y * vy1 +
i2.z * vz2 - i2.z * vz1 - i1.z * vz2 + i1.z * vz1)
c = -r * r + (i2.x - i1.x) * (i2.x - i1.x) + (i2.y -
i1.y) * (i2.y - i1.y) + (i2.z - i1.z) * (i2.z - i1.z)
discr = b * b - 4.0 * a * c
if discr < 0.0:
return None
v1 = (-b - math.sqrt(discr)) / (2.0 * a)
v2 = (-b + math.sqrt(discr)) / (2.0 * a)
if (v1 <= v2 and (v1 <= 1.0 and 1.0 <= v2 or v1 <= 0.0 and 0.0 <= v2 or 0.0 <= v1 and v2 <= 1.0)):
x1col = i1.x + vx1 * (v1 + v2) / 2.0
y1col = i1.y + vy1 * (v1 + v2) / 2.0
z1col = i1.z + vz1 * (v1 + v2) / 2.0
if z1col > CONSTANTS.MIN_Z and z1col <= CONSTANTS.MAX_Z and x1col >= CONSTANTS.MIN_X and \
x1col <= CONSTANTS.MAX_X and y1col >= CONSTANTS.MIN_Y and y1col <= CONSTANTS.MAX_Y:
return Vector3d(x1col, y1col, z1col)
else:
dist = (i2.x - i1.x) * (i2.x - i1.x) + (i2.y - i1.y) * \
(i2.y - i1.y) + (i2.z - i1.z) * (i2.z - i1.z)
dist = math.sqrt(dist)
if dist <= r:
return self.pos_one
return None
def get_aircraft(self):
return self.aircraft
def get_first_position(self):
return self.pos_one
def get_second_position(self):
return self.pos_two
def to_string(self):
res = ('Motion of AC: %s from %s to %s' % (
self.aircraft.__str__(), self.pos_one.to_string(), self.pos_two.to_string()))
return res
from rpython.dev.dev_CD.realtime.no_heap_realtime_thread import NoHeapRealtimeThread
from rpython.dev.dev_CD.immortal.nano_clock import NanoClock
from rpython.rlib.rrtmu.rtzebu import print_str
from rpython.dev.dev_CD.realtime.memory.lt_memory import fake_ltmemory, LTMemory
from rpython.dev.dev_CD.cd_consts import CONSTANTS
class PersistentDetectorScopeEntry(NoHeapRealtimeThread):
def __init__(self, scope=fake_ltmemory, priority_param=None, periodic_param=None):
NoHeapRealtimeThread.__init__(
self, scope, priority_param, periodic_param)
self.stop = False
def run_detector_in_scope(self, cd, transient_detector_scope, noise_generator):
from rpython.dev.dev_CD.cd_statics import FRAME_SYNCHRONIZER
from rpython.dev.dev_CD.cd_statics import IMMORTAL_ENTRY
immortal_entry = IMMORTAL_ENTRY.getobj()
frame_synchronizer = FRAME_SYNCHRONIZER.getobj()
if CONSTANTS.SYNCHRONOUS_DETECTOR:
frame_synchronizer.wait_for_producer()
f = immortal_entry.framebuffer.get_frame()
if f is None:
immortal_entry.frame_not_ready_count += 1
return
if (immortal_entry.frames_processed + immortal_entry.dropped_frames) == CONSTANTS.MAX_FRAMES:
self.stop = True
return
heap_free_before = 0
time_before = NanoClock.now()
noise_generator.generate_noise_if_enabled()
cd.set_frame(f)
transient_detector_scope.enter(cd)
# transient_detector_scope.reset()
time_after = NanoClock.now()
transient_detector_scope.reset()
# TODO
heap_free_after = 0
if immortal_entry.recorded_runs < immortal_entry.max_detector_runs:
immortal_entry.times_before[immortal_entry.recorded_runs] = time_before
immortal_entry.times_after[immortal_entry.recorded_runs] = time_after
immortal_entry.heap_free_before[immortal_entry.recorded_runs] = heap_free_before
immortal_entry.heap_free_after[immortal_entry.recorded_runs] = heap_free_after
immortal_entry.recorded_runs += 1
immortal_entry.frames_processed += 1
if (immortal_entry.frames_processed + immortal_entry.dropped_frames) == CONSTANTS.MAX_FRAMES:
self.stop = True
def start(self):
from rpython.dev.dev_CD.cd_statics import IMMORTAL_ENTRY
immortal_entry = IMMORTAL_ENTRY.getobj()
immortal_entry.detector_thread_start = NanoClock.now()
self.start_internal()
def start_internal(self):
from rpython.rlib.rrtmu.rtzebu import start_new_rt_thread, new_attr, set_attr_priority
from rpython.dev.dev_CD.realtime.realtime_thread import RealtimeThread
self.start_time = RealtimeThread.nano_time()
a = new_attr()
set_attr_priority(a, self.priority)
start_new_rt_thread(run, a)
def join(self):
from rpython.dev.dev_CD.realtime.realtime_thread import RealtimeThread
from rpython.dev.dev_CD.cd_statics import PDSE
entry_obj = PDSE.getobj()
RealtimeThread.join(entry_obj)
def _ready_to_join(self):
from rpython.dev.dev_CD.realtime.realtime_thread import RealtimeThread
from rpython.dev.dev_CD.cd_statics import PDSE
entry_obj = PDSE.getobj()
RealtimeThread._ready_to_join(entry_obj)
def run():
from rpython.dev.dev_CD.cd_statics import IMMORTAL_ENTRY, PDSE
from rpython.dev.dev_CD.immortal.noise_generator import NoiseGenerator
from rpython.dev.dev_CD.detector.state_table import StateTable
from rpython.dev.dev_CD.detector.transient_detector_scope import TransientDetectorScopeEntry
entry_obj = PDSE.getobj()
immortal_entry = IMMORTAL_ENTRY.getobj()
noise_generator = NoiseGenerator()
transient_detector_scope = LTMemory(CONSTANTS.TRANSIENT_DETECTOR_SCOPE_SIZE)
try:
cd = TransientDetectorScopeEntry(
StateTable(), CONSTANTS.GOOD_VOXEL_SIZE)
if CONSTANTS.DEBUG_DETECTOR:
thread_intro = 'Detector thread is ' + entry_obj.get_name() + '\n'
print_str(thread_intro)
thread_info = 'Entering detector loop, detector thread priority is ' + \
str(entry_obj.get_priority())
print_str(thread_info)
while not entry_obj.stop:
while True:
missed = not entry_obj.wait_for_next_period()
now = NanoClock.now()
if immortal_entry.recorded_detector_release_times < \
len(immortal_entry.detector_release_times):
immortal_entry.detector_reported_miss[
immortal_entry.recorded_detector_release_times] = missed
immortal_entry.detector_release_times[
immortal_entry.recorded_detector_release_times] = now
immortal_entry.recorded_detector_release_times += 1
if not missed:
break
immortal_entry.reported_missed_periods += 1
entry_obj.run_detector_in_scope(cd, transient_detector_scope, noise_generator)
print_str('Detector is finished, processed all frames.')
except Exception as err:
raise err
entry_obj._ready_to_join()
from rpython.rlib.rrtmu.rtzebu import print_str
class Reducer:
def __init__(self, voxel_size):
from vector import Vector2d
self.voxel_size = voxel_size
self.horizontal = Vector2d(voxel_size, 0.0)
self.vertical = Vector2d(0.0, voxel_size)
def voxel_hash(self, position, voxel):
xtmp = position.x / self.voxel_size
x_div = int(xtmp)
voxel.x = self.voxel_size * x_div
if voxel.x > position.x:
voxel.x -= 1.0
if position.x < 0.0:
voxel.x -= self.voxel_size
ytmp = position.y / self.voxel_size
y_div = int(ytmp)
voxel.y = self.voxel_size * y_div
if voxel.y > position.y:
voxel.y -= 1.0
if position.y < 0.0:
voxel.y -= self.voxel_size
def put_into_map(self, voxel_map, voxel, motion):
from rpython.rlib.rrtmu.rtzebu import print_str
vc = voxel
if vc not in voxel_map:
voxel_map[vc] = [motion]
else:
voxel_map[vc].append(motion)
def is_in_voxel(self, voxel, motion):
from rpython.dev.dev_CD.cd_consts import CONSTANTS
from rpython.rlib.rrtmu.rtzebu import print_str
if (voxel.x > CONSTANTS.MAX_X) or ((voxel.x + self.voxel_size) < CONSTANTS.MIN_X) or (
voxel.y > CONSTANTS.MAX_Y) or ((voxel.y + self.voxel_size) < CONSTANTS.MIN_Y):
return False
init = motion.pos_one
fin = motion.pos_two
v_s = self.voxel_size
r = CONSTANTS.PROXIMITY_RADIUS / 2.0
v_x = voxel.x
x0 = init.x
xv = fin.x - init.x
v_y = voxel.y
y0 = init.y
yv = fin.y - init.y
low_x = (v_x - r - x0) / xv
high_x = (v_x + v_s + r - x0) / xv
if xv < 0.0:
tmp = low_x
low_x = high_x
high_x = tmp
low_y = (v_y - r - y0) / yv
high_y = (v_y + v_s + r - y0) / yv
if yv < 0.0:
tmp = low_y
low_y = high_y
high_y = tmp
# (
# (
b1 = (xv == 0.0)
f1 = x0 + r
b2 = (v_x <= f1)
b1 = (b1 and b2) # (xv == 0.0 && v_x <= x0 + r && ...
f1 = x0 - r
f2 = v_x + v_s
b2 = (f1 <= f2)
b1 = (b1 and b2) # (xv == 0.0 && v_x <= x0 + r && x0 - r <= v_x + v_s) /* no motion in x */ || ...
# ) b1 or
# (
# (
b2 = (low_x <= 1.0)
b3 = (high_x >= 1.0)
b2 = (b2 and b3) # (low_x <= 1.0f && 1.0f <= high_x) || ...
# ) b2 or
# (
b3 = (low_x <= 0.0)
b4 = (high_x >= 0.0)
b3 = (b3 and b4) # ... || (low_x <= 0.0f && 0.0f <= high_x) || ...
b2 = (b2 or b3)
# ) b2 or
# (
b3 = (low_x >= 0.0)
b4 = (high_x <= 1.0)
b3 = (b3 and b4) # ... || (0.0f <= low_x && high_x <= 1.0f))
b2 = (b2 or b3)
# ) b2
# )
b1 = (b1 or b2) # 120 & 121
# ) b1 and
# (
# (
b2 = (yv == 0.0)
f1 = y0 + r
b3 = (v_y <= f1)
b2 = (b2 and b3) # (yv == 0.0 && v_y <= y0 + r && ...
f1 = y0 - r
f2 = v_y + v_s
b3 = (f1 <= f2)
b2 = (b2 and b3) # 125
# ) b2 or
# (
# (
b3 = (low_y <= 1.0)
b4 = (high_y >= 1.0)
b3 = (b3 and b4)
# ) b3 or
# (
b4 = (low_y <= 0.0)
b5 = (high_y >= 0.0)
b4 = (b4 and b5)
b3 = (b3 or b4)
# ) b3 or
# (
b4 = (low_y >= 0.0)
b5 = (high_y <= 1.0)
b4 = (b4 and b5)
b3 = (b3 or b4) # 126
# )
b2 = (b2 or b3) # 125, 126
# )
b1 = (b1 and b2) # 119-127
# ) b1 and
# (
b2 = (xv == 0.0)
b3 = (yv == 0.0)
b2 = (b2 or b3) # 129
# ) b2 or
# (
# (
b3 = (low_y <= high_x)
b4 = (high_x <= high_y)
b3 = (b3 and b4)
# )
b2 = (b2 or b3)
# ) b2 or
# (
# (
b3 = (low_y <= low_x)
b4 = (low_x <= high_y)
b3 = (b3 and b4)
# )
b2 = (b2 or b3)
# ) b2 or
# (
# (
b3 = (low_x <= low_y)
b4 = (high_y <= high_x)
b3 = (b3 and b4)
# )
b2 = (b2 or b3) # 130
# )
b1 = (b1 and b2) # 118-131
# )
result = b1
return result
def dfs_voxel_hash_recurse(self, motion, next_voxel, voxel_map, graph_colors):
from vector import Vector2d
from rpython.rlib.rrtmu.rtzebu import print_str
tmp = Vector2d()
if self.is_in_voxel(next_voxel, motion) and not graph_colors.contains(next_voxel):
graph_colors.add(next_voxel)
self.put_into_map(voxel_map, next_voxel, motion)
tmp = Vector2d.__sub__(next_voxel, self.horizontal)
self.dfs_voxel_hash_recurse(motion, tmp, voxel_map, graph_colors)
tmp = Vector2d.__add__(next_voxel, self.horizontal)
self.dfs_voxel_hash_recurse(motion, tmp, voxel_map, graph_colors)
tmp = Vector2d.__add__(next_voxel, self.vertical)
self.dfs_voxel_hash_recurse(motion, tmp, voxel_map, graph_colors)
tmp = Vector2d.__sub__(next_voxel, self.vertical)
self.dfs_voxel_hash_recurse(motion, tmp, voxel_map, graph_colors)
tmp = Vector2d.__sub__(next_voxel, self.horizontal)
tmp = Vector2d.__add__(tmp, self.vertical)
self.dfs_voxel_hash_recurse(motion, tmp, voxel_map, graph_colors)
tmp = Vector2d.__add__(next_voxel, self.horizontal)
tmp = Vector2d.__add__(tmp, self.vertical)
self.dfs_voxel_hash_recurse(motion, tmp, voxel_map, graph_colors)
tmp = Vector2d.__sub__(next_voxel, self.horizontal)
tmp = Vector2d.__sub__(tmp, self.vertical)
self.dfs_voxel_hash_recurse(motion, tmp, voxel_map, graph_colors)
tmp = Vector2d.__add__(next_voxel, self.horizontal)
tmp = Vector2d.__sub__(tmp, self.vertical)
self.dfs_voxel_hash_recurse(motion, tmp, voxel_map, graph_colors)
def perform_voxel_hashing(self, motion, voxel_map, graph_colors):
from rpython.rlib.rrtmu.rtzebu import print_str
from vector import Vector2d
graph_colors.clear()
voxel = Vector2d()
self.voxel_hash(motion.pos_one, voxel)
self.dfs_voxel_hash_recurse(motion, voxel, voxel_map, graph_colors)
def reduce_collision_set(self, motions):
from rpython.rlib.rrtmu.rtzebu import print_str
from rpython.dev.dev_CD.cd_helpers import Vector2dSet
voxel_map = {}
graph_colors = Vector2dSet()
# for motion in motions:
i = len(motions)
while i > 0:
i -= 1
motion = motions[i]
self.perform_voxel_hashing(motion, voxel_map, graph_colors)
ret = []
# for key in voxel_map:
keys = voxel_map.keys()
i = len(keys)
while i > 0:
i -= 1
key = keys[i]
ret.append(key)
return ret
from rpython.rlib.objectmodel import r_dict
from rpython.dev.dev_CD.detector.vector import Vector3d
from rpython.dev.dev_CD.aircraft import CallSign
from rpython.rlib.rrtmu.rtzebu import print_str
from rpython.rlib.rrtmu.ll_mem import printhex_bytearray_ref, enter_scope, exit_area
from rpython.dev.dev_CD.cd_statics import IMMORTAL_ENTRY
class StateTable:
MAX_AIRPLANES = 10000
class R:
def __init__(self, state_table):
from rpython.dev.dev_CD.cd_helpers import ByteArray
self.state_table = state_table
self.callsign = CallSign(ByteArray.from_str('none'))
self.x = 0.0
self.y = 0.0
self.z = 0.0
def run(self):
state_table = self.state_table
cs_val = self.callsign.val
if cs_val in state_table.motion_vectors.keys():
state_table.motion_vectors[cs_val].set(self.x, self.y, self.z)
else:
state_table.allocated_vectors[state_table.used_vectors].set(self.x, self.y, self.z)
pscope = IMMORTAL_ENTRY.getobj().persistent_detector_scope.scope
enter_scope(pscope)
state_table.motion_vectors[cs_val] = state_table.allocated_vectors[
state_table.used_vectors]
exit_area()
state_table.used_vectors += 1
def __init__(self):
from rpython.dev.dev_CD.cd_helpers import ByteArray
self.r = StateTable.R(self)
self.allocated_vectors = []
self.used_vectors = 0
self.motion_vectors = r_dict(ByteArray.eq, ByteArray.hash)
# for i in range(StateTable.MAX_AIRPLANES):
i = StateTable.MAX_AIRPLANES
while i > 0:
i -= 1
self.allocated_vectors.append(Vector3d(0.0, 0.0, 0.0))
def put(self, call_sign, x, y, z):
self.r.callsign = call_sign
self.r.x = x
self.r.y = y
self.r.z = z
self.r.run()
def get(self, call_sign):
if call_sign.val in self.motion_vectors.keys():
res = self.motion_vectors[call_sign.val]
return res
else:
return None
def set(self, call_sign, x, y, z):
self.motion_vectors[call_sign.val].set(x, y, z)
double_check = self.motion_vectors[call_sign.val].get()
# def dump_state(self):
# print_str('DUMP-STATE for StateTable:')
# print_str('# used vectors: %s' % self.used_vectors)
# print_str('Motion Vectors: # %s' % len(self.motion_vectors.keys()))
# for key in self.motion_vectors.keys():
# printhex_bytearray_ref('StateTable.dump_state.key: ', key)
# print_str('mv[%s] = %s' % (key, self.motion_vectors[key].to_string()))
import os
from rpython.dev.dev_CD.cd_consts import CONSTANTS
from rpython.dev.dev_CD.cd_statics import IMMORTAL_ENTRY
from rpython.rlib.rrtmu.rtzebu import print_str
from rpython.dev.dev_CD.cd_helpers import ByteArray, String
from rpython.dev.dev_CD.aircraft import CallSign
class TransientDetectorScopeEntry:
def __init__(self, s, voxel_size):
from rpython.dev.dev_CD.immortal.raw_frame import RawFrame
self.state = s
self.voxel_size = voxel_size
self.frameno = -1
self.current_frame = RawFrame()
def set_frame(self, f):
if CONSTANTS.DEBUG_DETECTOR or CONSTANTS.DUMP_RECEIVED_FRAMES or CONSTANTS.SYNCHRONOUS_DETECTOR: