@@ -2618,20 +2618,27 @@ internal::ProgramEntry::operator ProgramSource&() const
2618
2618
struct Program ::Impl
2619
2619
{
2620
2620
Impl (const ProgramSource& _src,
2621
- const String& _buildflags, String& errmsg)
2621
+ const String& _buildflags, String& errmsg) :
2622
+ src (_src),
2623
+ buildflags (_buildflags),
2624
+ handle (NULL )
2622
2625
{
2623
- CV_INSTRUMENT_REGION_OPENCL_COMPILE (cv::format (" Compile: %" PRIx64 " options: %s" , _src.hash (), _buildflags.c_str ()).c_str ());
2624
2626
refcount = 1 ;
2625
- const Context& ctx = Context::getDefault ();
2626
- src = _src;
2627
- buildflags = _buildflags;
2627
+ compile (Context::getDefault (), errmsg);
2628
+ }
2629
+
2630
+ bool compile (const Context& ctx, String& errmsg)
2631
+ {
2632
+ CV_Assert (handle == NULL );
2633
+ CV_INSTRUMENT_REGION_OPENCL_COMPILE (cv::format (" Compile: %" PRIx64 " options: %s" , src.hash (), buildflags.c_str ()).c_str ());
2628
2634
const String& srcstr = src.source ();
2629
2635
const char * srcptr = srcstr.c_str ();
2630
2636
size_t srclen = srcstr.size ();
2631
2637
cl_int retval = 0 ;
2632
2638
2633
2639
handle = clCreateProgramWithSource ((cl_context)ctx.ptr (), 1 , &srcptr, &srclen, &retval);
2634
- if ( handle && retval == CL_SUCCESS )
2640
+ CV_OclDbgAssert (handle && retval == CL_SUCCESS);
2641
+ if (handle && retval == CL_SUCCESS)
2635
2642
{
2636
2643
int i, n = (int )ctx.ndevices ();
2637
2644
AutoBuffer<void *> deviceListBuf (n+1 );
@@ -2649,33 +2656,49 @@ struct Program::Impl
2649
2656
(const cl_device_id*)deviceList,
2650
2657
buildflags.c_str (), 0 , 0 );
2651
2658
#if !CV_OPENCL_ALWAYS_SHOW_BUILD_LOG
2652
- if ( retval != CL_SUCCESS )
2659
+ if ( retval != CL_SUCCESS)
2653
2660
#endif
2654
2661
{
2662
+ AutoBuffer<char , 4096 > buffer; buffer[0 ] = 0 ;
2663
+
2655
2664
size_t retsz = 0 ;
2656
- cl_int buildInfo_retval = clGetProgramBuildInfo (handle, (cl_device_id)deviceList[0 ],
2657
- CL_PROGRAM_BUILD_LOG, 0 , 0 , &retsz);
2658
- if (buildInfo_retval == CL_SUCCESS && retsz > 1 )
2665
+ cl_int log_retval = clGetProgramBuildInfo (handle, (cl_device_id)deviceList[0 ],
2666
+ CL_PROGRAM_BUILD_LOG, 0 , 0 , &retsz);
2667
+ if (log_retval == CL_SUCCESS && retsz > 1 )
2659
2668
{
2660
- AutoBuffer<char > bufbuf (retsz + 16 );
2661
- char * buf = bufbuf;
2662
- buildInfo_retval = clGetProgramBuildInfo (handle, (cl_device_id)deviceList[0 ],
2663
- CL_PROGRAM_BUILD_LOG, retsz+1 , buf, &retsz);
2664
- if (buildInfo_retval == CL_SUCCESS)
2669
+ buffer.resize (retsz + 16 );
2670
+ log_retval = clGetProgramBuildInfo (handle, (cl_device_id)deviceList[0 ],
2671
+ CL_PROGRAM_BUILD_LOG, retsz+1 , (char *)buffer, &retsz);
2672
+ if (log_retval == CL_SUCCESS)
2673
+ {
2674
+ if (retsz < buffer.size ())
2675
+ buffer[retsz] = 0 ;
2676
+ else
2677
+ buffer[buffer.size () - 1 ] = 0 ;
2678
+ }
2679
+ else
2665
2680
{
2666
- // TODO It is useful to see kernel name & program file name also
2667
- errmsg = String (buf);
2668
- printf (" OpenCL program build log: %s\n %s\n " , buildflags.c_str (), errmsg.c_str ());
2669
- fflush (stdout);
2681
+ buffer[0 ] = 0 ;
2670
2682
}
2671
2683
}
2684
+
2685
+ errmsg = String (buffer);
2686
+ printf (" OpenCL program build log: %s (%s)\n Status %d: %s\n %s\n %s\n " ,
2687
+ src.getImpl ()->name_ .c_str (), src.getImpl ()->module_ .c_str (),
2688
+ retval, getOpenCLErrorString (retval),
2689
+ buildflags.c_str (), errmsg.c_str ());
2690
+ fflush (stdout);
2691
+
2692
+ // don't remove "retval != CL_SUCCESS" condition here:
2693
+ // it would break CV_OPENCL_ALWAYS_SHOW_BUILD_LOG mode
2672
2694
if (retval != CL_SUCCESS && handle)
2673
2695
{
2674
2696
clReleaseProgram (handle);
2675
2697
handle = NULL ;
2676
2698
}
2677
2699
}
2678
2700
}
2701
+ return handle != NULL ;
2679
2702
}
2680
2703
2681
2704
Impl (const String& _buf, const String& _buildflags)
0 commit comments