示例#1
0
 def reset(self):
     app.Log(2, "$ cp %s %s", self.bytecode_path,
             self.working_bytecode_path)
     shutil.copyfile(self.bytecode_path, self.working_bytecode_path)
     clang.Compile([self.working_bytecode_path],
                   self.binary_path,
                   copts=["-O0"])
     start_time = labdate.MillisecondsTimestamp()
     self.RunSetupCommand()
     self.RunBinary()
     if not self.BinaryIsValid():
         raise ValueError(f"Failed to validate base binary.")
     self.episodes.append(
         random_opt_pb2.Episode(step=[
             random_opt_pb2.Step(
                 start_time_epoch_ms=start_time,
                 status=random_opt_pb2.Step.PASS,
                 binary_runtime_ms=self.GetRuntimes(),
                 reward=0,
                 total_reward=0,
                 speedup=1.0,
                 total_speedup=1.0,
             )
         ]))
     self.episodes[-1].step[0].total_step_runtime_ms = (
         labdate.MillisecondsTimestamp() - start_time)
示例#2
0
 def step(self, action: int) -> Environment.step_t:
     """Perform the given action and return a step_t."""
     if not self.action_space.contains(action):
         raise ValueError(f"Unknown action: '{action}'")
     proto = self.Step(
         random_opt_pb2.Step(opt_pass=[self.config.candidate_pass[action]]))
     self.episodes[-1].step.extend([proto])
     # TODO(cec): Calculate observation once observation space is implemented.
     obs = self.observation_space.sample()
     reward = proto.reward
     done = False if proto.status == random_opt_pb2.Step.PASS else True
     return obs, reward, done, {}