报告修改完成

This commit is contained in:
LYC 2024-10-30 17:42:18 +08:00
parent 79bef93cab
commit 219211ddee
27 changed files with 179 additions and 92 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 26 KiB

83
cache/Project1/Proj1-2/Proj1-2/src/t.py vendored Normal file
View File

@ -0,0 +1,83 @@
import subprocess
import matplotlib.pyplot as plt
import warnings
import numpy as np
import itertools
# 忽略警告
warnings.filterwarnings("ignore")
def run_simulator(L1_SIZE, L2_SIZE=4096, BLOCKSIZE=32, L1_ASSOC=2, L2_ASSOC=4, Victim_Cache_SIZE=1024, trace_file="perl_trace.txt"):
cmd = ["./sim_cache", str(BLOCKSIZE), str(L1_SIZE), str(L2_SIZE), str(L1_ASSOC), str(L2_ASSOC), str(Victim_Cache_SIZE), trace_file]
try:
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode('utf-8')
return output
except subprocess.CalledProcessError as e:
print(f"Command failed with error: {e.output.decode('utf-8')}")
raise
def parse_output(output):
lines = output.split('\n')
results = {}
for line in lines:
if "average access time:" in line:
results['AAT'] = float(line.split()[-2])
return results
# 定义参数范围
L1_SIZES = [1024,2048,4096,8192,16384,32768,65536]
L2_SIZES = [4096,8192,16384,32768,65536]
BLOCKSIZES = [64,128,256,512] # 增加 BLOCKSIZE
L1_ASSOCS = [2,4]
L2_ASSOCS = [2,4]
VICTIM_CACHE_SIZES = [1024,2048,4096] # 增加 Victim Cache Size
# 存储结果
results = []
# 遍历所有参数组合
for L1_SIZE, L2_SIZE, BLOCKSIZE, L1_ASSOC, L2_ASSOC, Victim_Cache_SIZE in itertools.product(
L1_SIZES, L2_SIZES, BLOCKSIZES, L1_ASSOCS, L2_ASSOCS, VICTIM_CACHE_SIZES):
try:
output = run_simulator(L1_SIZE, L2_SIZE=L2_SIZE, BLOCKSIZE=BLOCKSIZE,
L1_ASSOC=L1_ASSOC, L2_ASSOC=L2_ASSOC,
Victim_Cache_SIZE=Victim_Cache_SIZE)
parsed_results = parse_output(output)
# 记录结果
results.append({
'params': (L1_SIZE, L2_SIZE, BLOCKSIZE, L1_ASSOC, L2_ASSOC, Victim_Cache_SIZE),
'AAT': parsed_results['AAT']
})
except Exception as e:
print(f"Error processing parameters L1_SIZE={L1_SIZE}, L2_SIZE={L2_SIZE}, BLOCKSIZE={BLOCKSIZE}, "
f"L1_ASSOC={L1_ASSOC}, L2_ASSOC={L2_ASSOC}, Victim_Cache_SIZE={Victim_Cache_SIZE}: {e}")
# 提取数据以绘制图表
AAT_values = [result['AAT'] for result in results]
param_combinations = [result['params'] for result in results]
# 可视化
plt.figure(figsize=(12, 8))
plt.scatter(range(len(AAT_values)), AAT_values, marker='o', color='blue', alpha=0.6)
plt.title('Average Access Time (AAT) vs Parameter Combinations')
plt.xlabel('Parameter Combinations Index')
plt.ylabel('Average Access Time (AAT)')
plt.grid()
# 添加最佳 AAT 标记
best_result = min(results, key=lambda x: x['AAT'])
best_AAT = best_result['AAT']
best_index = results.index(best_result)
plt.scatter(best_index, best_AAT, color='red', label='Best AAT', s=100, edgecolor='black')
plt.legend()
# 保存图像
plt.savefig('aat_vs_param_combinations.png', bbox_inches='tight')
plt.close() # 关闭图形以释放内存
# 输出最佳参数组合
print(f"最佳 AAT: {best_AAT}")
print(f"最佳参数组合: {best_result['params']}")

View File

