浏览代码

Configuration and compilation system: fix OpenCL settings

  - First search in the current environment or in directory specified on command line --with-opencl-dir
  - If not found, search in some default locations ("/usr/local/cuda" "/c/cuda" "/cygdrive/c/cuda" "/opt/cuda")

  - compilation and linking flags are all defined in STARPU_OPENCL_LDFLAGS and STARPU_OPENCL_CPPFLAGS which must be specifically added in Makefile.am
Nathalie Furmento 14 年之前
父节点
当前提交
4231064e60
共有 9 个文件被更改,包括 92 次插入54 次删除
  1. 75 38
      configure.ac
  2. 2 2
      examples/Makefile.am
  3. 4 3
      examples/starpufft/Makefile.am
  4. 2 2
      examples/stencil/Makefile.am
  5. 2 2
      mpi/Makefile.am
  6. 1 1
      src/Makefile.am
  7. 2 2
      tests/Makefile.am
  8. 2 2
      tests/opt/Makefile.am
  9. 2 2
      tools/Makefile.am

+ 75 - 38
configure.ac

@@ -364,7 +364,7 @@ if test x$enable_cuda = xyes; then
 #		*-*darwin*) AC_HAVE_LIBRARY([stdc++], []) ;;
 #		#*-*darwin*) AC_HAVE_LIBRARY([stdc++], [STARPU_CUDA_LDFLAGS="$STARPU_CUDA_LDFLAGS -lstdc++"]) ;;
 #	esac
-	STARPU_CUDA_LDFLAGS="$STARPU_CUDA_LDFLAGS -lcuda"
+	STARPU_CUDA_LDFLAGS="$STARPU_CUDA_LDFLAGS -lcuda -lcufft"
 
         if test "$F77" = "gfortran" ; then
             STARPU_CUDA_LDFLAGS="$STARPU_CUDA_LDFLAGS -lgfortran"
