forked from triton-inference-server/server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.client
273 lines (223 loc) · 10.7 KB
/
Makefile.client
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of NVIDIA CORPORATION nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
## Makefile for TensorRT Inference Server client library and examples
BUILDDIR ?= build
CFLAGS ?= -std=c++11 -fPIC -Wall -Werror -O2
#==============================================================================
MAKEFILE_NAME := $(lastword $(MAKEFILE_LIST))
MAKEFILE_DIR := $(dir $(abspath $(MAKEFILE_NAME)))
VERSION := `cat $(MAKEFILE_DIR)VERSION`
SRCDIR = src
CPPDIR := $(SRCDIR)/clients/c++
PYTHONDIR := $(SRCDIR)/clients/python
BDISTDIR := $(BUILDDIR)/dist
LIBGRPCDIR := $(shell pwd)/$(BUILDDIR)/grpc
LIBGRPC_BASE := libgrpc++.a \
libgrpc.a
LIBGRPC := $(addprefix $(LIBGRPCDIR)/lib/, $(LIBGRPC_BASE))
LIBPROTOBUF := $(LIBGRPCDIR)/grpc/libs/opt/protobuf/libprotobuf.a
IMAGE_SRCS := $(CPPDIR)/image_client.cc
IMAGE_OBJS := $(addprefix $(BUILDDIR)/, $(IMAGE_SRCS:%.cc=%.o))
IMAGE_LDFLAGS := $(LIBGRPC) $(LIBPROTOBUF) -lcurl -lz -lpthread \
`pkg-config --libs opencv` -ldl
ENSEMBLE_SRCS := $(CPPDIR)/ensemble_image_client.cc
ENSEMBLE_OBJS := $(addprefix $(BUILDDIR)/, $(ENSEMBLE_SRCS:%.cc=%.o))
ENSEMBLE_LDFLAGS := $(LIBGRPC) $(LIBPROTOBUF) -lcurl -lz -lpthread -ldl
PERF_SRCS := $(CPPDIR)/perf_client.cc
PERF_OBJS := $(addprefix $(BUILDDIR)/, $(PERF_SRCS:%.cc=%.o))
PERF_LDFLAGS := $(LIBGRPC) $(LIBPROTOBUF) -lcurl -lz -lpthread -ldl
SIMPLE_SRCS := $(CPPDIR)/simple_client.cc
SIMPLE_OBJS := $(addprefix $(BUILDDIR)/, $(SIMPLE_SRCS:%.cc=%.o))
SIMPLE_LDFLAGS := $(LIBGRPC) $(LIBPROTOBUF) -lcurl -lz -lpthread -ldl
SIMPSEQ_SRCS := $(CPPDIR)/simple_sequence_client.cc
SIMPSEQ_OBJS := $(addprefix $(BUILDDIR)/, $(SIMPSEQ_SRCS:%.cc=%.o))
SIMPSEQ_LDFLAGS := $(LIBGRPC) $(LIBPROTOBUF) -lcurl -lz -lpthread -ldl
SIMPSTR_SRCS := $(CPPDIR)/simple_string_client.cc
SIMPSTR_OBJS := $(addprefix $(BUILDDIR)/, $(SIMPSTR_SRCS:%.cc=%.o))
SIMPSTR_LDFLAGS := $(LIBGRPC) $(LIBPROTOBUF) -lcurl -lz -lpthread -ldl
LIBREQ_SRCS := $(PYTHONDIR)/crequest.cc
LIBREQ_OBJS := $(addprefix $(BUILDDIR)/, $(LIBREQ_SRCS:%.cc=%.o))
LIBREQ_LDFLAGS := $(LIBGRPC) $(LIBPROTOBUF) -lcurl -lz -ldl
CMN_SRCS := $(CPPDIR)/request.cc $(CPPDIR)/request_common.cc $(CPPDIR)/request_grpc.cc \
$(CPPDIR)/request_http.cc $(SRCDIR)/core/model_config.cc
CMN_OBJS := $(addprefix $(BUILDDIR)/, $(CMN_SRCS:%.cc=%.o))
CMN_LDFLAGS := $(LIBGRPC) $(LIBPROTOBUF) -ldl
PY_SRCS := $(PYTHONDIR)/__init__.py
PY_SETUP := $(PYTHONDIR)/setup.py
PROTOS := $(SRCDIR)/core/api.proto \
$(SRCDIR)/core/grpc_service.proto \
$(SRCDIR)/core/model_config.proto \
$(SRCDIR)/core/request_status.proto \
$(SRCDIR)/core/server_status.proto
PROTO_CP := $(addprefix $(BUILDDIR)/, $(PROTOS))
PROTO_HDRS := $(addprefix $(BUILDDIR)/, $(PROTOS:%.proto=%.pb.h))
PROTO_SRCS := $(PROTO_HDRS:.h=.cc)
PROTO_PY := $(PROTO_HDRS:.pb.h=_pb2.py)
PROTO_OBJS := $(PROTO_SRCS:.cc=.o)
GRPC_PROTO := core/grpc_service.proto
GRPC_HDRS := $(addprefix $(BUILDDIR)/, $(SRCDIR)/core/grpc_service.grpc.pb.h)
GRPC_SRCS := $(GRPC_HDRS:.h=.cc)
GRPC_OBJS := $(GRPC_SRCS:.cc=.o)
GRPC_PY := $(GRPC_HDRS:.grpc.pb.h=_pb2_grpc.py)
PROTOC := $(LIBGRPCDIR)/grpc/bins/opt/protobuf/protoc
PROTOBUF_INCLUDE_PATH := $(LIBGRPCDIR)/grpc/third_party/protobuf/src
CFLAGS += -MMD -MP
INCS += -I.
INCS += -I$(BUILDDIR)
INCS += -I$(LIBGRPCDIR)/include
INCS += -I$(PROTOBUF_INCLUDE_PATH)
DEPS = $(IMAGE_OBJS:.o=.d) $(ENSEMBLE_OBJS:.o=.d) $(PERF_OBJS:.o=.d) \
$(SIMPLE_OBJS:.o=.d) $(SIMPSEQ_OBJS:.o=.d) $(SIMPSTR_OBJS:.o=.d) \
$(CMN_OBJS:.o=.d) $(LIBREQ_OBJS:.o=.d) \
$(PROTO_OBJS:.o=.d) $(GRPC_OBJS:.o=.d)
.PHONY: all pip grpc protobuf clean help show
.SUFFIXES:
.SECONDARY: $(PROTO_HDRS) $(PROTO_SRCS) $(PROTO_PY) $(PROTO_CP)
all: pip $(BUILDDIR)/librequest.so $(BUILDDIR)/librequest.a \
$(BUILDDIR)/image_client $(BUILDDIR)/ensemble_image_client \
$(BUILDDIR)/perf_client $(BUILDDIR)/simple_client \
$(BUILDDIR)/simple_sequence_client $(BUILDDIR)/simple_string_client
# Need to fix protoc compiled imports (see
# https://github.com/google/protobuf/issues/1491). The 'sed' command
# below does this fix.
pip: $(PY_SRCS) $(GRPC_PY) $(PROTO_PY) $(BUILDDIR)/src/clients/python/libcrequest.so
$(RM) -fr $(BDISTDIR)
mkdir -p $(BDISTDIR)/tensorrtserver/api
cp $^ $(BDISTDIR)/tensorrtserver/api/.
sed -i "s/^import \([^ ]*\)_pb2 as \([^ ]*\)$$/from tensorrtserver.api import \1_pb2 as \2/" \
$(BDISTDIR)/tensorrtserver/api/*_pb2.py
sed -i "s/^import \([^ ]*\)_pb2 as \([^ ]*\)$$/from tensorrtserver.api import \1_pb2 as \2/" \
$(BDISTDIR)/tensorrtserver/api/*_pb2_grpc.py
cp $(PY_SETUP) $(BDISTDIR)/.
touch $(BDISTDIR)/tensorrtserver/__init__.py
(cd $(BDISTDIR) && VERSION=$(VERSION) python$(PYVER) setup.py bdist_wheel)
# Use libgrpc_indicator file to prevent GRPC from rebuilding
# unnecessaily
grpc: $(LIBGRPCDIR)/libgrpc_indicator
$(LIBGRPCDIR)/libgrpc_indicator:
mkdir -p $(LIBGRPCDIR)
# Build gRPc v1.19.0 since it is a known good build. Change to
# "git clone -b $(shell curl -L https://grpc.io/release)"
# to build with the latest release of gRPC
git clone -b v1.19.0 \
https://github.com/grpc/grpc $(LIBGRPCDIR)/grpc
cd $(LIBGRPCDIR)/grpc && \
git submodule update --checkout --init && \
$(MAKE) -j"$(nproc)" prefix=$(LIBGRPCDIR) install
touch $(LIBGRPCDIR)/libgrpc_indicator
protobuf: $(PROTO_HDRS) $(PROTO_SRCS) $(PROTO_PY)
$(PYTHONDIR)/crequest.cc $(PYTHONDIR)/crequest.h: $(GRPC_HDRS)
$(BUILDDIR)/src/clients/python/libcrequest.so: $(LIBREQ_OBJS) $(PROTO_OBJS) $(GRPC_OBJS) $(CMN_OBJS)
$(CXX) -shared -o $@ $^ $(LIBREQ_LDFLAGS)
$(BUILDDIR)/librequest.so: $(CMN_OBJS)
$(CXX) -shared -o $@ $^ $(CMN_LDFLAGS)
$(BUILDDIR)/librequest.a: $(CMN_OBJS)
ar rvs $@ $^
$(BUILDDIR)/image_client: $(IMAGE_OBJS) $(PROTO_OBJS) $(GRPC_OBJS) $(CMN_OBJS)
$(CXX) -o $@ $^ $(IMAGE_LDFLAGS)
$(BUILDDIR)/ensemble_image_client: $(ENSEMBLE_OBJS) $(PROTO_OBJS) $(GRPC_OBJS) $(CMN_OBJS)
$(CXX) -o $@ $^ $(ENSEMBLE_LDFLAGS)
$(BUILDDIR)/perf_client: $(PERF_OBJS) $(PROTO_OBJS) $(GRPC_OBJS) $(CMN_OBJS)
$(CXX) -o $@ $^ $(PERF_LDFLAGS)
$(BUILDDIR)/simple_client: $(SIMPLE_OBJS) $(PROTO_OBJS) $(GRPC_OBJS) $(CMN_OBJS)
$(CXX) -o $@ $^ $(SIMPLE_LDFLAGS)
$(BUILDDIR)/simple_sequence_client: $(SIMPSEQ_OBJS) $(PROTO_OBJS) $(GRPC_OBJS) $(CMN_OBJS)
$(CXX) -o $@ $^ $(SIMPSEQ_LDFLAGS)
$(BUILDDIR)/simple_string_client: $(SIMPSTR_OBJS) $(PROTO_OBJS) $(GRPC_OBJS) $(CMN_OBJS)
$(CXX) -o $@ $^ $(SIMPSTR_LDFLAGS)
$(BUILDDIR)/$(SRCDIR)/%.o: $(SRCDIR)/%.cc $(PROTO_HDRS) grpc
mkdir -p $(dir $@)
$(CXX) $(CFLAGS) $(INCS) -c $< -o $@
$(BUILDDIR)/%.pb.o: $(BUILDDIR)/%.pb.cc $(PROTO_HDRS)
mkdir -p $(dir $@)
$(CXX) $(CFLAGS) $(INCS) -c $< -o $@
$(GRPC_OBJS): $(GRPC_SRCS) $(GRPC_HDRS)
mkdir -p $(dir $@)
$(CXX) $(CFLAGS) $(INCS) -c $< -o $@
$(BUILDDIR)/$(SRCDIR)/%.proto: $(SRCDIR)/%.proto
mkdir -p $(dir $@)
cp $< $@
sed -i -e 's/src\/core\///' $@
$(BUILDDIR)/$(SRCDIR)/%.pb.cc $(BUILDDIR)/$(SRCDIR)/%.pb.h \
$(BUILDDIR)/$(SRCDIR)/%_pb2.py: $(BUILDDIR)/$(SRCDIR)/%.proto grpc
mkdir -p $(dir $<)
$(PROTOC) -I$(dir $<) --cpp_out=$(dir $<) --python_out=$(dir $<) $<
# Make sure other protobuf files are ready before compiling GRPC protobuf
# because adding $(PROTO_CP) as dependency for $(GRPC_SRCS) $(GRPC_HDRS)
# doesn't work as expected
$(BUILDDIR)/$(SRCDIR)/$(GRPC_PROTO): $(PROTO_CP)
$(GRPC_SRCS) $(GRPC_HDRS): $(BUILDDIR)/$(SRCDIR)/$(GRPC_PROTO) grpc
$(PROTOC) -I$(dir $<) --grpc_out=$(dir $<) \
--plugin=protoc-gen-grpc=$(LIBGRPCDIR)/bin/grpc_cpp_plugin $<
$(GRPC_PY): $(BUILDDIR)/$(SRCDIR)/$(GRPC_PROTO)
python$(PYVER) -m grpc_tools.protoc -I$(dir $<) --grpc_python_out=$(dir $<) $<
python$(PYVER) -m grpc_tools.protoc -I$(dir $<) --python_out=$(dir $<) $<
-include $(DEPS)
clean:
$(RM) -fr $(BUILDDIR)
# Show help.
help:
@echo 'TensorRT Inference Server Client Makefile'
@echo
@echo 'Usage: make [TARGET]'
@echo 'TARGETS:'
@echo ' all compile and link'
@echo ' pip create whl for python client'
@echo ' grpc git clone and build grpc libraries'
@echo ' protobuf generate protobuf *.pb.h and *.pb.cc'
@echo ' clean clean all build artifacts'
@echo ' show show variables'
@echo ' help print this message'
# Show variables
show:
@echo 'VERSION :' $(VERSION)
@echo 'BUILDDIR :' $(BUILDDIR)
@echo 'SRCDIR :' $(SRCDIR)
@echo 'CPPDIR :' $(CPPDIR)
@echo 'PYTHONDIR :' $(PYTHONDIR)
@echo 'CFLAGS :' $(CFLAGS)
@echo 'INCS :' $(INCS)
@echo 'IMAGE_SRCS :' $(IMAGE_SRCS)
@echo 'IMAGE_OBJS :' $(IMAGE_OBJS)
@echo 'ENSEMBLE_SRCS :' $(ENSEMBLE_SRCS)
@echo 'ENSEMBLE_OBJS :' $(ENSEMBLE_OBJS)
@echo 'PERF_SRCS :' $(PERF_SRCS)
@echo 'PERF_OBJS :' $(PERF_OBJS)
@echo 'SIMPLE_SRCS :' $(SIMPLE_SRCS)
@echo 'SIMPLE_OBJS :' $(SIMPLE_OBJS)
@echo 'SIMPSEQ_SRCS :' $(SIMPSEQ_SRCS)
@echo 'SIMPSEQ_OBJS :' $(SIMPSEQ_OBJS)
@echo 'SIMPSTR_SRCS :' $(SIMPSTR_SRCS)
@echo 'SIMPSTR_OBJS :' $(SIMPSTR_OBJS)
@echo 'CMN_SRCS :' $(CMN_SRCS)
@echo 'CMN_OBJS :' $(CMN_OBJS)
@echo 'LIBREQ_SRCS :' $(LIBREQ_SRCS)
@echo 'LIBREQ_OBJS :' $(LIBREQ_OBJS)
@echo 'PROTOS :' $(PROTOS)
@echo 'PROTO_HDRS :' $(PROTO_HDRS)
@echo 'PROTO_SRCS :' $(PROTO_SRCS)
@echo 'PROTO_OBJS :' $(PROTO_OBJS)
@echo 'DEPS :' $(DEPS)