-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcompositional_partitioner.sh
More file actions
executable file
·1211 lines (1030 loc) · 48.1 KB
/
compositional_partitioner.sh
File metadata and controls
executable file
·1211 lines (1030 loc) · 48.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Compositional Partitioner for ChipletPart
# This script implements a hierarchical partitioning strategy by:
# 1. Partitioning smaller test cases
# 2. Merging these partitions in various combinations
# 3. Comparing the results with direct partitioning
# 4. Selecting the best solution based on objective cost
# Set colors for better output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Define base directory and other paths
BASE_DIR="$(pwd)"
BUILD_DIR="${BASE_DIR}/build"
EXECUTABLE="${BUILD_DIR}/bin/chipletPart"
RESULTS_DIR="${BASE_DIR}/results/compositional"
TEST_DATA_DIR="${BASE_DIR}/test_data"
TEMP_DIR="${BASE_DIR}/temp_compositional"
# Create necessary directories
mkdir -p "${RESULTS_DIR}"
mkdir -p "${TEMP_DIR}"
# Default parameters
DEFAULT_REACH="0.50"
DEFAULT_SEPARATION="0.25"
DEFAULT_TECH="7nm"
DEFAULT_SEED="42"
# Function to display usage information
function show_help {
echo -e "${BLUE}Compositional Partitioner for ChipletPart${NC}"
echo
echo "Usage: $0 <command> [options]"
echo
echo "Commands:"
echo " verify-test-cases Verify that all test cases exist and contain required files"
echo " generate-partitions Generate partitions for all base test cases"
echo " compose-48_2 Evaluate compositional strategies for 48_2"
echo " compose-48_4 Evaluate compositional strategies for 48_4"
echo " compose-48_8 Evaluate compositional strategies for 48_8"
echo " compose-48_16 Evaluate compositional strategies for 48_16"
echo " evaluate-all Run all compositional evaluations"
echo
echo "Options:"
echo " --reach <value> Specify reach value (default: ${DEFAULT_REACH})"
echo " --separation <value> Specify separation value (default: ${DEFAULT_SEPARATION})"
echo " --tech <node> Specify tech node (default: ${DEFAULT_TECH})"
echo " --seed <value> Specify random seed (default: ${DEFAULT_SEED})"
echo " --help Display this help message"
echo
echo "Example: $0 compose-48_4 --tech 7nm --seed 123"
}
# Function to create base test cases from the existing test case
function verify_test_cases {
echo -e "${CYAN}Verifying existing test cases...${NC}"
# Check if all required test cases exist
local all_cases_exist=true
for test_case in "48_1_14_4_1600_1600" "48_2_14_4_1600_1600" "48_4_14_4_1600_1600" "48_8_14_4_1600_1600" "48_16_14_4_1600_1600"; do
if [ ! -d "${TEST_DATA_DIR}/${test_case}" ]; then
echo -e "${RED}Error: Test case directory ${TEST_DATA_DIR}/${test_case} does not exist.${NC}"
all_cases_exist=false
else
# Check if all required files exist
local test_dir="${TEST_DATA_DIR}/${test_case}"
for file in "io_definitions.xml" "layer_definitions.xml" "wafer_process_definitions.xml" \
"assembly_process_definitions.xml" "test_definitions.xml" \
"block_level_netlist.xml" "block_definitions.txt"; do
if [ ! -f "${test_dir}/${file}" ]; then
echo -e "${RED}Error: File ${file} not found in ${test_dir}.${NC}"
all_cases_exist=false
fi
done
echo -e "${GREEN}Test case ${test_case} verified.${NC}"
fi
done
if [ "$all_cases_exist" = true ]; then
echo -e "${GREEN}All test cases exist and contain required files.${NC}"
else
echo -e "${RED}Some test cases are missing or incomplete. Please ensure all test cases exist in ${TEST_DATA_DIR}.${NC}"
exit 1
fi
}
# Function to run the chipletPart executable on a test case
function run_chiplet_part {
local test_case=$1
local output_dir=$2
local tech=$3
local reach=$4
local separation=$5
local seed=$6
echo -e "${BLUE}Running ChipletPart on ${test_case}...${NC}"
# Define paths for the input files
local test_dir="${TEST_DATA_DIR}/${test_case}"
# Create output directory
mkdir -p "${output_dir}"
# Run the ChipletPart executable using the existing script
echo -e "Running: ./run_chiplet_test.sh ${test_case} --tech ${tech} --reach ${reach} --separation ${separation} --seed ${seed}"
./run_chiplet_test.sh "${test_case}" --tech "${tech}" --reach "${reach}" --separation "${separation}" --seed "${seed}" | tee "${output_dir}/run.log"
# Check if the execution was successful
if [ $? -ne 0 ]; then
echo -e "${RED}Error: ChipletPart execution failed for ${test_case}${NC}"
return 1
fi
# Copy partition results from the test data directory to the output directory
local partition_file="${TEST_DATA_DIR}/${test_case}/block_level_netlist.xml.cpart.4"
if [ -f "${partition_file}" ]; then
cp "${partition_file}" "${output_dir}/partition.txt"
echo -e "${GREEN}Found partition file: ${partition_file}${NC}"
else
echo -e "${YELLOW}Warning: Could not find expected partition file at ${partition_file}${NC}"
# Look for other cpart files
for cpart_file in ${TEST_DATA_DIR}/${test_case}/*.cpart.*; do
if [ -f "$cpart_file" ]; then
cp "$cpart_file" "${output_dir}/partition.txt"
echo -e "${GREEN}Found partition file: $cpart_file${NC}"
break
fi
done
fi
# Extract and store the objective cost from the log file
local cost=$(grep "Objective Cost:" "${output_dir}/run.log" | tail -1 | awk '{print $NF}')
if [ -n "$cost" ]; then
echo "$cost" > "${output_dir}/objective_cost.txt"
echo -e "${GREEN}ChipletPart completed for ${test_case}. Objective cost: ${cost}${NC}"
else
# Try another pattern that might be in the log
cost=$(grep "Cost" "${output_dir}/run.log" | grep -o '[0-9]\+\.[0-9]\+' | tail -1)
if [ -n "$cost" ]; then
echo "$cost" > "${output_dir}/objective_cost.txt"
echo -e "${GREEN}ChipletPart completed for ${test_case}. Objective cost: ${cost}${NC}"
else
echo -e "${YELLOW}Warning: Could not extract objective cost for ${test_case}${NC}"
return 1
fi
fi
return 0
}
# Function to generate partitions for all base test cases
function generate_partitions {
echo -e "${CYAN}Generating partitions for base test cases...${NC}"
local reach=${1:-$DEFAULT_REACH}
local separation=${2:-$DEFAULT_SEPARATION}
local tech=${3:-$DEFAULT_TECH}
local seed=${4:-$DEFAULT_SEED}
# Make sure the 48_1 test case is run first, since it's needed for the compositions
run_chiplet_part "48_1_14_4_1600_1600" "${RESULTS_DIR}/48_1_14_4_1600_1600_direct" "$tech" "$reach" "$separation" "$seed"
# Run ChipletPart on each remaining base test case
for test_case in "48_2_14_4_1600_1600" "48_4_14_4_1600_1600" "48_8_14_4_1600_1600" "48_16_14_4_1600_1600"; do
local output_dir="${RESULTS_DIR}/${test_case}_direct"
# Skip if the test case directory doesn't exist
if [ ! -d "${TEST_DATA_DIR}/${test_case}" ]; then
echo -e "${YELLOW}Warning: Test case directory ${TEST_DATA_DIR}/${test_case} does not exist. Skipping.${NC}"
continue
fi
run_chiplet_part "$test_case" "$output_dir" "$tech" "$reach" "$separation" "$seed"
done
echo -e "${GREEN}Partition generation completed.${NC}"
}
# Function to merge partitions from smaller test cases
function merge_partitions {
echo -e "${BLUE}Merging partitions...${NC}"
local output_file=$1
shift
local partition_files=("$@")
# Check if all input files exist
for file in "${partition_files[@]}"; do
if [ ! -f "$file" ]; then
echo -e "${RED}Error: Partition file not found: $file${NC}"
return 1
fi
done
# Use the Python utility to merge the partition files
local partition_files_args=""
for file in "${partition_files[@]}"; do
partition_files_args+=" $file"
done
echo -e "Merging partitions: ${partition_files_args} into ${output_file}"
${BASE_DIR}/compositional_utils.py merge-partitions \
--output-file "$output_file" \
--partition-files $partition_files_args \
--preserve-relative
if [ $? -ne 0 ]; then
echo -e "${RED}Error: Failed to merge partition files.${NC}"
return 1
fi
echo -e "${GREEN}Partitions merged into ${output_file}${NC}"
return 0
}
# Function to extract cost from evaluation log
function extract_cost_from_log {
local log_file=$1
local cost=""
# Try to extract from the evaluation output
cost=$(grep "Partition evaluation cost:" "$log_file" | awk '{print $NF}')
# If that fails, look for simulated cost
if [ -z "$cost" ]; then
cost=$(grep "Simulated cost:" "$log_file" | awk '{print $NF}')
fi
echo "$cost"
}
# Function to evaluate the composition of 48_2 test case
function compose_48_2 {
echo -e "${CYAN}Evaluating compositional strategies for 48_2_14_4_1600_1600...${NC}"
local reach=${1:-$DEFAULT_REACH}
local separation=${2:-$DEFAULT_SEPARATION}
local tech=${3:-$DEFAULT_TECH}
local seed=${4:-$DEFAULT_SEED}
# Create output directory for this evaluation
local eval_dir="${RESULTS_DIR}/48_2_evaluation"
mkdir -p "$eval_dir"
# Strategy 1: Direct partitioning of 48_2
local direct_result="${RESULTS_DIR}/48_2_14_4_1600_1600_direct"
local direct_cost="N/A"
if [ -f "${direct_result}/objective_cost.txt" ]; then
direct_cost=$(cat "${direct_result}/objective_cost.txt")
else
echo -e "${YELLOW}Warning: Direct partitioning results for 48_2 not found. Running direct partitioning...${NC}"
run_chiplet_part "48_2_14_4_1600_1600" "$direct_result" "$tech" "$reach" "$separation" "$seed"
if [ -f "${direct_result}/objective_cost.txt" ]; then
direct_cost=$(cat "${direct_result}/objective_cost.txt")
else
echo -e "${RED}Error: Failed to get direct partitioning cost for 48_2${NC}"
fi
fi
# Strategy 2: Merge two instances of 48_1
local merge_dir="${eval_dir}/48_1_x2"
mkdir -p "$merge_dir"
local result_48_1="${RESULTS_DIR}/48_1_14_4_1600_1600_direct"
local merged_partition="${merge_dir}/partition.txt"
if [ -f "${result_48_1}/partition.txt" ]; then
# Merge two instances of the 48_1 partition
merge_partitions "$merged_partition" "${result_48_1}/partition.txt" "${result_48_1}/partition.txt"
# Evaluate the merged partition using the ChipletPart cost model
local test_case_dir="${TEST_DATA_DIR}/48_2_14_4_1600_1600"
${BASE_DIR}/compositional_utils.py evaluate-partition \
--test-case-dir "$test_case_dir" \
--partition-file "$merged_partition" \
--tech "$tech" \
--reach "$reach" \
--separation "$separation" \
--seed "$seed" | tee "${merge_dir}/evaluation.log"
# Extract and store the cost from the evaluation log
local merged_cost=$(extract_cost_from_log "${merge_dir}/evaluation.log")
if [ -n "$merged_cost" ]; then
echo "$merged_cost" > "${merge_dir}/objective_cost.txt"
else
echo -e "${YELLOW}Warning: Could not extract cost from evaluation log.${NC}"
local merged_cost="N/A"
fi
else
echo -e "${YELLOW}Warning: Partition results for 48_1 not found.${NC}"
local merged_cost="N/A"
fi
# Compare the strategies and select the best one
echo -e "${GREEN}Compositional evaluation for 48_2 completed.${NC}"
echo -e "${BLUE}Results:${NC}"
echo -e " Direct partitioning: ${direct_cost}"
if [ -f "${merge_dir}/objective_cost.txt" ]; then
merged_cost=$(cat "${merge_dir}/objective_cost.txt")
echo -e " Merged 48_1 x2: ${merged_cost}"
# Determine the better strategy
if [ "$direct_cost" != "N/A" ] && [ "$merged_cost" != "N/A" ]; then
if (( $(echo "$merged_cost < $direct_cost" | bc -l) )); then
echo -e "${GREEN}The better strategy is: Merged 48_1 x2 (Cost: ${merged_cost})${NC}"
echo "merged" > "${eval_dir}/best_strategy.txt"
cp "${merged_partition}" "${eval_dir}/best_partition.txt"
else
echo -e "${GREEN}The better strategy is: Direct partitioning (Cost: ${direct_cost})${NC}"
echo "direct" > "${eval_dir}/best_strategy.txt"
cp "${direct_result}/partition.txt" "${eval_dir}/best_partition.txt"
fi
else
echo -e "${YELLOW}Unable to determine the best strategy due to missing costs.${NC}"
fi
else
echo -e " Merged 48_1 x2: N/A (evaluation failed)"
fi
echo -e "Compositional evaluation results saved to ${eval_dir}."
}
# Function to evaluate the composition of 48_4 test case
function compose_48_4 {
echo -e "${CYAN}Evaluating compositional strategies for 48_4_14_4_1600_1600...${NC}"
local reach=${1:-$DEFAULT_REACH}
local separation=${2:-$DEFAULT_SEPARATION}
local tech=${3:-$DEFAULT_TECH}
local seed=${4:-$DEFAULT_SEED}
# Create output directory for this evaluation
local eval_dir="${RESULTS_DIR}/48_4_evaluation"
mkdir -p "$eval_dir"
# Strategy 1: Direct partitioning of 48_4
local direct_result="${RESULTS_DIR}/48_4_14_4_1600_1600_direct"
local direct_cost="N/A"
if [ -f "${direct_result}/objective_cost.txt" ]; then
direct_cost=$(cat "${direct_result}/objective_cost.txt")
else
echo -e "${YELLOW}Warning: Direct partitioning results for 48_4 not found. Running direct partitioning...${NC}"
run_chiplet_part "48_4_14_4_1600_1600" "$direct_result" "$tech" "$reach" "$separation" "$seed"
if [ -f "${direct_result}/objective_cost.txt" ]; then
direct_cost=$(cat "${direct_result}/objective_cost.txt")
else
echo -e "${RED}Error: Failed to get direct partitioning cost for 48_4${NC}"
fi
fi
local test_case_dir="${TEST_DATA_DIR}/48_4_14_4_1600_1600"
local result_48_1="${RESULTS_DIR}/48_1_14_4_1600_1600_direct"
local result_48_2="${RESULTS_DIR}/48_2_14_4_1600_1600_direct"
# Strategy 2: Merge four instances of 48_1
local merge_dir1="${eval_dir}/48_1_x4"
mkdir -p "$merge_dir1"
local merged_partition1="${merge_dir1}/partition.txt"
local merged_cost1="N/A"
if [ -f "${result_48_1}/partition.txt" ]; then
# Merge four instances of the 48_1 partition
merge_partitions "$merged_partition1" "${result_48_1}/partition.txt" "${result_48_1}/partition.txt" "${result_48_1}/partition.txt" "${result_48_1}/partition.txt"
# Evaluate the merged partition
${BASE_DIR}/compositional_utils.py evaluate-partition \
--test-case-dir "$test_case_dir" \
--partition-file "$merged_partition1" \
--tech "$tech" \
--reach "$reach" \
--separation "$separation" \
--seed "$seed" | tee "${merge_dir1}/evaluation.log"
# Extract and store the cost
merged_cost1=$(extract_cost_from_log "${merge_dir1}/evaluation.log")
if [ -n "$merged_cost1" ]; then
echo "$merged_cost1" > "${merge_dir1}/objective_cost.txt"
else
echo -e "${YELLOW}Warning: Could not extract cost for 48_1 x4 strategy.${NC}"
merged_cost1="N/A"
fi
else
echo -e "${YELLOW}Warning: Partition results for 48_1 not found.${NC}"
fi
# Strategy 3: Merge two instances of 48_2
local merge_dir2="${eval_dir}/48_2_x2"
mkdir -p "$merge_dir2"
local merged_partition2="${merge_dir2}/partition.txt"
local merged_cost2="N/A"
if [ -f "${result_48_2}/partition.txt" ]; then
# Merge two instances of the 48_2 partition
merge_partitions "$merged_partition2" "${result_48_2}/partition.txt" "${result_48_2}/partition.txt"
# Evaluate the merged partition
${BASE_DIR}/compositional_utils.py evaluate-partition \
--test-case-dir "$test_case_dir" \
--partition-file "$merged_partition2" \
--tech "$tech" \
--reach "$reach" \
--separation "$separation" \
--seed "$seed" | tee "${merge_dir2}/evaluation.log"
# Extract and store the cost
merged_cost2=$(extract_cost_from_log "${merge_dir2}/evaluation.log")
if [ -n "$merged_cost2" ]; then
echo "$merged_cost2" > "${merge_dir2}/objective_cost.txt"
else
echo -e "${YELLOW}Warning: Could not extract cost for 48_2 x2 strategy.${NC}"
merged_cost2="N/A"
fi
else
echo -e "${YELLOW}Warning: Partition results for 48_2 not found.${NC}"
fi
# Strategy 4: Merge one instance of 48_2 and two instances of 48_1
local merge_dir3="${eval_dir}/48_2_x1_48_1_x2"
mkdir -p "$merge_dir3"
local merged_partition3="${merge_dir3}/partition.txt"
local merged_cost3="N/A"
if [ -f "${result_48_1}/partition.txt" ] && [ -f "${result_48_2}/partition.txt" ]; then
# Merge one 48_2 and two 48_1 partitions
merge_partitions "$merged_partition3" "${result_48_2}/partition.txt" "${result_48_1}/partition.txt" "${result_48_1}/partition.txt"
# Evaluate the merged partition
${BASE_DIR}/compositional_utils.py evaluate-partition \
--test-case-dir "$test_case_dir" \
--partition-file "$merged_partition3" \
--tech "$tech" \
--reach "$reach" \
--separation "$separation" \
--seed "$seed" | tee "${merge_dir3}/evaluation.log"
# Extract and store the cost
merged_cost3=$(extract_cost_from_log "${merge_dir3}/evaluation.log")
if [ -n "$merged_cost3" ]; then
echo "$merged_cost3" > "${merge_dir3}/objective_cost.txt"
else
echo -e "${YELLOW}Warning: Could not extract cost for 48_2 x1 + 48_1 x2 strategy.${NC}"
merged_cost3="N/A"
fi
else
echo -e "${YELLOW}Warning: Partition results for 48_1 or 48_2 not found.${NC}"
fi
# Compare the strategies and select the best one
echo -e "${GREEN}Compositional evaluation for 48_4 completed.${NC}"
echo -e "${BLUE}Results:${NC}"
echo -e " Direct partitioning: ${direct_cost}"
# Get all costs
if [ -f "${merge_dir1}/objective_cost.txt" ]; then
merged_cost1=$(cat "${merge_dir1}/objective_cost.txt")
fi
echo -e " Merged 48_1 x4: ${merged_cost1}"
if [ -f "${merge_dir2}/objective_cost.txt" ]; then
merged_cost2=$(cat "${merge_dir2}/objective_cost.txt")
fi
echo -e " Merged 48_2 x2: ${merged_cost2}"
if [ -f "${merge_dir3}/objective_cost.txt" ]; then
merged_cost3=$(cat "${merge_dir3}/objective_cost.txt")
fi
echo -e " Merged 48_2 x1 + 48_1 x2: ${merged_cost3}"
# Find the best strategy
local best_cost="$direct_cost"
local best_strategy="direct"
local best_partition="${direct_result}/partition.txt"
if [ "$merged_cost1" != "N/A" ] && (( $(echo "$merged_cost1 < $best_cost" | bc -l) )); then
best_cost="$merged_cost1"
best_strategy="48_1_x4"
best_partition="$merged_partition1"
fi
if [ "$merged_cost2" != "N/A" ] && (( $(echo "$merged_cost2 < $best_cost" | bc -l) )); then
best_cost="$merged_cost2"
best_strategy="48_2_x2"
best_partition="$merged_partition2"
fi
if [ "$merged_cost3" != "N/A" ] && (( $(echo "$merged_cost3 < $best_cost" | bc -l) )); then
best_cost="$merged_cost3"
best_strategy="48_2_x1_48_1_x2"
best_partition="$merged_partition3"
fi
echo -e "${GREEN}The best strategy is: ${best_strategy} (Cost: ${best_cost})${NC}"
echo "$best_strategy" > "${eval_dir}/best_strategy.txt"
if [ -f "$best_partition" ]; then
cp "$best_partition" "${eval_dir}/best_partition.txt"
else
echo -e "${YELLOW}Warning: Best partition file not found.${NC}"
fi
echo -e "Compositional evaluation results saved to ${eval_dir}."
}
# Function to evaluate the composition of 48_8 test case
function compose_48_8 {
echo -e "${CYAN}Evaluating compositional strategies for 48_8_14_4_1600_1600...${NC}"
local reach=${1:-$DEFAULT_REACH}
local separation=${2:-$DEFAULT_SEPARATION}
local tech=${3:-$DEFAULT_TECH}
local seed=${4:-$DEFAULT_SEED}
# Create output directory for this evaluation
local eval_dir="${RESULTS_DIR}/48_8_evaluation"
mkdir -p "$eval_dir"
# Strategy 1: Direct partitioning of 48_8
local direct_result="${RESULTS_DIR}/48_8_14_4_1600_1600_direct"
local direct_cost="N/A"
if [ -f "${direct_result}/objective_cost.txt" ]; then
direct_cost=$(cat "${direct_result}/objective_cost.txt")
else
echo -e "${YELLOW}Warning: Direct partitioning results for 48_8 not found. Running direct partitioning...${NC}"
run_chiplet_part "48_8_14_4_1600_1600" "$direct_result" "$tech" "$reach" "$separation" "$seed"
if [ -f "${direct_result}/objective_cost.txt" ]; then
direct_cost=$(cat "${direct_result}/objective_cost.txt")
else
echo -e "${RED}Error: Failed to get direct partitioning cost for 48_8${NC}"
fi
fi
local test_case_dir="${TEST_DATA_DIR}/48_8_14_4_1600_1600"
local result_48_1="${RESULTS_DIR}/48_1_14_4_1600_1600_direct"
local result_48_2="${RESULTS_DIR}/48_2_14_4_1600_1600_direct"
local result_48_4="${RESULTS_DIR}/48_4_14_4_1600_1600_direct"
# Strategy 2: Merge eight instances of 48_1
local merge_dir1="${eval_dir}/48_1_x8"
mkdir -p "$merge_dir1"
local merged_partition1="${merge_dir1}/partition.txt"
local merged_cost1="N/A"
if [ -f "${result_48_1}/partition.txt" ]; then
# Merge eight instances of the 48_1 partition
merge_partitions "$merged_partition1" "${result_48_1}/partition.txt" "${result_48_1}/partition.txt" "${result_48_1}/partition.txt" "${result_48_1}/partition.txt" "${result_48_1}/partition.txt" "${result_48_1}/partition.txt" "${result_48_1}/partition.txt" "${result_48_1}/partition.txt"
# Evaluate the merged partition
${BASE_DIR}/compositional_utils.py evaluate-partition \
--test-case-dir "$test_case_dir" \
--partition-file "$merged_partition1" \
--tech "$tech" \
--reach "$reach" \
--separation "$separation" \
--seed "$seed" | tee "${merge_dir1}/evaluation.log"
# Extract and store the cost
merged_cost1=$(extract_cost_from_log "${merge_dir1}/evaluation.log")
if [ -n "$merged_cost1" ]; then
echo "$merged_cost1" > "${merge_dir1}/objective_cost.txt"
else
echo -e "${YELLOW}Warning: Could not extract cost for 48_1 x8 strategy.${NC}"
merged_cost1="N/A"
fi
else
echo -e "${YELLOW}Warning: Partition results for 48_1 not found.${NC}"
fi
# Strategy 3: Merge four instances of 48_2
local merge_dir2="${eval_dir}/48_2_x4"
mkdir -p "$merge_dir2"
local merged_partition2="${merge_dir2}/partition.txt"
local merged_cost2="N/A"
if [ -f "${result_48_2}/partition.txt" ]; then
# Merge four instances of the 48_2 partition
merge_partitions "$merged_partition2" "${result_48_2}/partition.txt" "${result_48_2}/partition.txt" "${result_48_2}/partition.txt" "${result_48_2}/partition.txt"
# Evaluate the merged partition
${BASE_DIR}/compositional_utils.py evaluate-partition \
--test-case-dir "$test_case_dir" \
--partition-file "$merged_partition2" \
--tech "$tech" \
--reach "$reach" \
--separation "$separation" \
--seed "$seed" | tee "${merge_dir2}/evaluation.log"
# Extract and store the cost
merged_cost2=$(extract_cost_from_log "${merge_dir2}/evaluation.log")
if [ -n "$merged_cost2" ]; then
echo "$merged_cost2" > "${merge_dir2}/objective_cost.txt"
else
echo -e "${YELLOW}Warning: Could not extract cost for 48_2 x4 strategy.${NC}"
merged_cost2="N/A"
fi
else
echo -e "${YELLOW}Warning: Partition results for 48_2 not found.${NC}"
fi
# Strategy 4: Merge two instances of 48_4
local merge_dir3="${eval_dir}/48_4_x2"
mkdir -p "$merge_dir3"
local merged_partition3="${merge_dir3}/partition.txt"
local merged_cost3="N/A"
if [ -f "${result_48_4}/partition.txt" ]; then
# Merge two instances of the 48_4 partition
merge_partitions "$merged_partition3" "${result_48_4}/partition.txt" "${result_48_4}/partition.txt"
# Evaluate the merged partition
${BASE_DIR}/compositional_utils.py evaluate-partition \
--test-case-dir "$test_case_dir" \
--partition-file "$merged_partition3" \
--tech "$tech" \
--reach "$reach" \
--separation "$separation" \
--seed "$seed" | tee "${merge_dir3}/evaluation.log"
# Extract and store the cost
merged_cost3=$(extract_cost_from_log "${merge_dir3}/evaluation.log")
if [ -n "$merged_cost3" ]; then
echo "$merged_cost3" > "${merge_dir3}/objective_cost.txt"
else
echo -e "${YELLOW}Warning: Could not extract cost for 48_4 x2 strategy.${NC}"
merged_cost3="N/A"
fi
else
echo -e "${YELLOW}Warning: Partition results for 48_4 not found.${NC}"
fi
# Strategy 5: Merge one instance of 48_4 and two instances of 48_2
local merge_dir4="${eval_dir}/48_4_x1_48_2_x2"
mkdir -p "$merge_dir4"
local merged_partition4="${merge_dir4}/partition.txt"
local merged_cost4="N/A"
if [ -f "${result_48_4}/partition.txt" ] && [ -f "${result_48_2}/partition.txt" ]; then
# Merge one 48_4 and two 48_2 partitions
merge_partitions "$merged_partition4" "${result_48_4}/partition.txt" "${result_48_2}/partition.txt" "${result_48_2}/partition.txt"
# Evaluate the merged partition
${BASE_DIR}/compositional_utils.py evaluate-partition \
--test-case-dir "$test_case_dir" \
--partition-file "$merged_partition4" \
--tech "$tech" \
--reach "$reach" \
--separation "$separation" \
--seed "$seed" | tee "${merge_dir4}/evaluation.log"
# Extract and store the cost
merged_cost4=$(extract_cost_from_log "${merge_dir4}/evaluation.log")
if [ -n "$merged_cost4" ]; then
echo "$merged_cost4" > "${merge_dir4}/objective_cost.txt"
else
echo -e "${YELLOW}Warning: Could not extract cost for 48_4 x1 + 48_2 x2 strategy.${NC}"
merged_cost4="N/A"
fi
else
echo -e "${YELLOW}Warning: Partition results for 48_2 or 48_4 not found.${NC}"
fi
# Compare the strategies and select the best one
echo -e "${GREEN}Compositional evaluation for 48_8 completed.${NC}"
echo -e "${BLUE}Results:${NC}"
echo -e " Direct partitioning: ${direct_cost}"
# Get all costs
if [ -f "${merge_dir1}/objective_cost.txt" ]; then
merged_cost1=$(cat "${merge_dir1}/objective_cost.txt")
fi
echo -e " Merged 48_1 x8: ${merged_cost1}"
if [ -f "${merge_dir2}/objective_cost.txt" ]; then
merged_cost2=$(cat "${merge_dir2}/objective_cost.txt")
fi
echo -e " Merged 48_2 x4: ${merged_cost2}"
if [ -f "${merge_dir3}/objective_cost.txt" ]; then
merged_cost3=$(cat "${merge_dir3}/objective_cost.txt")
fi
echo -e " Merged 48_4 x2: ${merged_cost3}"
if [ -f "${merge_dir4}/objective_cost.txt" ]; then
merged_cost4=$(cat "${merge_dir4}/objective_cost.txt")
fi
echo -e " Merged 48_4 x1 + 48_2 x2: ${merged_cost4}"
# Find the best strategy
local best_cost="$direct_cost"
local best_strategy="direct"
local best_partition="${direct_result}/partition.txt"
if [ "$merged_cost1" != "N/A" ] && (( $(echo "$merged_cost1 < $best_cost" | bc -l) )); then
best_cost="$merged_cost1"
best_strategy="48_1_x8"
best_partition="$merged_partition1"
fi
if [ "$merged_cost2" != "N/A" ] && (( $(echo "$merged_cost2 < $best_cost" | bc -l) )); then
best_cost="$merged_cost2"
best_strategy="48_2_x4"
best_partition="$merged_partition2"
fi
if [ "$merged_cost3" != "N/A" ] && (( $(echo "$merged_cost3 < $best_cost" | bc -l) )); then
best_cost="$merged_cost3"
best_strategy="48_4_x2"
best_partition="$merged_partition3"
fi
if [ "$merged_cost4" != "N/A" ] && (( $(echo "$merged_cost4 < $best_cost" | bc -l) )); then
best_cost="$merged_cost4"
best_strategy="48_4_x1_48_2_x2"
best_partition="$merged_partition4"
fi
echo -e "${GREEN}The best strategy is: ${best_strategy} (Cost: ${best_cost})${NC}"
echo "$best_strategy" > "${eval_dir}/best_strategy.txt"
if [ -f "$best_partition" ]; then
cp "$best_partition" "${eval_dir}/best_partition.txt"
else
echo -e "${YELLOW}Warning: Best partition file not found.${NC}"
fi
echo -e "Compositional evaluation results saved to ${eval_dir}."
}
# Function to evaluate the composition of 48_16 test case
function compose_48_16 {
echo -e "${CYAN}Evaluating compositional strategies for 48_16_14_4_1600_1600...${NC}"
local reach=${1:-$DEFAULT_REACH}
local separation=${2:-$DEFAULT_SEPARATION}
local tech=${3:-$DEFAULT_TECH}
local seed=${4:-$DEFAULT_SEED}
# Create output directory for this evaluation
local eval_dir="${RESULTS_DIR}/48_16_evaluation"
mkdir -p "$eval_dir"
# Strategy 1: Direct partitioning of 48_16
local direct_result="${RESULTS_DIR}/48_16_14_4_1600_1600_direct"
local direct_cost="N/A"
if [ -f "${direct_result}/objective_cost.txt" ]; then
direct_cost=$(cat "${direct_result}/objective_cost.txt")
else
echo -e "${YELLOW}Warning: Direct partitioning results for 48_16 not found. Running direct partitioning...${NC}"
run_chiplet_part "48_16_14_4_1600_1600" "$direct_result" "$tech" "$reach" "$separation" "$seed"
if [ -f "${direct_result}/objective_cost.txt" ]; then
direct_cost=$(cat "${direct_result}/objective_cost.txt")
else
echo -e "${RED}Error: Failed to get direct partitioning cost for 48_16${NC}"
fi
fi
local test_case_dir="${TEST_DATA_DIR}/48_16_14_4_1600_1600"
local result_48_1="${RESULTS_DIR}/48_1_14_4_1600_1600_direct"
local result_48_2="${RESULTS_DIR}/48_2_14_4_1600_1600_direct"
local result_48_4="${RESULTS_DIR}/48_4_14_4_1600_1600_direct"
local result_48_8="${RESULTS_DIR}/48_8_14_4_1600_1600_direct"
# Array to store all strategy results
declare -A strategies
# Strategy 2: Merge sixteen instances of 48_1
if [ -f "${result_48_1}/partition.txt" ]; then
local merge_dir="${eval_dir}/48_1_x16"
mkdir -p "$merge_dir"
local merged_partition="${merge_dir}/partition.txt"
echo -e "${GREEN}Evaluating strategy: 48_1 x16${NC}"
merge_partitions "$merged_partition" \
"${result_48_1}/partition.txt" "${result_48_1}/partition.txt" \
"${result_48_1}/partition.txt" "${result_48_1}/partition.txt" \
"${result_48_1}/partition.txt" "${result_48_1}/partition.txt" \
"${result_48_1}/partition.txt" "${result_48_1}/partition.txt" \
"${result_48_1}/partition.txt" "${result_48_1}/partition.txt" \
"${result_48_1}/partition.txt" "${result_48_1}/partition.txt" \
"${result_48_1}/partition.txt" "${result_48_1}/partition.txt"
# Evaluate the merged partition
${BASE_DIR}/compositional_utils.py evaluate-partition \
--test-case-dir "$test_case_dir" \
--partition-file "$merged_partition" \
--tech "$tech" \
--reach "$reach" \
--separation "$separation" \
--seed "$seed" | tee "${merge_dir}/evaluation.log"
local cost=$(extract_cost_from_log "${merge_dir}/evaluation.log")
if [ -n "$cost" ]; then
echo "$cost" > "${merge_dir}/objective_cost.txt"
strategies["48_1_x16"]="$cost"
else
echo -e "${YELLOW}Warning: Could not extract cost for 48_1 x16 strategy.${NC}"
strategies["48_1_x16"]="N/A"
fi
else
echo -e "${YELLOW}Warning: Partition results for 48_1 not found.${NC}"
strategies["48_1_x16"]="N/A"
fi
# Strategy 3: Merge eight instances of 48_2
if [ -f "${result_48_2}/partition.txt" ]; then
local merge_dir="${eval_dir}/48_2_x8"
mkdir -p "$merge_dir"
local merged_partition="${merge_dir}/partition.txt"
echo -e "${GREEN}Evaluating strategy: 48_2 x8${NC}"
merge_partitions "$merged_partition" \
"${result_48_2}/partition.txt" "${result_48_2}/partition.txt" \
"${result_48_2}/partition.txt" "${result_48_2}/partition.txt" \
"${result_48_2}/partition.txt" "${result_48_2}/partition.txt" \
"${result_48_2}/partition.txt" "${result_48_2}/partition.txt"
# Evaluate the merged partition
${BASE_DIR}/compositional_utils.py evaluate-partition \
--test-case-dir "$test_case_dir" \
--partition-file "$merged_partition" \
--tech "$tech" \
--reach "$reach" \
--separation "$separation" \
--seed "$seed" | tee "${merge_dir}/evaluation.log"
local cost=$(extract_cost_from_log "${merge_dir}/evaluation.log")
if [ -n "$cost" ]; then
echo "$cost" > "${merge_dir}/objective_cost.txt"
strategies["48_2_x8"]="$cost"
else
echo -e "${YELLOW}Warning: Could not extract cost for 48_2 x8 strategy.${NC}"
strategies["48_2_x8"]="N/A"
fi
else
echo -e "${YELLOW}Warning: Partition results for 48_2 not found.${NC}"
strategies["48_2_x8"]="N/A"
fi
# Strategy 4: Merge four instances of 48_4
if [ -f "${result_48_4}/partition.txt" ]; then
local merge_dir="${eval_dir}/48_4_x4"
mkdir -p "$merge_dir"
local merged_partition="${merge_dir}/partition.txt"
echo -e "${GREEN}Evaluating strategy: 48_4 x4${NC}"
merge_partitions "$merged_partition" \
"${result_48_4}/partition.txt" "${result_48_4}/partition.txt" \
"${result_48_4}/partition.txt" "${result_48_4}/partition.txt"
# Evaluate the merged partition
${BASE_DIR}/compositional_utils.py evaluate-partition \
--test-case-dir "$test_case_dir" \
--partition-file "$merged_partition" \
--tech "$tech" \
--reach "$reach" \
--separation "$separation" \
--seed "$seed" | tee "${merge_dir}/evaluation.log"
local cost=$(extract_cost_from_log "${merge_dir}/evaluation.log")
if [ -n "$cost" ]; then
echo "$cost" > "${merge_dir}/objective_cost.txt"
strategies["48_4_x4"]="$cost"
else
echo -e "${YELLOW}Warning: Could not extract cost for 48_4 x4 strategy.${NC}"
strategies["48_4_x4"]="N/A"
fi
else
echo -e "${YELLOW}Warning: Partition results for 48_4 not found.${NC}"
strategies["48_4_x4"]="N/A"
fi
# Strategy 5: Merge two instances of 48_8
if [ -f "${result_48_8}/partition.txt" ]; then
local merge_dir="${eval_dir}/48_8_x2"
mkdir -p "$merge_dir"
local merged_partition="${merge_dir}/partition.txt"
echo -e "${GREEN}Evaluating strategy: 48_8 x2${NC}"
merge_partitions "$merged_partition" \
"${result_48_8}/partition.txt" "${result_48_8}/partition.txt"
# Evaluate the merged partition
${BASE_DIR}/compositional_utils.py evaluate-partition \
--test-case-dir "$test_case_dir" \
--partition-file "$merged_partition" \
--tech "$tech" \
--reach "$reach" \
--separation "$separation" \
--seed "$seed" | tee "${merge_dir}/evaluation.log"
local cost=$(extract_cost_from_log "${merge_dir}/evaluation.log")
if [ -n "$cost" ]; then
echo "$cost" > "${merge_dir}/objective_cost.txt"
strategies["48_8_x2"]="$cost"
else
echo -e "${YELLOW}Warning: Could not extract cost for 48_8 x2 strategy.${NC}"
strategies["48_8_x2"]="N/A"
fi
else
echo -e "${YELLOW}Warning: Partition results for 48_8 not found.${NC}"
strategies["48_8_x2"]="N/A"
fi
# Strategy 6: Merge one 48_8 and eight 48_1 instances
if [ -f "${result_48_8}/partition.txt" ] && [ -f "${result_48_1}/partition.txt" ]; then
local merge_dir="${eval_dir}/48_8_x1_48_1_x8"
mkdir -p "$merge_dir"
local merged_partition="${merge_dir}/partition.txt"
echo -e "${GREEN}Evaluating strategy: 48_8 x1 + 48_1 x8${NC}"
merge_partitions "$merged_partition" \
"${result_48_8}/partition.txt" \
"${result_48_1}/partition.txt" "${result_48_1}/partition.txt" \
"${result_48_1}/partition.txt" "${result_48_1}/partition.txt" \
"${result_48_1}/partition.txt" "${result_48_1}/partition.txt" \
"${result_48_1}/partition.txt" "${result_48_1}/partition.txt"
# Evaluate the merged partition
${BASE_DIR}/compositional_utils.py evaluate-partition \
--test-case-dir "$test_case_dir" \
--partition-file "$merged_partition" \
--tech "$tech" \
--reach "$reach" \
--separation "$separation" \
--seed "$seed" | tee "${merge_dir}/evaluation.log"
local cost=$(extract_cost_from_log "${merge_dir}/evaluation.log")
if [ -n "$cost" ]; then
echo "$cost" > "${merge_dir}/objective_cost.txt"
strategies["48_8_x1_48_1_x8"]="$cost"
else
echo -e "${YELLOW}Warning: Could not extract cost for 48_8 x1 + 48_1 x8 strategy.${NC}"
strategies["48_8_x1_48_1_x8"]="N/A"
fi
else
echo -e "${YELLOW}Warning: Partition results for 48_8 or 48_1 not found.${NC}"
strategies["48_8_x1_48_1_x8"]="N/A"
fi
# Strategy 7: Merge one 48_8, one 48_4, and two 48_2 instances
if [ -f "${result_48_8}/partition.txt" ] && [ -f "${result_48_4}/partition.txt" ] && [ -f "${result_48_2}/partition.txt" ]; then
local merge_dir="${eval_dir}/48_8_x1_48_4_x1_48_2_x2"
mkdir -p "$merge_dir"
local merged_partition="${merge_dir}/partition.txt"
echo -e "${GREEN}Evaluating strategy: 48_8 x1 + 48_4 x1 + 48_2 x2${NC}"
merge_partitions "$merged_partition" \
"${result_48_8}/partition.txt" \
"${result_48_4}/partition.txt" \
"${result_48_2}/partition.txt" "${result_48_2}/partition.txt"
# Evaluate the merged partition
${BASE_DIR}/compositional_utils.py evaluate-partition \
--test-case-dir "$test_case_dir" \
--partition-file "$merged_partition" \
--tech "$tech" \
--reach "$reach" \
--separation "$separation" \
--seed "$seed" | tee "${merge_dir}/evaluation.log"
local cost=$(extract_cost_from_log "${merge_dir}/evaluation.log")
if [ -n "$cost" ]; then
echo "$cost" > "${merge_dir}/objective_cost.txt"
strategies["48_8_x1_48_4_x1_48_2_x2"]="$cost"
else
echo -e "${YELLOW}Warning: Could not extract cost for 48_8 x1 + 48_4 x1 + 48_2 x2 strategy.${NC}"
strategies["48_8_x1_48_4_x1_48_2_x2"]="N/A"
fi
else
echo -e "${YELLOW}Warning: Partition results for 48_8, 48_4, or 48_2 not found.${NC}"
strategies["48_8_x1_48_4_x1_48_2_x2"]="N/A"
fi
# Strategy 8: Merge two 48_4 and eight 48_1 instances
if [ -f "${result_48_4}/partition.txt" ] && [ -f "${result_48_1}/partition.txt" ]; then
local merge_dir="${eval_dir}/48_4_x2_48_1_x8"
mkdir -p "$merge_dir"
local merged_partition="${merge_dir}/partition.txt"
echo -e "${GREEN}Evaluating strategy: 48_4 x2 + 48_1 x8${NC}"
merge_partitions "$merged_partition" \