@ -6,7 +6,7 @@ import numpy as np
# 忽略警告
warnings.filterwarnings("ignore")
def run_simulator(BLOCKSIZE,L2_SIZE=4096,L1_ASSOC=2, L1_SIZE=1024, L2_ASSOC=4, Victim_Cache_SIZE=1024, trace_file="gcc_trace.txt"):
def run_simulator(L1_SIZE,L2_SIZE=4096, BLOCKSIZE=32,L1_ASSOC=2, L2_ASSOC=4, Victim_Cache_SIZE=1024, trace_file="gcc_trace.txt"):
cmd = ["./sim_cache", str(BLOCKSIZE), str(L1_SIZE), str(L2_SIZE), str(L1_ASSOC), str(L2_ASSOC), str(Victim_Cache_SIZE), trace_file]
try:
@ -21,7 +21,7 @@ def parse_output(output):
results = {}
for line in lines:
if "L1 miss rate:" in line:
results['L1_miss_rate'] = float(line.split()[-1])
results['AAT'] = float(line.split()[-1])
elif "L2 miss rate:" in line:
results['L2_miss_rate'] = float(line.split()[-1])
elif "average access time:" in line:
@ -29,8 +29,8 @@ def parse_output(output):
return results
# Define L1_SIZE values to simulate
data = [2,4,8,16,32,64, 128, 256, 512, 1024]
# data = [2,4,8,16,32,64, 128, 256, 512, 1024]
data = [128, 256, 512, 1024,2048,4096,8192,16384,32678]
# Run simulations and collect results
results = {}
for item in data:
@ -42,15 +42,15 @@ for item in data:
print(f"Error processing L2_SIZE {item}: {e}")
# 准备数据用于可视化
l1_miss_rates = [results[size]['L1_miss_rate'] for size in data if size in results]
l1_miss_rates = [results[size]['AAT'] for size in data if size in results]
l1_sizes_kb = [size for size in data if size in results]
# 可视化
plt.figure(figsize=(10, 6))
plt.plot(l1_sizes_kb, l1_miss_rates, marker='o')
plt.title('L1 Miss Rate vs Block')
plt.xlabel('L1 Cache Size (KB)')
plt.ylabel('L1 Miss Rate')
plt.title('AAT vs L1')
plt.xlabel('L1')
plt.ylabel('AAT')
plt.grid()
# 设置均匀的 X 轴坐标

View File

