ATLAS Offline Software
Loading...
Searching...
No Matches
triton::backend::traccc::ModelState Class Reference
Inheritance diagram for triton::backend::traccc::ModelState:
Collaboration diagram for triton::backend::traccc::ModelState:

Public Member Functions

virtual ~ModelState ()=default
const std::string & InputCellsTensorName () const
TRITONSERVER_DataType InputCellsTensorDataType () const
const std::vector< int64_t > & InputCellsTensorNonBatchShape () const
size_t TotalInstanceCount () const
TRITONSERVER_Error * ValidateModelConfig ()

Static Public Member Functions

static TRITONSERVER_Error * Create (TRITONBACKEND_Model *triton_model, ModelState **state)

Public Attributes

int64_t cellFeatures

Private Member Functions

 ModelState (TRITONBACKEND_Model *triton_model)
 Also possible problems in this function!

Private Attributes

std::string m_inputCellsName
TRITONSERVER_DataType m_inputCellsDatatype
std::vector< int64_t > m_inputCellsNbShape
size_t m_totalInstanceCount = 1

Detailed Description

Definition at line 179 of file TracccTritonBackend.cxx.

Constructor & Destructor Documentation

◆ ~ModelState()

virtual triton::backend::traccc::ModelState::~ModelState ( )
virtualdefault

◆ ModelState()

triton::backend::traccc::ModelState::ModelState ( TRITONBACKEND_Model * triton_model)
private

Also possible problems in this function!

Definition at line 228 of file TracccTritonBackend.cxx.

229 : BackendModel(triton_model)
230{
231 // Validate that the model's configuration matches what is supported
232 // by this backend.
233 THROW_IF_BACKEND_MODEL_ERROR(ValidateModelConfig());
234}

Member Function Documentation

◆ Create()

TRITONSERVER_Error * triton::backend::traccc::ModelState::Create ( TRITONBACKEND_Model * triton_model,
ModelState ** state )
static

Definition at line 237 of file TracccTritonBackend.cxx.

238{
239 try {
240 *state = new ModelState(triton_model);
241 }
242 catch (const BackendModelException& ex) {
243 RETURN_ERROR_IF_TRUE(
244 ex.err_ == nullptr, TRITONSERVER_ERROR_INTERNAL,
245 std::string("unexpected nullptr in BackendModelException"));
246 RETURN_IF_ERROR(ex.err_);
247 }
248
249 return nullptr; // success
250}
ModelState(TRITONBACKEND_Model *triton_model)
Also possible problems in this function!

◆ InputCellsTensorDataType()

TRITONSERVER_DataType triton::backend::traccc::ModelState::InputCellsTensorDataType ( ) const
inline

Definition at line 189 of file TracccTritonBackend.cxx.

189{ return m_inputCellsDatatype; }

◆ InputCellsTensorName()

const std::string & triton::backend::traccc::ModelState::InputCellsTensorName ( ) const
inline

Definition at line 186 of file TracccTritonBackend.cxx.

◆ InputCellsTensorNonBatchShape()

const std::vector< int64_t > & triton::backend::traccc::ModelState::InputCellsTensorNonBatchShape ( ) const
inline

Definition at line 202 of file TracccTritonBackend.cxx.

203 {
204 return m_inputCellsNbShape;
205 }

◆ TotalInstanceCount()

size_t triton::backend::traccc::ModelState::TotalInstanceCount ( ) const
inline

◆ ValidateModelConfig()

TRITONSERVER_Error * triton::backend::traccc::ModelState::ValidateModelConfig ( )

Definition at line 253 of file TracccTritonBackend.cxx.

