Skip to content

Commit 434e503

Browse files
authored
Exposing trace context to python backend (#334)
* Adding trace context to infer trace
1 parent 2bd46a4 commit 434e503

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed

include/triton/core/tritonserver.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
// Copyright 2020-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
//
33
// Redistribution and use in source and binary forms, with or without
44
// modification, are permitted provided that the following conditions
@@ -91,7 +91,7 @@ struct TRITONSERVER_MetricFamily;
9191
/// }
9292
///
9393
#define TRITONSERVER_API_VERSION_MAJOR 1
94-
#define TRITONSERVER_API_VERSION_MINOR 28
94+
#define TRITONSERVER_API_VERSION_MINOR 29
9595

9696
/// Get the TRITONBACKEND API version supported by the Triton shared
9797
/// library. This value can be compared against the
@@ -894,6 +894,25 @@ TRITONSERVER_InferenceTraceSpawnChildTrace(
894894
struct TRITONSERVER_InferenceTrace* trace,
895895
struct TRITONSERVER_InferenceTrace** child_trace);
896896

897+
/// Set TRITONSERVER_InferenceTrace context.
898+
///
899+
/// \param trace The trace.
900+
/// \param trace_context A new trace context to associate with the trace.
901+
/// \return a TRITONSERVER_Error indicating success or failure.
902+
TRITONSERVER_DECLSPEC struct TRITONSERVER_Error*
903+
TRITONSERVER_InferenceTraceSetContext(
904+
struct TRITONSERVER_InferenceTrace* trace, const char* trace_context);
905+
906+
907+
/// Get TRITONSERVER_InferenceTrace context.
908+
///
909+
/// \param trace The trace.
910+
/// \param trace_context Returns the context associated with the trace.
911+
/// \return a TRITONSERVER_Error indicating success or failure.
912+
TRITONSERVER_DECLSPEC struct TRITONSERVER_Error*
913+
TRITONSERVER_InferenceTraceContext(
914+
struct TRITONSERVER_InferenceTrace* trace, const char** trace_context);
915+
897916
/// TRITONSERVER_InferenceRequest
898917
///
899918
/// Object representing an inference request. The inference request

src/infer_trace.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020-2021, NVIDIA CORPORATION. All rights reserved.
1+
// Copyright (c) 2020-2024, NVIDIA CORPORATION. All rights reserved.
22
//
33
// Redistribution and use in source and binary forms, with or without
44
// modification, are permitted provided that the following conditions
@@ -51,7 +51,7 @@ class InferenceTrace {
5151
TRITONSERVER_InferenceTraceReleaseFn_t release_fn, void* userp)
5252
: level_(level), id_(next_id_++), parent_id_(parent_id),
5353
activity_fn_(activity_fn), tensor_activity_fn_(tensor_activity_fn),
54-
release_fn_(release_fn), userp_(userp)
54+
release_fn_(release_fn), userp_(userp), context_("")
5555
{
5656
}
5757

@@ -63,10 +63,12 @@ class InferenceTrace {
6363
const std::string& ModelName() const { return model_name_; }
6464
int64_t ModelVersion() const { return model_version_; }
6565
const std::string& RequestId() const { return request_id_; }
66+
const std::string& Context() const { return context_; }
6667

6768
void SetModelName(const std::string& n) { model_name_ = n; }
6869
void SetModelVersion(int64_t v) { model_version_ = v; }
6970
void SetRequestId(const std::string& request_id) { request_id_ = request_id; }
71+
void SetContext(const std::string& context) { context_ = context; }
7072

7173
// Report trace activity.
7274
void Report(
@@ -125,6 +127,7 @@ class InferenceTrace {
125127
// Maintain next id statically so that trace id is unique even
126128
// across traces
127129
static std::atomic<uint64_t> next_id_;
130+
std::string context_;
128131
};
129132

130133
//
@@ -144,9 +147,11 @@ class InferenceTraceProxy {
144147
const std::string& ModelName() const { return trace_->ModelName(); }
145148
const std::string& RequestId() const { return trace_->RequestId(); }
146149
int64_t ModelVersion() const { return trace_->ModelVersion(); }
150+
const std::string& Context() const { return trace_->Context(); }
147151
void SetModelName(const std::string& n) { trace_->SetModelName(n); }
148152
void SetRequestId(const std::string& n) { trace_->SetRequestId(n); }
149153
void SetModelVersion(int64_t v) { trace_->SetModelVersion(v); }
154+
void SetContext(const std::string& context) { trace_->SetContext(context); }
150155

151156
void Report(
152157
const TRITONSERVER_InferenceTraceActivity activity, uint64_t timestamp_ns)

src/tritonserver.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,36 @@ TRITONSERVER_InferenceTraceSpawnChildTrace(
10971097
#endif // TRITON_ENABLE_TRACING
10981098
}
10991099

1100+
1101+
TRITONAPI_DECLSPEC TRITONSERVER_Error*
1102+
TRITONSERVER_InferenceTraceSetContext(
1103+
TRITONSERVER_InferenceTrace* trace, const char* trace_context)
1104+
{
1105+
#ifdef TRITON_ENABLE_TRACING
1106+
tc::InferenceTrace* ltrace = reinterpret_cast<tc::InferenceTrace*>(trace);
1107+
ltrace->SetContext(trace_context);
1108+
return nullptr; // Success
1109+
#else
1110+
return TRITONSERVER_ErrorNew(
1111+
TRITONSERVER_ERROR_UNSUPPORTED, "inference tracing not supported");
1112+
#endif // TRITON_ENABLE_TRACING
1113+
}
1114+
1115+
TRITONAPI_DECLSPEC TRITONSERVER_Error*
1116+
TRITONSERVER_InferenceTraceContext(
1117+
TRITONSERVER_InferenceTrace* trace, const char** trace_context)
1118+
{
1119+
#ifdef TRITON_ENABLE_TRACING
1120+
tc::InferenceTrace* ltrace = reinterpret_cast<tc::InferenceTrace*>(trace);
1121+
*trace_context = ltrace->Context().c_str();
1122+
return nullptr; // Success
1123+
#else
1124+
return TRITONSERVER_ErrorNew(
1125+
TRITONSERVER_ERROR_UNSUPPORTED, "inference tracing not supported");
1126+
#endif // TRITON_ENABLE_TRACING
1127+
}
1128+
1129+
11001130
//
11011131
// TRITONSERVER_ServerOptions
11021132
//

src/tritonserver_stub.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ TRITONSERVER_InferenceTraceSpawnChildTrace()
190190
{
191191
}
192192
TRITONAPI_DECLSPEC void
193+
TRITONSERVER_InferenceTraceSetContext()
194+
{
195+
}
196+
TRITONAPI_DECLSPEC void
197+
TRITONSERVER_InferenceTraceContext()
198+
{
199+
}
200+
TRITONAPI_DECLSPEC void
193201
TRITONSERVER_InferenceRequestNew()
194202
{
195203
}

0 commit comments

Comments
 (0)