Merge pull request #22656 from dkurt:halide_fixes
authorDmitry Kurtaev <dmitry.kurtaev@gmail.com>
Fri, 21 Oct 2022 14:49:49 +0000 (17:49 +0300)
committerGitHub <noreply@github.com>
Fri, 21 Oct 2022 14:49:49 +0000 (17:49 +0300)
* Fixes for Halide
* Enable some Halide tests

modules/dnn/src/halide_scheduler.cpp
modules/dnn/src/layers/pooling_layer.cpp
modules/dnn/test/test_backends.cpp

index 78335dd..679c5ab 100644 (file)
@@ -71,9 +71,17 @@ static void applyFuse(const FileNode& directive, Halide::Func& func)
 static void applyParallel(const FileNode& directive, Halide::Func& func)
 {
     std::string varName;
-    for (int i = 0, n = directive.size(); i < n; ++i)
+    if (directive.isSeq())
     {
-        directive[i] >> varName;
+        for (int i = 0, n = directive.size(); i < n; ++i)
+        {
+            directive[i] >> varName;
+            func.parallel(Halide::Var(varName));
+        }
+    }
+    else
+    {
+        directive >> varName;
         func.parallel(Halide::Var(varName));
     }
 }
@@ -81,9 +89,17 @@ static void applyParallel(const FileNode& directive, Halide::Func& func)
 static void applyUnroll(const FileNode& directive, Halide::Func& func)
 {
     std::string varName;
-    for (int i = 0, n = directive.size(); i < n; ++i)
+    if (directive.isSeq())
     {
-        directive[i] >> varName;
+        for (int i = 0, n = directive.size(); i < n; ++i)
+        {
+            directive[i] >> varName;
+            func.unroll(Halide::Var(varName));
+        }
+    }
+    else
+    {
+        directive >> varName;
         func.unroll(Halide::Var(varName));
     }
 }
index 6c584bf..9a808a7 100644 (file)
@@ -1173,6 +1173,12 @@ public:
         // Halide::argmax returns tuple (r.x, r.y, max).
         Halide::Tuple res = argmax(inputBuffer(kx, ky, c, n));
 
+        if (!computeMaxIdx)
+        {
+            top(x, y, c, n) = res[2];
+            return Ptr<BackendNode>(new HalideBackendNode(top));
+        }
+
         // Compute offset from argmax in range [0, kernel_size).
         Halide::Expr max_index;
         if(paddingLeft || paddingTop)
index 1933c11..2e1ff14 100644 (file)
@@ -101,9 +101,6 @@ public:
 TEST_P(DNNTestNetwork, AlexNet)
 {
     applyTestTag(CV_TEST_TAG_MEMORY_1GB);
-    if (backend == DNN_BACKEND_HALIDE)  // Realization contains wrong number of Images (1) for realizing pipeline with 2 outputs
-        applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
-
     processNet("dnn/bvlc_alexnet.caffemodel", "dnn/bvlc_alexnet.prototxt",
                Size(227, 227), "prob",
                target == DNN_TARGET_OPENCL ? "dnn/halide_scheduler_opencl_alexnet.yml" :
@@ -118,8 +115,6 @@ TEST_P(DNNTestNetwork, ResNet_50)
         (target == DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_512MB : CV_TEST_TAG_MEMORY_1GB),
         CV_TEST_TAG_DEBUG_LONG
     );
-    if (backend == DNN_BACKEND_HALIDE)  // Realization contains wrong number of Images (1) for realizing pipeline with 2 outputs
-        applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
 
     processNet("dnn/ResNet-50-model.caffemodel", "dnn/ResNet-50-deploy.prototxt",
                Size(224, 224), "prob",
@@ -131,9 +126,6 @@ TEST_P(DNNTestNetwork, ResNet_50)
 
 TEST_P(DNNTestNetwork, SqueezeNet_v1_1)
 {
-    if (backend == DNN_BACKEND_HALIDE)  // Realization contains wrong number of Images (1) for realizing pipeline with 2 outputs
-        applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
-
     processNet("dnn/squeezenet_v1.1.caffemodel", "dnn/squeezenet_v1.1.prototxt",
                Size(227, 227), "prob",
                target == DNN_TARGET_OPENCL ? "dnn/halide_scheduler_opencl_squeezenet_v1_1.yml" :
@@ -145,8 +137,6 @@ TEST_P(DNNTestNetwork, SqueezeNet_v1_1)
 TEST_P(DNNTestNetwork, GoogLeNet)
 {
     applyTestTag(target == DNN_TARGET_CPU ? "" : CV_TEST_TAG_MEMORY_512MB);
-    if (backend == DNN_BACKEND_HALIDE)  // Realization contains wrong number of Images (1) for realizing pipeline with 2 outputs
-        applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
 
     processNet("dnn/bvlc_googlenet.caffemodel", "dnn/bvlc_googlenet.prototxt",
                Size(224, 224), "prob");
@@ -157,8 +147,6 @@ TEST_P(DNNTestNetwork, GoogLeNet)
 TEST_P(DNNTestNetwork, Inception_5h)
 {
     applyTestTag(CV_TEST_TAG_MEMORY_512MB);
-    if (backend == DNN_BACKEND_HALIDE)  // Realization contains wrong number of Images (1) for realizing pipeline with 2 outputs
-        applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
 
     double l1 = default_l1, lInf = default_lInf;
     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && (target == DNN_TARGET_CPU || target == DNN_TARGET_OPENCL))
@@ -177,8 +165,6 @@ TEST_P(DNNTestNetwork, Inception_5h)
 TEST_P(DNNTestNetwork, ENet)
 {
     applyTestTag(target == DNN_TARGET_CPU ? "" : CV_TEST_TAG_MEMORY_512MB);
-    if (backend == DNN_BACKEND_HALIDE)  // Realization contains wrong number of Images (1) for realizing pipeline with 2 outputs
-        applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE);
 
     if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
         applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER);