Skip to content

Commit b51f60c

Browse files
committed
feat: add run config entries
1 parent c1c736b commit b51f60c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/session/run_options.rs

+20
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,26 @@ impl<O: SelectedOutputMarker> RunOptions<O> {
283283
ortsys![unsafe RunOptionsUnsetTerminate(self.run_options_ptr.as_ptr())?];
284284
Ok(())
285285
}
286+
287+
/// Adds a custom configuration option to the `RunOptions`.
288+
///
289+
/// This can be used to, for example, configure the graph ID when using compute graphs with an execution provider
290+
/// like CUDA:
291+
/// ```no_run
292+
/// # use std::sync::Arc;
293+
/// # use ort::{Session, RunOptions, Value, ValueType, TensorElementType};
294+
/// # fn main() -> ort::Result<()> {
295+
/// let mut run_options = RunOptions::new()?;
296+
/// run_options.add_config_entry("gpu_graph_id", "1")?;
297+
/// # Ok(())
298+
/// # }
299+
/// ```
300+
pub fn add_config_entry(&mut self, key: impl AsRef<str>, value: impl AsRef<str>) -> Result<()> {
301+
let key = CString::new(key.as_ref())?;
302+
let value = CString::new(value.as_ref())?;
303+
ortsys![unsafe AddRunConfigEntry(self.run_options_ptr.as_ptr(), key.as_ptr(), value.as_ptr())?];
304+
Ok(())
305+
}
286306
}
287307

288308
impl<O: SelectedOutputMarker> Drop for RunOptions<O> {

0 commit comments

Comments
 (0)