aboutsummaryrefslogtreecommitdiff
path: root/driver_library/python/src/ethosu_driver/swig/typemaps/buffer.i
diff options
context:
space:
mode:
authorKshitij Sisodia <kshitij.sisodia@arm.com>2022-09-30 16:42:50 +0100
committerKristofer Jonsson <kristofer.jonsson@arm.com>2022-10-25 16:36:45 +0000
commitf9efe0ddf865c55d28bcaa203fefffa94bf09b42 (patch)
tree928da5f68dafd7e5a0dee05a75f2f6fcd52df170 /driver_library/python/src/ethosu_driver/swig/typemaps/buffer.i
parent569aa558f5e7638852a928feede1f21e7323f664 (diff)
downloadethos-u-linux-driver-stack-f9efe0ddf865c55d28bcaa203fefffa94bf09b42.tar.gz
Added Python interface for Arm Ethos-U NPU driver library.22.11-rc1
Python `ethosu_driver` could be built as part of Arm Ethos-U Linux driver library CMake flow. See driver_library/python/README.md for more details. Change-Id: I177a890add5c13df9a839f4f43621f972afe5ab1 Signed-off-by: Kshitij Sisodia <kshitij.sisodia@arm.com>
Diffstat (limited to 'driver_library/python/src/ethosu_driver/swig/typemaps/buffer.i')
-rw-r--r--driver_library/python/src/ethosu_driver/swig/typemaps/buffer.i42
1 files changed, 42 insertions, 0 deletions
diff --git a/driver_library/python/src/ethosu_driver/swig/typemaps/buffer.i b/driver_library/python/src/ethosu_driver/swig/typemaps/buffer.i
new file mode 100644
index 0000000..13b7909
--- /dev/null
+++ b/driver_library/python/src/ethosu_driver/swig/typemaps/buffer.i
@@ -0,0 +1,42 @@
+//
+// SPDX-FileCopyrightText: Copyright 2021-2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
+// SPDX-License-Identifier: Apache-2.0
+//
+%define %mutable_buffer(TYPEMAP, SIZE)
+ %typemap(in) (TYPEMAP, SIZE) {
+ int res; void *buf = 0; size_t size = 0;
+ Py_buffer view;
+ res = PyObject_GetBuffer($input, &view, PyBUF_WRITABLE);
+ buf = view.buf;
+ size = view.len;
+ PyBuffer_Release(&view);
+ if (res < 0) {
+ PyErr_Clear();
+ %argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum);
+ }
+ $1 = ($1_ltype) buf;
+ $2 = ($2_ltype) size;
+ }
+
+ %typemap(typecheck) (TYPEMAP, SIZE) {
+ $1 = PyObject_CheckBuffer($input) || PyTuple_Check($input) ? 1 : 0;
+ }
+%enddef
+
+%define %clear_mutable_buffer(TYPEMAP, SIZE)
+ %typemap(in) (TYPEMAP, SIZE);
+ %typemap(typecheck) (TYPEMAP, SIZE);
+%enddef
+
+
+%define %driver_buffer_out
+ %typemap(out) (char*) {
+ auto size = arg1->size();
+ int readOnly = 0;
+ $result = PyMemoryView_FromMemory($1, size, readOnly);
+ }
+%enddef
+
+%define %clear_driver_buffer_out
+ %typemap(out) (char*);
+%enddef