mirror of
https://github.com/opencv/opencv.git
synced 2024-11-28 21:20:18 +08:00
Merge pull request #3604 from asmorkalov:ocv_samples_package
This commit is contained in:
commit
396f7e1a17
@ -64,7 +64,7 @@ set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://opencv.org")
|
||||
|
||||
#depencencies
|
||||
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS TRUE)
|
||||
set(CPACK_COMPONENT_samples_DEPENDS libs)
|
||||
set(CPACK_COMPONENT_samples_DEPENDS libs dev)
|
||||
set(CPACK_COMPONENT_dev_DEPENDS libs)
|
||||
set(CPACK_COMPONENT_docs_DEPENDS libs)
|
||||
set(CPACK_COMPONENT_java_DEPENDS libs)
|
||||
|
@ -19,6 +19,9 @@ if(ANDROID AND BUILD_ANDROID_EXAMPLES)
|
||||
add_subdirectory(android)
|
||||
endif()
|
||||
|
||||
install(FILES "CMakeLists.txt"
|
||||
DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}
|
||||
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples)
|
||||
|
||||
#
|
||||
# END OF BUILD CASE 1: Build samples with library sources
|
||||
@ -60,7 +63,7 @@ endif()
|
||||
add_subdirectory(c)
|
||||
add_subdirectory(cpp)
|
||||
add_subdirectory(ocl)
|
||||
# FIXIT: can't use cvconfig.h in samples: add_subdirectory(gpu)
|
||||
add_subdirectory(gpu)
|
||||
|
||||
#
|
||||
# END OF BUILD CASE 2: Build samples with library binaries
|
||||
|
@ -51,8 +51,8 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
if (INSTALL_C_EXAMPLES AND NOT WIN32)
|
||||
file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd )
|
||||
if (OCV_DEPENDENCIES_FOUND AND INSTALL_C_EXAMPLES AND NOT WIN32)
|
||||
file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd *.txt)
|
||||
install(FILES ${C_SAMPLES}
|
||||
DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/c
|
||||
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples)
|
||||
|
@ -2,13 +2,6 @@
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef HAVE_CVCONFIG_H
|
||||
#include <cvconfig.h>
|
||||
#endif
|
||||
#ifdef HAVE_TBB
|
||||
#include "tbb/task_scheduler_init.h"
|
||||
#endif
|
||||
|
||||
using namespace cv;
|
||||
|
||||
static void help()
|
||||
@ -31,28 +24,13 @@ static void detect_and_draw_objects( IplImage* image, CvLatentSvmDetector* detec
|
||||
CvSeq* detections = 0;
|
||||
int i = 0;
|
||||
int64 start = 0, finish = 0;
|
||||
#ifdef HAVE_TBB
|
||||
tbb::task_scheduler_init init(tbb::task_scheduler_init::deferred);
|
||||
if (numThreads > 0)
|
||||
{
|
||||
init.initialize(numThreads);
|
||||
printf("Number of threads %i\n", numThreads);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Number of threads is not correct for TBB version");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
cv::setNumThreads(numThreads);
|
||||
|
||||
start = cvGetTickCount();
|
||||
detections = cvLatentSvmDetectObjects(image, detector, storage, 0.5f, numThreads);
|
||||
finish = cvGetTickCount();
|
||||
printf("detection time = %.3f\n", (float)(finish - start) / (float)(cvGetTickFrequency() * 1000000.0));
|
||||
|
||||
#ifdef HAVE_TBB
|
||||
init.terminate();
|
||||
#endif
|
||||
for( i = 0; i < detections->total; i++ )
|
||||
{
|
||||
CvObjectDetection detection = *(CvObjectDetection*)cvGetSeqElem( detections, i );
|
||||
|
@ -90,8 +90,8 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
if (INSTALL_C_EXAMPLES AND NOT WIN32)
|
||||
file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd )
|
||||
if (OCV_DEPENDENCIES_FOUND AND INSTALL_C_EXAMPLES AND NOT WIN32)
|
||||
file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd *.txt)
|
||||
install(FILES ${C_SAMPLES}
|
||||
DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/cpp
|
||||
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples)
|
||||
|
@ -9,14 +9,6 @@
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CVCONFIG_H
|
||||
#include <cvconfig.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_TBB
|
||||
#include "tbb/task_scheduler_init.h"
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
|
@ -69,8 +69,28 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
|
||||
endif()
|
||||
ENDMACRO()
|
||||
|
||||
# remove all matching elements from the list
|
||||
MACRO(list_filterout lst regex)
|
||||
foreach(item ${${lst}})
|
||||
if(item MATCHES "${regex}")
|
||||
list(REMOVE_ITEM ${lst} "${item}")
|
||||
endif()
|
||||
endforeach()
|
||||
ENDMACRO()
|
||||
|
||||
file(GLOB all_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
|
||||
|
||||
if(NOT HAVE_OPENGL)
|
||||
list(REMOVE_ITEM all_samples "opengl.cpp")
|
||||
endif()
|
||||
|
||||
if(NOT HAVE_CUDA)
|
||||
list(REMOVE_ITEM all_samples "opticalflow_nvidia_api.cpp")
|
||||
list(REMOVE_ITEM all_samples "cascadeclassifier_nvidia_api.cpp")
|
||||
list(REMOVE_ITEM all_samples "driver_api_multi.cpp")
|
||||
list(REMOVE_ITEM all_samples "driver_api_stereo_multi.cpp")
|
||||
endif()
|
||||
|
||||
foreach(sample_filename ${all_samples})
|
||||
get_filename_component(sample ${sample_filename} NAME_WE)
|
||||
file(GLOB sample_srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${sample}.*)
|
||||
@ -80,8 +100,17 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
|
||||
include("performance/CMakeLists.txt")
|
||||
endif()
|
||||
|
||||
if (INSTALL_C_EXAMPLES AND NOT WIN32)
|
||||
file(GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd )
|
||||
if (OCV_DEPENDENCIES_FOUND AND INSTALL_C_EXAMPLES AND NOT WIN32)
|
||||
file(GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd *.txt)
|
||||
if(NOT HAVE_OPENGL)
|
||||
list_filterout(install_list ".*opengl.cpp")
|
||||
endif()
|
||||
if(NOT HAVE_CUDA)
|
||||
list_filterout(install_list ".*opticalflow_nvidia_api.cpp")
|
||||
list_filterout(install_list ".*cascadeclassifier_nvidia_api.cpp")
|
||||
list_filterout(install_list ".*driver_api_multi.cpp")
|
||||
list_filterout(install_list ".*driver_api_stereo_multi.cpp")
|
||||
endif()
|
||||
install(FILES ${install_list}
|
||||
DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/gpu
|
||||
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples)
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include <string>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "cvconfig.h"
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/gpu/gpu.hpp"
|
||||
|
@ -2,39 +2,24 @@
|
||||
#pragma warning( disable : 4201 4408 4127 4100)
|
||||
#endif
|
||||
|
||||
#include "cvconfig.h"
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <cstdio>
|
||||
#include "opencv2/gpu/gpu.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
#include "NCVHaarObjectDetection.hpp"
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
|
||||
#if !defined(HAVE_CUDA) || defined(__arm__)
|
||||
|
||||
int main( int, const char** )
|
||||
{
|
||||
#if !defined(HAVE_CUDA)
|
||||
std::cout << "CUDA support is required (CMake key 'WITH_CUDA' must be true)." << std::endl;
|
||||
#endif
|
||||
|
||||
#if defined(__arm__)
|
||||
int main()
|
||||
{
|
||||
std::cout << "Unsupported for ARM CUDA library." << std::endl;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
|
||||
const Size2i preferredVideoFrameSize(640, 480);
|
||||
const string wndTitle = "NVIDIA Computer Vision :: Haar Classifiers Cascade";
|
||||
|
||||
@ -386,4 +371,4 @@ int main(int argc, const char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif //!defined(HAVE_CUDA)
|
||||
#endif
|
||||
|
@ -7,56 +7,101 @@
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include "cvconfig.h"
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/gpu/gpu.hpp"
|
||||
|
||||
#if !defined(HAVE_CUDA) || !defined(HAVE_TBB) || defined(__arm__)
|
||||
|
||||
#if defined(__arm__)
|
||||
int main()
|
||||
{
|
||||
#if !defined(HAVE_CUDA)
|
||||
std::cout << "CUDA support is required (CMake key 'WITH_CUDA' must be true).\n";
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_TBB)
|
||||
std::cout << "TBB support is required (CMake key 'WITH_TBB' must be true).\n";
|
||||
#endif
|
||||
|
||||
#if defined(__arm__)
|
||||
std::cout << "Unsupported for ARM CUDA library." << std::endl;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <cuda.h>
|
||||
#include <cuda_runtime.h>
|
||||
#include "opencv2/core/internal.hpp" // For TBB wrappers
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::gpu;
|
||||
|
||||
struct Worker { void operator()(int device_id) const; };
|
||||
void destroyContexts();
|
||||
|
||||
#define safeCall(expr) safeCall_(expr, #expr, __FILE__, __LINE__)
|
||||
inline void safeCall_(int code, const char* expr, const char* file, int line)
|
||||
{
|
||||
if (code != CUDA_SUCCESS)
|
||||
{
|
||||
std::cout << "CUDA driver API error: code " << code << ", expr " << expr
|
||||
<< ", file " << file << ", line " << line << endl;
|
||||
destroyContexts();
|
||||
<< ", file " << file << ", line " << line << endl;
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
// Each GPU is associated with its own context
|
||||
CUcontext contexts[2];
|
||||
struct Worker: public ParallelLoopBody
|
||||
{
|
||||
Worker(int num_devices)
|
||||
{
|
||||
count = num_devices;
|
||||
contexts = new CUcontext[num_devices];
|
||||
for (int device_id = 0; device_id < num_devices; device_id++)
|
||||
{
|
||||
CUdevice device;
|
||||
safeCall(cuDeviceGet(&device, device_id));
|
||||
safeCall(cuCtxCreate(&contexts[device_id], 0, device));
|
||||
}
|
||||
}
|
||||
|
||||
virtual void operator() (const Range& range) const
|
||||
{
|
||||
for (int device_id = range.start; device_id != range.end; ++device_id)
|
||||
{
|
||||
// Set the proper context
|
||||
safeCall(cuCtxPushCurrent(contexts[device_id]));
|
||||
|
||||
Mat src(1000, 1000, CV_32F);
|
||||
Mat dst;
|
||||
|
||||
RNG rng(0);
|
||||
rng.fill(src, RNG::UNIFORM, 0, 1);
|
||||
|
||||
// CPU works
|
||||
transpose(src, dst);
|
||||
|
||||
// GPU works
|
||||
GpuMat d_src(src);
|
||||
GpuMat d_dst;
|
||||
transpose(d_src, d_dst);
|
||||
|
||||
// Check results
|
||||
bool passed = norm(dst - Mat(d_dst), NORM_INF) < 1e-3;
|
||||
std::cout << "GPU #" << device_id << " (" << DeviceInfo().name() << "): "
|
||||
<< (passed ? "passed" : "FAILED") << endl;
|
||||
|
||||
// Deallocate data here, otherwise deallocation will be performed
|
||||
// after context is extracted from the stack
|
||||
d_src.release();
|
||||
d_dst.release();
|
||||
|
||||
CUcontext prev_context;
|
||||
safeCall(cuCtxPopCurrent(&prev_context));
|
||||
}
|
||||
}
|
||||
|
||||
~Worker()
|
||||
{
|
||||
if ((contexts != NULL) && count != 0)
|
||||
{
|
||||
for (int device_id = 0; device_id < count; device_id++)
|
||||
{
|
||||
safeCall(cuCtxDestroy(contexts[device_id]));
|
||||
}
|
||||
|
||||
delete[] contexts;
|
||||
}
|
||||
}
|
||||
|
||||
CUcontext* contexts;
|
||||
int count;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
@ -84,67 +129,10 @@ int main()
|
||||
// Init CUDA Driver API
|
||||
safeCall(cuInit(0));
|
||||
|
||||
// Create context for GPU #0
|
||||
CUdevice device;
|
||||
safeCall(cuDeviceGet(&device, 0));
|
||||
safeCall(cuCtxCreate(&contexts[0], 0, device));
|
||||
// Execute calculation
|
||||
parallel_for_(cv::Range(0, num_devices), Worker(num_devices));
|
||||
|
||||
CUcontext prev_context;
|
||||
safeCall(cuCtxPopCurrent(&prev_context));
|
||||
|
||||
// Create context for GPU #1
|
||||
safeCall(cuDeviceGet(&device, 1));
|
||||
safeCall(cuCtxCreate(&contexts[1], 0, device));
|
||||
|
||||
safeCall(cuCtxPopCurrent(&prev_context));
|
||||
|
||||
// Execute calculation in two threads using two GPUs
|
||||
int devices[] = {0, 1};
|
||||
parallel_do(devices, devices + 2, Worker());
|
||||
|
||||
destroyContexts();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void Worker::operator()(int device_id) const
|
||||
{
|
||||
// Set the proper context
|
||||
safeCall(cuCtxPushCurrent(contexts[device_id]));
|
||||
|
||||
Mat src(1000, 1000, CV_32F);
|
||||
Mat dst;
|
||||
|
||||
RNG rng(0);
|
||||
rng.fill(src, RNG::UNIFORM, 0, 1);
|
||||
|
||||
// CPU works
|
||||
transpose(src, dst);
|
||||
|
||||
// GPU works
|
||||
GpuMat d_src(src);
|
||||
GpuMat d_dst;
|
||||
transpose(d_src, d_dst);
|
||||
|
||||
// Check results
|
||||
bool passed = norm(dst - Mat(d_dst), NORM_INF) < 1e-3;
|
||||
std::cout << "GPU #" << device_id << " (" << DeviceInfo().name() << "): "
|
||||
<< (passed ? "passed" : "FAILED") << endl;
|
||||
|
||||
// Deallocate data here, otherwise deallocation will be performed
|
||||
// after context is extracted from the stack
|
||||
d_src.release();
|
||||
d_dst.release();
|
||||
|
||||
CUcontext prev_context;
|
||||
safeCall(cuCtxPopCurrent(&prev_context));
|
||||
}
|
||||
|
||||
|
||||
void destroyContexts()
|
||||
{
|
||||
safeCall(cuCtxDestroy(contexts[0]));
|
||||
safeCall(cuCtxDestroy(contexts[1]));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -8,30 +8,16 @@
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include "cvconfig.h"
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/gpu/gpu.hpp"
|
||||
|
||||
#if !defined(HAVE_CUDA) || !defined(HAVE_TBB) || defined(__arm__)
|
||||
|
||||
#if defined(__arm__)
|
||||
int main()
|
||||
{
|
||||
#if !defined(HAVE_CUDA)
|
||||
std::cout << "CUDA support is required (CMake key 'WITH_CUDA' must be true).\n";
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_TBB)
|
||||
std::cout << "TBB support is required (CMake key 'WITH_TBB' must be true).\n";
|
||||
#endif
|
||||
|
||||
#if defined(__arm__)
|
||||
std::cout << "Unsupported for ARM CUDA library." << std::endl;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <cuda.h>
|
||||
@ -42,7 +28,6 @@ using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::gpu;
|
||||
|
||||
struct Worker { void operator()(int device_id) const; };
|
||||
void destroyContexts();
|
||||
|
||||
#define safeCall(expr) safeCall_(expr, #expr, __FILE__, __LINE__)
|
||||
@ -77,6 +62,27 @@ GpuMat d_right[2];
|
||||
StereoBM_GPU* bm[2];
|
||||
GpuMat d_result[2];
|
||||
|
||||
|
||||
struct Worker: public ParallelLoopBody
|
||||
{
|
||||
virtual void operator() (const Range& range) const
|
||||
{
|
||||
for (int device_id = range.start; device_id != range.end; ++device_id)
|
||||
{
|
||||
contextOn(device_id);
|
||||
|
||||
bm[device_id]->operator()(d_left[device_id], d_right[device_id],
|
||||
d_result[device_id]);
|
||||
|
||||
std::cout << "GPU #" << device_id << " (" << DeviceInfo().name()
|
||||
<< "): finished\n";
|
||||
|
||||
contextOff();
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static void printHelp()
|
||||
{
|
||||
std::cout << "Usage: driver_api_stereo_multi_gpu --left <left_image> --right <right_image>\n";
|
||||
@ -162,8 +168,7 @@ int main(int argc, char** argv)
|
||||
contextOff();
|
||||
|
||||
// Execute calculation in two threads using two GPUs
|
||||
int devices[] = {0, 1};
|
||||
parallel_do(devices, devices + 2, Worker());
|
||||
parallel_for_(cv::Range(0, 2), Worker());
|
||||
|
||||
// Release the first GPU resources
|
||||
contextOn(0);
|
||||
@ -188,21 +193,6 @@ int main(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void Worker::operator()(int device_id) const
|
||||
{
|
||||
contextOn(device_id);
|
||||
|
||||
bm[device_id]->operator()(d_left[device_id], d_right[device_id],
|
||||
d_result[device_id]);
|
||||
|
||||
std::cout << "GPU #" << device_id << " (" << DeviceInfo().name()
|
||||
<< "): finished\n";
|
||||
|
||||
contextOff();
|
||||
}
|
||||
|
||||
|
||||
void destroyContexts()
|
||||
{
|
||||
safeCall(cuCtxDestroy(contexts[0]));
|
||||
|
@ -7,34 +7,47 @@
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include "cvconfig.h"
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/gpu/gpu.hpp"
|
||||
|
||||
#if !defined(HAVE_CUDA) || !defined(HAVE_TBB)
|
||||
|
||||
int main()
|
||||
{
|
||||
#if !defined(HAVE_CUDA)
|
||||
std::cout << "CUDA support is required (CMake key 'WITH_CUDA' must be true).\n";
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_TBB)
|
||||
std::cout << "TBB support is required (CMake key 'WITH_TBB' must be true).\n";
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/core/internal.hpp" // For TBB wrappers
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::gpu;
|
||||
|
||||
struct Worker { void operator()(int device_id) const; };
|
||||
struct Worker: public ParallelLoopBody
|
||||
{
|
||||
virtual void operator() (const Range& range) const
|
||||
{
|
||||
for (int device_id = range.start; device_id != range.end; ++device_id)
|
||||
{
|
||||
setDevice(device_id);
|
||||
|
||||
Mat src(1000, 1000, CV_32F);
|
||||
Mat dst;
|
||||
|
||||
RNG rng(0);
|
||||
rng.fill(src, RNG::UNIFORM, 0, 1);
|
||||
|
||||
// CPU works
|
||||
transpose(src, dst);
|
||||
|
||||
// GPU works
|
||||
GpuMat d_src(src);
|
||||
GpuMat d_dst;
|
||||
transpose(d_src, d_dst);
|
||||
|
||||
// Check results
|
||||
bool passed = norm(dst - Mat(d_dst), NORM_INF) < 1e-3;
|
||||
std::cout << "GPU #" << device_id << " (" << DeviceInfo().name() << "): "
|
||||
<< (passed ? "passed" : "FAILED") << endl;
|
||||
|
||||
// Deallocate data here, otherwise deallocation will be performed
|
||||
// after context is extracted from the stack
|
||||
d_src.release();
|
||||
d_dst.release();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
@ -58,41 +71,8 @@ int main()
|
||||
}
|
||||
}
|
||||
|
||||
// Execute calculation in two threads using two GPUs
|
||||
int devices[] = {0, 1};
|
||||
parallel_do(devices, devices + 2, Worker());
|
||||
// Execute calculation in several threads, 1 GPU per thread
|
||||
parallel_for_(cv::Range(0, num_devices), Worker());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void Worker::operator()(int device_id) const
|
||||
{
|
||||
setDevice(device_id);
|
||||
|
||||
Mat src(1000, 1000, CV_32F);
|
||||
Mat dst;
|
||||
|
||||
RNG rng(0);
|
||||
rng.fill(src, RNG::UNIFORM, 0, 1);
|
||||
|
||||
// CPU works
|
||||
transpose(src, dst);
|
||||
|
||||
// GPU works
|
||||
GpuMat d_src(src);
|
||||
GpuMat d_dst;
|
||||
transpose(d_src, d_dst);
|
||||
|
||||
// Check results
|
||||
bool passed = norm(dst - Mat(d_dst), NORM_INF) < 1e-3;
|
||||
std::cout << "GPU #" << device_id << " (" << DeviceInfo().name() << "): "
|
||||
<< (passed ? "passed" : "FAILED") << endl;
|
||||
|
||||
// Deallocate data here, otherwise deallocation will be performed
|
||||
// after context is extracted from the stack
|
||||
d_src.release();
|
||||
d_dst.release();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -1,13 +1,4 @@
|
||||
#include <iostream>
|
||||
#include "cvconfig.h"
|
||||
|
||||
#ifndef HAVE_OPENGL
|
||||
int main()
|
||||
{
|
||||
std::cerr << "Library was built without OpenGL support" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
|
||||
#ifdef WIN32
|
||||
#define WIN32_LEAN_AND_MEAN 1
|
||||
|
@ -9,26 +9,14 @@
|
||||
#include <ctime>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "cvconfig.h"
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include "opencv2/gpu/gpu.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
#include "NPP_staging/NPP_staging.hpp"
|
||||
#include "NCVBroxOpticalFlow.hpp"
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_CUDA)
|
||||
int main( int, const char** )
|
||||
{
|
||||
std::cout << "Please compile the library with CUDA support" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
|
||||
//using std::tr1::shared_ptr;
|
||||
using cv::Ptr;
|
||||
|
||||
#define PARAM_LEFT "--left"
|
||||
@ -649,5 +637,3 @@ int main(int argc, char **argv)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -27,7 +27,7 @@ if(WIN32)
|
||||
endif()
|
||||
|
||||
if(INSTALL_C_EXAMPLES AND NOT WIN32)
|
||||
file(GLOB GPU_FILES performance/*.cpp performance/*.h)
|
||||
file(GLOB GPU_FILES performance/*.cpp performance/*.h performance/CMakeLists.txt)
|
||||
install(FILES ${GPU_FILES}
|
||||
DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/gpu/performance
|
||||
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "cvconfig.h"
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
|
@ -51,8 +51,8 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
if (INSTALL_C_EXAMPLES AND NOT WIN32)
|
||||
file(GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd )
|
||||
if (OCV_DEPENDENCIES_FOUND AND INSTALL_C_EXAMPLES AND NOT WIN32)
|
||||
file(GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd *.txt)
|
||||
install(FILES ${install_list}
|
||||
DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/ocl
|
||||
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples)
|
||||
|
Loading…
Reference in New Issue
Block a user