Skip to content

Commit

Permalink
Fix C# warnings. (#21913)
Browse files Browse the repository at this point in the history
### Description
<!-- Describe your changes. -->
Update some testing dependencies.
Fix various warnings. Mainly around documentation (existing) and unit
test usage (mainly resulting from xunit update).

Invalid angle brackets for generics in documentation were changed to use
curly braces based on
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/xmldoc/
> To refer to generic identifiers in code reference (cref) elements, you
can use either the escape characters (for example, cref="List&lt;T&gt;")
or braces (cref="List{T}"). As a special case, the compiler parses the
braces as angle brackets to make the documentation comment less
cumbersome to the author when referring to generic identifiers.

### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
  • Loading branch information
skottmckay committed Sep 3, 2024
1 parent bad00a3 commit e788b3d
Show file tree
Hide file tree
Showing 17 changed files with 71 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class DisposableNamedOnnxValue : NamedOnnxValue, IDisposable
/// Ctor
/// </summary>
/// <param name="name">Name of the output value</param>
/// <param name="value">Managed object created to represent output value, such as DenseTensor<T>
/// <param name="value">Managed object created to represent output value, such as DenseTensor{T};
/// List or Dictionary
/// </param>
/// <param name="elementType">Tensor element type if value type is a Tensor</param>
Expand Down Expand Up @@ -133,7 +133,7 @@ private DisposableNamedOnnxValue(string name, Object value, MapHelper mapHelper,
public TensorElementType ElementType { get; }

/// <summary>
/// Overrides the base class method. With respect to pinnedMemoryHandle, it has no operation
/// Overrides the base class method. With respect to memoryHolder, it has no operation
/// to do, as this class maintains a native buffer via _ortValueHolder and the memory will be
/// disposed by it. This is the case when we are dealing with an OrtValue that is backed by native memory
/// and not by pinned managed memory.
Expand All @@ -142,15 +142,15 @@ private DisposableNamedOnnxValue(string name, Object value, MapHelper mapHelper,
/// but the interface (derived from NamedOnnxValue) allows it to be passed as output and one of the test
/// cases does it. Unless we deprecate and re-do the interface, we must support it.
/// </summary>
/// <param name="pinnedMemoryHandle">always set to null</param>
/// <param name="memoryHolder">always set to null</param>
/// <returns>Native OrtValue handle</returns>
internal override IntPtr InputToOrtValueHandle(NodeMetadata metadata, out IDisposable memoryHolder)
{
if (_ortValueHolder == null)
{
throw new InvalidOperationException("The instance of this class does not own an OrtValue");
}
// PinnedMemoryHandle holds the default value as DisposableNamedOnnxValue
// memoryHolder holds the default value as DisposableNamedOnnxValue
// doesn't hold any managed buffer (that needs to be pinned)
memoryHolder = null;
// Return non-owning instance of OrtValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ private static IntPtr ExtractOrtValueHandleForOutput(NamedOnnxValue output, Node
/// </summary>
/// <param name="values">names to convert to zero terminated utf8 and pin</param>
/// <param name="nameExtractor">extractor functor that helps extracting names from inputs</param>
/// <param name="metaDict">inputs/outputs metadata</param>
/// <param name="metaLookup">inputs/outputs metadata</param>
/// <returns></returns>
private static IntPtr[] LookupUtf8Names<T>(IReadOnlyCollection<T> values, NameExtractor<T> nameExtractor,
MetadataLookup metaLookup)
Expand Down Expand Up @@ -1222,7 +1222,6 @@ private void Init(byte[] modelData, SessionOptions options,
/// Initializes the session object with a native session handle
/// </summary>
/// <param name="session">Value of a native session object</param>
/// <param name="options">Session options</param>
private void InitWithSessionHandle(IntPtr session)
{
_nativeHandle = session;
Expand Down Expand Up @@ -2075,7 +2074,7 @@ public long Version
/// <summary>
/// Custom metadata key/value pairs
/// </summary>
/// <value>An instance of a Dictionary<string,string></value>
/// <value>An instance of a Dictionary{string,string}</value>
public Dictionary<string, string> CustomMetadataMap
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ internal static OrtValue CreateProjection(NamedOnnxValue namedOnnxValue, NodeMet
/// The function creates OrtValue objects for each element of the sequence
/// and then creates an OrtValue for the whole sequence.
/// </summary>
/// <param name="namedOnnxValue">NamedOnnxValue containing a IEnumerable<NameOnnValue></param>
/// <param name="namedOnnxValue">NamedOnnxValue containing a IEnumerable{NamedOnnxValue}</param>
/// <param name="metadata">sequence metadata</param>
/// <returns>OrtValue that represents a sequence</returns>
/// <exception cref="OnnxRuntimeException"></exception>
Expand Down
23 changes: 6 additions & 17 deletions csharp/src/Microsoft.ML.OnnxRuntime/NamedOnnxValue.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ internal MapHelper(TensorBase keys, TensorBase values)
/// Other sequences and maps. Although the OnnxValueType is exposed,
/// the caller is supposed to know the actual data type contained.
///
/// The convention is that for tensors, it would contain a DenseTensor<T> instance or
/// anything derived from Tensor<T>.
/// The convention is that for tensors, it would contain a DenseTensor{T} instance or
/// anything derived from Tensor{T}.
///
/// For sequences, it would contain a IList<T> where T is an instance of NamedOnnxValue that
/// For sequences, it would contain a IList{T} where T is an instance of NamedOnnxValue that
/// would contain a tensor or another type.
///
/// For Maps, it would contain a IDictionary<K, V> where K,V are primitive types or strings.
/// For Maps, it would contain a IDictionary{K, V} where K,V are primitive types or strings.
///
/// </summary>
public class NamedOnnxValue
Expand Down Expand Up @@ -153,7 +153,7 @@ public static NamedOnnxValue CreateFromSequence<T>(string name, IEnumerable<T> v
}

/// <summary>
/// Instantiates NamedOnnxValue that contains IDictionary<K, V>
/// Instantiates NamedOnnxValue that contains IDictionary{K, V}
/// </summary>
/// <typeparam name="K">Keys type</typeparam>
/// <typeparam name="V">Values type</typeparam>
Expand Down Expand Up @@ -225,7 +225,7 @@ public IDictionary<K, V> AsDictionary<K, V>()
/// based on the pinned managed memory. The caller is responsible for Disposing
/// both OrtValue and pinnedMemoryHandle
/// </summary>
/// <param name="pinnedMemoryHandle">dispose after returned OrtValus is disposed</param>
/// <param name="memoryOwner">dispose after returned OrtValue is disposed</param>
/// <returns>The native OrtValue handle</returns>
internal virtual IntPtr InputToOrtValueHandle(NodeMetadata metadata, out IDisposable memoryOwner)
{
Expand Down Expand Up @@ -272,12 +272,6 @@ internal virtual IntPtr OutputToOrtValueHandle(NodeMetadata metadata, out IDispo
$" Use Run() overloads that return DisposableNamedOnnxValue to get access to all Onnx value types that may be returned as output.");
}

/// <summary>
/// This method is used internally to feed dictionary keys
/// to create an OrtValue for map keys
/// </summary>
/// <typeparam name="K"></typeparam>
/// <returns>DenseTensor<K>"</returns>
internal TensorBase GetDictionaryKeys()
{
if (ValueType != OnnxValueType.ONNX_TYPE_MAP)
Expand All @@ -289,11 +283,6 @@ internal TensorBase GetDictionaryKeys()
return _mapHelper.Keys;
}

/// <summary>
///
/// </summary>
/// <typeparam name="V"></typeparam>
/// <returns>DenseTensor<V>"</returns>
internal TensorBase GetDictionaryValues()
{
if (ValueType != OnnxValueType.ONNX_TYPE_MAP)
Expand Down
17 changes: 8 additions & 9 deletions csharp/src/Microsoft.ML.OnnxRuntime/NativeMethods.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,7 @@ IntPtr[] outputValues /* An array of output value pointers. Array must be alloca
/// <summary>
/// Destroy OrtIoBinding instance created by OrtCreateIoBinding
/// </summary>
/// <param name="io_bidning">instance of OrtIoBinding</param>
/// <param name="io_binding">instance of OrtIoBinding</param>
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
public delegate void DOrtReleaseIoBinding(IntPtr /*(OrtIoBinding)*/ io_binding);

Expand All @@ -1516,7 +1516,7 @@ IntPtr[] outputValues /* An array of output value pointers. Array must be alloca
/// Bind OrtValue to the model input with the specified name
/// If binding with the specified name already exists, it will be replaced
/// </summary>
/// <param name="io_bidning">instance of OrtIoBinding</param>
/// <param name="io_binding">instance of OrtIoBinding</param>
/// <param name="name">model input name (utf-8)</param>
/// <param name="ort_value">OrtValue that is used for input (may wrap arbitrary memory).
/// The param instance is copied internally so this argument may be released.
Expand Down Expand Up @@ -1544,7 +1544,7 @@ IntPtr[] outputValues /* An array of output value pointers. Array must be alloca
/// Bind OrtValue to the model output with the specified name
/// If binding with the specified name already exists, it will be replaced
/// </summary>
/// <param name="io_bidning">instance of OrtIoBinding</param>
/// <param name="io_binding">instance of OrtIoBinding</param>
/// <param name="name">model output name (utf-8)</param>
/// <param name="ort_value">OrtValue that is used for output (may wrap arbitrary memory).
/// The param instance is copied internally so this argument may be released.
Expand Down Expand Up @@ -1605,7 +1605,7 @@ IntPtr[] outputValues /* An array of output value pointers. Array must be alloca
/// The function returns output values after the model has been run with RunWithBinding()
/// It returns a natively allocated buffer of OrtValue pointers. All of the OrtValues must be individually
/// released after no longer needed. You may use OrtValue disposable class to wrap the native handle and properly dispose it
/// in connection with DisposableList<T>. All values are returned in the same order as they were bound.
/// in connection with DisposableList{T}. All values are returned in the same order as they were bound.
/// The buffer that contains OrtValues must deallocated using the same allocator that was specified as an argument.
/// You may use an instance OrtMemoryAllocation to properly dispose of the native memory.
/// </summary>
Expand Down Expand Up @@ -1643,9 +1643,7 @@ IntPtr[] outputValues /* An array of output value pointers. Array must be alloca
/// <summary>
/// Provides element-level access into a tensor.
/// </summary>
/// <param name="location_values">a pointer to an array of index values that specify an element's location in the tensor data blob</param>
/// <param name="location_values_count">length of location_values</param>
/// <param name="out">a pointer to the element specified by location_values</param>
/// <param name="io_binding">instance of OrtIoBinding</param>
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
public delegate void DOrtTensorAt(IntPtr /*(OrtIoBinding)*/ io_binding);

Expand All @@ -1656,10 +1654,11 @@ IntPtr[] outputValues /* An array of output value pointers. Array must be alloca
/// sharing between multiple sessions that use the same env instance.
/// Lifetime of the created allocator will be valid for the duration of the environment.
/// Returns an error if an allocator with the same OrtMemoryInfo is already registered.
/// </summary>
/// <param name="env">Native OrtEnv instance</param>
/// <param name="memInfo">Native OrtMemoryInfo instance</param>
/// <param name="arenaCfg">Native OrtArenaCfg instance</param>
/// <retruns>A pointer to native ortStatus indicating success/failure</retruns>
/// <returns>A pointer to native ortStatus indicating success/failure</returns>
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
public delegate IntPtr /*(OrtStatus*)*/ DOrtCreateAndRegisterAllocator(IntPtr /*(OrtEnv*)*/ env,
IntPtr /*(const OrtMemoryInfo*)*/ memInfo,
Expand Down Expand Up @@ -1890,7 +1889,7 @@ IntPtr[] outputValues /* An array of output value pointers. Array must be alloca
public static DOrtFillStringTensor OrtFillStringTensor;

/// \param value A tensor created from OrtCreateTensor... function.
/// \param index The index of the entry in the tensor to resize. <summary>
/// \param index The index of the entry in the tensor to resize.
/// \param length_in_bytes Length to resize the string to.
/// \param buffer The resized buffer.
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ internal MarshaledString(string input)
}

/// <summary>
// Native allocation (UTF8-8 string length with terminating zero)
/// Native allocation (UTF8-8 string length with terminating zero)
/// </summary>
internal int Length { get; private set; }

Expand Down
2 changes: 1 addition & 1 deletion csharp/src/Microsoft.ML.OnnxRuntime/OrtEnv.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private OrtEnv(IntPtr handle, OrtLoggingLevel logLevel)
/// <param name="severity"></param>
/// <param name="category"></param>
/// <param name="logid"></param>
/// <param name="code_location"></param>
/// <param name="codeLocation"></param>
/// <param name="message"></param>
private static void LoggingFunctionThunk(IntPtr param,
IntPtr severity,
Expand Down
11 changes: 5 additions & 6 deletions csharp/src/Microsoft.ML.OnnxRuntime/OrtFloat16.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ internal static uint BFloat16BitsToSingleBits(ushort bfloatBits)
}

/// <summary>
/// Creates float NaN with the given sign and fp16 significand shifted << 54
/// Creates float NaN with the given sign and fp16 significand shifted &lt;&lt; 54
/// </summary>
/// <param name="sign">true for negative</param>
/// <param name="significand">should be shifted 54 bits left before calling the function
/// so only 8 bits of signidicand remains</param>
/// so only 8 bits of significand remains</param>
/// <returns></returns>
internal static float CreateSingleNaN(bool sign, ulong significand)
{
Expand Down Expand Up @@ -416,12 +416,11 @@ internal static ushort ExtractTrailingSignificandFromBits(ushort bits)

/// <summary>
/// Compares values of two Float16
///
/// </summary>
/// <param name="left">left hand side</param>
/// <param name="right">right hand side</param>
/// <returns>returns true if left is greater or equal than right according to IEEE</returns>
/// <inheritdoc cref="IComparisonOperators{TSelf, TOther, TResult}.op_GreaterThanOrEqual(TSelf, TOther)" />
/// <inheritdoc />
public static bool operator >=(Float16 left, Float16 right)
{
return right <= left;
Expand Down Expand Up @@ -492,7 +491,7 @@ public static bool IsNaN(Float16 value)
/// Determines whether the specified value is negative.
/// </summary>
/// <param name="value">Float16 instance</param>
/// <returns>true if the value is negative</returns></returns>
/// <returns>true if the value is negative</returns>
public static bool IsNegative(Float16 value)
{
return (short)(value.value) < 0;
Expand Down Expand Up @@ -1115,7 +1114,7 @@ public static bool IsNaN(BFloat16 value)
/// Determines whether the specified value is negative.
/// </summary>
/// <param name="value">BFloat16 instance</param>
/// <returns>true if the value is negative</returns></returns>
/// <returns>true if the value is negative</returns>
public static bool IsNegative(BFloat16 value)
{
return (short)(value.value) < 0;
Expand Down
8 changes: 4 additions & 4 deletions csharp/src/Microsoft.ML.OnnxRuntime/ProviderOptions.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ public static void StringToDict(string s, Dictionary<string, string> dict)
}

/// <summary>
/// CoreML flags for use with SessionOptions
/// CoreML flags for use with SessionOptions.
/// See https://github.com/microsoft/onnxruntime/blob/main/include/onnxruntime/core/providers/coreml/coreml_provider_factory.h
/// </summary>
/// <see cref="https://github.com/microsoft/onnxruntime/blob/main/include/onnxruntime/core/providers/coreml/coreml_provider_factory.h"/>
[Flags]
public enum CoreMLFlags : uint
{
Expand All @@ -332,9 +332,9 @@ public enum CoreMLFlags : uint
}

/// <summary>
/// NNAPI flags for use with SessionOptions
/// NNAPI flags for use with SessionOptions.
/// See https://github.com/microsoft/onnxruntime/blob/main/include/onnxruntime/core/providers/nnapi/nnapi_provider_factory.h
/// </summary>
/// <see cref="https://github.com/microsoft/onnxruntime/blob/main/include/onnxruntime/core/providers/nnapi/nnapi_provider_factory.h"/>
[Flags]
public enum NnapiFlags
{
Expand Down
10 changes: 5 additions & 5 deletions csharp/src/Microsoft.ML.OnnxRuntime/SessionOptions.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -768,8 +768,8 @@ public int LogVerbosityLevel
private int _logVerbosityLevel = 0;

/// <summary>
// Sets the number of threads used to parallelize the execution within nodes
// A value of 0 means ORT will pick a default
/// Sets the number of threads used to parallelize the execution within nodes
/// A value of 0 means ORT will pick a default
/// </summary>
/// <value>returns _intraOpNumThreads value</value>
public int IntraOpNumThreads
Expand All @@ -787,9 +787,9 @@ public int IntraOpNumThreads
private int _intraOpNumThreads = 0; // set to what is set in C++ SessionOptions by default;

/// <summary>
// Sets the number of threads used to parallelize the execution of the graph (across nodes)
// If sequential execution is enabled this value is ignored
// A value of 0 means ORT will pick a default
/// Sets the number of threads used to parallelize the execution of the graph (across nodes)
/// If sequential execution is enabled this value is ignored
/// A value of 0 means ORT will pick a default
/// </summary>
/// <value>returns _interOpNumThreads value</value>
public int InterOpNumThreads
Expand Down
Loading

0 comments on commit e788b3d

Please sign in to comment.