スレッドごとのローカル メモリの量が私のGPU(GTX 580、計算能力2.0)では512 Koです。
Linux で CUDA 6.5 を使用してこの制限を確認しようとしましたが失敗しました。
これが私が使用したコードです(その唯一の目的はローカルメモリの制限をテストすることであり、有用な計算は行いません):
#include <iostream>
#include <stdio.h>
#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<<<dimGrid, dimBlock>>>(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 (CUDA 6.5 を搭載した Linux) でテストも行いました。MEMSIZE=200000 ではエラーなく実行されましたが、MEMSIZE=250000 では実行時に「メモリ不足エラー」が発生しました。
この動作を説明するにはどうすればよいですか? 私は何か間違っていますか?