@ -1,67 +1,86 @@
\section{实验分析}
\subsection{Miss Rate}
\begin{figure}[htbp]
\begin{figure}[!htbp]
\centering
\begin{minipage}{0.4\linewidth}
\begin{minipage}{0.3\linewidth}
\includegraphics[width=\linewidth]{L1Miss.png}
\caption{L1 Miss vs Size}
\end{minipage}
\begin{minipage}{0.4\linewidth}
\hfill
\begin{minipage}{0.3\linewidth}
\includegraphics[width=\linewidth]{block.png}
\caption{L1 Miss vs Block Size}
\end{minipage}
\begin{minipage}{0.6\linewidth}
\hfill
\begin{minipage}{0.3\linewidth}
\includegraphics[width=\linewidth]{assoc.png}
\caption{L1 Miss vs Associativity}
\end{minipage}
\end{figure}
\begin{itemize}
\item 当 L1 缓存大小增加时L1MissRate 平均值呈现下降趋势,更大的缓存大小通常意味着更低的缺失率。
\item 对于给定的数据,块大小似乎并没有对 L1MissRate 产生显著的影响。这可能是因为块大小的选择需要与其他参数,如缓存大小和 associativity相匹配才能获得最佳性能。
\item L1 Associativity 值与 L1MissRate 之间的关系似乎并不明确。这可能是因为其他参数的变化对缺失率产生了影响,使得 associativity 的影响不太明显。通常,增加 associativity 可以减少缺失率,但如果其他参数不合适,这种效果可能会受到抵消。
\item 随着 L1 缓存大小的增加L1 Miss Rate 的平均值呈现下降趋势,通常较大的缓存意味着更低的缺失率。
\item 为了实现最佳性能,块大小必须与缓存大小和关联度等其他参数相协调。一般来说,命中率会随着块大小的变化而先上升后下降。
\item L1 关联度值与 L1 Miss Rate 之间的关系受到其他参数变化的影响,因此缺失率在一定范围内波动。通常,增加关联度可以降低缺失率,但在不合适的参数配置下,这种效果会减弱,导致缺失率在增加过程中上下波动。
\end{itemize}
\subsection{AAT}
\begin{itemize}
\item 增大 L1 Cache Size 或 L1 ASSOC 通常可以降低 AAT。这可能是因为增大这些参数可以增加缓存的容量和关联性从而降低缺失率和增加缓存命中率。
\item 与 L1 缓存类似,增大 L2 SIZE 或 L2 ASSOC 也可以降低 AAT。但是L2 缓存的影响可能不如 L1 缓存明显,因为 L2 缓存通常在 L1 缓存缺失时才被访问。
\end{itemize}
\begin{figure}[!htbp]
\centering
\subfmacro{blocksize_comparison}{Block Size}{.47}
\subfmacro{victim_comparison_sorted}{Victim Size}{.47}
\caption{AAT}\label{fig:aatBs}
\begin{minipage}{0.32\linewidth}
\includegraphics[width=\linewidth]{L1.png}
\caption{AAT vs L1}
\end{minipage}
\hfill
\begin{minipage}{0.32\linewidth}
\includegraphics[width=\linewidth]{block.png}
\caption{AAT vs Block Size}
\end{minipage}
\hfill
\begin{minipage}{0.32\linewidth}
\includegraphics[width=\linewidth]{L2.png}
\caption{AAT vs L2}
\end{minipage}
\end{figure}
\begin{itemize}
\item 对于所有三个 trace file随着 BLOCKSIZE 的增加AAT 似乎都有所减少,尤其在较小的 BLOCKSIZE 值时下降得较为明显。这可能是因为增大 BLOCKSIZE 可以提高空间局部性从而增加缓存命中率。但是BLOCKSIZE 过大可能会导致缓存行里的一些数据没有被利用,从而浪费缓存空间。对于 \verb|go_trace.txt|,在 BLOCKSIZE 较大时AAT 的减少不如其他两个明显,这可能是因为这个工作负载与其他两个有所不同。
\item 对于所有三个 trace file当 Victim Cache SIZE 为 512 时AAT 值都是最高的。这可能是因为该大小不适合这些特定的工作负载,或者这个大小的 Victim Cache 在逐出数据时可能不够有效。
随着 Victim Cache SIZE 的增加(从 512 开始AAT 明显降低。这表明,增大 Victim Cache 的大小可以提高其效率,从而降低 AAT。当 Victim Cache SIZE 达到一定值后,例如 32 或 64AAT 的下降趋势放缓,表明在这些值之后,进一步增加 Victim Cache 的大小可能不会带来显著的性能提升。
\item 增加 L1 缓存大小或 L1 关联度通常能降低平均访问时间AAT。这可能是因为这些参数的增大提高了缓存的容量和关联性从而降低了缺失率并提升了命中率。
\item 类似于 L1 缓存,增大 L2 缓存大小或 L2 关联度也有助于降低 AAT。不过L2 缓存的影响可能不如 L1 缓存明显,因为 L2 缓存通常只有在 L1 缓存发生缺失时才会被访问。
\end{itemize}
\subsection{最优参数组合}
\subsection{最优参数}
\begin{figure}[!htbp]
\centering
\begin{minipage}{0.32\linewidth}
\includegraphics[width=\linewidth]{R1.png}
\caption{gcc}
\end{minipage}
\hfill
\begin{minipage}{0.32\linewidth}
\includegraphics[width=\linewidth]{R2.png}
\caption{go}
\end{minipage}
\hfill
\begin{minipage}{0.32\linewidth}
\includegraphics[width=\linewidth]{R3.png}
\caption{perl}
\end{minipage}
\end{figure}
\begin{table}[!htbp]
\centering
\caption{最优参数组合}\label{tab:res2}
\caption{搜索结果}\label{tab:res2}
\begin{tabular}{cccccc}
\hline
Trace & L1 & L2 & blocksize & victim size & Best AAT \\
\hline
gcc & 8192, 2 & 65536, 8 & 128 & 4096 & 0.8182 \\
go & 2048, 2 & 65536, 2 & 128 & 2048 & 0.8466 \\
gcc & 8192, 2 & 65536, 4 & 128 & 4096 & 0.8186 \\
go & 1024, 2 & 65536, 2 & 128 & 4096 & 0.8415 \\
perl & 8192, 2 & 65536, 2 & 64 & 4096 & 0.6714 \\
\hline
\end{tabular}

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 KiB

View File

@ -6,15 +6,17 @@
\newlabel{fig:result.png}{{1}{1}}
\@writefile{toc}{\contentsline {section}{\numberline {3}实验分析}{1}{}\protected@file@percent }
\@writefile{toc}{\contentsline {subsection}{\numberline {3.1}Miss Rate}{1}{}\protected@file@percent }
\@writefile{toc}{\contentsline {subsection}{\numberline {3.2}AAT}{1}{}\protected@file@percent }
\@writefile{lof}{\contentsline {figure}{\numberline {2}{\ignorespaces L1 Miss vs Size}}{2}{}\protected@file@percent }
\@writefile{lof}{\contentsline {figure}{\numberline {3}{\ignorespaces L1 Miss vs Block Size}}{2}{}\protected@file@percent }
\@writefile{lof}{\contentsline {figure}{\numberline {4}{\ignorespaces L1 Miss vs Associativity}}{2}{}\protected@file@percent }
\@writefile{lof}{\contentsline {figure}{\numberline {5}{\ignorespaces AAT}}{2}{}\protected@file@percent }
\@writefile{lof}{\contentsline {subfigure}{\numberline{(a)}{\ignorespaces {Block Size}}}{2}{}\protected@file@percent }
\@writefile{lof}{\contentsline {subfigure}{\numberline{(b)}{\ignorespaces {Victim Size}}}{2}{}\protected@file@percent }
\newlabel{fig:aatBs}{{5}{2}}
\@writefile{toc}{\contentsline {subsection}{\numberline {3.3}最优参数组合}{3}{}\protected@file@percent }
\@writefile{lot}{\contentsline {table}{\numberline {1}{\ignorespaces 最优参数组合}}{3}{}\protected@file@percent }
\newlabel{tab:res2}{{1}{3}}
\gdef \@abspage@last{5}
\@writefile{lof}{\contentsline {figure}{\numberline {2}{\ignorespaces L1 Miss vs Size}}{1}{}\protected@file@percent }
\@writefile{lof}{\contentsline {figure}{\numberline {3}{\ignorespaces L1 Miss vs Block Size}}{1}{}\protected@file@percent }
\@writefile{lof}{\contentsline {figure}{\numberline {4}{\ignorespaces L1 Miss vs Associativity}}{1}{}\protected@file@percent }
\@writefile{toc}{\contentsline {subsection}{\numberline {3.2}AAT}{2}{}\protected@file@percent }
\@writefile{lof}{\contentsline {figure}{\numberline {5}{\ignorespaces AAT vs L1}}{2}{}\protected@file@percent }
\@writefile{lof}{\contentsline {figure}{\numberline {6}{\ignorespaces AAT vs Block Size}}{2}{}\protected@file@percent }
\@writefile{lof}{\contentsline {figure}{\numberline {7}{\ignorespaces AAT vs L2}}{2}{}\protected@file@percent }
\@writefile{toc}{\contentsline {subsection}{\numberline {3.3}最优参数}{2}{}\protected@file@percent }
\@writefile{lof}{\contentsline {figure}{\numberline {8}{\ignorespaces gcc}}{2}{}\protected@file@percent }
\@writefile{lof}{\contentsline {figure}{\numberline {9}{\ignorespaces go}}{2}{}\protected@file@percent }
\@writefile{lof}{\contentsline {figure}{\numberline {10}{\ignorespaces perl}}{2}{}\protected@file@percent }
\@writefile{lot}{\contentsline {table}{\numberline {1}{\ignorespaces 搜索结果}}{2}{}\protected@file@percent }
\newlabel{tab:res2}{{1}{2}}
\gdef \@abspage@last{4}

View File

@ -1,4 +1,4 @@
This is XeTeX, Version 3.141592653-2.6-0.999993 (TeX Live 2022/dev/Debian) (preloaded format=xelatex 2024.10.30) 30 OCT 2024 15:41
This is XeTeX, Version 3.141592653-2.6-0.999993 (TeX Live 2022/dev/Debian) (preloaded format=xelatex 2024.10.30) 30 OCT 2024 17:39
entering extended mode
restricted \write18 enabled.
%&-line parsing enabled.
@ -673,27 +673,19 @@ Package fancyhdr Warning: \headheight is too small (12.0pt):
(fancyhdr) \addtolength{\topmargin}{-0.64723pt}.
[1]
File: figures//blocksize_comparison.pdf Graphic file (type pdf)
<use figures//blocksize_comparison.pdf>
File: figures//victim_comparison_sorted.pdf Graphic file (type pdf)
<use figures//victim_comparison_sorted.pdf>
Package fontspec Warning: Font "FandolFang-Regular" does not contain requested
(fontspec) Script "CJK".
Package fontspec Info: Font family 'FandolFang-Regular(0)' created for font
(fontspec) 'FandolFang-Regular' with options
(fontspec) [Script={CJK},Extension={.otf}].
(fontspec)
(fontspec) This font family consists of the following NFSS
(fontspec) series/shapes:
(fontspec)
(fontspec) - 'normal' (m/n) with NFSS spec.:
(fontspec) <->"[FandolFang-Regular.otf]/OT:language=dflt;"
(fontspec) - 'small caps' (m/sc) with NFSS spec.:
File: figures//L1.png Graphic file (type bmp)
<figures//L1.png>
File: figures//block.png Graphic file (type bmp)
<figures//block.png>
File: figures//L2.png Graphic file (type bmp)
<figures//L2.png>
File: figures//R1.png Graphic file (type bmp)
<figures//R1.png>
File: figures//R2.png Graphic file (type bmp)
<figures//R2.png>
File: figures//R3.png Graphic file (type bmp)
<figures//R3.png>
)
Package fancyhdr Warning: \headheight is too small (12.0pt):
(fancyhdr) Make it at least 12.64723pt, for example:
@ -702,28 +694,19 @@ Package fancyhdr Warning: \headheight is too small (12.0pt):
(fancyhdr) \addtolength{\topmargin}{-0.64723pt}.
[2])
Package fancyhdr Warning: \headheight is too small (12.0pt):
(fancyhdr) Make it at least 12.64723pt, for example:
(fancyhdr) \setlength{\headheight}{12.64723pt}.
(fancyhdr) You might also make \topmargin smaller to compensate:
(fancyhdr) \addtolength{\topmargin}{-0.64723pt}.
[3] (./main.aux)
[2] (./main.aux)
LaTeX Font Warning: Size substitutions with differences
(Font) up to 0.65625pt have occurred.
)
Here is how much of TeX's memory you used:
12999 strings out of 477756
304834 string characters out of 5843517
644734 words of memory out of 5000000
33431 multiletter control sequences out of 15000+600000
476154 words of font info for 79 fonts, out of 8000000 for 9000
13016 strings out of 477756
305127 string characters out of 5843517
641726 words of memory out of 5000000
33449 multiletter control sequences out of 15000+600000
476122 words of font info for 75 fonts, out of 8000000 for 9000
264 hyphenation exceptions out of 8191
103i,11n,111p,1195b,439s stack positions out of 5000i,500n,10000p,200000b,80000s
103i,11n,111p,1195b,422s stack positions out of 5000i,500n,10000p,200000b,80000s
Output written on main.pdf (5 pages).
Output written on main.pdf (4 pages).

View File

@ -2,5 +2,5 @@
\contentsline {section}{\numberline {2}实验结果}{1}{}%
\contentsline {section}{\numberline {3}实验分析}{1}{}%
\contentsline {subsection}{\numberline {3.1}Miss Rate}{1}{}%
\contentsline {subsection}{\numberline {3.2}AAT}{1}{}%
\contentsline {subsection}{\numberline {3.3}最优参数组合}{3}{}%
\contentsline {subsection}{\numberline {3.2}AAT}{2}{}%
\contentsline {subsection}{\numberline {3.3}最优参数}{2}{}%