254{
255 // If verbose logging is enabled, dump the model's configuration as
256 // JSON into the console output.
257 if (TRITONSERVER_LogIsEnabled(TRITONSERVER_LOG_VERBOSE)) {
258 common::TritonJson::WriteBuffer buffer;
259 RETURN_IF_ERROR(ModelConfig().PrettyWrite(&buffer));
260 LOG_MESSAGE(
261 TRITONSERVER_LOG_VERBOSE,
262 (std::string("model configuration:\n") + buffer.Contents()).c_str());
263 }
264
265 // ModelConfig is the model configuration as a TritonJson
266 // object. Use the TritonJson utilities to parse the JSON and
267 // determine if the configuration is supported by this backend.
268 common::TritonJson::Value inputs, outputs;
269 RETURN_IF_ERROR(ModelConfig().MemberAsArray("input", &inputs));
270 RETURN_IF_ERROR(ModelConfig().MemberAsArray("output", &outputs));
271
272 // The model must have exactly the 2 inputs (CELLS, EVENT_IOV) and the 4
273 // outputs the client reads back
274 RETURN_ERROR_IF_FALSE(
275 inputs.ArraySize() == 2, TRITONSERVER_ERROR_INVALID_ARG,
276 std::string("model configuration must have 2 inputs"));
277 RETURN_ERROR_IF_FALSE(
278 outputs.ArraySize() == outputNames.size(), TRITONSERVER_ERROR_INVALID_ARG,
279 std::string("model configuration must have ") +
280 std::to_string(outputNames.size()) + " outputs");
281
282 // CELLS comes first; EVENT_IOV is looked up by its fixed name, and
283 // Triton checks its type and shape against this configuration
284 common::TritonJson::Value input_cells;
285 RETURN_IF_ERROR(inputs.IndexAsObject(0, &input_cells));
286
287 // Record the input name in the model state.
288 const char *input_cells_name;
289 size_t input_cells_len;
290 RETURN_IF_ERROR(input_cells.MemberAsString("name", &input_cells_name, &input_cells_len));
291 // MemberAsString hands back a pointer into the parsed JSON plus its
292 // length; that buffer is not guaranteed to be NUL-terminated, so the
293 // length must be used. Building the name with the const char* overload
294 // instead can append trailing garbage, which then makes
295 // TRITONBACKEND_RequestInput fail to find the tensor at execute time.
296 m_inputCellsName = std::string(input_cells_name, input_cells_len);
297
298 LOG_MESSAGE(TRITONSERVER_LOG_INFO,
299 (std::string("'traccc' backend: input tensor is '") +
300 m_inputCellsName + "' (" +
301 std::to_string(m_inputCellsName.size()) + " chars)").c_str());
302
303 std::string input_cells_dtype;
304 RETURN_IF_ERROR(input_cells.MemberAsString("data_type", &input_cells_dtype));
305 m_inputCellsDatatype = ModelConfigDataTypeToTritonServerDataType(input_cells_dtype);
306
307 RETURN_IF_ERROR(backend::ParseShape(input_cells, "dims", &m_inputCellsNbShape));
308
309 // The output tensors are written by fixed name, so the configured names
310 // must be exactly the expected set (order is irrelevant).
311 std::set<std::string> configured_outputs;
312 for (size_t i = 0; i < outputs.ArraySize(); ++i) {
313 common::TritonJson::Value output;
314 RETURN_IF_ERROR(outputs.IndexAsObject(i, &output));
315 const char *output_name;
316 size_t output_name_len;
317 RETURN_IF_ERROR(
318 output.MemberAsString("name", &output_name, &output_name_len));
319 configured_outputs.emplace(output_name, output_name_len);
320 }
321 for (const auto &expected : outputNames) {
322 RETURN_ERROR_IF_FALSE(
323 configured_outputs.count(expected) == 1, TRITONSERVER_ERROR_INVALID_ARG,
324 std::string("model configuration is missing output '") + expected + "'");
325 }
326
327 // Count the instances Triton is going to create, so the embedded Athena
328 // application can be brought up with one event-store slot per instance.
330 common::TritonJson::Value instance_groups;
331 if (ModelConfig().Find("instance_group", &instance_groups)) {
332 for (size_t i = 0; i < instance_groups.ArraySize(); ++i) {
333 common::TritonJson::Value group;
334 RETURN_IF_ERROR(instance_groups.IndexAsObject(i, &group));
335
336 int64_t count = 1;
337 if (group.Find("count")) {
338 RETURN_IF_ERROR(group.MemberAsInt("count", &count));
339 }
340 RETURN_ERROR_IF_FALSE(
341 count >= 0, TRITONSERVER_ERROR_INVALID_ARG,
342 std::string("instance_group count must not be negative"));
343
344 size_t devices = 1;
345 common::TritonJson::Value gpus;
346 if (group.Find("gpus", &gpus) && gpus.ArraySize() > 0) {
347 devices = gpus.ArraySize();
348 }
349 m_totalInstanceCount += static_cast<size_t>(count) * devices;
350 }
351 }
352 // No instance_group at all, or one that resolves to nothing, still means
353 // Triton creates a single instance.
354 if (m_totalInstanceCount == 0) {
356 }
357
358 LOG_MESSAGE(TRITONSERVER_LOG_INFO,
359 (std::string("'traccc' backend: model configured with ") +
360 std::to_string(m_totalInstanceCount) +
361 " instance(s), one event slot each").c_str());
362
363 return nullptr; // success
364}
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:148
output
Definition merge.py:16
const std::array< std::string, 4 > outputNames

Member Data Documentation

◆ cellFeatures

int64_t triton::backend::traccc::ModelState::cellFeatures

Definition at line 213 of file TracccTritonBackend.cxx.

◆ m_inputCellsDatatype

TRITONSERVER_DataType triton::backend::traccc::ModelState::m_inputCellsDatatype
private

Definition at line 220 of file TracccTritonBackend.cxx.

◆ m_inputCellsName

std::string triton::backend::traccc::ModelState::m_inputCellsName
private

Definition at line 218 of file TracccTritonBackend.cxx.

◆ m_inputCellsNbShape

std::vector<int64_t> triton::backend::traccc::ModelState::m_inputCellsNbShape
private

Definition at line 222 of file TracccTritonBackend.cxx.

◆ m_totalInstanceCount

size_t triton::backend::traccc::ModelState::m_totalInstanceCount = 1
private

Definition at line 224 of file TracccTritonBackend.cxx.


The documentation for this class was generated from the following file: