Packages
evision
0.2.17-rc2
1.0.1-rc.0
1.0.0
1.0.0-rc.0
0.2.17
0.2.17-rc2
0.2.17-rc1
0.2.16
0.2.16-pre.2
0.2.16-pre
0.2.15
0.2.14
0.2.13
0.2.12
0.2.11
0.2.9
0.2.8
0.2.7
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.2-rc2
0.2.1
0.2.0
0.1.39
0.1.38
0.1.37
0.1.36
0.1.35
0.1.34
0.1.33
0.1.32
retired
0.1.31
0.1.30
0.1.29
0.1.28
0.1.27
0.1.26
0.1.26-rc3
0.1.26-rc2
0.1.26-rc1
0.1.26-rc0
0.1.25
0.1.24
0.1.23
0.1.22
0.1.21
0.1.20
0.1.19
0.1.18
0.1.17
0.1.16
0.1.15
0.1.14
0.1.13
0.1.12
0.1.11
0.1.10
0.1.9
0.1.8
0.1.7
OpenCV-Erlang/Elixir binding.
Current section
Files
Jump to
Current section
Files
c_src/modules/evision_cuda_ipc.cc
#include "evision_cuda_ipc.h"
#ifdef CUDA_HOST_IPC_ENABLED
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include <iostream>
// Function to create or open a shared memory object and set its size
int get_ipc_handle(const char* memname, size_t memsize) {
int fd = shm_open(memname, O_CREAT | O_RDWR, 0666);
if (fd == -1) {
return -1;
}
if (ftruncate(fd, memsize) == -1) {
close(fd);
return -1;
}
return fd;
}
// Function to map the shared memory in this process
void* open_ipc_handle(int fd, size_t memsize) {
std::cout << "fd: " << fd << std::endl;
std::cout << "memsize: " << memsize << std::endl;
void* ptr = mmap(NULL, memsize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (ptr == MAP_FAILED) {
perror("mmap");
return nullptr;
}
std::cout << "ptr: " << ptr << std::endl;
return ptr;
}
int close_ipc_handle(int fd, void* ptr, char* memname, size_t memsize) {
if (munmap(ptr, memsize) == -1) {
return -1;
}
if (close(fd) == -1) {
return -1;
}
shm_unlink(memname);
return 0;
}
#else
int get_ipc_handle(const char* memname, size_t memsize) {
return -1;
}
void* open_ipc_handle(int fd, size_t memsize) {
return nullptr;
}
int close_ipc_handle(int fd, void* ptr, char* memname, size_t memsize) {
return -1;
}
#endif // CUDA_HOST_IPC_ENABLED