Skip to content

Commit 036f542

Browse files
committed
wip
1 parent 18ff69b commit 036f542

File tree

1 file changed

+80
-75
lines changed

1 file changed

+80
-75
lines changed

chipflow_lib/steps/silicon.py

Lines changed: 80 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
logger = logging.getLogger(__name__)
2323

24-
2524
class SiliconTop(StepBase, Elaboratable):
2625
def __init__(self, config={}):
2726
self._config = config
@@ -191,80 +190,7 @@ def submit(self, rtlil_path, *, dry_run=False, wait=False):
191190
resp_data = resp.text
192191

193192
# Handle response based on status code
194-
if resp.status_code == 200:
195-
logger.info(f"Submitted design: {resp_data}")
196-
build_url = f"{chipflow_api_origin}/build/{resp_data['build_id']}"
197-
build_status_url = f"{chipflow_api_origin}/build/{resp_data['build_id']}/status"
198-
log_stream_url = f"{chipflow_api_origin}/build/{resp_data['build_id']}/logs?follow=true"
199-
200-
print(f"Design submitted successfully! Build URL: {build_url}")
201-
202-
# Poll the status API until the build is completed or failed
203-
stream_event_counter = 0
204-
fail_counter = 0
205-
warned_last = False
206-
timeout = 10.0;
207-
208-
if wait:
209-
while True:
210-
logger.info("Polling build status...")
211-
try:
212-
status_resp = requests.get(
213-
build_status_url,
214-
auth=(None, chipflow_api_key),
215-
timeout=timeout
216-
)
217-
if status_resp.status_code != 200:
218-
fail_counter += 1
219-
logger.error(f"Failed to fetch build status {fail_counter} times: {status_resp.text}")
220-
if fail_counter > 5:
221-
logger.error(f"Failed to fetch build status {fail_counter} times. Exiting.")
222-
raise ChipFlowError("Error while checking build status.")
223-
except requests.Timeout:
224-
continue #go round again
225-
226-
status_data = status_resp.json()
227-
build_status = status_data.get("status")
228-
logger.info(f"Build status: {build_status}")
229-
230-
if build_status == "completed":
231-
print("Build completed successfully!")
232-
exit(0)
233-
elif build_status == "failed":
234-
print("Build failed.")
235-
exit(1)
236-
elif build_status == "running":
237-
print("Build running.")
238-
# Wait before polling again
239-
# time.sleep(10)
240-
# Attempt to stream logs rather than time.sleep
241-
try:
242-
if stream_event_counter > 1 and not warned_last:
243-
logger.warning("Log streaming may have been interrupted. Some logs may be missing.")
244-
logger.warning(f"Check {build_url}")
245-
warned_last = True
246-
with requests.get(
247-
log_stream_url,
248-
auth=(None, chipflow_api_key),
249-
stream=True, timeout=timeout
250-
) as log_resp:
251-
if log_resp.status_code == 200:
252-
warned_last = False
253-
for line in log_resp.iter_lines():
254-
if line:
255-
print(line.decode("utf-8")) # Print logs in real-time
256-
sys.stdout.flush()
257-
else:
258-
logger.warning(f"Failed to stream logs: {log_resp.text}")
259-
stream_event_counter += 1
260-
except requests.Timeout as e:
261-
continue #go round again
262-
except requests.RequestException as e:
263-
logger.error(f"Error while streaming logs: {e}")
264-
stream_event_counter += 1
265-
pass
266-
time.sleep(0.5) # Wait before polling again
267-
else:
193+
if resp.status_code != 200:
268194
# Log detailed information about the failed request
269195
logger.error(f"Request failed with status code {resp.status_code}")
270196
logger.error(f"Request URL: {resp.request.url}")
@@ -280,3 +206,82 @@ def submit(self, rtlil_path, *, dry_run=False, wait=False):
280206
logger.error(f"Response body: {resp_data}")
281207

282208
raise ChipFlowError(f"Failed to submit design: {resp_data}")
209+
210+
logger.info(f"Submitted design: {resp_data}")
211+
build_url = f"{chipflow_api_origin}/build/{resp_data['build_id']}"
212+
build_status_url = f"{chipflow_api_origin}/build/{resp_data['build_id']}/status"
213+
log_stream_url = f"{chipflow_api_origin}/build/{resp_data['build_id']}/logs?follow=true"
214+
215+
print(f"Design submitted successfully! Build URL: {build_url}")
216+
217+
# Poll the status API until the build is completed or failed
218+
stream_event_counter = 0
219+
fail_counter = 0
220+
warned_last = False
221+
timeout = 10.0
222+
223+
def stream_until_fail_or_done():
224+
fail_count = 0
225+
while fail_count < (2*60//timeout):
226+
try:
227+
if stream_event_counter > 1 and not warned_last:
228+
logger.warning("Log streaming may have been interrupted. Some logs may be missing.")
229+
logger.warning(f"Check {build_url}")
230+
warned_last = True
231+
with requests.get(
232+
log_stream_url,
233+
auth=(None, chipflow_api_key),
234+
stream=True, timeout=timeout
235+
) as log_resp:
236+
if log_resp.status_code == 200:
237+
warned_last = False
238+
for line in log_resp.iter_lines():
239+
if line:
240+
print(line.decode("utf-8")) # Print logs in real-time
241+
sys.stdout.flush()
242+
else:
243+
logger.warning(f"Failed to stream logs: {log_resp.text}")
244+
stream_event_counter += 1
245+
except requests.Timeout:
246+
continue #go round again
247+
except requests.RequestException as e:
248+
logger.error(f"Error while streaming logs: {e}")
249+
stream_event_counter += 1
250+
return "failed"
251+
status_data = status_resp.json()
252+
build_status = status_data.get("status")
253+
return build_status
254+
255+
256+
if not wait:
257+
exit(0)
258+
259+
while True:
260+
logger.info("Polling build status...")
261+
try:
262+
status_resp = requests.get(
263+
build_status_url,
264+
auth=(None, chipflow_api_key),
265+
timeout=timeout
266+
)
267+
if status_resp.status_code != 200:
268+
fail_counter += 1
269+
logger.error(f"Failed to fetch build status {fail_counter} times: {status_resp.text}")
270+
if fail_counter > 5:
271+
logger.error(f"Failed to fetch build status {fail_counter} times. Exiting.")
272+
raise ChipFlowError("Error while checking build status.")
273+
except requests.Timeout:
274+
continue #go round again
275+
276+
build_status = stream_until_fail_or_done()
277+
if build_status == "completed":
278+
print("Build completed successfully!")
279+
exit(0)
280+
elif build_status == "failed":
281+
print("Build failed.")
282+
exit(1)
283+
elif build_status == "running":
284+
print("Build running.")
285+
# Wait before polling again
286+
time.sleep(0.5) # Wait before polling again
287+

0 commit comments

Comments
 (0)