Skip to content

Commit 55dac42

Browse files
committed
Merge Win/Unix functions. Opaque shm file handling
1 parent 4f8273e commit 55dac42

File tree

9 files changed

+112
-170
lines changed

9 files changed

+112
-170
lines changed

src/python/CMakeLists.txt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# Copyright 2021-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
#
33
# Redistribution and use in source and binary forms, with or without
44
# modification, are permitted provided that the following conditions
@@ -45,13 +45,6 @@ if(NOT CMAKE_BUILD_TYPE)
4545
set(CMAKE_BUILD_TYPE Release)
4646
endif()
4747

48-
# FIXME: Windows client currently does not support GPU tensors.
49-
# For simplicity, we will override this option here.
50-
if(WIN32 AND TRITON_ENABLE_GPU)
51-
message("GPU shared memory is not currently supported by the Windows python client. Forcing TRITON_ENABLE_GPU to false.")
52-
set(TRITON_ENABLE_GPU OFF CACHE BOOL "GPU disabled" FORCE)
53-
endif()
54-
5548
#
5649
# Dependencies
5750
#

src/python/library/CMakeLists.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2020-2021, NVIDIA CORPORATION. All rights reserved.
1+
# Copyright (c) 2020-2024, NVIDIA CORPORATION. All rights reserved.
22
#
33
# Redistribution and use in source and binary forms, with or without
44
# modification, are permitted provided that the following conditions
@@ -180,13 +180,13 @@ endif() # TRITON_ENABLE_PYTHON_GRPC
180180

181181

182182
if(WIN32)
183-
install(
184-
CODE "file(GLOB _Wheel \"${CMAKE_CURRENT_BINARY_DIR}/windows/triton*.whl\")"
185-
CODE "file(INSTALL \${_Wheel} DESTINATION \"${CMAKE_INSTALL_PREFIX}/python\")"
186-
)
183+
set(WHEEL_DIR "${CMAKE_CURRENT_BINARY_DIR}/windows")
187184
else()
188-
install(
189-
CODE "file(GLOB _Wheel \"${CMAKE_CURRENT_BINARY_DIR}/linux/triton*.whl\")"
190-
CODE "file(INSTALL \${_Wheel} DESTINATION \"${CMAKE_INSTALL_PREFIX}/python\")"
191-
)
192-
endif() # NOT WIN32
185+
set(WHEEL_DIR "${CMAKE_CURRENT_BINARY_DIR}/linux")
186+
endif() # WIN32
187+
188+
install(
189+
CODE "file(GLOB _Wheel \"${WHEEL_DIR}/triton*.whl\")"
190+
CODE "file(INSTALL \${_Wheel} DESTINATION \"${CMAKE_INSTALL_PREFIX}/python\")"
191+
)
192+

