天天看点

cuda 本地内存使用_每个CUDA线程的本地内存量

我在NVIDIA文档(

http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#features-and-technical-specifications,表#12)中读到,我的GPU(GTX 580,计算能力2.0)每个线程的本地内存量为512 Ko.

我尝试用CUDA 6.5检查Linux上的这个限制是不成功的.

这是我使用的代码(它的唯一目的是测试本地内存限制,它不会进行任何有用的计算):

#include

#include

#define MEMSIZE 65000 // 65000 -> out of memory, 60000 -> ok

inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=false)

{

if (code != cudaSuccess)

{

fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);

if( abort )

exit(code);

}

}

inline void gpuCheckKernelExecutionError( const char *file, int line)

{

gpuAssert( cudaPeekAtLastError(), file, line);

gpuAssert( cudaDeviceSynchronize(), file, line);

}

__global__ void kernel_test_private(char *output)

{

int c = blockIdx.x*blockDim.x + threadIdx.x; // absolute col

int r = blockIdx.y*blockDim.y + threadIdx.y; // absolute row

char tmp[MEMSIZE];

for( int i = 0; i < MEMSIZE; i++)

tmp[i] = 4*r + c; // dummy computation in local mem

for( int i = 0; i < MEMSIZE; i++)

output[i] = tmp[i];

}

int main( void)

{

printf( "MEMSIZE=%d bytes.\n", MEMSIZE);

// allocate memory

char output[MEMSIZE];

char *gpuOutput;

cudaMalloc( (void**) &gpuOutput, MEMSIZE);

// run kernel

dim3 dimBlock( 1, 1);

dim3 dimGrid( 1, 1);

kernel_test_private<<>>(gpuOutput);

gpuCheckKernelExecutionError( __FILE__, __LINE__);

// transfer data from GPU memory to CPU memory

cudaMemcpy( output, gpuOutput, MEMSIZE, cudaMemcpyDeviceToHost);

// release resources

cudaFree(gpuOutput);

cudaDeviceReset();

return 0;

}

和编译命令行:

nvcc -o cuda_test_private_memory -Xptxas -v -O2 --compiler-options -Wall cuda_test_private_memory.cu

汇编没问题,并报告:

ptxas info : 0 bytes gmem

ptxas info : Compiling entry function '_Z19kernel_test_privatePc' for 'sm_20'

ptxas info : Function properties for _Z19kernel_test_privatePc

65000 bytes stack frame, 0 bytes spill stores, 0 bytes spill loads

ptxas info : Used 21 registers, 40 bytes cmem[0]

当我在每个线程达到65000字节时,我在GTX 580上运行时出现“内存不足”错误.以下是控制台中程序的确切输出:

MEMSIZE=65000 bytes.

GPUassert: out of memory cuda_test_private_memory.cu 48

我还使用GTX 770 GPU进行了测试(在Linux上使用CUDA 6.5).对于MEMSIZE = 200000,它没有错误地运行,但是在MEMSIZE = 250000时,在运行时发生了“内存不足错误”.

如何解释这种行为?难道我做错了什么 ?