From b3a261c7ceff720c609d7e4cac845798a7880d44 Mon Sep 17 00:00:00 2001 From: YashasSamaga Date: Sun, 24 May 2020 19:01:17 +0530 Subject: [PATCH] set stream at the site of creation --- modules/dnn/src/dnn.cpp | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/modules/dnn/src/dnn.cpp b/modules/dnn/src/dnn.cpp index 308da294b0..f62b1dad9f 100644 --- a/modules/dnn/src/dnn.cpp +++ b/modules/dnn/src/dnn.cpp @@ -1277,6 +1277,13 @@ struct Net::Impl } Ptr wrapper = wrapMat(preferableBackend, preferableTarget, host); +#ifdef HAVE_CUDA + if (preferableBackend == DNN_BACKEND_CUDA) + { + auto cudaWrapper = wrapper.dynamicCast(); + cudaWrapper->setStream(cudaInfo->context.stream); + } +#endif backendWrappers[data] = wrapper; return wrapper; } @@ -2414,16 +2421,7 @@ struct Net::Impl ninputs = netInputLayer->inputsData.size(); ld.inputBlobsWrappers.resize(ninputs); for (size_t i = 0; i < ninputs; i++) - { ld.inputBlobsWrappers[i] = wrap(netInputLayer->inputsData[i]); -#ifdef HAVE_CUDA - if (IS_DNN_CUDA_TARGET(preferableTarget)) - { - auto wrapper = ld.inputBlobsWrappers[i].dynamicCast(); - wrapper->setStream(cudaInfo->context.stream); - } -#endif - } } else { @@ -2449,23 +2447,12 @@ struct Net::Impl preferableTarget == DNN_TARGET_OPENCL_FP16); ld.outputBlobsWrappers.resize(ld.outputBlobs.size()); for (int i = 0; i < ld.outputBlobs.size(); ++i) - { ld.outputBlobsWrappers[i] = wrap(ld.outputBlobs[i]); -#ifdef HAVE_CUDA - if (IS_DNN_CUDA_TARGET(preferableTarget)) - { - auto wrapper = ld.outputBlobsWrappers[i].dynamicCast(); - wrapper->setStream(cudaInfo->context.stream); - } -#endif - } /* CUDA backend has its own system for internal blobs; we don't need these */ ld.internalBlobsWrappers.resize((preferableBackend == DNN_BACKEND_CUDA) ? 0 : ld.internals.size()); for (int i = 0; i < ld.internalBlobsWrappers.size(); ++i) - { ld.internalBlobsWrappers[i] = wrap(ld.internals[i]); - } Ptr layerPtr = ld.getLayerInstance(); {