src/python/library/build_wheel.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
2-
# Copyright 2021-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# Copyright 2021-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
33
#
44
# Redistribution and use in source and binary forms, with or without
55
# modification, are permitted provided that the following conditions
@@ -78,13 +78,14 @@ def sed(pattern, replace, source, dest=None):
7878
parser.add_argument(
7979
"--dest-dir", type=str, required=True, help="Destination directory."
8080
)
81-
parser.add_argument(
81+
platform_group = parser.add_mutually_exclusive_group()
82+
platform_group.add_argument(
8283
"--linux",
8384
action="store_true",
8485
required=False,
8586
help="Include linux specific artifacts.",
8687
)
87-
parser.add_argument(
88+
platform_group.add_argument(
8889
"--windows",
8990
action="store_true",
9091
required=False,
@@ -210,7 +211,7 @@ def sed(pattern, replace, source, dest=None):
210211
"tritonclient/utils/Release/cshm.dll",
211212
os.path.join(FLAGS.whl_dir, "tritonclient/utils/shared_memory/cshm.dll"),
212213
)
213-
# FIXME: Enable when Windows supports GPU tensors
214+
# FIXME: Enable when Windows supports GPU tensors DLIS-4169
214215
# cpdir(
215216
# "tritonclient/utils/cuda_shared_memory",
216217
# os.path.join(FLAGS.whl_dir, "tritonclient/utils/cuda_shared_memory"),

src/python/library/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22

3-
# Copyright 2020-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
# Copyright 2020-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
44
#
55
# Redistribution and use in source and binary forms, with or without
66
# modification, are permitted provided that the following conditions

src/python/library/tritonclient/utils/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2020-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# Copyright 2020-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
#
33
# Redistribution and use in source and binary forms, with or without
44
# modification, are permitted provided that the following conditions
@@ -24,6 +24,13 @@
2424
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2525
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626

27+
# FIXME: Windows client currently does not support GPU tensors.
28+
# For simplicity, we will override this option here.
29+
if(WIN32 AND TRITON_ENABLE_GPU)
30+
message(FATAL_ERROR "GPU shared memory is not currently supported by the Windows python client.")
31+
set(TRITON_ENABLE_GPU OFF CACHE BOOL "GPU disabled" FORCE)
32+
endif()
33+
2734
configure_file(__init__.py __init__.py COPYONLY)
2835
configure_file(_dlpack.py _dlpack.py COPYONLY)
2936
configure_file(_shared_memory_tensor.py _shared_memory_tensor.py COPYONLY)
@@ -40,7 +47,7 @@ endif() # TRITON_ENABLE_GPU
4047

4148
if(NOT WIN32)
4249
target_link_libraries(cshm PRIVATE rt)
43-
endif() # WIN32
50+
endif() # NOT WIN32
4451

4552
configure_file(shared_memory/__init__.py shared_memory/__init__.py COPYONLY)
4653

src/python/library/tritonclient/utils/shared_memory/__init__.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22

3-
# Copyright 2019-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
# Copyright 2019-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
44
#
55
# Redistribution and use in source and binary forms, with or without
66
# modification, are permitted provided that the following conditions
@@ -63,7 +63,7 @@ def from_param(cls, value):
6363
c_void_p,
6464
POINTER(c_char_p),
6565
POINTER(c_char_p),
66-
POINTER(c_int),
66+
POINTER(c_void_p),
6767
POINTER(c_uint64),
6868
POINTER(c_uint64),
6969
]
@@ -205,7 +205,7 @@ def get_contents_as_numpy(shm_handle, datatype, shape, offset=0):
205205
The numpy array generated using the contents of the specified shared
206206
memory region.
207207
"""
208-
shm_fd = c_int()
208+
shm_file = c_void_p()
209209
region_offset = c_uint64()
210210
byte_size = c_uint64()
211211
shm_addr = c_char_p()
@@ -216,7 +216,7 @@ def get_contents_as_numpy(shm_handle, datatype, shape, offset=0):
216216
shm_handle,
217217
byref(shm_addr),
218218
byref(shm_key),
219-
byref(shm_fd),
219+
byref(shm_file),
220220
byref(region_offset),
221221
byref(byte_size),
222222
)
@@ -285,9 +285,7 @@ def destroy_shared_memory_region(shm_handle):
285285
If unable to unlink the shared memory region.
286286
"""
287287

288-
_raise_if_error(c_int(_cshm_shared_memory_region_destroy(shm_handle)))
289-
290-
shm_fd = c_int()
288+
shm_file = c_void_p()
291289
offset = c_uint64()
292290
byte_size = c_uint64()
293291
shm_addr = c_char_p()
@@ -298,13 +296,16 @@ def destroy_shared_memory_region(shm_handle):
298296
shm_handle,
299297
byref(shm_addr),
300298
byref(shm_key),
301-
byref(shm_fd),
299+
byref(shm_file),
302300
byref(offset),
303301
byref(byte_size),
304302
)
305303
)
306304
)
307-
mapped_shm_regions.remove(shm_key.value.decode("utf-8"))
305+
shm_key_copy = bytes(shm_key.value)
306+
_raise_if_error(c_int(_cshm_shared_memory_region_destroy(shm_handle)))
307+
308+
mapped_shm_regions.remove(shm_key_copy.decode("utf-8"))
308309

309310
return
310311

0 commit comments

Comments
 (0)