Merged revision(s) 8474 from trunk:
authorVladislav Vinogradov <no@email>
Mon, 28 May 2012 14:04:39 +0000 (14:04 +0000)
committerVladislav Vinogradov <no@email>
Mon, 28 May 2012 14:04:39 +0000 (14:04 +0000)
fixed several problems with CUDA 5.0
* gpu::LUT, uses device memory instead of host memory
* gpu::multiply, round mod for CV_8U depth
........

modules/gpu/src/arithm.cpp
modules/gpu/src/element_operations.cpp
modules/gpu/test/test_core.cpp
modules/gpu/test/test_gpumat.cpp

index 4eb9587..2a0dfee 100644 (file)
@@ -320,12 +320,23 @@ void cv::gpu::LUT(const GpuMat& src, const Mat& lut, GpuMat& dst, Stream& s)
         const Npp32s* pLevels3[3];\r
         int nValues3[3];\r
 \r
+#if (CUDA_VERSION > 4020)\r
+        GpuMat d_pLevels;\r
+#endif\r
+\r
         LevelsInit()\r
         {\r
             nValues3[0] = nValues3[1] = nValues3[2] = 256;\r
             for (int i = 0; i < 256; ++i)\r
                 pLevels[i] = i;\r
+\r
+\r
+#if (CUDA_VERSION <= 4020)\r
             pLevels3[0] = pLevels3[1] = pLevels3[2] = pLevels;\r
+#else\r
+            d_pLevels.upload(Mat(1, 256, CV_32S, pLevels));\r
+            pLevels3[0] = pLevels3[1] = pLevels3[2] = d_pLevels.ptr<Npp32s>();\r
+#endif\r
         }\r
     };\r
     static LevelsInit lvls;\r
@@ -350,22 +361,48 @@ void cv::gpu::LUT(const GpuMat& src, const Mat& lut, GpuMat& dst, Stream& s)
 \r
     if (src.type() == CV_8UC1)\r
     {\r
+#if (CUDA_VERSION <= 4020)\r
         nppSafeCall( nppiLUT_Linear_8u_C1R(src.ptr<Npp8u>(), static_cast<int>(src.step),\r
             dst.ptr<Npp8u>(), static_cast<int>(dst.step), sz, nppLut.ptr<Npp32s>(), lvls.pLevels, 256) );\r
+#else\r
+        GpuMat d_nppLut(Mat(1, 256, CV_32S, nppLut.data));\r
+        nppSafeCall( nppiLUT_Linear_8u_C1R(src.ptr<Npp8u>(), static_cast<int>(src.step),\r
+            dst.ptr<Npp8u>(), static_cast<int>(dst.step), sz, d_nppLut.ptr<Npp32s>(), lvls.d_pLevels.ptr<Npp32s>(), 256) );\r
+#endif\r
     }\r
     else\r
     {\r
-        Mat nppLut3[3];\r
         const Npp32s* pValues3[3];\r
+\r
+        Mat nppLut3[3];\r
         if (nppLut.channels() == 1)\r
+        {\r
+#if (CUDA_VERSION <= 4020)\r
             pValues3[0] = pValues3[1] = pValues3[2] = nppLut.ptr<Npp32s>();\r
+#else\r
+            GpuMat d_nppLut(Mat(1, 256, CV_32S, nppLut.data));\r
+            pValues3[0] = pValues3[1] = pValues3[2] = d_nppLut.ptr<Npp32s>();\r
+#endif\r
+        }\r
         else\r
         {\r
             cv::split(nppLut, nppLut3);\r
+\r
+#if (CUDA_VERSION <= 4020)\r
             pValues3[0] = nppLut3[0].ptr<Npp32s>();\r
             pValues3[1] = nppLut3[1].ptr<Npp32s>();\r
             pValues3[2] = nppLut3[2].ptr<Npp32s>();\r
+#else\r
+            GpuMat d_nppLut0(Mat(1, 256, CV_32S, nppLut3[0].data));\r
+            GpuMat d_nppLut1(Mat(1, 256, CV_32S, nppLut3[1].data));\r
+            GpuMat d_nppLut2(Mat(1, 256, CV_32S, nppLut3[2].data));\r
+\r
+            pValues3[0] = d_nppLut0.ptr<Npp32s>();\r
+            pValues3[1] = d_nppLut1.ptr<Npp32s>();\r
+            pValues3[2] = d_nppLut2.ptr<Npp32s>();\r
+#endif\r
         }\r
+\r
         nppSafeCall( nppiLUT_Linear_8u_C3R(src.ptr<Npp8u>(), static_cast<int>(src.step),\r
             dst.ptr<Npp8u>(), static_cast<int>(dst.step), sz, pValues3, lvls.pLevels3, lvls.nValues3) );\r
     }\r
