I have this https://stackoverflow.com/questions/12159709/cuda-out-of-memory-threads-and-blocks-issue-address-is-out-of-bounds/12230988#comment16400460_12230988代码在这里(由于答案而修改)。
Info
32 字节堆栈帧、0 字节溢出存储、0 字节溢出加载
ptxas info :使用了 46 个寄存器,120 字节 cmem[0],176 字节
cmem[2],76 字节 cmem[16]
我不知道为了使其适用于点“numPointsRs”和“numPointsRp”的不同组合还需要考虑什么
例如,当我运行 Rs=10000 和 Rp=100000 且 block=(128,1,1),grid=(200,1) 的代码时,就可以了。
我的计算:
46个寄存器*128线程=5888个寄存器。
我的卡限制 32768 个寄存器,所以 32768/5888=5 +some => 5 block/SM
(我的卡有限额6)。
通过占用率计算器,我发现使用 128 个线程/块
给我 42%,而且我的卡限额之内。
另外,每个 MP 的线程数为 640(限制为 1536)
现在,如果我尝试使用 Rs=100000 和 Rp=100000 (对于相同的线程和块),它会给我标题中的消息,其中:
cuEventDestroy 失败:启动超时
cuModuleUnload 失败:启动超时
1)我不知道/理解还需要计算什么。
2)我不明白我们如何使用/查找块的数量。我可以看到
大多数情况下,有人放置 (threads-1+points)/threads ,但这仍然
不起作用。
- - - - - - - 更新 - - - - - - - - - - - - - - - - - - ------------
使用 driver.Context.synchronize() 后,代码适用于很多点(1000000)!
但是,这个添加对代码有什么影响?(很多时候屏幕会冻结 1 分钟或更长时间)。我应该使用它吗?
--------------更新2------------------------------------ ------------
现在,如果不执行任何操作,代码将不再起作用!
代码快照:
import pycuda.gpuarray as gpuarray
import pycuda.autoinit
from pycuda.compiler import SourceModule
import numpy as np
import cmath
import pycuda.driver as drv
import pycuda.tools as t
#---- Initialization and passing(allocate memory and transfer data) to GPU -------------------------
Rs_gpu=gpuarray.to_gpu(Rs)
Rp_gpu=gpuarray.to_gpu(Rp)
J_gpu=gpuarray.to_gpu(np.ones((numPointsRs,3)).astype(np.complex64))
M_gpu=gpuarray.to_gpu(np.ones((numPointsRs,3)).astype(np.complex64))
Evec_gpu=gpuarray.to_gpu(np.zeros((numPointsRp,3)).astype(np.complex64))
Hvec_gpu=gpuarray.to_gpu(np.zeros((numPointsRp,3)).astype(np.complex64))
All_gpu=gpuarray.to_gpu(np.ones(numPointsRp).astype(np.complex64))
#-----------------------------------------------------------------------------------
mod =SourceModule("""
#include <pycuda-complex.hpp>
#include <cmath>
#include <vector>
typedef pycuda::complex<float> cmplx;
typedef float fp3[3];
typedef cmplx cp3[3];
__device__ __constant__ float Pi;
extern "C"{
__device__ void computeEvec(fp3 Rs_mat[], int numPointsRs,
cp3 J[],
cp3 M[],
fp3 Rp,
cmplx kp,
cmplx eta,
cmplx *Evec,
cmplx *Hvec, cmplx *All)
{
while (c<numPointsRs){
...
c++;
}
}
__global__ void computeEHfields(float *Rs_mat_, int numPointsRs,
float *Rp_mat_, int numPointsRp,
cmplx *J_,
cmplx *M_,
cmplx kp,
cmplx eta,
cmplx E[][3],
cmplx H[][3], cmplx *All )
{
fp3 * Rs_mat=(fp3 *)Rs_mat_;
fp3 * Rp_mat=(fp3 *)Rp_mat_;
cp3 * J=(cp3 *)J_;
cp3 * M=(cp3 *)M_;
int k=threadIdx.x+blockIdx.x*blockDim.x;
while (k<numPointsRp)
{
computeEvec( Rs_mat, numPointsRs, J, M, Rp_mat[k], kp, eta, E[k], H[k], All );
k+=blockDim.x*gridDim.x;
}
}
}
""" ,no_extern_c=1,options=['--ptxas-options=-v'])
#call the function(kernel)
func = mod.get_function("computeEHfields")
func(Rs_gpu,np.int32(numPointsRs),Rp_gpu,np.int32(numPointsRp),J_gpu, M_gpu, np.complex64(kp), np.complex64(eta),Evec_gpu,Hvec_gpu, All_gpu, block=(128,1,1),grid=(200,1))
#----- get data back from GPU-----
Rs=Rs_gpu.get()
Rp=Rp_gpu.get()
J=J_gpu.get()
M=M_gpu.get()
Evec=Evec_gpu.get()
Hvec=Hvec_gpu.get()
All=All_gpu.get()
My card:
Device 0: "GeForce GTX 560"
CUDA Driver Version / Runtime Version 4.20 / 4.10
CUDA Capability Major/Minor version number: 2.1
Total amount of global memory: 1024 MBytes (1073283072 bytes)
( 0) Multiprocessors x (48) CUDA Cores/MP: 0 CUDA Cores //CUDA Cores 336 => 7 MP and 48 Cores/MP