diff --git a/benchmarks/DeepLearning/Models/CMakeLists.txt b/benchmarks/DeepLearning/Models/CMakeLists.txt index 89177d9bc3cff432d6021125ae56283fe34bfdbd..9c8233e3ca508e14242b09ac8473818e44dccd11 100644 --- a/benchmarks/DeepLearning/Models/CMakeLists.txt +++ b/benchmarks/DeepLearning/Models/CMakeLists.txt @@ -1,3 +1,5 @@ add_subdirectory(MobileNet-V2) add_subdirectory(ResNet-V2-50) add_subdirectory(MobileNet-V3) +add_subdirectory(Inception-V3) + diff --git a/benchmarks/DeepLearning/Models/Inception-V3/.gitattributes b/benchmarks/DeepLearning/Models/Inception-V3/.gitattributes new file mode 100644 index 0000000000000000000000000000000000000000..bb151175102ee82832fee4fcf1f1af78458c4bff --- /dev/null +++ b/benchmarks/DeepLearning/Models/Inception-V3/.gitattributes @@ -0,0 +1 @@ +Inception.mlir filter=lfs diff=lfs merge=lfs -text diff --git a/benchmarks/DeepLearning/Models/Inception-V3/CMakeLists.txt b/benchmarks/DeepLearning/Models/Inception-V3/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..12b18c4aed579564b215e5ba03e5d6d18f5efec2 --- /dev/null +++ b/benchmarks/DeepLearning/Models/Inception-V3/CMakeLists.txt @@ -0,0 +1,24 @@ +add_buddy_model_benchmark(inception-v3-benchmark + OpenCV + MLIR Inception.mlir + BITCODE inception-v3-default.o + LIBRARY InceptionV3Default + OPTIONS + --linalg-bufferize + --convert-linalg-to-loops + --convert-vector-to-scf + --convert-scf-to-std + --func-bufferize + --tensor-constant-bufferize + --tensor-bufferize + --std-bufferize + --finalizing-bufferize + --lower-affine + --convert-vector-to-llvm + -std-expand -arith-expand + --convert-memref-to-llvm + --convert-math-to-llvm + --convert-std-to-llvm='emit-c-wrappers=1' + --reconcile-unrealized-casts + SOURCE Main.cpp InceptionBenchmark.cpp +) diff --git a/benchmarks/DeepLearning/Models/Inception-V3/Images/curtain.png b/benchmarks/DeepLearning/Models/Inception-V3/Images/curtain.png new file mode 100644 index 0000000000000000000000000000000000000000..1ae383d3597c0c6e7cc1bc5e26c54aa4f78a7e84 Binary files /dev/null and b/benchmarks/DeepLearning/Models/Inception-V3/Images/curtain.png differ diff --git a/benchmarks/DeepLearning/Models/Inception-V3/Images/dog.png b/benchmarks/DeepLearning/Models/Inception-V3/Images/dog.png new file mode 100644 index 0000000000000000000000000000000000000000..12f0e0dd1162b94a5b0919ce8b91821450965985 Binary files /dev/null and b/benchmarks/DeepLearning/Models/Inception-V3/Images/dog.png differ diff --git a/benchmarks/DeepLearning/Models/Inception-V3/Images/ice-cream.png b/benchmarks/DeepLearning/Models/Inception-V3/Images/ice-cream.png new file mode 100644 index 0000000000000000000000000000000000000000..209d8999d6c2bd6321cd79e794a0c5d54db1c1ea Binary files /dev/null and b/benchmarks/DeepLearning/Models/Inception-V3/Images/ice-cream.png differ diff --git a/benchmarks/DeepLearning/Models/Inception-V3/Images/kite.png b/benchmarks/DeepLearning/Models/Inception-V3/Images/kite.png new file mode 100644 index 0000000000000000000000000000000000000000..23ffe9613dd96dcc5bee8c2bbe0467e6b845a117 Binary files /dev/null and b/benchmarks/DeepLearning/Models/Inception-V3/Images/kite.png differ diff --git a/benchmarks/DeepLearning/Models/Inception-V3/Images/traffic-light.png b/benchmarks/DeepLearning/Models/Inception-V3/Images/traffic-light.png new file mode 100644 index 0000000000000000000000000000000000000000..fa1a1e3f6170a08168a3bd58125ee278f302ede9 Binary files /dev/null and b/benchmarks/DeepLearning/Models/Inception-V3/Images/traffic-light.png differ diff --git a/benchmarks/DeepLearning/Models/Inception-V3/Inception.mlir b/benchmarks/DeepLearning/Models/Inception-V3/Inception.mlir new file mode 100644 index 0000000000000000000000000000000000000000..1166cd288e5869c8cbd5306a7b1728a9c29afcbc --- /dev/null +++ b/benchmarks/DeepLearning/Models/Inception-V3/Inception.mlir @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:213b3da8bded65e7783414943eaa9efefcea86195da1c9eb333866f92dcfff12 +size 204305331 diff --git a/benchmarks/DeepLearning/Models/Inception-V3/InceptionBenchmark.cpp b/benchmarks/DeepLearning/Models/Inception-V3/InceptionBenchmark.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cb6ce8f8d3aa3d56d5c63b1f1060ef4994b6dfac --- /dev/null +++ b/benchmarks/DeepLearning/Models/Inception-V3/InceptionBenchmark.cpp @@ -0,0 +1,124 @@ +//===- InceptionV3Benchmark.cpp +//---------------------------------------------===// +// +// 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 implements the benchmark for e2e inceptionv3. +// +//===----------------------------------------------------------------------===// + +#include "Utils/Container.h" +#include <benchmark/benchmark.h> +#include <fstream> +#include <opencv2/opencv.hpp> +#include <string> + +namespace { + +// Declare the inceptionv3 C interface. +extern "C" { +void _mlir_ciface_inception_v3(MemRef<float, 2> *output, + MemRef<float, 4> *input); +} + +const cv::Mat imagePreprocessing() { + + cv::Mat inputImage = cv::imread( + "../../benchmarks/DeepLearning/Models/Inception-V3/Images/dog.png"); + assert(!inputImage.empty() && "Could not read the image."); + cv::Mat resizedImage; + int imageWidth = 299; + int imageHeight = 299; + cv::resize(inputImage, resizedImage, cv::Size(imageWidth, imageHeight), + cv::INTER_LINEAR); + return resizedImage; +} + +cv::Mat image = imagePreprocessing(); + +intptr_t sizesInput[4] = {1, image.rows, image.cols, 3}; +intptr_t sizesOutnput[2] = {1, 1001}; + +MemRef<float, 4> input(image, sizesInput); +MemRef<float, 2> output(sizesOutnput); + +// Define benchmark function. +void BM_InceptionV3(benchmark::State &state) { + for (auto _ : state) { + for (int i = 0; i < state.range(0); ++i) { + _mlir_ciface_inception_v3(&output, &input); + } + } +} + +// Softmax function. +void softmax(float *input, size_t size) { + assert(0 <= size <= sizeof(input) / sizeof(float)); + int i; + float m, sum, constant; + m = -INFINITY; + for (i = 0; i < size; ++i) { + if (m < input[i]) { + m = input[i]; + } + } + + sum = 0.0; + for (i = 0; i < size; ++i) { + sum += exp(input[i] - m); + } + + constant = m + log(sum); + for (i = 0; i < size; ++i) { + input[i] = exp(input[i] - constant); + } +} + +std::string getLabel(int idx) { + std::ifstream in( + "../../benchmarks/DeepLearning/Models/Inception-V3/Labels.txt"); + assert(in.is_open() && "Could not read the label file."); + std::string label; + for (int i = 0; i < idx; ++i) + std::getline(in, label); + std::getline(in, label); + in.close(); + return label; +} + +} // namespace + +// Register benchmarking function with different arguments. +BENCHMARK(BM_InceptionV3)->Arg(1); + +// Print result function. +void printResult() { + // Run the model and activation function. + _mlir_ciface_inception_v3(&output, &input); + auto out = output.getData(); + softmax(out, 1001); + // Find the classification and print the result. + float maxVal = 0; + float maxIdx = 0; + for (int i = 0; i < 1001; ++i) { + if (out[i] > maxVal) { + maxVal = out[i]; + maxIdx = i; + } + } + std::cout << "Classification Index: " << maxIdx << std::endl; + std::cout << "Classification: " << getLabel(maxIdx) << std::endl; + std::cout << "Probability: " << maxVal << std::endl; +} diff --git a/benchmarks/DeepLearning/Models/Inception-V3/Labels.txt b/benchmarks/DeepLearning/Models/Inception-V3/Labels.txt new file mode 100644 index 0000000000000000000000000000000000000000..fe811239d8e2989de19fecabb1ebb0c9dddac514 --- /dev/null +++ b/benchmarks/DeepLearning/Models/Inception-V3/Labels.txt @@ -0,0 +1,1001 @@ +background +tench +goldfish +great white shark +tiger shark +hammerhead +electric ray +stingray +cock +hen +ostrich +brambling +goldfinch +house finch +junco +indigo bunting +robin +bulbul +jay +magpie +chickadee +water ouzel +kite +bald eagle +vulture +great grey owl +European fire salamander +common newt +eft +spotted salamander +axolotl +bullfrog +tree frog +tailed frog +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 +African crocodile +American alligator +triceratops +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 +trilobite +harvestman +scorpion +black and gold garden spider +barn spider +garden spider +black widow +tarantula +wolf spider +tick +centipede +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 +tusker +echidna +platypus +wallaby +koala +wombat +jellyfish +sea anemone +brain coral +flatworm +nematode +conch +snail +slug +sea slug +chiton +chambered nautilus +Dungeness crab +rock crab +fiddler crab +king crab +American lobster +spiny lobster +crayfish +hermit crab +isopod +white stork +black stork +spoonbill +flamingo +little blue heron +American egret +bittern +crane +limpkin +European gallinule +American coot +bustard +ruddy turnstone +red-backed sandpiper +redshank +dowitcher +oystercatcher +pelican +king penguin +albatross +grey whale +killer whale +dugong +sea lion +Chihuahua +Japanese spaniel +Maltese dog +Pekinese +Shih-Tzu +Blenheim spaniel +papillon +toy terrier +Rhodesian ridgeback +Afghan hound +basset +beagle +bloodhound +bluetick +black-and-tan coonhound +Walker hound +English foxhound +redbone +borzoi +Irish wolfhound +Italian greyhound +whippet +Ibizan hound +Norwegian elkhound +otterhound +Saluki +Scottish deerhound +Weimaraner +Staffordshire bullterrier +American Staffordshire terrier +Bedlington terrier +Border terrier +Kerry blue terrier +Irish terrier +Norfolk terrier +Norwich terrier +Yorkshire terrier +wire-haired fox terrier +Lakeland terrier +Sealyham terrier +Airedale +cairn +Australian terrier +Dandie Dinmont +Boston bull +miniature schnauzer +giant schnauzer +standard schnauzer +Scotch terrier +Tibetan terrier +silky terrier +soft-coated wheaten terrier +West Highland white terrier +Lhasa +flat-coated retriever +curly-coated retriever +golden retriever +Labrador retriever +Chesapeake Bay retriever +German short-haired pointer +vizsla +English setter +Irish setter +Gordon setter +Brittany spaniel +clumber +English springer +Welsh springer spaniel +cocker spaniel +Sussex spaniel +Irish water spaniel +kuvasz +schipperke +groenendael +malinois +briard +kelpie +komondor +Old English sheepdog +Shetland sheepdog +collie +Border collie +Bouvier des Flandres +Rottweiler +German shepherd +Doberman +miniature pinscher +Greater Swiss Mountain dog +Bernese mountain dog +Appenzeller +EntleBucher +boxer +bull mastiff +Tibetan mastiff +French bulldog +Great Dane +Saint Bernard +Eskimo dog +malamute +Siberian husky +dalmatian +affenpinscher +basenji +pug +Leonberg +Newfoundland +Great Pyrenees +Samoyed +Pomeranian +chow +keeshond +Brabancon griffon +Pembroke +Cardigan +toy poodle +miniature poodle +standard poodle +Mexican hairless +timber wolf +white wolf +red wolf +coyote +dingo +dhole +African hunting dog +hyena +red fox +kit fox +Arctic fox +grey fox +tabby +tiger cat +Persian cat +Siamese cat +Egyptian cat +cougar +lynx +leopard +snow leopard +jaguar +lion +tiger +cheetah +brown bear +American black bear +ice bear +sloth bear +mongoose +meerkat +tiger beetle +ladybug +ground beetle +long-horned beetle +leaf beetle +dung beetle +rhinoceros beetle +weevil +fly +bee +ant +grasshopper +cricket +walking stick +cockroach +mantis +cicada +leafhopper +lacewing +dragonfly +damselfly +admiral +ringlet +monarch +cabbage butterfly +sulphur butterfly +lycaenid +starfish +sea urchin +sea cucumber +wood rabbit +hare +Angora +hamster +porcupine +fox squirrel +marmot +beaver +guinea pig +sorrel +zebra +hog +wild boar +warthog +hippopotamus +ox +water buffalo +bison +ram +bighorn +ibex +hartebeest +impala +gazelle +Arabian camel +llama +weasel +mink +polecat +black-footed ferret +otter +skunk +badger +armadillo +three-toed sloth +orangutan +gorilla +chimpanzee +gibbon +siamang +guenon +patas +baboon +macaque +langur +colobus +proboscis monkey +marmoset +capuchin +howler monkey +titi +spider monkey +squirrel monkey +Madagascar cat +indri +Indian elephant +African elephant +lesser panda +giant panda +barracouta +eel +coho +rock beauty +anemone fish +sturgeon +gar +lionfish +puffer +abacus +abaya +academic gown +accordion +acoustic guitar +aircraft carrier +airliner +airship +altar +ambulance +amphibian +analog clock +apiary +apron +ashcan +assault rifle +backpack +bakery +balance beam +balloon +ballpoint +Band Aid +banjo +bannister +barbell +barber chair +barbershop +barn +barometer +barrel +barrow +baseball +basketball +bassinet +bassoon +bathing cap +bath towel +bathtub +beach wagon +beacon +beaker +bearskin +beer bottle +beer glass +bell cote +bib +bicycle-built-for-two +bikini +binder +binoculars +birdhouse +boathouse +bobsled +bolo tie +bonnet +bookcase +bookshop +bottlecap +bow +bow tie +brass +brassiere +breakwater +breastplate +broom +bucket +buckle +bulletproof vest +bullet train +butcher shop +cab +caldron +candle +cannon +canoe +can opener +cardigan +car mirror +carousel +carpenter's kit +carton +car wheel +cash machine +cassette +cassette player +castle +catamaran +CD player +cello +cellular telephone +chain +chainlink fence +chain mail +chain saw +chest +chiffonier +chime +china cabinet +Christmas stocking +church +cinema +cleaver +cliff dwelling +cloak +clog +cocktail shaker +coffee mug +coffeepot +coil +combination lock +computer keyboard +confectionery +container ship +convertible +corkscrew +cornet +cowboy boot +cowboy hat +cradle +crane +crash helmet +crate +crib +Crock Pot +croquet ball +crutch +cuirass +dam +desk +desktop computer +dial telephone +diaper +digital clock +digital watch +dining table +dishrag +dishwasher +disk brake +dock +dogsled +dome +doormat +drilling platform +drum +drumstick +dumbbell +Dutch oven +electric fan +electric guitar +electric locomotive +entertainment center +envelope +espresso maker +face powder +feather boa +file +fireboat +fire engine +fire screen +flagpole +flute +folding chair +football helmet +forklift +fountain +fountain pen +four-poster +freight car +French horn +frying pan +fur coat +garbage truck +gasmask +gas pump +goblet +go-kart +golf ball +golfcart +gondola +gong +gown +grand piano +greenhouse +grille +grocery store +guillotine +hair slide +hair spray +half track +hammer +hamper +hand blower +hand-held computer +handkerchief +hard disc +harmonica +harp +harvester +hatchet +holster +home theater +honeycomb +hook +hoopskirt +horizontal bar +horse cart +hourglass +iPod +iron +jack-o'-lantern +jean +jeep +jersey +jigsaw puzzle +jinrikisha +joystick +kimono +knee pad +knot +lab coat +ladle +lampshade +laptop +lawn mower +lens cap +letter opener +library +lifeboat +lighter +limousine +liner +lipstick +Loafer +lotion +loudspeaker +loupe +lumbermill +magnetic compass +mailbag +mailbox +maillot +maillot +manhole cover +maraca +marimba +mask +matchstick +maypole +maze +measuring cup +medicine chest +megalith +microphone +microwave +military uniform +milk can +minibus +miniskirt +minivan +missile +mitten +mixing bowl +mobile home +Model T +modem +monastery +monitor +moped +mortar +mortarboard +mosque +mosquito net +motor scooter +mountain bike +mountain tent +mouse +mousetrap +moving van +muzzle +nail +neck brace +necklace +nipple +notebook +obelisk +oboe +ocarina +odometer +oil filter +organ +oscilloscope +overskirt +oxcart +oxygen mask +packet +paddle +paddlewheel +padlock +paintbrush +pajama +palace +panpipe +paper towel +parachute +parallel bars +park bench +parking meter +passenger car +patio +pay-phone +pedestal +pencil box +pencil sharpener +perfume +Petri dish +photocopier +pick +pickelhaube +picket fence +pickup +pier +piggy bank +pill bottle +pillow +ping-pong ball +pinwheel +pirate +pitcher +plane +planetarium +plastic bag +plate rack +plow +plunger +Polaroid camera +pole +police van +poncho +pool table +pop bottle +pot +potter's wheel +power drill +prayer rug +printer +prison +projectile +projector +puck +punching bag +purse +quill +quilt +racer +racket +radiator +radio +radio telescope +rain barrel +recreational vehicle +reel +reflex camera +refrigerator +remote control +restaurant +revolver +rifle +rocking chair +rotisserie +rubber eraser +rugby ball +rule +running shoe +safe +safety pin +saltshaker +sandal +sarong +sax +scabbard +scale +school bus +schooner +scoreboard +screen +screw +screwdriver +seat belt +sewing machine +shield +shoe shop +shoji +shopping basket +shopping cart +shovel +shower cap +shower curtain +ski +ski mask +sleeping bag +slide rule +sliding door +slot +snorkel +snowmobile +snowplow +soap dispenser +soccer ball +sock +solar dish +sombrero +soup bowl +space bar +space heater +space shuttle +spatula +speedboat +spider web +spindle +sports car +spotlight +stage +steam locomotive +steel arch bridge +steel drum +stethoscope +stole +stone wall +stopwatch +stove +strainer +streetcar +stretcher +studio couch +stupa +submarine +suit +sundial +sunglass +sunglasses +sunscreen +suspension bridge +swab +sweatshirt +swimming trunks +swing +switch +syringe +table lamp +tank +tape player +teapot +teddy +television +tennis ball +thatch +theater curtain +thimble +thresher +throne +tile roof +toaster +tobacco shop +toilet seat +torch +totem pole +tow truck +toyshop +tractor +trailer truck +tray +trench coat +tricycle +trimaran +tripod +triumphal arch +trolleybus +trombone +tub +turnstile +typewriter keyboard +umbrella +unicycle +upright +vacuum +vase +vault +velvet +vending machine +vestment +viaduct +violin +volleyball +waffle iron +wall clock +wallet +wardrobe +warplane +washbasin +washer +water bottle +water jug +water tower +whiskey jug +whistle +wig +window screen +window shade +Windsor tie +wine bottle +wing +wok +wooden spoon +wool +worm fence +wreck +yawl +yurt +web site +comic book +crossword puzzle +street sign +traffic light +book jacket +menu +plate +guacamole +consomme +hot pot +trifle +ice cream +ice lolly +French loaf +bagel +pretzel +cheeseburger +hotdog +mashed potato +head cabbage +broccoli +cauliflower +zucchini +spaghetti squash +acorn squash +butternut squash +cucumber +artichoke +bell pepper +cardoon +mushroom +Granny Smith +strawberry +orange +lemon +fig +pineapple +banana +jackfruit +custard apple +pomegranate +hay +carbonara +chocolate sauce +dough +meat loaf +pizza +potpie +burrito +red wine +espresso +cup +eggnog +alp +bubble +cliff +coral reef +geyser +lakeside +promontory +sandbar +seashore +valley +volcano +ballplayer +groom +scuba diver +rapeseed +daisy +yellow lady's slipper +corn +acorn +hip +buckeye +coral fungus +agaric +gyromitra +stinkhorn +earthstar +hen-of-the-woods +bolete +ear +toilet tissue diff --git a/benchmarks/DeepLearning/Models/Inception-V3/Main.cpp b/benchmarks/DeepLearning/Models/Inception-V3/Main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..729d0599b023cb2fcd28d3208cbd9db65b59f489 --- /dev/null +++ b/benchmarks/DeepLearning/Models/Inception-V3/Main.cpp @@ -0,0 +1,33 @@ +//===- Main.cpp -----------------------------------------------------------===// +// +// 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 is the main file of the deep learning benchmark. +// +//===----------------------------------------------------------------------===// + +#include <benchmark/benchmark.h> + +void printResult(); + +int main(int argc, char **argv) { + // Run benchmarks. + ::benchmark::Initialize(&argc, argv); + ::benchmark::RunSpecifiedBenchmarks(); + // Print classification result. + printResult(); + + return 0; +}