From 6316ec9cc5d008201c9b2fa68258179210590b47 Mon Sep 17 00:00:00 2001 From: Arturo Buzarra Date: Wed, 23 Jun 2021 16:26:12 +0200 Subject: [PATCH] meta-digi: Add Google Coral support recipes This commit adds the required libraries and packages to exercise the Google Coral devices with Digi Embedded Yocto. https://onedigi.atlassian.net/browse/DEL-7547 Signed-off-by: Arturo Buzarra --- .../recipes-bsp/libedgetpu/libedgetpu_13.0.bb | 37 ++++++++++ .../tensorflow-lite/tensorflow-lite_2.5.0.bb | 46 +++++++++++++ meta-digi-dey/conf/distro/dey.conf | 3 + .../python3-pycoral/python3-pycoral_1.0.1.bb | 68 +++++++++++++++++++ 4 files changed, 154 insertions(+) create mode 100644 meta-digi-arm/recipes-bsp/libedgetpu/libedgetpu_13.0.bb create mode 100644 meta-digi-arm/recipes-bsp/tensorflow-lite/tensorflow-lite_2.5.0.bb create mode 100644 meta-digi-dey/recipes-devtools/python3-pycoral/python3-pycoral_1.0.1.bb diff --git a/meta-digi-arm/recipes-bsp/libedgetpu/libedgetpu_13.0.bb b/meta-digi-arm/recipes-bsp/libedgetpu/libedgetpu_13.0.bb new file mode 100644 index 000000000..aebd42ece --- /dev/null +++ b/meta-digi-arm/recipes-bsp/libedgetpu/libedgetpu_13.0.bb @@ -0,0 +1,37 @@ +SUMMARY = "Edge TPU runtime library for Coral devices" +HOMEPAGE = "https://coral.googlesource.com/edgetpu" +LICENSE = "Apache-2.0" +LIC_FILES_CHKSUM = "file://libedgetpu/LICENSE.txt;md5=c0e85c67b919e863a1a7a3da109dc40d" + +SRC_URI = "https://dl.google.com/coral/edgetpu_api/edgetpu_runtime_20210119.zip" +SRC_URI[md5sum] = "5c0b992d73683e395d6993761064d2df" +SRC_URI[sha256sum] = "b23b2c5a227d7f0e65dcc91585028d27c12e764f8ce4c4db3f114be4a49af3ae" + +S = "${WORKDIR}/edgetpu_runtime" + +RDEPENDS_${PN} = "libusb1" + +# The library files in direct correspond to max frequency, those in throttled correspond to reduced frequency. +LIBEDGETPU_TYPE = "direct" +LIBEDGETPU_ARCH = "aarch64" + +do_install() { + install -d ${D}${sysconfdir}/udev/rules.d + install -m 0644 ${S}/libedgetpu/edgetpu-accelerator.rules \ + ${D}${sysconfdir}/udev/rules.d/99-edgetpu-accelerator.rules + + install -d ${D}/${libdir} + install -m 755 ${S}/libedgetpu/${LIBEDGETPU_TYPE}/${LIBEDGETPU_ARCH}/libedgetpu.so.1.0 \ + ${D}/${libdir}/libedgetpu.so.1.0 + ln -sf ${libdir}/libedgetpu.so.1.0 ${D}/${libdir}/libedgetpu.so.1 + ln -sf ${libdir}/libedgetpu.so.1.0 ${D}/${libdir}/libedgetpu.so + + install -d ${D}/${includedir} + install -m 755 ${S}/libedgetpu/edgetpu.h ${D}/${includedir}/edgetpu.h +} + +FILES_${PN} += "${libdir}/libedgetpu.so \ + ${includedir}/edgetpu.h \ +" + +INSANE_SKIP_${PN} += "already-stripped" diff --git a/meta-digi-arm/recipes-bsp/tensorflow-lite/tensorflow-lite_2.5.0.bb b/meta-digi-arm/recipes-bsp/tensorflow-lite/tensorflow-lite_2.5.0.bb new file mode 100644 index 000000000..8a4fbab12 --- /dev/null +++ b/meta-digi-arm/recipes-bsp/tensorflow-lite/tensorflow-lite_2.5.0.bb @@ -0,0 +1,46 @@ +SUMMARY = "TensorFlow Lite Python Library" +DESCRIPTION = "TensorFlow Lite is the official solution for running machine learning models on mobile and embedded devices." +SECTION = "devel/python" +HOMEPAGE = "https://www.tensorflow.org/lite/" +LICENSE = "Apache-2.0" +LIC_FILES_CHKSUM = "file://${S}/tflite_runtime-2.5.0.dist-info/METADATA;md5=8c4b9e107a64b0121980a8705094014b" + +PYTHON_PACKAGE = "tflite_runtime-2.5.0-cp38-cp38-linux_aarch64.whl" + +SRC_URI = "https://github.com/google-coral/pycoral/releases/download/v1.0.1/${PYTHON_PACKAGE};downloadfilename=${PYTHON_PACKAGE};subdir=${BP}" +SRC_URI[md5sum] = "9c47617e1fa0bdca673a78b8b6688d64" +SRC_URI[sha256sum] = "b87a4c152be05d3585521a1d5418f7645a4fb82965772489b983e93aae6bd9ac" + +DEPENDS = "python3 python3-pip-native python3-wheel-native" + +RDEPENDS_${PN} = "${PYTHON_PN} \ + ${PYTHON_PN}-numpy \ +" + +inherit python3native + +do_unpack[depends] += "unzip-native:do_populate_sysroot" + +do_unpack_extra(){ + [ -d ${S} ] || mkdir -p ${S} + cd ${S} + unzip -q -o ${S}/${PYTHON_PACKAGE} -d ${S} +} +addtask unpack_extra after do_unpack before do_patch + +do_install() { + # Install pip package + install -d ${D}/${PYTHON_SITEPACKAGES_DIR} + ${STAGING_BINDIR_NATIVE}/pip3 install --disable-pip-version-check -v \ + -t ${D}/${PYTHON_SITEPACKAGES_DIR} --no-cache-dir --no-deps \ + ${WORKDIR}/${BP}/tflite_runtime-*.whl +} + +FILES_${PN} += "\ + ${libdir}/${PYTHON_DIR}/site-packages/* \ +" + +INSANE_SKIP_${PN} += "already-stripped" + +COMPATIBLE_MACHINE = "(-)" +COMPATIBLE_MACHINE_aarch64 = "(.*)" diff --git a/meta-digi-dey/conf/distro/dey.conf b/meta-digi-dey/conf/distro/dey.conf index ee59aa9e2..614150a65 100644 --- a/meta-digi-dey/conf/distro/dey.conf +++ b/meta-digi-dey/conf/distro/dey.conf @@ -76,6 +76,9 @@ PREFERRED_VERSION_wpewebkit = "2.32.1" # Use the FDO backend for WPE WebKit PREFERRED_PROVIDER_virtual/wpebackend = "wpebackend-fdo" +# Use recipe from our meta-digi layer +PREFERRED_VERSION_tensorflow-lite ?= "2.5.0" + SDK_NAME = "${DISTRO}-${TCLIBC}-${SDKMACHINE}-${IMAGE_BASENAME}-${TUNE_PKGARCH}-${MACHINE}" SDKPATH = "/opt/${DISTRO}/${SDK_VERSION}/${MACHINE}" diff --git a/meta-digi-dey/recipes-devtools/python3-pycoral/python3-pycoral_1.0.1.bb b/meta-digi-dey/recipes-devtools/python3-pycoral/python3-pycoral_1.0.1.bb new file mode 100644 index 000000000..a4c39d351 --- /dev/null +++ b/meta-digi-dey/recipes-devtools/python3-pycoral/python3-pycoral_1.0.1.bb @@ -0,0 +1,68 @@ +SUMMARY = "Python Library for Coral devices" +DESCRIPTION = "Python Library to run inferences and perform on-device transfer learning with TensorFlow Lite models on Coral devices" +SECTION = "devel/python" +HOMEPAGE = "https://coral.ai/software/#pycoral-api" +LICENSE = "Apache-2.0" +LIC_FILES_CHKSUM = "file://${S}/pycoral-1.0.1.dist-info/LICENSE;md5=d8927f3331d2b3e321b7dd1925166d25" + +PYTHON_PACKAGE = "pycoral-1.0.1-cp38-cp38-linux_aarch64.whl" + +SRC_URI = "git://github.com/google-coral/pycoral.git;protocol=https" +SRCREV = "d4b9f572fa3baef9d854483a171e02a6b3f9dbd0" + +SRC_URI += "https://github.com/google-coral/pycoral/releases/download/v1.0.1/${PYTHON_PACKAGE};downloadfilename=${PYTHON_PACKAGE};subdir=${BP};name=python-wheel" +SRC_URI[python-wheel.md5sum] = "ea89677a47d7d81d2558b8dbbae44d95" +SRC_URI[python-wheel.sha256sum] = "894468447192fbcf946157db0f3b6424ece6d70bcec1243892d27cd7b521f176" + +DEPENDS = "python3 python3-pip-native python3-wheel-native curl-native ca-certificates-native" + +RDEPENDS_${PN} = "${PYTHON_PN} \ + ${PYTHON_PN}-numpy \ + ${PYTHON_PN}-pycairo \ + ${PYTHON_PN}-pygobject \ + ${PYTHON_PN}-pillow \ + libedgetpu \ + tensorflow-lite \ +" + +inherit python3native + +do_unpack[depends] += "unzip-native:do_populate_sysroot" + +do_unpack_extra(){ + [ -d ${S} ] || mkdir -p ${S} + cd ${S} + unzip -q -o ${S}/${PYTHON_PACKAGE} -d ${S} +} +addtask unpack_extra after do_unpack before do_patch + + +do_configure() { + export CURL_CA_BUNDLE=${STAGING_DIR_NATIVE}/etc/ssl/certs/ca-certificates.crt + + cd ${WORKDIR}/git + bash examples/install_requirements.sh classify_image.py +} + +do_install() { + # Install examples + install -d ${D}/opt/pycoral + install -m 0555 ${WORKDIR}/git/test_data/* ${D}/opt/pycoral + install -m 0555 ${WORKDIR}/git/examples/classify_image.py ${D}/opt/pycoral + + # Install pip package + install -d ${D}/${PYTHON_SITEPACKAGES_DIR} + ${STAGING_BINDIR_NATIVE}/pip3 install --disable-pip-version-check -v \ + -t ${D}/${PYTHON_SITEPACKAGES_DIR} --no-cache-dir --no-deps \ + ${WORKDIR}/${BP}/pycoral-*.whl +} + +FILES_${PN} += "\ + ${libdir}/${PYTHON_DIR}/site-packages/* \ + /opt/pycoral/* \ +" + +INSANE_SKIP_${PN} += "already-stripped" + +COMPATIBLE_MACHINE = "(-)" +COMPATIBLE_MACHINE_aarch64 = "(.*)"