Debian Codegraph @

m4/ax_have_opencl.m4

raw
1 # -*- mode: autoconf -*-
2 #
3 # AX_HAVE_OPENCL
4 #
5 # Check for an OpenCL implementation. If CL is found, HAVE_OPENCL is defined
6 # and the required CPP and linker flags are included in the output variables
7 # "CL_CPPFLAGS" and "CL_LIBS", respectively. If no usable CL implementation is
8 # found then "no_cl" is set to "yes" (otherwise it is set to "no").
9 #
10 # If the header <CL/cl.h> is found, "HAVE_CL_CL_H" is defined. If the header
11 # <OpenCL/cl.h> is found, HAVE_OPENCL_CL_H is defined. These preprocessor
12 # definitions may not be mutually exclusive.
13 #
14 # This macro first checks /usr/include and /usr/lib for OpenCL support; if it is not
15 # found in those locations, then it checks in the standard installation locations
16 # for AMD's (/opt/AMDAPP) and NVIDIA's (/usr/local/cuda) SDKs.
17 #
18 # This program is free software; you can redistribute it and/or modify
19 # it under the terms of the GNU General Public License as published by
20 # the Free Software Foundation; either version 2, or (at your option)
21 # any later version.
22 #
23 # This program is distributed in the hope that it will be useful,
24 # but WITHOUT ANY WARRANTY; without even the implied warranty of
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 # GNU General Public License for more details.
27 #
28 # You should have received a copy of the GNU General Public License
29 # along with this program; if not, write to the Free Software
30 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
31 # 02110-1301, USA.
32 #
33 # As a special exception, the you may copy, distribute and modify the
34 # configure scripts that are the output of Autoconf when processing
35 # the Macro. You need not follow the terms of the GNU General Public
36 # License when using or distributing such scripts.
37 #
38 AC_DEFUN([AX_HAVE_OPENCL],
39 [dnl
40 AC_REQUIRE([AC_CANONICAL_HOST])dnl
41 AC_ARG_ENABLE([opencl],
42 [AS_HELP_STRING([--enable-opencl],
43 [use OpenCL])],
44 [enable_opencl=$enableval],
45 [enable_opencl='no'])
46 if test x"$enable_opencl" != xno ; then
47 CL_CPPFLAGS=""
48 AC_CHECK_HEADERS([CL/cl.h OpenCL/cl.h], [HAVE_CL_H="yes"; break], [HAVE_CL_H="no"])
49 if test x"$HAVE_CL_H" = xno ; then
50 # check for AMD's SDK
51 AC_MSG_CHECKING([for AMD's SDK cl.h])
52 if test -d /opt/AMDAPP/include/CL ; then
53 HAVE_CL_H="yes"
54 AC_DEFINE([HAVE_CL_CL_H])
55 CL_CPPFLAGS="-I/opt/AMDAPP/include"
56 fi
57 AC_MSG_RESULT([$HAVE_CL_H])
58 fi
59 if test x"$HAVE_CL_H" = xno ; then
60 # check for NVIDIA's SDK
61 AC_MSG_CHECKING([for NVIDIA's SDK cl.h])
62 if test -d /usr/local/cuda/include/CL ; then
63 HAVE_CL_H="yes"
64 AC_DEFINE([HAVE_CL_CL_H])
65 CL_CPPFLAGS="-I/usr/local/cuda/include"
66 elif test -d /usr/local/cuda-6.5/include/CL ; then
67 HAVE_CL_H="yes"
68 AC_DEFINE([HAVE_CL_CL_H])
69 CL_CPPFLAGS="-I/usr/local/cuda-6.5/include"
70 elif test -d /usr/local/cuda-6.0/include/CL ; then
71 HAVE_CL_H="yes"
72 AC_DEFINE([HAVE_CL_CL_H])
73 CL_CPPFLAGS="-I/usr/local/cuda-6.0/include"
74 elif test -d /usr/local/cuda-5.5/include/CL ; then
75 HAVE_CL_H="yes"
76 AC_DEFINE([HAVE_CL_CL_H])
77 CL_CPPFLAGS="-I/usr/local/cuda-5.5/include"
78 fi
79 AC_MSG_RESULT([$HAVE_CL_H])
80 fi
81 if test x"$HAVE_CL_H" = xno ; then
82 no_cl=yes
83 AC_MSG_WARN([no OpenCL headers found])
84 CL_ENABLED=false
85 CL_VERSION=0
86 else
87 #
88 # First we check for macOS, since OpenCL is standard there
89 #
90 CL_LIBS=""
91 AC_MSG_CHECKING([for OpenCL library])
92 case "$host_os" in
93 darwin*) # On macOS we check for installed frameworks
94 AX_CHECK_FRAMEWORK([OpenCL], [
95 CL_LIBS="-framework OpenCL"
96 no_cl=no
97 AC_MSG_RESULT(yes)
98 CL_ENABLED=true
99 CL_VERSION=1
100 ]
101 ,
102 [
103 no_cl=yes
104 AC_MSG_RESULT(no)
105 CL_ENABLED=false
106 CL_VERSION=0
107 ])
108 ;;
109 *)
110 save_LIBS=$LIBS
111 save_CFLAGS=$CFLAGS
112 CFLAGS=$CL_CPPFLAGS
113 LIBS="$save_LIBS -L/usr/lib64/nvidia -L/usr/lib/nvidia -lOpenCL"
114 AC_LINK_IFELSE(
115 [AC_LANG_PROGRAM([
116 #ifdef HAVE_OPENCL_CL_H
117 #include <OpenCL/cl.h>
118 #elif defined(HAVE_CL_CL_H)
119 #include <CL/cl.h>
120 #endif
121 #include <stddef.h>
122 ],[
123 clGetPlatformIDs(0, NULL, NULL);
124 ])],[
125 no_cl=no
126 AC_MSG_RESULT(yes)
127 CL_ENABLED=true
128 CL_VERSION=1
129 CL_LIBS="-L/usr/lib64/nvidia -L/usr/lib/nvidia -lOpenCL"
130 ],[
131 no_cl=yes
132 AC_MSG_RESULT(no)
133 CL_ENABLED=false
134 CL_VERSION=0
135 ])
136
137 LIBS=$save_LIBS
138 CFLAGS=$save_CFLAGS
139 ;;
140 esac
141 fi
142 else
143 no_cl=yes
144 AC_MSG_CHECKING([for OpenCL library])
145 AC_MSG_RESULT(disabled)
146 CL_ENABLED=false
147 CL_VERSION=0
148 fi
149 ])