aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancis Murtagh <francis.murtagh@arm.com>2021-08-13 16:15:09 +0100
committerMatthew Sloyan <matthew.sloyan@arm.com>2021-08-16 20:31:03 +0100
commit2332e458e43a7f8821ca66c1a31c6430cbf8fdba (patch)
tree3a27c3ed8edb0670067f91071e7dd6fef5c8ca78
parentab4b28eee1f302405ceabda9b0451256feed5954 (diff)
downloadarmnn-2332e458e43a7f8821ca66c1a31c6430cbf8fdba.tar.gz
IVGCVSW-6076 PCA: Add support for Importing Protected DMA buffers
* Add DmaBufProtected support to ClImportTensorHandle::Import() * Add DmaBufProtected to Map/Unmap switch case in ClBackend * Remove unreachable return statement Signed-off-by: Francis Murtagh <francis.murtagh@arm.com> Change-Id: I5918f6235af74ae287b8a73744a8cc979a07b0bf
-rw-r--r--src/backends/cl/ClBackend.hpp44
-rw-r--r--src/backends/cl/ClImportTensorHandle.hpp31
2 files changed, 63 insertions, 12 deletions
diff --git a/src/backends/cl/ClBackend.hpp b/src/backends/cl/ClBackend.hpp
index e3ff91c268..4f68c3bcc7 100644
--- a/src/backends/cl/ClBackend.hpp
+++ b/src/backends/cl/ClBackend.hpp
@@ -140,9 +140,9 @@ public:
{
const cl_import_properties_arm importProperties[] =
{
- CL_IMPORT_TYPE_ARM,
- CL_IMPORT_TYPE_HOST_ARM,
- 0
+ CL_IMPORT_TYPE_ARM,
+ CL_IMPORT_TYPE_HOST_ARM,
+ 0
};
cl_int error = CL_SUCCESS;
cl_mem buffer = clImportMemoryARM(arm_compute::CLKernelLibrary::get().context().get(),
@@ -163,11 +163,37 @@ public:
{
const cl_import_properties_arm importProperties[] =
{
- CL_IMPORT_TYPE_ARM,
- CL_IMPORT_TYPE_DMA_BUF_ARM,
- CL_IMPORT_DMA_BUF_DATA_CONSISTENCY_WITH_HOST_ARM,
- CL_TRUE,
- 0
+ CL_IMPORT_TYPE_ARM,
+ CL_IMPORT_TYPE_DMA_BUF_ARM,
+ CL_IMPORT_DMA_BUF_DATA_CONSISTENCY_WITH_HOST_ARM,
+ CL_TRUE,
+ 0
+ };
+ cl_int error = CL_SUCCESS;
+ cl_mem buffer = clImportMemoryARM(arm_compute::CLKernelLibrary::get().context().get(),
+ CL_MEM_READ_WRITE,
+ importProperties,
+ memory,
+ roundedSize,
+ &error);
+ if (error == CL_SUCCESS)
+ {
+ m_AllocatedBufferMappings.insert(std::make_pair(static_cast<void *>(buffer), memory));
+ return buffer;
+ }
+ throw armnn::Exception(
+ "Mapping allocated memory from CustomMemoryAllocator failed, errcode: "
+ + std::to_string(error));
+ }
+ else if (source == MemorySource::DmaBufProtected)
+ {
+ const cl_import_properties_arm importProperties[] =
+ {
+ CL_IMPORT_TYPE_ARM,
+ CL_IMPORT_TYPE_DMA_BUF_ARM,
+ CL_IMPORT_TYPE_PROTECTED_ARM,
+ CL_TRUE,
+ 0
};
cl_int error = CL_SUCCESS;
cl_mem buffer = clImportMemoryARM(arm_compute::CLKernelLibrary::get().context().get(),
@@ -228,6 +254,7 @@ public:
return _mapping;
break;
case armnn::MemorySource::DmaBuf:
+ case armnn::MemorySource::DmaBufProtected:
// If the source is a Dmabuf then the memory ptr should be pointing to an integer value for the fd
_mapping = mmap(NULL, _size, PROT_WRITE, MAP_SHARED, *(reinterpret_cast<int*>(m_HostMemPtr)), 0);
return _mapping;
@@ -247,6 +274,7 @@ public:
_mapping = nullptr;
break;
case armnn::MemorySource::DmaBuf:
+ case armnn::MemorySource::DmaBufProtected:
munmap(_mapping, _size);
_mapping = nullptr;
break;
diff --git a/src/backends/cl/ClImportTensorHandle.hpp b/src/backends/cl/ClImportTensorHandle.hpp
index 69cd4a6d81..48fb2f7d30 100644
--- a/src/backends/cl/ClImportTensorHandle.hpp
+++ b/src/backends/cl/ClImportTensorHandle.hpp
@@ -125,6 +125,20 @@ public:
return ClImport(importProperties, memory);
}
+ if (source == MemorySource::DmaBufProtected)
+ {
+ const cl_import_properties_arm importProperties[] =
+ {
+ CL_IMPORT_TYPE_ARM,
+ CL_IMPORT_TYPE_DMA_BUF_ARM,
+ CL_IMPORT_TYPE_PROTECTED_ARM,
+ CL_TRUE,
+ 0
+ };
+
+ return ClImport(importProperties, memory, true);
+
+ }
else
{
throw MemoryImportException("ClImportTensorHandle::Import flag is not supported");
@@ -134,11 +148,10 @@ public:
{
throw MemoryImportException("ClImportTensorHandle::Incorrect import flag");
}
- return false;
}
private:
- bool ClImport(const cl_import_properties_arm* importProperties, void* memory)
+ bool ClImport(const cl_import_properties_arm* importProperties, void* memory, bool isProtected = false)
{
size_t totalBytes = m_Tensor.info()->total_size();
@@ -148,8 +161,18 @@ private:
auto roundedSize = cachelineAlignment + totalBytes - (totalBytes % cachelineAlignment);
cl_int error = CL_SUCCESS;
- cl_mem buffer = clImportMemoryARM(arm_compute::CLKernelLibrary::get().context().get(),
- CL_MEM_READ_WRITE, importProperties, memory, roundedSize, &error);
+ cl_mem buffer;
+ if (isProtected)
+ {
+ buffer = clImportMemoryARM(arm_compute::CLKernelLibrary::get().context().get(),
+ CL_MEM_HOST_NO_ACCESS, importProperties, memory, roundedSize, &error);
+ }
+ else
+ {
+ buffer = clImportMemoryARM(arm_compute::CLKernelLibrary::get().context().get(),
+ CL_MEM_READ_WRITE, importProperties, memory, roundedSize, &error);
+ }
+
if (error != CL_SUCCESS)
{
throw MemoryImportException("ClImportTensorHandle::Invalid imported memory" + std::to_string(error));