index c614af8..8c07376 100644 (file)
@@ -657,7 +657,11 @@ void cv::gpu::multiply(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, doub
 \r
         dst.create(src1.size(), CV_MAKE_TYPE(CV_MAT_DEPTH(dtype), src1.channels()));\r
 \r
+#if (CUDA_VERSION <= 4020)\r
         if (scale == 1 && dst.type() == src1.type() && src1.depth() <= CV_32F)\r
+#else\r
+        if (scale == 1 && dst.type() == src1.type() && src1.depth() <= CV_32F && src1.depth() > CV_8U)\r
+#endif\r
         {\r
             npp_funcs[src1.depth()](src1.reshape(1), src2.reshape(1), dst.reshape(1), stream);\r
             return;\r
index d0a4634..06b9fa3 100644 (file)
@@ -1189,18 +1189,18 @@ INSTANTIATE_TEST_CASE_P(GPU_Core, AbsDiff, testing::Combine(
 ////////////////////////////////////////////////////////////////////////////////\r
 // Abs\r
 \r
-PARAM_TEST_CASE(Abs, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi)\r
+PARAM_TEST_CASE(Abs, cv::gpu::DeviceInfo, cv::Size, MatDepth, UseRoi)\r
 {\r
     cv::gpu::DeviceInfo devInfo;\r
     cv::Size size;\r
-    int type;\r
+    int depth;\r
     bool useRoi;\r
 \r
     virtual void SetUp()\r
     {\r
         devInfo = GET_PARAM(0);\r
         size = GET_PARAM(1);\r
-        type = GET_PARAM(2);\r
+        depth = GET_PARAM(2);\r
         useRoi = GET_PARAM(3);\r
 \r
         cv::gpu::setDevice(devInfo.deviceID());\r
@@ -1209,9 +1209,9 @@ PARAM_TEST_CASE(Abs, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi)
 \r
 TEST_P(Abs, Accuracy)\r
 {\r
-    cv::Mat src = randomMat(size, type);\r
+    cv::Mat src = randomMat(size, depth);\r
 \r
-    cv::gpu::GpuMat dst = createMat(size, type, useRoi);\r
+    cv::gpu::GpuMat dst = createMat(size, depth, useRoi);\r
     cv::gpu::abs(loadMat(src, useRoi), dst);\r
 \r
     cv::Mat dst_gold = cv::abs(src);\r
@@ -1222,24 +1222,24 @@ TEST_P(Abs, Accuracy)
 INSTANTIATE_TEST_CASE_P(GPU_Core, Abs, testing::Combine(\r
     ALL_DEVICES,\r
     DIFFERENT_SIZES,\r
-    testing::Values(MatType(CV_16SC1), MatType(CV_32FC1)),\r
+    testing::Values(MatDepth(CV_16S), MatDepth(CV_32F)),\r
     WHOLE_SUBMAT));\r
 \r
 ////////////////////////////////////////////////////////////////////////////////\r
 // Sqr\r
 \r
-PARAM_TEST_CASE(Sqr, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi)\r
+PARAM_TEST_CASE(Sqr, cv::gpu::DeviceInfo, cv::Size, MatDepth, UseRoi)\r
 {\r
     cv::gpu::DeviceInfo devInfo;\r
     cv::Size size;\r
-    int type;\r
+    int depth;\r
     bool useRoi;\r
 \r
     virtual void SetUp()\r
     {\r
         devInfo = GET_PARAM(0);\r
         size = GET_PARAM(1);\r
-        type = GET_PARAM(2);\r
+        depth = GET_PARAM(2);\r
         useRoi = GET_PARAM(3);\r
 \r
         cv::gpu::setDevice(devInfo.deviceID());\r
@@ -1248,9 +1248,9 @@ PARAM_TEST_CASE(Sqr, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi)
 \r
 TEST_P(Sqr, Accuracy)\r
 {\r
-    cv::Mat src = randomMat(size, type);\r
+    cv::Mat src = randomMat(size, depth, 0, depth == CV_8U ? 16 : 255);\r
 \r
-    cv::gpu::GpuMat dst = createMat(size, type, useRoi);\r
+    cv::gpu::GpuMat dst = createMat(size, depth, useRoi);\r
     cv::gpu::sqr(loadMat(src, useRoi), dst);\r
 \r
     cv::Mat dst_gold;\r
@@ -1262,10 +1262,10 @@ TEST_P(Sqr, Accuracy)
 INSTANTIATE_TEST_CASE_P(GPU_Core, Sqr, testing::Combine(\r
     ALL_DEVICES,\r
     DIFFERENT_SIZES,\r
-    testing::Values(MatType(CV_8UC1),\r
-                    MatType(CV_16UC1),\r
-                    MatType(CV_16SC1),\r
-                    MatType(CV_32FC1)),\r
+    testing::Values(MatDepth(CV_8U),\r
+                    MatDepth(CV_16U),\r
+                    MatDepth(CV_16S),\r
+                    MatDepth(CV_32F)),\r
     WHOLE_SUBMAT));\r
 \r
 ////////////////////////////////////////////////////////////////////////////////\r
@@ -1295,18 +1295,18 @@ void sqrtGold(const cv::Mat& src, cv::Mat& dst)
     funcs[src.depth()](src, dst);\r
 }\r
 \r
-PARAM_TEST_CASE(Sqrt, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi)\r
+PARAM_TEST_CASE(Sqrt, cv::gpu::DeviceInfo, cv::Size, MatDepth, UseRoi)\r
 {\r
     cv::gpu::DeviceInfo devInfo;\r
     cv::Size size;\r
-    int type;\r
+    int depth;\r
     bool useRoi;\r
 \r
     virtual void SetUp()\r
     {\r
         devInfo = GET_PARAM(0);\r
         size = GET_PARAM(1);\r
-        type = GET_PARAM(2);\r
+        depth = GET_PARAM(2);\r
         useRoi = GET_PARAM(3);\r
 \r
         cv::gpu::setDevice(devInfo.deviceID());\r
@@ -1315,24 +1315,24 @@ PARAM_TEST_CASE(Sqrt, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi)
 \r
 TEST_P(Sqrt, Accuracy)\r
 {\r
-    cv::Mat src = randomMat(size, type);\r
+    cv::Mat src = randomMat(size, depth);\r
 \r
-    cv::gpu::GpuMat dst = createMat(size, type, useRoi);\r
+    cv::gpu::GpuMat dst = createMat(size, depth, useRoi);\r
     cv::gpu::sqrt(loadMat(src, useRoi), dst);\r
 \r
     cv::Mat dst_gold;\r
     sqrtGold(src, dst_gold);\r
 \r
-    EXPECT_MAT_NEAR(dst_gold, dst, 1e-5);\r
+    EXPECT_MAT_NEAR(dst_gold, dst, depth < CV_32F ? 1.0 : 1e-5);\r
 }\r
 \r
 INSTANTIATE_TEST_CASE_P(GPU_Core, Sqrt, testing::Combine(\r
     ALL_DEVICES,\r
     DIFFERENT_SIZES,\r
-    testing::Values(MatType(CV_8UC1),\r
-                    MatType(CV_16UC1),\r
-                    MatType(CV_16SC1),\r
-                    MatType(CV_32FC1)),\r
+    testing::Values(MatDepth(CV_8U),\r
+                    MatDepth(CV_16U),\r
+                    MatDepth(CV_16S),\r
+                    MatDepth(CV_32F)),\r
     WHOLE_SUBMAT));\r
 \r
 ////////////////////////////////////////////////////////////////////////////////\r
@@ -1362,18 +1362,18 @@ void logGold(const cv::Mat& src, cv::Mat& dst)
     funcs[src.depth()](src, dst);\r
 }\r
 \r
-PARAM_TEST_CASE(Log, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi)\r
+PARAM_TEST_CASE(Log, cv::gpu::DeviceInfo, cv::Size, MatDepth, UseRoi)\r
 {\r
     cv::gpu::DeviceInfo devInfo;\r
     cv::Size size;\r
-    int type;\r
+    int depth;\r
     bool useRoi;\r
 \r
     virtual void SetUp()\r
     {\r
         devInfo = GET_PARAM(0);\r
         size = GET_PARAM(1);\r
-        type = GET_PARAM(2);\r
+        depth = GET_PARAM(2);\r
         useRoi = GET_PARAM(3);\r
 \r
         cv::gpu::setDevice(devInfo.deviceID());\r
@@ -1382,24 +1382,24 @@ PARAM_TEST_CASE(Log, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi)
 \r
 TEST_P(Log, Accuracy)\r
 {\r
-    cv::Mat src = randomMat(size, type, 1.0, 255.0);\r
+    cv::Mat src = randomMat(size, depth, 1.0, 255.0);\r
 \r
-    cv::gpu::GpuMat dst = createMat(size, type, useRoi);\r
+    cv::gpu::GpuMat dst = createMat(size, depth, useRoi);\r
     cv::gpu::log(loadMat(src, useRoi), dst);\r
 \r
     cv::Mat dst_gold;\r
     logGold(src, dst_gold);\r
 \r
-    EXPECT_MAT_NEAR(dst_gold, dst, 1e-6);\r
+    EXPECT_MAT_NEAR(dst_gold, dst, depth < CV_32F ? 1.0 : 1e-6);\r
 }\r
 \r
 INSTANTIATE_TEST_CASE_P(GPU_Core, Log, testing::Combine(\r
     ALL_DEVICES,\r
     DIFFERENT_SIZES,\r
-    testing::Values(MatType(CV_8UC1),\r
-                    MatType(CV_16UC1),\r
-                    MatType(CV_16SC1),\r
-                    MatType(CV_32FC1)),\r
+    testing::Values(MatDepth(CV_8U),\r
+                    MatDepth(CV_16U),\r
+                    MatDepth(CV_16S),\r
+                    MatDepth(CV_32F)),\r
     WHOLE_SUBMAT));\r
 \r
 ////////////////////////////////////////////////////////////////////////////////\r
@@ -1439,18 +1439,18 @@ void expGold(const cv::Mat& src, cv::Mat& dst)
     funcs[src.depth()](src, dst);\r
 }\r
 \r
-PARAM_TEST_CASE(Exp, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi)\r
+PARAM_TEST_CASE(Exp, cv::gpu::DeviceInfo, cv::Size, MatDepth, UseRoi)\r
 {\r
     cv::gpu::DeviceInfo devInfo;\r
     cv::Size size;\r
-    int type;\r
+    int depth;\r
     bool useRoi;\r
 \r
     virtual void SetUp()\r
     {\r
         devInfo = GET_PARAM(0);\r
         size = GET_PARAM(1);\r
-        type = GET_PARAM(2);\r
+        depth = GET_PARAM(2);\r
         useRoi = GET_PARAM(3);\r
 \r
         cv::gpu::setDevice(devInfo.deviceID());\r
@@ -1459,24 +1459,24 @@ PARAM_TEST_CASE(Exp, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi)
 \r
 TEST_P(Exp, Accuracy)\r
 {\r
-    cv::Mat src = randomMat(size, type, 0.0, 10.0);\r
+    cv::Mat src = randomMat(size, depth, 0.0, 10.0);\r
 \r
-    cv::gpu::GpuMat dst = createMat(size, type, useRoi);\r
+    cv::gpu::GpuMat dst = createMat(size, depth, useRoi);\r
     cv::gpu::exp(loadMat(src, useRoi), dst);\r
 \r
     cv::Mat dst_gold;\r
     expGold(src, dst_gold);\r
 \r
-    EXPECT_MAT_NEAR(dst_gold, dst, 1e-2);\r
+    EXPECT_MAT_NEAR(dst_gold, dst, depth < CV_32F ? 1.0 : 1e-2);\r
 }\r
 \r
 INSTANTIATE_TEST_CASE_P(GPU_Core, Exp, testing::Combine(\r
     ALL_DEVICES,\r
     DIFFERENT_SIZES,\r
-    testing::Values(MatType(CV_8UC1),\r
-                    MatType(CV_16UC1),\r
-                    MatType(CV_16SC1),\r
-                    MatType(CV_32FC1)),\r
+    testing::Values(MatDepth(CV_8U),\r
+                    MatDepth(CV_16U),\r
+                    MatDepth(CV_16S),\r
+                    MatDepth(CV_32F)),\r
     WHOLE_SUBMAT));\r
 \r
 ////////////////////////////////////////////////////////////////////////////////\r
index 8457b71..4dd419a 100644 (file)
@@ -311,7 +311,7 @@ TEST_P(ConvertTo, WithScaling)
         cv::Mat dst_gold;\r
         src.convertTo(dst_gold, depth2, a, b);\r
 \r
-        EXPECT_MAT_NEAR(dst_gold, dst, depth2 < CV_32F ? 0.0 : 1e-4);\r
+        EXPECT_MAT_NEAR(dst_gold, dst, depth2 < CV_32F ? 1.0 : 1e-4);\r
     }\r
 }\r
 \r