Improve the structure of NNAPI AIDL Memory
Prior to this change, the NN AIDL HAL created a Memory struct analogous
to hidl_memory, consisting of a name, size, and native handle. However,
this Memory struct is not very structured, and requires both the client
and server to agree on how the data should be interpreted.
This CL tightens the structure of the Memory representation by
introducing Ashmem and MappableFile structs to android.hardware.common
in order to hold specific file descriptors representing memory regions.
Further, this CL redefines android.hardwre.neuralnetworks's Memory
object as a union of the Ashmem, MappableFile, and (existing)
HardwareBuffer memory types.
This change also adds "com.android.neuralnetworks" to the graphics
AIDL HAL's apex_available build rule.
Bug: 183118727
Test: mma
Change-Id: I32322df676b83597c9e95f13662c322a6a80accc
Merged-In: I32322df676b83597c9e95f13662c322a6a80accc
(cherry picked from commit 1158c80ff6
)
This commit is contained in:
parent
f609b99111
commit
8c4f0fcfc0
9 changed files with 213 additions and 18 deletions
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// This file is a snapshot of an AIDL file. Do not edit it manually. There are
|
||||
// two cases:
|
||||
// 1). this is a frozen version file - do not edit this in any case.
|
||||
// 2). this is a 'current' file. If you make a backwards compatible change to
|
||||
// the interface (from the latest frozen version), the build system will
|
||||
// prompt you to update this file with `m <name>-update-api`.
|
||||
//
|
||||
// You must not make a backward incompatible change to any AIDL file built
|
||||
// with the aidl_interface module type with versions property set. The module
|
||||
// type is used to build AIDL files in a way that they can be used across
|
||||
// independently updatable components of the system. If a device is shipped
|
||||
// with such a backward incompatible change, it has a high risk of breaking
|
||||
// later when a module using the interface is updated, e.g., Mainline modules.
|
||||
|
||||
package android.hardware.common;
|
||||
@VintfStability
|
||||
parcelable Ashmem {
|
||||
ParcelFileDescriptor fd;
|
||||
long size;
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// This file is a snapshot of an AIDL file. Do not edit it manually. There are
|
||||
// two cases:
|
||||
// 1). this is a frozen version file - do not edit this in any case.
|
||||
// 2). this is a 'current' file. If you make a backwards compatible change to
|
||||
// the interface (from the latest frozen version), the build system will
|
||||
// prompt you to update this file with `m <name>-update-api`.
|
||||
//
|
||||
// You must not make a backward incompatible change to any AIDL file built
|
||||
// with the aidl_interface module type with versions property set. The module
|
||||
// type is used to build AIDL files in a way that they can be used across
|
||||
// independently updatable components of the system. If a device is shipped
|
||||
// with such a backward incompatible change, it has a high risk of breaking
|
||||
// later when a module using the interface is updated, e.g., Mainline modules.
|
||||
|
||||
package android.hardware.common;
|
||||
@VintfStability
|
||||
parcelable MappableFile {
|
||||
long length;
|
||||
int prot;
|
||||
ParcelFileDescriptor fd;
|
||||
long offset;
|
||||
}
|
|
@ -1,14 +1,30 @@
|
|||
/*
|
||||
* Copyright 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// This file is a snapshot of an AIDL interface (or parcelable). Do not try to
|
||||
// edit this file. It looks like you are doing that because you have modified
|
||||
// an AIDL interface in a backward-incompatible way, e.g., deleting a function
|
||||
// from an interface or a field from a parcelable and it broke the build. That
|
||||
// breakage is intended.
|
||||
// This file is a snapshot of an AIDL file. Do not edit it manually. There are
|
||||
// two cases:
|
||||
// 1). this is a frozen version file - do not edit this in any case.
|
||||
// 2). this is a 'current' file. If you make a backwards compatible change to
|
||||
// the interface (from the latest frozen version), the build system will
|
||||
// prompt you to update this file with `m <name>-update-api`.
|
||||
//
|
||||
// You must not make a backward incompatible changes to the AIDL files built
|
||||
// You must not make a backward incompatible change to any AIDL file built
|
||||
// with the aidl_interface module type with versions property set. The module
|
||||
// type is used to build AIDL files in a way that they can be used across
|
||||
// independently updatable components of the system. If a device is shipped
|
||||
|
|
34
common/aidl/android/hardware/common/Ashmem.aidl
Normal file
34
common/aidl/android/hardware/common/Ashmem.aidl
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.hardware.common;
|
||||
|
||||
import android.os.ParcelFileDescriptor;
|
||||
|
||||
/**
|
||||
* Type that holds same memory as the "ashmem" hidl_memory type from HIDL.
|
||||
*/
|
||||
@VintfStability
|
||||
parcelable Ashmem {
|
||||
/**
|
||||
* A handle to a memory region.
|
||||
*/
|
||||
ParcelFileDescriptor fd;
|
||||
/**
|
||||
* Size of the memory region in bytes.
|
||||
*/
|
||||
long size;
|
||||
}
|
53
common/aidl/android/hardware/common/MappableFile.aidl
Normal file
53
common/aidl/android/hardware/common/MappableFile.aidl
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.hardware.common;
|
||||
|
||||
import android.os.ParcelFileDescriptor;
|
||||
|
||||
/**
|
||||
* A region of a file that can be mapped into memory.
|
||||
*
|
||||
* In Linux, MappableFile may be used with mmap as `MAP_SHARED`.
|
||||
*
|
||||
* MappableFile is compatible with ::android::base::MappedFile.
|
||||
*/
|
||||
@VintfStability
|
||||
parcelable MappableFile {
|
||||
/**
|
||||
* Length of the mapping region in bytes.
|
||||
*/
|
||||
long length;
|
||||
/**
|
||||
* The desired memory protection for the mapping.
|
||||
*
|
||||
* In Linux, prot is either `PROT_NONE` (indicating that mapped pages may not be accessed) or
|
||||
* the bitwise OR of one or more of the following flags:
|
||||
* - `PROT_READ` (indicating that the mapped pages may be read)
|
||||
* - `PROT_WRITE` (indicating that the mapped pages may be written)
|
||||
*/
|
||||
int prot;
|
||||
/**
|
||||
* A handle to a mappable file.
|
||||
*/
|
||||
ParcelFileDescriptor fd;
|
||||
/**
|
||||
* The offset in the file to the beginning of the mapping region in number of bytes.
|
||||
*
|
||||
* Note: Some mapping functions require that the offset is aligned to the page size.
|
||||
*/
|
||||
long offset;
|
||||
}
|
|
@ -34,6 +34,7 @@ aidl_interface {
|
|||
apex_available: [
|
||||
"//apex_available:platform",
|
||||
"com.android.media.swcodec",
|
||||
"com.android.neuralnetworks",
|
||||
],
|
||||
min_sdk_version: "29",
|
||||
},
|
||||
|
|
|
@ -16,6 +16,7 @@ aidl_interface {
|
|||
stability: "vintf",
|
||||
imports: [
|
||||
"android.hardware.common",
|
||||
"android.hardware.graphics.common",
|
||||
],
|
||||
backend: {
|
||||
java: {
|
||||
|
|
|
@ -33,8 +33,8 @@
|
|||
|
||||
package android.hardware.neuralnetworks;
|
||||
@VintfStability
|
||||
parcelable Memory {
|
||||
android.hardware.common.NativeHandle handle;
|
||||
long size;
|
||||
String name;
|
||||
union Memory {
|
||||
android.hardware.common.Ashmem ashmem;
|
||||
android.hardware.common.MappableFile mappableFile;
|
||||
android.hardware.graphics.common.HardwareBuffer hardwareBuffer;
|
||||
}
|
||||
|
|
|
@ -15,16 +15,26 @@
|
|||
*/
|
||||
|
||||
package android.hardware.neuralnetworks;
|
||||
import android.hardware.common.NativeHandle;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
|
||||
import android.hardware.common.Ashmem;
|
||||
import android.hardware.common.MappableFile;
|
||||
import android.hardware.graphics.common.HardwareBuffer;
|
||||
|
||||
/**
|
||||
* A type that is used to pass pieces of shared memory between processes.
|
||||
* The type structure mimics hidl_memory type from HIDL.
|
||||
* The different types of memory that can be shared across processes.
|
||||
*/
|
||||
@VintfStability
|
||||
parcelable Memory {
|
||||
NativeHandle handle;
|
||||
long size;
|
||||
String name;
|
||||
union Memory {
|
||||
/**
|
||||
* Ashmem hidl_memory type from HIDL.
|
||||
*/
|
||||
Ashmem ashmem;
|
||||
/**
|
||||
* File that can be mapped.
|
||||
*/
|
||||
MappableFile mappableFile;
|
||||
/**
|
||||
* AIDL representation of AHardwareBuffer.
|
||||
*/
|
||||
HardwareBuffer hardwareBuffer;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue