Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Double-Type Inference Request/Response Parameters #307

Merged
merged 5 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion include/triton/core/tritonbackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ struct TRITONBACKEND_Batcher;
/// }
///
#define TRITONBACKEND_API_VERSION_MAJOR 1
#define TRITONBACKEND_API_VERSION_MINOR 17
#define TRITONBACKEND_API_VERSION_MINOR 18

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

/// Set a double parameter in the response.
///
/// \param response The response.
/// \param name The name of the parameter.
/// \param value The value of the parameter.
/// \return a TRITONSERVER_Error indicating success or failure.
TRITONBACKEND_DECLSPEC TRITONSERVER_Error*
TRITONBACKEND_ResponseSetDoubleParameter(
TRITONBACKEND_Response* response, const char* name, const double value);

/// Create an output tensor in the response. The lifetime of the
/// returned output tensor object matches that of the response and so
/// the output tensor object should not be accessed after the response
Expand Down
12 changes: 12 additions & 0 deletions include/triton/core/tritonserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ typedef enum TRITONSERVER_parametertype_enum {
TRITONSERVER_PARAMETER_STRING,
TRITONSERVER_PARAMETER_INT,
TRITONSERVER_PARAMETER_BOOL,
TRITONSERVER_PARAMETER_DOUBLE,
TRITONSERVER_PARAMETER_BYTES
} TRITONSERVER_ParameterType;

Expand Down Expand Up @@ -1422,6 +1423,17 @@ TRITONSERVER_InferenceRequestSetBoolParameter(
struct TRITONSERVER_InferenceRequest* request, const char* key,
const bool value);

/// Set a double parameter in the request.
///
/// \param request The request.
/// \param key The name of the parameter.
/// \param value The value of the parameter.
/// \return a TRITONSERVER_Error indicating success or failure.
TRITONSERVER_DECLSPEC struct TRITONSERVER_Error*
TRITONSERVER_InferenceRequestSetDoubleParameter(
struct TRITONSERVER_InferenceRequest* request, const char* key,
const double value);

/// TRITONSERVER_InferenceResponse
///
/// Object representing an inference response. The inference response
Expand Down
9 changes: 9 additions & 0 deletions src/backend_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,15 @@ TRITONBACKEND_ResponseSetBoolParameter(
return nullptr; // success
}

TRITONAPI_DECLSPEC TRITONSERVER_Error*
TRITONBACKEND_ResponseSetDoubleParameter(
TRITONBACKEND_Response* response, const char* name, const double value)
{
InferenceResponse* tr = reinterpret_cast<InferenceResponse*>(response);
RETURN_TRITONSERVER_ERROR_IF_ERROR(tr->AddParameter(name, value));
return nullptr; // success
}

TRITONAPI_DECLSPEC TRITONSERVER_Error*
TRITONBACKEND_ResponseOutput(
TRITONBACKEND_Response* response, TRITONBACKEND_Output** output,
Expand Down
2 changes: 2 additions & 0 deletions src/infer_parameter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ InferenceParameter::ValuePointer() const
return reinterpret_cast<const void*>(&value_int64_);
case TRITONSERVER_PARAMETER_BOOL:
return reinterpret_cast<const void*>(&value_bool_);
case TRITONSERVER_PARAMETER_DOUBLE:
return reinterpret_cast<const void*>(&value_double_);
case TRITONSERVER_PARAMETER_BYTES:
return reinterpret_cast<const void*>(value_bytes_);
default:
Expand Down
8 changes: 8 additions & 0 deletions src/infer_parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ class InferenceParameter {
{
}

InferenceParameter(const char* name, const double value)
: name_(name), type_(TRITONSERVER_PARAMETER_DOUBLE), value_double_(value),
byte_size_(sizeof(double))
{
}

InferenceParameter(const char* name, const void* ptr, const uint64_t size)
: name_(name), type_(TRITONSERVER_PARAMETER_BYTES), value_bytes_(ptr),
byte_size_(size)
Expand All @@ -73,6 +79,7 @@ class InferenceParameter {
// TRITONSERVER_PARAMETER_STRING -> const char*
// TRITONSERVER_PARAMETER_INT -> int64_t*
// TRITONSERVER_PARAMETER_BOOL -> bool*
// TRITONSERVER_PARAMETER_DOUBLE -> double*
// TRITONSERVER_PARAMETER_BYTES -> const void*
const void* ValuePointer() const;

Expand All @@ -93,6 +100,7 @@ class InferenceParameter {
std::string value_string_;
int64_t value_int64_;
bool value_bool_;
double value_double_;
const void* value_bytes_;
uint64_t byte_size_;
};
Expand Down
7 changes: 7 additions & 0 deletions src/infer_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ InferenceRequest::AddParameter(const char* name, const bool value)
return Status::Success;
}

Status
InferenceRequest::AddParameter(const char* name, const double value)
{
parameters_.emplace_back(name, value);
return Status::Success;
}

Status
InferenceRequest::SetParameters(
const std::deque<InferenceParameter>& parameters)
Expand Down
1 change: 1 addition & 0 deletions src/infer_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ class InferenceRequest {
Status AddParameter(const char* name, const char* value);
Status AddParameter(const char* name, const int64_t value);
Status AddParameter(const char* name, const bool value);
Status AddParameter(const char* name, const double value);
Status SetParameters(const std::deque<InferenceParameter>& parameters);
const std::deque<InferenceParameter>& Parameters() const
{
Expand Down
7 changes: 7 additions & 0 deletions src/infer_response.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ InferenceResponse::AddParameter(const char* name, const bool value)
return Status::Success;
}

Status
InferenceResponse::AddParameter(const char* name, const double value)
{
parameters_.emplace_back(name, value);
return Status::Success;
}

Status
InferenceResponse::AddOutput(
const std::string& name, const inference::DataType datatype,
Expand Down
1 change: 1 addition & 0 deletions src/infer_response.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ class InferenceResponse {
Status AddParameter(const char* name, const char* value);
Status AddParameter(const char* name, const int64_t value);
Status AddParameter(const char* name, const bool value);
Status AddParameter(const char* name, const double value);

// The response outputs.
const std::deque<Output>& Outputs() const { return outputs_; }
Expand Down
10 changes: 10 additions & 0 deletions src/tritonserver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2036,6 +2036,16 @@ TRITONSERVER_InferenceRequestSetBoolParameter(
return nullptr; // success
}

TRITONAPI_DECLSPEC TRITONSERVER_Error*
TRITONSERVER_InferenceRequestSetDoubleParameter(
TRITONSERVER_InferenceRequest* request, const char* name,
const double value)
{
tc::InferenceRequest* tr = reinterpret_cast<tc::InferenceRequest*>(request);
RETURN_IF_STATUS_ERROR(tr->AddParameter(name, value));
return nullptr; // success
}

//
// TRITONSERVER_InferenceResponse
//
Expand Down
8 changes: 8 additions & 0 deletions src/tritonserver_stub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,10 @@ TRITONSERVER_InferenceRequestSetBoolParameter()
{
}
TRITONAPI_DECLSPEC void
TRITONSERVER_InferenceRequestSetDoubleParameter()
{
}
TRITONAPI_DECLSPEC void
TRITONSERVER_InferenceRequestSetIntParameter()
{
}
Expand Down Expand Up @@ -783,6 +787,10 @@ TRITONBACKEND_ResponseSetBoolParameter()
{
}
TRITONAPI_DECLSPEC void
TRITONBACKEND_ResponseSetDoubleParameter()
{
}
TRITONAPI_DECLSPEC void
TRITONBACKEND_ResponseOutput()
{
}
Expand Down
Loading