|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130 |
- /**
- * \file dnn/test/x86/conv_bias.cpp
- * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
- *
- * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or
- * implied.
- */
- #include "src/x86/utils.h"
- #include "test/x86/fixture.h"
-
- #include "megdnn/opr_param_defs.h"
- #include "megdnn/oprs.h"
- #include "test/common/benchmarker.h"
- #include "test/common/checker.h"
- #include "test/common/conv_bias.h"
- #include "test/common/rng.h"
- #include "test/common/task_record_check.h"
- #include "test/common/tensor.h"
- #include "test/common/workspace_wrapper.h"
- namespace megdnn {
- namespace test {
-
- TEST_F(X86, CONV_BIAS_FORWARD) {
- using namespace conv_bias;
- std::vector<TestArg> args = get_args();
- Checker<ConvBiasForward> checker(handle());
- NormalRNG default_rng;
- ConstValue const_val;
- for (auto&& arg : args) {
- checker.set_dtype(0, dtype::Float32())
- .set_dtype(1, dtype::Float32())
- .set_dtype(2, dtype::Float32())
- .set_rng(0, &default_rng)
- .set_rng(1, &default_rng)
- .set_rng(2, &default_rng)
- .set_epsilon(1e-3)
- .set_param(arg.param)
- .execs({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
-
- TEST_F(X86, CONV_BIAS_FORWARD_RECORD) {
- using namespace conv_bias;
- std::vector<TestArg> args = get_args();
- TaskRecordChecker<ConvBiasForward> checker(0);
- NormalRNG default_rng;
- ConstValue const_val;
- for (auto&& arg : args) {
- checker.set_dtype(0, dtype::Float32())
- .set_dtype(1, dtype::Float32())
- .set_dtype(2, dtype::Float32())
- .set_rng(0, &default_rng)
- .set_rng(1, &default_rng)
- .set_rng(2, &default_rng)
- .set_epsilon(1e-3)
- .set_param(arg.param)
- .execs({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
-
- static void avx2_chanwise_direct_int8x8x32(
- Handle* handle, uint32_t stride, const char* algo) {
- using namespace conv_bias;
- std::vector<TestArg> args;
-
- auto run = [&](size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = stride;
- param.stride_w = stride;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- param.sparse = param::ConvBias::Sparse::GROUP;
- //! no bias
- args.emplace_back(
- param, TensorShape{2, ic, h, w}, TensorShape{ic, 1, 1, kernel, kernel},
- TensorShape{});
- //! bias channel
- args.emplace_back(
- param, TensorShape{2, ic, h, w}, TensorShape{ic, 1, 1, kernel, kernel},
- TensorShape{1, ic, 1, 1});
- };
-
- for (size_t kernel : {2, 3, 5, 7})
- for (size_t pad : {0, 1})
- for (size_t ic : {1, 5, 17, 20})
- for (size_t h : {7, 16, 38, 40})
- for (size_t w : {16, 25, 40, 55})
- for (NonlineMode nonline_mode : {NonlineMode::IDENTITY})
- run(ic, w, h, kernel, pad, nonline_mode);
-
- Checker<ConvBias> checker(handle);
- UniformIntRNG rng{-50, 50};
- checker.set_dtype(0, dtype::Int8())
- .set_dtype(1, dtype::Int8())
- .set_dtype(2, dtype::Int32())
- .set_dtype(4, dtype::Int32())
- .set_rng(0, &rng)
- .set_rng(1, &rng)
- .set_rng(2, &rng)
- .set_epsilon(1e-3);
- checker.set_before_exec_callback(
- conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(algo));
- for (auto&& arg : args) {
- checker.set_param(arg.param).exec({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
-
- TEST_F(X86_MULTI_THREADS, AVX2_CHANWISE_DIRECT_STRIDE1_INT8x8x32) {
- avx2_chanwise_direct_int8x8x32(
- handle(), 1, "X86_CONV_BIAS_CHANWISE_AVX2_INT8_STRIDE1");
- }
-
- TEST_F(X86, AVX2_CHANWISE_DIRECT_STRIDE1_INT8x8x32_RECORD) {
- using namespace conv_bias;
- std::vector<TestArg> args;
- size_t stride = 1;
- auto run = [&](size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = stride;
- param.stride_w = stride;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- param.sparse = param::ConvBias::Sparse::GROUP;
- //! no bias
- args.emplace_back(
- param, TensorShape{2, ic, h, w}, TensorShape{ic, 1, 1, kernel, kernel},
- TensorShape{});
- //! bias channel
- args.emplace_back(
- param, TensorShape{2, ic, h, w}, TensorShape{ic, 1, 1, kernel, kernel},
- TensorShape{1, ic, 1, 1});
- };
-
- run(5, 16, 7, 2, 1, NonlineMode::IDENTITY);
-
- TaskRecordChecker<ConvBias> checker(0);
- UniformIntRNG rng{-50, 50};
- checker.set_dtype(0, dtype::Int8())
- .set_dtype(1, dtype::Int8())
- .set_dtype(2, dtype::Int32())
- .set_dtype(4, dtype::Int32())
- .set_rng(0, &rng)
- .set_rng(1, &rng)
- .set_rng(2, &rng)
- .set_epsilon(1e-3);
- for (auto&& arg : args) {
- checker.set_param(arg.param).exec({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
-
- TEST_F(X86_MULTI_THREADS, AVX2_CHANWISE_DIRECT_STRIDE2_INT8x8x32) {
- avx2_chanwise_direct_int8x8x32(
- handle(), 2, "X86_CONV_BIAS_CHANWISE_AVX2_INT8_STRIDE2");
- }
-
- static void avx2_chanwise_direct_quantizeds32(
- Handle* handle, uint32_t stride, const char* algo) {
- using namespace conv_bias;
- std::vector<TestArg> args;
-
- auto run = [&](size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = stride;
- param.stride_w = stride;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- param.sparse = param::ConvBias::Sparse::GROUP;
- //! no bias
- args.emplace_back(
- param, TensorShape{2, ic, h, w}, TensorShape{ic, 1, 1, kernel, kernel},
- TensorShape{});
- //! bias channel
- args.emplace_back(
- param, TensorShape{2, ic, h, w}, TensorShape{ic, 1, 1, kernel, kernel},
- TensorShape{1, ic, 1, 1});
- };
-
- for (size_t kernel : {2, 3, 5, 7})
- for (size_t pad : {0, 1})
- for (size_t ic : {1, 3, 5, 7, 17})
- for (size_t h : {10, 17, 25, 30})
- for (size_t w : {19, 28, 58, 168})
- for (NonlineMode nonline_mode : {NonlineMode::IDENTITY})
- run(ic, w, h, kernel, pad, nonline_mode);
-
- Checker<ConvBias> checker(handle);
- UniformIntRNG rng{-50, 50};
- checker.set_dtype(0, dtype::QuantizedS8(2.5f))
- .set_dtype(1, dtype::QuantizedS8(2.5f))
- .set_dtype(2, dtype::QuantizedS32(6.25f))
- .set_dtype(4, {})
- .set_rng(0, &rng)
- .set_rng(1, &rng)
- .set_rng(2, &rng)
- .set_epsilon(1e-3);
- checker.set_before_exec_callback(
- conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(algo));
- for (auto&& arg : args) {
- checker.set_param(arg.param).exec({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
-
- TEST_F(X86_MULTI_THREADS, AVX2_CHANWISE_DIRECT_STRIDE1_QuantizedS32) {
- avx2_chanwise_direct_quantizeds32(
- handle(), 1, "X86_CONV_BIAS_CHANWISE_AVX2_INT8_STRIDE1");
- }
-
- TEST_F(X86_MULTI_THREADS, AVX2_CHANWISE_DIRECT_STRIDE2_QuantizedS32) {
- avx2_chanwise_direct_quantizeds32(
- handle(), 2, "X86_CONV_BIAS_CHANWISE_AVX2_INT8_STRIDE2");
- }
-
- static void avx2_chanwise_direct_quantizeds8x8x8(
- Handle* handle, uint32_t stride, const char* algo) {
- using namespace conv_bias;
- std::vector<TestArg> args;
-
- auto run = [&](size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = stride;
- param.stride_w = stride;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- param.sparse = param::ConvBias::Sparse::GROUP;
- //! no bias
- args.emplace_back(
- param, TensorShape{2, ic, h, w}, TensorShape{ic, 1, 1, kernel, kernel},
- TensorShape{});
- //! bias channel
- args.emplace_back(
- param, TensorShape{2, ic, h, w}, TensorShape{ic, 1, 1, kernel, kernel},
- TensorShape{1, ic, 1, 1});
- };
-
- for (size_t kernel : {2, 3, 5, 7})
- for (size_t pad : {0, 1})
- for (size_t ic : {1, 3, 5, 7, 17})
- for (size_t h : {10, 15, 17, 30})
- for (size_t w : {19, 28, 58, 168})
- for (NonlineMode nonline_mode :
- {NonlineMode::IDENTITY, NonlineMode::H_SWISH,
- NonlineMode::RELU})
- run(ic, w, h, kernel, pad, nonline_mode);
-
- Checker<ConvBias> checker(handle);
- UniformIntRNG rng{-50, 50};
- checker.set_dtype(0, dtype::QuantizedS8(2.5f))
- .set_dtype(1, dtype::QuantizedS8(2.5f))
- .set_dtype(2, dtype::QuantizedS32(6.25f))
- .set_dtype(4, dtype::QuantizedS8(60.25f))
- .set_rng(0, &rng)
- .set_rng(1, &rng)
- .set_rng(2, &rng)
- .set_epsilon(1e-3);
- checker.set_before_exec_callback(
- conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(algo));
- for (auto&& arg : args) {
- checker.set_param(arg.param).exec({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
-
- TEST_F(X86_MULTI_THREADS, AVX2_CHANWISE_DIRECT_STRIDE1_QuantizedS8x8x8) {
- avx2_chanwise_direct_quantizeds8x8x8(
- handle(), 1, "X86_CONV_BIAS_CHANWISE_AVX2_INT8_STRIDE1");
- }
-
- TEST_F(X86_MULTI_THREADS, AVX2_CHANWISE_DIRECT_STRIDE2_QuantizedS8x8x8) {
- avx2_chanwise_direct_quantizeds8x8x8(
- handle(), 2, "X86_CONV_BIAS_CHANWISE_AVX2_INT8_STRIDE2");
- }
-
- TEST_F(X86_MULTI_THREADS, AVX2_CONV_BIAS_DIRECT_STRIDE1_INT8x8x32) {
- using namespace conv_bias;
- std::vector<TestArg> args;
-
- auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = 1;
- param.stride_w = 1;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- param.sparse = param::ConvBias::Sparse::DENSE;
- //! no bias
- args.emplace_back(
- param, TensorShape{2, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{});
-
- param.sparse = param::ConvBias::Sparse::GROUP;
- //! no bias
- args.emplace_back(
- param, TensorShape{2, 2 * ic, h, w},
- TensorShape{2, oc / 2, ic, kernel, kernel}, TensorShape{});
- };
-
- for (size_t kernel : {2, 3, 5, 7})
- for (size_t pad : {0, 1})
- for (size_t oc : {4, 8, 13, 16, 24})
- for (size_t ic : {2, 3, 7, 10})
- for (size_t h : {10, 11})
- for (size_t w : {8, 10})
- for (NonlineMode nonline_mode : {NonlineMode::IDENTITY})
- run(oc, ic, w, h, kernel, pad, nonline_mode);
-
- Checker<ConvBias> checker(handle());
- UniformIntRNG rng{-50, 50};
- checker.set_dtype(0, dtype::Int8())
- .set_dtype(1, dtype::Int8())
- .set_dtype(2, dtype::Int32())
- .set_dtype(4, dtype::Int32())
- .set_rng(0, &rng)
- .set_rng(1, &rng)
- .set_rng(2, &rng)
- .set_epsilon(1e-3);
- checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
- "X86_CONV_BIAS_DIRECT_AVX2_INT8_STRIDE1"));
- for (auto&& arg : args) {
- checker.set_param(arg.param).exec({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
- TEST_F(X86_MULTI_THREADS, AVX2_CONV_BIAS_DIRECT_STRIDE1_QuantizedS32) {
- using namespace conv_bias;
- std::vector<TestArg> args;
-
- auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = 1;
- param.stride_w = 1;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- param.sparse = param::ConvBias::Sparse::DENSE;
- //! no bias
- args.emplace_back(
- param, TensorShape{2, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{});
-
- param.sparse = param::ConvBias::Sparse::GROUP;
- //! no bias
- args.emplace_back(
- param, TensorShape{2, 2 * ic, h, w},
- TensorShape{2, oc / 2, ic, kernel, kernel}, TensorShape{});
- };
-
- for (size_t kernel : {2, 3, 5, 7})
- for (size_t pad : {0, 1})
- for (size_t oc : {4, 8, 13, 16, 24})
- for (size_t ic : {2, 3, 7, 10})
- for (size_t h : {10, 11})
- for (size_t w : {8, 10})
- for (NonlineMode nonline_mode : {NonlineMode::IDENTITY})
- run(oc, ic, w, h, kernel, pad, nonline_mode);
-
- Checker<ConvBias> checker(handle());
- UniformIntRNG rng{-50, 50};
- checker.set_dtype(0, dtype::QuantizedS8(2.5f))
- .set_dtype(1, dtype::QuantizedS8(2.5f))
- .set_dtype(2, dtype::QuantizedS32(6.25f))
- .set_dtype(4, {})
- .set_rng(0, &rng)
- .set_rng(1, &rng)
- .set_rng(2, &rng)
- .set_epsilon(1e-3);
- checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
- "X86_CONV_BIAS_DIRECT_AVX2_INT8_STRIDE1"));
- for (auto&& arg : args) {
- checker.set_param(arg.param).exec({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
-
- TEST_F(X86_MULTI_THREADS, AVX2_CONV_BIAS_DIRECT_STRIDE1_S8S8S8) {
- using namespace conv_bias;
- std::vector<TestArg> args;
-
- auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = 1;
- param.stride_w = 1;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- param.sparse = param::ConvBias::Sparse::DENSE;
- //! no bias
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{});
- //! bias channel
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{1, oc, 1, 1});
-
- param.sparse = param::ConvBias::Sparse::GROUP;
- //! no bias
- args.emplace_back(
- param, TensorShape{2, 2 * ic, h, w},
- TensorShape{2, oc / 2, ic, kernel, kernel}, TensorShape{});
- //! bias channel
- args.emplace_back(
- param, TensorShape{2, 2 * ic, h, w},
- TensorShape{2, oc / 2, ic, kernel, kernel}, TensorShape{1, oc, 1, 1});
- };
-
- for (size_t kernel : {2, 3, 5, 7})
- for (size_t pad : {0, 1})
- for (size_t oc : {4, 8, 14, 16, 24})
- for (size_t ic : {2, 3, 7, 10})
- for (size_t h : {10, 11})
- for (size_t w : {8, 10})
- for (NonlineMode nonline_mode :
- {NonlineMode::IDENTITY, NonlineMode::RELU,
- NonlineMode::H_SWISH})
- run(oc, ic, w, h, kernel, pad, nonline_mode);
-
- Checker<ConvBias> checker(handle());
- UniformIntRNG rng{-50, 50};
- checker.set_dtype(0, dtype::QuantizedS8(2.5f))
- .set_dtype(1, dtype::QuantizedS8(2.5f))
- .set_dtype(2, dtype::QuantizedS32(6.25f))
- .set_dtype(4, dtype::QuantizedS8(60.25f))
- .set_rng(0, &rng)
- .set_rng(1, &rng)
- .set_rng(2, &rng)
- .set_epsilon(1e-3);
- checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
- "X86_CONV_BIAS_DIRECT_AVX2_INT8_STRIDE1"));
- for (auto&& arg : args) {
- checker.set_param(arg.param).exec({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
-
- TEST_F(X86_MULTI_THREADS, AVX2_CONV_BIAS_DIRECT_STRIDE2_INT8x8x32) {
- using namespace conv_bias;
- std::vector<TestArg> args;
-
- auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = 2;
- param.stride_w = 2;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- param.sparse = param::ConvBias::Sparse::DENSE;
- //! no bias
- args.emplace_back(
- param, TensorShape{2, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{});
-
- param.sparse = param::ConvBias::Sparse::GROUP;
- //! no bias
- args.emplace_back(
- param, TensorShape{2, 2 * ic, h, w},
- TensorShape{2, oc / 2, ic, kernel, kernel}, TensorShape{});
- };
-
- for (size_t kernel : {2, 3, 5, 7})
- for (size_t pad : {0, 1, 2, 5})
- for (size_t oc : {4, 8, 13, 16, 24})
- for (size_t ic : {2, 3, 7, 10})
- for (size_t h : {10, 11})
- for (size_t w : {8, 10, 20})
- for (NonlineMode nonline_mode : {NonlineMode::IDENTITY})
- run(oc, ic, w, h, kernel, pad, nonline_mode);
-
- Checker<ConvBias> checker(handle());
- UniformIntRNG rng{-50, 50};
- checker.set_dtype(0, dtype::Int8())
- .set_dtype(1, dtype::Int8())
- .set_dtype(2, dtype::Int32())
- .set_dtype(4, dtype::Int32())
- .set_rng(0, &rng)
- .set_rng(1, &rng)
- .set_rng(2, &rng)
- .set_epsilon(1e-3);
- checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
- "X86_CONV_BIAS_DIRECT_AVX2_INT8_STRIDE2"));
- for (auto&& arg : args) {
- checker.set_param(arg.param).exec({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
- TEST_F(X86_MULTI_THREADS, AVX2_CONV_BIAS_DIRECT_STRIDE2_QuantizedS32) {
- using namespace conv_bias;
- std::vector<TestArg> args;
-
- auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = 2;
- param.stride_w = 2;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- param.sparse = param::ConvBias::Sparse::DENSE;
- //! no bias
- args.emplace_back(
- param, TensorShape{2, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{});
-
- param.sparse = param::ConvBias::Sparse::GROUP;
- //! no bias
- args.emplace_back(
- param, TensorShape{2, 2 * ic, h, w},
- TensorShape{2, oc / 2, ic, kernel, kernel}, TensorShape{});
- };
-
- for (size_t kernel : {2, 3, 5, 7})
- for (size_t pad : {0, 1, 3, 5})
- for (size_t oc : {4, 8, 13, 16, 24})
- for (size_t ic : {2, 3, 7, 10})
- for (size_t h : {10, 11})
- for (size_t w : {8, 10, 19})
- for (NonlineMode nonline_mode : {NonlineMode::IDENTITY})
- run(oc, ic, w, h, kernel, pad, nonline_mode);
-
- Checker<ConvBias> checker(handle());
- UniformIntRNG rng{-50, 50};
- checker.set_dtype(0, dtype::QuantizedS8(2.5f))
- .set_dtype(1, dtype::QuantizedS8(2.5f))
- .set_dtype(2, dtype::QuantizedS32(6.25f))
- .set_dtype(4, {})
- .set_rng(0, &rng)
- .set_rng(1, &rng)
- .set_rng(2, &rng)
- .set_epsilon(1e-3);
- checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
- "X86_CONV_BIAS_DIRECT_AVX2_INT8_STRIDE2"));
- for (auto&& arg : args) {
- checker.set_param(arg.param).exec({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
-
- TEST_F(X86_MULTI_THREADS, AVX2_CONV_BIAS_DIRECT_STRIDE2_S8S8S8) {
- using namespace conv_bias;
- std::vector<TestArg> args;
-
- auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = 2;
- param.stride_w = 2;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- param.sparse = param::ConvBias::Sparse::DENSE;
- //! no bias
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{});
- //! bias channel
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{1, oc, 1, 1});
-
- param.sparse = param::ConvBias::Sparse::GROUP;
- //! no bias
- args.emplace_back(
- param, TensorShape{2, 2 * ic, h, w},
- TensorShape{2, oc / 2, ic, kernel, kernel}, TensorShape{});
- //! bias channel
- args.emplace_back(
- param, TensorShape{2, 2 * ic, h, w},
- TensorShape{2, oc / 2, ic, kernel, kernel}, TensorShape{1, oc, 1, 1});
- };
-
- for (size_t kernel : {2, 3, 5, 7})
- for (size_t pad : {0, 1, 3, 5})
- for (size_t oc : {4, 8, 14, 16, 24})
- for (size_t ic : {2, 3, 7, 10})
- for (size_t h : {10, 11})
- for (size_t w : {8, 10, 18})
- for (NonlineMode nonline_mode :
- {NonlineMode::IDENTITY, NonlineMode::RELU,
- NonlineMode::H_SWISH})
- run(oc, ic, w, h, kernel, pad, nonline_mode);
-
- Checker<ConvBias> checker(handle());
- UniformIntRNG rng{-50, 50};
- checker.set_dtype(0, dtype::QuantizedS8(2.5f))
- .set_dtype(1, dtype::QuantizedS8(2.5f))
- .set_dtype(2, dtype::QuantizedS32(6.25f))
- .set_dtype(4, dtype::QuantizedS8(60.25f))
- .set_rng(0, &rng)
- .set_rng(1, &rng)
- .set_rng(2, &rng)
- .set_epsilon(1e-3);
- checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
- "X86_CONV_BIAS_DIRECT_AVX2_INT8_STRIDE2"));
- for (auto&& arg : args) {
- checker.set_param(arg.param).exec({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
-
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_DIRECT_STRIDE1_DENSE) {
- using namespace conv_bias;
- std::vector<TestArg> args;
-
- auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = 1;
- param.stride_w = 1;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- //! no bias
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{});
- //! bias channel
- args.emplace_back(
- param, TensorShape{2, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{1, oc, 1, 1});
- //! bias
- args.emplace_back(
- param, TensorShape{2, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{
- 2, oc, (h + param.pad_h * 2 - kernel) + 1,
- (w + param.pad_w * 2 - kernel) + 1});
- };
-
- for (size_t kernel : {1, 2, 3, 4, 5, 6, 7})
- for (size_t ic : {1, 4, 8, 16})
- for (size_t oc : {1, 4, 8})
- for (size_t p : {0, 2})
- for (size_t size : {20, 21, 24})
- for (NonlineMode nonline_mode :
- {NonlineMode::RELU, NonlineMode::SIGMOID,
- NonlineMode::H_SWISH, NonlineMode::IDENTITY}) {
- run(oc, ic, size, size, kernel, p, nonline_mode);
- }
-
- Checker<ConvBias> checker(handle());
- UniformIntRNG rng{-50, 50};
- checker.set_dtype(0, dtype::Float32())
- .set_dtype(1, dtype::Float32())
- .set_dtype(2, dtype::Float32())
- .set_rng(0, &rng)
- .set_rng(1, &rng)
- .set_rng(2, &rng);
- checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
- "X86_CONV_BIAS_DIRECT_STRIDE1_LARGE_GROUP"));
- for (auto&& arg : args) {
- checker.set_param(arg.param).exec({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
-
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_DIRECT_STRIDE1_GROUP) {
- using namespace conv_bias;
- std::vector<TestArg> args;
-
- auto run = [&](size_t group, size_t channel, size_t w, size_t h, size_t kernel,
- size_t p, NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = 1;
- param.stride_w = 1;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
- param.sparse = param::ConvBias::Sparse::GROUP;
-
- //! no bias
- args.emplace_back(
- param, TensorShape{1, channel, h, w},
- TensorShape{group, channel / group, channel / group, kernel, kernel},
- TensorShape{});
- //! bias channel
- args.emplace_back(
- param, TensorShape{2, channel, h, w},
- TensorShape{group, channel / group, channel / group, kernel, kernel},
- TensorShape{1, channel, 1, 1});
- //! bias
- args.emplace_back(
- param, TensorShape{2, channel, h, w},
- TensorShape{group, channel / group, channel / group, kernel, kernel},
- TensorShape{
- 2, channel, (h + param.pad_h * 2 - kernel) + 1,
- (w + param.pad_w * 2 - kernel) + 1});
- };
-
- for (size_t kernel : {1, 2, 3, 4, 5, 6, 7})
- for (size_t channel : {4, 8, 16})
- for (size_t group : {1, 2, 4})
- for (size_t p : {0, 2})
- for (size_t size : {20, 21, 24})
- for (NonlineMode nonline_mode :
- {NonlineMode::RELU, NonlineMode::SIGMOID,
- NonlineMode::H_SWISH, NonlineMode::IDENTITY}) {
- run(group, channel, size, size, kernel, p, nonline_mode);
- }
-
- Checker<ConvBias> checker(handle());
- UniformIntRNG rng{-50, 50};
- checker.set_dtype(0, dtype::Float32())
- .set_dtype(1, dtype::Float32())
- .set_dtype(2, dtype::Float32())
- .set_rng(0, &rng)
- .set_rng(1, &rng)
- .set_rng(2, &rng);
- checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
- "X86_CONV_BIAS_DIRECT_STRIDE1_LARGE_GROUP"));
- for (auto&& arg : args) {
- checker.set_param(arg.param).exec({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
-
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_DIRECT_STRIDE2_DENSE) {
- using namespace conv_bias;
- std::vector<TestArg> args;
-
- auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = 2;
- param.stride_w = 2;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- //! no bias
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{});
- };
-
- for (size_t kernel : {2, 3, 5, 7})
- for (size_t ic : {1, 4, 8, 16})
- for (size_t oc : {1, 4, 8})
- for (size_t p : {0, 2})
- for (size_t size : {20, 21, 24})
- for (NonlineMode nonline_mode :
- {NonlineMode::RELU, NonlineMode::SIGMOID,
- NonlineMode::H_SWISH, NonlineMode::IDENTITY}) {
- run(oc, ic, size, size, kernel, p, nonline_mode);
- }
-
- Checker<ConvBias> checker(handle());
- UniformIntRNG rng{-50, 50};
- checker.set_dtype(0, dtype::Float32())
- .set_dtype(1, dtype::Float32())
- .set_dtype(2, dtype::Float32())
- .set_rng(0, &rng)
- .set_rng(1, &rng)
- .set_rng(2, &rng);
- checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
- "X86_CONV_BIAS_DIRECT_STRIDE2_LARGE_GROUP"));
- for (auto&& arg : args) {
- checker.set_param(arg.param).exec({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
-
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_DIRECT_STRIDE2_GROUP) {
- using namespace conv_bias;
- std::vector<TestArg> args;
-
- auto run = [&](size_t group, size_t channel, size_t w, size_t h, size_t kernel,
- size_t p, NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = 2;
- param.stride_w = 2;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
- param.sparse = param::ConvBias::Sparse::GROUP;
-
- //! no bias
- args.emplace_back(
- param, TensorShape{1, channel, h, w},
- TensorShape{group, channel / group, channel / group, kernel, kernel},
- TensorShape{});
- //! bias channel
- args.emplace_back(
- param, TensorShape{2, channel, h, w},
- TensorShape{group, channel / group, channel / group, kernel, kernel},
- TensorShape{1, channel, 1, 1});
- //! bias
- args.emplace_back(
- param, TensorShape{2, channel, h, w},
- TensorShape{group, channel / group, channel / group, kernel, kernel},
- TensorShape{
- 2, channel, (h + param.pad_h * 2 - kernel) / 2 + 1,
- (w + param.pad_w * 2 - kernel) / 2 + 1});
- };
-
- for (size_t kernel : {2, 3, 5, 7})
- for (size_t channel : {4, 8, 16})
- for (size_t group : {1, 2, 4})
- for (size_t p : {0, 2})
- for (size_t size : {20, 21, 24})
- for (NonlineMode nonline_mode :
- {NonlineMode::RELU, NonlineMode::SIGMOID,
- NonlineMode::H_SWISH, NonlineMode::IDENTITY}) {
- run(group, channel, size, size, kernel, p, nonline_mode);
- }
-
- Checker<ConvBias> checker(handle());
- UniformIntRNG rng{-50, 50};
- checker.set_dtype(0, dtype::Float32())
- .set_dtype(1, dtype::Float32())
- .set_dtype(2, dtype::Float32())
- .set_rng(0, &rng)
- .set_rng(1, &rng)
- .set_rng(2, &rng);
- checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBiasForward>(
- "X86_CONV_BIAS_DIRECT_STRIDE2_LARGE_GROUP"));
- for (auto&& arg : args) {
- checker.set_param(arg.param).exec({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
-
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8X8X32) {
- using namespace conv_bias;
- std::vector<TestArg> args;
-
- auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = 1;
- param.stride_w = 1;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- //! no bias
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{});
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{1, oc, 1, 1});
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{1, oc, (h + 2 * p - kernel) + 1, (h + 2 * p - kernel) + 1});
- };
-
- for (size_t kernel : {2, 3, 4, 5, 6, 7})
- for (size_t ic : {1, 4, 8, 16})
- for (size_t oc : {1, 4, 8})
- for (size_t p : {0, 2})
- for (size_t size : {20, 21, 24})
- for (NonlineMode nonline_mode : {NonlineMode::IDENTITY}) {
- run(oc, ic, size, size, kernel, p, nonline_mode);
- }
- //! test OC block
- run(2046, 1, 8, 8, 2, 0, NonlineMode::IDENTITY);
-
- Checker<ConvBias> checker(handle());
- UniformIntRNG rng{-50, 50};
- #define cb(algo_name) \
- checker.set_before_exec_callback( \
- conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name)); \
- checker.set_dtype(0, dtype::Int8()); \
- checker.set_dtype(1, dtype::Int8()); \
- checker.set_dtype(2, dtype::Int32()); \
- checker.set_dtype(4, dtype::Int32()); \
- for (auto&& arg : args) { \
- checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}}); \
- } \
- for (auto&& arg : args) { \
- checker.set_dtype(0, dtype::QuantizedS8(2.5f)) \
- .set_dtype(1, dtype::QuantizedS8(2.5f)) \
- .set_dtype(2, dtype::QuantizedS32(6.25f)) \
- .set_dtype(4, {}) \
- .set_rng(0, &rng) \
- .set_rng(1, &rng) \
- .set_rng(2, &rng) \
- .set_param(arg.param) \
- .execs({arg.src, arg.filter, {}, {}, {}}); \
- }
- #define cb2(algo_name) \
- checker.set_before_exec_callback( \
- conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name)); \
- checker.set_dtype(0, dtype::Int8()); \
- checker.set_dtype(1, dtype::Int8()); \
- checker.set_dtype(2, dtype::Int16()); \
- checker.set_dtype(4, dtype::Int16()); \
- for (auto&& arg : args) { \
- checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}}); \
- }
-
- #if MEGDNN_X86_WITH_MKL_DNN
- if (megdnn::x86::is_supported(x86::SIMDType::VNNI)) {
- cb("IM2COLMATMUL");
- }
- #endif
- #if MEGDNN_X86_WITH_VNNI
- if (megdnn::x86::is_supported(x86::SIMDType::VNNI)) {
- cb("IM2COLMATMUL:X86_INT8X8X32_VNNI");
- }
- #endif
- if (megdnn::x86::is_supported(x86::SIMDType::AVX2)) {
- cb("IM2COLMATMUL:X86_INT8X8X32_AVX2_2X4X16");
- cb("IM2COLMATMUL:X86_INT8X8X32_AVX2_4X16X2");
- cb2("IM2COLMATMUL:X86_INT8X8X16_AVX2");
- }
- if (::megdnn::x86::is_supported(::megdnn::x86::SIMDType::SSE4_2)) {
- cb("IM2COLMATMUL:X86_INT8X8X32_SSE_4X8X2");
- cb2("IM2COLMATMUL:X86_INT8X8X16_SSE");
- }
-
- #undef cb
- #undef cb2
- }
-
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_INT8X8X32_FILTER_PREPROCESS) {
- using namespace conv_bias;
- std::vector<TestArg> args;
-
- auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = 1;
- param.stride_w = 1;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- //! no bias
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{});
- };
-
- for (size_t kernel : {2, 3, 4, 5, 6, 7})
- for (size_t ic : {1, 4, 8, 16})
- for (size_t oc : {1, 4, 8})
- for (size_t p : {0, 2})
- for (size_t size : {20, 21, 24})
- for (NonlineMode nonline_mode : {NonlineMode::IDENTITY}) {
- run(oc, ic, size, size, kernel, p, nonline_mode);
- }
- //! test OC block
- run(2046, 1, 8, 8, 2, 0, NonlineMode::IDENTITY);
-
- Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
- handle());
- UniformIntRNG rng{-50, 50};
- #define cb(algo_name) \
- checker.set_before_exec_callback( \
- conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name)); \
- checker.set_dtype(0, dtype::Int8()); \
- checker.set_dtype(1, dtype::Int8()); \
- checker.set_dtype(2, dtype::Int32()); \
- checker.set_dtype(4, dtype::Int32()); \
- for (auto&& arg : args) { \
- checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}}); \
- } \
- for (auto&& arg : args) { \
- checker.set_dtype(0, dtype::QuantizedS8(2.5f)) \
- .set_dtype(1, dtype::QuantizedS8(2.5f)) \
- .set_dtype(2, dtype::QuantizedS32(6.25f)) \
- .set_dtype(4, {}) \
- .set_rng(0, &rng) \
- .set_rng(1, &rng) \
- .set_rng(2, &rng) \
- .set_param(arg.param) \
- .execs({arg.src, arg.filter, {}, {}, {}}); \
- }
- #define cb2(algo_name) \
- checker.set_before_exec_callback( \
- conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name)); \
- checker.set_dtype(0, dtype::Int8()); \
- checker.set_dtype(1, dtype::Int8()); \
- checker.set_dtype(2, dtype::Int16()); \
- checker.set_dtype(4, dtype::Int16()); \
- for (auto&& arg : args) { \
- checker.set_param(arg.param).execs({arg.src, arg.filter, {}, {}, {}}); \
- }
-
- #if MEGDNN_X86_WITH_MKL_DNN
- if (megdnn::x86::is_supported(x86::SIMDType::VNNI)) {
- cb("IM2COLMATMUL");
- }
- #endif
- #if MEGDNN_X86_WITH_VNNI
- if (megdnn::x86::is_supported(x86::SIMDType::VNNI)) {
- cb("IM2COLMATMUL:X86_INT8X8X32_VNNI");
- }
- #endif
- if (megdnn::x86::is_supported(x86::SIMDType::AVX2)) {
- cb("IM2COLMATMUL:X86_INT8X8X32_AVX2_2X4X16");
- cb("IM2COLMATMUL:X86_INT8X8X32_AVX2_4X16X2");
- cb2("IM2COLMATMUL:X86_INT8X8X16_AVX2");
- }
- if (::megdnn::x86::is_supported(::megdnn::x86::SIMDType::SSE4_2)) {
- cb("IM2COLMATMUL:X86_INT8X8X32_SSE_4X8X2");
- cb2("IM2COLMATMUL:X86_INT8X8X16_SSE");
- }
-
- #undef cb
- #undef cb2
- }
-
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_FP32) {
- using namespace conv_bias;
- std::vector<TestArg> args;
-
- auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = 1;
- param.stride_w = 1;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- //! no bias
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{});
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{1, oc, 1, 1});
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{
- 1, oc, (h + 2 * p - kernel) / param.stride_h + 1,
- (w + 2 * p - kernel) / param.stride_w + 1});
- };
-
- for (size_t kernel : {2, 3, 4, 5, 6, 7})
- for (size_t ic : {1, 4, 8, 16})
- for (size_t oc : {1, 4, 8, 16, 300})
- for (size_t p : {0, 2})
- for (size_t size : {8, 24})
- for (NonlineMode nonline_mode :
- {NonlineMode::IDENTITY, NonlineMode::RELU}) {
- run(oc, ic, size, size, kernel, p, nonline_mode);
- }
-
- run(2046, 8, 20, 20, 3, 1, NonlineMode::IDENTITY);
- Checker<ConvBias> checker(handle());
- #define cb(algo_name) \
- checker.set_before_exec_callback( \
- conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name)); \
- for (auto&& arg : args) { \
- checker.set_param(arg.param).execs({arg.src, arg.filter, arg.bias, {}, {}}); \
- }
-
- #if MEGDNN_X86_WITH_MKL || MEGDNN_X86_WITH_OPENBLAS
- cb("IM2COLMATMUL:X86_F32_BLAS");
- #endif
-
- #undef cb
- }
-
- #if MEGDNN_X86_WITH_MKL || MEGDNN_X86_WITH_OPENBLAS
- TEST_F(X86, CONV_BIAS_IM2COLMATMUL_FP32) {
- using namespace conv_bias;
- std::vector<TestArg> args;
-
- auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = 1;
- param.stride_w = 1;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- //! no bias
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{});
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{1, oc, 1, 1});
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{
- 1, oc, (h + 2 * p - kernel) / param.stride_h + 1,
- (w + 2 * p - kernel) / param.stride_w + 1});
- };
-
- for (size_t kernel : {2, 3, 4, 5, 6, 7})
- for (size_t ic : {1, 4, 8, 16})
- for (size_t oc : {1, 4, 8, 16, 300})
- for (size_t p : {0, 2})
- for (size_t size : {8, 24})
- for (NonlineMode nonline_mode :
- {NonlineMode::IDENTITY, NonlineMode::RELU}) {
- run(oc, ic, size, size, kernel, p, nonline_mode);
- }
-
- run(2046, 8, 20, 20, 3, 1, NonlineMode::IDENTITY);
- Checker<ConvBias> checker(handle());
- #define cb(algo_name) \
- checker.set_before_exec_callback( \
- conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name)); \
- for (auto&& arg : args) { \
- checker.set_param(arg.param).execs({arg.src, arg.filter, arg.bias, {}, {}}); \
- }
-
- cb("IM2COLMATMUL:X86_F32_BLAS");
-
- #undef cb
- }
-
- TEST_F(X86, CONV_BIAS_IM2COLMATMUL_FP32_RECORD) {
- using namespace conv_bias;
- std::vector<TestArg> args;
-
- auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = 1;
- param.stride_w = 1;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- //! no bias
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{});
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{1, oc, 1, 1});
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{
- 1, oc, (h + 2 * p - kernel) / param.stride_h + 1,
- (w + 2 * p - kernel) / param.stride_w + 1});
- };
- for (NonlineMode nonline_mode : {NonlineMode::IDENTITY, NonlineMode::RELU}) {
- run(1, 1, 24, 24, 2, 2, nonline_mode);
- }
-
- TaskRecordChecker<ConvBias> checker(0);
- for (auto&& arg : args) {
- checker.set_param(arg.param).execs({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
-
- TEST_F(X86, CONV_BIAS_IM2COLMATMUL_FP32_NOPACK_PREPROCESS) {
- using namespace conv_bias;
- std::vector<TestArg> args;
-
- auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = 1;
- param.stride_w = 1;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- //! no bias
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{});
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{1, oc, 1, 1});
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{
- 1, oc, (h + 2 * p - kernel) / param.stride_h + 1,
- (w + 2 * p - kernel) / param.stride_w + 1});
- };
-
- for (size_t kernel : {2, 3, 4, 5, 6, 7})
- for (size_t ic : {1, 4, 8, 16})
- for (size_t oc : {1, 4, 8, 16, 300})
- for (size_t p : {0, 2})
- for (size_t size : {8, 24})
- for (NonlineMode nonline_mode :
- {NonlineMode::IDENTITY, NonlineMode::RELU}) {
- run(oc, ic, size, size, kernel, p, nonline_mode);
- }
-
- run(2046, 8, 20, 20, 3, 1, NonlineMode::IDENTITY);
-
- Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
- handle());
- #define cb(algo_name) \
- checker.set_before_exec_callback( \
- conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name)); \
- for (auto&& arg : args) { \
- checker.set_param(arg.param).execs({arg.src, arg.filter, arg.bias, {}, {}}); \
- }
- cb("IM2COLMATMUL:X86_F32_BLAS");
-
- #undef cb
- }
-
- #endif
-
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_FP32_6x16) {
- using namespace conv_bias;
- std::vector<TestArg> args;
- auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = 1;
- param.stride_w = 1;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- //! no bias
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{});
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{1, oc, 1, 1});
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{
- 1, oc, (h + 2 * p - kernel) / param.stride_h + 1,
- (w + 2 * p - kernel) / param.stride_w + 1});
- };
-
- for (size_t kernel : {2, 3, 4, 5, 6, 7})
- for (size_t ic : {1, 4, 8, 16})
- for (size_t oc : {1, 4, 8, 16, 300})
- for (size_t p : {0, 2})
- for (size_t size : {8, 24})
- for (NonlineMode nonline_mode :
- {NonlineMode::IDENTITY, NonlineMode::RELU}) {
- run(oc, ic, size, size, kernel, p, nonline_mode);
- }
-
- run(2046, 8, 20, 20, 3, 1, NonlineMode::IDENTITY);
- Checker<ConvBias> checker(handle());
-
- #define cb(algo_name) \
- checker.set_before_exec_callback( \
- conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name)); \
- for (auto&& arg : args) { \
- checker.set_param(arg.param).execs({arg.src, arg.filter, arg.bias, {}, {}}); \
- }
- cb("IM2COLMATMUL:X86_F32_6x16:192");
- }
-
- #if MEGDNN_X86_WITH_MKL && SUPPORT_MKL_PACKED_GEMM
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_FP32_PACKA) {
- using namespace conv_bias;
- std::vector<TestArg> args;
-
- auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = 1;
- param.stride_w = 1;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- //! no bias
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{});
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{1, oc, 1, 1});
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{
- 1, oc, (h + 2 * p - kernel) / param.stride_h + 1,
- (w + 2 * p - kernel) / param.stride_w + 1});
- param.sparse = param::ConvBias::Sparse::GROUP;
- args.emplace_back(
- param, TensorShape{1, 2 * ic, h, w},
- TensorShape{2, oc, ic, kernel, kernel}, TensorShape{});
- args.emplace_back(
- param, TensorShape{1, 2 * ic, h, w},
- TensorShape{2, oc, ic, kernel, kernel}, TensorShape{1, oc * 2, 1, 1});
-
- args.emplace_back(
- param, TensorShape{1, 2 * ic, h, w},
- TensorShape{2, oc, ic, kernel, kernel},
- TensorShape{
- 1, 2 * oc, (h + 2 * param.pad_h - kernel) / 1 + 1,
- (w + 2 * param.pad_w - kernel) / 1 + 1});
- };
-
- for (size_t kernel : {2, 3, 4, 5, 6, 7})
- for (size_t ic : {1, 4, 8, 16})
- for (size_t oc : {1, 4, 8, 16})
- for (size_t p : {0, 1})
- for (size_t size : {8, 24})
- for (NonlineMode nonline_mode :
- {NonlineMode::IDENTITY, NonlineMode::RELU}) {
- run(oc, ic, size, size, kernel, p, nonline_mode);
- }
-
- run(2046, 8, 20, 20, 3, 1, NonlineMode::IDENTITY);
- Checker<ConvBias> checker(handle());
- #define cb(algo_name) \
- checker.set_before_exec_callback( \
- conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name)); \
- for (auto&& arg : args) { \
- checker.set_param(arg.param).execs({arg.src, arg.filter, arg.bias, {}, {}}); \
- }
-
- cb("IM2COLMATMUL:X86_F32_MKL_PACKA:192");
-
- #undef cb
- }
-
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_FP32_PACKA_FILTER_PREPROCESS) {
- using namespace conv_bias;
- std::vector<TestArg> args;
-
- auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = 1;
- param.stride_w = 1;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- //! no bias
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{});
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{1, oc, 1, 1});
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{
- 1, oc, (h + 2 * p - kernel) / param.stride_h + 1,
- (w + 2 * p - kernel) / param.stride_w + 1});
- param.sparse = param::ConvBias::Sparse::GROUP;
- args.emplace_back(
- param, TensorShape{1, 2 * ic, h, w},
- TensorShape{2, oc, ic, kernel, kernel}, TensorShape{});
- args.emplace_back(
- param, TensorShape{1, 2 * ic, h, w},
- TensorShape{2, oc, ic, kernel, kernel}, TensorShape{1, oc * 2, 1, 1});
-
- args.emplace_back(
- param, TensorShape{1, 2 * ic, h, w},
- TensorShape{2, oc, ic, kernel, kernel},
- TensorShape{
- 1, 2 * oc, (h + 2 * param.pad_h - kernel) / 1 + 1,
- (w + 2 * param.pad_w - kernel) / 1 + 1});
- };
-
- for (size_t kernel : {2, 3, 4, 5, 6, 7})
- for (size_t ic : {1, 4, 8, 16})
- for (size_t oc : {1, 4, 8, 16})
- for (size_t p : {0, 1})
- for (size_t size : {8, 24})
- for (NonlineMode nonline_mode :
- {NonlineMode::IDENTITY, NonlineMode::RELU}) {
- run(oc, ic, size, size, kernel, p, nonline_mode);
- }
-
- run(2046, 8, 20, 20, 3, 1, NonlineMode::IDENTITY);
- Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
- handle());
- #define cb(algo_name) \
- checker.set_before_exec_callback( \
- conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name)); \
- for (auto&& arg : args) { \
- checker.set_param(arg.param).execs({arg.src, arg.filter, arg.bias, {}, {}}); \
- }
-
- cb("IM2COLMATMUL:X86_F32_MKL_PACKA:192");
-
- #undef cb
- }
-
- /**************************** Conv1x1 PackA *************************/
- namespace {
- void checker_conv_bias(
- std::vector<conv_bias::TestArg> args, Handle* handle, RNG* rng, float epsilon,
- DType type0, DType type1, DType type2, DType type3, const char* algo_name) {
- using namespace conv_bias;
-
- Checker<ConvBias> checker(handle);
- checker.set_before_exec_callback(
- conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
- checker.set_dtype(0, type0);
- checker.set_dtype(1, type1);
- checker.set_dtype(2, type2);
- checker.set_dtype(4, type3);
- checker.set_epsilon(epsilon);
- if (NULL != rng) {
- checker.set_rng(0, rng).set_rng(1, rng).set_rng(2, rng).set_rng(3, rng);
- }
- for (auto&& arg : args) {
- checker.set_param(arg.param).execs({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
-
- void checker_conv_bias_preprocess(
- std::vector<conv_bias::TestArg> args, Handle* handle, RNG* rng, float epsilon,
- DType type0, DType type1, DType type2, DType type3, const char* algo_name) {
- using namespace conv_bias;
-
- Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(handle);
- checker.set_before_exec_callback(
- conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name));
- checker.set_dtype(0, type0);
- checker.set_dtype(1, type1);
- checker.set_dtype(2, type2);
- checker.set_dtype(4, type3);
- checker.set_epsilon(epsilon);
- if (NULL != rng) {
- checker.set_rng(0, rng).set_rng(1, rng).set_rng(2, rng).set_rng(3, rng);
- }
- for (auto&& arg : args) {
- checker.set_param(arg.param).execs({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
-
- } // namespace
-
- #if MEGDNN_X86_WITH_MKL
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_CONV1X1_S1_FP32_PACKA) {
- using namespace conv_bias;
- std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
- check_conv_bias(args, handle(), "CONV1x1:X86_F32_MKL_PACKA:24");
- }
-
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_CONV1X1_S1_FP32_PACKA_PREPROCESS) {
- using namespace conv_bias;
- std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
- checker_conv_bias_preprocess(
- args, handle(), nullptr, 0.001, dtype::Float32{}, dtype::Float32{},
- dtype::Float32{}, dtype::Float32{}, "CONV1x1:X86_F32_MKL_PACKA:24");
- }
-
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_CONV1X1_S1_FP32_BLAS) {
- using namespace conv_bias;
- std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
- check_conv_bias(args, handle(), "CONV1x1:X86_F32_BLAS:48");
- }
-
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_CONV1X1_S1_FP32_BLAS_NOPACK_REPROCESS) {
- using namespace conv_bias;
- std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
- checker_conv_bias_preprocess(
- args, handle(), nullptr, 0.001, dtype::Float32{}, dtype::Float32{},
- dtype::Float32{}, dtype::Float32{}, "CONV1x1:X86_F32_BLAS:24");
- }
- #endif
-
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_CONV1X1_S1_INT8X8X32) {
- using namespace conv_bias;
- UniformIntRNG rng{-50, 50};
- float epsilon = 0.001;
- std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, true);
- #if MEGDNN_X86_WITH_MKL_DNN
- if (x86::is_supported(x86::SIMDType::VNNI)) {
- checker_conv_bias(
- args, handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{},
- dtype::Int32{}, dtype::Int32{}, "CONV1x1:X86_INT8X8X32_MKLDNN:24");
- }
- #endif
- #if MEGDNN_X86_WITH_VNNI
- if (x86::is_supported(x86::SIMDType::VNNI)) {
- checker_conv_bias(
- args, handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{},
- dtype::Int32{}, dtype::Int32{}, "CONV1x1:X86_INT8X8X32_VNNI:24");
- }
- #endif
- if (x86::is_supported(x86::SIMDType::AVX2)) {
- checker_conv_bias(
- args, handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{},
- dtype::Int32{}, dtype::Int32{}, "CONV1x1:X86_INT8X8X32_AVX2_4X16X2:24");
- checker_conv_bias(
- args, handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{},
- dtype::Int32{}, dtype::Int32{}, "CONV1x1:X86_INT8X8X32_AVX2_2X4X16:24");
- checker_conv_bias(
- args, handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{},
- dtype::Int16{}, dtype::Int16{}, "CONV1x1:X86_INT8X8X16_AVX2");
- }
- checker_conv_bias(
- args, handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{}, dtype::Int32{},
- dtype::Int32{}, "CONV1x1:X86_INT8X8X32_SSE_4X8X2:48");
- checker_conv_bias(
- args, handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{}, dtype::Int16{},
- dtype::Int16{}, "CONV1x1:X86_INT8X8X16_SSE");
- }
-
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_CONV1X1_S1_INT8X8X32_PREPROCESS) {
- using namespace conv_bias;
- UniformIntRNG rng{-50, 50};
- float epsilon = 0.001;
- std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, true);
- #if MEGDNN_X86_WITH_VNNI
- if (x86::is_supported(x86::SIMDType::VNNI)) {
- checker_conv_bias_preprocess(
- args, handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{},
- dtype::Int32{}, dtype::Int32{}, "CONV1x1:X86_INT8X8X32_VNNI:24");
- }
- #endif
- if (x86::is_supported(x86::SIMDType::AVX2)) {
- checker_conv_bias_preprocess(
- args, handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{},
- dtype::Int32{}, dtype::Int32{}, "CONV1x1:X86_INT8X8X32_AVX2_4X16X2:24");
- checker_conv_bias_preprocess(
- args, handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{},
- dtype::Int32{}, dtype::Int32{}, "CONV1x1:X86_INT8X8X32_AVX2_2X4X16:24");
- checker_conv_bias_preprocess(
- args, handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{},
- dtype::Int16{}, dtype::Int16{}, "CONV1x1:X86_INT8X8X16_AVX2");
- }
- checker_conv_bias_preprocess(
- args, handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{}, dtype::Int32{},
- dtype::Int32{}, "CONV1x1:X86_INT8X8X32_SSE_4X8X2:48");
- checker_conv_bias_preprocess(
- args, handle(), &rng, epsilon, dtype::Int8{}, dtype::Int8{}, dtype::Int16{},
- dtype::Int16{}, "CONV1x1:X86_INT8X8X16_SSE");
- }
-
- /************************* End Conv1x1 PackA ************************/
-
- #endif
-
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_CONV1X1_S1_FP32_6x16) {
- using namespace conv_bias;
- std::vector<conv_bias::TestArg> args = get_conv_bias_1x1_args(false, false);
- check_conv_bias(args, handle(), "CONV1x1:X86_F32_6x16:48");
- }
-
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QINT8) {
- using namespace conv_bias;
- std::vector<TestArg> args;
-
- auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = 1;
- param.stride_w = 1;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- //! no bias
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{});
- //! bias channel
- args.emplace_back(
- param, TensorShape{2, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{1, oc, 1, 1});
- };
-
- for (size_t kernel : {2, 3, 4, 5, 6, 7})
- for (size_t ic : {1, 4, 8, 16})
- for (size_t oc : {1, 4, 8})
- for (size_t p : {0, 2})
- for (size_t size : {20, 21, 24})
- for (NonlineMode nonline_mode :
- {NonlineMode::IDENTITY, NonlineMode::RELU,
- NonlineMode::H_SWISH}) {
- run(oc, ic, size, size, kernel, p, nonline_mode);
- }
- run(2046, 8, 20, 20, 3, 1, NonlineMode::IDENTITY);
- Checker<ConvBias> checker(handle());
- #define cb(algo_name) \
- checker.set_before_exec_callback( \
- conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name)); \
- UniformIntRNG rng{-50, 50}; \
- for (auto&& arg : args) { \
- checker.set_dtype(0, dtype::QuantizedS8(2.5f)) \
- .set_dtype(1, dtype::QuantizedS8(2.5f)) \
- .set_dtype(2, dtype::QuantizedS32(6.25f)) \
- .set_dtype(4, dtype::QuantizedS8(60.25)) \
- .set_rng(0, &rng) \
- .set_rng(1, &rng) \
- .set_rng(2, &rng) \
- .set_param(arg.param) \
- .execs({arg.src, arg.filter, {}, {}, {}}); \
- }
-
- #if MEGDNN_X86_WITH_MKL_DNN
- if (x86::is_supported(x86::SIMDType::VNNI)) {
- cb("IM2COLMATMUL");
- }
- #endif
- #if MEGDNN_X86_WITH_VNNI
- if (x86::is_supported(x86::SIMDType::VNNI)) {
- cb("IM2COLMATMUL:X86_INT8X8X32_VNNI");
- }
- #endif
- if (x86::is_supported(x86::SIMDType::AVX2)) {
- cb("IM2COLMATMUL:X86_INT8X8X32_AVX2_2X4X16");
- }
-
- #undef cb
- }
-
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_IM2COLMATMUL_QINT8_FILTER_PREPROCESS) {
- using namespace conv_bias;
- std::vector<TestArg> args;
-
- auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = 1;
- param.stride_w = 1;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- //! no bias
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{});
- //! bias channel
- args.emplace_back(
- param, TensorShape{2, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{1, oc, 1, 1});
- };
-
- for (size_t kernel : {2, 3, 4, 5, 6, 7})
- for (size_t ic : {1, 4, 8, 16})
- for (size_t oc : {1, 4, 8})
- for (size_t p : {0, 2})
- for (size_t size : {20, 21, 24})
- for (NonlineMode nonline_mode :
- {NonlineMode::IDENTITY, NonlineMode::RELU,
- NonlineMode::H_SWISH}) {
- run(oc, ic, size, size, kernel, p, nonline_mode);
- }
- run(2046, 8, 20, 20, 3, 1, NonlineMode::IDENTITY);
- Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
- handle());
- #define cb(algo_name) \
- checker.set_before_exec_callback( \
- conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name)); \
- UniformIntRNG rng{-50, 50}; \
- for (auto&& arg : args) { \
- checker.set_dtype(0, dtype::QuantizedS8(2.5f)) \
- .set_dtype(1, dtype::QuantizedS8(2.5f)) \
- .set_dtype(2, dtype::QuantizedS32(6.25f)) \
- .set_dtype(4, dtype::QuantizedS8(60.25)) \
- .set_rng(0, &rng) \
- .set_rng(1, &rng) \
- .set_rng(2, &rng) \
- .set_param(arg.param) \
- .execs({arg.src, arg.filter, {}, {}, {}}); \
- }
-
- #if MEGDNN_X86_WITH_MKL_DNN
- if (x86::is_supported(x86::SIMDType::VNNI)) {
- cb("IM2COLMATMUL");
- }
- #endif
- #if MEGDNN_X86_WITH_VNNI
- if (x86::is_supported(x86::SIMDType::VNNI)) {
- cb("IM2COLMATMUL:X86_INT8X8X32_VNNI");
- }
- #endif
- if (x86::is_supported(x86::SIMDType::AVX2)) {
- cb("IM2COLMATMUL:X86_INT8X8X32_AVX2_2X4X16");
- }
-
- #undef cb
- }
-
- #if MEGDNN_WITH_BENCHMARK
- #if MEGDNN_X86_WITH_MKL_DNN
- static void x86_benchmark_fp32_mkldnn(Handle* handle) {
- constexpr size_t RUNS = 30;
- param::ConvBias param;
-
- Benchmarker<ConvBias> benchmarker_mkldnn(handle);
- benchmarker_mkldnn.set_display(false).set_times(RUNS);
- benchmarker_mkldnn.set_before_exec_callback(
- AlgoChecker<ConvBias>("MKLDNN_CONV_FP32"));
-
- Benchmarker<ConvBias> benchmarker_im2col(handle);
- benchmarker_im2col.set_display(false).set_times(RUNS);
- benchmarker_im2col.set_before_exec_callback(
- AlgoChecker<ConvBias>("IM2COLMATMUL.+"));
- auto run = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W, size_t FS,
- size_t SZ, size_t GROUP = 1) {
- TensorShape src({N, IC, H, W}), filter({OC, IC, FS, FS}), bias({1, OC, 1, 1}),
- z({}), dst({N, OC, H / SZ, W / SZ});
- param.pad_h = FS / 2;
- param.pad_w = FS / 2;
- param.stride_h = SZ;
- param.stride_w = SZ;
- param.format = param::ConvBias::Format::NCHW;
- param.sparse = param::ConvBias::Sparse::DENSE;
- if (GROUP > 1) {
- param.sparse = param::ConvBias::Sparse::GROUP;
- filter = {GROUP, OC / GROUP, IC / GROUP, FS, FS};
- }
- auto im2col_used =
- benchmarker_im2col.set_param(param).exec({src, filter, bias, z, dst}) /
- RUNS;
-
- src = IC < 8 ? TensorShape{N, IC, H, W} : TensorShape{N, IC / 8, H, W, 8};
-
- filter = IC < 8 ? TensorShape{OC / 8, FS, FS, IC, 8}
- : TensorShape{OC / 8, IC / 8, FS, FS, 8, 8};
- if (GROUP > 1 && OC == GROUP && IC == GROUP) {
- filter = {GROUP / 8, 1, 1, FS, FS, 8};
- } else if (GROUP > 1 && OC / GROUP % 8 == 0 && IC / GROUP % 8 == 0) {
- filter = {GROUP, OC / GROUP / 8, IC / GROUP / 8, FS, FS, 8, 8};
- }
- bias = {1, OC / 8, 1, 1, 8};
- z = {};
- dst = {N, OC / 8, H / SZ, W / SZ, 8};
- param.format = param::ConvBias::Format::NCHW88;
- auto mkldnn_used =
- benchmarker_mkldnn.set_param(param).exec({src, filter, bias, z, dst}) /
- RUNS;
- float computations =
- (IC / GROUP * FS * FS + 1) * dst.total_nr_elems() * 2 * 1e-6;
- std::cout << "run " << src.to_string() << " " << filter.to_string() << " "
- << bias.to_string() << " " << dst.to_string() << std::endl;
- std::cout << "im2col: " << im2col_used << " ms, "
- << (computations / im2col_used) << " Gops, ";
- std::cout << "mkldnn: " << mkldnn_used << " ms, "
- << (computations / mkldnn_used) << " Gops, "
- << "spped up: " << (im2col_used / mkldnn_used) << ", ";
- std::cout << std::endl;
- };
-
- run(1, 64, 64, 56, 56, 3, 1);
-
- run(1, 3, 64, 224, 224, 3, 1);
- run(1, 3, 64, 224, 224, 7, 2);
-
- run(1, 64, 64, 56, 56, 3, 1);
- run(1, 128, 128, 28, 28, 3, 1);
- run(1, 256, 256, 14, 14, 3, 1);
- run(1, 512, 512, 7, 7, 3, 1);
- run(1, 256, 64, 56, 56, 1, 1);
- run(1, 512, 128, 28, 28, 1, 1);
- run(1, 1024, 256, 14, 14, 1, 1);
- run(1, 2048, 512, 7, 7, 1, 1);
-
- run(1, 32, 32, 112, 112, 3, 1, 32);
- run(1, 144, 144, 56, 56, 3, 1, 144);
- run(1, 192, 192, 28, 28, 3, 1, 192);
- run(1, 384, 384, 28, 28, 3, 1, 384);
- run(1, 576, 576, 14, 14, 3, 1, 576);
- run(1, 960, 960, 7, 7, 3, 1, 960);
-
- run(1, 256, 128, 56, 56, 1, 2, 1);
- run(1, 512, 256, 28, 28, 1, 2, 1);
- run(1, 1024, 512, 14, 14, 1, 2, 1);
- run(1, 96, 96, 112, 112, 3, 2, 96);
- run(1, 144, 144, 56, 56, 3, 2, 144);
- run(1, 384, 384, 28, 28, 3, 2, 384);
- run(1, 576, 576, 14, 14, 3, 2, 576);
- }
- TEST_F(X86, BENCHMARK_CONVBIAS_FP32_MKLDNN) {
- x86_benchmark_fp32_mkldnn(handle());
- }
- TEST_F(X86_MULTI_THREADS, BENCHMARK_CONVBIAS_FP32_MKLDNN) {
- x86_benchmark_fp32_mkldnn(handle());
- }
- #endif
- #endif
-
- /************************* Winograd ****************************/
- namespace {
- std::vector<conv_bias::TestArg> get_winograd_mk_nchw88_args() {
- std::vector<conv_bias::TestArg> args;
- param::ConvBias cur_param;
- cur_param.format = param::ConvBias::Format::NCHW88;
- using NLMode = param::ConvBias::NonlineMode;
-
- // clang-format off
- for (auto nlmode :
- {NLMode::IDENTITY, NLMode::RELU, NLMode::SIGMOID, NLMode::H_SWISH}) {
- for (size_t ic : {1, 2}) {
- for (size_t oc : {1, 2}) {
- for (size_t i : {9, 63}) {
-
- cur_param.mode = param::ConvBias::Mode::CROSS_CORRELATION;
- cur_param.nonlineMode = nlmode;
-
- cur_param.sparse = param::ConvBias::Sparse::DENSE;
- cur_param.pad_h = cur_param.pad_w = 1;
-
- args.emplace_back(cur_param, TensorShape{1, ic, i, i, 8},
- TensorShape{oc, ic, 3, 3, 8, 8},
- TensorShape{1, oc, 1, 1, 8});
- args.emplace_back(cur_param, TensorShape{1, ic, i, i, 8},
- TensorShape{oc, ic, 3, 3, 8, 8},TensorShape{});
- //! bias
- args.emplace_back(cur_param, TensorShape{2, ic, i, i, 8},
- TensorShape{oc, ic, 3, 3, 8, 8},
- TensorShape{2, oc, i, i, 8});
-
- /*cur_param.sparse = param::ConvBias::Sparse::GROUP;
- args.emplace_back(cur_param, TensorShape{2, 2 * ic, i, i, 8},
- TensorShape{2, oc, ic, 3, 3, 8, 8},
- TensorShape{1, 2 * oc, 1, 1, 8});*/
- }}}
- // clang-format on
- //! test for multi-thread OC parallel
- cur_param.sparse = param::ConvBias::Sparse::DENSE;
- cur_param.pad_h = cur_param.pad_w = 1;
- args.emplace_back(
- cur_param, TensorShape{2, 1, 9, 9, 8}, TensorShape{128, 1, 3, 3, 8, 8},
- TensorShape{1, 128, 1, 1, 8});
- /*cur_param.sparse = param::ConvBias::Sparse::GROUP;
- args.emplace_back(cur_param, TensorShape{2, 2, 9, 9, 8},
- TensorShape{2, 128, 1, 3, 3, 8, 8},
- TensorShape{1, 2 * 128, 1, 1, 8});*/
- }
- return args;
- }
- } // namespace
-
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_WINOGRAD_NCHW88_F63) {
- using namespace conv_bias;
- std::vector<TestArg> args = get_winograd_mk_nchw88_args();
- Checker<ConvBiasForward> checker(handle());
-
- checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
- ssprintf("WINOGRAD:X86_F32MK8_8X8:8:6").c_str()));
-
- for (auto&& arg : args) {
- checker.set_param(arg.param).execs({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
-
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_WINOGRAD_NCHW88_F63_WEIGHT_PREPROCESS) {
- using namespace conv_bias;
- std::vector<TestArg> args = get_winograd_mk_nchw88_args();
- Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
- handle());
-
- checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
- ssprintf("WINOGRAD:X86_F32MK8_8X8:8:6").c_str()));
-
- for (auto&& arg : args) {
- checker.set_param(arg.param).execs({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
-
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_WINOGRAD_NCHW88_F23) {
- using namespace conv_bias;
- std::vector<TestArg> args = get_winograd_mk_nchw88_args();
- Checker<ConvBiasForward> checker(handle());
-
- checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
- ssprintf("WINOGRAD:X86_F32MK8_8X8:8:2").c_str()));
-
- for (auto&& arg : args) {
- checker.set_param(arg.param).execs({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
-
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_WINOGRAD_NCHW88_F23_WEIGHT_PREPROCESS) {
- using namespace conv_bias;
- std::vector<TestArg> args = get_winograd_mk_nchw88_args();
- Checker<ConvBiasForward, OprWeightPreprocessProxy<ConvBiasForward>> checker(
- handle());
-
- checker.set_before_exec_callback(conv_bias::ConvBiasAlgoChecker<ConvBias>(
- ssprintf("WINOGRAD:X86_F32MK8_8X8:8:2").c_str()));
-
- for (auto&& arg : args) {
- checker.set_param(arg.param).execs({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
-
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_WINOGRAD_WEIGHT_PREPROCESS) {
- using namespace conv_bias;
- std::vector<TestArg> args = get_winograd_mk_nchw88_args();
- Checker<ConvBiasForward> checker(handle());
-
- auto run = [&checker](
- const std::vector<TestArg>& args, DType A_dtype, DType B_dtype,
- DType C_dtype, DType D_dtype, const float eps) {
- for (auto&& arg : args) {
- checker.set_dtype(0, A_dtype)
- .set_dtype(1, B_dtype)
- .set_dtype(2, C_dtype)
- .set_dtype(4, D_dtype)
- .set_epsilon(eps)
- .set_param(arg.param)
- .execs({arg.src, arg.filter, arg.bias, {}, {}});
- }
- };
- run(args, dtype::Float32(), dtype::Float32(), dtype::Float32(), dtype::Float32(),
- 1e-3f);
- }
-
- /*********************************** End winograd ************************/
- #if MEGDNN_X86_WITH_MKL_DNN
- static void x86_correctness_fp32_mkldnn_run(
- Checker<ConvBias>& checker, UniformIntRNG& rng, Handle* handle,
- ConvBiasForward::BiasMode bias_mode, param::ConvBias::NonlineMode noline_mode,
- size_t n, size_t stride, size_t kernel, size_t oc, size_t ic, size_t h,
- size_t w, size_t group) {
- auto oc_per_group = oc / group;
- auto ic_per_group = ic / group;
- bool ok_group = oc_per_group % 8 == 0 && oc_per_group > 0 &&
- (ic_per_group % 8 == 0 || ic_per_group == 3) && ic_per_group > 0;
- bool ok_depthwise = oc == ic && oc == group;
- if (!(ok_group || ok_depthwise)) {
- return;
- }
- size_t pad = kernel / 2;
- size_t kernel_h = kernel;
- size_t kernel_w = kernel;
- param::ConvBias param;
- param.format = param::ConvBias::Format::NCHW88;
- param.stride_h = stride;
- param.stride_w = stride;
- param.pad_h = pad;
- param.pad_w = pad;
- param.nonlineMode = noline_mode;
- auto src_tensor_shape = TensorShape{n, ic / 8, h, w, 8};
- if (ic == 3) {
- src_tensor_shape = TensorShape{n, ic, h, w};
- }
-
- auto weight_tensor_shape = TensorShape{oc / 8, ic / 8, kernel_h, kernel_w, 8, 8};
- if (ic == 3) {
- weight_tensor_shape = TensorShape{oc / 8, kernel_h, kernel_w, ic, 8};
- }
-
- auto bias_tensor_shape = TensorShape{};
-
- if (bias_mode == megdnn::BiasMode::BROADCAST_CHANNEL_BIAS) {
- bias_tensor_shape = {1, oc / 8, 1, 1, 8};
- } else if (bias_mode == megdnn::BiasMode::BIAS) {
- TensorLayout dst_layout;
- auto ConvBiasOp = handle->create_operator<ConvBias>();
- ConvBiasOp->param() = param;
- ConvBiasOp->deduce_layout(
- {src_tensor_shape, dtype::Float32()},
- {weight_tensor_shape, dtype::Float32()}, {}, {}, dst_layout);
- bias_tensor_shape = dst_layout;
- }
-
- if (group == 1) {
- param.sparse = param::ConvBias::Sparse::DENSE;
- } else if (group > 1 && ic / group == 1 && oc / group == 1) {
- param.sparse = param::ConvBias::Sparse::GROUP;
- weight_tensor_shape = TensorShape{group / 8, 1, 1, kernel_h, kernel_w, 8};
- } else if (
- group > 1 && oc / group % 8 == 0 && oc / group > 0 && ic / group % 8 == 0 &&
- ic / group > 0) {
- param.sparse = param::ConvBias::Sparse::GROUP;
- weight_tensor_shape = TensorShape{
- group, oc / group / 8, ic / group / 8, kernel_h, kernel_w, 8, 8};
- }
- checker.set_dtype(0, dtype::Float32())
- .set_dtype(1, dtype::Float32())
- .set_dtype(2, dtype::Float32())
- .set_dtype(4, dtype::Float32())
- .set_rng(0, &rng)
- .set_rng(1, &rng)
- .set_rng(2, &rng)
- .set_epsilon(1e-3)
- .set_param(param)
- .execs({src_tensor_shape, weight_tensor_shape, bias_tensor_shape, {}, {}});
- }
-
- static void x86_correctness_fp32_mkldnn(Handle* handle) {
- Checker<ConvBias> checker(handle);
- UniformIntRNG rng{-127, 127};
-
- checker.set_before_exec_callback(
- conv_bias::ConvBiasAlgoChecker<ConvBiasForward>("MKLDNN_CONV_FP32"));
-
- for (auto bias_mode :
- {megdnn::BiasMode::NO_BIAS, megdnn::BiasMode::BROADCAST_CHANNEL_BIAS,
- megdnn::BiasMode::BIAS})
- for (auto noline_mode :
- {param::ConvBias::NonlineMode::IDENTITY,
- param::ConvBias::NonlineMode::SIGMOID,
- param::ConvBias::NonlineMode::H_SWISH})
- for (size_t n : {1, 2})
- for (size_t stride : {1, 2})
- for (size_t kernel : {3, 5, 7})
- for (size_t oc : {8, 16})
- for (size_t ic : {3, 8, 16})
- for (size_t h : {22, 33})
- for (size_t w : {22, 33}) {
- for (size_t group = 1;
- group <= std::min(oc, ic); ++group) {
- x86_correctness_fp32_mkldnn_run(
- checker, rng, handle, bias_mode,
- noline_mode, n, stride, kernel, oc,
- ic, h, w, group);
- }
- }
- }
-
- TEST_F(X86, CONV_BIAS_DIRECT_MKLDNN_C8) {
- x86_correctness_fp32_mkldnn(handle());
- }
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_DIRECT_MKLDNN_C8) {
- x86_correctness_fp32_mkldnn(handle());
- }
-
- TEST_F(X86, CONV_BIAS_MKL_DNN_MATMUL_INT8) {
- using namespace conv_bias;
-
- std::vector<TestArg> args;
- auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = 1;
- param.stride_w = 1;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- //! no bias
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{});
- };
-
- for (size_t kernel : {2, 3, 5, 7})
- for (size_t ic : {1, 2, 3, 4})
- for (size_t oc : {1, 2, 4})
- for (size_t p : {0, 2})
- for (size_t size : {20, 21, 22, 23, 24})
- for (NonlineMode nonline_mode : {NonlineMode::IDENTITY}) {
- run(oc, ic, size, size, kernel, p, nonline_mode);
- }
-
- Checker<ConvBias> checker(handle());
- checker.set_before_exec_callback(
- conv_bias::ConvBiasAlgoChecker<ConvBiasForward>("MKLDNN_MATMUL_INT8"));
- checker.set_epsilon(1);
- UniformIntRNG rng{-50, 50};
- checker.set_dtype(0, dtype::Int8())
- .set_dtype(1, dtype::Int8())
- .set_dtype(2, dtype::Int32())
- .set_dtype(4, dtype::Int32())
- .set_rng(0, &rng)
- .set_rng(1, &rng)
- .set_rng(2, &rng);
-
- for (auto&& arg : args) {
- checker.set_param(arg.param).exec({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
-
- TEST_F(X86, CONV_BIAS_MKL_DNN_INT8) {
- using namespace conv_bias;
-
- std::vector<TestArg> args;
- auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = 1;
- param.stride_w = 1;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- //! no bias
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{});
- };
-
- for (size_t kernel : {2, 3, 5, 7})
- for (size_t ic : {1, 2, 3, 4})
- for (size_t oc : {1, 2, 4})
- for (size_t p : {0, 2})
- for (size_t size : {20, 22, 24})
- for (NonlineMode nonline_mode : {NonlineMode::IDENTITY}) {
- run(oc, ic, size, size, kernel, p, nonline_mode);
- }
-
- Checker<ConvBias> checker(handle());
- checker.set_before_exec_callback(
- conv_bias::ConvBiasAlgoChecker<ConvBiasForward>("MKLDNN_INT8"));
- checker.set_epsilon(1);
- UniformIntRNG rng{-50, 50};
- checker.set_dtype(0, dtype::Int8())
- .set_dtype(1, dtype::Int8())
- .set_dtype(2, dtype::Int32())
- .set_dtype(4, dtype::Int32())
- .set_rng(0, &rng)
- .set_rng(1, &rng)
- .set_rng(2, &rng);
-
- for (auto&& arg : args) {
- checker.set_param(arg.param).exec({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
-
- TEST_F(X86_MULTI_THREADS, CONV_BIAS_MKL_DNN_INT8) {
- using namespace conv_bias;
-
- std::vector<TestArg> args;
- auto run = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel, size_t p,
- NonlineMode nonline_mode) {
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
- param::ConvBias param;
- param.stride_h = 1;
- param.stride_w = 1;
- param.pad_h = p;
- param.pad_w = p;
- param.nonlineMode = nonline_mode;
-
- //! no bias
- args.emplace_back(
- param, TensorShape{1, ic, h, w}, TensorShape{oc, ic, kernel, kernel},
- TensorShape{});
- };
-
- for (size_t kernel : {2, 3, 5, 7})
- for (size_t ic : {1, 2, 3, 4})
- for (size_t oc : {1, 2, 4})
- for (size_t p : {0, 2})
- for (size_t size : {20, 22, 24})
- for (NonlineMode nonline_mode : {NonlineMode::IDENTITY}) {
- run(oc, ic, size, size, kernel, p, nonline_mode);
- }
-
- Checker<ConvBias> checker(handle());
- checker.set_before_exec_callback(
- conv_bias::ConvBiasAlgoChecker<ConvBiasForward>("MKLDNN_INT8"));
- checker.set_epsilon(1);
- UniformIntRNG rng{-50, 50};
- checker.set_dtype(0, dtype::Int8())
- .set_dtype(1, dtype::Int8())
- .set_dtype(2, dtype::Int32())
- .set_dtype(4, dtype::Int32())
- .set_rng(0, &rng)
- .set_rng(1, &rng)
- .set_rng(2, &rng);
-
- for (auto&& arg : args) {
- checker.set_param(arg.param).exec({arg.src, arg.filter, arg.bias, {}, {}});
- }
- }
- #endif
-
- #if MEGDNN_WITH_BENCHMARK
- namespace {
- void benchmark_impl(
- const param::ConvBias param,
- std::vector<std::pair<SmallVector<TensorShape>, float>>& shapes_and_computation,
- const std::string algo_name, size_t RUNS,
- TaskExecutorConfig&& multi_thread_config,
- TaskExecutorConfig&& single_thread_config, std::vector<DType> dtype_v) {
- std::vector<DType> data_type = {
- dtype::Float32(), dtype::Float32(), dtype::Float32(), dtype::Float32()};
-
- std::vector<float> multi_thread_times, single_thread_times;
- {
- auto multi_thread_hanle = create_cpu_handle(0, true, &multi_thread_config);
- auto benchmarker = Benchmarker<ConvBias>(multi_thread_hanle.get());
- benchmarker.set_times(RUNS)
- .set_display(false)
- .set_dtype(0, dtype_v[0])
- .set_dtype(1, dtype_v[1])
- .set_dtype(2, dtype_v[2])
- .set_dtype(4, dtype_v[3])
- .set_param(param)
- .set_before_exec_callback(
- conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name.c_str()));
- for (auto shape : shapes_and_computation) {
- multi_thread_times.push_back(benchmarker.exec(shape.first) / RUNS);
- }
- }
- {
- auto single_thread_handle = create_cpu_handle(0, true, &single_thread_config);
- auto benchmarker = Benchmarker<ConvBias>(single_thread_handle.get());
- benchmarker.set_times(RUNS)
- .set_display(false)
- .set_dtype(0, dtype_v[0])
- .set_dtype(1, dtype_v[1])
- .set_dtype(2, dtype_v[2])
- .set_dtype(4, dtype_v[3])
- .set_param(param)
- .set_before_exec_callback(
- conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name.c_str()));
- for (auto shape : shapes_and_computation) {
- single_thread_times.push_back(benchmarker.exec(shape.first) / RUNS);
- }
- }
- printf("Benchmark : Multi threads %zu, ", multi_thread_config.nr_thread);
- printf("core_ids:");
- for (size_t i = 0; i < multi_thread_config.affinity_core_set.size(); i++) {
- printf("%zu ", multi_thread_config.affinity_core_set[i]);
- }
- printf(", Single thread core_id %zu\n", single_thread_config.affinity_core_set[0]);
- for (size_t i = 0; i < shapes_and_computation.size(); i++) {
- auto shapes = shapes_and_computation[i];
- printf("Bench case: ");
- for (auto&& shape : shapes.first) {
- printf("%s ", shape.to_string().c_str());
- }
- float computations = shapes.second;
- printf("%zu threads gflops: %f,\n single thread gflops: "
- "%f. spead up = %f, speedup/cores=%f\n",
- multi_thread_config.nr_thread, computations / multi_thread_times[i],
- computations / single_thread_times[i],
- single_thread_times[i] / multi_thread_times[i],
- single_thread_times[i] / multi_thread_times[i] /
- multi_thread_config.nr_thread);
- }
- }
-
- void benchmark_impl_comp(
- const param::ConvBias param,
- std::vector<std::pair<SmallVector<TensorShape>, float>>& shapes_and_computation,
- const std::string algo_name, const std::string algo_name1, size_t RUNS,
- TaskExecutorConfig&& multi_thread_config,
- TaskExecutorConfig&& single_thread_config, std::vector<DType> dtype_v) {
- std::vector<DType> data_type = {
- dtype::Float32(), dtype::Float32(), dtype::Float32(), dtype::Float32()};
-
- std::vector<float> multi_thread_times, single_thread_times;
- {
- auto multi_thread_hanle = create_cpu_handle(0, true, &multi_thread_config);
- auto benchmarker = Benchmarker<ConvBias>(multi_thread_hanle.get());
- benchmarker.set_times(RUNS)
- .set_display(false)
- .set_dtype(0, dtype_v[0])
- .set_dtype(1, dtype_v[1])
- .set_dtype(2, dtype_v[2])
- .set_dtype(4, dtype_v[3])
- .set_param(param)
- .set_before_exec_callback(
- conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name.c_str()));
- for (auto shape : shapes_and_computation) {
- multi_thread_times.push_back(benchmarker.exec(shape.first) / RUNS);
- }
- }
- {
- auto single_thread_handle = create_cpu_handle(0, true, &single_thread_config);
- auto benchmarker = Benchmarker<ConvBias>(single_thread_handle.get());
- benchmarker.set_times(RUNS)
- .set_display(false)
- .set_dtype(0, dtype_v[0])
- .set_dtype(1, dtype_v[1])
- .set_dtype(2, dtype_v[2])
- .set_dtype(4, dtype_v[3])
- .set_param(param)
- .set_before_exec_callback(
- conv_bias::ConvBiasAlgoChecker<ConvBias>(algo_name1.c_str()));
- for (auto shape : shapes_and_computation) {
- single_thread_times.push_back(benchmarker.exec(shape.first) / RUNS);
- }
- }
- printf("Benchmark : Multi threads %zu, ", multi_thread_config.nr_thread);
- printf("core_ids:");
- for (size_t i = 0; i < multi_thread_config.affinity_core_set.size(); i++) {
- printf("%zu ", multi_thread_config.affinity_core_set[i]);
- }
- for (size_t i = 0; i < shapes_and_computation.size(); i++) {
- auto shapes = shapes_and_computation[i];
- printf("Bench case: ");
- for (auto&& shape : shapes.first) {
- printf("%s ", shape.to_string().c_str());
- }
- float computations = shapes.second;
- printf("algo:%s gflops: %f,\n algo:%s gflops: "
- "%f. spead up = %f\n",
- algo_name.c_str(), computations / multi_thread_times[i],
- algo_name1.c_str(), computations / single_thread_times[i],
- single_thread_times[i] / multi_thread_times[i]);
- }
- }
-
- } // namespace
-
- static void benchmark_convbias_chanwise_avx2_int8(uint32_t stride, const char* algo) {
- constexpr size_t RUNS = 50;
- param::ConvBias param;
- param.stride_h = stride;
- param.stride_w = stride;
- param.sparse = param::ConvBias::Sparse::GROUP;
-
- std::vector<DType> data_type = {
- dtype::Int8(), dtype::Int8(), dtype::Int32(), dtype::Int32()};
-
- std::vector<std::pair<SmallVector<TensorShape>, float>> shapes_and_computation;
- auto bench_case = [&](size_t N, size_t IC, size_t H, size_t W, size_t FS) {
- param.pad_h = FS / 2;
- param.pad_w = FS / 2;
-
- SmallVector<TensorShape> shapes{{N, IC, H, W}, {IC, 1, 1, FS, FS}, {}, {}, {}};
- TensorShape dst{
- N, IC, (H + 2 * param.pad_h - FS) + 1, (W + 2 * param.pad_w - FS) + 1};
- float computations = (FS * FS * dst.total_nr_elems() * 2) * 1e-6;
- shapes_and_computation.push_back(std::make_pair(shapes, computations));
- };
-
- bench_case(1, 32, 112, 112, 7);
- bench_case(1, 144, 56, 56, 7);
- bench_case(1, 192, 28, 28, 7);
- bench_case(1, 384, 28, 28, 7);
- bench_case(1, 576, 14, 14, 7);
- bench_case(1, 960, 7, 7, 7);
-
- bench_case(1, 32, 112, 112, 5);
- bench_case(1, 144, 56, 56, 5);
- bench_case(1, 192, 28, 28, 5);
- bench_case(1, 384, 28, 28, 5);
- bench_case(1, 576, 14, 14, 5);
- bench_case(1, 960, 7, 7, 5);
-
- bench_case(1, 32, 112, 112, 3);
- bench_case(1, 144, 56, 56, 3);
- bench_case(1, 192, 28, 28, 3);
- bench_case(1, 384, 28, 28, 3);
- bench_case(1, 576, 14, 14, 3);
- bench_case(1, 960, 7, 7, 3);
-
- bench_case(1, 32, 112, 112, 2);
- bench_case(1, 144, 56, 56, 2);
- bench_case(1, 192, 28, 28, 2);
- bench_case(1, 384, 28, 28, 2);
- bench_case(1, 576, 14, 14, 2);
- bench_case(1, 960, 7, 7, 2);
-
- std::string algo_name = algo;
- printf("Benchmark %s\n", algo);
- benchmark_impl(
- param, shapes_and_computation, algo_name, RUNS, {4, {4, 5, 6, 7}}, {1, {4}},
- data_type);
- benchmark_impl(
- param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}}, {1, {4}},
- data_type);
- shapes_and_computation.clear();
- }
- TEST_F(X86_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_CHANWISE_AVX2_INT8_S1) {
- benchmark_convbias_chanwise_avx2_int8(
- 1, "X86_CONV_BIAS_CHANWISE_AVX2_INT8_STRIDE1");
- }
-
- TEST_F(X86_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_CHANWISE_AVX2_INT8_S2) {
- benchmark_convbias_chanwise_avx2_int8(
- 2, "X86_CONV_BIAS_CHANWISE_AVX2_INT8_STRIDE2");
- }
-
- TEST_F(X86_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_DIRECT_AVX2_INT8) {
- constexpr size_t RUNS = 50;
- param::ConvBias param;
- param.stride_h = 1;
- param.stride_w = 1;
- param.sparse = param::ConvBias::Sparse::DENSE;
-
- std::vector<DType> data_type = {
- dtype::Int8(), dtype::Int8(), dtype::Int32(), dtype::Int32()};
-
- std::vector<std::pair<SmallVector<TensorShape>, float>> shapes_and_computation;
- auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
- size_t FS) {
- param.pad_h = FS / 2;
- param.pad_w = FS / 2;
-
- SmallVector<TensorShape> shapes{{N, IC, H, W}, {OC, IC, FS, FS}, {}, {}, {}};
- TensorShape dst{
- N, OC, (H + 2 * param.pad_h - FS) + 1, (W + 2 * param.pad_w - FS) + 1};
- float computations = (IC * FS * FS * dst.total_nr_elems() * 2) * 1e-6;
- shapes_and_computation.push_back(std::make_pair(shapes, computations));
- };
-
- bench_case(1, 32, 32, 200, 200, 7);
- bench_case(1, 32, 64, 200, 200, 7);
- bench_case(1, 32, 32, 128, 128, 7);
- bench_case(1, 32, 64, 128, 128, 7);
- bench_case(1, 32, 32, 100, 100, 7);
- bench_case(1, 32, 64, 100, 100, 7);
- bench_case(1, 32, 32, 80, 80, 7);
- bench_case(1, 32, 64, 80, 80, 7);
-
- bench_case(1, 32, 32, 200, 200, 5);
- bench_case(1, 32, 64, 200, 200, 5);
- bench_case(1, 32, 32, 128, 128, 5);
- bench_case(1, 32, 64, 128, 128, 5);
- bench_case(1, 32, 32, 100, 100, 5);
- bench_case(1, 32, 64, 100, 100, 5);
- bench_case(1, 32, 32, 80, 80, 5);
- bench_case(1, 32, 64, 80, 80, 5);
-
- bench_case(1, 32, 32, 200, 200, 3);
- bench_case(1, 32, 64, 200, 200, 3);
- bench_case(1, 32, 32, 128, 128, 3);
- bench_case(1, 32, 64, 128, 128, 3);
- bench_case(1, 32, 32, 100, 100, 3);
- bench_case(1, 32, 64, 100, 100, 3);
- bench_case(1, 32, 32, 80, 80, 3);
- bench_case(1, 32, 64, 80, 80, 3);
-
- bench_case(1, 32, 32, 200, 200, 2);
- bench_case(1, 32, 64, 200, 200, 2);
- bench_case(1, 32, 32, 128, 128, 2);
- bench_case(1, 32, 64, 128, 128, 2);
- bench_case(1, 32, 32, 100, 100, 2);
- bench_case(1, 32, 64, 100, 100, 2);
- bench_case(1, 32, 32, 80, 80, 2);
- bench_case(1, 32, 64, 80, 80, 2);
-
- std::string algo_name = "X86_CONV_BIAS_DIRECT_AVX2_INT8_STRIDE1";
- printf("Benchmark X86_CONV_BIAS_DIRECT_AVX2_INT8_STRIDE1 algo\n");
- benchmark_impl(
- param, shapes_and_computation, algo_name, RUNS, {4, {4, 5, 6, 7}}, {1, {4}},
- data_type);
- benchmark_impl(
- param, shapes_and_computation, algo_name, RUNS, {4, {4, 5, 6, 7}}, {1, {7}},
- data_type);
- benchmark_impl(
- param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}}, {1, {4}},
- data_type);
- shapes_and_computation.clear();
- }
-
- TEST_F(X86_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_8816) {
- constexpr size_t RUNS = 30;
- param::ConvBias param;
- param.stride_h = 1;
- param.stride_w = 1;
- param.sparse = param::ConvBias::Sparse::DENSE;
-
- std::vector<DType> data_type = {
- dtype::Int8(), dtype::Int8(), dtype::Int16(), dtype::Int16()};
-
- std::vector<std::pair<SmallVector<TensorShape>, float>> shapes_and_computation;
- auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
- size_t FS) {
- param.pad_h = FS / 2;
- param.pad_w = FS / 2;
-
- SmallVector<TensorShape> shapes{{N, IC, H, W}, {OC, IC, FS, FS}, {}, {}, {}};
- TensorShape dst{
- N, OC, (H + 2 * param.pad_h - FS) / param.stride_h + 1,
- (W + 2 * param.pad_w - FS) / param.stride_w + 1};
- float computations = (IC * FS * FS * dst.total_nr_elems() * 2) * 1e-6;
- shapes_and_computation.push_back(std::make_pair(shapes, computations));
- };
-
- bench_case(1, 48, 192, 15, 15, 1);
-
- std::string algo_name = "IM2COLMATMUL:X86_INT8X8X16_AVX2";
- benchmark_impl(
- param, shapes_and_computation, algo_name, RUNS, {4, {4, 5, 6, 7}}, {1, {4}},
- data_type);
- shapes_and_computation.clear();
- }
-
- TEST_F(X86_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_DIRECT_AVX2_INT8_STRIDE2) {
- constexpr size_t RUNS = 50;
- param::ConvBias param;
- param.stride_h = 2;
- param.stride_w = 2;
- param.sparse = param::ConvBias::Sparse::DENSE;
-
- std::vector<DType> data_type = {
- dtype::Int8(), dtype::Int8(), dtype::Int32(), dtype::Int32()};
-
- std::vector<std::pair<SmallVector<TensorShape>, float>> shapes_and_computation;
- auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W,
- size_t FS) {
- param.pad_h = FS / 2;
- param.pad_w = FS / 2;
-
- SmallVector<TensorShape> shapes{{N, IC, H, W}, {OC, IC, FS, FS}, {}, {}, {}};
- TensorShape dst{
- N, OC, (H + 2 * param.pad_h - FS) / param.stride_h + 1,
- (W + 2 * param.pad_w - FS) / param.stride_w + 1};
- float computations = (IC * FS * FS * dst.total_nr_elems() * 2) * 1e-6;
- shapes_and_computation.push_back(std::make_pair(shapes, computations));
- };
-
- bench_case(1, 32, 32, 200, 200, 7);
- bench_case(1, 32, 64, 200, 200, 7);
- bench_case(1, 32, 32, 128, 128, 7);
- bench_case(1, 32, 64, 128, 128, 7);
- bench_case(1, 32, 32, 100, 100, 7);
- bench_case(1, 32, 64, 100, 100, 7);
- bench_case(1, 32, 32, 80, 80, 7);
- bench_case(1, 32, 64, 80, 80, 7);
-
- bench_case(1, 32, 32, 200, 200, 5);
- bench_case(1, 32, 64, 200, 200, 5);
- bench_case(1, 32, 32, 128, 128, 5);
- bench_case(1, 32, 64, 128, 128, 5);
- bench_case(1, 32, 32, 100, 100, 5);
- bench_case(1, 32, 64, 100, 100, 5);
- bench_case(1, 32, 32, 80, 80, 5);
- bench_case(1, 32, 64, 80, 80, 5);
-
- bench_case(1, 32, 32, 200, 200, 3);
- bench_case(1, 32, 64, 200, 200, 3);
- bench_case(1, 32, 32, 128, 128, 3);
- bench_case(1, 32, 64, 128, 128, 3);
- bench_case(1, 32, 32, 100, 100, 3);
- bench_case(1, 32, 64, 100, 100, 3);
- bench_case(1, 32, 32, 80, 80, 3);
- bench_case(1, 32, 64, 80, 80, 3);
-
- bench_case(1, 32, 32, 200, 200, 2);
- bench_case(1, 32, 64, 200, 200, 2);
- bench_case(1, 32, 32, 128, 128, 2);
- bench_case(1, 32, 64, 128, 128, 2);
- bench_case(1, 32, 32, 100, 100, 2);
- bench_case(1, 32, 64, 100, 100, 2);
- bench_case(1, 32, 32, 80, 80, 2);
- bench_case(1, 32, 64, 80, 80, 2);
-
- std::string algo_name = "X86_CONV_BIAS_DIRECT_AVX2_INT8_STRIDE2";
- printf("Benchmark X86_CONV_BIAS_DIRECT_AVX2_INT8_STRIDE2 algo\n");
- benchmark_impl(
- param, shapes_and_computation, algo_name, RUNS, {4, {4, 5, 6, 7}}, {1, {4}},
- data_type);
- benchmark_impl(
- param, shapes_and_computation, algo_name, RUNS, {4, {4, 5, 6, 7}}, {1, {7}},
- data_type);
- benchmark_impl(
- param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}}, {1, {4}},
- data_type);
- shapes_and_computation.clear();
- }
-
- TEST_F(X86_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_DIRECTF32) {
- constexpr size_t RUNS = 50;
-
- param::ConvBias param;
- param.nonlineMode = param::ConvBias::NonlineMode::RELU;
- param.pad_h = 1;
- param.pad_w = 1;
- param.stride_h = 1;
- param.stride_w = 1;
- param.sparse = param::ConvBias::Sparse::GROUP;
-
- std::vector<DType> data_type = {
- dtype::Float32(), dtype::Float32(), dtype::Float32(), dtype::Float32()};
-
- std::vector<std::pair<SmallVector<TensorShape>, float>> shapes_and_computation;
- auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W, size_t FS,
- size_t group) {
- SmallVector<TensorShape> shapes{
- {N, IC, H, W},
- {group, OC / group, IC / group, FS, FS},
- {1, OC, 1, 1},
- {},
- {N, OC, H, W}};
- TensorShape dst{N, OC, H, W};
- float computations = ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
- dst.total_nr_elems()) *
- 1e-6;
- shapes_and_computation.push_back(std::make_pair(shapes, computations));
- };
-
- bench_case(1, 32, 32, 200, 200, 3, 4);
- bench_case(1, 32, 32, 200, 200, 3, 32);
- bench_case(1, 32, 32, 128, 128, 3, 4);
- bench_case(1, 32, 32, 128, 128, 3, 32);
- bench_case(1, 32, 32, 100, 100, 3, 4);
- bench_case(1, 32, 32, 100, 100, 3, 32);
- bench_case(1, 32, 32, 80, 80, 3, 4);
- bench_case(1, 32, 32, 80, 80, 3, 32);
-
- std::string algo_name = "X86_CONV_BIAS_DIRECT_STRIDE1_LARGE_GROUP";
- printf("Benchmark X86_CONV_BIAS_DIRECT_STRIDE1_GROUP algo\n");
- benchmark_impl(
- param, shapes_and_computation, algo_name, RUNS, {4, {4, 5, 6, 7}}, {1, {4}},
- data_type);
- benchmark_impl(
- param, shapes_and_computation, algo_name, RUNS, {4, {4, 5, 6, 7}}, {1, {7}},
- data_type);
- benchmark_impl(
- param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}}, {1, {4}},
- data_type);
- shapes_and_computation.clear();
-
- algo_name = "X86_CONV_BIAS_DIRECT_STRIDE1_LARGE_GROUP";
- printf("Benchmark X86_CONV_BIAS_DIRECT_STRIDE1_DENSE algo\n");
- bench_case(1, 32, 32, 200, 200, 3, 1);
- bench_case(1, 32, 32, 128, 128, 3, 1);
- bench_case(1, 32, 32, 100, 100, 3, 1);
- bench_case(1, 32, 32, 80, 80, 3, 1);
- benchmark_impl(
- param, shapes_and_computation, algo_name, RUNS, {4, {4, 5, 6, 7}}, {1, {4}},
- data_type);
- benchmark_impl(
- param, shapes_and_computation, algo_name, RUNS, {4, {4, 5, 6, 7}}, {1, {7}},
- data_type);
- benchmark_impl(
- param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}}, {1, {4}},
- data_type);
- }
-
- TEST_F(X86_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_IM2COL_F32) {
- constexpr size_t RUNS = 50;
-
- param::ConvBias param;
- param.nonlineMode = param::ConvBias::NonlineMode::RELU;
- param.pad_h = 1;
- param.pad_w = 1;
- param.stride_h = 1;
- param.stride_w = 1;
-
- std::vector<DType> data_type = {
- dtype::Float32(), dtype::Float32(), dtype::Float32(), dtype::Float32()};
- std::vector<std::pair<SmallVector<TensorShape>, float>> shapes_and_computation;
- auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W, size_t FS,
- size_t group) {
- SmallVector<TensorShape> shapes{
- {N, IC, H, W},
- {OC / group, IC / group, FS, FS},
- {1, OC, 1, 1},
- {},
- {N, OC, H, W}};
- TensorShape dst{N, OC, H, W};
- float computations = ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
- dst.total_nr_elems()) *
- 1e-6;
- shapes_and_computation.push_back(std::make_pair(shapes, computations));
- };
-
- bench_case(1, 32, 32, 200, 200, 3, 1);
- bench_case(1, 32, 32, 200, 200, 3, 1);
- bench_case(1, 32, 32, 128, 128, 3, 1);
- bench_case(1, 32, 32, 128, 128, 3, 1);
- bench_case(1, 32, 32, 100, 100, 3, 1);
- bench_case(1, 32, 32, 100, 100, 3, 1);
- bench_case(1, 32, 32, 80, 80, 3, 1);
- bench_case(1, 32, 32, 80, 80, 3, 1);
-
- bench_case(1, 64, 32, 7, 7, 3, 1);
- bench_case(1, 64, 64, 7, 7, 3, 1);
- bench_case(1, 64, 128, 7, 7, 3, 1);
- bench_case(1, 64, 256, 7, 7, 3, 1);
- bench_case(1, 64, 512, 7, 7, 3, 1);
- bench_case(1, 64, 1024, 7, 7, 3, 1);
-
- bench_case(1, 64, 32, 14, 14, 3, 1);
- bench_case(1, 64, 64, 14, 14, 3, 1);
- bench_case(1, 64, 128, 14, 14, 3, 1);
- bench_case(1, 64, 256, 14, 14, 3, 1);
- bench_case(1, 64, 512, 14, 14, 3, 1);
-
- bench_case(1, 64, 1024, 14, 14, 3, 1);
- bench_case(1, 128, 128, 14, 14, 3, 1);
- bench_case(1, 128, 256, 14, 14, 3, 1);
- bench_case(1, 512, 512, 14, 14, 3, 1);
- bench_case(1, 256, 512, 14, 14, 3, 1);
- bench_case(1, 512, 1024, 14, 14, 3, 1);
- bench_case(1, 1024, 1024, 14, 14, 3, 1);
-
- std::string algo_name = "IM2COLMATMUL:X86_F32_BLAS:192";
- printf("Benchmark IM2COLMATMUL:X86_F32_BLAS algo\n");
- benchmark_impl(
- param, shapes_and_computation, algo_name, RUNS, {4, {4, 5, 6, 7}}, {1, {4}},
- data_type);
- benchmark_impl(
- param, shapes_and_computation, algo_name, RUNS, {4, {4, 5, 6, 7}}, {1, {7}},
- data_type);
- benchmark_impl(
- param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}}, {1, {4}},
- data_type);
- shapes_and_computation.clear();
- }
-
- TEST_F(X86_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_IM2COL_F32_single_thread) {
- constexpr size_t RUNS = 50;
-
- param::ConvBias param;
- param.nonlineMode = param::ConvBias::NonlineMode::RELU;
- param.pad_h = 1;
- param.pad_w = 1;
- param.stride_h = 1;
- param.stride_w = 1;
-
- std::vector<DType> data_type = {
- dtype::Float32(), dtype::Float32(), dtype::Float32(), dtype::Float32()};
- std::vector<std::pair<SmallVector<TensorShape>, float>> shapes_and_computation;
- auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W, size_t FS,
- size_t group) {
- SmallVector<TensorShape> shapes{
- {N, IC, H, W},
- {OC / group, IC / group, FS, FS},
- {1, OC, 1, 1},
- {},
- {N, OC, H, W}};
- TensorShape dst{N, OC, H, W};
- float computations = ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
- dst.total_nr_elems()) *
- 1e-6;
- shapes_and_computation.push_back(std::make_pair(shapes, computations));
- };
-
- bench_case(1, 32, 32, 200, 200, 3, 1);
- bench_case(1, 32, 32, 200, 200, 3, 1);
- bench_case(1, 32, 32, 128, 128, 3, 1);
- bench_case(1, 32, 32, 128, 128, 3, 1);
- bench_case(1, 32, 32, 100, 100, 3, 1);
- bench_case(1, 32, 32, 100, 100, 3, 1);
- bench_case(1, 32, 32, 80, 80, 3, 1);
- bench_case(1, 32, 32, 80, 80, 3, 1);
-
- bench_case(1, 64, 32, 7, 7, 3, 1);
- bench_case(1, 64, 64, 7, 7, 3, 1);
- bench_case(1, 64, 128, 7, 7, 3, 1);
- bench_case(1, 64, 256, 7, 7, 3, 1);
- bench_case(1, 64, 512, 7, 7, 3, 1);
- bench_case(1, 64, 1024, 7, 7, 3, 1);
-
- bench_case(1, 64, 32, 14, 14, 3, 1);
- bench_case(1, 64, 64, 14, 14, 3, 1);
- bench_case(1, 64, 128, 14, 14, 3, 1);
- bench_case(1, 64, 256, 14, 14, 3, 1);
- bench_case(1, 64, 512, 14, 14, 3, 1);
-
- bench_case(1, 64, 1024, 14, 14, 3, 1);
- bench_case(1, 128, 128, 14, 14, 3, 1);
- bench_case(1, 128, 256, 14, 14, 3, 1);
- bench_case(1, 512, 512, 14, 14, 3, 1);
- bench_case(1, 256, 512, 14, 14, 3, 1);
- bench_case(1, 512, 1024, 14, 14, 3, 1);
- bench_case(1, 1024, 1024, 14, 14, 3, 1);
-
- std::string algo_name = "IM2COLMATMUL:X86_F32_MKL_PACKA:192";
- std::string algo_name1 = "IM2COLMATMUL:X86_F32_BLAS:192";
- printf("Benchmark IM2COLMATMUL:X86_F32_BLAS algo\n");
- benchmark_impl_comp(
- param, shapes_and_computation, algo_name, algo_name1, RUNS, {1, {4}},
- {1, {4}}, data_type);
- benchmark_impl_comp(
- param, shapes_and_computation, algo_name, algo_name1, RUNS, {1, {7}},
- {1, {7}}, data_type);
- shapes_and_computation.clear();
- }
-
- TEST_F(X86_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_IM2COL_F32_6x16) {
- constexpr size_t RUNS = 50;
-
- param::ConvBias param;
- param.nonlineMode = param::ConvBias::NonlineMode::RELU;
- param.pad_h = 1;
- param.pad_w = 1;
- param.stride_h = 1;
- param.stride_w = 1;
-
- std::vector<DType> data_type = {
- dtype::Float32(), dtype::Float32(), dtype::Float32(), dtype::Float32()};
- std::vector<std::pair<SmallVector<TensorShape>, float>> shapes_and_computation;
- auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W, size_t FS,
- size_t group) {
- SmallVector<TensorShape> shapes{
- {N, IC, H, W},
- {OC / group, IC / group, FS, FS},
- {1, OC, 1, 1},
- {},
- {N, OC, H, W}};
- TensorShape dst{N, OC, H, W};
- float computations = ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
- dst.total_nr_elems()) *
- 1e-6;
- shapes_and_computation.push_back(std::make_pair(shapes, computations));
- };
-
- bench_case(1, 32, 32, 200, 200, 3, 1);
- bench_case(1, 32, 32, 200, 200, 3, 1);
- bench_case(1, 32, 32, 128, 128, 3, 1);
- bench_case(1, 32, 32, 128, 128, 3, 1);
- bench_case(1, 32, 32, 100, 100, 3, 1);
- bench_case(1, 32, 32, 100, 100, 3, 1);
- bench_case(1, 32, 32, 80, 80, 3, 1);
- bench_case(1, 32, 32, 80, 80, 3, 1);
-
- bench_case(1, 64, 32, 7, 7, 3, 1);
- bench_case(1, 64, 64, 7, 7, 3, 1);
- bench_case(1, 64, 128, 7, 7, 3, 1);
- bench_case(1, 64, 256, 7, 7, 3, 1);
- bench_case(1, 64, 512, 7, 7, 3, 1);
- bench_case(1, 64, 1024, 7, 7, 3, 1);
-
- bench_case(1, 64, 32, 14, 14, 3, 1);
- bench_case(1, 64, 64, 14, 14, 3, 1);
- bench_case(1, 64, 128, 14, 14, 3, 1);
- bench_case(1, 64, 256, 14, 14, 3, 1);
- bench_case(1, 64, 512, 14, 14, 3, 1);
-
- bench_case(1, 64, 1024, 14, 14, 3, 1);
- bench_case(1, 128, 128, 14, 14, 3, 1);
- bench_case(1, 128, 256, 14, 14, 3, 1);
- bench_case(1, 512, 512, 14, 14, 3, 1);
- bench_case(1, 256, 512, 14, 14, 3, 1);
- bench_case(1, 512, 1024, 14, 14, 3, 1);
- bench_case(1, 1024, 1024, 14, 14, 3, 1);
-
- std::string algo_name = "IM2COLMATMUL:X86_F32_6x16:192";
- printf("Benchmark IM2COLMATMUL:X86_F32_6x16 algo\n");
- benchmark_impl(
- param, shapes_and_computation, algo_name, RUNS, {4, {4, 5, 6, 7}}, {1, {4}},
- data_type);
- benchmark_impl(
- param, shapes_and_computation, algo_name, RUNS, {4, {4, 5, 6, 7}}, {1, {7}},
- data_type);
- benchmark_impl(
- param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}}, {1, {4}},
- data_type);
- shapes_and_computation.clear();
- }
-
- TEST_F(X86_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_IM2COL_F32_6X16_single_thread) {
- constexpr size_t RUNS = 50;
-
- param::ConvBias param;
- param.nonlineMode = param::ConvBias::NonlineMode::RELU;
- param.pad_h = 1;
- param.pad_w = 1;
- param.stride_h = 1;
- param.stride_w = 1;
-
- std::vector<DType> data_type = {
- dtype::Float32(), dtype::Float32(), dtype::Float32(), dtype::Float32()};
- std::vector<std::pair<SmallVector<TensorShape>, float>> shapes_and_computation;
- auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W, size_t FS,
- size_t group) {
- SmallVector<TensorShape> shapes{
- {N, IC, H, W},
- {OC / group, IC / group, FS, FS},
- {1, OC, 1, 1},
- {},
- {N, OC, H, W}};
- TensorShape dst{N, OC, H, W};
- float computations = ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
- dst.total_nr_elems()) *
- 1e-6;
- shapes_and_computation.push_back(std::make_pair(shapes, computations));
- };
-
- bench_case(1, 32, 32, 200, 200, 3, 1);
- bench_case(1, 32, 32, 200, 200, 3, 1);
- bench_case(1, 32, 32, 128, 128, 3, 1);
- bench_case(1, 32, 32, 128, 128, 3, 1);
- bench_case(1, 32, 32, 100, 100, 3, 1);
- bench_case(1, 32, 32, 100, 100, 3, 1);
- bench_case(1, 32, 32, 80, 80, 3, 1);
- bench_case(1, 32, 32, 80, 80, 3, 1);
-
- bench_case(1, 64, 32, 7, 7, 3, 1);
- bench_case(1, 64, 64, 7, 7, 3, 1);
- bench_case(1, 64, 128, 7, 7, 3, 1);
- bench_case(1, 64, 256, 7, 7, 3, 1);
- bench_case(1, 64, 512, 7, 7, 3, 1);
- bench_case(1, 64, 1024, 7, 7, 3, 1);
-
- bench_case(1, 64, 32, 14, 14, 3, 1);
- bench_case(1, 64, 64, 14, 14, 3, 1);
- bench_case(1, 64, 128, 14, 14, 3, 1);
- bench_case(1, 64, 256, 14, 14, 3, 1);
- bench_case(1, 64, 512, 14, 14, 3, 1);
-
- bench_case(1, 64, 1024, 14, 14, 3, 1);
- bench_case(1, 128, 128, 14, 14, 3, 1);
- bench_case(1, 128, 256, 14, 14, 3, 1);
- bench_case(1, 512, 512, 14, 14, 3, 1);
- bench_case(1, 256, 512, 14, 14, 3, 1);
- bench_case(1, 512, 1024, 14, 14, 3, 1);
- bench_case(1, 1024, 1024, 14, 14, 3, 1);
-
- std::string algo_name = "IM2COLMATMUL:X86_F32_MKL_PACKA:192";
- std::string algo_name1 = "IM2COLMATMUL:X86_F32_6x16:192";
- printf("Benchmark IM2COLMATMUL:X86_F32_6x16 algo\n");
- benchmark_impl_comp(
- param, shapes_and_computation, algo_name, algo_name1, RUNS, {1, {4}},
- {1, {4}}, data_type);
- benchmark_impl_comp(
- param, shapes_and_computation, algo_name, algo_name1, RUNS, {1, {7}},
- {1, {7}}, data_type);
- shapes_and_computation.clear();
- }
-
- TEST_F(X86_BENCHMARK_MULTI_THREADS, BENCHMARK_CONVBIAS_IM2COL_INT8X8X32) {
- constexpr size_t RUNS = 50;
-
- param::ConvBias param;
- param.pad_h = 1;
- param.pad_w = 1;
- param.stride_h = 1;
- param.stride_w = 1;
-
- std::vector<std::pair<SmallVector<TensorShape>, float>> shapes_and_computation;
- auto bench_case = [&](size_t N, size_t IC, size_t OC, size_t H, size_t W, size_t FS,
- size_t group) {
- SmallVector<TensorShape> shapes{
- {N, IC, H, W},
- {OC / group, IC / group, FS, FS},
- {1, OC, 1, 1},
- {},
- {N, OC, H, W}};
- TensorShape dst{N, OC, H, W};
- float computations = ((IC / group) * FS * FS * dst.total_nr_elems() * 2 +
- dst.total_nr_elems()) *
- 1e-6;
- shapes_and_computation.push_back(std::make_pair(shapes, computations));
- };
-
- bench_case(1, 32, 32, 200, 200, 3, 1);
- bench_case(1, 32, 32, 200, 200, 3, 1);
- bench_case(1, 32, 32, 128, 128, 3, 1);
- bench_case(1, 32, 32, 128, 128, 3, 1);
- bench_case(1, 32, 32, 100, 100, 3, 1);
- bench_case(1, 32, 32, 100, 100, 3, 1);
- bench_case(1, 32, 32, 80, 80, 3, 1);
- bench_case(1, 32, 32, 80, 80, 3, 1);
-
- bench_case(1, 64, 32, 7, 7, 3, 1);
- bench_case(1, 64, 64, 7, 7, 3, 1);
- bench_case(1, 64, 128, 7, 7, 3, 1);
- bench_case(1, 64, 256, 7, 7, 3, 1);
- bench_case(1, 64, 512, 7, 7, 3, 1);
- bench_case(1, 64, 1024, 7, 7, 3, 1);
-
- bench_case(1, 64, 32, 14, 14, 3, 1);
- bench_case(1, 64, 64, 14, 14, 3, 1);
- bench_case(1, 64, 128, 14, 14, 3, 1);
- bench_case(1, 64, 256, 14, 14, 3, 1);
- bench_case(1, 64, 512, 14, 14, 3, 1);
-
- bench_case(1, 64, 1024, 14, 14, 3, 1);
- bench_case(1, 128, 128, 14, 14, 3, 1);
- bench_case(1, 128, 256, 14, 14, 3, 1);
- bench_case(1, 512, 512, 14, 14, 3, 1);
- bench_case(1, 256, 512, 14, 14, 3, 1);
- bench_case(1, 512, 1024, 14, 14, 3, 1);
- bench_case(1, 1024, 1024, 14, 14, 3, 1);
-
- std::vector<DType> data_type = {
- dtype::Int8(), dtype::Int8(), dtype::Int32(), dtype::Int32()};
- std::string algo_name = "IM2COLMATMUL:X86_INT8X8X32_AVX2_4X16X2:192";
- // std::string algo_name = "IM2COLMATMUL:X86_INT8X8X32_AVX2_2X4X16";
- // printf("Benchmark IM2COLMATMUL:X86_INT8X8X32_AVX2_4X16X2 algo\n");
- benchmark_impl(
- param, shapes_and_computation, algo_name, RUNS, {4, {4, 5, 6, 7}}, {1, {4}},
- data_type);
- benchmark_impl(
- param, shapes_and_computation, algo_name, RUNS, {4, {4, 5, 6, 7}}, {1, {7}},
- data_type);
- benchmark_impl(
- param, shapes_and_computation, algo_name, RUNS, {2, {4, 5}}, {1, {4}},
- data_type);
- shapes_and_computation.clear();
- }
-
- namespace {
- std::vector<conv_bias::TestArg> get_winograd_benchmark_args(
- size_t kernel, size_t pack_size) {
- std::vector<conv_bias::TestArg> args;
- auto pack = [&](size_t oc, size_t ic, size_t w, size_t h, size_t kernel, size_t p) {
- if (ic % pack_size != 0 || oc % pack_size != 0)
- return;
- if (w + 2 * p < kernel || h + 2 * p < kernel)
- return;
-
- param::ConvBias param;
- param.mode = param::ConvBias::Mode::CROSS_CORRELATION;
- param.format = param::ConvBias::Format::NCHW88;
- param.sparse = param::ConvBias::Sparse::DENSE;
- param.nonlineMode = param::ConvBias::NonlineMode::RELU;
- param.stride_h = 1;
- param.stride_w = 1;
- param.pad_h = p;
- param.pad_w = p;
-
- args.push_back(conv_bias::TestArg{
- param,
- TensorShape{1, ic / 8, h, w, 8},
- TensorShape{oc / 8, ic / 8, kernel, kernel, 8, 8},
- {1, oc / 8, 1, 1, 8}});
- };
- for (size_t ic : {64, 128, 256}) {
- for (size_t oc : {64, 128, 256}) {
- pack(oc, ic, 56, 56, kernel, kernel / 2);
- pack(oc, ic, 14, 14, kernel, kernel / 2);
- pack(oc, ic, 28, 28, kernel, kernel / 2);
- }
- }
-
- //! conv in vgg16
- pack(512, 512, 15, 15, kernel, kernel / 2);
- pack(512, 256, 15, 15, kernel, kernel / 2);
- pack(256, 256, 29, 29, kernel, kernel / 2);
- pack(256, 128, 29, 29, kernel, kernel / 2);
- pack(128, 128, 57, 57, kernel, kernel / 2);
- pack(128, 64, 57, 57, kernel, kernel / 2);
- pack(64, 64, 56, 56, kernel, kernel / 2);
- pack(128, 128, 28, 28, kernel, kernel / 2);
- pack(512, 512, 14, 14, kernel, kernel / 2);
- return args;
- }
-
- void benchmark_winograd(
- const char* algo_name, Handle* handle, size_t kernel, size_t pack_size) {
- auto&& args = get_winograd_benchmark_args(kernel, pack_size);
- using namespace conv_bias;
- constexpr size_t RUN = 10;
- Benchmarker<ConvBias> benchmark(handle);
- benchmark.set_display(false);
- benchmark.set_times(RUN);
-
- Benchmarker<ConvBias> benchmark_winograd(handle);
- benchmark_winograd.set_display(false);
- benchmark_winograd.set_times(RUN);
-
- for (auto&& arg : args) {
- TensorLayout dst_layout;
- auto opr = handle->create_operator<ConvBias>();
- opr->param() = arg.param;
- opr->deduce_layout(
- {arg.src, dtype::Float32()}, {arg.filter, dtype::Float32()},
- {arg.bias, dtype::Float32()}, {}, dst_layout);
- //! dst.nr_elems * IC * FH * FW * 2
- float computations = dst_layout.total_nr_elems() * arg.filter[1] *
- arg.filter[2] * arg.filter[3] * 2.0 * 8.0 /
- (1024 * 1024 * 1024) * 1e3;
-
- auto used =
- benchmark.set_param(arg.param).exec({arg.src, arg.filter, {}, {}, {}}) /
- RUN;
-
- benchmark_winograd.set_param(arg.param);
- auto used_winograd = algo_benchmark<ConvBias>(
- benchmark_winograd,
- {arg.src, arg.filter, {}, {}, {}}, algo_name) /
- RUN;
-
- printf("%s %s: normal: %f ms %f Gflops winograd: %f ms %f GFlops "
- "speedup: "
- "%f\n",
- arg.src.to_string().c_str(), arg.filter.to_string().c_str(), used,
- computations / used, used_winograd, computations / used_winograd,
- used / used_winograd);
- }
- }
- } // namespace
-
- TEST_F(X86, BENCHMARK_CONVBIAS_WINOGRAD_F63_8x8) {
- benchmark_winograd("WINOGRAD:X86_F32MK8_8X8:8:6:8", handle(), 3, 8);
- }
-
- TEST_F(X86, BENCHMARK_CONVBIAS_WINOGRAD_F23_8x8) {
- benchmark_winograd("WINOGRAD:X86_F32MK8_8X8:8:2:8", handle(), 3, 8);
- }
-
- #endif
-
- } // namespace test
- } // namespace megdnn
-
- // vim: syntax=cpp.doxygen
|