Cuda 我的GTX680真的在运行吗
我试图测试我的GTX680的计算性能,因为我对它的实际性能有些怀疑。我想知道是否有人也可以测试他的GTX680,如果相同的结果给出,或者可能告诉我什么可以做得更好,以从卡上点击更多的性能 我写了这个小程序Cuda 我的GTX680真的在运行吗,cuda,Cuda,我试图测试我的GTX680的计算性能,因为我对它的实际性能有些怀疑。我想知道是否有人也可以测试他的GTX680,如果相同的结果给出,或者可能告诉我什么可以做得更好,以从卡上点击更多的性能 我写了这个小程序 #include <stdlib.h> #include <stdio.h> #include <float.h> #include "cuComplex.h" #include "time.h" #include "cuda_runtime.h" #inc
#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);
}
循环中1次迭代的总失败次数为7次
只考虑迭代
我们每个线程有300次迭代
我们有1024*1000个街区
总迭代次数FLOPS=300*1024*1000*7=2.15gflops
总内核时间为1.936ms
因此,吞吐量=1.11万亿次
提前谢谢你的帮助
Daniel看看这段代码是否能获得更好的结果。这只是一个例子,它与你的代码做的事情并不完全相同,我认为你必须重新计算失败
#include <stdio.h>
using namespace std;
__global__ void test(float loop, float *out)
{
register float a=1.0f;
for (float x=0;x<loop;x++)
{
a+=x*loop;
a+=x*loop;
a+=x*loop;
a+=x*loop;
a+=x*loop;
a+=x*loop;
a+=x*loop;
a+=x*loop;
a+=x*loop;
a+=x*loop;
}
if (out!=NULL) *out=a;
}
int main(int argc, char *argv[])
{
float timestamp;
cudaEvent_t event_start,event_stop;
// Initialise
cudaDeviceReset();
cudaSetDevice(0);
cudaThreadSetCacheConfig(cudaFuncCachePreferShared);
// Allocate and generate buffers
cudaEventCreate(&event_start);
cudaEventCreate(&event_stop);
cudaEventRecord(event_start, 0);
dim3 threadsPerBlock;
dim3 blocks;
threadsPerBlock.x=32;
threadsPerBlock.y=32;
threadsPerBlock.z=1;
blocks.x=1;
blocks.y=1000;
blocks.z=1;
test<<<blocks,threadsPerBlock,0>>>(30,
NULL
);
cudaEventRecord(event_stop, 0);
cudaEventSynchronize(event_stop);
cudaEventElapsedTime(×tamp, event_start, event_stop);
printf("Calculated in %f\n", timestamp);
}
#包括
使用名称空间std;
__全局无效测试(浮点循环、浮点*输出)
{
寄存器浮点a=1.0f;
对于(float x=0;x您的测试内核正在执行整数运算,而不是浮点运算。因此,FLOPS对于该内核来说是错误的度量
FLOPS = FLoating point Operations Per Second
回到最初的问题,您的内核速度很慢,因为GPU针对浮点计算而不是整数计算进行了优化
要进行正确的测试,请尝试将测试内核转换为使用浮点数,而不是整数
此外,在将触发器注释到步骤的循环中,触发器同样没有意义,因为它是每秒的度量值,这些都是整数运算。转换后,只需将它们计算为单个浮点运算,而不是每秒的浮点运算。此示例程序基于@Robert Crovel答:Robert的内核受到数据依赖性的限制。通过减少FMA指令之间的数据依赖性,该内核在GTX680上应达到2.4-2.5 TFLOPS
当前的实现是指令获取和数据依赖受限的。内核应该能够进行调整,以将实现的触发器再提高10%
Nsight Visual Studio Edition 2.x和新的3.0 RC候选版本提供了分析此内核所需的指标
在2.x和3.0中,您应该使用以下实验来分析内核:
指令统计-SM活动-验证所有SMs是否接近100%
问题效率-合格翘曲-开普勒上每个活动周期的合格翘曲必须大于4,以便每个翘曲计划程序每个周期发出一条指令
问题效率-问题暂停-翘曲问题效率将指定每个翘曲计划程序由于合格翘曲数不足而无法问题的频率。如果此频率较高,则问题暂停原因将有助于识别限制器
已实现的浮点-显示内核执行的单精度和双精度浮点操作的类型和速率
在Robert的内核中,执行依赖性非常高,因为每条指令都有一个先读后写的依赖性。通过增加指令级并行性,我们将性能提高了三倍。内核现在主要受指令获取限制
新的Nsight VSE 3.0 RC(今天提供)还将显示带有每条指令统计信息注释的程序集或源代码,如执行的指令数和每条指令的活动线程数。在本例中,该工具可用于识别数据相关性,并确保编译器生成的FMA指令需要达到更高的精度理论上有超过50%的失败
__global__ void test(float loop, float *out)
{
register float a=1.0f;
register float b=1.0f;
register float c=1.0f;
register float d=1.0f;
register float e=1.0f;
register float f=1.0f;
register float g=1.0f;
register float h=1.0f;
for (float x=0;x<loop;x++)
{
a+=x*loop;
b+=x*loop;
c+=x*loop;
d+=x*loop;
e+=x*loop;
f+=x*loop;
g+=x*loop;
h+=x*loop;
a+=x*loop;
b+=x*loop;
c+=x*loop;
d+=x*loop;
e+=x*loop;
f+=x*loop;
g+=x*loop;
h+=x*loop;
a+=x*loop;
b+=x*loop;
c+=x*loop;
d+=x*loop;
e+=x*loop;
f+=x*loop;
g+=x*loop;
h+=x*loop;
a+=x*loop;
b+=x*loop;
c+=x*loop;
d+=x*loop;
e+=x*loop;
f+=x*loop;
g+=x*loop;
h+=x*loop;
a+=x*loop;
b+=x*loop;
c+=x*loop;
d+=x*loop;
e+=x*loop;
f+=x*loop;
g+=x*loop;
h+=x*loop;
}
if (out!=NULL) *out=a+b+c+d+e+f+g+h;
}
int main(int argc, char *argv[])
{
float timestamp;
cudaEvent_t event_start,event_stop;
// Initialise
cudaDeviceReset();
cudaSetDevice(0);
cudaThreadSetCacheConfig(cudaFuncCachePreferShared);
// Allocate and generate buffers
cudaEventCreate(&event_start);
cudaEventCreate(&event_stop);
cudaEventRecord(event_start, 0);
dim3 threadsPerBlock;
dim3 blocks;
threadsPerBlock.x=32;
threadsPerBlock.y=32;
threadsPerBlock.z=1;
blocks.x=1;
blocks.y=1000;
blocks.z=1;
test<<<blocks,threadsPerBlock,0>>>(30,NULL);
cudaEventRecord(event_stop, 0);
cudaEventSynchronize(event_stop);
cudaEventElapsedTime(×tamp, event_start, event_stop);
printf("Calculated in %f\n", timestamp);
}
\uuuu全局\uuuuu无效测试(浮点循环,浮点*输出)
{
寄存器浮点a=1.0f;
寄存器浮点b=1.0f;
寄存器浮点数c=1.0f;
寄存器浮点d=1.0f;
寄存器浮点数e=1.0f;
寄存器浮点数f=1.0f;
寄存器浮点数g=1.0f;
寄存器浮点h=1.0f;
对于(float x=0;x我认为问题在于您使用的是整数乘法。compute capability 3.0体系结构上的32位整数乘法仅为32位浮点吞吐量的1/6(请参阅下表,摘自CUDA C编程指南5.5版)。比较3.0体系结构的32位整数乘法性能与32位浮点性能
其他一些主要用于计算应用程序的整数操作和类型转换也同样降低了3.0的性能
帮不了你,这是我力所能及的,但它给人留下了深刻的印象。尝试展开循环,紧循环消耗了大量循环。你是说有条件的跳跃(@%p2 bra)需要更多的2次浮点运算时间才能完成…?我正在做一些其他的研究..当我使用gpu-z时,整数运算在gpu中是否较慢?它告诉我它只能达到500giops/s,而达到近2tflops?在你的问题中,你正在计算执行的指令数。这些指令应该从SASS(汇编代码)中计算出来不是中间的PTX代码。使用cuobjdump-sass EXECUTABLE/SO获取sass代码。CUDA命令行探查器、nvprof、Visual profiler和Nsight VSE CUDA探查器都可以收集inst_执行的计数器。如果您对只计算浮点操作感兴趣,Nsight VSE CUDA探查器将提供实验“已实现的触发器”(不是指令)。内核花费了0.469216ms。我现在正在计算Thorughtput。很抱歉花了这么多时间来获取backSo。我认为有11个FMA(您要离开FADD R0,R0,0x3f800;行)所以(每次迭代11次失败)X(每个线程30次迭代)X(每个块1024个线程)X(1000个块)/0.4969216=680GFLOPS/秒!!!!非常糟糕..我越来越觉得我的卡(或系统)性能不好..周围有没有人有GTX 680并且愿意运行此代码…我只需要知道花了多少时间?我的
FLOPS = FLoating point Operations Per Second
__global__ void test(float loop, float *out)
{
register float a=1.0f;
register float b=1.0f;
register float c=1.0f;
register float d=1.0f;
register float e=1.0f;
register float f=1.0f;
register float g=1.0f;
register float h=1.0f;
for (float x=0;x<loop;x++)
{
a+=x*loop;
b+=x*loop;
c+=x*loop;
d+=x*loop;
e+=x*loop;
f+=x*loop;
g+=x*loop;
h+=x*loop;
a+=x*loop;
b+=x*loop;
c+=x*loop;
d+=x*loop;
e+=x*loop;
f+=x*loop;
g+=x*loop;
h+=x*loop;
a+=x*loop;
b+=x*loop;
c+=x*loop;
d+=x*loop;
e+=x*loop;
f+=x*loop;
g+=x*loop;
h+=x*loop;
a+=x*loop;
b+=x*loop;
c+=x*loop;
d+=x*loop;
e+=x*loop;
f+=x*loop;
g+=x*loop;
h+=x*loop;
a+=x*loop;
b+=x*loop;
c+=x*loop;
d+=x*loop;
e+=x*loop;
f+=x*loop;
g+=x*loop;
h+=x*loop;
}
if (out!=NULL) *out=a+b+c+d+e+f+g+h;
}
int main(int argc, char *argv[])
{
float timestamp;
cudaEvent_t event_start,event_stop;
// Initialise
cudaDeviceReset();
cudaSetDevice(0);
cudaThreadSetCacheConfig(cudaFuncCachePreferShared);
// Allocate and generate buffers
cudaEventCreate(&event_start);
cudaEventCreate(&event_stop);
cudaEventRecord(event_start, 0);
dim3 threadsPerBlock;
dim3 blocks;
threadsPerBlock.x=32;
threadsPerBlock.y=32;
threadsPerBlock.z=1;
blocks.x=1;
blocks.y=1000;
blocks.z=1;
test<<<blocks,threadsPerBlock,0>>>(30,NULL);
cudaEventRecord(event_stop, 0);
cudaEventSynchronize(event_stop);
cudaEventElapsedTime(×tamp, event_start, event_stop);
printf("Calculated in %f\n", timestamp);
}