40
40
#include < string>
41
41
42
42
namespace {
43
+ const std::string RESULT{" result" };
43
44
const std::string INFERENCE{" inference" };
44
45
const std::string ERROR{" error" };
45
46
const std::string TIME_MS{" time_ms" };
47
+ const std::string THREAD_SETTINGS{" thread_settings" };
48
+ const std::string INFERENCE_THREADS{" inference_threads" };
49
+ const std::string MODEL_THREADS{" model_threads" };
46
50
}
47
51
48
52
torch::Tensor infer (torch::jit::script::Module& module,
@@ -116,17 +120,22 @@ void writeError(const std::string& requestId,
116
120
const std::string& message,
117
121
ml::core::CRapidJsonConcurrentLineWriter& jsonWriter) {
118
122
jsonWriter.StartObject ();
123
+ jsonWriter.Key (RESULT);
124
+ jsonWriter.StartObject ();
119
125
jsonWriter.Key (ml::torch::CCommandParser::REQUEST_ID);
120
126
jsonWriter.String (requestId);
121
127
jsonWriter.Key (ERROR);
122
128
jsonWriter.String (message);
123
129
jsonWriter.EndObject ();
130
+ jsonWriter.EndObject ();
124
131
}
125
132
126
133
void writeDocumentOpening (const std::string& requestId,
127
134
std::uint64_t timeMs,
128
135
ml::core::CRapidJsonConcurrentLineWriter& jsonWriter) {
129
136
jsonWriter.StartObject ();
137
+ jsonWriter.Key (RESULT);
138
+ jsonWriter.StartObject ();
130
139
jsonWriter.Key (ml::torch::CCommandParser::REQUEST_ID);
131
140
jsonWriter.String (requestId);
132
141
jsonWriter.Key (TIME_MS);
@@ -135,6 +144,22 @@ void writeDocumentOpening(const std::string& requestId,
135
144
136
145
void writeDocumentClosing (ml::core::CRapidJsonConcurrentLineWriter& jsonWriter) {
137
146
jsonWriter.EndObject ();
147
+ jsonWriter.EndObject ();
148
+ }
149
+
150
+ void writeThreadSettings (ml::core::CJsonOutputStreamWrapper& wrappedOutputStream,
151
+ std::int32_t inferenceThreads,
152
+ std::int32_t modelThreads) {
153
+ ml::core::CRapidJsonConcurrentLineWriter jsonWriter (wrappedOutputStream);
154
+ jsonWriter.StartObject ();
155
+ jsonWriter.Key (THREAD_SETTINGS);
156
+ jsonWriter.StartObject ();
157
+ jsonWriter.Key (INFERENCE_THREADS);
158
+ jsonWriter.Uint64 (inferenceThreads);
159
+ jsonWriter.Key (MODEL_THREADS);
160
+ jsonWriter.Uint64 (modelThreads);
161
+ jsonWriter.EndObject ();
162
+ jsonWriter.EndObject ();
138
163
}
139
164
140
165
template <std::size_t N>
@@ -306,6 +331,10 @@ int main(int argc, char** argv) {
306
331
LOG_DEBUG (<< at::get_parallel_info ());
307
332
LOG_DEBUG (<< " Model threads: " << modelThreads);
308
333
334
+ ml::core::CJsonOutputStreamWrapper wrappedOutputStream{ioMgr.outputStream ()};
335
+
336
+ writeThreadSettings (wrappedOutputStream, inferenceThreads, modelThreads);
337
+
309
338
torch::jit::script::Module module;
310
339
try {
311
340
auto readAdapter = std::make_unique<ml::torch::CBufferedIStreamAdapter>(
@@ -324,8 +353,6 @@ int main(int argc, char** argv) {
324
353
325
354
ml::torch::CCommandParser commandParser{ioMgr.inputStream ()};
326
355
327
- ml::core::CJsonOutputStreamWrapper wrappedOutputStream{ioMgr.outputStream ()};
328
-
329
356
// Starting the executor with 1 thread will use an extra thread that isn't necessary
330
357
// so we only start it when more than 1 threads are set.
331
358
if (modelThreads > 1 ) {
0 commit comments