Skip to content

Commit

Permalink
Merge branch 'ovep-develop-lnl-1.1' into ankit/enable_device_plugins_…
Browse files Browse the repository at this point in the history
…validation
  • Loading branch information
ankitm3k committed Jul 11, 2024
2 parents 856d4d7 + 6c7d990 commit 5cecdee
Show file tree
Hide file tree
Showing 95 changed files with 299 additions and 224 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ IntPtr[] outputValues /* An array of output value pointers. Array must be alloca
OrtAllocatorType allocatorType,
int identifier,
OrtMemType memType,
out IntPtr /*(OrtMemoryInfo*)*/ allocatorInfo // memory ownership transfered to caller
out IntPtr /*(OrtMemoryInfo*)*/ allocatorInfo // memory ownership transferred to caller
);

public static DOrtCreateMemoryInfo OrtCreateMemoryInfo;
Expand Down
76 changes: 38 additions & 38 deletions csharp/src/Microsoft.ML.OnnxRuntime/OrtValue.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public enum OnnxValueType
ONNX_TYPE_MAP = 3, // It's a map
ONNX_TYPE_OPAQUE = 4, // It's an experimental Opaque object
ONNX_TYPE_SPARSETENSOR = 5, // It's a Sparse Tensor
ONNX_TYPE_OPTIONAL = 6, // It's an optional type that designates anything above (except UNKOWN)
ONNX_TYPE_OPTIONAL = 6, // It's an optional type that designates anything above (except UNKNOWN)
}

