ocl: code cleanup, fix .clb files

This commit is contained in:
Alexander Alekhin 2013-10-11 01:16:12 +04:00
parent ad1ba56fcf
commit 238550cdad
6 changed files with 28 additions and 59 deletions

View File

@ -83,15 +83,6 @@ namespace cv
DEVICE_MEM_PM //persistent memory
};
//Get the global device memory and read/write type
//return 1 if unified memory system supported, otherwise return 0
CV_EXPORTS int getDevMemType(DevMemRW& rw_type, DevMemType& mem_type);
//Set the global device memory and read/write type,
//the newly generated oclMat will all use this type
//return -1 if the target type is unsupported, otherwise return 0
CV_EXPORTS int setDevMemType(DevMemRW rw_type = DEVICE_MEM_R_W, DevMemType mem_type = DEVICE_MEM_DEFAULT);
// these classes contain OpenCL runtime information
struct PlatformInfo;
@ -113,6 +104,7 @@ namespace cv
std::vector<size_t> maxWorkItemSizes;
int maxComputeUnits;
size_t localMemorySize;
size_t maxMemAllocSize;
int deviceVersionMajor;
int deviceVersionMinor;
@ -199,23 +191,19 @@ namespace cv
void CV_EXPORTS finish();
enum BINARY_CACHE_MODE
{
CACHE_NONE = 0, // do not cache OpenCL binary
CACHE_DEBUG = 0x1 << 0, // cache OpenCL binary when built in debug mode
CACHE_RELEASE = 0x1 << 1, // default behavior, only cache when built in release mode
CACHE_ALL = CACHE_DEBUG | CACHE_RELEASE, // cache opencl binary
};
//! Enable or disable OpenCL program binary caching onto local disk
// After a program (*.cl files in opencl/ folder) is built at runtime, we allow the
// compiled OpenCL program to be cached to the path automatically as "path/*.clb"
// binary file, which will be reused when the OpenCV executable is started again.
//
// Caching mode is controlled by the following enums
// Notes
// 1. the feature is by default enabled when OpenCV is built in release mode.
// 2. the CACHE_DEBUG / CACHE_RELEASE flags only effectively work with MSVC compiler;
// for GNU compilers, the function always treats the build as release mode (enabled by default).
enum
{
CACHE_NONE = 0, // do not cache OpenCL binary
CACHE_DEBUG = 0x1 << 0, // cache OpenCL binary when built in debug mode (only work with MSVC)
CACHE_RELEASE = 0x1 << 1, // default behavior, only cache when built in release mode (only work with MSVC)
CACHE_ALL = CACHE_DEBUG | CACHE_RELEASE, // always cache opencl binary
};
// This feature is enabled by default.
CV_EXPORTS void setBinaryDiskCache(int mode = CACHE_RELEASE, cv::String path = "./");
//! set where binary cache to be saved to

View File

@ -98,9 +98,13 @@ inline cl_int getStringInfo(Functor f, ObjectType obj, cl_uint name, std::string
return err;
param.resize(required);
err = f(obj, name, required, &param.at(0), NULL);
if (err != CL_SUCCESS)
return err;
if (required > 0)
{
err = f(obj, name, required, &param.at(0), NULL);
if (err != CL_SUCCESS)
return err;
param.resize(required - 1); // last symbol is '\0'
}
return CL_SUCCESS;
};

View File

@ -412,6 +412,9 @@ static int initializeOpenCLDevices()
openCLSafeCall(getScalarInfo(clGetDeviceInfo, device, CL_DEVICE_LOCAL_MEM_SIZE, localMemorySize));
deviceInfo.info.localMemorySize = (size_t)localMemorySize;
cl_ulong maxMemAllocSize = 0;
openCLSafeCall(getScalarInfo(clGetDeviceInfo, device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, maxMemAllocSize));
deviceInfo.info.maxMemAllocSize = (size_t)maxMemAllocSize;
cl_bool unifiedMemory = false;
openCLSafeCall(getScalarInfo(clGetDeviceInfo, device, CL_DEVICE_HOST_UNIFIED_MEMORY, unifiedMemory));
@ -452,7 +455,7 @@ static int initializeOpenCLDevices()
DeviceInfo::DeviceInfo()
: _id(-1), deviceType(DeviceType(0)),
deviceVendorId(-1),
maxWorkGroupSize(0), maxComputeUnits(0), localMemorySize(0),
maxWorkGroupSize(0), maxComputeUnits(0), localMemorySize(0), maxMemAllocSize(0),
deviceVersionMajor(0), deviceVersionMinor(0),
haveDoubleSupport(false), isUnifiedMemory(false),
platform(NULL)

View File

@ -110,17 +110,12 @@ void ProgramCache::releaseProgram()
cacheSize = 0;
}
static int enable_disk_cache = true ||
#ifdef _DEBUG
false;
#else
true;
#endif
static bool enable_disk_cache = true;
static String binpath = "";
void setBinaryDiskCache(int mode, String path)
{
enable_disk_cache = 0;
enable_disk_cache = false;
binpath = "";
if(mode == CACHE_NONE)
@ -128,7 +123,7 @@ void setBinaryDiskCache(int mode, String path)
return;
}
enable_disk_cache =
#ifdef _DEBUG
#if defined(_DEBUG) || defined(DEBUG)
(mode & CACHE_DEBUG) == CACHE_DEBUG;
#else
(mode & CACHE_RELEASE) == CACHE_RELEASE;

View File

@ -45,26 +45,6 @@
#include "precomp.hpp"
#ifdef __GNUC__
#if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402
#define GCC_DIAG_STR(s) #s
#define GCC_DIAG_JOINSTR(x,y) GCC_DIAG_STR(x ## y)
# define GCC_DIAG_DO_PRAGMA(x) _Pragma (#x)
# define GCC_DIAG_PRAGMA(x) GCC_DIAG_DO_PRAGMA(GCC diagnostic x)
# if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406
# define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(push) \
GCC_DIAG_PRAGMA(ignored GCC_DIAG_JOINSTR(-W,x))
# define GCC_DIAG_ON(x) GCC_DIAG_PRAGMA(pop)
# else
# define GCC_DIAG_OFF(x) GCC_DIAG_PRAGMA(ignored GCC_DIAG_JOINSTR(-W,x))
# define GCC_DIAG_ON(x) GCC_DIAG_PRAGMA(warning GCC_DIAG_JOINSTR(-W,x))
# endif
#else
# define GCC_DIAG_OFF(x)
# define GCC_DIAG_ON(x)
#endif
#endif /* __GNUC__ */
using namespace std;
namespace cv
@ -134,9 +114,6 @@ namespace cv
build_options, finish_mode);
}
#ifdef __GNUC__
GCC_DIAG_OFF(deprecated-declarations)
#endif
cl_mem bindTexture(const oclMat &mat)
{
cl_mem texture;
@ -234,9 +211,6 @@ namespace cv
openCLSafeCall(err);
return texture;
}
#ifdef __GNUC__
GCC_DIAG_ON(deprecated-declarations)
#endif
Ptr<TextureCL> bindTexturePtr(const oclMat &mat)
{

View File

@ -45,6 +45,11 @@
#include "precomp.hpp"
#include "opencl_kernels.hpp"
// TODO Remove this after HAVE_CLAMDBLAS eliminating
#ifdef __GNUC__
# pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#endif
using namespace cv;
using namespace ocl;