Skip to content

Commit b177852

Browse files
authored
Support Double-Type Inference Request/Response Parameters (#307)
* Support Double-Type Infer/Response Parameters
1 parent 9468f5f commit b177852

11 files changed

+76
-1
lines changed

include/triton/core/tritonbackend.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ struct TRITONBACKEND_Batcher;
9494
/// }
9595
///
9696
#define TRITONBACKEND_API_VERSION_MAJOR 1
97-
#define TRITONBACKEND_API_VERSION_MINOR 17
97+
#define TRITONBACKEND_API_VERSION_MINOR 18
9898

9999
/// Get the TRITONBACKEND API version supported by Triton. This value
100100
/// can be compared against the TRITONBACKEND_API_VERSION_MAJOR and
@@ -725,6 +725,16 @@ TRITONBACKEND_DECLSPEC TRITONSERVER_Error*
725725
TRITONBACKEND_ResponseSetBoolParameter(
726726
TRITONBACKEND_Response* response, const char* name, const bool value);
727727

728+
/// Set a double parameter in the response.
729+
///
730+
/// \param response The response.
731+
/// \param name The name of the parameter.
732+
/// \param value The value of the parameter.
733+
/// \return a TRITONSERVER_Error indicating success or failure.
734+
TRITONBACKEND_DECLSPEC TRITONSERVER_Error*
735+
TRITONBACKEND_ResponseSetDoubleParameter(
736+
TRITONBACKEND_Response* response, const char* name, const double value);
737+
728738
/// Create an output tensor in the response. The lifetime of the
729739
/// returned output tensor object matches that of the response and so
730740
/// the output tensor object should not be accessed after the response

include/triton/core/tritonserver.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ typedef enum TRITONSERVER_parametertype_enum {
182182
TRITONSERVER_PARAMETER_STRING,
183183
TRITONSERVER_PARAMETER_INT,
184184
TRITONSERVER_PARAMETER_BOOL,
185+
TRITONSERVER_PARAMETER_DOUBLE,
185186
TRITONSERVER_PARAMETER_BYTES
186187
} TRITONSERVER_ParameterType;
187188

@@ -1422,6 +1423,17 @@ TRITONSERVER_InferenceRequestSetBoolParameter(
14221423
struct TRITONSERVER_InferenceRequest* request, const char* key,
14231424
const bool value);
14241425

1426+
/// Set a double parameter in the request.
1427+
///
1428+
/// \param request The request.
1429+
/// \param key The name of the parameter.
1430+
/// \param value The value of the parameter.
1431+
/// \return a TRITONSERVER_Error indicating success or failure.
1432+
TRITONSERVER_DECLSPEC struct TRITONSERVER_Error*
1433+
TRITONSERVER_InferenceRequestSetDoubleParameter(
1434+
struct TRITONSERVER_InferenceRequest* request, const char* key,
1435+
const double value);
1436+
14251437
/// TRITONSERVER_InferenceResponse
14261438
///
14271439
/// Object representing an inference response. The inference response

src/backend_model.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,15 @@ TRITONBACKEND_ResponseSetBoolParameter(
15691569
return nullptr; // success
15701570
}
15711571

1572+
TRITONAPI_DECLSPEC TRITONSERVER_Error*
1573+
TRITONBACKEND_ResponseSetDoubleParameter(
1574+
TRITONBACKEND_Response* response, const char* name, const double value)
1575+
{
1576+
InferenceResponse* tr = reinterpret_cast<InferenceResponse*>(response);
1577+
RETURN_TRITONSERVER_ERROR_IF_ERROR(tr->AddParameter(name, value));
1578+
return nullptr; // success
1579+
}
1580+
15721581
TRITONAPI_DECLSPEC TRITONSERVER_Error*
15731582
TRITONBACKEND_ResponseOutput(
15741583
TRITONBACKEND_Response* response, TRITONBACKEND_Output** output,

src/infer_parameter.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ InferenceParameter::ValuePointer() const
3939
return reinterpret_cast<const void*>(&value_int64_);
4040
case TRITONSERVER_PARAMETER_BOOL:
4141
return reinterpret_cast<const void*>(&value_bool_);
42+
case TRITONSERVER_PARAMETER_DOUBLE:
43+
return reinterpret_cast<const void*>(&value_double_);
4244
case TRITONSERVER_PARAMETER_BYTES:
4345
return reinterpret_cast<const void*>(value_bytes_);
4446
default:

src/infer_parameter.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ class InferenceParameter {
5555
{
5656
}
5757

58+
InferenceParameter(const char* name, const double value)
59+
: name_(name), type_(TRITONSERVER_PARAMETER_DOUBLE), value_double_(value),
60+
byte_size_(sizeof(double))
61+
{
62+
}
63+
5864
InferenceParameter(const char* name, const void* ptr, const uint64_t size)
5965
: name_(name), type_(TRITONSERVER_PARAMETER_BYTES), value_bytes_(ptr),
6066
byte_size_(size)
@@ -73,6 +79,7 @@ class InferenceParameter {
7379
// TRITONSERVER_PARAMETER_STRING -> const char*
7480
// TRITONSERVER_PARAMETER_INT -> int64_t*
7581
// TRITONSERVER_PARAMETER_BOOL -> bool*
82+
// TRITONSERVER_PARAMETER_DOUBLE -> double*
7683
// TRITONSERVER_PARAMETER_BYTES -> const void*
7784
const void* ValuePointer() const;
7885

@@ -93,6 +100,7 @@ class InferenceParameter {
93100
std::string value_string_;
94101
int64_t value_int64_;
95102
bool value_bool_;
103+
double value_double_;
96104
const void* value_bytes_;
97105
uint64_t byte_size_;
98106
};

src/infer_request.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,13 @@ InferenceRequest::AddParameter(const char* name, const bool value)
266266
return Status::Success;
267267
}
268268

269+
Status
270+
InferenceRequest::AddParameter(const char* name, const double value)
271+
{
272+
parameters_.emplace_back(name, value);
273+
return Status::Success;
274+
}
275+
269276
Status
270277
InferenceRequest::SetParameters(
271278
const std::deque<InferenceParameter>& parameters)

src/infer_request.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ class InferenceRequest {
372372
Status AddParameter(const char* name, const char* value);
373373
Status AddParameter(const char* name, const int64_t value);
374374
Status AddParameter(const char* name, const bool value);
375+
Status AddParameter(const char* name, const double value);
375376
Status SetParameters(const std::deque<InferenceParameter>& parameters);
376377
const std::deque<InferenceParameter>& Parameters() const
377378
{

src/infer_response.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ InferenceResponse::AddParameter(const char* name, const bool value)
131131
return Status::Success;
132132
}
133133

134+
Status
135+
InferenceResponse::AddParameter(const char* name, const double value)
136+
{
137+
parameters_.emplace_back(name, value);
138+
return Status::Success;
139+
}
140+
134141
Status
135142
InferenceResponse::AddOutput(
136143
const std::string& name, const inference::DataType datatype,

src/infer_response.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ class InferenceResponse {
258258
Status AddParameter(const char* name, const char* value);
259259
Status AddParameter(const char* name, const int64_t value);
260260
Status AddParameter(const char* name, const bool value);
261+
Status AddParameter(const char* name, const double value);
261262

262263
// The response outputs.
263264
const std::deque<Output>& Outputs() const { return outputs_; }

src/tritonserver.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,6 +2036,16 @@ TRITONSERVER_InferenceRequestSetBoolParameter(
20362036
return nullptr; // success
20372037
}
20382038

2039+
TRITONAPI_DECLSPEC TRITONSERVER_Error*
2040+
TRITONSERVER_InferenceRequestSetDoubleParameter(
2041+
TRITONSERVER_InferenceRequest* request, const char* name,
2042+
const double value)
2043+
{
2044+
tc::InferenceRequest* tr = reinterpret_cast<tc::InferenceRequest*>(request);
2045+
RETURN_IF_STATUS_ERROR(tr->AddParameter(name, value));
2046+
return nullptr; // success
2047+
}
2048+
20392049
//
20402050
// TRITONSERVER_InferenceResponse
20412051
//

0 commit comments

Comments
 (0)