mirror of https://github.com/opencv/opencv.git
Merge pull request #761 from jet47:gpu-core-refactoring
commit
2cd67cc92b
169 changed files with 1730 additions and 2019 deletions
@ -0,0 +1,143 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_CORE_GPU_PRIVATE_HPP__ |
||||
#define __OPENCV_CORE_GPU_PRIVATE_HPP__ |
||||
|
||||
#ifndef __OPENCV_BUILD |
||||
# error this is a private header which should not be used from outside of the OpenCV library |
||||
#endif |
||||
|
||||
#include "cvconfig.h" |
||||
|
||||
#include "opencv2/core/cvdef.h" |
||||
#include "opencv2/core/base.hpp" |
||||
|
||||
#ifdef HAVE_CUDA |
||||
# include <cuda.h> |
||||
# include <cuda_runtime.h> |
||||
# include <npp.h> |
||||
# include "opencv2/core/stream_accessor.hpp" |
||||
# include "opencv2/core/cuda/common.hpp" |
||||
|
||||
# define CUDART_MINIMUM_REQUIRED_VERSION 4020 |
||||
|
||||
# if (CUDART_VERSION < CUDART_MINIMUM_REQUIRED_VERSION) |
||||
# error "Insufficient Cuda Runtime library version, please update it." |
||||
# endif |
||||
|
||||
# if defined(CUDA_ARCH_BIN_OR_PTX_10) |
||||
# error "OpenCV GPU module doesn't support NVIDIA compute capability 1.0" |
||||
# endif |
||||
#endif |
||||
|
||||
namespace cv { namespace gpu { |
||||
CV_EXPORTS cv::String getNppErrorMessage(int code); |
||||
CV_EXPORTS cv::String getCudaDriverApiErrorMessage(int code); |
||||
|
||||
// Converts CPU border extrapolation mode into GPU internal analogue.
|
||||
// Returns true if the GPU analogue exists, false otherwise.
|
||||
CV_EXPORTS bool tryConvertToGpuBorderType(int cpuBorderType, int& gpuBorderType); |
||||
}} |
||||
|
||||
#ifndef HAVE_CUDA |
||||
|
||||
static inline void throw_no_cuda() { CV_Error(cv::Error::GpuNotSupported, "The library is compiled without GPU support"); } |
||||
|
||||
#else // HAVE_CUDA
|
||||
|
||||
static inline void throw_no_cuda() { CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform"); } |
||||
|
||||
namespace cv { namespace gpu |
||||
{ |
||||
static inline void checkNppError(int code, const char* file, const int line, const char* func) |
||||
{ |
||||
if (code < 0) |
||||
cv::error(cv::Error::GpuApiCallError, getNppErrorMessage(code), func, file, line); |
||||
} |
||||
|
||||
static inline void checkCudaDriverApiError(int code, const char* file, const int line, const char* func) |
||||
{ |
||||
if (code != CUDA_SUCCESS) |
||||
cv::error(cv::Error::GpuApiCallError, getCudaDriverApiErrorMessage(code), func, file, line); |
||||
} |
||||
|
||||
template<int n> struct NPPTypeTraits; |
||||
template<> struct NPPTypeTraits<CV_8U> { typedef Npp8u npp_type; }; |
||||
template<> struct NPPTypeTraits<CV_8S> { typedef Npp8s npp_type; }; |
||||
template<> struct NPPTypeTraits<CV_16U> { typedef Npp16u npp_type; }; |
||||
template<> struct NPPTypeTraits<CV_16S> { typedef Npp16s npp_type; }; |
||||
template<> struct NPPTypeTraits<CV_32S> { typedef Npp32s npp_type; }; |
||||
template<> struct NPPTypeTraits<CV_32F> { typedef Npp32f npp_type; }; |
||||
template<> struct NPPTypeTraits<CV_64F> { typedef Npp64f npp_type; }; |
||||
|
||||
class NppStreamHandler |
||||
{ |
||||
public: |
||||
inline explicit NppStreamHandler(cudaStream_t newStream) |
||||
{ |
||||
oldStream = nppGetStream(); |
||||
nppSetStream(newStream); |
||||
} |
||||
|
||||
inline ~NppStreamHandler() |
||||
{ |
||||
nppSetStream(oldStream); |
||||
} |
||||
|
||||
private: |
||||
cudaStream_t oldStream; |
||||
}; |
||||
}} |
||||
|
||||
#if defined(__GNUC__) |
||||
#define nppSafeCall(expr) cv::gpu::checkNppError(expr, __FILE__, __LINE__, __func__) |
||||
#define cuSafeCall(expr) cv::gpu::checkCudaDriverApiError(expr, __FILE__, __LINE__, __func__) |
||||
#else /* defined(__CUDACC__) || defined(__MSVC__) */ |
||||
#define nppSafeCall(expr) cv::gpu::checkNppError(expr, __FILE__, __LINE__, "") |
||||
#define cuSafeCall(expr) cv::gpu::checkCudaDriverApiError(expr, __FILE__, __LINE__, "") |
||||
#endif |
||||
|
||||
#endif // HAVE_CUDA
|
||||
|
||||
#endif // __OPENCV_CORE_GPU_PRIVATE_HPP__
|
@ -1,67 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_GPU_GPU_DEVICE_STATIC_CHECK_HPP__ |
||||
#define __OPENCV_GPU_GPU_DEVICE_STATIC_CHECK_HPP__ |
||||
|
||||
#if defined(__CUDACC__) |
||||
#define __OPENCV_GPU_HOST_DEVICE__ __host__ __device__ __forceinline__ |
||||
#else |
||||
#define __OPENCV_GPU_HOST_DEVICE__ |
||||
#endif |
||||
|
||||
namespace cv { namespace gpu |
||||
{ |
||||
namespace device |
||||
{ |
||||
template<bool expr> struct Static {}; |
||||
|
||||
template<> struct Static<true> |
||||
{ |
||||
__OPENCV_GPU_HOST_DEVICE__ static void check() {}; |
||||
}; |
||||
} |
||||
}} |
||||
|
||||
#undef __OPENCV_GPU_HOST_DEVICE__ |
||||
|
||||
#endif /* __OPENCV_GPU_GPU_DEVICE_STATIC_CHECK_HPP__ */ |
@ -1,137 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "cu_safe_call.h" |
||||
|
||||
#ifdef HAVE_CUDA |
||||
|
||||
namespace |
||||
{ |
||||
#define error_entry(entry) { entry, #entry } |
||||
|
||||
struct ErrorEntry |
||||
{ |
||||
int code; |
||||
const char* str; |
||||
}; |
||||
|
||||
class ErrorEntryComparer |
||||
{ |
||||
public: |
||||
inline ErrorEntryComparer(int code) : code_(code) {} |
||||
|
||||
inline bool operator()(const ErrorEntry& e) const { return e.code == code_; } |
||||
|
||||
private: |
||||
int code_; |
||||
}; |
||||
|
||||
cv::String getErrorString(int code, const ErrorEntry* errors, size_t n) |
||||
{ |
||||
size_t idx = std::find_if(errors, errors + n, ErrorEntryComparer(code)) - errors; |
||||
|
||||
const char* msg = (idx != n) ? errors[idx].str : "Unknown error code"; |
||||
cv::String str = cv::format("%s [Code = %d]", msg, code); |
||||
|
||||
return str; |
||||
} |
||||
|
||||
const ErrorEntry cu_errors [] = |
||||
{ |
||||
error_entry( CUDA_SUCCESS ), |
||||
error_entry( CUDA_ERROR_INVALID_VALUE ), |
||||
error_entry( CUDA_ERROR_OUT_OF_MEMORY ), |
||||
error_entry( CUDA_ERROR_NOT_INITIALIZED ), |
||||
error_entry( CUDA_ERROR_DEINITIALIZED ), |
||||
error_entry( CUDA_ERROR_PROFILER_DISABLED ), |
||||
error_entry( CUDA_ERROR_PROFILER_NOT_INITIALIZED ), |
||||
error_entry( CUDA_ERROR_PROFILER_ALREADY_STARTED ), |
||||
error_entry( CUDA_ERROR_PROFILER_ALREADY_STOPPED ), |
||||
error_entry( CUDA_ERROR_NO_DEVICE ), |
||||
error_entry( CUDA_ERROR_INVALID_DEVICE ), |
||||
error_entry( CUDA_ERROR_INVALID_IMAGE ), |
||||
error_entry( CUDA_ERROR_INVALID_CONTEXT ), |
||||
error_entry( CUDA_ERROR_CONTEXT_ALREADY_CURRENT ), |
||||
error_entry( CUDA_ERROR_MAP_FAILED ), |
||||
error_entry( CUDA_ERROR_UNMAP_FAILED ), |
||||
error_entry( CUDA_ERROR_ARRAY_IS_MAPPED ), |
||||
error_entry( CUDA_ERROR_ALREADY_MAPPED ), |
||||
error_entry( CUDA_ERROR_NO_BINARY_FOR_GPU ), |
||||
error_entry( CUDA_ERROR_ALREADY_ACQUIRED ), |
||||
error_entry( CUDA_ERROR_NOT_MAPPED ), |
||||
error_entry( CUDA_ERROR_NOT_MAPPED_AS_ARRAY ), |
||||
error_entry( CUDA_ERROR_NOT_MAPPED_AS_POINTER ), |
||||
error_entry( CUDA_ERROR_ECC_UNCORRECTABLE ), |
||||
error_entry( CUDA_ERROR_UNSUPPORTED_LIMIT ), |
||||
error_entry( CUDA_ERROR_CONTEXT_ALREADY_IN_USE ), |
||||
error_entry( CUDA_ERROR_INVALID_SOURCE ), |
||||
error_entry( CUDA_ERROR_FILE_NOT_FOUND ), |
||||
error_entry( CUDA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND ), |
||||
error_entry( CUDA_ERROR_SHARED_OBJECT_INIT_FAILED ), |
||||
error_entry( CUDA_ERROR_OPERATING_SYSTEM ), |
||||
error_entry( CUDA_ERROR_INVALID_HANDLE ), |
||||
error_entry( CUDA_ERROR_NOT_FOUND ), |
||||
error_entry( CUDA_ERROR_NOT_READY ), |
||||
error_entry( CUDA_ERROR_LAUNCH_FAILED ), |
||||
error_entry( CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES ), |
||||
error_entry( CUDA_ERROR_LAUNCH_TIMEOUT ), |
||||
error_entry( CUDA_ERROR_LAUNCH_INCOMPATIBLE_TEXTURING ), |
||||
error_entry( CUDA_ERROR_PEER_ACCESS_ALREADY_ENABLED ), |
||||
error_entry( CUDA_ERROR_PEER_ACCESS_NOT_ENABLED ), |
||||
error_entry( CUDA_ERROR_PRIMARY_CONTEXT_ACTIVE ), |
||||
error_entry( CUDA_ERROR_CONTEXT_IS_DESTROYED ), |
||||
error_entry( CUDA_ERROR_ASSERT ), |
||||
error_entry( CUDA_ERROR_TOO_MANY_PEERS ), |
||||
error_entry( CUDA_ERROR_HOST_MEMORY_ALREADY_REGISTERED ), |
||||
error_entry( CUDA_ERROR_HOST_MEMORY_NOT_REGISTERED ), |
||||
error_entry( CUDA_ERROR_UNKNOWN ) |
||||
}; |
||||
|
||||
const size_t cu_errors_num = sizeof(cu_errors) / sizeof(cu_errors[0]); |
||||
} |
||||
|
||||
cv::String cv::gpu::detail::cuGetErrString(CUresult res) |
||||
{ |
||||
return getErrorString(res, cu_errors, cu_errors_num); |
||||
} |
||||
|
||||
#endif // HAVE_CUDA
|
@ -1,67 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __CU_SAFE_CALL_H__ |
||||
#define __CU_SAFE_CALL_H__ |
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
#ifdef HAVE_CUDA |
||||
|
||||
namespace cv { namespace gpu { |
||||
namespace detail |
||||
{ |
||||
String cuGetErrString(CUresult res); |
||||
|
||||
inline void cuSafeCall_impl(CUresult res, const char* file, int line) |
||||
{ |
||||
if (res != CUDA_SUCCESS) |
||||
cv::error( cv::Exception(CV_GpuApiCallError, cuGetErrString(res), "unknown function", file, line) ); |
||||
} |
||||
} |
||||
}} |
||||
|
||||
#define cuSafeCall( op ) cv::gpu::detail::cuSafeCall_impl( (op), __FILE__, __LINE__ ) |
||||
|
||||
#endif // HAVE_CUDA
|
||||
|
||||
#endif // __CU_SAFE_CALL_H__
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue