Skip to content

Commit 93d2e51

Browse files
committed
Initial commit
1 parent c63d09e commit 93d2e51

File tree

9 files changed

+266
-41
lines changed

9 files changed

+266
-41
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ if(NOT TRITON_ENABLE_PYTHON_GRPC)
6464
set(TRITON_COMMON_ENABLE_PROTOBUF_PYTHON OFF)
6565
endif()
6666

67+
# FIXME: Windows client currently does not support GPU tensors.
68+
# For simplicity, we will override this option here.
69+
if(WIN32 AND TRITON_ENABLE_GPU)
70+
message("GPU shared memory is not currently supported by the Windows client. Forcing TRITON_ENABLE_GPU to false.")
71+
set(TRITON_ENABLE_GPU OFF CACHE BOOL "GPU disabled" FORCE)
72+
endif()
73+
6774
#
6875
# Dependencies
6976
#

src/python/library/CMakeLists.txt

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ if(${TRITON_ENABLE_PYTHON_HTTP})
3838
file(COPY tritonhttpclient DESTINATION .)
3939
endif() # TRITON_ENABLE_PYTHON_HTTP
4040
file(COPY tritonclientutils DESTINATION .)
41-
if (NOT WIN32)
42-
file(COPY tritonshmutils DESTINATION .)
43-
endif() # NOT WIN32
41+
file(COPY tritonshmutils DESTINATION .)
4442
####################################
4543

4644
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/TRITON_VERSION ${TRITON_VERSION})
@@ -90,6 +88,35 @@ add_custom_target(
9088
"${wheel_stamp_file}"
9189
)
9290

91+
#
92+
# Windows-specific Wheel file.
93+
#
94+
if(WIN32)
95+
set(WINDOWS_WHEEL_DEPENDS
96+
cshm
97+
${WHEEL_DEPENDS}
98+
)
99+
100+
if (${TRITON_ENABLE_PERF_ANALYZER})
101+
set(perf_analyzer_arg --perf-analyzer ${CMAKE_INSTALL_PREFIX}/bin/perf_analyzer)
102+
endif()
103+
set(windows_wheel_stamp_file "windows_stamp.whl")
104+
add_custom_command(
105+
OUTPUT "${windows_wheel_stamp_file}"
106+
COMMAND python3
107+
ARGS
108+
"${CMAKE_CURRENT_SOURCE_DIR}/build_wheel.py"
109+
--dest-dir "${CMAKE_CURRENT_BINARY_DIR}/windows"
110+
--windows
111+
${perf_analyzer_arg}
112+
DEPENDS ${LINUX_WHEEL_DEPENDS}
113+
)
114+
115+
add_custom_target(
116+
windows-client-wheel ALL
117+
DEPENDS
118+
"${windows_wheel_stamp_file}"
119+
)
93120
#
94121
# Linux specific Wheel file. Compatible with x86, x64 and aarch64
95122
#
@@ -147,14 +174,20 @@ if(${TRITON_ENABLE_PYTHON_GRPC})
147174
)
148175
endif() # TRITON_ENABLE_PYTHON_GRPC
149176

150-
install(
151-
CODE "file(GLOB _Wheel \"${CMAKE_CURRENT_BINARY_DIR}/generic/triton*.whl\")"
152-
CODE "file(INSTALL \${_Wheel} DESTINATION \"${CMAKE_INSTALL_PREFIX}/python\")"
153-
)
154177

155-
if (NOT WIN32)
178+
if(WIN32)
179+
install(
180+
CODE "file(GLOB _Wheel \"${CMAKE_CURRENT_BINARY_DIR}/windows/triton*.whl\")"
181+
CODE "file(INSTALL \${_Wheel} DESTINATION \"${CMAKE_INSTALL_PREFIX}/python\")"
182+
)
183+
elseif(NOT WIN32)
156184
install(
157185
CODE "file(GLOB _Wheel \"${CMAKE_CURRENT_BINARY_DIR}/linux/triton*.whl\")"
158186
CODE "file(INSTALL \${_Wheel} DESTINATION \"${CMAKE_INSTALL_PREFIX}/python\")"
159187
)
188+
else()
189+
install(
190+
CODE "file(GLOB _Wheel \"${CMAKE_CURRENT_BINARY_DIR}/generic/triton*.whl\")"
191+
CODE "file(INSTALL \${_Wheel} DESTINATION \"${CMAKE_INSTALL_PREFIX}/python\")"
192+
)
160193
endif() # NOT WIN32

