Skip to content

Commit 1f465a0

Browse files
wzw-intelpli2-intel
authored andcommitted
dnn(ocl4dnn): fuseLayer() use umat_input/outputBlobs for OpenCL target
Also, fix bug when use OPENCL target but no OpenCL runtime Signed-off-by: Wu Zhiwen <zhiwen.wu@intel.com>
1 parent a47fbd2 commit 1f465a0

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

modules/dnn/src/dnn.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,8 @@ struct Net::Impl
11961196
// some other layers.
11971197

11981198
// TODO: OpenCL target support more fusion styles.
1199-
if ( preferableTarget == DNN_TARGET_OPENCL && ld.layerInstance->type.compare("Convolution") )
1199+
if ( preferableTarget == DNN_TARGET_OPENCL &&
1200+
(!cv::ocl::useOpenCL() || ld.layerInstance->type.compare("Convolution")) )
12001201
continue;
12011202

12021203
Ptr<Layer>& currLayer = ld.layerInstance;
@@ -1214,7 +1215,10 @@ struct Net::Impl
12141215
{
12151216
printf_(("\tfused with %s\n", nextBNormLayer->name.c_str()));
12161217
bnormData->skipFlags[DNN_BACKEND_DEFAULT] = true;
1217-
ld.outputBlobs = layers[lpNext.lid].outputBlobs;
1218+
if ( preferableTarget == DNN_TARGET_OPENCL )
1219+
ld.umat_outputBlobs = layers[lpNext.lid].umat_outputBlobs;
1220+
else
1221+
ld.outputBlobs = layers[lpNext.lid].outputBlobs;
12181222
if( bnormData->consumers.size() == 1 )
12191223
{
12201224
nextData = &layers[bnormData->consumers[0].lid];
@@ -1234,7 +1238,10 @@ struct Net::Impl
12341238
{
12351239
printf_(("\tfused with %s\n", nextScaleLayer->name.c_str()));
12361240
scaleData->skipFlags[DNN_BACKEND_DEFAULT] = true;
1237-
ld.outputBlobs = layers[lpNext.lid].outputBlobs;
1241+
if ( preferableTarget == DNN_TARGET_OPENCL )
1242+
ld.umat_outputBlobs = layers[lpNext.lid].umat_outputBlobs;
1243+
else
1244+
ld.outputBlobs = layers[lpNext.lid].outputBlobs;
12381245
if( scaleData->consumers.size() == 1 )
12391246
{
12401247
nextData = &layers[scaleData->consumers[0].lid];
@@ -1263,7 +1270,10 @@ struct Net::Impl
12631270
LayerData *activData = nextData;
12641271
printf_(("\tfused with %s\n", nextActivLayer->name.c_str()));
12651272
activData->skipFlags[DNN_BACKEND_DEFAULT] = true;
1266-
ld.outputBlobs = layers[lpNext.lid].outputBlobs;
1273+
if ( preferableTarget == DNN_TARGET_OPENCL )
1274+
ld.umat_outputBlobs = layers[lpNext.lid].umat_outputBlobs;
1275+
else
1276+
ld.outputBlobs = layers[lpNext.lid].outputBlobs;
12671277

12681278
if ( preferableTarget == DNN_TARGET_OPENCL )
12691279
{
@@ -1325,13 +1335,13 @@ struct Net::Impl
13251335
!nextData->type.compare("Power")) &&
13261336
currLayer->setActivation(nextActivLayer) )
13271337
{
1328-
CV_Assert(firstConvLayerData->outputBlobs.size() == 1 && ld.inputBlobs.size() == 1);
1329-
ld.inputBlobs.push_back(&firstConvLayerData->outputBlobs[0]);
1338+
CV_Assert(firstConvLayerData->umat_outputBlobs.size() == 1 && ld.umat_inputBlobs.size() == 1);
1339+
ld.umat_inputBlobs.push_back(firstConvLayerData->umat_outputBlobs[0]);
13301340
printf_(("\tfused with %s\n", nextEltwiseLayer->name.c_str()));
13311341
printf_(("\tfused with %s\n", nextActivLayer->name.c_str()));
13321342
eltwiseData->skipFlags[DNN_BACKEND_DEFAULT] = true;
13331343
nextData->skipFlags[DNN_BACKEND_DEFAULT] = true;
1334-
ld.outputBlobs = layers[lpNext.lid].outputBlobs;
1344+
ld.umat_outputBlobs = layers[lpNext.lid].umat_outputBlobs;
13351345
}
13361346
}
13371347
}

0 commit comments

Comments
 (0)