Commit graph

6 commits

Author SHA1 Message Date
Michael Butler
4024d8f4d8 Change NN canonical timings to nanoseconds -- hal
A sibling CL to this CL changes the definition of nn::TimePoint to the
same type as std::chrono::steady_clock::time_point but has changed the
underlying duration representation to use uint64_t. That sibling CL also
renames nn::OptionalTimeoutDuration to nn::OptionalDuration, and changes
the definition to the same type as std::nanoseconds except the
underlying duration representation now uses uint64_t.

This CL makes changes to the NN HAL utility code in response to the
changes in the sibling CL.

Bug: 174297663
Test: mma
Test: NeuralNetworksTest_static
Change-Id: If44d9aefadb2c78b632ff289b5ff5a49f766525c
Merged-In: If44d9aefadb2c78b632ff289b5ff5a49f766525c
(cherry picked from commit ca11420785)
2020-12-21 21:08:43 -08:00
Michael Butler
cca3e20e23 Cleanup how transport errors are handled in NN utils
Prior to this change, whenever the NN utility code encountered a HIDL
transport error, the error message would display the file and line
number of the "handleTransportError" function itself. This change
introduces a new macro "HANDLE_TRANSPORT_FAILURE" that handles the
transport error in a similar way but now the error message displays
the file and line number of where the macro is called.

Bug: N/A
Test: mma
Change-Id: I35b34f8f5be52b7fcff0fbb58a37ab2b8c7dd8bb
Merged-In: I35b34f8f5be52b7fcff0fbb58a37ab2b8c7dd8bb
(cherry picked from commit 61f508e018)
2020-12-07 22:38:16 -08:00
Michael Butler
6547b2ac9c Validate during NN conversions by default -- hal
This change renames all `convert` functions to `unvalidatedConvert`.
This change also introduces new `convert` functions that act only on the
types that appear in the NN HIDL methods directly. These new `convert`
functions perform validation. Specifically, if either the source or
destination value is invalid, then the conversion fails.

Bug: 160667419
Test: mma
Test: NeuralNetworksTest_static
Change-Id: I492956ff60ad1466c67893993d28cdd6f3860708
Merged-In: I492956ff60ad1466c67893993d28cdd6f3860708
(cherry picked from commit 32acc06144)
2020-12-07 22:37:28 -08:00
Slava Shklyaev
49817a0e0f Replace nn::NativeHandle with nn::SharedHandle
Bug: 160669116
Test: mma
Change-Id: I73b2b93aab6cbf37d3c145e15ee9ae45228954f1
Merged-In: I73b2b93aab6cbf37d3c145e15ee9ae45228954f1
(cherry picked from commit d4290b8bf8)
2020-11-20 13:55:05 +00:00
Michael Butler
4b276a767b Implement NNAPI canonical interfaces
This CL implements the canonical IDevice, IPreparedModel, and IBuffer
interfaces for the 1.0, 1.1, 1.2, and 1.3 NN HIDL HAL interfaces.
Further, it introduces "Resilient" adapter interfaces to automatically
retrieve a handle to a recovered interface object after it has died and
rebooted.

This CL also updates the conversion code from returning nn::Result to
nn::GeneralResult, which includes a ErrorStatus code in the case of an
error.

Finally, this CL introduces a new static library
neuralnetworks_utils_hal_service which consists of a single function
::android::nn::hal::getDevices which can be used by the NNAPI runtime to
retrieve the HIDL services without knowing the underlying HIDL types.

Bug: 160668438
Test: mma
Test: NeuralNetworksTest_static
Change-Id: Iec6ae739df196b4034ffb35ea76781fd541ffec3
Merged-In: Iec6ae739df196b4034ffb35ea76781fd541ffec3
(cherry picked from commit 3670c385c4)
2020-11-16 14:29:55 -08:00
Michael Butler
b98aa6d6bf Create conversions to/from NNAPI canonical types
This CL creates the following primary sets of functions:
* V1_X::utils::convert(<canonical_type>) -- Converts a canonical type
  to the corresponding HAL version type.
* nn::convert(<V1_X_HAL_type>) -- Converts a HAL version type to the
  corresponding canonical type.
* neuralnetworks::utils::hasNoPointerData -- Indicates if the object
  contains no pointer-based data that could be relocated to shared
  memory.
* neuralnetworks::utils::flushDataFromPointerToShared -- Relocate
  pointer-based data to shared memory.
* neuralnetworks::utils::unflushDataFromSharedToPointer -- Undoes
  `flushDataFromPointerToShared` on a Request object. More
  specifically, `unflushDataFromSharedToPointer` copies the output
  shared memory data from the transformed Request object back to the
  output pointer-based memory in the original Request object.

It also introduces some other minor utility code, including
makeQuantized8PerformanceConsistentWithP, countNumberOfConsumers,
validate, valid, and validatedConvertToCanonical.

Bug: 160667419
Test: mma
Change-Id: I0732e658c1f4ed40cd122f1ca8581fb40b056757
Merged-In: I0732e658c1f4ed40cd122f1ca8581fb40b056757
(cherry picked from commit a685c3dbf4)
2020-10-05 12:47:57 -07:00