onnxruntime/onnxruntime/test
Dmitri Smirnov 5dae0c477d
Deprecate CustomApi and refactor public API for better safety and consistency (#13215)
### Description
Deprecate CustomOpApi and refactor dependencies for exception safety and
eliminate memory leaks.
Refactor API classes for clear ownership and semantics.
Introduce `InitProviderOrtApi()`

### Motivation and Context
Make public API better and safer.

Special note about `Ort::Unowned`. The class suffers from the following
problems:

1. It is not able to hold const pointers to the underlying C objects.
This forces users to `const_cast` and circumvent constness of the
returned object. The user is now able to call mutating interfaces on the
object which violates invariants and may be a thread-safety issue. It
also enables to take ownership of the pointer and destroy it
unintentionally (see examples below).
2. The objects that are unowned cannot be copied and that makes coding
inconvenient and at times unsafe.
3. It directly inherits from the type it `unowns`.

All of the above creates great conditions for inadvertent unowned object
mutations and destructions. Consider the following examples of object
slicing, one of them is from a real customer issue and the other one I
accidentally coded myself (and I am supposed to know how this works).
None of the below can be solved by aftermarket patches and can be hard
to diagnose.

#### Example 1 slicing of argument
```cpp
void SlicingOnArgument(Ort::Value& value) {
  // This will take possession of the input and if the argument
  // is Ort::Unowned<Ort::Value> it would again double free the ptr
  // regardless if it was const or not since we cast it away.
  Ort::Value output_values[] = {std::move(value)};
}

void main() {
  const OrtValue* ptr = nullptr;  // some value does not matter
  Ort::Unowned<Ort::Value> unowned{const_cast<OrtValue*>(ptr)};
  // onowned is destroyed when the call returns.
  SlicingOnArgument(unowned);
}
```

#### Example 2 slicing of return value
```cpp
// The return will be sliced to Ort::Value that would own and relase (double free the ptr)
Ort::Value SlicingOnReturn() {
  const OrtValue* ptr = nullptr; // some value does not matter
  Ort::Unowned<Ort::Value> unowned{const_cast<OrtValue*>(ptr)};
  return unowned;
}
```
2022-10-06 14:57:37 -07:00
..
api_tests_without_env
common [CUDA] Add Strided Tensor Support for Expand->GatherElements for Training (#11976) 2022-07-25 16:05:26 +08:00
contrib_ops BFP schemas: Change block dimension type to Int (#13169) 2022-10-06 11:11:43 -07:00
debug_node_inputs_outputs
eager Revert "fixed point based requantization on arm64 (#11540)" (#11732) 2022-06-03 19:12:25 -07:00
framework Add handling for variadic inputs/outputs in a function. (#13140) 2022-09-30 14:51:17 +10:00
fuzzing Remove previously deprecated API (#12935) 2022-09-14 10:58:03 -07:00
global_thread_pools Drop nuphar (#11555) 2022-09-07 15:11:18 -07:00
ir Fix C6011: dereferencing NULL pointer with_data (and external_data) (#12982) 2022-09-16 09:49:36 -07:00
mlas Disable QGEMM, s8 A, s8 B (Packed) bench for AMD64 (#12765) 2022-08-30 16:47:36 -07:00
onnx Deprecate CustomApi and refactor public API for better safety and consistency (#13215) 2022-10-06 14:57:37 -07:00
opaque_api Deprecate APIs returning raw ptrs and provide replacements (#11922) 2022-06-24 09:50:04 -07:00
optimizer Multiple Gather to Split Fusion (#13095) 2022-09-29 11:09:57 +08:00
perftest Deprecate CustomApi and refactor public API for better safety and consistency (#13215) 2022-10-06 14:57:37 -07:00
platform Update kernel matching logic: decouple from op schemas and remove kernel def hashes (#12791) 2022-09-20 14:24:59 -07:00
proto
providers Deprecate CustomApi and refactor public API for better safety and consistency (#13215) 2022-10-06 14:57:37 -07:00
python refine QuantConfig (#13155) 2022-10-03 08:34:49 -07:00
quantization
shared_lib Deprecate CustomApi and refactor public API for better safety and consistency (#13215) 2022-10-06 14:57:37 -07:00
testdata Deprecate CustomApi and refactor public API for better safety and consistency (#13215) 2022-10-06 14:57:37 -07:00
unittest_main
util Deprecate CustomApi and refactor public API for better safety and consistency (#13215) 2022-10-06 14:57:37 -07:00
wasm
win_getopt
xctest