Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python Client API support for shared memory #570

Merged
merged 26 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0d25464
Add Shared Memory Python client support
CoderHam Jul 23, 2019
62188c1
keep shared memory wrapper separate for now - will merge in future
CoderHam Aug 17, 2019
1d347a6
add shared memory helper functions to python API
CoderHam Aug 19, 2019
c4a13dd
fix docs
CoderHam Aug 20, 2019
ac9a5e6
move shared memory back out of regular client
CoderHam Aug 20, 2019
4802dba
modify shared memory python client with new API
CoderHam Aug 20, 2019
68061e6
WIP - read output_values into list of numpy arrays
CoderHam Aug 21, 2019
538b0fa
Python client integration
CoderHam Aug 21, 2019
28fd76b
fix set input shared memory
CoderHam Aug 21, 2019
6f3f426
support read output from shared memory
CoderHam Aug 21, 2019
41cc60c
- fix typos
CoderHam Aug 22, 2019
c0a772c
return result for shared memory like regular results
CoderHam Aug 22, 2019
146543b
migrate to using shared memory handle instead of base address
CoderHam Aug 23, 2019
c3bd8ac
Add python client to simple shared_memory test
CoderHam Aug 23, 2019
65d7819
move shared memory helpers to `tensorrtserver.shared_memory`
CoderHam Aug 23, 2019
fbcb727
fix segfault during shared memory handle creation
CoderHam Aug 23, 2019
ef46c11
move shared memory handle struct to a different header file
CoderHam Aug 24, 2019
71a2d8a
review edits
CoderHam Aug 26, 2019
9c3aef7
- use handle when possible - fix import for shared_memory (remove unn…
CoderHam Aug 27, 2019
f820b19
fix segfault due to empty handle
CoderHam Aug 28, 2019
4f84563
fix for windows build
CoderHam Aug 28, 2019
1ed4da3
use only handle to denote shared memory region - one shared memory re…
CoderHam Aug 28, 2019
98fc877
fix for batch_size != 1
CoderHam Aug 28, 2019
13919c0
remove dependency of shared_memory on request
CoderHam Aug 29, 2019
7a41f1a
review edits
CoderHam Aug 29, 2019
5d04920
fix raising exception
CoderHam Aug 29, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions qa/L0_simple_shared_memory_example/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

SIMPLE_SHM_CLIENT=../clients/simple_shm_client
SIMPLE_SHM_CLIENT_PY=../clients/simple_shm_client.py

SERVER=/opt/tensorrtserver/bin/trtserver
SERVER_ARGS=--model-repository=`pwd`/models
Expand Down Expand Up @@ -56,6 +57,16 @@ if [ $? -ne 0 ]; then
RET=1
fi

python $SIMPLE_SHM_CLIENT_PY -i grpc -u localhost:8001 -v >>client_py.log 2>&1
if [ $? -ne 0 ]; then
RET=1
fi

python $SIMPLE_SHM_CLIENT_PY -v >>client_py.log 2>&1
if [ $? -ne 0 ]; then
RET=1
fi

if [ `grep -c "localhost:8000" client_c++.log` != "9" ]; then
echo -e "\n***\n*** Failed. Expected 9 Host: localhost:8000 headers for C++ client\n***"
RET=1
Expand Down
15 changes: 11 additions & 4 deletions src/clients/c++/simple_shm_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,17 @@ CreateSharedMemoryRegion(std::string shm_key, size_t batch_byte_size)
// get shared memory region descriptor
int shm_fd = shm_open(shm_key.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
if (shm_fd == -1) {
std::cerr << "error: unable to get shared memory descriptor";
std::cerr << "error: unable to get shared memory descriptor for "
"shared-memory key '" +
shm_key + "'";
exit(1);
}
// extend shared memory object as by default it's initialized with size 0
int res = ftruncate(shm_fd, batch_byte_size);
if (res == -1) {
std::cerr << "error: unable to get initialize size";
std::cerr << "error: unable to initialize shared-memory key '" + shm_key +
"' to requested size " + std::to_string(batch_byte_size) +
" bytes";
exit(1);
}
return shm_fd;
Expand All @@ -93,7 +97,9 @@ MapSharedMemory(int shm_fd, size_t offset, size_t batch_byte_size)
void* shm_addr =
mmap(NULL, batch_byte_size, PROT_WRITE, MAP_SHARED, shm_fd, offset);
if (shm_addr == MAP_FAILED) {
std::cerr << "error: unable to process address space";
std::cerr << "error: unable to process address space or shared-memory "
"descriptor: " +
std::to_string(shm_fd);
exit(1);
}
return shm_addr;
Expand All @@ -104,7 +110,8 @@ UnlinkSharedMemoryRegion(std::string shm_key)
{
int shm_fd = shm_unlink(shm_key.c_str());
if (shm_fd == -1) {
std::cerr << "error: unable to unlink shared memory for " << shm_key;
std::cerr << "error: unable to unlink shared memory for key '" + shm_key +
"'";
exit(1);
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/clients/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,22 @@ target_link_libraries(
PUBLIC request
)

#
# libcshm.so
#
add_library(cshm SHARED shared_memory/shared_memory.cc)
target_link_libraries(
cshm
rt
)

#
# Wheel file
#
set(wheel_stamp_file "stamp.whl")
configure_file(../../../VERSION VERSION COPYONLY)
configure_file(__init__.py __init__.py COPYONLY)
configure_file(shared_memory/__init__.py shared_memory/__init__.py COPYONLY)
configure_file(setup.py setup.py COPYONLY)

add_custom_command(
Expand Down Expand Up @@ -70,6 +80,7 @@ install(
simple_client.py
simple_callback_client.py
simple_string_client.py
simple_shm_client.py
simple_sequence_client.py
DESTINATION python
)
Expand Down
Loading