Skip to content

Commit 0b4f3f0

Browse files
authored
Add support for session.use_device_allocator_for_initializers in onnxruntime_backend (#294)
* Add support for ArenaCfg configuration options
1 parent 2be37f7 commit 0b4f3f0

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
# Copyright (c) 2020-2024, NVIDIA CORPORATION. All rights reserved.
2+
# Copyright (c) 2020-2025, NVIDIA CORPORATION. All rights reserved.
33
#
44
# Redistribution and use in source and binary forms, with or without
55
# modification, are permitted provided that the following conditions
@@ -283,6 +283,7 @@ for more information.
283283
* `memory.enable_memory_arena_shrinkage`:
284284
See [this](https://github.com/microsoft/onnxruntime/blob/master/include/onnxruntime/core/session/onnxruntime_run_options_config_keys.h)
285285
for more information.
286+
* `session.use_device_allocator_for_initializers`: Use "1" to enable using device allocator for allocating initialized tensor memory and "0" to disable. The default is "0". See [this](https://onnxruntime.ai/docs/get-started/with-c.html) for more information.
286287

287288
### Command line options
288289

src/onnxruntime.cc

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
// Copyright 2019-2025, 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
@@ -302,6 +302,31 @@ ModelState::ModelState(TRITONBACKEND_Model* triton_model)
302302
}
303303
}
304304

305+
// Enable/disable use_device_allocator_for_initializers
306+
{
307+
triton::common::TritonJson::Value params;
308+
if (ModelConfig().Find("parameters", &params)) {
309+
triton::common::TritonJson::Value json_value;
310+
const char* use_device_allocator_for_initializers_key =
311+
"session.use_device_allocator_for_initializers";
312+
if (params.Find(use_device_allocator_for_initializers_key, &json_value)) {
313+
std::string string_value;
314+
THROW_IF_BACKEND_MODEL_ERROR(
315+
json_value.MemberAsString("string_value", &string_value));
316+
317+
LOG_MESSAGE(
318+
TRITONSERVER_LOG_VERBOSE,
319+
(std::string("Configuring '") +
320+
use_device_allocator_for_initializers_key + "' to '" +
321+
string_value + "' for '" + Name() + "'")
322+
.c_str());
323+
THROW_IF_BACKEND_MODEL_ORT_ERROR(ort_api->AddSessionConfigEntry(
324+
soptions, use_device_allocator_for_initializers_key,
325+
string_value.c_str()));
326+
}
327+
}
328+
}
329+
305330
// memory configs
306331
// enable/disable mem arena
307332
{

0 commit comments

Comments
 (0)