Ejemplo n.º 1
0
def step_test():
    self.ctx  = driver.Device(0).make_context()
    self.device = self.ctx.get_device()
    mass = np.random.randn(3*N).astype(np.float32)
    pos = np.random.randn(3*N).reshape(N,3).astype(np.float32)
    vel = np.random.randn(3*N).reshape(N,3).astype(np.float32)

    hs = HostState(mass, pos, vel)
    ds = DeviceState(mass, pos, vel)

    ds.step(np.float32(0.1))
    self.ctx.pop()
    del self.ctx
Ejemplo n.º 2
0
    def __init__(self):
        self.modules = {}
        self.module_type_map = defaultdict(deque)

        self.device_state = DeviceState()
        self.event_queue = PriorityQueue()
        self.alarms = []
        self.modules = {}
        self.event_listeners = defaultdict(deque)
        self.trace_reader = None
        self.verbose = False
        self.debug_mode = False
        self.debug_interval = 1
        self.debug_interval_cnt = 0
Ejemplo n.º 3
0
 def get_transformed_event(self, device):
     event_dict = self.event_dict.copy()
     if 'target_view' in event_dict:
         target_view = event_dict.pop('target_view')
         target_view_selector = event_dict.pop('target_view_selector')
         state = device.get_current_state()
         matched_view = None
         for view_dict in state.views:
             if target_view_selector.match(view_dict):
                 matched_view = view_dict
                 break
         if matched_view is None:
             device.logger.warning("target_view no match: %s" % target_view)
         else:
             from device import DeviceState
             (event_dict['x'], event_dict['y']) = DeviceState.get_view_center(matched_view)
     return AppEvent.get_event(event_dict)
Ejemplo n.º 4
0
    def __init__(self):
        self._sim_modules = {}
        self._module_type_map = defaultdict(deque)

        self._device_state = DeviceState()
        self._event_queue = PriorityQueue()

        self._current_time = None
        self._warmup_period = None

        self._event_listeners = defaultdict(deque)
        self._trace_reader = None
        self._trace_executed = False
        self._verbose = False
        self._debug_mode = False
        self._debug_interval = 1
        self._debug_interval_cnt = 0
Ejemplo n.º 5
0
    def run(self):
        #Setup the device state wholly within the simulator thread
        self.deviceState = DeviceState.from_host_state(self.hostState)

        print("Starting physics simulator")
        while(not self.stopped):

            #Tell the device to perform the step
            self.deviceState.step(self.dt, self.G)

            #Get the host lock and copy over the new information
            with self.phys_lock:
                self.hostState.sync_with_device(self.deviceState)

            self.time += self.dt
            self.clock.tick(50)
        print("Stopping physics simulator")
Ejemplo n.º 6
0
 def create_device_state(self, device, options):
     self.device_state_objs.append(DeviceState(self.name + "-" + device.name, device, options))