-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(exla): Host IPC and revamped pointer representation (#1531)
- Loading branch information
1 parent
116b124
commit 93e4383
Showing
10 changed files
with
260 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
#pragma once | ||
|
||
#include <cstddef> | ||
#include <cstdint> | ||
#include <vector> | ||
|
||
std::pair<std::vector<unsigned char>, int> get_cuda_ipc_handle(std::uintptr_t); | ||
std::pair<void*, int> get_pointer_for_ipc_handle(std::vector<int64_t>, int); | ||
std::pair<void*, int> get_pointer_for_ipc_handle(uint8_t*, size_t, int); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include "ipc.h" | ||
|
||
#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) { | ||
void* ptr = mmap(NULL, memsize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); | ||
if (ptr == MAP_FAILED) { | ||
perror("mmap"); | ||
return nullptr; | ||
} | ||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
|
||
#include <cstddef> | ||
|
||
int get_ipc_handle(const char* memname, size_t memsize); | ||
void* open_ipc_handle(int fd, size_t memsize); | ||
int close_ipc_handle(int fd, void* ptr, char* memname, size_t memsize); |
Oops, something went wrong.