/// <summary>
Expand All @@ -31,7 +31,7 @@ public enum OnnxValueType
/// The class implements IDisposable and must
/// be disposed of, otherwise native resources will leak
/// and will eventually cause the application to slow down or crash.
///
///
/// If the OrtValue instance is constructed over a managed memory, and it is not
/// disposed properly, the pinned memory will continue to be pinned and interfere
/// with GC operation.
Expand Down Expand Up @@ -72,7 +72,7 @@ internal OrtValue(IntPtr handle, OnnxValueType onnxValueType)
/// Constructor. The newly constructed OrtValue takes ownership of the native OrtValue instance
/// and disposes of it when the OrtValue instance is disposed. The instance will take ownership and will
/// dispose of compositeMembers instances.
///
///
/// This constructor can only throw if OnnxType is not specified.
/// </summary>
/// <param name="handle">native ortValue handle</param>
Expand Down Expand Up @@ -189,10 +189,10 @@ public OrtValue GetValue(int index, OrtAllocator allocator)
/// <summary>
/// Returns a ReadOnlySpan<typeparamref name="T"/> over tensor native buffer that
/// provides a read-only view.
///
///
/// Note, that the memory may be device allocated and, therefore, not accessible from the CPU.
/// To get memory descriptor use GetTensorMemoryInfo().
///
///
/// OrtValue must contain a non-string tensor.
/// The span is valid as long as the OrtValue instance is alive (not disposed).
/// </summary>
Expand All @@ -210,10 +210,10 @@ public ReadOnlySpan<T> GetTensorDataAsSpan<T>() where T : unmanaged
/// This enables you to safely and efficiently modify the underlying
/// native buffer in a type-safe manner. This is useful for example in IOBinding scenarios
/// where you want to modify results of the inference and feed it back as input.
///
///
/// Note, that the memory may be device allocated.
/// To get memory descriptor use GetTensorMemoryInfo().
///
///
/// OrtValue must contain a non-string tensor.
/// The span is valid as long as the OrtValue instance is alive (not disposed).
/// </summary>
Expand All @@ -237,7 +237,7 @@ public Span<byte> GetTensorMutableRawData()
/// <summary>
/// Fetch string tensor element buffer pointer at the specified index,
/// convert/copy to UTF-16 char[] and return a ReadOnlyMemory<char> instance.
///
///
/// Obtain TensorTypeAndShape to get shape and element count.
/// </summary>
/// <param name="index">flat string tensor element index</param>
Expand All @@ -256,7 +256,7 @@ public ReadOnlyMemory<char> GetStringElementAsMemory(int index)
/// <summary>
/// Fetch string tensor element buffer pointer at the specified index,
/// copy/convert UTF-8 into a UTF-16 string and return it.
///
///
/// Obtain TensorTypeAndShape to get shape and element count.
/// </summary>
/// <param name="index">flat string tensor element index</param>
Expand All @@ -279,7 +279,7 @@ public string GetStringElement(int index)
/// <summary>
/// Get a span over the native memory of the string tensor element.
/// The span is valid as long as the OrtValue is valid.
///
///
/// This is useful if you want to perform your own UTF-8 decoding or
/// you do not care about decoding.
/// Obtain TensorTypeAndShape to get shape and element count.
Expand Down Expand Up @@ -483,7 +483,7 @@ private Span<byte> GetTensorBufferRawData(Type requestedType)
/// This can be a piece of arbitrary memory that may be allocated by OrtAllocator (possibly on a device),
/// a chunk of managed memory (must be pinned for the duration of OrtValue lifetime) or a memory that is allocated
/// natively allocated using Marshal.AllocHGlobal(), stackalloc or other means (may be on a device).
///
///
/// The resulting OrtValue does not own the underlying memory buffer and will not attempt to
/// deallocate it. The caller must make sure that the memory remains valid for the duration of OrtValue lifetime.
/// </summary>
Expand Down Expand Up @@ -769,12 +769,12 @@ out IntPtr valueHandle
/// Converts the string argument represented by ReadOnlySpan to UTF-8,
/// allocates space in the native tensor and copies it into the native tensor memory.
/// Typically, this is used to populate a new empty string tensor element.
///
///
/// The number of elements is according to the shape supplied to CreateTensorWithEmptyStrings().
/// However, this API can also be used to overwrite any existing element within the string tensor.
///
///
/// In general, to obtain the number of elements for any tensor, use GetTensorTypeAndShape() which
/// would return a disposable instance of TensorTypeAndShapeInfo.
/// would return a disposable instance of TensorTypeAndShapeInfo.
/// Then call GetElementCount() or GetShape().
/// </summary>
/// <param name="str">ReadOnlySpan over chars</param>
Expand All @@ -795,12 +795,12 @@ public void StringTensorSetElementAt(ReadOnlySpan<char> str, int index)
/// Converts the string argument represented by ReadOnlyMemory to UTF-8,
/// allocates space in the native tensor and copies it into the native tensor memory.
/// Typically, this is used to populate a new empty string tensor element.
///
///
/// The number of elements is according to the shape supplied to CreateTensorWithEmptyStrings().
/// However, this API can also be used to overwrite any existing element within the string tensor.
///
///
/// In general, to obtain the number of elements for any tensor, use GetTensorTypeAndShape() which
/// would return a disposable instance of TensorTypeAndShapeInfo.
/// would return a disposable instance of TensorTypeAndShapeInfo.
/// Then call GetElementCount() or GetShape().
///
/// </summary>
Expand All @@ -815,7 +815,7 @@ public void StringTensorSetElementAt(ReadOnlyMemory<char> rom, int index)
/// <summary>
/// This API resizes String Tensor element to the requested amount of bytes (UTF-8)
/// and copies the bytes from the supplied ReadOnlySpan into the native tensor memory (resized buffer).
///
///
/// The API is useful for quick loading of utf8 data into the native tensor memory.
/// </summary>
/// <param name="utf8Bytes">read only span of bytes</param>
Expand All @@ -841,7 +841,7 @@ public void StringTensorSetElementAt(ReadOnlySpan<byte> utf8Bytes, int index)
/// Creates an OrtValue that contains a string tensor.
/// String tensors are always allocated on CPU.
/// String data will be converted to UTF-8 and copied to native memory.
///
///
/// Note, this is different from creating an OrtValue from other primitive data types
/// where memory is pinned (if necessary) and the OrtValue points to that chunk of memory.
/// </summary>
Expand Down Expand Up @@ -885,10 +885,10 @@ public static OrtValue CreateFromStringTensor(Tensor<string> tensor)
/// Creates a sequence of OrtValues from a collection of OrtValues.
/// All OrtValues in the collection must be of the same Onnx type.
/// I.e. (Tensor, SparseTensor, Map, Sequence, etc.)
///
///
/// The ortValues that are passed as argument are taken possession of by the newly
/// created OrtValue. The caller should not dispose them, unless this call fails.
///
///
/// The ortValues would be empty on successful return.
/// </summary>
/// <param name="ortValues">a collection of OrtValues. On success the ortValues contained in the list
Expand Down Expand Up @@ -978,24 +978,24 @@ public void ProcessSequence(SequenceElementVisitor visitor, OrtAllocator allocat
/// Creates a map OrtValue with keys and values.
/// On a high level the Onnxruntime representation of the map always consists of two
/// OrtValues, keys and values.
///
///
/// According to ONNX standard map keys can be unmanaged types only (or strings).
/// Those keys are contained in a single tensor within OrtValue keys.
///
///
/// Map values, on the other hand, can be composite types. The values parameter
/// can either contain a single tensor with unmanaged map values with the same number of
/// elements as the keys, or it can be a sequence of OrtValues,
/// each of those can be a composite type (tensor, sequence, map). If it is a sequence,
/// then the number of elements must match the number of elements in keys.
///
///
/// Keys and values must be in the same order.
///
///
/// ORT supports only a subset of types for keys and values, however, this API does not
/// restrict it.
///
///
/// The ortValues that are passed as argument are taken possession of by the newly
/// created OrtValue. The caller should not dispose them, unless this call fails.
///
///
/// Keys and values arguments will be set to null on success.
/// </summary>
/// <param name="keys">Contains keys</param>
Expand Down Expand Up @@ -1031,10 +1031,10 @@ public static OrtValue CreateMap(ref OrtValue keys, ref OrtValue values)
/// This API helps to quickly creates a map OrtValue with unmanaged (primitive) keys and values specified as arrays.
/// This helps the user not to create OrtValues for keys and values separately and deal only with the final result.
/// The map would consist of two tensors, one for keys and one for values.
///
///
/// The OrtValues would be created on top of the managed memory arrays and use it directly.
/// The number of elements in keys and values must be the same and they must be in order.
///
///
/// The types must be unmanaged.
/// </summary>
/// <typeparam name="K">keys type</typeparam>
Expand Down Expand Up @@ -1078,10 +1078,10 @@ public static OrtValue CreateMap<K, V>(K[] keys, V[] values) where K : unmanaged
/// This helps the user not to create OrtValues for keys and values separately.
/// The number of elements in keys and values must be the same and they must be in order.
/// The map would consist of two tensors, one for keys and one for values.
///
///
/// string keys would be converted to UTF-8 encoding and copied to an allocated native memory.
/// The OrtValue for values would be created on top of the managed memory using it directly.
///
///
/// The values type must be unmanaged.
/// </summary>
/// <typeparam name="V"></typeparam>
Expand Down Expand Up @@ -1128,13 +1128,13 @@ public static OrtValue CreateMapWithStringKeys<V>(IReadOnlyCollection<string> ke

/// <summary>
/// Creates a map OrtValue with non-string keys and string values.
///
///
/// This helps the user not to create OrtValues for keys and values separately.
/// The number of elements in keys and values must be the same and they must be in order.
///
///
/// The OrtValue for keys would be created on top of the managed memory using it directly.
/// string values would be converted to UTF-8 encoding and copied to an allocated native memory.
///
///
/// </summary>
/// <typeparam name="K">unmanaged type of keys</typeparam>
/// <param name="keys"></param>
Expand Down Expand Up @@ -1182,17 +1182,17 @@ public static OrtValue CreateMapWithStringValues<K>(K[] keys, IReadOnlyCollectio
/// Typically, when one uses GetValue() API, it creates a copy of OrtValue
/// that points to the same buffer as keys or values. This API helps to deal with those
/// temporary instances and avoid leaks.
///
///
/// According to ONNX standard map keys can be unmanaged types only (or strings).
/// Those keys are contained in a single tensor within OrtValue keys. So you can query those
/// directly from keys argument.
///
///
/// Map values, on the other hand, can be composite types. The values parameter
/// can either contain a single tensor with unmanaged map values with the same number of
/// elements as the keys, or it can be a sequence of OrtValues,
/// each of those can be a composite type (tensor, sequence, map). If it is a sequence,
/// then the number of elements must match the number of elements in keys.
///
///
/// Depending on the structure of the values, one will either directly query a single tensor
/// from values, or will have to iterate over the sequence of OrtValues and visit each of those
/// resulting in a recursive visitation.
Expand All @@ -1204,7 +1204,7 @@ public static OrtValue CreateMapWithStringValues<K>(K[] keys, IReadOnlyCollectio
/// <summary>
/// This API helps the user to process a map OrtValue without
/// having to deal with the lifespan of intermediate OrtValues.
///
///
/// each API value is fed to the vistor functor.
/// </summary>
/// <param name="visitor">visitor function</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ public void TestSessionOptions()

var directml_dll_path = AppDomain.CurrentDomain.BaseDirectory;
SetDllDirectory(directml_dll_path);

try
{
opt.AppendExecutionProvider_DML(0);
}
catch (OnnxRuntimeException ortException)
{
// if we run on a CI machine with the incorrect hardware we might get an error due to that.
// allow that as the call made it through to the DML EP so the C# layer is working correctly.
// allow that as the call made it through to the DML EP so the C# layer is working correctly.
// any other exception type or error message is considered a failure.
Assert.Contains("The specified device interface or feature level is not supported on this system.",
ortException.Message);
Expand Down Expand Up @@ -1895,7 +1895,7 @@ private void TestSharedAllocatorUsingCreateAndRegisterAllocator()
sessionOptions.AddSessionConfigEntry("session.use_env_allocators", "1");

// Create two sessions to share the allocator
// Create a thrid session that DOES NOT use the allocator in the environment
// Create a third session that DOES NOT use the allocator in the environment
using (var session1 = new InferenceSession(model, sessionOptions))
using (var session2 = new InferenceSession(model, sessionOptions))
using (var session3 = new InferenceSession(model)) // Use the default SessionOptions instance
Expand Down Expand Up @@ -2127,7 +2127,7 @@ private void TestLoadAzureEP()
}
catch (Exception) {
Assert.True(false);
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion csharp/tools/Microsoft.ML.OnnxRuntime.PerfTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CommandOptions
[Option('i', "input_file", Required = false, HelpText = "Input file.")]
public string InputFile { get; set; }

[Option('p', Required = false, HelpText = "Run with parallel exection. Default is false")]
[Option('p', Required = false, HelpText = "Run with parallel execution. Default is false")]
public bool ParallelExecution { get; set; } = false;

[Option('o', "optimization_level", Required = false, HelpText = "Optimization Level. Default is 99, all optimization.")]
Expand Down
5 changes: 4 additions & 1 deletion include/onnxruntime/core/eager/ort_kernel_invoker.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ class ORTInvoker {
public:
ORTInvoker(std::shared_ptr<IExecutionProvider> execution_provider,
const logging::Logger& logger,
const IOnnxRuntimeOpSchemaRegistryList& custom_op_registries) : execution_provider_(std::move(execution_provider)), logger_(logger), custom_op_registries_(custom_op_registries) {
const IOnnxRuntimeOpSchemaRegistryList& custom_op_registries)
: execution_provider_(std::move(execution_provider)),
logger_(logger),
custom_op_registries_(custom_op_registries) {
if (!execution_provider_) {
ORT_THROW("Execution provider is nullptr");
}
Expand Down
2 changes: 1 addition & 1 deletion include/onnxruntime/core/framework/execution_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class IExecutionProvider {
const std::reference_wrapper<GraphViewer> filtered_graph;
};

// Fusion approach that is suppported
// Fusion approach that is supported
// !!! The "Function" FusionStyle is deprecated.
// !!! If your EP is using this fusion style, please migrate it to "FilteredGraphViewer" style.
enum class FusionStyle {
Expand Down
2 changes: 1 addition & 1 deletion include/onnxruntime/core/framework/op_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class OpKernel {
}

// Override this function to return a list of attributes the session can safely remove
// after it is intialized and saved. This option is useful to reduce memory usage
// after it is initialized and saved. This option is useful to reduce memory usage
// when the kernel does not reuse the operator attributes but copies them.
// All attributes returned by this method will be removed by method
// PruneRemovableAttributes of they exists.
Expand Down
4 changes: 2 additions & 2 deletions include/onnxruntime/core/framework/stream_handles.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ class Stream {
// update its lookup table with the table snapshot in notification.
// The memory reusing strategy is:
// A kernel in current stream is safe to reuse another stream's memory chunk
// as long as the reused chunk's timestamp is less than the last synchonized
// as long as the reused chunk's timestamp is less than the last synchronized
// timestamp recorded in the lookup table.

// Get the current timestamp
uint64_t GetCurrentTimestamp() const { return timestamp_; }

// return the timestamp when the last synchronization happened between target stream and current stream.
// return 0 if no synchonization happened.
// return 0 if no synchronization happened.
// if target_stream is nullptr, it means it is a sequence running on device doesn't support Stream (i.e. CPU)
// we can safely return 0 in that case to save a lookup.
uint64_t GetLastSyncTimestampWithTargetStream(Stream* target_stream) const {
Expand Down
Loading

0 comments on commit 5cecdee

Please sign in to comment.