[FFmpeg-devel] configure needs to check for OpenCL version 1.2 and look elsewhere as well

Hanspeter Niederstrasser niederstrasser at gmail.com
Mon Apr 22 23:10:31 CEST 2013


On Sun, Apr 21, 2013 at 7:33 AM, Wei Gao <highgod0401 at gmail.com> wrote:
> Hi
>
>
> 2013/4/20 Hanspeter Niederstrasser <niederstrasser at gmail.com>
>
>> On Fri, Apr 19, 2013 at 10:52 PM, Wei Gao <highgod0401 at gmail.com> wrote:
>> > Hi, sorry for replying late, and also I am not familiar with configure
>> > things, I do some works and test as your patch, some comments as follows:
>>
>> No problem.  I'm also trying to figure this out as I go.
>>
>> > 2013/4/13 Hanspeter Niederstrasser <niederstrasser at gmail.com>
>> >
>> >> The OpenCL test just checks for CL/cl.h which doesn't exist on OS X
>> >> (it's at OpenCL/cl.h).  In trying to fix that, I also noticed that
>> >> ffmpeg needs OpenCL >= 1.2, so I tried to add a version check to
>> >> configure as well.  Here's my current patch, but it is not setting
>> >> HAVE_OPENCL_CL_H, even though config.log says that the header and
>> >> library were found.
>> >>
>> >> diff --git a/configure b/configure
>> >> index fe976fd..83bb71f 100755
>> >> --- a/configure
>> >> +++ b/configure
>> >> @@ -1471,6 +1471,7 @@ HAVE_LIST="
>> >>      mprotect
>> >>      msvcrt
>> >>      nanosleep
>> >> +    opencl_cl_h
>> >>      openjpeg_1_5_openjpeg_h
>> >>      PeekNamedPipe
>> >>      perl
>> >>
>> > it should add a check header line:check_header opencl/cl.h to set the
>> > opencl_cl_h
>>
>> Both check_lib() and require() already call check_header(), but even
>> when I just use
>>
>> enabled opencl     && check_header OpenCL/cl.h
>>
>> HAVE_OPENCL_CL_H is not set in config.log.  To make sure my syntax is
>> right, when I search for the completely unrelated header
>> "exiv2/exv_conf.h", HAVE_EXIV2_EXV_CONF_H is set to 1 in config.log.
>>
> I use CL_CL_H to test on my computer:
> 1.  check_header cl/cl.h
> 2.HAVE_LIST="
>   cl_cl_h
> the HAVE_CL_CL_H can be set to 1, and the result is correct. Do you try
> that?

Yes, although I used "OpenCL/cl.h" and "opencl_cl_h", respectively, in
order to match where the cl.h header is on OS X.  And when I do that,
configure passes, but I get "#define HAVE_OPENCL_CL_H 0" in config.h
(using just CL/cl.h causes a 'header not found' error during
configure).

>> >> @@ -4034,7 +4035,12 @@ enabled openal     && { { for al_libs in
>> >> "${OPENAL_LIBS}" "-lopenal" "-lOpenAL32
>> >>                          die "ERROR: openal not found"; } &&
>> >>                        { check_cpp_condition "AL/al.h"
>> >> "defined(AL_VERSION_1_1)" ||
>> >>                          die "ERROR: openal must be installed and
>> >> version must be 1.1 or compatible"; }
>> >> -enabled opencl     && require2 opencl CL/cl.h clEnqueueNDRangeKernel
>> >> -lOpenCL
>> >> +enabled opencl     && { check_lib OpenCL/cl.h clEnqueueNDRangeKernel
>> >> -Wl,-framework,OpenCL ||
>> >> +                        check_lib CL/cl.h clEnqueueNDRangeKernel
>> -lOpenCL
>> >> ||
>> >> +                        die "ERROR: opencl not found"; } &&
>> >> +                      { check_cpp_condition "OpenCL/cl.h"
>> >> "defined(CL_VERSION_1_2)" ||
>> >> +                        check_cpp_condition "CL/cl.h"
>> >> "defined(CL_VERSION_1_2)"  ||
>> >> +                        die "ERROR: opencl must be installed and
>> >> version must be 1.2 or compatible"; }
>> >>
>> > I tried this on my computer, it does not pass the configure, I think it
>> > should be written like this:
>> > enabled opencl     && { check_lib2 OpenCL/cl.h clEnqueueNDRangeKernel
>> > -Wl,-framework,OpenCL ||
>> >                         check_lib2 CL/cl.h clEnqueueNDRangeKernel
>> -lOpenCL
>> > ||
>> >                         die "ERROR: opencl not found"; } &&
>> >                       { check_cpp_condition "OpenCL/cl.h"
>> > "defined(CL_VERSION_1_2)" ||
>> >                         check_cpp_condition "CL/cl.h"
>> > "defined(CL_VERSION_1_2)" ||
>> >                         die "ERROR: opencl must be installed and version
>> > must be 1.2 or compatible"; }
>> > use check_lib2 to check, and this can pass on my computer.
>>
>> I've tried that too and configure accepts it, but config.log doesn't
>> provide any indication that the header or the library were not found.
>> If I give it a non-existing header, configure errors out, so the
>> syntax seems right.
>>
>> when I use  check_lib, the configure can't find clEnqueueNDRangeKernel,
> if you use bin tools to review the lib, you can find that the function has
> "@" symbol, I think it is a CPP lib and you can't use check_lib to detect
> the function, you should use check_lib2, check_lib can't pass on my
> computer.

I have tried check_lib, check_lib2, and require.  They all give the
same result.  The header is found, the function is detected, and the
library is added to EXTRALIBS.  However, none of the 3 mehods defines
HAVE_OPENCL_CL_H.  Since you say only check_lib2 works for you, I will
only use that from now on.

>> And I want to
>> > ask a question: -Wl,-framework,OpenCL, what does these mean? Isn't
>> >  -lOpenCL OK?
>>
>> On OS X, the system OpenCL is found inside a Framework, rather than in
>> the usual $(PREFIX)/{include,lib} layout found in most other systems,
>> so -lOpenCL will not work.  The actual file path is complicated, but
>> OS X compilers and linkers know where to search for Frameworks if
>> provided with a header of the form "OpenCL/cl.h" and a library of
>> "-framework OpenCL".  The "-Wl,-framework,OpenCL" string is just an
>> alternative syntax so that the compiler passes "-framework OpenCL" to
>> the linker.
>>
>>
>> https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPFrameworks/Tasks/IncludingFrameworks.html
>
>
> can it pass the configuer stage? you can use cflags to indicate the path.

No flags are needed to detect the header.  The physical header path is
"/System/Library/Frameworks/OpenCL.framework/Headers/cl.h", and
passing "-I/System/Library/Frameworks/OpenCL.framework" and similar
derivations do anything different.

>> >  enabled openssl    && { check_lib openssl/ssl.h SSL_library_init
>> >> -lssl -lcrypto ||
>> >>                          check_lib openssl/ssl.h SSL_library_init
>> >> -lssl32 -leay32 ||
>> >>                          check_lib openssl/ssl.h SSL_library_init
>> >> -lssl -lcrypto -lws2_32 -lgdi32 ||
>> >> diff --git a/libavutil/opencl.h b/libavutil/opencl.h
>> >> index acafe36..5450537 100644
>> >> --- a/libavutil/opencl.h
>> >> +++ b/libavutil/opencl.h
>> >> @@ -31,7 +31,11 @@
>> >>  #ifndef LIBAVUTIL_OPENCL_H
>> >>  #define LIBAVUTIL_OPENCL_H
>> >>
>> >> +#if HAVE_OPENCL_CL_H
>> >> +#include <OpenCL/cl.h>
>> >> +#else
>> >>  #include <CL/cl.h>
>> >> +#endif
>> >>  #include "config.h"
>> >>  #include "dict.h"
>> >>
>> > I think the  #include "config.h" should above the #if HAVE_OPENCL_CL_H
>> > line. It should be written as follows:
>> >
>> >  #include "config.h"
>> > +#if HAVE_OPENCL_CL_H
>> > +#include <OpenCL/cl.h>
>> > +#else
>> >  #include <CL/cl.h>
>> > +#endif
>> >  #include "dict.h"
>>
>> You're right.  I had kept the original order, but config.h is needed
>> to find HAVE_OPENCL_CL_H.
>>
>> An alternative would be to conditional the header choice in opencl.h
>> on __APPLE__ instead of HAVE_OPENCL_CL_H.  The configure check does
>> seem to work (it sets EXTRALIBS correctly, for example), but it would
>> be nice to find out why HAVE_OPENCL_CL_H is not being set.  Thanks
>> again for your help.
>>
> HAVE_OPENCL_CL_H can be set because the HAVE_CL_CL_H can be set on my
> computer, you can try my method.
>
>   I use __APPLE__  in my previous patches, but it should be detected on the
> configure stage, and stop the compile if the environment is not correct.

I've copied/pasted directly from your examples and just replaced
CL/cl.h with OpenCL/cl.h and HAVE_OPENCL_CL_H remains at 0.  I think
I'm going to clean up my branch and submit a patch that 1) uses
check_lib2 to find the header and library, and 2) #ifdefs the header
to use on __APPLE__ unless someone else has an idea as to why
OpenCL/cl.h works for detecting the header in configure, but fails to
set HAVE_OPENCL_CL_H.  The checks should still work for "CL/cl.h +
-lOpenCL" systems.

Hanspeter

-- 
Disclaimer:
By sending an email to ANY of my addresses you are agreeing that:
1. I am by definition, "the intended recipient"
2. All information in the email is mine to do with as I see fit and
make such financial profit, political mileage, or good joke as it
lends itself to.
3. I may take the contents as representing the views of your company.
4. This overrides any disclaimer or statement of confidentiality that
may be included with your message.


More information about the ffmpeg-devel mailing list