hopefully, fixed compile errors on Win & Linux; fixed getMatVector() so core & imgpro...
authorVadim Pisarevsky <vadim.pisarevsky@gmail.com>
Tue, 22 Oct 2013 13:41:28 +0000 (17:41 +0400)
committerVadim Pisarevsky <vadim.pisarevsky@gmail.com>
Tue, 22 Oct 2013 13:41:28 +0000 (17:41 +0400)
modules/core/doc/operations_on_arrays.rst
modules/core/include/opencv2/core/ocl.hpp
modules/core/src/matrix.cpp
modules/core/src/ocl.cpp
modules/core/src/system.cpp
modules/core/src/umatrix.cpp

index d38f57a..a894d07 100644 (file)
@@ -378,7 +378,7 @@ Calculates the covariance matrix of a set of vectors.
 
 .. ocv:function:: void calcCovarMatrix( const Mat* samples, int nsamples, Mat& covar, Mat& mean, int flags, int ctype=CV_64F)
 
-.. ocv:function:: void calcCovarMatrix( InputArray samples, OutputArray covar, OutputArray mean, int flags, int ctype=CV_64F)
+.. ocv:function:: void calcCovarMatrix( InputArray samples, OutputArray covar, InputOutputArray mean, int flags, int ctype=CV_64F)
 
 .. ocv:pyfunction:: cv2.calcCovarMatrix(samples, flags[, covar[, mean[, ctype]]]) -> covar, mean
 
index 0f62c08..5f54834 100644 (file)
@@ -57,7 +57,7 @@ class CV_EXPORTS Kernel;
 class CV_EXPORTS Program;
 class CV_EXPORTS ProgramSource;
 class CV_EXPORTS Queue;
-    
+
 class CV_EXPORTS Device
 {
 public:
@@ -211,10 +211,9 @@ public:
     bool create(int dtype);
     size_t ndevices() const;
     const Device& device(size_t idx) const;
-    int dtype() const;
     Program getProg(const ProgramSource& prog,
                     const String& buildopt, String& errmsg);
-    
+
     static Context& getDefault();
     void* ptr() const;
 protected:
@@ -231,12 +230,12 @@ public:
     ~Queue();
     Queue(const Queue& q);
     Queue& operator = (const Queue& q);
-    
+
     bool create(const Context& c=Context(), const Device& d=Device());
     void finish();
     void* ptr() const;
     static Queue& getDefault();
-    
+
 protected:
     struct Impl;
     Impl* p;
@@ -451,7 +450,7 @@ public:
 
     const String& source() const;
     hash_t hash() const;
-    
+
 protected:
     struct Impl;
     Impl* p;
index 6ab4193..d0d18f7 100644 (file)
@@ -1276,6 +1276,17 @@ void _InputArray::getMatVector(std::vector<Mat>& mv) const
         return;
     }
 
+    if( k == STD_VECTOR_MAT )
+    {
+        const std::vector<Mat>& v = *(const std::vector<Mat>*)obj;
+        size_t i, n = v.size();
+        mv.resize(n);
+
+        for( i = 0; i < n; i++ )
+            mv[i] = v[i];
+        return;
+    }
+
     if( k == STD_VECTOR_UMAT )
     {
         const std::vector<UMat>& v = *(const std::vector<UMat>*)obj;
index fdcedfa..114cb55 100644 (file)
@@ -391,7 +391,7 @@ typedef struct _cl_buffer_region {
 #define CL_MEM_USE_HOST_PTR                         (1 << 3)
 #define CL_MEM_ALLOC_HOST_PTR                       (1 << 4)
 #define CL_MEM_COPY_HOST_PTR                        (1 << 5)
-// reserved                                         (1 << 6)    
+// reserved                                         (1 << 6)
 #define CL_MEM_HOST_WRITE_ONLY                      (1 << 7)
 #define CL_MEM_HOST_READ_ONLY                       (1 << 8)
 #define CL_MEM_HOST_NO_ACCESS                       (1 << 9)
@@ -627,13 +627,13 @@ static void* initOpenCLAndLoad(const char* funcname)
         {
             handle = LoadLibraryA("OpenCL.dll");
             initialized = true;
-            g_haveOpenCL = handle != 0 && GetProcAddressA(handle, oclFuncToCheck) != 0;
+            g_haveOpenCL = handle != 0 && GetProcAddress(handle, oclFuncToCheck) != 0;
         }
         if(!handle)
             return 0;
     }
-    
-    return funcname ? (void*)GetProcAddressA(handle, funcname) : 0;
+
+    return funcname ? (void*)GetProcAddress(handle, funcname) : 0;
 }
 
 #elif defined(__linux)
