- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我估算英特尔 CPU 的最大 FLOPs/s 的公式是
Max SP FLOPs/s = frequencey * 4 SSE(8AVX) * 2 (MAC) * number of cores (not HW threads)
Max DP FLOPs/s = 0.5 * Max SP FLOPs/s
我所说的 MAC 是指 CPU 可以同时执行一个 SSE(AVX) 乘法和加法。在我使用的系统上,负载下的最大频率是 2.66 GHz。它只有 SSE,核心数(不是硬件线程)为 4。这给出了:Max SP FLOPs/s = 85.12 GFLOPs/s。
矩阵乘法的 FLOP 数约为 2*n*m*k
。对于 n=1000 的方阵,它是 2*10E9 FLOPs(20 亿 FLOPs)。一旦我知道时间,我就可以估计 FLOPs/s。
但是,对于我自己的代码,我能得到的最好结果是大约 40 SP GFLOPs/s,例如 n=1000。我得到与 Eigen 大致相同的结果。这大约是 45% 的效率。我对最大值的计算是错误的吗?对于大型密集矩阵乘法,英特尔 CPU 的最佳效率是多少?有人有描述这个的论文吗?
我知道在GPU上效率可以超过60%。 http://www.anandtech.com/show/6774/nvidias-geforce-gtx-titan-part-2-titans-performance-unveiled/3
编辑:对于 n=500,我得到了类似的结果,它很容易适合我系统的 12MB L3 缓存,因此缓存似乎不是限制因素(尽管也许我可以更有效地使用它)。
编辑2:Eigen Benchmarks 表明它与 MKL(对于 SSE)一样好。他们使用 Intel(R) Core(TM)2 Quad CPU Q9400 @ 2.66GHz。所以 2.66* 2(DP SSE) *2 MAC * 4 核 = 42.25 DP GFLOPs/s。你可以在图中看到他们都不到 20。像我这样大约有 45% 的人。 http://eigen.tuxfamily.org/index.php?title=Benchmark
http://ark.intel.com/products/35365/Intel-Core2-Quad-Processor-Q9400-6M-Cache-2_66-GHz-1333-MHz-FSB
编辑3:这是我为任何关心的人编写的代码。我可以得到比这稍微好一点的结果,但也好不了多少。我正在为 SEE/AVX 使用 Agner Fog 的矢量类。并将 Vec8f 设置为 float8,将 Vec4d 设置为 double4
//SGEMM and AVX call MM_tile<float, float8>(nthreads, a, b, c, n, m, k);
template <typename ftype, typename floatn>
void GEMM_tile(const int nthreads, const ftype*A , const ftype* B, ftype* C, const int N, const int M, const int K) {
for(int i=0; i<N; i++) {
for(int j=0; j<K; j++) {
C[K*i + j] = 0;
}
}
const int nc = 32;
const int kc = 32;
const int mc = 32;
omp_set_num_threads(nthreads);
#pragma omp parallel for if(nthreads>1)
for(int ii=0; ii<N; ii+=nc) {
for(int jj=0; jj<K; jj+=kc)
for(int ll=0; ll<M; ll+=mc) {
const int nb = min(N-ii, nc);
const int kb = min(K-jj, kc);
const int mb = min(M-ll, mc);
MM_block<ftype, floatn>(nb, mb, kb, &A[M*ii+ll], N, &B[K*ll+jj], K, &C[K*ii+jj], K );
}
}
}
template <typename ftype, typename floatn>
void MM_block(int n, int m, int k, const ftype *a, const int stridea,
const ftype *b, const int strideb,
ftype *c, const int stridec ) {
const int vec_size = sizeof(floatn)/sizeof(ftype);
for(int i=0; i<n; i+=4) {
for(int j=0; j<k; j+=vec_size) {
Dot4x4_vec_block<ftype, floatn>(m, &a[strideb*i], &b[j], &c[stridec*i + j], stridea, strideb, stridec);
}
}
template <typename ftype, typename floatn>
inline void Dot4x4_vec_block(const int n, const ftype *a, const ftype *b, ftype *c, const int stridea, const int strideb, const int stridec) {
floatn tmp0, tmp1, tmp2, tmp3;
load(tmp0, &c[stridec*0]);
load(tmp1, &c[stridec*1]);
load(tmp2, &c[stridec*2]);
load(tmp3, &c[stridec*3]);
ftype *a0_ptr = (ftype*)&a[stridea*0];
ftype *a1_ptr = (ftype*)&a[stridea*1];
ftype *a2_ptr = (ftype*)&a[stridea*2];
ftype *a3_ptr = (ftype*)&a[stridea*3];
for(int i=0; i<n; i++) {
floatn breg = floatn().load(&b[i*strideb + 0]);
floatn areg0 = *a0_ptr++;
floatn areg1 = *a1_ptr++;
floatn areg2 = *a2_ptr++;
floatn areg3 = *a3_ptr++;
tmp0 += areg0 * breg;
tmp1 += areg1 * breg;
tmp2 += areg2 * breg;
tmp3 += areg3 * breg;
}
tmp0.store(&c[stridec*0]);
tmp1.store(&c[stridec*1]);
tmp2.store(&c[stridec*2]);
tmp3.store(&c[stridec*3]);
}
最佳答案
通常,处理吞吐量的限制因素是内存带宽,尤其是在您的工作集不适合 CPU 缓存的情况下(float
的 1000×1000 矩阵将占用~4 MB,而您的 CPU 可能有 2 MB L3 缓存)。在这种情况下,您的算法结构可能会对其执行方式产生很大影响,但您通常会在某个时候碰壁,因为您正在等待来自某些算法的值而无法更快地运行内存层次结构中的更高级别。
此外,您的理论数字假设您有足够的指令而没有数据依赖性,可以让所有执行单元在每个周期都执行任务。这在实践中可能很难做到。我不确定一般矩阵乘法的最佳吞吐量是多少,但请查看 this previous question了解有关如何最大限度地提高指令吞吐量的信息。
关于performance - 矩阵乘法的最大 FLOPS Intel/AMD CPU,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16038729/
我来自这个线程:FLOPS Intel core and testing it with C (innerproduct) 当我开始编写简单的测试脚本时,我想到了几个问题。 为什么是 float ?我
我如何测量 FLOPS或 IOPS ?如果我测量普通浮点加法/乘法的时间,它是否等同于 FLOPS? 最佳答案 FLOPS 是每秒的浮点运算。要测量 FLOPS,您首先需要执行此类操作的代码。如果你有
我的系统: 系统规范:Intel core2duo E4500 3700g内存二级缓存2M x64 fedora 17 我如何测量 flops/mflops 好吧,我使用 papi 库(读取硬件性能计
我正在对一个 GPU(无法透露是哪个)进行建模以估计 OpenCL 和 OpenGL 应用程序的性能,该模型可以合理地估计正在执行的应用程序/内核/代码的 FLOPS 有没有办法从FLOPS,还是对帧
我想知道 Tensorflow 卷积层中浮点运算的数量。 当我等待这个功能在 TF 2.x 上发布时,我在 TF 1.x 上进行了尝试,结果我不明白它是如何计算的,其中之一非常糟糕令人印象深刻(检查第
为了测量 CPU 的峰值 FLOPS 性能,我编写了一个小的 C++ 程序。但是测量结果给我的结果比我的 CPU 的理论峰值 FLOPS 大。怎么了? 这是我写的代码: #include #incl
我想知道快速傅里叶变换 (FFT) 执行了多少 FLOPS。 所以,如果我有一个 1 维数组,包含 N 个 float ,我想计算这组数字的 FFT,有多少 FLOPS 需要执行吗? 我知道这取决于所
数学库经常根据 FLOPS 进行比较。当我看到 FLOPS 与大小的关系图以及几个不同数学库的点集时,向我传达了什么信息? 如果比较相同算法的两个实现或两个不同硬件上的相同软件,FLOPS 作为性能衡
如何计算应用程序的 FLOPS?如果我有执行指令的总数,我可以将它除以执行时间。但是,如何统计执行的指令数呢? 我的问题很笼统,非常感谢任何语言的回答。但我希望为我的应用程序找到一个由 C/C++ 和
我想计算 LeNet-5 ( paper) 的每一层需要多少触发器。一些论文总共给出了其他架构的 FLOPs(1,2,3)但是,这些论文没有详细说明如何计算 FLOPs 的数量,我不知道有多少 FLO
我能得到的最接近的例子是在这个问题中找到的:https://github.com/tensorflow/tensorflow/issues/899 使用这个最小的可重现代码: import tenso
我想计算图形硬件的理论峰值性能。嗯,其实我想了解一下计算。 以 AMD Radeon HD 6670 为例:AMD Accelerated Parallel Processing Programmin
我被要求测量一个在多 CPU 系统上求解微分方程的 Fortran 程序的性能。我的雇主坚持要求我测量 FLOP/s(每秒 float 操作)并将结果与基准进行比较( LINPACK ),但我不相
Microsoft's Parallel Programming whitepaper描述了在各种 FLOPS 阈值下最优的情况,并且 FLOPS 率是关于何时应使用特定实现的决策点。 如何测量应用程
我被要求测量一个在多 CPU 系统上求解微分方程的 Fortran 程序的性能。我的雇主坚持要求我测量 FLOP/s(每秒 float 操作)并将结果与基准进行比较( LINPACK ),但我不相
我一直在关注 OpenCL 的一些教程,很多时候人们用 FLOPS 来说话.维基百科确实解释了公式,但没有说明它的实际含义?例如,1光年= 9.4605284 × 10^15米,其实就是光在一年中行进
我的问题是我得到了一个长度为 l 的数组。 假设这是我的数组:[1,5,4,2,9,3,6] 我们称它为 A。 这个数组可以有多个子数组,子数组的节点彼此相邻。所以我们可以有 [1,5,4] 或 [2
我们必须实现一个 ASM 程序来乘以坐标方案格式 (COOS) 以及压缩行格式 (CSR) 的稀疏矩阵。现在我们已经实现了所有这些算法,我们想知道与通常的矩阵乘法相比,它们的性能要高多少。我们已经实现
我想编写一个 go 程序来对我的 CPU 进行基准测试并计算出我的笔记本电脑的 GFLOPS。 func benchmarkFlopTime(){ num_operations := int(
如何在现代 x86-64 Intel CPU 上实现每周期 4 次浮点运算( double )的理论峰值性能? 据我了解,SSE 需要三个周期add mul 的五个周期在大多数现代 Intel CPU
我是一名优秀的程序员,十分优秀!