HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
experimental_onnxruntime_cxx_api.h
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License.
3 
4 // Summary: The experimental Ort C++ API is a wrapper around the Ort C++ API.
5 //
6 // This C++ API further simplifies usage and provides support for modern C++ syntax/features
7 // at the cost of some overhead (i.e. using std::string over char *).
8 //
9 // Where applicable, default memory allocator options are used unless explicitly set.
10 //
11 // Experimental components are designed as drop-in replacements of the regular API, requiring
12 // minimal code modifications to use.
13 //
14 // Example: Ort::Session -> Ort::Experimental::Session
15 //
16 // NOTE: Experimental API components are subject to change based on feedback and provide no
17 // guarantee of backwards compatibility in future releases.
18 
19 #pragma once
20 #include "onnxruntime_cxx_api.h"
21 
22 namespace Ort {
23 namespace Experimental {
24 
27  : Ort::Session(env, model_path.data(), options){};
28  Session(Env& env, void* model_data, size_t model_data_length, SessionOptions& options)
29  : Ort::Session(env, model_data, model_data_length, options){};
30 
31  // overloaded Run() with sensible defaults
32  std::vector<Ort::Value> Run(const std::vector<std::string>& input_names,
33  const std::vector<Ort::Value>& input_values,
34  const std::vector<std::string>& output_names,
35  const RunOptions& run_options = RunOptions());
36  void Run(const std::vector<std::string>& input_names,
37  const std::vector<Ort::Value>& input_values,
38  const std::vector<std::string>& output_names,
39  std::vector<Ort::Value>& output_values,
40  const RunOptions& run_options = RunOptions());
41 
42  // convenience methods that simplify common lower-level API calls
43  std::vector<std::string> GetInputNames() const;
44  std::vector<std::string> GetOutputNames() const;
45  std::vector<std::string> GetOverridableInitializerNames() const;
46 
47  // NOTE: shape dimensions may have a negative value to indicate a symbolic/unknown dimension.
48  std::vector<std::vector<int64_t> > GetInputShapes() const;
49  std::vector<std::vector<int64_t> > GetOutputShapes() const;
50  std::vector<std::vector<int64_t> > GetOverridableInitializerShapes() const;
51 };
52 
53 struct Value : Ort::Value {
55  : Ort::Value(p){};
56 
57  template <typename T>
58  static Ort::Value CreateTensor(T* p_data, size_t p_data_element_count, const std::vector<int64_t>& shape);
59  static Ort::Value CreateTensor(void* p_data, size_t p_data_byte_count, const std::vector<int64_t>& shape, ONNXTensorElementDataType type);
60 
61  template <typename T>
62  static Ort::Value CreateTensor(const std::vector<int64_t>& shape);
63  static Ort::Value CreateTensor(const std::vector<int64_t>& shape, ONNXTensorElementDataType type);
64 };
65 
66 } // namespace Experimental
67 } // namespace Ort
68 
std::vector< std::vector< int64_t > > GetInputShapes() const
std::vector< std::vector< int64_t > > GetOverridableInitializerShapes() const
Wrapper around OrtValue.
The Env (Environment)
Session(Env &env, void *model_data, size_t model_data_length, SessionOptions &options)
static Ort::Value CreateTensor(T *p_data, size_t p_data_element_count, const std::vector< int64_t > &shape)
std::vector< std::string > GetInputNames() const
std::vector< Ort::Value > Run(const std::vector< std::string > &input_names, const std::vector< Ort::Value > &input_values, const std::vector< std::string > &output_names, const RunOptions &run_options=RunOptions())
std::vector< std::string > GetOutputNames() const
std::vector< std::vector< int64_t > > GetOutputShapes() const
OrtRunOptions RunOptions
Definition: run_options.h:48
std::vector< std::string > GetOverridableInitializerNames() const
Session(Env &env, std::basic_string< ORTCHAR_T > &model_path, SessionOptions &options)
Wrapper around ::OrtSessionOptions.
type
Definition: core.h:1059
Wrapper around ::OrtSession.
Definition: format.h:895