def _synth(stub: synthesis_service_pb2_grpc.SynthesisServiceStub, verilog_text: str, top_module_name: str) -> synthesis_pb2.CompileResponse: """Bisects the space of frequencies and sends requests to the server.""" high = FLAGS.max_freq_mhz low = FLAGS.min_freq_mhz epsilon = 10 best_result = synthesis_pb2.CompileResponse() while high - low > epsilon: current = (high + low) / 2 request = synthesis_pb2.CompileRequest() request.target_frequency_hz = int(current * 10e6) request.module_text = verilog_text request.top_module_name = top_module_name logging.vlog(3, '--- Request') logging.vlog(3, request) response = stub.Compile(request) if response.slack_ps >= 0: logging.info('PASS at %dMHz (slack %d).', current, response.slack_ps) low = current if current > best_result.max_frequency_hz: best_result = response else: logging.info('FAIL at %dMHz (slack %d).', current, response.slack_ps) high = current best_result.max_frequency_hz = int(current * 10e6) return best_result
def _synth(stub: synthesis_service_pb2_grpc.SynthesisServiceStub, verilog_text: str, top_module_name: str) -> synthesis_pb2.CompileResponse: request = synthesis_pb2.CompileRequest() request.module_text = verilog_text request.top_module_name = top_module_name logging.vlog(3, '--- Request') logging.vlog(3, request) return stub.Compile(request)
def _generate_sources( self, op: op_pb2.OpProto, operand_types: Iterable[xls_type_pb2.TypeProto], output_type: xls_type_pb2.TypeProto) -> Tuple[str, str]: """Generates XLS IR and netlist sources for a single LEC execution. This function creates IR and a netlist for the given op and argument/output types, suitable as inputs to a LEC operation. Currently, this only supports a single op (per the internal operation of op_module_generator). In the future, it will likely be useful to see how execution time scales with operation composition. Args: op: The XLS IR opcode for which to generate sources. operand_types: The types of the arguments to use for this op execution. output_type: The type of the operation output. Returns: A tuple of IR and netlist sources for executing the given operation as text. """ op_name = op_pb2.OpProto.Name(op)[3:].lower() operand_type_strs = [ self._proto_to_ir_type(ot) for ot in operand_types ] ir_text = op_module_generator.generate_ir_package( op_name, self._proto_to_ir_type(output_type), operand_type_strs, [], None) verilog_text = op_module_generator.generate_verilog_module( self._MODULE_NAME, ir_text).verilog_text creds = client_credentials.get_credentials() netlist_text = None with grpc.secure_channel(self._synthesis_server_address, creds) as channel: grpc.channel_ready_future(channel).result() stub = synthesis_service_pb2_grpc.SynthesisServiceStub(channel) request = synthesis_pb2.CompileRequest() logging.vlog(logging.INFO, 'Module text:\n %s', verilog_text) request.module_text = verilog_text request.top_module_name = self._MODULE_NAME # We're always going to be in a single cycle. request.target_frequency_hz = 1 response = stub.Compile(request) netlist_text = response.netlist return (ir_text, netlist_text)
def main(argv): if len(argv) != 2: raise app.UsageError('Must specify verilog file.') with open(argv[1], 'r') as f: verilog_text = f.read() channel_creds = client_credentials.get_credentials() with grpc.secure_channel(f'localhost:{FLAGS.port}', channel_creds) as channel: grpc.channel_ready_future(channel).result() stub = synthesis_service_pb2_grpc.SynthesisServiceStub(channel) request = synthesis_pb2.CompileRequest() request.module_text = verilog_text request.top_module_name = FLAGS.top request.target_frequency_hz = int(FLAGS.ghz * 1e9) logging.info('--- Request') logging.info(request) response = stub.Compile(request) print(response)
def run_sample(target_hz: int) -> synthesis_pb2.CompileResponse: logging.info( 'Running with target frequency %0.3fGHz. Range: [%0.3fGHz, %0.3fGHz]', target_hz / 1e9, start_hz / 1e9, limit_hz / 1e9) grpc.channel_ready_future(grpc_channel).result() stub = synthesis_service_pb2_grpc.SynthesisServiceStub(grpc_channel) request = synthesis_pb2.CompileRequest() request.module_text = verilog_text request.top_module_name = top_module_name request.target_frequency_hz = target_hz response = stub.Compile(request) synthesis_result = sweep_result.results.add() synthesis_result.target_frequency_hz = target_hz synthesis_result.response.CopyFrom(response) if response.slack_ps >= 0: logging.info(' PASSED TIMING') sweep_result.max_frequency_hz = max(sweep_result.max_frequency_hz, target_hz) else: logging.info(' FAILED TIMING (slack %dps)', response.slack_ps) return response