SIMD 延迟吞吐量

SIMD latency throughput

在大多数指令的 Intel Intrisics Guide 上,它还具有延迟和吞吐量的值。示例:

__m128i _mm_min_epi32

Performance
Architecture Latency Throughput
Haswell      1       0.5
Ivy Bridge   1       0.5
Sandy Bridge 1       0.5
Westmere     1       1
Nehalem      1       1

这些数字到底是什么意思?我想较慢的延迟意味着命令需要更长的时间来执行,但是 Nehalem 的吞吐量 1 和 Ivy 的 0.5 意味着命令在 Nehalem 上更快?

一条指令的"latency"是执行一条指令需要多少个时钟周期(结果准备好让相关指令将其用作输入需要多长时间)。如果你有一个循环携带的依赖链,你可以把操作的延迟加起来找到关键路径的长度。

如果你在每个循环迭代中都有独立的工作,乱序执行可以重叠它。该链的长度(以延迟周期为单位)告诉您 OoO exec 必须付出多少努力才能重叠该依赖链的多个实例。


通常吞吐量是每个时钟周期的指令数,但这实际上是 相互吞吐量:每个独立指令启动的时钟周期数 - 所以 0.5 个时钟周期意味着 2指令可以在一个时钟周期发出,结果在下一个时钟周期就绪。

请注意,执行单元是流水线化的,除了除法器之外的所有执行单元都是完全流水线化的(每个时钟周期开始一条新指令)。延迟与吞吐量是分开的(independent 操作可以启动的频率)。许多指令是单 uop,因此它们的吞吐量通常是 1/n,其中 n 是一个小整数(具有可以 运行 该指令的执行单元的端口数)。

英特尔在此处记录: https://software.intel.com/en-us/articles/measuring-instruction-latency-and-throughput


要了解两个不同指令是否相互竞争相同的吞吐量资源,您需要查阅更详细的指南。例如,https://agner.org/optimize/ 有指令表和微架构指南。这些详细介绍了执行端口,并将指令分解为三个重要的维度:以微指令为单位的前端成本、后端端口和延迟。

例如,_mm_shuffle_epi8_mm_cvtsi32_si128 都 运行 在大多数 Intel CPU 的端口 5 上,因此竞争相同的 1/clock 吞吐量。但是 _mm_add_epi32 运行s 在 Haswell 的端口 1 或端口 5 上,因此它的 0.5c 吞吐量仅部分与随机播放竞争。

https://uops.info/ 有非常详细的自动化测试指令表,包括从每个输入到输出的延迟。

Agner Fog 的表格很好(紧凑且可读),但有时会有错别字或错误,而且只有一个延迟数字,您并不总是知道哪个输入构成了 dep 链。

另见 What considerations go into predicting latency for operations on modern superscalar processors and how can I calculate them by hand?

以下引用自英特尔页面Measuring Instruction Latency and Throughput

Latency and Throughput

Latency is the number of processor clocks it takes for an instruction to have its data available for use by another instruction. Therefore, an instruction which has a latency of 6 clocks will have its data available for another instruction that many clocks after it starts its execution.

Throughput is the number of processor clocks it takes for an instruction to execute or perform its calculations. An instruction with a throughput of 2 clocks would tie up its execution unit for that many cycles which prevents an instruction needing that execution unit from being executed. Only after the instruction is done with the execution unit can the next instruction enter.