reverted wrong commit for one of gpu samples
authorAlexey Spizhevoy <no@email>
Thu, 9 Jun 2011 10:21:02 +0000 (10:21 +0000)
committerAlexey Spizhevoy <no@email>
Thu, 9 Jun 2011 10:21:02 +0000 (10:21 +0000)
samples/gpu/driver_api_stereo_multi.cpp

index ce2925b..e55132e 100644 (file)
@@ -32,11 +32,7 @@ int main()
 \r
 #include <cuda.h>\r
 #include <cuda_runtime.h>\r
-#include <GL/gl.h>\r
-#include <cudaGL.h>\r
 #include "opencv2/core/internal.hpp" // For TBB wrappers\r
-#include "tbb/tbb.h"\r
-#include "tbb/mutex.h"\r
 \r
 using namespace std;\r
 using namespace cv;\r
@@ -58,14 +54,14 @@ inline void safeCall_(int code, const char* expr, const char* file, int line)
 }\r
 \r
 // Each GPU is associated with its own context\r
-CUcontext contexts[/*2*/1];\r
+CUcontext contexts[2];\r
 \r
-void inline contextOn(int id) \r
+void inline contextOn(int id)\r
 {\r
     safeCall(cuCtxPushCurrent(contexts[id]));\r
 }\r
 \r
-void inline contextOff() \r
+void inline contextOff()\r
 {\r
     CUcontext prev_context;\r
     safeCall(cuCtxPopCurrent(&prev_context));\r
@@ -80,10 +76,6 @@ GpuMat d_result[2];
 // CPU result\r
 Mat result;\r
 \r
-int some[2];\r
-\r
-tbb::mutex mutex;\r
-\r
 int main(int argc, char** argv)\r
 {\r
     if (argc < 3)\r
@@ -93,11 +85,11 @@ int main(int argc, char** argv)
     }\r
 \r
     int num_devices = getCudaEnabledDeviceCount();\r
-//    if (num_devices < 2)\r
-//    {\r
-//        std::cout << "Two or more GPUs are required\n";\r
-//        return -1;\r
-//    }\r
+    if (num_devices < 2)\r
+    {\r
+        std::cout << "Two or more GPUs are required\n";\r
+        return -1;\r
+    }\r
 \r
     for (int i = 0; i < num_devices; ++i)\r
     {\r
@@ -131,14 +123,13 @@ int main(int argc, char** argv)
     // Create context for GPU #0\r
     CUdevice device;\r
     safeCall(cuDeviceGet(&device, 0));\r
-    safeCall(cuGLCtxCreate(&contexts[0], 0, device));\r
-    //safeCall(cuCtxCreate(&contexts[0], 0, device));\r
+    safeCall(cuCtxCreate(&contexts[0], 0, device));\r
     contextOff();\r
 \r
-//    // Create context for GPU #1\r
-//    safeCall(cuDeviceGet(&device, 0));\r
-//    safeCall(cuCtxCreate(&contexts[1], 0, device));\r
-//    contextOff();\r
+    // Create context for GPU #1\r
+    safeCall(cuDeviceGet(&device, 1));\r
+    safeCall(cuCtxCreate(&contexts[1], 0, device));\r
+    contextOff();\r
 \r
     // Split source images for processing on GPU #0\r
     contextOn(0);\r
@@ -148,20 +139,15 @@ int main(int argc, char** argv)
     contextOff();\r
 \r
     // Split source images for processing on the GPU #1\r
-    contextOn(0);\r
+    contextOn(1);\r
     d_left[1].upload(left.rowRange(left.rows / 2, left.rows));\r
     d_right[1].upload(right.rowRange(right.rows / 2, right.rows));\r
     bm[1] = new StereoBM_GPU();\r
     contextOff();\r
 \r
-    some[0] = some[1] = 0;\r
     // Execute calculation in two threads using two GPUs\r
-    vector<int> devices;\r
-    for (int i = 0; i < 4; ++i)\r
-        devices.push_back(rand()%2);\r
-    tbb::parallel_do(&devices[0], &devices[devices.size() - 1], Worker());\r
-\r
-    cout << some[0] << " " << some[1] << endl;\r
+    int devices[] = {0, 1};\r
+    parallel_do(devices, devices + 2, Worker());\r
 \r
     // Release the first GPU resources\r
     contextOn(0);\r
@@ -173,7 +159,7 @@ int main(int argc, char** argv)
     contextOff();\r
 \r
     // Release the second GPU resources\r
-    contextOn(0);\r
+    contextOn(1);\r
     imshow("GPU #1 result", Mat(d_result[1]));\r
     d_left[1].release();\r
     d_right[1].release();\r
@@ -189,9 +175,7 @@ int main(int argc, char** argv)
 \r
 void Worker::operator()(int device_id) const\r
 {\r
-    mutex.lock();\r
-\r
-    contextOn(0);\r
+    contextOn(device_id);\r
 \r
     bm[device_id]->operator()(d_left[device_id], d_right[device_id],\r
                               d_result[device_id]);\r
@@ -200,16 +184,13 @@ void Worker::operator()(int device_id) const
         << "): finished\n";\r
 \r
     contextOff();\r
-\r
-    mutex.unlock();\r
 }\r
 \r
 \r
 void destroyContexts()\r
 {\r
     safeCall(cuCtxDestroy(contexts[0]));\r
-    //safeCall(cuCtxDestroy(contexts[1]));\r
+    safeCall(cuCtxDestroy(contexts[1]));\r
 }\r
 \r
 #endif\r
-\r