def FeedInput(self, request, context): logger.info("server: feed_input") if request.comp_id not in self.computations: message = 'unknown computation id {}'.format(request.comp_id) return hetr_pb2.FeedInputReply(status=False, message=message) try: values = [] for v in request.values: if v.HasField('scalar'): values.append(protobuf_scalar_to_python(v.scalar)) else: values.append(pb_to_tensor(v.tensor)) computation = self.computations[request.comp_id] if self.transformer.transformer_name == "gpu": import pycuda.driver as drv if self.transformer.runtime and \ not self.transformer.runtime.ctx == drv.Context.get_current(): self.transformer.runtime.ctx.push() outputs = computation(*values) self.transformer.runtime.ctx.pop() else: outputs = computation(*values) self.results[request.comp_id] = outputs return hetr_pb2.FeedInputReply(status=True) except Exception: return hetr_pb2.FeedInputReply(status=False, message=traceback.format_exc())
def get_results(self): logger.info("client: get results") if self.feed_input_response_future is None: raise RuntimeError("call feed_input before get_results") response = self.feed_input_response_future.result() self.feed_input_response_future = None if not response.status: raise RuntimeError("RPC feed_input request failed: {}".format( response.message)) response = self.RPC.GetResults( hetr_pb2.GetResultsRequest(comp_id=self.comp_id), _TIMEOUT_SECONDS) if not response.status: raise RuntimeError("RPC get_results request failed: {}".format( response.message)) return_list = [] for r in response.results: if r.HasField('scalar'): return_list.append(protobuf_scalar_to_python(r.scalar)) else: return_list.append(pb_to_tensor(r.tensor)) return_dict = { op: return_list[mypos] for (op, mypos) in iteritems(self.returns) } return return_dict
def FeedInput(self, request, context): if request.comp_id >= len(self.computations): return hetr_pb2.FeedInputReply(status=False) values = [] for v in request.values: if v.HasField('scalar'): values.append(protobuf_scalar_to_python(v.scalar)) else: values.append(pb_to_tensor(v.tensor)) computation = self.computations[request.comp_id] outputs = computation(*values) self.results[request.comp_id] = outputs return hetr_pb2.FeedInputReply(status=True)
def get_results(self): response = self.RPC.GetResults( hetr_pb2.GetResultsRequest(comp_id=self.comp_id), _TIMEOUT_SECONDS) if not response.status: raise RuntimeError("RPC get_results request failed!") return_list = [] for r in response.results: if r.HasField('scalar'): return_list.append(protobuf_scalar_to_python(r.scalar)) else: return_list.append(pb_to_tensor(r.tensor)) return_dict = { op: return_list[mypos] for (op, mypos) in iteritems(self.returns) } return return_dict