Unmapping fails opengl interop

Hey,

As for now i am using a workaround using a memcopy, instead of storing everything used by cpu and gpu afterwards in opengl buffers.
Anybody got any ideas what could cause an unmapping error to fail? (error showed invaliddevicepointer). But i was registering/mapping/unmapping/unregistering in that sequence, doing nothing in between.

As for now the workaround works, but I will have to explain why using buffers didn’t work anyway.

Niels

I managed to reproduce the problem and code below gave me an unmapping error after 12 runs or so …

The unmapping I am talking about is in a completely different part of the code. I try to register/map/unmap/unregister a pbo at that other part. The error (invaliddevicepointer) only occurs when unmapping the pbo.

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

{

	if (i %3)

	{

  CUDA_SAFE_CALL( cudaMalloc( (void**) &indicesGPU, mem_size/4));

	}

	else

	{

  CUDA_SAFE_CALL( cudaMalloc( (void**) &indicesGPU, mem_size));

      }

	indices = m_textureUpdateCuda->getBuffer(i);

	if (i %3)

	{

         CUDA_SAFE_CALL( cudaMemcpy( indicesGPU, indices, mem_size/4,cudaMemcpyHostToDevice) );

	}

	else

	{

  CUDA_SAFE_CALL( cudaMemcpy( indicesGPU, indices, mem_size,cudaMemcpyHostToDevice) );

	}

	indices = m_textureUpdateCuda->getBuffer(i+3);

	if (i %3)

	{

         CUDA_SAFE_CALL( cudaMemcpy( indicesGPU, indices, mem_size/4,cudaMemcpyHostToDevice) );

	}

	else

	{

  CUDA_SAFE_CALL( cudaMemcpy( indicesGPU, indices, mem_size,cudaMemcpyHostToDevice) );

	}

	indices = m_textureUpdateCuda->getBuffer(i+6);

	if (i %3)

	{

         CUDA_SAFE_CALL( cudaMemcpy( indicesGPU, indices, mem_size/4,cudaMemcpyHostToDevice) );

	}

	else

	{

  CUDA_SAFE_CALL( cudaMemcpy( indicesGPU, indices, mem_size,cudaMemcpyHostToDevice) );

	}

        CUDA_SAFE_CALL(cudaFree(indicesGPU));

}

That part gave an unmapping error in some other part of the code, i changed this to

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

{

         indices = m_textureUpdateCuda->getBuffer(i);

         if (i %3)

	{

                CUDA_SAFE_CALL( cudaMalloc( (void**) &indicesGPU, mem_size/4));

  CUDA_SAFE_CALL( cudaMemcpy( indicesGPU, indices, mem_size,cudaMemcpyHostToDevice) );

	}

	else

	{

  CUDA_SAFE_CALL( cudaMalloc( (void**) &indicesGPU, mem_size));

  CUDA_SAFE_CALL( cudaMemcpy( indicesGPU, indices, mem_size,cudaMemcpyHostToDevice) );

	}

        CUDA_SAFE_CALL(cudaFree(indicesGPU));

         indices = m_textureUpdateCuda->getBuffer(i+3);

         if (i %3)

	{

                CUDA_SAFE_CALL( cudaMalloc( (void**) &indicesGPU, mem_size/4));

  CUDA_SAFE_CALL( cudaMemcpy( indicesGPU, indices, mem_size,cudaMemcpyHostToDevice) );

	}

	else

	{

  CUDA_SAFE_CALL( cudaMalloc( (void**) &indicesGPU, mem_size));

  CUDA_SAFE_CALL( cudaMemcpy( indicesGPU, indices, mem_size,cudaMemcpyHostToDevice) );

	}

        CUDA_SAFE_CALL(cudaFree(indicesGPU));

         indices = m_textureUpdateCuda->getBuffer(i+6);

         if (i %3)

	{

                CUDA_SAFE_CALL( cudaMalloc( (void**) &indicesGPU, mem_size/4));

  CUDA_SAFE_CALL( cudaMemcpy( indicesGPU, indices, mem_size,cudaMemcpyHostToDevice) );

	}

	else

	{

  CUDA_SAFE_CALL( cudaMalloc( (void**) &indicesGPU, mem_size));

  CUDA_SAFE_CALL( cudaMemcpy( indicesGPU, indices, mem_size,cudaMemcpyHostToDevice) );

	}

        CUDA_SAFE_CALL(cudaFree(indicesGPU));

}

Running it like this doesn’t give an unmapping other in a complete different part of the code…

The only difference is for every step in the for loop doing one malloc and free vs 3 times malloc and freeing…

Any help would be appreciated because i am getting desperate :D

Niels

Hey,

Another update …
When i reboot the pc, i will always get a few freeruns, but from the moment the program crashed a few times, or i went into debug mode and stopped debugging, it will start to spawn unmapping errors.
By crashing/stopping debugging : my program doesn’t go into the the deleting part of the buffers anymore, so I wonder if this could be a bug in the cuda runtime, and if the buffer wasn’t deleted as it should, cuda will think that space on the gpu-memory is still in use, and after a few runs, the whole memory will be full and thus will give undescripted behaviour?

Sounds logical or am i looking into a wrong direction… ?

Niels

Ignore last remark,
Even after reboot I get device unmapping fails, so last reply has nothing to do with it…

When i run in device-emulation this problem doesn’t occur, can anybody please help me because I have a deadline approaching and nobody replied yet in this topic :s

Now :
I have 3 cpp classes calling extern C, which calls a kernel…

First kernel uses : Output of kernel 2, and some data i memcopy from cpu.
Second kernel uses, output of kernel 1 and some other data i memcopy from cpu
Third kernel uses output of kernel 2 and writes into pbo for onscreen rendering.

I made sure I unmapped first kernel inputs, and i mapped it again for kernel 2 to write-into. Unmapping of the buffer shared kernel 2 gives me error (invaliddevicepointer). This happens in release, in debug, (not deviceemu though) at first occurence.
When i make them use different buffers, it doesn’t give any problems at all. Just because kernel 2 gets always executed right after kernel 1 it’s popping up that irritating error, from which i can’t find any answers on google/forums.

I am trying to reproduce it, but no luck so far :s

SOLVED for now :
I think i will have to file a bugreport …
I was said that it’s more secure to register/unregister the buffers right before accessing them.
I changed the order of unregistering in Kernel 2, and it doesn’t spawn an error at the next unmapping operation.