@@ -649,16 +649,16 @@ static void* initOpenCLAndLoad(const char* funcname)
     {
         if(!initialized)
         {
-            handle = dlopen("libOpenCL.so");
+            handle = dlopen("libOpenCL.so", RTLD_LAZY);
             if(!handle)
-                handle = dlopen("libCL.so");
+                handle = dlopen("libCL.so", RTLD_LAZY);
             initialized = true;
             g_haveOpenCL = handle != 0 && dlsym(handle, oclFuncToCheck) != 0;
         }
         if(!handle)
             return 0;
     }
-    
+
     return funcname ? (void*)dlsym(handle, funcname) : 0;
 }
 
@@ -726,9 +726,9 @@ OCL_FUNC(cl_int, clGetDeviceInfo,
 
 OCL_FUNC(cl_int, clGetDeviceIDs,
     (cl_platform_id platform,
-    cl_device_type device_type, 
-    cl_uint num_entries, 
-    cl_device_id * devices, 
+    cl_device_type device_type,
+    cl_uint num_entries,
+    cl_device_id * devices,
     cl_uint * num_devices),
     (platform, device_type, num_entries, devices, num_devices))
 
@@ -755,17 +755,17 @@ OCL_FUNC_P(cl_context, clCreateContextFromType,
     (properties, device_type, pfn_notify, user_data, errcode_ret))
 
 OCL_FUNC(cl_int, clGetContextInfo,
-    (cl_context context, 
-    cl_context_info param_name, 
-    size_t param_value_size, 
-    void * param_value, 
+    (cl_context context,
+    cl_context_info param_name,
+    size_t param_value_size,
+    void * param_value,
     size_t * param_value_size_ret),
-    (context, param_name, param_value_size, 
+    (context, param_name, param_value_size,
     param_value, param_value_size_ret))
 */
 OCL_FUNC_P(cl_command_queue, clCreateCommandQueue,
-    (cl_context context, 
-    cl_device_id device, 
+    (cl_context context,
+    cl_device_id device,
     cl_command_queue_properties properties,
     cl_int * errcode_ret),
     (context, device, properties, errcode_ret))
@@ -803,7 +803,7 @@ OCL_FUNC_P(cl_mem, clCreateImage,
     (cl_context context,
     cl_mem_flags flags,
     const cl_image_format * image_format,
-    const cl_image_desc * image_desc, 
+    const cl_image_desc * image_desc,
     void * host_ptr,
     cl_int * errcode_ret),
     (context, flags, image_format, image_desc, host_ptr, errcode_ret))
@@ -850,7 +850,7 @@ OCL_FUNC(cl_int, clGetKernelArgInfo,
  void * param_value,
  size_t * param_value_size_ret),
  (kernel, arg_indx, param_name, param_value_size, param_value, param_value_size_ret))
+
 OCL_FUNC(cl_int, clEnqueueReadImage,
  (cl_command_queue command_queue,
  cl_mem image,
@@ -955,7 +955,7 @@ OCL_FUNC_P(void*, clEnqueueMapImage,
  event_wait_list, event, errcode_ret))
 
 OCL_FUNC(cl_int, clRetainProgram, (cl_program program), (program))
+
 OCL_FUNC(cl_int, clGetKernelInfo,
  (cl_kernel kernel,
  cl_kernel_info param_name,
@@ -995,7 +995,7 @@ OCL_FUNC(cl_int, clBuildProgram,
     (cl_program program,
     cl_uint num_devices,
     const cl_device_id * device_list,
-    const char * options, 
+    const char * options,
     void (CL_CALLBACK * pfn_notify)(cl_program, void *),
     void * user_data),
     (program, num_devices, device_list, options, pfn_notify, user_data))
@@ -1016,7 +1016,7 @@ OCL_FUNC(cl_int, clGetProgramBuildInfo,
     void * param_value,
     size_t * param_value_size_ret),
     (program, device, param_name, param_value_size, param_value, param_value_size_ret))
-                      
+
 OCL_FUNC_P(cl_kernel, clCreateKernel,
     (cl_program program,
     const char * kernel_name,
@@ -1040,7 +1040,7 @@ OCL_FUNC(cl_int, clGetKernelWorkGroupInfo,
     void * param_value,
     size_t * param_value_size_ret),
     (kernel, device, param_name, param_value_size, param_value, param_value_size_ret))
-                         
+
 OCL_FUNC(cl_int, clFinish, (cl_command_queue command_queue), (command_queue))
 
 OCL_FUNC(cl_int, clEnqueueReadBuffer,
@@ -1048,7 +1048,7 @@ OCL_FUNC(cl_int, clEnqueueReadBuffer,
     cl_mem buffer,
     cl_bool blocking_read,
     size_t offset,
-    size_t size, 
+    size_t size,
     void * ptr,
     cl_uint num_events_in_wait_list,
     const cl_event * event_wait_list,
@@ -1061,12 +1061,12 @@ OCL_FUNC(cl_int, clEnqueueReadBufferRect,
     cl_mem buffer,
     cl_bool blocking_read,
     const size_t * buffer_offset,
-    const size_t * host_offset, 
+    const size_t * host_offset,
     const size_t * region,
     size_t buffer_row_pitch,
     size_t buffer_slice_pitch,
     size_t host_row_pitch,
-    size_t host_slice_pitch,                        
+    size_t host_slice_pitch,
     void * ptr,
     cl_uint num_events_in_wait_list,
     const cl_event * event_wait_list,
@@ -1076,14 +1076,14 @@ OCL_FUNC(cl_int, clEnqueueReadBufferRect,
     event_wait_list, event))
 
 OCL_FUNC(cl_int, clEnqueueWriteBuffer,
-    (cl_command_queue command_queue, 
-    cl_mem buffer, 
-    cl_bool blocking_write, 
-    size_t offset, 
-    size_t size, 
-    const void * ptr, 
-    cl_uint num_events_in_wait_list, 
-    const cl_event * event_wait_list, 
+    (cl_command_queue command_queue,
+    cl_mem buffer,
+    cl_bool blocking_write,
+    size_t offset,
+    size_t size,
+    const void * ptr,
+    cl_uint num_events_in_wait_list,
+    const cl_event * event_wait_list,
     cl_event * event),
     (command_queue, buffer, blocking_write, offset, size, ptr,
     num_events_in_wait_list, event_wait_list, event))
@@ -1093,12 +1093,12 @@ OCL_FUNC(cl_int, clEnqueueWriteBufferRect,
     cl_mem buffer,
     cl_bool blocking_write,
     const size_t * buffer_offset,
-    const size_t * host_offset, 
+    const size_t * host_offset,
     const size_t * region,
     size_t buffer_row_pitch,
     size_t buffer_slice_pitch,
     size_t host_row_pitch,
-    size_t host_slice_pitch,                        
+    size_t host_slice_pitch,
     const void * ptr,
     cl_uint num_events_in_wait_list,
     const cl_event * event_wait_list,
@@ -1107,26 +1107,26 @@ OCL_FUNC(cl_int, clEnqueueWriteBufferRect,
     region, buffer_row_pitch, buffer_slice_pitch, host_row_pitch,
     host_slice_pitch, ptr, num_events_in_wait_list, event_wait_list, event))
 
-OCL_FUNC(cl_int, clEnqueueFillBuffer,
+/*OCL_FUNC(cl_int, clEnqueueFillBuffer,
     (cl_command_queue command_queue,
-    cl_mem buffer, 
-    const void * pattern, 
-    size_t pattern_size, 
-    size_t offset, 
-    size_t size, 
-    cl_uint num_events_in_wait_list, 
-    const cl_event * event_wait_list, 
+    cl_mem buffer,
+    const void * pattern,
+    size_t pattern_size,
+    size_t offset,
+    size_t size,
+    cl_uint num_events_in_wait_list,
+    const cl_event * event_wait_list,
     cl_event * event),
-    (command_queue, buffer, pattern, pattern_size, offset, size, 
-    num_events_in_wait_list, event_wait_list, event))
+    (command_queue, buffer, pattern, pattern_size, offset, size,
+    num_events_in_wait_list, event_wait_list, event))*/
 
 OCL_FUNC(cl_int, clEnqueueCopyBuffer,
-    (cl_command_queue command_queue, 
+    (cl_command_queue command_queue,
     cl_mem src_buffer,
-    cl_mem dst_buffer, 
+    cl_mem dst_buffer,
     size_t src_offset,
     size_t dst_offset,
-    size_t size, 
+    size_t size,
     cl_uint num_events_in_wait_list,
     const cl_event * event_wait_list,
     cl_event * event),
@@ -1134,12 +1134,12 @@ OCL_FUNC(cl_int, clEnqueueCopyBuffer,
     size, num_events_in_wait_list, event_wait_list, event))
 
 OCL_FUNC(cl_int, clEnqueueCopyBufferRect,
-    (cl_command_queue command_queue, 
+    (cl_command_queue command_queue,
     cl_mem src_buffer,
-    cl_mem dst_buffer, 
+    cl_mem dst_buffer,
     const size_t * src_origin,
     const size_t * dst_origin,
-    const size_t * region, 
+    const size_t * region,
     size_t src_row_pitch,
     size_t src_slice_pitch,
     size_t dst_row_pitch,
@@ -1154,7 +1154,7 @@ OCL_FUNC(cl_int, clEnqueueCopyBufferRect,
 OCL_FUNC_P(void*, clEnqueueMapBuffer,
     (cl_command_queue command_queue,
     cl_mem buffer,
-    cl_bool blocking_map, 
+    cl_bool blocking_map,
     cl_map_flags map_flags,
     size_t offset,
     size_t size,
@@ -1737,7 +1737,6 @@ struct Context::Impl
 
     cl_context handle;
     std::vector<Device> devices;
-    int dtype;
     bool initialized;
 
     typedef ProgramSource::hash_t hash_t;
@@ -1766,11 +1765,6 @@ Context::Context(int dtype)
     create(dtype);
 }
 
-int Context::dtype() const
-{
-    return p ? p->dtype : 0;
-}
-
 bool Context::create(int dtype0)
 {
     if( !haveOpenCL() )
@@ -2113,9 +2107,8 @@ int Kernel::set(int i, const KernelArg& arg)
         }
         else
         {
-            clSetKernelArg(p->handle, (cl_uint)(i+1), sizeof(size_t), &arg.m->offset);
-            clSetKernelArg(p->handle, (cl_uint)(i+1), sizeof(size_t)*(dims-1), &arg.m->step.p[0]);
-            clSetKernelArg(p->handle, (cl_uint)(i+2), sizeof(cl_int)*dims, &arg.m->size.p[0]);
+            clSetKernelArg(p->handle, (cl_uint)(i+2), sizeof(size_t)*(dims-1), &arg.m->step.p[0]);
+            clSetKernelArg(p->handle, (cl_uint)(i+3), sizeof(cl_int)*dims, &arg.m->size.p[0]);
             return i + 4;
         }
     }
@@ -2249,13 +2242,13 @@ struct Program::Impl
         const Context& ctx = Context::getDefault();
         const Device& dev = Device::getDefault();
         const char* pos0 = _buf.c_str();
-        char* pos1 = strchr(pos0, '\n');
+        const char* pos1 = strchr(pos0, '\n');
         if(!pos1)
             return;
-        char* pos2 = strchr(pos1+1, '\n');
+        const char* pos2 = strchr(pos1+1, '\n');
         if(!pos2)
             return;
-        char* pos3 = strchr(pos2+1, '\n');
+        const char* pos3 = strchr(pos2+1, '\n');
         if(!pos3)
             return;
         size_t prefixlen = (pos3 - pos0)+1;
@@ -2580,6 +2573,9 @@ public:
             u->markHostCopyObsolete(false);
             clReleaseMemObject((cl_mem)u->handle);
             u->currAllocator = u->prevAllocator;
+            if(u->data && u->copyOnMap())
+                fastFree(u->data);
+            u->data = u->origdata;
             if(u->refcount == 0)
                 u->currAllocator->deallocate(u);
         }
@@ -2898,4 +2894,3 @@ MatAllocator* getOpenCLAllocator()
 }
 
 }}
-
index 4971347..aa02323 100644 (file)
@@ -877,14 +877,14 @@ TLSData::TLSData()
     {
         if( tlsKey == TLS_OUT_OF_INDEXES )
         {
-            tlsRNGKey = TlsAlloc();
-            CV_Assert(tlsRNGKey != TLS_OUT_OF_INDEXES);
+            tlsKey = TlsAlloc();
+            CV_Assert(tlsKey != TLS_OUT_OF_INDEXES);
         }
         TLSData* d = (TLSData*)TlsGetValue( tlsKey );
         if( !d )
         {
             d = new TLSData;
-            TlsSetValue( tlsRNGKey, d );
+            TlsSetValue( tlsKey, d );
         }
         return d;
     }
index 4ed0e51..996138e 100644 (file)
@@ -548,7 +548,7 @@ Mat UMat::getMat(int accessFlags) const
     Mat hdr(dims, size.p, type(), u->data + offset, step.p);
     hdr.refcount = &u->refcount;
     hdr.u = u;
-    hdr.datastart = u->data;
+    hdr.datastart = hdr.data = u->data;
     hdr.datalimit = hdr.dataend = u->data + u->size;
     CV_XADD(hdr.refcount, 1);
     return hdr;
@@ -565,24 +565,24 @@ void* UMat::handle(int accessFlags) const
         CV_Assert(u->refcount == 0);
         u->currAllocator->unmap(u);
     }
-    else if( u->refcount > 0 && (accessFlags & ACCESS_WRITE) )
+    /*else if( u->refcount > 0 && (accessFlags & ACCESS_WRITE) )
     {
         CV_Error(Error::StsError,
                  "it's not allowed to access UMat handle for writing "
                  "while it's mapped; call Mat::release() first for all its mappings");
-    }
+    }*/
     return u->handle;
 }
 
 void UMat::ndoffset(size_t* ofs) const
 {
     // offset = step[0]*ofs[0] + step[1]*ofs[1] + step[2]*ofs[2] + ...;
-    size_t t = offset;
+    size_t val = offset;
     for( int i = 0; i < dims; i++ )
     {
         size_t s = step.p[i];
-        ofs[i] = t / s;
-        t -= ofs[i]*s;
+        ofs[i] = val / s;
+        val -= ofs[i]*s;
     }
 }