Hardware: I am using a Jetson AGX Orin.
I am trying to set an IPC between multiples processes to stream a video. I use a classic shm_open/mmap shm mechanism, then I try to map it on CUDA with pinned/locked memory.
void SharedMemory::registerCudaMemory() {
if (!checkCudaZeroCopySupport()) {
std::cerr << "CUDA device does not support zero-copy, using POSIX shared "
"memory instead\n";
return;
}
cudaError_t err = cudaHostRegister(shm_ptr, size, cudaHostRegisterMapped);
if (err != cudaSuccess) {
std::cerr << "Failed to register host memory with CUDA:"
<< cudaGetErrorString(err) << std::endl;
}
err = cudaHostGetDevicePointer(&cuda_ptr, shm_ptr, 0);
if (err == cudaSuccess) {
std::cout << "CUDA device pointer for registered memory: " << cuda_ptr
<< std::endl;
use_cuda = true;
}
if (err != cudaSuccess) {
std::cerr << "Failed to get CUDA device pointer for registered memory: "
<< cudaGetErrorString(err) << std::endl;
cudaHostUnregister(shm_ptr);
shm_ptr = nullptr;
}
// Check if the pointers are the same for zero-copy
if (shm_ptr == cuda_ptr) {
// use_cuda = true;
std::cout
<< "Zero-copy memory confirmed. shm_ptr and cuda_ptr are the same.\n";
} else {
std::cerr << "Warning: Zero-copy memory expected but shm_ptr and cuda_ptr "
"are different.\n";
std::cerr << "shm_ptr: " << shm_ptr << " cuda_ptr: " << cuda_ptr << "\n";
cudaHostUnregister(shm_ptr);
}
}
The problem is I always get a different address than my CPU. Also I am having trouble using another process to read the memory within that CUDA address. I try to share the pointer through an HTTP web server but keep having error with a cudamemcpy. I believe I might not be using the best of methods.
Looking forward for any help.
best regards,
Karim