【发布时间】:2019-06-07 11:51:19
【问题描述】:
我正在使用 MATLAB R2017a。我正在运行一个简单的代码来计算从第一个点到第 i 个点的累积总和。
我的 CUDA 内核代码是:
__global__ void summ(const double *A, double *B, int N){
for (int i=threadIdx.x; i<N; i++){
B[i+1] = B[i] + A[i];}}
我的 MATLAB 代码是
k=parallel.gpu.CUDAKernel('summ.ptx','summ.cu');
n=10^7;
A=rand(n,1);
ans=zeros(n,1);
A1=gpuArray(A);
ans2=gpuArray(ans);
k.ThreadBlockSize = [1024,1,1];
k.GridSize = [3,1];
G = feval(k,A1,ans2,n);
G1 = gather(G);
GPU_time = toc
我想知道为什么当我增加网格大小 (k,.GridSize) 时 GPU 时间会增加。即时获取 10^7 数据,
k.GridSize=[1,1] the time is 8.0748s
k.GridSize=[2,1] the time is 8.0792s
k.GridSize=[3,1] the time is 8.0928s
据我了解,对于 10^7 的数据,系统需要 10^7 / 1024 ~ 9767 个块,所以网格大小应该是 [9767,1]。
GPU设备是
Name: 'Tesla K20c'
Index: 1
ComputeCapability: '3.5'
SupportsDouble: 1
DriverVersion: 9.1000
ToolkitVersion: 8
MaxThreadsPerBlock: 1024
MaxShmemPerBlock: 49152
MaxThreadBlockSize: [1024 1024 64]
MaxGridSize: [2.1475e+09 65535 65535]
SIMDWidth: 32
TotalMemory: 5.2983e+09
AvailableMemory: 4.9132e+09
MultiprocessorCount: 13
ClockRateKHz: 705500
ComputeMode: 'Default'
GPUOverlapsTransfers: 1
KernelExecutionTimeout: 0
CanMapHostMemory: 1
DeviceSupported: 1
DeviceSelected: 1
感谢您的回复。
【问题讨论】:
-
这段代码不会给你一个正确的结果。