Skip to content

Commit b09b317

Browse files
committed
support multiple L3 caches
1 parent 372b4bb commit b09b317

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

core/utils/cpu.py

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,13 @@ def create_cpu_topology_visualization(p_cores, e_cores, cache_structure):
399399
l3_color = '#8C8544' # Lighter gold
400400
text_color = '#E0E0E0' # Light gray for text
401401

402-
# Rest of the dimensions remain the same
403402
core_width = 0.8
404403
core_height = 0.8
405404
core_gap = 0.4
406405
x_spacing = core_width + core_gap
407406
y_spacing = 1.0
407+
l3_height = 0.8
408+
l3_spacing = 0.8
408409

409410
# Calculate layout dimensions
410411
p_cores_per_row = len(p_cores) // 2
@@ -418,6 +419,15 @@ def create_cpu_topology_visualization(p_cores, e_cores, cache_structure):
418419
e_section_start = p_cores_width + x_spacing
419420
total_width = p_cores_width + ((e_cores_width + x_spacing) if e_cores else 0)
420421

422+
# First, determine which rows have L3 caches
423+
l3_caches = [cache for cache in cache_structure if cache['level'] == 3]
424+
rows_with_l3 = set()
425+
for l3_cache in l3_caches:
426+
shared_cores = sorted(l3_cache['cores'])
427+
row = min(shared_cores) // p_cores_per_row
428+
rows_with_l3.add(row)
429+
430+
421431
def format_size(size):
422432
if size >= 1024 * 1024:
423433
return f"{size / (1024 * 1024):.0f}M"
@@ -434,8 +444,16 @@ def format_size(size):
434444

435445
# Draw P-cores
436446
for i, core in enumerate(sorted(p_cores)):
447+
row = i // p_cores_per_row
437448
x = (i % p_cores_per_row) * x_spacing
438-
y = (i // p_cores_per_row) * y_spacing * 3
449+
450+
# Calculate y position based on whether previous rows had L3 caches
451+
y = 0
452+
for prev_row in range(row):
453+
if prev_row in rows_with_l3:
454+
y += y_spacing * 3 + l3_spacing
455+
else:
456+
y += y_spacing * 3
439457
rect = patches.Rectangle((x, y), core_width, core_height, facecolor=p_core_color, edgecolor='white',
440458
linewidth=0.5)
441459
ax.add_patch(rect)
@@ -468,8 +486,16 @@ def format_size(size):
468486

469487
# Draw E-cores
470488
for i, core in enumerate(sorted(e_cores)):
489+
row = i // e_cores_per_row
471490
x = (i % e_cores_per_row) * x_spacing + e_section_start
472-
y = (i // e_cores_per_row) * y_spacing * 3
491+
492+
# Calculate y position based on whether previous rows had L3 caches
493+
y = 0
494+
for prev_row in range(row):
495+
if prev_row in rows_with_l3:
496+
y += y_spacing * 3 + l3_spacing
497+
else:
498+
y += y_spacing * 3
473499
rect = patches.Rectangle((x, y), core_width, core_height,
474500
facecolor=e_core_color, edgecolor='white', linewidth=0.5)
475501
ax.add_patch(rect)
@@ -502,12 +528,22 @@ def format_size(size):
502528
break
503529

504530
# Draw L3 cache
505-
l3_caches = [cache for cache in cache_structure if cache['level'] == 3]
506531
for l3_cache in l3_caches:
507-
# Find the leftmost and rightmost cores that share this L3
508532
shared_cores = sorted(l3_cache['cores'])
509533
leftmost_core = min(shared_cores)
510534
rightmost_core = max(shared_cores)
535+
row = leftmost_core // p_cores_per_row
536+
537+
# Calculate y position for L3 cache
538+
y_position = (row * y_spacing * 3) - 2.0
539+
540+
for prev_row in range(row + 1):
541+
if prev_row < row:
542+
if prev_row in rows_with_l3:
543+
y_position += y_spacing * 3 + l3_spacing
544+
else:
545+
y_position += y_spacing * 3
546+
y_position -= l3_spacing # Position it below the current row's cores
511547

512548
# Calculate the x-coordinates for this L3 section
513549
if leftmost_core in p_cores:
@@ -532,11 +568,11 @@ def format_size(size):
532568

533569
l3_width = end_x - start_x + core_width
534570

535-
# Draw this L3 section
536-
l3 = patches.Rectangle((start_x, -3), l3_width, 0.8,
571+
# Draw this L3 section at the correct y-position
572+
l3 = patches.Rectangle((start_x, y_position), l3_width, l3_height,
537573
facecolor=l3_color, edgecolor='white', linewidth=0.5)
538574
ax.add_patch(l3)
539-
ax.text(start_x + l3_width / 2, -2.6,
575+
ax.text(start_x + l3_width / 2, y_position + l3_height / 2,
540576
f"L3 {format_size(l3_cache['size'])} (Cores {min(shared_cores)}-{max(shared_cores)})",
541577
ha='center', va='center', color=text_color)
542578

0 commit comments

Comments
 (0)