我正在尝试测试我的 GTX680 的计算性能,因为我怀疑它的实际性能如何。我想知道如果给出相同的结果,是否有人也可以在他的 GTX 680 上进行测试,或者告诉我可以做得更好以从卡中获得更多性能
我写了这个小程序
#include <stdlib.h>
#include <stdio.h>
#include <float.h>
#include "cuComplex.h"
#include "time.h"
#include "cuda_runtime.h"
#include <iostream>
using namespace std;
__global__ void test(int loop, int *out)
{
    register int a=0;
    for (int x=0;x<loop;x++)
    {
        a+=x*loop;
    }
    if (out!=NULL) *out=a;
}
int main(int argc, char *argv[])
{
    float timestamp;
    cudaEvent_t event_start,event_stop;
    // Initialise
    cudaDeviceReset();
    cudaDeviceReset();
    cudaSetDevice(0);
    cudaThreadSetCacheConfig(cudaFuncCachePreferShared);        
    // Allocate and generate buffers
    cudaEventCreate(&event_start);
    cudaEventCreate(&event_stop);
    cudaEventRecord(event_start, 0);
    dim3 threadsPerBlock;
    dim3 blocks;
    int b=1000; 
    threadsPerBlock.x=32;
    threadsPerBlock.y=32;
    threadsPerBlock.z=1;
    blocks.x=1;
    blocks.y=1000;
    blocks.z=1;
    test<<<blocks,threadsPerBlock,0>>>(300,
            NULL
            );
    cudaEventRecord(event_stop, 0);
    cudaEventSynchronize(event_stop);
    cudaEventElapsedTime(×tamp, event_start, event_stop);
    printf("Calculated in %f", timestamp);
}
用 nvcc 编译我得到这个 PTX
//
// Generated by NVIDIA NVVM Compiler
// Compiler built on Sat Sep 22 02:35:14 2012 (1348274114)
// Cuda compilation tools, release 5.0, V0.2.1221
//
.version 3.1
.target sm_30
.address_size 64
    .file   1 "/tmp/tmpxft_00000e7b_00000000-9_perf.cpp3.i"
    .file   2 "/opt/home/daniel/a/perf.cu"
 .visible .entry _Z4testiPi(
    .param .u32 _Z4testiPi_param_0,
    .param .u64 _Z4testiPi_param_1
 )
 {
    .reg .pred      %p<4>;
    .reg .s32       %r<15>;
    .reg .s64       %rd<3>;
    ld.param.u32    %r6, [_Z4testiPi_param_0];
    ld.param.u64    %rd2, [_Z4testiPi_param_1];
    cvta.to.global.u64      %rd1, %rd2;
    mov.u32         %r13, 0;
    .loc 2 12 1
    setp.lt.s32     %p1, %r6, 1;
    mov.u32         %r14, %r13;
    mov.u32         %r11, %r13;
    @%p1 bra        BB0_2;
 BB0_1:
    .loc 2 14 1
    mad.lo.s32      %r14, %r11, %r6, %r14;
    .loc 2 12 20
    add.s32         %r11, %r11, 1;
    .loc 2 12 1
    setp.lt.s32     %p2, %r11, %r6;
    mov.u32         %r13, %r14;
    @%p2 bra        BB0_1;
 BB0_2:
    .loc 2 18 1
    setp.eq.s64     %p3, %rd2, 0;
    @%p3 bra        BB0_4;
    .loc 2 18 1
    st.global.u32   [%rd1], %r13;
 BB0_4:
    .loc 2 21 2
    ret; 
 }
内核运行时间为 1.936ms
我的计算表明 GFLOPS 性能为 1.1 TFLOP,仅为 3TFLOPS 理论值的三分之一(参考:http ://www.geforce.com/hardware/desktop-gpus/geforce-gtx-680 ).. 为什么这么慢?
我的计算细节如下
mad.lo.s32      %r14, %r11, %r6, %r14;  //2 FLOPS
.loc 2 12 20
 add.s32         %r11, %r11, 1;     //1 FLOP
.loc 2 12 1
 setp.lt.s32     %p2, %r11, %r6;    //1 FLOP
 mov.u32         %r13, %r14;        // 1 FLOP
 @%p2 bra        BB0_1;             //1 FLOP
 + 1 FLOP (just as a buffer as I don't know branching how much it takes)
循环中 1 次迭代的总 FLOPS 为 7 FLOPS
只考虑迭代
我们每个线程有 300 次迭代 我们有 1024*1000 个块
总迭代 FLOPS = 300*1024*1000*7 = 2.15 GFLOPS
总内核时间为 1.936ms
因此吞吐量 = 1.11 TFLOPS
提前感谢您的帮助
丹尼尔
