@@ -18,7 +18,7 @@ test_dir=$(pwd)
18
18
rtl_real_src_dir=" ${test_dir} /rtl_real_source"
19
19
synth_dir=" ${test_dir} /nl_single"
20
20
synalign_log_file=" ${test_dir} /extractor_alignment_tests/${top_name} _Synalign.log"
21
-
21
+ original_arrival_time=0.00
22
22
# which is the top module?
23
23
if [[ " $PWD " == * " PipelineDino" * ]]; then
24
24
top_name=" PipelinedCPU"
32
32
rtl_path=" ${test_dir} /rtl_modules"
33
33
rtl_selected_top_path=" ${test_dir} /rtl_single"
34
34
rtl_selected_top_file=" ${rtl_selected_top_path} /${top_name} .v"
35
+ rtl_opt_dir=" ${test_dir} /rtl_optimized"
36
+ INPUT_YAMLS=" /home/sgarg3/hagent/hagent/step/replicate_code/tests/input_yamls"
37
+ GEN_YAMLS=" /home/sgarg3/hagent/generated_yamls"
35
38
36
39
# example of what this function does: top.v(rtl)--{yosys}-->rtl_single/pipelinedCPU.v(rtl)
37
40
create_selected_top_file () {
186
189
# Extract the line with "slack" and get the corresponding value
187
190
# -m 1 --> will select only the 1st occurence. otherwise all the slack values will be printed.
188
191
arrival_time=$( grep -m 1 -oP ' \s*-?\d+\.\d+\s+data arrival time' " $latest_report " | awk ' {print $1}' )
189
-
192
+ original_arrival_time=arrival_time
190
193
# Output the slack value
191
194
echo " arrival_time: $arrival_time "
192
195
@@ -293,7 +296,16 @@ inou/yosys/lgcheck --top
293
296
294
297
}
295
298
296
- create_yaml_for_hagent () {
299
+ create_yaml_and_call_hagent () {
300
+
301
+ # Use sed to replace "module <top_name>_original" with "module <top_name>" in place
302
+ sed -i " s/module[[:space:]]\+${top_name} _original\>/module ${top_name} /" " $rtl_path /liveparse/${top_name} .v"
303
+ if [ -f " $rtl_path /liveparse/${top_name} _commented.v" ]; then
304
+ sed -i " s/module[[:space:]]\+${top_name} _original\>/module ${top_name} /" " $rtl_path /liveparse/${top_name} _commented.v"
305
+ fi
306
+ echo " NOTE: Reverted SynAlign renaming in $rtl_path /liveparse/${top_name} .v"
307
+
308
+
297
309
# Find all files ending with "_commented.v" and store in an array
298
310
files=($( find " ${rtl_path} /liveparse/" -type f -name " *_commented.v" ) )
299
311
@@ -316,38 +328,168 @@ create_yaml_for_hagent() {
316
328
base_name=$( basename " $file " " _commented.v" ) # Extract module name
317
329
output_file=" ${base_name} .yaml" # Construct output file name
318
330
echo " Creating yaml for $file -> $output_file "
319
- python3 ../create_yaml_for_hagent.py $file -m " openai/o3-mini-2025-01-31" -o ${rtl_path} /liveparse/$output_file
320
- done
331
+ python3 ../create_yaml_for_hagent.py $file $base_name -m " openai/o3-mini-2025-01-31" -o ${rtl_path} /liveparse/$output_file
332
+
333
+ # now call hagent for each of these files.
334
+
335
+ # Check and create input_yamls if it doesn't exist
336
+ if [ ! -d " $INPUT_YAMLS " ]; then
337
+ echo " Creating directory: $INPUT_YAMLS "
338
+ mkdir -p " $INPUT_YAMLS "
339
+ else
340
+ echo " Directory already exists: $INPUT_YAMLS "
341
+ fi
342
+
343
+ # Check and create generated_yamls if it doesn't exist
344
+ if [ ! -d " $GEN_YAMLS " ]; then
345
+ echo " Creating directory: $GEN_YAMLS "
346
+ mkdir -p " $GEN_YAMLS "
347
+ else
348
+ echo " Directory already exists: $GEN_YAMLS "
349
+ fi
350
+
351
+ # run hagent:
352
+ cp ${rtl_path} /liveparse/$output_file ${INPUT_YAMLS} /$output_file
353
+ echo " Copying ${rtl_path} /liveparse/$output_file to ${INPUT_YAMLS} /$output_file "
354
+
355
+
356
+ # go to hagent replicate_code directory
357
+ cd ~ /hagent/
358
+ ret_val=$?
359
+ if [ $ret_val -ne 0 ]; then
360
+ echo " \n--------hagent folder not found. check the directory structure and make necessary changes.--------\n\n"
361
+ exit $ret_val
362
+ fi
363
+ # rm res.log ; #rm replicate_code.log ; #poetry run python3 ./hagent/step/replicate_code/replicate_code.py -ogenerated_yamls/ALU.yaml ./hagent/step/replicate_code/tests/input_yamls/ALU.yaml |& tee res.log
364
+ poetry run python3 ./hagent/step/replicate_code/replicate_code.py -o${GEN_YAMLS} /${base_name} .yaml ${INPUT_YAMLS} /${base_name} .yaml 2>&1 | tee ${GEN_YAMLS} /${base_name} .log
365
+ echo " writing to ${GEN_YAMLS} /${base_name} .log...."
366
+ cd $test_dir
321
367
368
+ done
322
369
323
370
324
371
}
325
372
373
+ synth_yosys_and_calc_new_freq () {
326
374
327
- # #call_hagent() {
328
- # #}
375
+ echo " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
376
+ echo " Synthesize optimized design: $top_name ... "
377
+ echo " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
378
+ # # #Check if any file ending with "_optimized.v" is created using hagent:
379
+ # # #if they are created then bring them (without _optimized.v) to rtl_optimized directory in the test dir
380
+ if [ ! -d " $rtl_opt_dir " ]; then
381
+ mkdir -p " $rtl_opt_dir "
382
+ else
383
+ rm -r $rtl_opt_dir /*
384
+ fi
385
+ # get all orig files for synth:
386
+ # files=$(find "${rtl_path}/liveparse" -type f -name "*.v" ! -name "*_optimized.v" ! -name "*_commented.v") # Find all .v files but exclude _optimized.v and _commented.v
387
+ find " $rtl_path /liveparse" -type f -name " *.v" ! -name " *_optimized.v" ! -name " *_commented.v" -exec cp {} " $rtl_opt_dir " \;
388
+ # get optimized file from GEN_YAMLS and use these optimized modules instead of original modules:
389
+ files=$( find " $GEN_YAMLS " -type f -name " *_optimized.v" )
390
+ if [ -z " $files " ]; then
391
+ echo " No *_optimized.v files found in $GEN_YAMLS ."
392
+ else
393
+ echo " $files " | while read -r file; do
394
+ new_name=$( basename " $file " | sed ' s/_optimized//' )
395
+ cp " $file " " $rtl_opt_dir /$new_name "
396
+ echo " Copied and renamed: $file -> $rtl_opt_dir /$new_name "
397
+ done
398
+ fi
329
399
330
- # #./clean_tests.sh
331
- # #create_selected_top_file
332
- # #split_into_modules
333
- # #synth_yosys
334
- # #calc_frequency_and_create_color_dot_json
335
- # ##now we need to lower the arrival time to improve frequency.
336
- # ##Which part of rtl does the nodes in above reported timing path belong to?
337
- # #run_synalign
338
- # ##orig files are from liveparse/
339
- # #cd $test_dir
340
- # #comment_rtl
341
- # #
342
- # #echo `pwd`
400
+ # now we have all files to be synthesized in rtl_opt_dir
401
+ mkdir $rtl_opt_dir /synth_file
402
+ optimized_netlist=" $rtl_opt_dir /synth_file/${top_name} _synth.v"
403
+ yosys -p "
404
+ read_verilog -sv -defer $rtl_opt_dir /*.v
405
+ hierarchy -top $top_name ;
406
+ flatten $top_name ;
407
+ opt;
408
+ synth -top $top_name ;
409
+ dfflibmap -liberty $LIBERTY_FILE ;
410
+ printattrs;
411
+ stat;
412
+ abc -liberty $LIBERTY_FILE -dff -keepff -g aig;
413
+ stat;
414
+ write_verilog $optimized_netlist ;
415
+ " > synth_top.log
416
+ if [ $? -eq 0 ]; then
417
+ echo " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
418
+ echo " Synthesis using Yosys completed. "
419
+ echo " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
420
+ else
421
+ echo " ~~~~~~~~~~~~~ ERROR: YOSYS synthesis failed! ~~~~~~~~~~~"
422
+ exit 1
423
+ fi
343
424
344
- # now use AI to generate optimized versions of _commented.v files(modules)
345
- create_yaml_for_hagent
346
- # #call_hagent to create _optimized.v as well as run lec check on _optimized and _commented versions
347
425
426
+ echo " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
427
+ echo " Find frequency using openSTA for $top_name ... "
428
+ echo " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
429
+ cd $test_dir
430
+ mkdir $rtl_opt_dir /timing
431
+ # Define variables
432
+ new_sta_tcl=" $rtl_opt_dir /timing/run_sta.tcl" # Replace with the actual SDC filename
433
+
434
+ # Create the SDC file and write the required content
435
+ cat > " $new_sta_tcl " << EOF
436
+ read_liberty $LIBERTY_FILE
437
+ set_units -time ns -capacitance pF -voltage V -current mA -resistance kOhm -distance um
438
+ set_operating_conditions ff_100C_1v95
439
+ read_verilog $optimized_netlist
440
+ link_design $top_name
441
+ read_sdc ${top_name} .sdc
442
+ report_checks -path_delay max > ${rtl_opt_dir} /timing/timing_report.rpt
443
+ EOF
444
+
445
+ echo " SDC file created: $new_sta_tcl "
446
+
447
+ # Run OpenSTA
448
+ echo " source $new_sta_tcl " | ~ /opensta/OpenSTA/app/sta
449
+
450
+ # Find the latest timing report file
451
+ latest_report=$( ls ${rtl_opt_dir} /timing/timing_report.rpt 2> /dev/null | tail -n 1)
452
+ # Check if a file was found
453
+ if [ ! -n " $latest_report " ]; then
454
+ echo " No timing report found."
455
+ exit 1
456
+ fi
457
+
458
+ # Extract the line with "slack" and get the corresponding value
459
+ arrival_time=$( grep -m 1 -oP ' \s*-?\d+\.\d+\s+data arrival time' " $latest_report " | awk ' {print $1}' )
460
+ original_arrival_time=arrival_time
461
+ # Output the slack value
462
+ echo " new arrival_time: $arrival_time "
463
+
464
+ improved_arrival_time_diff=$( echo " $original_arrival_time - $arrival_time " | bc)
465
+ echo " ####################################################################"
466
+ echo " NOTE: improvement in arrival time: $improved_arrival_time_diff ns"
467
+ echo " ####################################################################"
348
468
349
- # if lec fails, get another version from LLM and retry LEC until it passes.
350
- # #write the chat command: "your solution fails LEC. try again."
351
469
470
+ }
471
+
472
+
473
+ ./clean_tests.sh
474
+ create_selected_top_file
475
+ split_into_modules
476
+ synth_yosys
477
+ calc_frequency_and_create_color_dot_json
478
+ # now we need to lower the arrival time to improve frequency.
479
+ # Which part of rtl does the nodes in above reported timing path belong to?
480
+ run_synalign
481
+ # orig files are from liveparse/
482
+ cd $test_dir
483
+ comment_rtl
484
+
485
+ echo ` pwd`
486
+
487
+ # now use AI to generate optimized versions of _commented.v files(modules)
488
+ create_yaml_and_call_hagent
489
+ # call_hagent to create _optimized.v as well as run lec check on _optimized and _commented versions
490
+ # if lec fails, get another version from LLM and retry LEC until it passes.
491
+ # write the chat command: "your solution fails LEC. try again."
352
492
# if lec passes, stitch optimized version with all other modules and create a neww top and re run synth+timing to check if freq. improved!
353
493
494
+ synth_yosys_and_calc_new_freq
495
+
0 commit comments