GLbufferregistering

Hey everybody,

Because I didn’t want anything to be different, i made one big cuda file with a lot of extern functions that get called from different classes of a c++ project.

Previously I called a method from main class and in that method I did

cudaError_t errRegisterBuffer = cudaGLRegisterBufferObject(m_videoMemoryCUDA->getVideoTextureWrite(0));

cudaError_t errRegisterBuffer2 = cudaGLMapBufferObject((void**)&m_videoY, m_videoMemoryCUDA->getVideoTextureWrite(0));

Now I am calling another method from another class to the same cuda file (so there aren’t any differences in compiling, in that method I do :

 

cudaError_t errRegisterBuffer = cudaGLRegisterBufferObject(m_videoMemoryCUDA->getVideoTextureRead(i));

cudaError_t errRegisterBuffer2 = cudaGLMapBufferObject((void**)&m_video, m_videoMemoryCUDA->getVideoTextureRead(i));

i = 0, so it should all work. When I go back to first case, errRegisterBuffer tells me cudasucces and in the second case (only difference is calling from another method) it says unknown error when i try to register the buffer.

I made sure that :

The buffer wasn’t already registered in cuda at the moment

The buffer wasn’t mapped by the cpu anymore.

Next I manually checked that both buffers are showing an integer (to say which buffer it is, and that’s correct too…

…Output of the error is unknown error, so I am pretty clueless at the moment… And I don’t know how to get these buffers registered and eventually mapped in CUDA…

Anybody can help?

Hey,

Updated: CUDA crashes when there is something wrong any buffer at all.
In this case CUDA tried to map a working buffer which was initialised properly etc…
But if there is any other buffer which isn’t set up right, or you just write into it and didn’t allocated enough space for it. CUDA will fail on registering/mapping on the next time you try to work on a working/non-working buffer. Where it fails (registering/mapping) depends on what mistake you made in your bad buffer ;)
Sorry for confusing english…

Can you post a minimal version of the code that reproduces this?

Paulius

Heyho,

i recently got the same error calling cudaGLRegisterBufferObject(…);

The Reason was, the buffer object was still bind to opengl.

ERROR: External Image

glBindBuffer( GL_ARRAY_BUFFER, ...);

...

cudaGLRegisterBufferObject(..);

...

glBindBuffer( GL_ARRAY_BUFFER, 0);

This one worked without an error: External Image

glBindBuffer( GL_ARRAY_BUFFER, ...);

...

glBindBuffer( GL_ARRAY_BUFFER, 0);

...

cudaGLRegisterBufferObject(..);

Maybe it helped a little…

Hugie

P.S. bad englisch → german author

Hey,

I double checked everything now, and all registering and mapping works…
I made sure I didn’t write outside the buffer at any point.
But now I get a cudaErrorInvalidDevicePointer when i try unmap a buffer.
Any idea would have caused this?
I would paste some code, but i commented out a lot to uncomment it step by step and keep it working. Basicly at the moment my code is registering/mapping and writing few integers on the cpu. I didn’t run any kernel yet at this moment…

Kind regards
Niels

Update :

I thought something moved between mapping and unmapping would could have explained the errors :D

Anyways look at the code below

CVideoMemoryCUDA* m_videoMemoryCUDA;

m_videoMemoryCUDA= (CVideoMemoryCUDA*)g_videoMemory;

CTextureUpdateCUDA* m_textureUpdateCuda;

m_textureUpdateCuda = (CTextureUpdateCUDA*)textureUpdate;

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

{

unsigned char *m_video = NULL;

int *m_indices = NULL;

CUDA_SAFE_CALL(cudaGLRegisterBufferObject(m_videoMemoryCUDA->getVideoTextureWrite(i)));

CUDA_SAFE_CALL(cudaGLMapBufferObject((void**)&m_video, m_videoMemoryCUDA->getVideoTextureWrite(i)));

CUDA_SAFE_CALL(cudaGLRegisterBufferObject(m_textureUpdateCuda->getBuffer(i)));

CUDA_SAFE_CALL(cudaGLMapBufferObject((void**)&m_indices, m_textureUpdateCuda->getBuffer(i)));

CUDA_SAFE_CALL(cudaGLUnmapBufferObject(m_textureUpdateCuda->getBuffer(i)));

CUDA_SAFE_CALL(cudaGLUnregisterBufferObject(m_textureUpdateCuda->getBuffer(i)));

cudaError_t errRegisterBuffer = cudaGLUnmapBufferObject(m_videoMemoryCUDA->getVideoTextureWrite(i));

CUDA_SAFE_CALL(cudaGLMapBufferObject((void**)&m_video, m_videoMemoryCUDA->getVideoTextureWrite(i)));

CUDA_SAFE_CALL(cudaGLRegisterBufferObject(m_textureUpdateCuda->getBuffer(i+3)));

CUDA_SAFE_CALL(cudaGLMapBufferObject((void**)&m_indices, m_textureUpdateCuda->getBuffer(i+3)));

CUDA_SAFE_CALL(cudaGLUnmapBufferObject(m_textureUpdateCuda->getBuffer(i+3)));

CUDA_SAFE_CALL(cudaGLUnregisterBufferObject(m_textureUpdateCuda->getBuffer(i+3)));

errRegisterBuffer = cudaGLUnmapBufferObject(m_videoMemoryCUDA->getVideoTextureWrite(i));

CUDA_SAFE_CALL(cudaGLMapBufferObject((void**)&m_video, m_videoMemoryCUDA->getVideoTextureWrite(i)));

CUDA_SAFE_CALL(cudaGLRegisterBufferObject(m_textureUpdateCuda->getBuffer(i+6)));

CUDA_SAFE_CALL(cudaGLMapBufferObject((void**)&m_indices, m_textureUpdateCuda->getBuffer(i+6)));

CUDA_SAFE_CALL(cudaGLUnmapBufferObject(m_textureUpdateCuda->getBuffer(i+6)));

errRegisterBuffer = cudaGLUnmapBufferObject(m_videoMemoryCUDA->getVideoTextureWrite(i));

CUDA_SAFE_CALL(cudaGLUnregisterBufferObject(m_videoMemoryCUDA->getVideoTextureWrite(i)));

CUDA_SAFE_CALL(cudaGLUnregisterBufferObject(m_textureUpdateCuda->getBuffer(i+6)));

}

Sorry it’s a lot of code.

Anyways, this runs fine and if i keep a watch on the errRegisterBuffer it says :

//i = 0

cudaErrorInvalidDevicePointer

cudaErrorInvalidDevicePointer

cudaSucces

//i = 1

cudaSucces

cudaSucces

cudaSucces

//i = 2

cudaErrorInvalidDevicePointer

cudaSucces

cudaErrorInvalidDevicePointer

Hope anybody can explain why this all happening, and why this is all happening on unmapping the before (not at registering/mapping/unregistering)

When i comment out everything with textureupdate it’s working without spawning cuda_errors at unmapping.

And last but not least :

GLuint      m_indexBuffer[9];

glGenBuffersARB(m_NumberOfGroups, m_indexBuffer);

for ( i = 0; i < m_NumberOfGroups; i++)

{

if ( i % 3)

{

glBindBufferARB(GL_ARRAY_BUFFER, m_indexBuffer[i]);

glBufferDataARB(GL_ARRAY_BUFFER, w8 * h8/4, NULL, GL_DYNAMIC_COPY_ARB);

}

else

{

glBindBufferARB(GL_ARRAY_BUFFER, m_indexBuffer[i]);

glBufferDataARB(GL_ARRAY_BUFFER, w8 * h8, NULL, GL_DYNAMIC_COPY_ARB);

}

}

glBindBufferARB(GL_ARRAY_BUFFER, 0);

That part is used for initializing the buffer of textureupdate. I don’t use them at all, I haven’t mapped/unmapped them any cpu code. (it’s all commented out at the moment)

Best regards and thx for those taking the time to read all this :D

Niels

What I was thinking, is there like a maximum number of buffers allowed?
And because at testing one buffer gets moved after mapping causing the pointer to become an invaliddevicepointer?

Niels