summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSrinivas Kandagatla <srinivas.kandagatla@linaro.org>2019-09-05 17:27:39 +0100
committerSrinivas Kandagatla <srinivas.kandagatla@linaro.org>2019-09-30 15:09:00 +0100
commitb7133d3c4ed463d42db456fa87bc3c7fad0d01bd (patch)
tree5f4db6f687aa4d8d9902b6a7fa8fb25c64c238d2
ImagenetCv: First commitcamera
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
-rw-r--r--CMakeLists.txt7
-rw-r--r--ImagenetCv.cpp1269
-rw-r--r--README153
-rw-r--r--include/hexagon_nn.h222
-rwxr-xr-xinclude/remote.h294
-rwxr-xr-xinclude/rpcmem.h140
6 files changed, 2085 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..4dc5ad0
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 2.8)
+project( ImagenetCv )
+find_package( OpenCV REQUIRED )
+include_directories( ${OpenCV_INCLUDE_DIRS} ./include/ )
+link_directories( /home/linaro/apps )
+add_executable( ImagenetCv ImagenetCv.cpp )
+target_link_libraries( ImagenetCv ${OpenCV_LIBS} -lhexagon_nn -lcdsprpc )
diff --git a/ImagenetCv.cpp b/ImagenetCv.cpp
new file mode 100644
index 0000000..6361636
--- /dev/null
+++ b/ImagenetCv.cpp
@@ -0,0 +1,1269 @@
+/*
+ * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2019, Linaro Limited
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted (subject to the limitations in the
+ * disclaimer below) provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
+ * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
+ * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <opencv2/core.hpp>
+#include <opencv2/videoio.hpp>
+#include <opencv2/highgui.hpp>
+#include <opencv2/imgproc.hpp>
+#include <iostream>
+#include <fstream>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <math.h>
+#include <stdint.h>
+#include <rpcmem.h>
+#include <hexagon_nn.h>
+#include <assert.h>
+
+using namespace std;
+using namespace cv;
+using std::cout; using std::cerr; using std::endl;
+#define IMG_HEIGHT 299
+#define IMG_WIDTH 299
+#define IMG_DEPTH 3
+#define IMG_ELEMENT_SIZE 1
+#define BUFFER_SIZE (IMG_ELEMENT_SIZE * IMG_WIDTH * IMG_HEIGHT * IMG_DEPTH)
+#define ION_HEAP_ID_SYSTEM 25
+#define OUTPUT_SIZE (1024 * sizeof(float))
+
+extern "C" void init_graph(int nn_id);
+
+const char *categories[] = {
+"dummy",
+"kit fox",
+"English setter",
+"Siberian husky",
+"Australian terrier",
+"English springer",
+"grey whale",
+"lesser panda",
+"Egyptian cat",
+"ibex",
+"Persian cat",
+"cougar",
+"gazelle",
+"porcupine",
+"sea lion",
+"malamute",
+"badger",
+"Great Dane",
+"Walker hound",
+"Welsh springer spaniel",
+"whippet",
+"Scottish deerhound",
+"killer whale",
+"mink",
+"African elephant",
+"Weimaraner",
+"soft-coated wheaten terrier",
+"Dandie Dinmont",
+"red wolf",
+"Old English sheepdog",
+"jaguar",
+"otterhound",
+"bloodhound",
+"Airedale",
+"hyena",
+"meerkat",
+"giant schnauzer",
+"titi",
+"three-toed sloth",
+"sorrel",
+"black-footed ferret",
+"dalmatian",
+"black-and-tan coonhound",
+"papillon",
+"skunk",
+"Staffordshire bullterrier",
+"Mexican hairless",
+"Bouvier des Flandres",
+"weasel",
+"miniature poodle",
+"Cardigan",
+"malinois",
+"bighorn",
+"fox squirrel",
+"colobus",
+"tiger cat",
+"Lhasa",
+"impala",
+"coyote",
+"Yorkshire terrier",
+"Newfoundland",
+"brown bear",
+"red fox",
+"Norwegian elkhound",
+"Rottweiler",
+"hartebeest",
+"Saluki",
+"grey fox",
+"schipperke",
+"Pekinese",
+"Brabancon griffon",
+"West Highland white terrier",
+"Sealyham terrier",
+"guenon",
+"mongoose",
+"indri",
+"tiger",
+"Irish wolfhound",
+"wild boar",
+"EntleBucher",
+"zebra",
+"ram",
+"French bulldog",
+"orangutan",
+"basenji",
+"leopard",
+"Bernese mountain dog",
+"Maltese dog",
+"Norfolk terrier",
+"toy terrier",
+"vizsla",
+"cairn",
+"squirrel monkey",
+"groenendael",
+"clumber",
+"Siamese cat",
+"chimpanzee",
+"komondor",
+"Afghan hound",
+"Japanese spaniel",
+"proboscis monkey",
+"guinea pig",
+"white wolf",
+"ice bear",
+"gorilla",
+"borzoi",
+"toy poodle",
+"Kerry blue terrier",
+"ox",
+"Scotch terrier",
+"Tibetan mastiff",
+"spider monkey",
+"Doberman",
+"Boston bull",
+"Greater Swiss Mountain dog",
+"Appenzeller",
+"Shih-Tzu",
+"Irish water spaniel",
+"Pomeranian",
+"Bedlington terrier",
+"warthog",
+"Arabian camel",
+"siamang",
+"miniature schnauzer",
+"collie",
+"golden retriever",
+"Irish terrier",
+"affenpinscher",
+"Border collie",
+"hare",
+"boxer",
+"silky terrier",
+"beagle",
+"Leonberg",
+"German short-haired pointer",
+"patas",
+"dhole",
+"baboon",
+"macaque",
+"Chesapeake Bay retriever",
+"bull mastiff",
+"kuvasz",
+"capuchin",
+"pug",
+"curly-coated retriever",
+"Norwich terrier",
+"flat-coated retriever",
+"hog",
+"keeshond",
+"Eskimo dog",
+"Brittany spaniel",
+"standard poodle",
+"Lakeland terrier",
+"snow leopard",
+"Gordon setter",
+"dingo",
+"standard schnauzer",
+"hamster",
+"Tibetan terrier",
+"Arctic fox",
+"wire-haired fox terrier",
+"basset",
+"water buffalo",
+"American black bear",
+"Angora",
+"bison",
+"howler monkey",
+"hippopotamus",
+"chow",
+"giant panda",
+"American Staffordshire terrier",
+"Shetland sheepdog",
+"Great Pyrenees",
+"Chihuahua",
+"tabby",
+"marmoset",
+"Labrador retriever",
+"Saint Bernard",
+"armadillo",
+"Samoyed",
+"bluetick",
+"redbone",
+"polecat",
+"marmot",
+"kelpie",
+"gibbon",
+"llama",
+"miniature pinscher",
+"wood rabbit",
+"Italian greyhound",
+"lion",
+"cocker spaniel",
+"Irish setter",
+"dugong",
+"Indian elephant",
+"beaver",
+"Sussex spaniel",
+"Pembroke",
+"Blenheim spaniel",
+"Madagascar cat",
+"Rhodesian ridgeback",
+"lynx",
+"African hunting dog",
+"langur",
+"Ibizan hound",
+"timber wolf",
+"cheetah",
+"English foxhound",
+"briard",
+"sloth bear",
+"Border terrier",
+"German shepherd",
+"otter",
+"koala",
+"tusker",
+"echidna",
+"wallaby",
+"platypus",
+"wombat",
+"revolver",
+"umbrella",
+"schooner",
+"soccer ball",
+"accordion",
+"ant",
+"starfish",
+"chambered nautilus",
+"grand piano",
+"laptop",
+"strawberry",
+"airliner",
+"warplane",
+"airship",
+"balloon",
+"space shuttle",
+"fireboat",
+"gondola",
+"speedboat",
+"lifeboat",
+"canoe",
+"yawl",
+"catamaran",
+"trimaran",
+"container ship",
+"liner",
+"pirate",
+"aircraft carrier",
+"submarine",
+"wreck",
+"half track",
+"tank",
+"missile",
+"bobsled",
+"dogsled",
+"bicycle-built-for-two",
+"mountain bike",
+"freight car",
+"passenger car",
+"barrow",
+"shopping cart",
+"motor scooter",
+"forklift",
+"electric locomotive",
+"steam locomotive",
+"amphibian",
+"ambulance",
+"beach wagon",
+"cab",
+"convertible",
+"jeep",
+"limousine",
+"minivan",
+"Model T",
+"racer",
+"sports car",
+"go-kart",
+"golfcart",
+"moped",
+"snowplow",
+"fire engine",
+"garbage truck",
+"pickup",
+"tow truck",
+"trailer truck",
+"moving van",
+"police van",
+"recreational vehicle",
+"streetcar",
+"snowmobile",
+"tractor",
+"mobile home",
+"tricycle",
+"unicycle",
+"horse cart",
+"jinrikisha",
+"oxcart",
+"bassinet",
+"cradle",
+"crib",
+"four-poster",
+"bookcase",
+"china cabinet",
+"medicine chest",
+"chiffonier",
+"table lamp",
+"file",
+"park bench",
+"barber chair",
+"throne",
+"folding chair",
+"rocking chair",
+"studio couch",
+"toilet seat",
+"desk",
+"pool table",
+"dining table",
+"entertainment center",
+"wardrobe",
+"Granny Smith",
+"orange",
+"lemon",
+"fig",
+"pineapple",
+"banana",
+"jackfruit",
+"custard apple",
+"pomegranate",
+"acorn",
+"hip",
+"ear",
+"rapeseed",
+"corn",
+"buckeye",
+"organ",
+"upright",
+"chime",
+"drum",
+"gong",
+"maraca",
+"marimba",
+"steel drum",
+"banjo",
+"cello",
+"violin",
+"harp",
+"acoustic guitar",
+"electric guitar",
+"cornet",
+"French horn",
+"trombone",
+"harmonica",
+"ocarina",
+"panpipe",
+"bassoon",
+"oboe",
+"sax",
+"flute",
+"daisy",
+"yellow lady's slipper",
+"cliff",
+"valley",
+"alp",
+"volcano",
+"promontory",
+"sandbar",
+"coral reef",
+"lakeside",
+"seashore",
+"geyser",
+"hatchet",
+"cleaver",
+"letter opener",
+"plane",
+"power drill",
+"lawn mower",
+"hammer",
+"corkscrew",
+"can opener",
+"plunger",
+"screwdriver",
+"shovel",
+"plow",
+"chain saw",
+"cock",
+"hen",
+"ostrich",
+"brambling",
+"goldfinch",
+"house finch",
+"junco",
+"indigo bunting",
+"robin",
+"bulbul",
+"jay",
+"magpie",
+"chickadee",
+"water ouzel",
+"kite",
+"bald eagle",
+"vulture",
+"great grey owl",
+"black grouse",
+"ptarmigan",
+"ruffed grouse",
+"prairie chicken",
+"peacock",
+"quail",
+"partridge",
+"African grey",
+"macaw",
+"sulphur-crested cockatoo",
+"lorikeet",
+"coucal",
+"bee eater",
+"hornbill",
+"hummingbird",
+"jacamar",
+"toucan",
+"drake",
+"red-breasted merganser",
+"goose",
+"black swan",
+"white stork",
+"black stork",
+"spoonbill",
+"flamingo",
+"American egret",
+"little blue heron",
+"bittern",
+"crane",
+"limpkin",
+"American coot",
+"bustard",
+"ruddy turnstone",
+"red-backed sandpiper",
+"redshank",
+"dowitcher",
+"oystercatcher",
+"European gallinule",
+"pelican",
+"king penguin",
+"albatross",
+"great white shark",
+"tiger shark",
+"hammerhead",
+"electric ray",
+"stingray",
+"barracouta",
+"coho",
+"tench",
+"goldfish",
+"eel",
+"rock beauty",
+"anemone fish",
+"lionfish",
+"puffer",
+"sturgeon",
+"gar",
+"loggerhead",
+"leatherback turtle",
+"mud turtle",
+"terrapin",
+"box turtle",
+"banded gecko",
+"common iguana",
+"American chameleon",
+"whiptail",
+"agama",
+"frilled lizard",
+"alligator lizard",
+"Gila monster",
+"green lizard",
+"African chameleon",
+"Komodo dragon",
+"triceratops",
+"African crocodile",
+"American alligator",
+"thunder snake",
+"ringneck snake",
+"hognose snake",
+"green snake",
+"king snake",
+"garter snake",
+"water snake",
+"vine snake",
+"night snake",
+"boa constrictor",
+"rock python",
+"Indian cobra",
+"green mamba",
+"sea snake",
+"horned viper",
+"diamondback",
+"sidewinder",
+"European fire salamander",
+"common newt",
+"eft",
+"spotted salamander",
+"axolotl",
+"bullfrog",
+"tree frog",
+"tailed frog",
+"whistle",
+"wing",
+"paintbrush",
+"hand blower",
+"oxygen mask",
+"snorkel",
+"loudspeaker",
+"microphone",
+"screen",
+"mouse",
+"electric fan",
+"oil filter",
+"strainer",
+"space heater",
+"stove",
+"guillotine",
+"barometer",
+"rule",
+"odometer",
+"scale",
+"analog clock",
+"digital clock",
+"wall clock",
+"hourglass",
+"sundial",
+"parking meter",
+"stopwatch",
+"digital watch",
+"stethoscope",
+"syringe",
+"magnetic compass",
+"binoculars",
+"projector",
+"sunglasses",
+"loupe",
+"radio telescope",
+"bow",
+"cannon [ground]",
+"assault rifle",
+"rifle",
+"projectile",
+"computer keyboard",
+"typewriter keyboard",
+"crane",
+"lighter",
+"abacus",
+"cash machine",
+"slide rule",
+"desktop computer",
+"hand-held computer",
+"notebook",
+"web site",
+"harvester",
+"thresher",
+"printer",
+"slot",
+"vending machine",
+"sewing machine",
+"joystick",
+"switch",
+"hook",
+"car wheel",
+"paddlewheel",
+"pinwheel",
+"potter's wheel",
+"gas pump",
+"carousel",
+"swing",
+"reel",
+"radiator",
+"puck",
+"hard disc",
+"sunglass",
+"pick",
+"car mirror",
+"solar dish",
+"remote control",
+"disk brake",
+"buckle",
+"hair slide",
+"knot",
+"combination lock",
+"padlock",
+"nail",
+"safety pin",
+"screw",
+"muzzle",
+"seat belt",
+"ski",
+"candle",
+"jack-o'-lantern",
+"spotlight",
+"torch",
+"neck brace",
+"pier",
+"tripod",
+"maypole",
+"mousetrap",
+"spider web",
+"trilobite",
+"harvestman",
+"scorpion",
+"black and gold garden spider",
+"barn spider",
+"garden spider",
+"black widow",
+"tarantula",
+"wolf spider",
+"tick",
+"centipede",
+"isopod",
+"Dungeness crab",
+"rock crab",
+"fiddler crab",
+"king crab",
+"American lobster",
+"spiny lobster",
+"crayfish",
+"hermit crab",
+"tiger beetle",
+"ladybug",
+"ground beetle",
+"long-horned beetle",
+"leaf beetle",
+"dung beetle",
+"rhinoceros beetle",
+"weevil",
+"fly",
+"bee",
+"grasshopper",
+"cricket",
+"walking stick",
+"cockroach",
+"mantis",
+"cicada",
+"leafhopper",
+"lacewing",
+"dragonfly",
+"damselfly",
+"admiral",
+"ringlet",
+"monarch",
+"cabbage butterfly",
+"sulphur butterfly",
+"lycaenid",
+"jellyfish",
+"sea anemone",
+"brain coral",
+"flatworm",
+"nematode",
+"conch",
+"snail",
+"slug",
+"sea slug",
+"chiton",
+"sea urchin",
+"sea cucumber",
+"iron",
+"espresso maker",
+"microwave",
+"Dutch oven",
+"rotisserie",
+"toaster",
+"waffle iron",
+"vacuum",
+"dishwasher",
+"refrigerator",
+"washer",
+"Crock Pot",
+"frying pan",
+"wok",
+"caldron",
+"coffeepot",
+"teapot",
+"spatula",
+"altar",
+"triumphal arch",
+"patio",
+"steel arch bridge",
+"suspension bridge",
+"viaduct",
+"barn",
+"greenhouse",
+"palace",
+"monastery",
+"library",
+"apiary",
+"boathouse",
+"church",
+"mosque",
+"stupa",
+"planetarium",
+"restaurant",
+"cinema",
+"home theater",
+"lumbermill",
+"coil",
+"obelisk",
+"totem pole",
+"castle",
+"prison",
+"grocery store",
+"bakery",
+"barbershop",
+"bookshop",
+"butcher shop",
+"confectionery",
+"shoe shop",
+"tobacco shop",
+"toyshop",
+"fountain",
+"cliff dwelling",
+"yurt",
+"dock",
+"brass",
+"megalith",
+"bannister",
+"breakwater",
+"dam",
+"chainlink fence",
+"picket fence",
+"worm fence",
+"stone wall",
+"grille",
+"sliding door",
+"turnstile",
+"mountain tent",
+"scoreboard",
+"honeycomb",
+"plate rack",
+"pedestal",
+"beacon",
+"mashed potato",
+"bell pepper",
+"head cabbage",
+"broccoli",
+"cauliflower",
+"zucchini",
+"spaghetti squash",
+"acorn squash",
+"butternut squash",
+"cucumber",
+"artichoke",
+"cardoon",
+"mushroom",
+"shower curtain",
+"jean",
+"carton",
+"handkerchief",
+"sandal",
+"ashcan",
+"safe",
+"plate",
+"necklace",
+"croquet ball",
+"fur coat",
+"thimble",
+"pajama",
+"running shoe",
+"cocktail shaker",
+"chest",
+"manhole cover",
+"modem",
+"tub",
+"tray",
+"balance beam",
+"bagel",
+"prayer rug",
+"kimono",
+"hot pot",
+"whiskey jug",
+"knee pad",
+"book jacket",
+"spindle",
+"ski mask",
+"beer bottle",
+"crash helmet",
+"bottlecap",
+"tile roof",
+"mask",
+"maillot",
+"Petri dish",
+"football helmet",
+"bathing cap",
+"teddy bear",
+"holster",
+"pop bottle",
+"photocopier",
+"vestment",
+"crossword puzzle",
+"golf ball",
+"trifle",
+"suit",
+"water tower",
+"feather boa",
+"cloak",
+"red wine",
+"drumstick",
+"shield",
+"Christmas stocking",
+"hoopskirt",
+"menu",
+"stage",
+"bonnet",
+"meat loaf",
+"baseball",
+"face powder",
+"scabbard",
+"sunscreen",
+"beer glass",
+"hen-of-the-woods",
+"guacamole",
+"lampshade",
+"wool",
+"hay",
+"bow tie",
+"mailbag",
+"water jug",
+"bucket",
+"dishrag",
+"soup bowl",
+"eggnog",
+"mortar",
+"trench coat",
+"paddle",
+"chain",
+"swab",
+"mixing bowl",
+"potpie",
+"wine bottle",
+"shoji",
+"bulletproof vest",
+"drilling platform",
+"binder",
+"cardigan",
+"sweatshirt",
+"pot",
+"birdhouse",
+"hamper",
+"ping-pong ball",
+"pencil box",
+"pay-phone",
+"consomme",
+"apron",
+"punching bag",
+"backpack",
+"groom",
+"bearskin",
+"pencil sharpener",
+"broom",
+"mosquito net",
+"abaya",
+"mortarboard",
+"poncho",
+"crutch",
+"Polaroid camera",
+"space bar",
+"cup",
+"racket",
+"traffic light",
+"quill",
+"radio",
+"dough",
+"cuirass",
+"military uniform",
+"lipstick",
+"shower cap",
+"monitor",
+"oscilloscope",
+"mitten",
+"brassiere",
+"French loaf",
+"vase",
+"milk can",
+"rugby ball",
+"paper towel",
+"earthstar",
+"envelope",
+"miniskirt",
+"cowboy hat",
+"trolleybus",
+"perfume",
+"bathtub",
+"hotdog",
+"coral fungus",
+"bullet train",
+"pillow",
+"toilet tissue",
+"cassette",
+"carpenter's kit",
+"ladle",
+"stinkhorn",
+"lotion",
+"hair spray",
+"academic gown",
+"dome",
+"crate",
+"wig",
+"burrito",
+"pill bottle",
+"chain mail",
+"theater curtain",
+"window shade",
+"barrel",
+"washbasin",
+"ballpoint",
+"basketball",
+"bath towel",
+"cowboy boot",
+"gown",
+"window screen",
+"agaric",
+"cellular telephone",
+"nipple",
+"barbell",
+"mailbox",
+"lab coat",
+"fire screen",
+"minibus",
+"packet",
+"maze",
+"pole",
+"horizontal bar",
+"sombrero",
+"pickelhaube",
+"rain barrel",
+"wallet",
+"cassette player",
+"comic book",
+"piggy bank",
+"street sign",
+"bell cote",
+"fountain pen",
+"Windsor tie",
+"volleyball",
+"overskirt",
+"sarong",
+"purse",
+"bolo tie",
+"bib",
+"parachute",
+"sleeping bag",
+"television",
+"swimming trunks",
+"measuring cup",
+"espresso",
+"pizza",
+"breastplate",
+"shopping basket",
+"wooden spoon",
+"saltshaker",
+"chocolate sauce",
+"ballplayer",
+"goblet",
+"gyromitra",
+"stretcher",
+"water bottle",
+"dial telephone",
+"soap dispenser",
+"jersey",
+"school bus",
+"jigsaw puzzle",
+"plastic bag",
+"reflex camera",
+"diaper",
+"Band Aid",
+"ice lolly",
+"velvet",
+"tennis ball",
+"gasmask",
+"doormat",
+"Loafer",
+"ice cream",
+"pretzel",
+"quilt",
+"maillot",
+"tape player",
+"clog",
+"iPod",
+"bolete",
+"scuba diver",
+"pitcher",
+"matchstick",
+"bikini",
+"sock",
+"CD player",
+"lens cap",
+"thatch",
+"vault",
+"beaker",
+"bubble",
+"cheeseburger",
+"parallel bars",
+"flagpole",
+"coffee mug",
+"rubber eraser",
+"stole",
+"carbonara",
+"dumbbell",
+"OVERFLOW!",
+"OVERFLOW!",
+"OVERFLOW!",
+"OVERFLOW!",
+"OVERFLOW!",
+"OVERFLOW!",
+"OVERFLOW!",
+"OVERFLOW!",
+"OVERFLOW!",
+"OVERFLOW!",
+"OVERFLOW!",
+"OVERFLOW!",
+"OVERFLOW!",
+"OVERFLOW!",
+"OVERFLOW!",
+"OVERFLOW!",
+"OVERFLOW!",
+"OVERFLOW!",
+"OVERFLOW!",
+"OVERFLOW!",
+"OVERFLOW!",
+"OVERFLOW!",
+"OVERFLOW!",
+};
+
+struct indexed_data {
+ float f;
+ int i;
+};
+
+int indexed_data_sort(const void *va, const void *vb)
+{
+ const struct indexed_data *a = (const struct indexed_data *)va;
+ const struct indexed_data *b = (const struct indexed_data *)vb;
+ if (a->f > b->f) return -1;
+ if (a->f < b->f) return 1;
+ return 0;
+}
+#define NUM_CATEGORIES 1024
+struct indexed_data data[NUM_CATEGORIES];
+
+void get_top5(float *v, Mat *frame)
+{
+ int i, k;
+ char label[256];
+ int fontface = cv::FONT_HERSHEY_PLAIN;
+ double scale = 1.0;
+ int thickness = 1;
+ int baseline = 0;
+
+ for (i = 0; i < NUM_CATEGORIES; i++) {
+ data[i].f = v[i];
+ data[i].i = i;
+ }
+
+ qsort(data, NUM_CATEGORIES,sizeof(struct indexed_data),
+ indexed_data_sort);
+
+ for (i = 0; i < 5; i++) {
+ k = (i + 1)*20;
+ sprintf(label, "%02.2f%%, %s",data[i].f * 100,
+ categories[data[i].i]);
+ cv::Size text = cv::getTextSize(label, fontface, scale, thickness, &baseline);
+ cv::rectangle(*frame, cv::Point(30, k) + cv::Point(0, baseline), cv::Point(30, k) + cv::Point(text.width, -text.height), CV_RGB(0,0,0), cv::FILLED);
+ cv::putText(*frame, label, cv::Point(30,k),
+ cv::FONT_HERSHEY_PLAIN,
+ 1.0, cv::Scalar(57,255,20), 1, LINE_8);
+
+ }
+}
+static int match_check(const void *va, const void *vb)
+{
+ float *a = (float *) va;
+ float *b = (float *) vb;
+ if (a < b) return -1;
+ if (a > b) return 1;
+ return 0;
+}
+
+static float get_top5_match(float *values, int n_floats, int *idx)
+{
+ qsort(values, n_floats, sizeof(float), match_check);
+ return 0;
+}
+
+static float get_top_match(float *values, int n_floats, int *idx)
+{
+ int i;
+ float match = 0.0;
+ for (i = 0; i < n_floats; i++) {
+ if (values[i] > match) {
+ match = values[i];
+ *idx = i;
+ }
+ }
+
+ return match;
+}
+
+// Convert a tensor of uchar into a tensor of floats
+static int uint8_to_float(uint8_t *data, uint8_t *fdata, size_t length)
+{
+ float *float_data = (float *)fdata;
+
+ // Scale the uint8t data into floats
+ for (int i = 0; i < length; i++)
+ float_data[i] = (data[i] * (1.0) / 255) + 0.0;
+
+ return 0;
+}
+
+static int imagenet_run(uint32_t id, void *input, void *output, void *finput)
+{
+ uint32_t out_batches, out_height, out_width, out_depth, out_data_size;
+ int elementsize;
+
+ uint8_to_float((uint8_t *)input, (uint8_t*)finput, BUFFER_SIZE);
+ elementsize = sizeof(float);
+
+ return hexagon_nn_execute(id, 1, IMG_HEIGHT, IMG_WIDTH, IMG_DEPTH,
+ (const uint8_t *)finput,
+ IMG_DEPTH * IMG_HEIGHT * IMG_WIDTH * elementsize,
+ &out_batches, &out_height, &out_width, &out_depth,
+ (uint8_t *)output, OUTPUT_SIZE,&out_data_size);
+}
+
+int main(int, char**)
+{
+ uint32_t graph_id;
+ Mat frame, frame1, cFrame;
+ void *data, *output, *fdata;
+ char label[256];
+ int ret, idx = 0;
+ float match;
+
+ hexagon_nn_config();
+ ret = hexagon_nn_init((hexagon_nn_nn_id*)&graph_id);
+ hexagon_nn_set_debug_level(graph_id, 0);
+
+ /* Imagenet graph init */
+ init_graph(graph_id);
+
+ ret = hexagon_nn_prepare(graph_id);
+ if (ret) {
+ printf("Error: Could not prepare New Graph\n");
+ return ret;
+ }
+
+ /* Allocate buffers */
+ if ((data = rpcmem_alloc(ION_HEAP_ID_SYSTEM, RPCMEM_DEFAULT_FLAGS,
+ BUFFER_SIZE)) == NULL) {
+ printf("malloc failed\n");
+ return -1;
+ }
+
+ if ((output = rpcmem_alloc(ION_HEAP_ID_SYSTEM, RPCMEM_DEFAULT_FLAGS,
+ OUTPUT_SIZE)) == NULL) {
+ printf("error: malloc fail");
+ return -1;
+ }
+
+ if ((fdata = rpcmem_alloc(ION_HEAP_ID_SYSTEM, RPCMEM_DEFAULT_FLAGS,
+ sizeof(float)*BUFFER_SIZE)) == NULL) {
+ printf("malloc failed\n");
+ return -1;
+ }
+ Mat rgb_mat(IMG_HEIGHT, IMG_WIDTH, CV_8UC3, data);
+
+ VideoCapture capture(2); // open the first camera
+ if (!capture.isOpened())
+ {
+ cerr << "ERROR: Can't initialize camera capture" << endl;
+ return 1;
+ }
+ for (;;)
+ {
+ capture >> frame; // read the next frame from camera
+ if (frame.empty())
+ {
+ cerr << "ERROR: Can't grab camera frame." << endl;
+ break;
+ }
+
+ cv::resize(frame, frame1, cv::Size(IMG_HEIGHT, IMG_WIDTH));
+ cv::cvtColor(frame1, rgb_mat, cv::COLOR_BGR2RGB);
+ /* Pass resize image buffers to imagenet graph */
+ if (imagenet_run(graph_id, data, output, fdata) != 0)
+ return -1;
+
+ get_top5((float *)output, &frame);
+ imshow("USB-Camera", frame);
+ waitKey(1);
+ }
+
+ /* Free rpmsg buffers */
+ hexagon_nn_teardown(graph_id);
+ rpcmem_free(output);
+ rpcmem_free(fdata);
+ rpcmem_free(data);
+
+ return 0;
+}
diff --git a/README b/README
new file mode 100644
index 0000000..63a7747
--- /dev/null
+++ b/README
@@ -0,0 +1,153 @@
+Here are few steps required to get Imagenet based on OpenCV working DB845c
+
+######################## On Host #################################
+
+Step 1: Build Hexagon NN DSP library for DB845c CDSP
+------------------------------------------------------
+## First download (https://developer.qualcomm.com/downloads/hexagon-sdk-v342-linux?referrer=node/6116)
+and Install Hexagon SDK 3.4.2 if you have not already done
+## Compile Hexagon NN with below commands.
+
+$ source $HEXAGON_SDK_ROOT/setup_sdk_env.source
+$ cd $HEXAGON_SDK_ROOT/libs/hexagon_nn/2.5/
+$ make tree VERBOSE=1 CDSP_FLAG=1 V=hexagon_Release_dynamic_toolv82_v65 V65=1
+
+This step will generate hexagon_Release_dynamic_toolv82_v65/ship/libhexagon_nn_skel.so
+which is a shared library for the CDSP.
+
+Step 2: Generate Testsig and sign libhexagon_nn_skel.so with it.
+------------------------------------------------------
+##Get serial number from the DB845c console using below command and pass it to elfsigner.py.
+
+root@linaro-alip:/# cat /sys/bus/soc/devices/soc0/serial_number
+
+##elfsigner tool takes SoC Serial number as input to generate a testsig, you can get
+##serial number by using getserial or from board sysfs entry as described in above step
+
+$ cd $HEXAGON_SDK_ROOT
+$ python tools/elfsigner/elfsigner.py -t $SERIAL_NUMBER
+$ python tools/elfsigner/elfsigner.py -i libs/hexagon_nn/2.5/hexagon_Release_dynamic_toolv82_v65/ship/libhexagon_nn_skel.so
+
+Step 3: Generate Inception v3 model graph for hexagon.
+------------------------------------------------------
+
+Option 1: Download the Tensorflow Inception v3 Frozen graph and covert to hexagon compatible c file.
+========
+$ curl http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz -o /tmp/inceptionv3.tgz
+$ tar xzf /tmp/inceptionv3.tgz -C /tmp/
+
+## Then download and Install bazel and build tensorflow More instructions at https://docs.bazel.build/versions/master/install-ubuntu.html
+## I have used Bazel 0.21.0 and TensorFlow 1.13.2 release version.
+
+$ wget https://github.com/bazelbuild/bazel/releases/download/0.21.0/bazel-0.21.0-installer-linux-x86_64.sh
+$ wget https://github.com/tensorflow/tensorflow/archive/v1.13.2.tar.gz
+$ chmod +x bazel-0.21.0-installer-linux-x86_64.sh
+$ sh ./bazel-0.21.0-installer-linux-x86_64.sh --user
+$ tar -zxvf v1.13.2.tar.gz
+$ cd tensorflow-1.13.2
+$ ./configure
+
+## Build transform_graph tool in tensorflow About tranform_graph https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/graph_transforms/README.md#using-the-graph-transform-tool
+
+$ bazel build tensorflow/tools/graph_transforms:transform_graph
+
+## Quantize protobuf using Graph Transform Tool
+
+$ bazel-bin/tensorflow/tools/graph_transforms/transform_graph --in_graph=/tmp/classify_image_graph_def.pb --out_graph=/tmp/inception_v3_quantized.pb --inputs="Mul" --outputs='softmax' --transforms='add_default_attributes strip_unused_nodes(type=float, shape="1,299,299,3") remove_nodes(op=Identity, op=CheckNumerics) fold_constants(ignore_errors=true) fold_batch_norms fold_old_batch_norms quantize_weights quantize_nodes fold_constants strip_unused_nodes sort_by_execution_order'
+
+##Then convert the quantized protobuf into a C file:
+
+$ cd $HEXAGON_SDK_ROOT/examples/hexagon_nn/
+$ virtualenv -p python2 env2
+$ source env2/bin/activate
+$ pip install -r environments/req2.txt
+$ cd -
+$ python $HEXAGON_SDK_ROOT/examples/hexagon_nn/scripts/tensorflow_to_hexagon_nn.py /tmp/inception_v3_quantized.pb $HEXAGON_SDK_ROOT/examples/hexagon_nn/tutorials/007-tensorflow-to-hexagon-nn/inceptionv3_v1.yaml > iv3.c
+$ cp iv3.c $HEXAGON_SDK_ROOT/libs/hexagon_nn/2.5/
+
+Option 2: download iv3.c file which I generated using above steps.
+========
+I can share my iv3.c file incase you want to avoid installing tensor flow on your machine.
+$ cp iv3.c $HEXAGON_SDK_ROOT/libs/hexagon_nn/2.5/
+
+Step 4: Compile new fastrpc library
+------------------------------------------------------
+
+$ git clone -b automake https://git.linaro.org/landing-teams/working/qualcomm/fastrpc.git
+$ cd fastrpc
+$ ./autogen.sh
+$ ./configure --host=aarch64-linux-gnu
+$ make
+$ cp src/.libs/libadsprpc.so* $HEXAGON_SDK_ROOT/libs/common/remote/ship/UbuntuARM_Debug_aarch64/
+$ cp src/.libs/libcdsprpc.so* $HEXAGON_SDK_ROOT/libs/common/remote/ship/UbuntuARM_Debug_aarch64
+
+Step 5: Compile hexagon-nn shared userspace library.
+------------------------------------------------------
+
+## Patch Hexagon NN with patch to compile as shared library for userspace.
+$ cd $HEXAGON_SDK_ROOT/libs/hexagon_nn/2.5/
+$ wget http://people.linaro.org/~srinivas.kandagatla/hexagon_nn_3.4.2_shared_lib.patch
+$ patch -p1 < hexagon_nn_3.4.2_shared_lib.patch
+$ make tree V=UbuntuARM_Debug_aarch64 CDSP_FLAG=1 V65=1 GRAPHINIT="iv3.c"
+
+
+Step 6: Push files to target
+------------------------------------------------------
+$ ssh linaro@DB_IP_ADDR mkdir /home/linaro/apps /home/linaro/dsp
+
+$ scp $HEXAGON_SDK_ROOT/output/testsig*.so linaro@DB_IP_ADDR:~/dsp/
+$ scp $HEXAGON_SDK_ROOT/output/libhexagon_nn_skel.so linaro@DB_IP_ADDR:~/dsp/
+
+$ scp $HEXAGON_SDK_ROOT/libs/hexagon_nn/2.5/UbuntuARM_Debug_aarch64/ship/libhexagon_nn.so linaro@DB_IP_ADDR:~/apps/
+$ scp $FASTRPC_LIB_PATH/src/.libs/libcdsp* linaro@DB_IP_ADDR:~/apps/
+$ scp $FASTRPC_LIB_PATH/src/.libs/libadsp* linaro@DB_IP_ADDR:~/apps/
+$ scp $FASTRPC_LIB_PATH/src/.libs/*rpcd linaro@DB_IP_ADDR:~/apps/
+
+
+######################## on TARGET DB845c ###############################
+
+Step 1: Install new fastrpc lib on DB845c
+------------------------------------------------------
+## For now remove any old adsprpc libraries. new releases should not need this, but for now lets do it.
+$ rm /usr/local/libadsp* /usr/local/libcdsp* /usr/local/bin/cdsprpcd /usr/local/bin/adsprpcd
+$ cp /home/linaro/apps/libcdsp* /usr/local/lib/
+$ cp /home/linaro/apps/libcdsp* /usr/local/lib/
+$ cp /home/linaro/apps/*rpcd /usr/local/bin
+
+Step 2: Copy dsp libraries to correct place and start cdsprpcd deamon
+------------------------------------------------------
+$ mkdir /dsp
+$ mount /dev/disk/by-partlabel/dsp_a /dsp
+$ cp /home/linaro/dsp/* /dsp/cdsp/
+$ export ADSP_LIBRARY_PATH=/dsp/cdsp
+$ cdsprpcd&
+
+Step 3: Install OpenCV on the Target
+------------------------------------------------------
+##Its possible to optimize opencv by enabling neon but for now lets ignore this!
+
+$ git clone https://github.com/opencv/opencv.git
+$ cd ~/opencv
+$ mkdir build
+$ cd build
+$ cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
+$ make -j8
+$ sudo make install
+
+Or
+
+$ sudo apt-get install libopencv-dev python3-opencv
+
+
+Step 4: Build OpenCV Imagenet application and run
+------------------------------------------------------
+## To Build ##
+$ git clone https://git.linaro.org/people/srinivas.kandagatla/ImagenetCv.git
+$ cd ImagenetCv
+$ cmake .
+$ make
+$ ./ImagenetCv
+
+Same instructions apply to images branch aswell.
+This should show up a live video with Image Classifications.
+
diff --git a/include/hexagon_nn.h b/include/hexagon_nn.h
new file mode 100644
index 0000000..8892878
--- /dev/null
+++ b/include/hexagon_nn.h
@@ -0,0 +1,222 @@
+#ifndef _HEXAGON_NN_H
+#define _HEXAGON_NN_H
+//#include <AEEStdDef.h>
+#include "remote.h"
+#ifndef __QAIC_HEADER
+#define __QAIC_HEADER(ff) ff
+#endif //__QAIC_HEADER
+
+#ifndef __QAIC_HEADER_EXPORT
+#define __QAIC_HEADER_EXPORT
+#endif // __QAIC_HEADER_EXPORT
+
+#ifndef __QAIC_HEADER_ATTRIBUTE
+#define __QAIC_HEADER_ATTRIBUTE
+#endif // __QAIC_HEADER_ATTRIBUTE
+
+#ifndef __QAIC_IMPL
+#define __QAIC_IMPL(ff) ff
+#endif //__QAIC_IMPL
+
+#ifndef __QAIC_IMPL_EXPORT
+#define __QAIC_IMPL_EXPORT
+#endif // __QAIC_IMPL_EXPORT
+
+#ifndef __QAIC_IMPL_ATTRIBUTE
+#define __QAIC_IMPL_ATTRIBUTE
+#endif // __QAIC_IMPL_ATTRIBUTE
+#ifdef __cplusplus
+extern "C" {
+#endif
+#if !defined(__QAIC_STRING1_OBJECT_DEFINED__) && !defined(__STRING1_OBJECT__)
+#define __QAIC_STRING1_OBJECT_DEFINED__
+#define __STRING1_OBJECT__
+typedef struct _cstring1_s {
+ char* data;
+ int dataLen;
+} _cstring1_t;
+
+#endif /* __QAIC_STRING1_OBJECT_DEFINED__ */
+typedef struct hexagon_nn_input hexagon_nn_input;
+struct hexagon_nn_input {
+ unsigned int src_id;
+ unsigned int output_idx;
+};
+typedef struct hexagon_nn_output hexagon_nn_output;
+struct hexagon_nn_output {
+ unsigned int rank;
+ unsigned int max_sizes[8];
+ unsigned int elementsize;
+ int zero_offset;
+ float stepsize;
+};
+typedef struct hexagon_nn_perfinfo hexagon_nn_perfinfo;
+struct hexagon_nn_perfinfo {
+ unsigned int node_id;
+ unsigned int executions;
+ unsigned int counter_lo;
+ unsigned int counter_hi;
+};
+typedef int hexagon_nn_nn_id;
+typedef struct hexagon_nn_initinfo hexagon_nn_initinfo;
+struct hexagon_nn_initinfo {
+ int priority;
+};
+enum hexagon_nn_padding_type {
+ NN_PAD_NA,
+ NN_PAD_SAME,
+ NN_PAD_VALID,
+ NN_PAD_MIRROR_REFLECT,
+ NN_PAD_MIRROR_SYMMETRIC,
+ NN_PAD_SAME_CAFFE,
+ _32BIT_PLACEHOLDER_hexagon_nn_padding_type = 0x7fffffff
+};
+typedef enum hexagon_nn_padding_type hexagon_nn_padding_type;
+enum hexagon_nn_corner_type {
+ NN_CORNER_RELEASE,
+ NN_CORNER_TURBO,
+ NN_CORNER_NOMPLUS,
+ NN_CORNER_NOMINAL,
+ NN_CORNER_SVSPLUS,
+ NN_CORNER_SVS,
+ NN_CORNER_SVS2,
+ _32BIT_PLACEHOLDER_hexagon_nn_corner_type = 0x7fffffff
+};
+typedef enum hexagon_nn_corner_type hexagon_nn_corner_type;
+enum hexagon_nn_dcvs_type {
+ NN_DCVS_DEFAULT,
+ NN_DCVS_ENABLE,
+ NN_DCVS_DISABLE,
+ _32BIT_PLACEHOLDER_hexagon_nn_dcvs_type = 0x7fffffff
+};
+typedef enum hexagon_nn_dcvs_type hexagon_nn_dcvs_type;
+typedef struct hexagon_nn_tensordef hexagon_nn_tensordef;
+struct hexagon_nn_tensordef {
+ unsigned int batches;
+ unsigned int height;
+ unsigned int width;
+ unsigned int depth;
+ unsigned char* data;
+ int dataLen;
+ unsigned int data_valid_len;
+ unsigned int unused;
+};
+enum hexagon_nn_option_type {
+ NN_OPTION_NOSUCHOPTION,
+ NN_OPTION_SCALAR_THREADS,
+ NN_OPTION_HVX_THREADS,
+ NN_OPTION_VTCM_REQ,
+ _32BIT_PLACEHOLDER_hexagon_nn_option_type = 0x7fffffff
+};
+typedef enum hexagon_nn_option_type hexagon_nn_option_type;
+typedef struct hexagon_nn_uint_option hexagon_nn_uint_option;
+struct hexagon_nn_uint_option {
+ unsigned int option_id;
+ unsigned int uint_value;
+};
+typedef struct hexagon_nn_string_option hexagon_nn_string_option;
+struct hexagon_nn_string_option {
+ unsigned int option_id;
+ unsigned char* string_data;
+ int string_dataLen;
+ unsigned int string_valid_len;
+};
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_config)(void) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_config_with_options)(const hexagon_nn_uint_option* uint_options, int uint_optionsLen, const hexagon_nn_string_option* string_options, int string_optionsLen) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_get_dsp_offset)(unsigned int* libhexagon_addr, unsigned int* fastrpc_shell_addr) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_init)(hexagon_nn_nn_id* g) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_set_debug_level)(hexagon_nn_nn_id id, int level) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_snpprint)(hexagon_nn_nn_id id, unsigned char* buf, int bufLen) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_getlog)(hexagon_nn_nn_id id, unsigned char* buf, int bufLen) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_append_node)(hexagon_nn_nn_id id, unsigned int node_id, unsigned int operation, hexagon_nn_padding_type padding, const hexagon_nn_input* inputs, int inputsLen, const hexagon_nn_output* outputs, int outputsLen) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_append_const_node)(hexagon_nn_nn_id id, unsigned int node_id, unsigned int batches, unsigned int height, unsigned int width, unsigned int depth, const unsigned char* data, int dataLen) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_append_empty_const_node)(hexagon_nn_nn_id id, unsigned int node_id, unsigned int batches, unsigned int height, unsigned int width, unsigned int depth, unsigned int size) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_populate_const_node)(hexagon_nn_nn_id id, unsigned int node_id, const unsigned char* data, int dataLen, unsigned int target_offset) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_prepare)(hexagon_nn_nn_id id) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_execute)(hexagon_nn_nn_id id, unsigned int batches_in, unsigned int height_in, unsigned int width_in, unsigned int depth_in, const unsigned char* data_in, int data_inLen, unsigned int* batches_out, unsigned int* height_out, unsigned int* width_out, unsigned int* depth_out, unsigned char* data_out, int data_outLen, unsigned int* data_len_out) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_teardown)(hexagon_nn_nn_id id) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_variable_read)(hexagon_nn_nn_id id, unsigned int node_id, int output_index, unsigned int* batches_out, unsigned int* height_out, unsigned int* width_out, unsigned int* depth_out, unsigned char* data_out, int data_outLen, unsigned int* data_len_out) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_variable_write)(hexagon_nn_nn_id id, unsigned int node_id, int output_index, unsigned int batches, unsigned int height, unsigned int width, unsigned int depth, const unsigned char* data_in, int data_inLen) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_variable_write_flat)(hexagon_nn_nn_id id, unsigned int node_id, int output_index, const unsigned char* data_in, int data_inLen) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_set_powersave_level)(unsigned int level) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_set_powersave_details)(hexagon_nn_corner_type corner, hexagon_nn_dcvs_type dcvs, unsigned int latency) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_get_perfinfo)(hexagon_nn_nn_id id, hexagon_nn_perfinfo* info_out, int info_outLen, unsigned int* n_items) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_reset_perfinfo)(hexagon_nn_nn_id id, unsigned int event) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_last_execution_cycles)(hexagon_nn_nn_id id, unsigned int* cycles_lo, unsigned int* cycles_hi) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_version)(int* ver) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_op_name_to_id)(const char* name, unsigned int* node_id) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_op_id_to_name)(unsigned int node_id, char* name, int nameLen) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_get_num_nodes_in_graph)(hexagon_nn_nn_id id, unsigned int* num_nodes) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_disable_dcvs)(void) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_GetHexagonBinaryVersion)(int* ver) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_PrintLog)(const unsigned char* buf, int bufLen) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_execute_new)(hexagon_nn_nn_id id, const hexagon_nn_tensordef* inputs, int inputsLen, hexagon_nn_tensordef* outputs, int outputsLen) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_init_with_info)(hexagon_nn_nn_id* g, const hexagon_nn_initinfo* info) __QAIC_HEADER_ATTRIBUTE;
+/**
+ * Opens the handle in the specified domain. If this is the first
+ * handle, this creates the session. Typically this means opening
+ * the device, aka open("/dev/adsprpc-smd"), then calling ioctl
+ * device APIs to create a PD on the DSP to execute our code in,
+ * then asking that PD to dlopen the .so and dlsym the skel function.
+ *
+ * @param uri, <interface>_URI"&_dom=aDSP"
+ * <interface>_URI is a QAIC generated uri, or
+ * "file:///<sofilename>?<interface>_skel_handle_invoke&_modver=1.0"
+ * If the _dom parameter is not present, _dom=DEFAULT is assumed
+ * but not forwarded.
+ * Reserved uri keys:
+ * [0]: first unamed argument is the skel invoke function
+ * _dom: execution domain name, _dom=mDSP/aDSP/DEFAULT
+ * _modver: module version, _modver=1.0
+ * _*: any other key name starting with an _ is reserved
+ * Unknown uri keys/values are forwarded as is.
+ * @param h, resulting handle
+ * @retval, 0 on success
+ */
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_open)(const char* uri, remote_handle64* h) __QAIC_HEADER_ATTRIBUTE;
+/**
+ * Closes a handle. If this is the last handle to close, the session
+ * is closed as well, releasing all the allocated resources.
+
+ * @param h, the handle to close
+ * @retval, 0 on success, should always succeed
+ */
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_close)(remote_handle64 h) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_config)(remote_handle64 _h) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_config_with_options)(remote_handle64 _h, const hexagon_nn_uint_option* uint_options, int uint_optionsLen, const hexagon_nn_string_option* string_options, int string_optionsLen) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_get_dsp_offset)(remote_handle64 _h, unsigned int* libhexagon_addr, unsigned int* fastrpc_shell_addr) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_init)(remote_handle64 _h, hexagon_nn_nn_id* g) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_set_debug_level)(remote_handle64 _h, hexagon_nn_nn_id id, int level) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_snpprint)(remote_handle64 _h, hexagon_nn_nn_id id, unsigned char* buf, int bufLen) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_getlog)(remote_handle64 _h, hexagon_nn_nn_id id, unsigned char* buf, int bufLen) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_append_node)(remote_handle64 _h, hexagon_nn_nn_id id, unsigned int node_id, unsigned int operation, hexagon_nn_padding_type padding, const hexagon_nn_input* inputs, int inputsLen, const hexagon_nn_output* outputs, int outputsLen) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_append_const_node)(remote_handle64 _h, hexagon_nn_nn_id id, unsigned int node_id, unsigned int batches, unsigned int height, unsigned int width, unsigned int depth, const unsigned char* data, int dataLen) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_append_empty_const_node)(remote_handle64 _h, hexagon_nn_nn_id id, unsigned int node_id, unsigned int batches, unsigned int height, unsigned int width, unsigned int depth, unsigned int size) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_populate_const_node)(remote_handle64 _h, hexagon_nn_nn_id id, unsigned int node_id, const unsigned char* data, int dataLen, unsigned int target_offset) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_prepare)(remote_handle64 _h, hexagon_nn_nn_id id) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_execute)(remote_handle64 _h, hexagon_nn_nn_id id, unsigned int batches_in, unsigned int height_in, unsigned int width_in, unsigned int depth_in, const unsigned char* data_in, int data_inLen, unsigned int* batches_out, unsigned int* height_out, unsigned int* width_out, unsigned int* depth_out, unsigned char* data_out, int data_outLen, unsigned int* data_len_out) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_teardown)(remote_handle64 _h, hexagon_nn_nn_id id) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_variable_read)(remote_handle64 _h, hexagon_nn_nn_id id, unsigned int node_id, int output_index, unsigned int* batches_out, unsigned int* height_out, unsigned int* width_out, unsigned int* depth_out, unsigned char* data_out, int data_outLen, unsigned int* data_len_out) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_variable_write)(remote_handle64 _h, hexagon_nn_nn_id id, unsigned int node_id, int output_index, unsigned int batches, unsigned int height, unsigned int width, unsigned int depth, const unsigned char* data_in, int data_inLen) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_variable_write_flat)(remote_handle64 _h, hexagon_nn_nn_id id, unsigned int node_id, int output_index, const unsigned char* data_in, int data_inLen) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_set_powersave_level)(remote_handle64 _h, unsigned int level) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_set_powersave_details)(remote_handle64 _h, hexagon_nn_corner_type corner, hexagon_nn_dcvs_type dcvs, unsigned int latency) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_get_perfinfo)(remote_handle64 _h, hexagon_nn_nn_id id, hexagon_nn_perfinfo* info_out, int info_outLen, unsigned int* n_items) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_reset_perfinfo)(remote_handle64 _h, hexagon_nn_nn_id id, unsigned int event) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_last_execution_cycles)(remote_handle64 _h, hexagon_nn_nn_id id, unsigned int* cycles_lo, unsigned int* cycles_hi) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_version)(remote_handle64 _h, int* ver) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_op_name_to_id)(remote_handle64 _h, const char* name, unsigned int* node_id) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_op_id_to_name)(remote_handle64 _h, unsigned int node_id, char* name, int nameLen) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_get_num_nodes_in_graph)(remote_handle64 _h, hexagon_nn_nn_id id, unsigned int* num_nodes) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_disable_dcvs)(remote_handle64 _h) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_GetHexagonBinaryVersion)(remote_handle64 _h, int* ver) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_PrintLog)(remote_handle64 _h, const unsigned char* buf, int bufLen) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_execute_new)(remote_handle64 _h, hexagon_nn_nn_id id, const hexagon_nn_tensordef* inputs, int inputsLen, hexagon_nn_tensordef* outputs, int outputsLen) __QAIC_HEADER_ATTRIBUTE;
+__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_domains_init_with_info)(remote_handle64 _h, hexagon_nn_nn_id* g, const hexagon_nn_initinfo* info) __QAIC_HEADER_ATTRIBUTE;
+#ifndef hexagon_nn_domains_URI
+#define hexagon_nn_domains_URI "file:///libhexagon_nn_skel.so?hexagon_nn_domains_skel_handle_invoke&_modver=1.0"
+#endif /*hexagon_nn_domains_URI*/
+#ifdef __cplusplus
+}
+#endif
+#endif //_HEXAGON_NN_H
diff --git a/include/remote.h b/include/remote.h
new file mode 100755
index 0000000..813cc33
--- /dev/null
+++ b/include/remote.h
@@ -0,0 +1,294 @@
+/*
+ * Copyright (c) 2012-2014,2016,2017 Qualcomm Technologies, Inc.
+ * All Rights Reserved.
+ * Confidential and Proprietary - Qualcomm Technologies, Inc.
+ */
+#ifndef REMOTE_H
+#define REMOTE_H
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef uint32_t remote_handle;
+typedef uint64_t remote_handle64; //! used by multi domain modules
+ //! 64 bit handles are translated to 32 bit values
+ //! by the transport layer
+
+typedef struct {
+ void *pv;
+ size_t nLen;
+} remote_buf;
+
+typedef struct {
+ int32_t fd;
+ uint32_t offset;
+} remote_dma_handle;
+
+typedef union {
+ remote_buf buf;
+ remote_handle h;
+ remote_handle64 h64; //! used by multi domain modules
+ remote_dma_handle dma;
+} remote_arg;
+
+/*Retrives method attribute from the scalars parameter*/
+#define REMOTE_SCALARS_METHOD_ATTR(dwScalars) (((dwScalars) >> 29) & 0x7)
+
+/*Retrives method index from the scalars parameter*/
+#define REMOTE_SCALARS_METHOD(dwScalars) (((dwScalars) >> 24) & 0x1f)
+
+/*Retrives number of input buffers from the scalars parameter*/
+#define REMOTE_SCALARS_INBUFS(dwScalars) (((dwScalars) >> 16) & 0x0ff)
+
+/*Retrives number of output buffers from the scalars parameter*/
+#define REMOTE_SCALARS_OUTBUFS(dwScalars) (((dwScalars) >> 8) & 0x0ff)
+
+/*Retrives number of input handles from the scalars parameter*/
+#define REMOTE_SCALARS_INHANDLES(dwScalars) (((dwScalars) >> 4) & 0x0f)
+
+/*Retrives number of output handles from the scalars parameter*/
+#define REMOTE_SCALARS_OUTHANDLES(dwScalars) ((dwScalars) & 0x0f)
+
+#define REMOTE_SCALARS_MAKEX(nAttr,nMethod,nIn,nOut,noIn,noOut) \
+ ((((uint32_t) (nAttr) & 0x7) << 29) | \
+ (((uint32_t) (nMethod) & 0x1f) << 24) | \
+ (((uint32_t) (nIn) & 0xff) << 16) | \
+ (((uint32_t) (nOut) & 0xff) << 8) | \
+ (((uint32_t) (noIn) & 0x0f) << 4) | \
+ ((uint32_t) (noOut) & 0x0f))
+
+#define REMOTE_SCALARS_MAKE(nMethod,nIn,nOut) REMOTE_SCALARS_MAKEX(0,nMethod,nIn,nOut,0,0)
+
+#define REMOTE_SCALARS_LENGTH(sc) (REMOTE_SCALARS_INBUFS(sc) +\
+ REMOTE_SCALARS_OUTBUFS(sc) +\
+ REMOTE_SCALARS_INHANDLES(sc) +\
+ REMOTE_SCALARS_OUTHANDLES(sc))
+
+#ifndef __QAIC_REMOTE
+#define __QAIC_REMOTE(ff) ff
+#endif //__QAIC_REMOTE
+
+#ifndef __QAIC_REMOTE_EXPORT
+#ifdef _WIN32
+#define __QAIC_REMOTE_EXPORT __declspec(dllexport)
+#else //_WIN32
+#define __QAIC_REMOTE_EXPORT
+#endif //_WIN32
+#endif //__QAIC_REMOTE_EXPORT
+
+#ifndef __QAIC_REMOTE_ATTRIBUTE
+#define __QAIC_REMOTE_ATTRIBUTE
+#endif
+
+#define NUM_DOMAINS 4
+#define NUM_SESSIONS 2
+#define DOMAIN_ID_MASK 3
+
+#ifndef DEFAULT_DOMAIN_ID
+#define DEFAULT_DOMAIN_ID 0
+#endif
+
+#define ADSP_DOMAIN_ID 0
+#define MDSP_DOMAIN_ID 1
+#define SDSP_DOMAIN_ID 2
+#define CDSP_DOMAIN_ID 3
+
+#define ADSP_DOMAIN "&_dom=adsp"
+#define MDSP_DOMAIN "&_dom=mdsp"
+#define SDSP_DOMAIN "&_dom=sdsp"
+#define CDSP_DOMAIN "&_dom=cdsp"
+
+/* All other values are reserved */
+
+/* opens a remote_handle "name"
+ * returns 0 on success
+ */
+__QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_handle_open)(const char* name, remote_handle *ph) __QAIC_REMOTE_ATTRIBUTE;
+__QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_handle64_open)(const char* name, remote_handle64 *ph) __QAIC_REMOTE_ATTRIBUTE;
+
+/* invokes the remote handle
+ * see retrive macro's on dwScalars format
+ * pra, contains the arguments in the following order, inbufs, outbufs, inhandles, outhandles.
+ * implementors should ignore and pass values asis that the transport doesn't understand.
+ */
+__QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_handle_invoke)(remote_handle h, uint32_t dwScalars, remote_arg *pra) __QAIC_REMOTE_ATTRIBUTE;
+__QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_handle64_invoke)(remote_handle64 h, uint32_t dwScalars, remote_arg *pra) __QAIC_REMOTE_ATTRIBUTE;
+
+/* closes the remote handle
+ */
+__QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_handle_close)(remote_handle h) __QAIC_REMOTE_ATTRIBUTE;
+__QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_handle64_close)(remote_handle64 h) __QAIC_REMOTE_ATTRIBUTE;
+
+/* remote handle control interface
+ */
+/* request ID for fastrpc latency control */
+#define DSPRPC_CONTROL_LATENCY (1)
+struct remote_rpc_control_latency {
+ uint32_t enable; // enable auto control of rpc latency
+ uint32_t latency; // latency: reserved
+};
+
+__QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_handle_control)(uint32_t req, void* data, uint32_t datalen) __QAIC_REMOTE_ATTRIBUTE;
+__QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_handle64_control)(remote_handle64 h, uint32_t req, void* data, uint32_t datalen) __QAIC_REMOTE_ATTRIBUTE;
+
+/* remote session control interface
+ */
+/* request ID for setting DSP user thread params */
+#define FASTRPC_THREAD_PARAMS (1)
+struct remote_rpc_thread_params {
+ int domain; // Remote subsystem domain ID, pass -1 to set params for all domains
+ int prio; // user thread priority (1 to 255), pass -1 to use default
+ int stack_size; // user thread stack size, pass -1 to use default
+};
+
+/* request ID for fastrpc unsigned module */
+#define DSPRPC_CONTROL_UNSIGNED_MODULE (2)
+struct remote_rpc_control_unsigned_module {
+ int domain; // Remote subsystem domain ID, -1 to set params for all domains
+ int enable; // enable unsigned module loading
+};
+
+/* Set remote session parameters
+ *
+ * @param req, request ID
+ * @param data, address of structure with parameters
+ * @param datalen, length of data
+ * @retval, 0 on success
+ */
+__QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_session_control)(uint32_t req, void *data, uint32_t datalen) __QAIC_REMOTE_ATTRIBUTE;
+
+/* map memory to the remote domain
+ *
+ * @param fd, fd assosciated with this memory
+ * @param flags, flags to be used for the mapping
+ * @param vaddrin, input address
+ * @param size, size of buffer
+ * @param vaddrout, output address
+ * @retval, 0 on success
+ */
+__QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_mmap)(int fd, uint32_t flags, uint32_t vaddrin, int size, uint32_t* vaddrout) __QAIC_REMOTE_ATTRIBUTE;
+
+/* unmap memory from the remote domain
+ *
+ * @param vaddrout, remote address mapped
+ * @param size, size to unmap. Unmapping a range partially may not be supported.
+ * @retval, 0 on success, may fail if memory is still mapped
+ */
+__QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_munmap)(uint32_t vaddrout, int size) __QAIC_REMOTE_ATTRIBUTE;
+
+/*
+ * Attribute to map a buffer as dma non-coherent
+ * Driver perform cache maintenance.
+ */
+#define FASTRPC_ATTR_NON_COHERENT (2)
+
+/*
+ * Attribute to map a buffer as dma coherent
+ * Driver skips cache maintenenace
+ * It will be ignored if a device is marked as dma-coherent in device tree.
+ */
+#define FASTRPC_ATTR_COHERENT (4)
+
+/* Attribute to keep the buffer persistant
+ * until unmap is called explicitly
+ */
+#define FASTRPC_ATTR_KEEP_MAP (8)
+
+/*
+ * Attribute for secure buffers to skip
+ * smmu mapping in fastrpc driver
+ */
+#define FASTRPC_ATTR_NOMAP (16)
+
+/* Register a file descriptor for a buffer. This is only valid on
+ * android with ION allocated memory. Users of fastrpc should register
+ * a buffer allocated with ION to enable sharing that buffer to the
+ * dsp via the smmu. Some versions of libadsprpc.so lack this
+ * function, so users should set this symbol as weak.
+ *
+ * #pragma weak remote_register_buf
+ * #pragma weak remote_register_buf_attr
+ *
+ * @param buf, virtual address of the buffer
+ * @param size, size of the buffer
+ * @fd, the file descriptor, callers can use -1 to deregister.
+ * @attr, map buffer as coherent or non-coherent
+ */
+__QAIC_REMOTE_EXPORT void __QAIC_REMOTE(remote_register_buf)(void* buf, int size, int fd) __QAIC_REMOTE_ATTRIBUTE;
+__QAIC_REMOTE_EXPORT void __QAIC_REMOTE(remote_register_buf_attr)(void* buf, int size, int fd, int attr) __QAIC_REMOTE_ATTRIBUTE;
+
+/* Register a dma handle with fastrpc. This is only valid on
+ * android with ION allocated memory. Users of fastrpc should register
+ * a file descriptor allocated with ION to enable sharing that memory to the
+ * dsp via the smmu. Some versions of libadsprpc.so lack this
+ * function, so users should set this symbol as weak.
+ *
+ * #pragma weak remote_register_dma_handle
+ * #pragma weak remote_register_dma_handle_attr
+ *
+ * @fd, the file descriptor, callers can use -1 to deregister.
+ * @param len, size of the buffer
+ * @attr, map buffer as coherent or non-coherent or no-map
+ */
+__QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_register_dma_handle)(int fd, uint32_t len) __QAIC_REMOTE_ATTRIBUTE;
+__QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_register_dma_handle_attr)(int fd, uint32_t len, uint32_t attr) __QAIC_REMOTE_ATTRIBUTE;
+
+/*
+ * This is the default mode for the driver. While the driver is in parallel
+ * mode it will try to invalidate output buffers after it transfers control
+ * to the dsp. This allows the invalidate operations to overlap with the
+ * dsp processing the call. This mode should be used when output buffers
+ * are only read on the application processor and only written on the aDSP.
+ */
+#define REMOTE_MODE_PARALLEL 0
+
+/*
+ * When operating in SERIAL mode the driver will invalidate output buffers
+ * before calling into the dsp. This mode should be used when output
+ * buffers have been written to somewhere besides the aDSP.
+ */
+#define REMOTE_MODE_SERIAL 1
+
+/*
+ * Internal transport prefix
+ */
+#define ITRANSPORT_PREFIX "'\":;./\\"
+
+/*
+ * Set the mode of operation.
+ *
+ * Some versions of libadsprpc.so lack this function, so users should set
+ * this symbol as weak.
+ *
+ * #pragma weak remote_set_mode
+ *
+ * @param mode, the mode
+ * @retval, 0 on success
+ */
+__QAIC_REMOTE_EXPORT int __QAIC_REMOTE(remote_set_mode)(uint32_t mode) __QAIC_REMOTE_ATTRIBUTE;
+
+/* Register a file descriptor. This can be used when users do not have
+ * a mapping to pass to the RPC layer. The generated address is a mapping
+ * with PROT_NONE, any access to this memory will fail, so it should only
+ * be used as an ID to identify this file descriptor to the RPC layer.
+ *
+ * To deregister use remote_register_buf(addr, size, -1).
+ *
+ * #pragma weak remote_register_fd
+ *
+ * @param fd, the file descriptor.
+ * @param size, size to of the buffer
+ * @retval, (void*)-1 on failure, address on success.
+ *
+ */
+__QAIC_REMOTE_EXPORT void *__QAIC_REMOTE(remote_register_fd)(int fd, int size) __QAIC_REMOTE_ATTRIBUTE;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // REMOTE_H
diff --git a/include/rpcmem.h b/include/rpcmem.h
new file mode 100755
index 0000000..960f1bd
--- /dev/null
+++ b/include/rpcmem.h
@@ -0,0 +1,140 @@
+/**
+ * Copyright (c) 2019, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef RPCMEM_H
+#define RPCMEM_H
+
+//#include "AEEStdDef.h"
+typedef uint32_t uint32;
+/**
+ * RPCMEM_DEFAULT_HEAP
+ * Dynamicaly select the heap to use. This should be ok for most usecases.
+ */
+#define RPCMEM_DEFAULT_HEAP -1
+
+
+/**
+ * RPCMEM_DEFAULT_FLAGS should allocate memory with the same properties
+ * as the ION_FLAG_CACHED flag
+ */
+#ifdef ION_FLAG_CACHED
+#define RPCMEM_DEFAULT_FLAGS ION_FLAG_CACHED
+#else
+#define RPCMEM_DEFAULT_FLAGS 1
+#endif
+
+/**
+ * RPCMEM_FLAG_UNCACHED
+ * ION_FLAG_CACHED should be defined as 1
+ */
+#define RPCMEM_FLAG_UNCACHED 0
+#define RPCMEM_FLAG_CACHED RPCMEM_DEFAULT_FLAGS
+
+/**
+ * examples:
+ *
+ * heap 22, uncached, 1kb
+ * rpcmem_alloc(22, 0, 1024);
+ * rpcmem_alloc(22, RPCMEM_FLAG_UNCACHED, 1024);
+ *
+ * heap 21, cached, 2kb
+ * rpcmem_alloc(21, RPCMEM_FLAG_CACHED, 2048);
+ * #include <ion.h>
+ * rpcmem_alloc(21, ION_FLAG_CACHED, 2048);
+ *
+ * just give me the defaults, 2kb
+ * rpcmem_alloc(RPCMEM_DEFAULT_HEAP, RPCMEM_DEFAULT_FLAGS, 2048);
+ * rpcmem_alloc_def(2048);
+ *
+ * give me the default flags, but from heap 18, 4kb
+ * rpcmem_alloc(18, RPCMEM_DEFAULT_FLAGS, 4096);
+ *
+ */
+#define ION_SECURE_FLAGS ((1 << 31) | (1 << 19))
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * call once to initialize the library
+ * Note: should not call this if rpcmem is linked from libadsprpc.so
+ * /libcdsprpc.so/libmdsprpc.so/libsdsprpc.so
+ */
+void rpcmem_init(void);
+/**
+ * call once for cleanup
+ * Note: should not call this if rpcmem is linked from libadsprpc.so
+ * /libcdsprpc.so/libmdsprpc.so/libsdsprpc.so
+ */
+void rpcmem_deinit(void);
+
+/**
+ * Allocate via ION a buffer of size
+ * @heapid, the heap id to use
+ * @flags, ion flags to use to when allocating
+ * @size, the buffer size to allocate
+ * @retval, 0 on failure, pointer to buffer on success
+ *
+ * For example:
+ * buf = rpcmem_alloc(RPCMEM_DEFAULT_HEAP, RPCMEM_DEFAULT_FLAGS, size);
+ */
+
+void* rpcmem_alloc(int heapid, uint32 flags, int size);
+
+/**
+ * allocate with default settings
+ */
+ #if !defined(WINNT) && !defined (_WIN32_WINNT)
+__attribute__((unused))
+#endif
+static __inline void* rpcmem_alloc_def(int size) {
+ return rpcmem_alloc(RPCMEM_DEFAULT_HEAP, RPCMEM_DEFAULT_FLAGS, size);
+}
+
+/**
+ * free buffer, ignores invalid buffers
+ */
+void rpcmem_free(void* po);
+
+/**
+ * returns associated fd
+ */
+int rpcmem_to_fd(void* po);
+
+#ifdef __cplusplus
+}
+#endif
+
+#define RPCMEM_HEAP_DEFAULT 0x80000000
+#define RPCMEM_HEAP_NOREG 0x40000000
+#define RPCMEM_HEAP_UNCACHED 0x20000000
+#define RPCMEM_HEAP_NOVA 0x10000000
+#define RPCMEM_HEAP_NONCOHERENT 0x08000000
+
+#endif //RPCMEM_H