forked from triton-inference-server/server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.h
138 lines (122 loc) · 6.25 KB
/
common.h
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
// Copyright 2019-2022, NVIDIA CORPORATION & AFFILIATES. 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.
#pragma once
#include <iostream>
#include <string>
#include <vector>
#include "triton/core/tritonserver.h"
namespace triton { namespace server {
constexpr char kInferHeaderContentLengthHTTPHeader[] =
"Inference-Header-Content-Length";
constexpr char kAcceptEncodingHTTPHeader[] = "Accept-Encoding";
constexpr char kContentEncodingHTTPHeader[] = "Content-Encoding";
constexpr char kContentTypeHeader[] = "Content-Type";
constexpr char kContentLengthHeader[] = "Content-Length";
constexpr int MAX_GRPC_MESSAGE_SIZE = INT32_MAX;
/// The value for a dimension in a shape that indicates that that
/// dimension can take on any size.
constexpr int WILDCARD_DIM = -1;
#define RETURN_IF_ERR(X) \
do { \
TRITONSERVER_Error* err__ = (X); \
if (err__ != nullptr) { \
return err__; \
} \
} while (false)
#define RETURN_MSG_IF_ERR(X, MSG) \
do { \
TRITONSERVER_Error* err__ = (X); \
if (err__ != nullptr) { \
return TRITONSERVER_ErrorNew( \
TRITONSERVER_ErrorCode(err__), \
(std::string(MSG) + ": " + TRITONSERVER_ErrorMessage(err__)) \
.c_str()); \
} \
} while (false)
#define GOTO_IF_ERR(X, T) \
do { \
TRITONSERVER_Error* err__ = (X); \
if (err__ != nullptr) { \
goto T; \
} \
} while (false)
#define FAIL(MSG) \
do { \
std::cerr << "error: " << (MSG) << std::endl; \
exit(1); \
} while (false)
#define FAIL_IF_ERR(X, MSG) \
do { \
TRITONSERVER_Error* err__ = (X); \
if (err__ != nullptr) { \
std::cerr << "error: " << (MSG) << ": " \
<< TRITONSERVER_ErrorCodeString(err__) << " - " \
<< TRITONSERVER_ErrorMessage(err__) << std::endl; \
TRITONSERVER_ErrorDelete(err__); \
exit(1); \
} \
} while (false)
#define IGNORE_ERR(X) \
do { \
TRITONSERVER_Error* err__ = (X); \
if (err__ != nullptr) { \
TRITONSERVER_ErrorDelete(err__); \
} \
} while (false)
#ifdef TRITON_ENABLE_GPU
#define FAIL_IF_CUDA_ERR(X, MSG) \
do { \
cudaError_t err__ = (X); \
if (err__ != cudaSuccess) { \
std::cerr << "error: " << (MSG) << ": " << cudaGetErrorString(err__) \
<< std::endl; \
exit(1); \
} \
} while (false)
#endif // TRITON_ENABLE_GPU
/// Get the integral version from a string, or fail if string does not
/// represent a valid version.
///
/// \param version_string The string version.
/// \param version Returns the integral version.
/// \return The error status. Failure if 'version_string' doesn't
/// convert to valid version.
TRITONSERVER_Error* GetModelVersionFromString(
const std::string& version_string, int64_t* version);
/// Get the value of the environment variable, or default value if not set
///
/// \param variable_name The name of the environment variable.
/// \param default_value The default value.
/// \return The environment variable or the default value if not set.
std::string GetEnvironmentVariableOrDefault(
const std::string& variable_name, const std::string& default_value);
/// Get the number of elements in a shape.
/// \param dims The shape.
/// \return The number of elements, or -1 if the number of elements
/// cannot be determined because the shape contains one or more
/// wilcard dimensions.
int64_t GetElementCount(const std::vector<int64_t>& dims);
}} // namespace triton::server