Fix opencl check

This commit is contained in:
Tal Regev 2021-03-16 17:27:25 +02:00
parent 4af1360faa
commit 336825cd02
3 changed files with 70 additions and 126 deletions

View File

@ -217,13 +217,6 @@ if test x$enable_server = xyes ; then
configured_to_build="${configured_to_build} server" configured_to_build="${configured_to_build} server"
fi fi
if test x$enable_apps = xyes ; then if test x$enable_apps = xyes ; then
AX_CHECK_CL
if test "X$no_cl" = "Xyes"; then
AC_MSG_WARN([OpenCL is missing, OpenClApp example is disable])
enable_openclapp=no
else
enable_openclapp=yes
fi
configured_to_build="${configured_to_build} apps" configured_to_build="${configured_to_build} apps"
fi fi
if test x$enable_unit_tests = xyes ; then if test x$enable_unit_tests = xyes ; then
@ -562,6 +555,12 @@ dnl check for X11
AC_PATH_X AC_PATH_X
AC_PATH_XTRA AC_PATH_XTRA
dnl Check for CL library opencl
AX_CHECK_CL
if test "x$with_opencl" = "xno"; then
AC_MSG_WARN([OpenCL is missing, OpenClApp example is disabled])
fi
dnl check for GL library dnl check for GL library
AX_CHECK_GL AX_CHECK_GL
AX_CHECK_GLU AX_CHECK_GLU
@ -1076,11 +1075,11 @@ AM_CONDITIONAL(ENABLE_MANAGER, [ test "x${ac_cv_have_wxwidgets}" = xyes -a "${en
AM_CONDITIONAL(ENABLE_LIBRARIES, [test "${enable_libraries}" = yes]) AM_CONDITIONAL(ENABLE_LIBRARIES, [test "${enable_libraries}" = yes])
AM_CONDITIONAL(ENABLE_BOINCZIP, [test "${enable_boinczip}" = yes]) AM_CONDITIONAL(ENABLE_BOINCZIP, [test "${enable_boinczip}" = yes])
AM_CONDITIONAL(ENABLE_APPS, [test "${enable_apps}" = yes]) AM_CONDITIONAL(ENABLE_APPS, [test "${enable_apps}" = yes])
AM_CONDITIONAL(ENABLE_OPENCLAPP, [test "${enable_openclapp}" = yes])
AM_CONDITIONAL(ENABLE_UNIT_TESTS, [test "${enable_unit_tests}" = yes]) AM_CONDITIONAL(ENABLE_UNIT_TESTS, [test "${enable_unit_tests}" = yes])
AM_CONDITIONAL(ENABLE_BOINCCRYPT, [test "x${enable_server}" = xyes || test "x${enable_client}" = xyes ]) AM_CONDITIONAL(ENABLE_BOINCCRYPT, [test "x${enable_server}" = xyes || test "x${enable_client}" = xyes ])
AM_CONDITIONAL(INSTALL_HEADERS, [test "${enable_install_headers}" = yes]) AM_CONDITIONAL(INSTALL_HEADERS, [test "${enable_install_headers}" = yes])
AM_CONDITIONAL(HAVE_CUDA_LIB, [test "${enable_client}" = yes -a -f ./coprocs/CUDA/posix/${boinc_platform}/libcudart.so]) AM_CONDITIONAL(HAVE_CUDA_LIB, [test "${enable_client}" = yes -a -f ./coprocs/CUDA/posix/${boinc_platform}/libcudart.so])
AM_CONDITIONAL(BUILD_OPENCL, [test "x$with_opencl" = "xyes"])
dnl ====================================================================== dnl ======================================================================
dnl some more vodoo required for building portable client-binary (client, clientgui) dnl some more vodoo required for building portable client-binary (client, clientgui)

View File

@ -1,120 +1,65 @@
# -*- mode: autoconf -*-
# # OpenCL support
# AX_CHECK_CL
#
# Check for an OpenCL implementation. If CL is found, the required compiler
# and linker flags are included in the output variables "CL_CFLAGS" and
# "CL_LIBS", respectively. If no usable CL implementation is found, "no_cl"
# is set to "yes".
#
# If the header "CL/cl.h" is found, "HAVE_CL_CL_H" is defined. If the header
# "OpenCL/cl.h" is found, HAVE_OPENCL_CL_H is defined. These preprocessor
# definitions may not be mutually exclusive.
#
# Based on AX_CHECK_GL, version: 2.4 author: Braden McDaniel
# <braden@endoframe.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
# As a special exception, the you may copy, distribute and modify the
# configure scripts that are the output of Autoconf when processing
# the Macro. You need not follow the terms of the GNU General Public
# License when using or distributing such scripts.
#
AC_DEFUN([AX_CHECK_CL], AC_DEFUN([AX_CHECK_CL],
[AC_REQUIRE([AC_CANONICAL_HOST])dnl [AC_ARG_WITH([opencl],
AC_REQUIRE([AC_PATH_X])dnl [AS_HELP_STRING([--with-opencl],
AC_REQUIRE([AC_PROG_SED])dnl [build OpenClApp with OpenCL @<:@default=check@:>@])],
AC_REQUIRE([ACX_PTHREAD])dnl [],
[with_opencl=check])
AC_LANG_PUSH([C]) # detect/verify we have a working OpenCL header and library
AX_LANG_COMPILER_MS AS_IF([test "x$with_opencl" != xno],
AS_IF([test X$ax_compiler_ms = Xno], [
[CL_CFLAGS="${PTHREAD_CFLAGS}"; CL_LIBS="${PTHREAD_LIBS} -lm"]) # check for usable OpenCL header
# note C++ binding uses opencl.h, not just cl.h
# AC_MSG_NOTICE([checking for usable OpenCL opencl.h header])
# Use x_includes and x_libraries if they have been set (presumably by AC_CHECK_HEADER([OpenCL/opencl.h],
# AC_PATH_X). [OPENCL_HEADER='"OpenCL/opencl.h"'],
# [AC_CHECK_HEADER([CL/opencl.h],
AS_IF([test X$no_x != Xyes], [OPENCL_HEADER='"CL/opencl.h"'],
[AS_IF([test -n "$x_includes"], [if test "x$with_opencl" != xcheck; then
[CL_CFLAGS="-I$x_includes $CL_CFLAGS"])] AC_MSG_FAILURE([OpenCL support was requested, but no usable OpenCL header was found])
AS_IF([test -n "$x_libraries"], fi
[CL_LIBS="-L$x_libraries -lX11 $CL_LIBS"])) ]
)
ax_save_CPPFLAGS=$CPPFLAGS ]
CPPFLAGS="$CL_CFLAGS $CPPFLAGS" )
AC_CHECK_HEADERS([CL/cl.h OpenCL/cl.h]) AS_IF([test "x$OPENCL_HEADER" != x],
CPPFLAGS=$ax_save_CPPFLAGS [
# we have a header, check for usable OpenCL library
AC_CHECK_HEADERS([windows.h]) # we cannot use AC_CHECK_LIB because we want to check
# using the OS X OpenCL framework, and AC_CHECK_LIB does not
m4_define([AX_CHECK_CL_PROGRAM], # know how to use the framework linker syntax.
[AC_LANG_PROGRAM([[ # (we also do not want the OpenCL libs to be added to the
# if defined(HAVE_WINDOWS_H) && defined(_WIN32) # LIBS variable, and AC_CHECK_LIB does that if it succeeds)
# include <windows.h> AC_MSG_CHECKING([for usable OpenCL library])
# endif savedLIBS=$LIBS
# ifdef HAVE_CL_CL_H OPENCL_LIBS="-framework OpenCL"
# include <CL/cl.h> LIBS="$OPENCL_LIBS $savedLIBS"
# elif defined(HAVE_OPENCL_CL_H) AC_LINK_IFELSE( [AC_LANG_PROGRAM([@%:@include $OPENCL_HEADER],[clGetPlatformIDs(0,0,0);])],
# include <OpenCL/cl.h> [AC_MSG_RESULT($OPENCL_LIBS)],
# else [OPENCL_LIBS="-lOpenCL"
# error no cl.h LIBS="$OPENCL_LIBS $savedLIBS"
# endif]], AC_LINK_IFELSE( [AC_LANG_PROGRAM([@%:@include $OPENCL_HEADER],[clGetPlatformIDs(0,0,0);])],
[[clFinish(0)]])]) [AC_MSG_RESULT($OPENCL_LIBS)],
[AC_MSG_RESULT([no])
AC_CACHE_CHECK([for OpenCL library], [ax_cv_check_cl_libcl], if test "x$with_opencl" != xcheck; then
[ax_cv_check_cl_libcl=no AC_MSG_FAILURE([OpenCL support was requested, but no usable OpenCL library was found])
case $host_cpu in fi
x86_64) ax_check_cl_libdir=lib64 ;; ]
*) ax_check_cl_libdir=lib ;; )
esac ]
ax_save_CPPFLAGS=$CPPFLAGS )
CPPFLAGS="$CL_CFLAGS $CPPFLAGS" LIBS=$savedLIBS
ax_save_LIBS=$LIBS ]
LIBS="" )
ax_check_libs="-lOpenCL -lCL" AS_IF([test "x$OPENCL_HEADER" != "x" -a "x$OPENCL_LIBS" != "x"],
for ax_lib in $ax_check_libs; do [with_opencl=yes
AS_IF([test X$ax_compiler_ms = Xyes], MPI_SUBDIRS="$MPI_SUBDIRS opencl"
[ax_try_lib=`echo $ax_lib | $SED -e 's/^-l//' -e 's/$/.lib/'`], AC_SUBST([OPENCL_LIBS])
[ax_try_lib=$ax_lib]) ],
LIBS="$ax_try_lib $CL_LIBS $ax_save_LIBS" [AC_MSG_NOTICE([no usable OpenCL installation found])
AC_LINK_IFELSE([AX_CHECK_CL_PROGRAM], with_opencl=no
[ax_cv_check_cl_libcl=$ax_try_lib; break], ])
[ax_check_cl_nvidia_flags="-L/usr/$ax_check_cl_libdir/nvidia" LIBS="$ax_try_lib $ax_check_cl_nvidia_flags $CL_LIBS $ax_save_LIBS" ])
AC_LINK_IFELSE([AX_CHECK_CL_PROGRAM],
[ax_cv_check_cl_libcl="$ax_try_lib $ax_check_cl_nvidia_flags"; break],
[ax_check_cl_dylib_flag='-dylib_file /System/Library/Frameworks/OpenCL.framework/Versions/A/Libraries/libCL.dylib:/System/Library/Frameworks/OpenCL.framework/Versions/A/Libraries/libCL.dylib' LIBS="$ax_try_lib $ax_check_cl_dylib_flag $CL_LIBS $ax_save_LIBS"
AC_LINK_IFELSE([AX_CHECK_CL_PROGRAM],
[ax_cv_check_cl_libcl="$ax_try_lib $ax_check_cl_dylib_flag"; break])])])
done
AS_IF([test "X$ax_cv_check_cl_libcl" = Xno -a X$no_x = Xyes],
[LIBS='-framework OpenCL'
AC_LINK_IFELSE([AX_CHECK_CL_PROGRAM],
[ax_cv_check_cl_libcl=$LIBS])])
LIBS=$ax_save_LIBS
CPPFLAGS=$ax_save_CPPFLAGS])
AS_IF([test "X$ax_cv_check_cl_libcl" = Xno],
[no_cl=yes; CL_CFLAGS=""; CL_LIBS=""],
[CL_LIBS="$ax_cv_check_cl_libcl $CL_LIBS"])
AC_LANG_POP([C])
AC_SUBST([CL_CFLAGS])
AC_SUBST([CL_LIBS])
])dnl ])dnl

View File

@ -7,7 +7,7 @@ include $(top_srcdir)/Makefile.incl
SUBDIRS = condor example_app multi_thread sleeper vboxmonitor vboxwrapper worker wrapper SUBDIRS = condor example_app multi_thread sleeper vboxmonitor vboxwrapper worker wrapper
## build openclapp if you have opencl on your device ## build openclapp if you have opencl on your device
if ENABLE_OPENCLAPP if BUILD_OPENCL
SUBDIRS += openclapp SUBDIRS += openclapp
endif endif