@@ -454,7 +454,6 @@ AC_CHECK_TYPE(cufftDoubleComplex,
 AM_CONDITIONAL(STARPU_HAVE_CUFFTDOUBLECOMPLEX, test x$have_cufftdoublecomplex = xyes)
 if test x$have_cufftdoublecomplex = xyes; then
 	AC_DEFINE(STARPU_HAVE_CUFFTDOUBLECOMPLEX, [1], [cufftDoubleComplex is available])
-        STARPU_CUDA_LDFLAGS="$STARPU_CUDA_LDFLAGS -lcufft"
 fi
 
 # The CURAND library is only available since CUDA 3.2
@@ -491,6 +490,66 @@ AC_DEFINE_UNQUOTED(STARPU_MAXOPENCLDEVS, [$nmaxopencldev],
 AC_ARG_ENABLE(opencl, [AS_HELP_STRING([--disable-opencl],
 		[do not use OpenCL device(s)])],, [enable_opencl=maybe])
 
+AC_DEFUN([STARPU_CHECK_OPENCL],
+[
+    __opencl_dir=$1
+    __opencl_include_dir=$2
+    __opencl_lib_dir=$3
+
+    if test "$__opencl_dir" != "no" ; then
+	AC_MSG_CHECKING(whether OpenCL is available in $__opencl_dir)
+    else
+	AC_MSG_CHECKING(whether OpenCL is available)
+    fi
+    AC_MSG_RESULT()
+
+    if test "$__opencl_include_dir" = "no" -a "$__opencl_dir" != "no" ; then
+        __opencl_include_dir="$__opencl_dir/include"
+    fi
+    if test "$__opencl_lib_dir" = "no" -a "$__opencl_dir" != "no" ; then
+        __opencl_lib_dir="$__opencl_dir/lib"
+    fi
+
+    SAVED_CPPFLAGS="$CPPFLAGS"
+    SAVED_LDFLAGS="${LDFLAGS}"
+
+    if test "$__opencl_include_dir" != "no" ; then
+        CPPFLAGS="${CPPFLAGS} -I$__opencl_include_dir"
+    fi
+    AC_CHECK_HEADER([CL/cl.h],[have_valid_opencl=yes],[have_valid_opencl=no])
+    unset ac_cv_header_CL_cl_h
+
+    if test "$have_valid_opencl" = "yes" ; then
+	if test "$__opencl_lib_dir" != "no"; then
+	    LDFLAGS="${SAVED_LDFLAGS} -L$__opencl_lib_dir"
+        fi
+	AC_HAVE_LIBRARY([OpenCL],[have_valid_opencl=yes],[have_valid_opencl=no])
+        unset ac_cv_lib_OpenCL_main
+        if test "$have_valid_opencl" = "no" ; then
+            if test "$3" = "no" -a "$__opencl_dir" != "no" ; then
+                __opencl_lib_dir="$__opencl_dir/lib64"
+	        LDFLAGS="${SAVED_LDFLAGS} -L$__opencl_lib_dir"
+	        AC_HAVE_LIBRARY([OpenCL],[have_valid_opencl=yes],[have_valid_opencl=no])
+                unset ac_cv_lib_OpenCL_main
+            fi
+        fi
+    fi
+
+    CPPFLAGS="${SAVED_CPPFLAGS}"
+    LDFLAGS="${SAVED_LDFLAGS}"
+
+    if test "$have_valid_opencl" = "yes" -a "$__opencl_include_dir" != "no"; then
+        STARPU_OPENCL_CPPFLAGS="-I$__opencl_include_dir"
+    fi
+    if test "$have_valid_opencl" = "yes" ; then
+        if test "$__opencl_lib_dir" != "no"; then
+            STARPU_OPENCL_LDFLAGS="-L$__opencl_lib_dir"
+        fi
+        STARPU_OPENCL_LDFLAGS="${STARPU_OPENCL_LDFLAGS} -lOpenCL"
+    fi
+
+])
+
 #AC_MSG_CHECKING(whether OpenCL is available)
 AC_ARG_WITH(opencl-dir,
 	[AS_HELP_STRING([--with-opencl-dir=<path>],
@@ -520,41 +579,19 @@ AC_ARG_WITH(opencl-lib-dir,
 	], [opencl_lib_dir=no])
 
 if test x$enable_opencl = xyes -o x$enable_opencl = xmaybe; then
-
-	if test x$opencl_include_dir = xno; then
-	        if test x$opencl_dir != xno; then
-		    opencl_include_dir="$opencl_dir/include"
-		fi
-	fi
-
-	if test -d "$opencl_include_dir" && test "$opencl_include_dir" != "/usr/include" ; then
-		CPPFLAGS="${CPPFLAGS} -I$opencl_include_dir "
-	fi
-
-	# do we have a valid OpenCL setup ?
-	have_valid_opencl=yes
-	AC_CHECK_HEADER([CL/cl.h],,[have_valid_opencl=no])
-
-	# we are looking for the proper option in LDFLAGS, so we save the
-	# current value of LDFLAGS so that we can add new things in it and
-	# restore it in case it's not working.
-	SAVED_LDFLAGS="${LDFLAGS}"
-
-	if test x$opencl_lib_dir = xno; then
-	        if test x$opencl_dir != xno; then
-		# Default location
-		    opencl_lib_dir="$opencl_dir/lib/"
-		fi
-	fi
-
-	if test -d "$opencl_lib_dir"; then
-		LDFLAGS="${SAVED_LDFLAGS} -L$opencl_lib_dir "
-	fi
-	AC_HAVE_LIBRARY([OpenCL],[],[have_valid_opencl=no])
+    	STARPU_CHECK_OPENCL($opencl_dir, $opencl_include_dir, $opencl_lib_dir)
+        if test "$have_valid_opencl" = "no" ; then
+            for f in "/usr/local/cuda" "/c/cuda" "/cygdrive/c/cuda" "/opt/cuda" ; do
+    	        STARPU_CHECK_OPENCL($f, "no", "no")
+                if test "$have_valid_opencl" = "yes" ; then
+                    break
+                fi
+            done
+        fi
 
 	# in case OpenCL was explicitely required, but is not available, this is an error
 	if test x$enable_opencl = xyes -a x$have_valid_opencl = no; then
-		AC_MSG_ERROR([cannot find OpenCL])
+	    AC_MSG_ERROR([cannot find OpenCL])
 	fi
 
 	# now we enable OpenCL if and only if a proper setup is available
@@ -565,12 +602,12 @@ AC_MSG_CHECKING(whether OpenCL should be used)
 AC_MSG_RESULT($enable_opencl)
 AC_SUBST(STARPU_USE_OPENCL, $enable_opencl)
 AM_CONDITIONAL(STARPU_USE_OPENCL, test x$enable_opencl = xyes)
-if test x$enable_opencl = xyes; then
+if test x$enable_opencl = xyes ; then
 	AC_DEFINE(STARPU_USE_OPENCL, [1], [OpenCL support is activated])
-	CPPFLAGS="${CPPFLAGS} -DSTARPU_OPENCL_DATADIR=${datarootdir}/starpu/opencl"
+	STARPU_OPENCL_CPPFLAGS="${STARPU_OPENCL_CPPFLAGS} -DSTARPU_OPENCL_DATADIR=${datarootdir}/starpu/opencl"
         AC_SUBST(STARPU_OPENCL_DATAdir, "$(eval echo ${datarootdir}/starpu/opencl/examples)")
-else
-        LDFLAGS="${SAVED_LDFLAGS}"
+        AC_SUBST(STARPU_OPENCL_CPPFLAGS)
+        AC_SUBST(STARPU_OPENCL_LDFLAGS)
 fi
 
 ###############################################################################

+ 2 - 2
examples/Makefile.am

@@ -14,10 +14,10 @@
 #
 # See the GNU Lesser General Public License in COPYING.LGPL for more details.
 
-AM_CFLAGS = $(HWLOC_CFLAGS) -Wall $(STARPU_CUDA_CPPFLAGS)
+AM_CFLAGS = $(HWLOC_CFLAGS) -Wall $(STARPU_CUDA_CPPFLAGS) $(STARPU_OPENCL_CPPFLAGS)
 LIBS = $(top_builddir)/src/libstarpu.la $(HWLOC_LIBS) @LIBS@
 AM_CPPFLAGS = -I$(top_srcdir)/include/ -I$(top_srcdir)/examples/ -I$(top_builddir)/include
-AM_LDFLAGS = $(STARPU_CUDA_LDFLAGS)
+AM_LDFLAGS = $(STARPU_CUDA_LDFLAGS) $(STARPU_OPENCL_LDFLAGS)
 
 TESTS	=	$(check_PROGRAMS)
 

+ 4 - 3
examples/starpufft/Makefile.am

@@ -1,7 +1,7 @@
 # StarPU --- Runtime system for heterogeneous multicore architectures.
 #
 # Copyright (C) 2009, 2010  Université de Bordeaux 1
-# Copyright (C) 2010  Centre National de la Recherche Scientifique
+# Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
 #
 # StarPU is free software; you can redistribute it and/or modify
 # it under the terms of the GNU Lesser General Public License as published by
@@ -14,7 +14,8 @@
 #
 # See the GNU Lesser General Public License in COPYING.LGPL for more details.
 #
-AM_CPPFLAGS = -I$(top_srcdir)/include/ -I$(top_builddir)/include $(STARPU_CUDA_CPPFLAGS)
+AM_CPPFLAGS = -I$(top_srcdir)/include/ -I$(top_builddir)/include $(STARPU_CUDA_CPPFLAGS) $(STARPU_OPENCL_CPPFLAGS)
+AM_LDFLAGS = $(STARPU_CUDA_LDFLAGS) $(STARPU_OPENCL_LDFLAGS)
 
 lib_LTLIBRARIES = libstarpufft.la
 
@@ -55,7 +56,7 @@ libstarpufft_la_SOURCES += cuda_kernels.cu
 am_libstarpufft_la_OBJECTS += cuda_kernels.o starpufft.lo
 endif
 
-libstarpufft_la_LIBADD += $(STARPU_CUDA_LDFLAGS)
+libstarpufft_la_LIBADD +=  $(STARPU_CUDA_LDFLAGS)
 endif
 
 check_PROGRAMS = testf

+ 2 - 2
examples/stencil/Makefile.am

@@ -13,10 +13,10 @@
 #
 # See the GNU Lesser General Public License in COPYING.LGPL for more details.
 
-AM_CFLAGS = $(HWLOC_CFLAGS) $(STARPU_CUDA_CPPFLAGS)
+AM_CFLAGS = $(HWLOC_CFLAGS) $(STARPU_CUDA_CPPFLAGS) $(STARPU_OPENCL_CPPFLAGS)
 LIBS = $(top_builddir)/src/libstarpu.la $(HWLOC_LIBS) @LIBS@
 AM_CPPFLAGS = -I$(top_srcdir)/include/ -I$(top_srcdir)/examples/ -I$(top_builddir)/include
-AM_LDFLAGS = $(STARPU_CUDA_LDFLAGS)
+AM_LDFLAGS = $(STARPU_CUDA_LDFLAGS) $(STARPU_OPENCL_LDFLAGS)
 
 if USE_MPI
 LIBS += $(top_builddir)/mpi/libstarpumpi.la

+ 2 - 2
mpi/Makefile.am

@@ -58,10 +58,10 @@ NVCCFLAGS += -I$(top_srcdir)/include/ -I$(top_builddir)/include $(HWLOC_CFLAGS)
 	$(NVCC) $< -c -o $@ --compiler-options -fno-strict-aliasing  $(NVCCFLAGS) -I$(top_srcdir)/include/  -I$(top_builddir)/include/
 endif
 
-AM_CFLAGS = $(HWLOC_CFLAGS) -Wall $(STARPU_CUDA_CPPFLAGS)
+AM_CFLAGS = $(HWLOC_CFLAGS) -Wall $(STARPU_CUDA_CPPFLAGS) $(STARPU_OPENCL_CPPFLAGS)
 LIBS = $(top_builddir)/src/libstarpu.la $(HWLOC_LIBS) @LIBS@
 AM_CPPFLAGS = -I$(top_srcdir)/include/ -I$(top_srcdir)/mpi/ -I$(top_srcdir)/src/  -I$(top_srcdir)/examples/ -I$(top_builddir)/src -I$(top_builddir)/include
-AM_LDFLAGS = $(STARPU_CUDA_LDFLAGS)
+AM_LDFLAGS = $(STARPU_CUDA_LDFLAGS) $(STARPU_OPENCL_LDFLAGS)
 
 lib_LTLIBRARIES = libstarpumpi.la
 

+ 1 - 1
src/Makefile.am

@@ -48,7 +48,7 @@ lib_LTLIBRARIES = libstarpu.la
 
 libstarpu_la_CPPFLAGS = -I$(top_srcdir)/include/
 
-libstarpu_la_CFLAGS = -W -Wall -Wextra $(HWLOC_CFLAGS) $(STARPU_CUDA_CPPFLAGS)
+libstarpu_la_CFLAGS = -W -Wall -Wextra $(HWLOC_CFLAGS) $(STARPU_CUDA_CPPFLAGS) $(STARPU_OPENCL_CPPFLAGS)
 libstarpu_la_LIBADD = -lm $(HWLOC_LIBS)
 libstarpu_la_LDFLAGS = $(ldflags) -version-number 0:0:0 -no-undefined
 

+ 2 - 2
tests/Makefile.am

@@ -15,10 +15,10 @@
 #
 # See the GNU Lesser General Public License in COPYING.LGPL for more details.
 
-AM_CFLAGS = $(HWLOC_CFLAGS) -Wall $(STARPU_CUDA_CPPFLAGS)
+AM_CFLAGS = $(HWLOC_CFLAGS) -Wall $(STARPU_CUDA_CPPFLAGS) $(STARPU_OPENCL_CPPFLAGS)
 LIBS = $(top_builddir)/src/libstarpu.la $(HWLOC_LIBS) @LIBS@
 AM_CPPFLAGS = -I$(top_srcdir)/include/ -I$(top_srcdir)/src/
-AM_LDFLAGS = $(STARPU_CUDA_LDFLAGS)
+AM_LDFLAGS = $(STARPU_CUDA_LDFLAGS) $(STARPU_OPENCL_LDFLAGS)
 
 EXTRA_DIST =					\
 	microbenchs/null_kernel_gordon.c	\

+ 2 - 2
tests/opt/Makefile.am

@@ -15,10 +15,10 @@
 #
 # See the GNU Lesser General Public License in COPYING.LGPL for more details.
 
-AM_CFLAGS = $(HWLOC_CFLAGS) -Wall $(STARPU_CUDA_CPPFLAGS)
+AM_CFLAGS = $(HWLOC_CFLAGS) -Wall $(STARPU_CUDA_CPPFLAGS) $(STARPU_OPENCL_CPPFLAGS)
 LIBS = $(top_builddir)/src/libstarpu.la $(HWLOC_LIBS) @LIBS@
 AM_CPPFLAGS = -I$(top_srcdir)/include/ -I$(top_srcdir)/src/
-AM_LDFLAGS = $(STARPU_CUDA_LDFLAGS)
+AM_LDFLAGS = $(STARPU_CUDA_LDFLAGS) $(STARPU_OPENCL_LDFLAGS)
 
 optbindir = $(libdir)/starpu/tests
 optbin_PROGRAMS =

+ 2 - 2
tools/Makefile.am

@@ -16,10 +16,10 @@
 
 SUBDIRS =
 
-AM_CFLAGS = $(HWLOC_CFLAGS) $(STARPU_CUDA_CPPFLAGS)
+AM_CFLAGS = $(HWLOC_CFLAGS) $(STARPU_CUDA_CPPFLAGS) $(STARPU_OPENCL_CPPFLAGS)
 LIBS = $(top_builddir)/src/libstarpu.la $(HWLOC_LIBS) @LIBS@
 AM_CPPFLAGS = -I$(top_srcdir)/include/ -I$(top_srcdir)/tools/ -I$(top_srcdir)/mpi/ -I$(top_builddir)/src -I$(top_srcdir)/src
-AM_LDFLAGS = $(STARPU_CUDA_LDFLAGS)
+AM_LDFLAGS = $(STARPU_CUDA_LDFLAGS) $(STARPU_OPENCL_LDFLAGS)
 
 bin_PROGRAMS =
 dist_bin_SCRIPTS =