Hello,
I would like to share the contents of a NvBuffer in process A with another process B. If I understand the documentation correctly, the NvBufferMemMapEx() function combined with the various NvBufferMemSync* functions is the way to go. I am, however, not quite sure how to do this right and can’t seem to make this work, because I do not know which function to call when and with what arguments.
What I basically want is to have a shared view on the buffer between the processes, so that when I update the buffer in process A, process B can work with the updated buffer, without copying the content.
Currently, my code looks something like this:
Process A:
// Some function to generate the buffer
int bufferFDProcessA = getBuffer();
// Send the NvBufferParams und NvBufferParamsEx struct objects of this buffer to process B
sendBufferParamsToProcessB(bufferFDProcessA)
// Wait for process B to to call NvBufferMemMapEx()
...
// Update buffer contents
void* bufferPtr = nullptr;
NvBufferMemMap(bufferFDProcessA , 0, NvBufferMem_Write, &bufferPtr);
((char*)bufferPtr)[0] = 1;
NvBufferMemSyncForDevice(bufferFD, 0, &bufferPtr)
Process B:
// Receive buffer params from process A
NvBufferParams paramsA = receiveParamsFromProcessA();
NvBufferParamsEx paramsExA = receiveParamsExFromProcessA();
// Unclear: what buffer fd to use...Create new buffer or use fd from process A?
int bufferFD = ...
void* bufferPtr = nullptr;
NvBufferMemMapEx(bufferFD, &(paramsExA), 0, NvBufferMem_Read, &bufferPtr)
// Notify process A that memory mapping is done and wait a bit
...
// Synchronize and get new data
NvBufferMemSyncForCpuEx(bufferFD, &(bufferParamsEx.paramsEx), 0, &bufferPtr)
char value = ((char*) bufferPtr)[0]; // Should be 1
Currently this is not working and I am honestly not quite sure what to do here, since the change of the buffer in process A is not reflected in the buffer of process B. I am also not quite sure, which buffer descriptor to use when calling NvBufferMemMapEx(). Do I use the FD from process A, which can be accesses via NvBufferParams.dmabuf_fd? Or do I have create a new buffer in process B and use the FD of that?
The API documentation is not really clear at this point and I can’t find a single example code snippet anywhere, where these functions have been used before. Can anyone help me with this?