src/python/library/build_wheel.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import argparse
2929
import os
3030
import pathlib
31+
import platform
3132
import re
3233
import shutil
3334
import subprocess
@@ -83,6 +84,12 @@ def sed(pattern, replace, source, dest=None):
8384
required=False,
8485
help="Include linux specific artifacts.",
8586
)
87+
parser.add_argument(
88+
"--windows",
89+
action="store_true",
90+
required=False,
91+
help="Include windows specific artifacts.",
92+
)
8693
parser.add_argument(
8794
"--perf-analyzer",
8895
type=str,
@@ -118,7 +125,7 @@ def sed(pattern, replace, source, dest=None):
118125
cpdir("tritonhttpclient", os.path.join(FLAGS.whl_dir, "tritonhttpclient"))
119126
if os.path.isdir("tritongrpcclient"):
120127
cpdir("tritongrpcclient", os.path.join(FLAGS.whl_dir, "tritongrpcclient"))
121-
if FLAGS.linux:
128+
if FLAGS.linux or FLAGS.windows:
122129
if os.path.isdir("tritonshmutils"):
123130
cpdir("tritonshmutils", os.path.join(FLAGS.whl_dir, "tritonshmutils"))
124131

@@ -194,6 +201,21 @@ def sed(pattern, replace, source, dest=None):
194201
if not os.path.exists(os.path.join(FLAGS.whl_dir, "perf_client")):
195202
os.symlink("perf_analyzer", os.path.join(FLAGS.whl_dir, "perf_client"))
196203

204+
if FLAGS.windows:
205+
cpdir(
206+
"tritonclient/utils/shared_memory",
207+
os.path.join(FLAGS.whl_dir, "tritonclient/utils/shared_memory"),
208+
)
209+
shutil.copyfile(
210+
"tritonclient/utils/Release/cshm.dll",
211+
os.path.join(FLAGS.whl_dir, "tritonclient/utils/shared_memory/cshm.dll"),
212+
)
213+
# FIXME: Enable when Windows supports GPU tensors
214+
# cpdir(
215+
# "tritonclient/utils/cuda_shared_memory",
216+
# os.path.join(FLAGS.whl_dir, "tritonclient/utils/cuda_shared_memory"),
217+
# )
218+
197219
shutil.copyfile("LICENSE.txt", os.path.join(FLAGS.whl_dir, "LICENSE.txt"))
198220
shutil.copyfile("setup.py", os.path.join(FLAGS.whl_dir, "setup.py"))
199221
cpdir("requirements", os.path.join(FLAGS.whl_dir, "requirements"))
@@ -208,6 +230,9 @@ def sed(pattern, replace, source, dest=None):
208230
else:
209231
platform_name = "manylinux1_x86_64"
210232
args = ["python3", "setup.py", "bdist_wheel", "--plat-name", platform_name]
233+
elif FLAGS.windows and platform.uname().machine == "AMD64":
234+
platform_name = "win_amd64"
235+
args = ["python3", "setup.py", "bdist_wheel", "--plat-name", platform_name]
211236
else:
212237
args = ["python3", "setup.py", "bdist_wheel"]
213238

src/python/library/setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ def req_file(filename, folder="requirements"):
7676
extras_require["all"] = list(chain(extras_require.values()))
7777

7878
platform_package_data = []
79-
if PLATFORM_FLAG != "any":
79+
if "linux" in PLATFORM_FLAG:
8080
platform_package_data += ["libcshm.so"]
81+
elif PLATFORM_FLAG == "win_amd64":
82+
platform_package_data += ["cshm.dll"]
8183

8284
data_files = [
8385
("", ["LICENSE.txt"]),

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,23 @@ configure_file(__init__.py __init__.py COPYONLY)
2828
configure_file(_dlpack.py _dlpack.py COPYONLY)
2929
configure_file(_shared_memory_tensor.py _shared_memory_tensor.py COPYONLY)
3030

31-
if(NOT WIN32)
32-
file(COPY shared_memory DESTINATION .)
31+
file(COPY shared_memory DESTINATION .)
32+
#
33+
# libcshm.so / cshm.dll
34+
#
35+
add_library(cshm SHARED shared_memory/shared_memory.cc)
36+
if(${TRITON_ENABLE_GPU})
37+
target_compile_definitions(cshm PUBLIC TRITON_ENABLE_GPU=1)
38+
target_link_libraries(cshm PUBLIC CUDA::cudart)
39+
endif() # TRITON_ENABLE_GPU
3340

34-
#
35-
# libcshm.so
36-
#
37-
add_library(cshm SHARED shared_memory/shared_memory.cc)
38-
if(${TRITON_ENABLE_GPU})
39-
target_compile_definitions(cshm PUBLIC TRITON_ENABLE_GPU=1)
40-
target_link_libraries(cshm PUBLIC CUDA::cudart)
41-
endif() # TRITON_ENABLE_GPU
41+
if(NOT WIN32)
4242
target_link_libraries(cshm PRIVATE rt)
4343
endif() # WIN32
4444

45-
if(NOT WIN32)
46-
configure_file(shared_memory/__init__.py shared_memory/__init__.py COPYONLY)
45+
configure_file(shared_memory/__init__.py shared_memory/__init__.py COPYONLY)
46+
47+
if(${TRITON_ENABLE_GPU})
4748
configure_file(cuda_shared_memory/__init__.py cuda_shared_memory/__init__.py COPYONLY)
4849
configure_file(cuda_shared_memory/_utils.py cuda_shared_memory/_utils.py COPYONLY)
49-
endif() # NOT WIN32
50+
endif() # TRITON_ENABLE_GPU

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ def __init__(self, err):
326326
-4: "unable to read/mmap the shared memory region",
327327
-5: "unable to unlink the shared memory region",
328328
-6: "unable to munmap the shared memory region",
329+
-7: "unable to create file mapping",
329330
}
330331
self._msg = None
331332
if type(err) == str:

0 commit comments

Comments
 (0)