Хабр
- 1 ответ
- 0 вопросов
3
Вклад в тег
__global__ void RunTest(unsigned long *heartbeat)
{
unsigned long tid = blockIdx.x*blockDim.x + threadIdx.x;
heartbeat[tid] = 1;
}
void Runkerneltest(int grids, int threads, unsigned long *heartbeat)
{
RunTest <<<grids, threads>>> (heartbeat);
}
bool TestKernel(int grids, int threads)
{
unsigned long* heartbeat = new unsigned long [grids*threads];
memset (heartbeat, 0, grids*threads*sizeof (unsigned long));
void* heartbeat_device = 0;
cudaError err;
err = cudaMalloc ((void**)&heartbeat_device, grids*threads*sizeof (unsigned long));
Check("cudaMalloc heartbeat_device",err);
err = cudaMemset (heartbeat_device, 0, grids*threads*sizeof(unsigned long));
Check("cudaMemset heartbeat_device",err);
Runkerneltest(grids,threads,(unsigned long*)heartbeat_device);
err = cudaThreadSynchronize();
Check("cudaThreadSynchronize()", err);
err = cudaMemcpy( heartbeat, heartbeat_device, grids*threads*sizeof(unsigned long), cudaMemcpyDeviceToHost );
Check("cudaMemcpy( heartbeat, heartbeat_device)", err);
bool error = false;
for (int i=0; i<grids*threads; i++)
if (heartbeat[i] != 1)
{
LOG("tid %d test fails",i);
error = true;
break;
}
cudaFree (heartbeat_device);
delete (heartbeat);
return (error ? false : true); //если была ошибка, то false
}