I would like to calculate a picture with CUDA and then display it directly. Therefore I created a CudaArray and I calculated a float Array in the device Memory called "d_A" which contains the image data.
When I call "cudaGraphicsMapResources" the Debug says:
Unhandled exception at 0x00007FFA1429F5E0 (nvcuda.dll) in CudaProgrammMitGLCode.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
What could I have made wrong? Is this possible at all what I am planning to do?
The important part of my code is here:
// Unbind the texture
glDisable(GL_TEXTURE_2D);
// creating a GraphicsResource
cudaGraphicsResource* Res;
// Allocate CUDA array in device memory
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc(32, 0, 0, 0,
cudaChannelFormatKindFloat);
//creating a Cuda Array
cudaArray* CuArr;
cudaMallocArray(&CuArr, &channelDesc, N, N);
size_t spitch, pitch;
cudaMallocPitch((void**)&d_A,&pitch, N *sizeof(float),N);
cudaMakeCheckImage <<<grid, block >> >(d_A);
cudaError_t eError = cudaGraphicsGLRegisterImage(&Res, texName, GL_TEXTURE_2D, cudaGraphicsMapFlagsNone);
cudaMemcpy2DToArray(CuArr, 0, 0, d_A, N, N, pitch, cudaMemcpyDeviceToDevice);
// the next command is for testing purposes, but I get some strange numbers with cout
cudaMemcpy(host, CuArr, N * N * sizeof(float), cudaMemcpyDeviceToHost);
std::cout << "Write CudaArray to host memory" << std::endl;
std::cout << host[0] << " , " << host[1] << " , " << host[2] << " , " << host[3] << " , " << host[4] << " , " << host[5] << std::endl;
std::cout << host[1024] << " , " << host[1025] << " , " << host[1026] << " , " << host[1027] << " , " << host[1028] << " , " << host[1029] << std::endl;
cudaError_t eError2 = cudaGraphicsMapResources(1, &Res, 0);
cudaError_t eError3 = cudaGraphicsSubResourceGetMappedArray(&CuArr, Res, 0, 0);
cudaError_t eError4 = cudaGraphicsUnmapResources(0, &Res, 0);
cudaFree(d_A);
delete[] host_dA;
delete[] host;
User contributions licensed under CC BY-SA 3.0