summaryrefslogtreecommitdiff
path: root/m4/ax_have_opencl.m4
blob: 678193c2cd745bec897a4bd78f8cd3328b0992be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# -*- mode: autoconf -*-
#
# AX_HAVE_OPENCL
#
# Check for an OpenCL implementation.  If CL is found, HAVE_OPENCL is defined
# and the required CPP and linker flags are included in the output variables
# "CL_CPPFLAGS" and "CL_LIBS", respectively.  If no usable CL implementation is
# found then "no_cl" is set to "yes" (otherwise it is set to "no").
#
# If the header <CL/OpenCL.h> is found, "HAVE_CL_OPENCL_H" is defined.  If the
# header <OpenCL/OpenCL.h> is found, HAVE_OPENCL_OPENCL_H is defined.  These
# preprocessor definitions may not be mutually exclusive.
#
# This macro first checks /usr/include and /usr/lib for OpenCL support; if it is not
# found in those locations, then it checks in the standard installation locations
# for AMD's (/opt/AMDAPP) and NVIDIA's (/usr/local/cuda) SDKs.
#
# 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_HAVE_OPENCL],
[dnl
  AC_REQUIRE([AC_CANONICAL_HOST])dnl
  AC_ARG_ENABLE([opencl],
  [AS_HELP_STRING([--disable-opencl],
                  [do not use OpenCL])],
  [enable_opencl=$enableval],
  [enable_opencl='yes'])
  if test x"$enable_opencl" != xno ; then
    CPPFLAGS_CL=""
    AC_CHECK_HEADERS([CL/cl.h OpenCL/cl.h], [HAVE_CL_H="yes"; break], [HAVE_CL_H="no"])
    if test x"$HAVE_CL_H" = xno ; then
      # check for AMD's SDK
      AC_MSG_CHECKING([for AMD's SDK cl.h])
      if test -d /opt/AMDAPP/include/CL ; then
        HAVE_CL_H="yes"
        AC_DEFINE([HAVE_CL_CL_H])
        CPPFLAGS_CL="-I/opt/AMDAPP/include"
      fi
      AC_MSG_RESULT([$HAVE_CL_H])
    fi
    if test x"$HAVE_CL_H" = xno ; then
      # check for NVIDIA's SDK
      AC_MSG_CHECKING([for NVIDIA's SDK cl.h])
      if test -d /usr/local/cuda/include/CL ; then
        HAVE_CL_H="yes"
        AC_DEFINE([HAVE_CL_CL_H])
        CPPFLAGS_CL="-I/usr/local/cuda/include"
      elif test -d /usr/local/cuda-6.5/include/CL ; then
        HAVE_CL_H="yes"
        AC_DEFINE([HAVE_CL_CL_H])
        CPPFLAGS_CL="-I/usr/local/cuda-6.5/include"
      elif test -d /usr/local/cuda-6.0/include/CL ; then
        HAVE_CL_H="yes"
        AC_DEFINE([HAVE_CL_CL_H])
        CPPFLAGS_CL="-I/usr/local/cuda-6.0/include"
      elif test -d /usr/local/cuda-5.5/include/CL ; then
        HAVE_CL_H="yes"
        AC_DEFINE([HAVE_CL_CL_H])
        CPPFLAGS_CL="-I/usr/local/cuda-5.5/include"
      fi
      AC_MSG_RESULT([$HAVE_CL_H])
    fi
    if test x"$HAVE_CL_H" = xno ; then
      no_cl=yes
      AC_MSG_WARN([no OpenCL headers found])
      CL_ENABLED=false
      CL_VERSION=0
    else
      #
      # First we check for Mac OS X, since OpenCL is standard there
      #
      LIBS_CL="none"
      AC_MSG_CHECKING([for OpenCL library])
      case "$host_os" in
        darwin*) # On Mac OS X we check for installed frameworks
        AX_CHECK_FRAMEWORK([OpenCL], [
          LIBS_CL="-framework OpenCL"
          no_cl=no
          AC_MSG_RESULT(yes)
          CL_ENABLED=true
          CL_VERSION=1
        ]
        ,
        [
          no_cl=yes
          AC_MSG_RESULT(no)
          CL_ENABLED=false
          CL_VERSION=0
        ])
      ;;
      *)
        save_LIBS=$LIBS
        save_CFLAGS=$CFLAGS
        CFLAGS=$CPPFLAGS_CL
        LIBS="$save_LIBS -L/usr/lib64/nvidia -L/usr/lib/nvidia -lOpenCL"
        AC_LINK_IFELSE(
        [AC_LANG_PROGRAM([
          #ifdef HAVE_OPENCL_CL_H
            #include <OpenCL/cl.h>
          #elif defined(HAVE_CL_CL_H)
            #include <CL/cl.h>
          #endif
          #include <stddef.h>
        ],[
          clGetPlatformIDs(0, NULL, NULL);
        ])],[
          no_cl=no
          AC_MSG_RESULT(yes)
          CL_ENABLED=true
          CL_VERSION=1
          LIBS_CL="$save_LIBS -L/usr/lib64/nvidia -L/usr/lib/nvidia -lOpenCL"
        ],[
          no_cl=yes
          AC_MSG_RESULT(no)
          CL_ENABLED=false
          CL_VERSION=0
        ])
    
        LIBS=$save_LIBS
        CFLAGS=$save_CFLAGS
      ;;
      esac
    fi
  else
    no_cl=yes
    AC_MSG_CHECKING([for OpenCL library])
    AC_MSG_RESULT(disabled)
    CL_ENABLED=false
    CL_VERSION=0
  fi
])