Browse Source

Load OpenCL library dynamically, to support building without any vendor-specific files

Luke Dashjr 13 years ago
parent
commit
b934937c94
7 changed files with 422 additions and 82 deletions
  1. 5 5
      CL/cl.h
  2. 2 2
      Makefile.am
  3. 14 64
      configure.ac
  4. 221 0
      driver-opencl.c
  5. 1 5
      miner.h
  6. 178 1
      ocl.c
  7. 1 5
      ocl.h

+ 5 - 5
CL/cl.h

@@ -24,11 +24,7 @@
 #ifndef __OPENCL_CL_H
 #ifndef __OPENCL_CL_H
 #define __OPENCL_CL_H
 #define __OPENCL_CL_H
 
 
-#ifdef __APPLE__
-#include <OpenCL/cl_platform.h>
-#else
-#include <CL/cl_platform.h>
-#endif	
+#include "cl_platform.h"
 
 
 #ifdef __cplusplus
 #ifdef __cplusplus
 extern "C" {
 extern "C" {
@@ -561,6 +557,8 @@ typedef struct _cl_buffer_region {
 
 
 /********************************************************************************************************/
 /********************************************************************************************************/
 
 
+#ifndef OMIT_OPENCL_API
+
 /* Platform API */
 /* Platform API */
 extern CL_API_ENTRY cl_int CL_API_CALL
 extern CL_API_ENTRY cl_int CL_API_CALL
 clGetPlatformIDs(cl_uint          /* num_entries */,
 clGetPlatformIDs(cl_uint          /* num_entries */,
@@ -1231,6 +1229,8 @@ clGetExtensionFunctionAddressForPlatform(cl_platform_id /* platform */,
     clGetExtensionFunctionAddress(const char * /* func_name */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
     clGetExtensionFunctionAddress(const char * /* func_name */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
 #endif /* CL_USE_DEPRECATED_OPENCL_1_2_APIS */
 #endif /* CL_USE_DEPRECATED_OPENCL_1_2_APIS */
 
 
+#endif /* OMIT_OPENCL_API */
+
 #ifdef __cplusplus
 #ifdef __cplusplus
 }
 }
 #endif
 #endif

+ 2 - 2
Makefile.am

@@ -22,10 +22,10 @@ bin_SCRIPTS	= *.cl
 
 
 cgminer_LDFLAGS	= $(PTHREAD_FLAGS)
 cgminer_LDFLAGS	= $(PTHREAD_FLAGS)
 cgminer_LDADD	= $(DLOPEN_FLAGS) @LIBCURL_LIBS@ @JANSSON_LIBS@ @PTHREAD_LIBS@ \
 cgminer_LDADD	= $(DLOPEN_FLAGS) @LIBCURL_LIBS@ @JANSSON_LIBS@ @PTHREAD_LIBS@ \
-		  @OPENCL_LIBS@ @NCURSES_LIBS@ @PDCURSES_LIBS@ @WS2_LIBS@ \
+		  @NCURSES_LIBS@ @PDCURSES_LIBS@ @WS2_LIBS@ \
 		  @UDEV_LIBS@ @USB_LIBS@ \
 		  @UDEV_LIBS@ @USB_LIBS@ \
 		  @MATH_LIBS@ lib/libgnu.a ccan/libccan.a
 		  @MATH_LIBS@ lib/libgnu.a ccan/libccan.a
-cgminer_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib @OPENCL_FLAGS@
+cgminer_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib
 
 
 # common sources
 # common sources
 cgminer_SOURCES := cgminer.c
 cgminer_SOURCES := cgminer.c

+ 14 - 64
configure.ac

@@ -65,7 +65,6 @@ PTHREAD_FLAGS="-lpthread"
 USB_LIBS=""
 USB_LIBS=""
 USB_FLAGS=""
 USB_FLAGS=""
 DLOPEN_FLAGS="-ldl"
 DLOPEN_FLAGS="-ldl"
-OPENCL_LIBS="-lOpenCL"
 WS2_LIBS=""
 WS2_LIBS=""
 MATH_LIBS="-lm"
 MATH_LIBS="-lm"
 
 
@@ -95,25 +94,13 @@ case $target in
     ;;
     ;;
   powerpc-*-darwin*)
   powerpc-*-darwin*)
     CFLAGS="$CFLAGS -faltivec"
     CFLAGS="$CFLAGS -faltivec"
-    OPENCL_LIBS=""
     PTHREAD_FLAGS=""
     PTHREAD_FLAGS=""
     ;;
     ;;
   *-*-darwin*)
   *-*-darwin*)
-    OPENCL_LIBS="-framework OpenCL"
     PTHREAD_FLAGS=""
     PTHREAD_FLAGS=""
 	;;
 	;;
 esac
 esac
 
 
-if test "x$ATISTREAMSDKROOT" != x; then
-	if test "x$have_x86_64" = xtrue; then
-		ATI_STREAM_ARCH_DIR=x86_64
-	else
-		ATI_STREAM_ARCH_DIR=x86
-	fi
-	OPENCL_FLAGS="-I$ATISTREAMSDKROOT/include $OPENCL_FLAGS"
-	OPENCL_LIBS="-L$ATISTREAMSDKROOT/lib/$ATI_STREAM_ARCH_DIR $OPENCL_LIBS"
-fi
-
 cpumining="no"
 cpumining="no"
 
 
 AC_ARG_ENABLE([cpumining],
 AC_ARG_ENABLE([cpumining],
@@ -128,39 +115,13 @@ AM_CONDITIONAL([HAS_CPUMINE], [test x$cpumining = xyes])
 opencl="yes"
 opencl="yes"
 
 
 AC_ARG_ENABLE([opencl],
 AC_ARG_ENABLE([opencl],
-	[AC_HELP_STRING([--disable-opencl],[Override detection and disable building with opencl])],
+	[AC_HELP_STRING([--disable-opencl],[Build without support for OpenCL (default enabled)])],
 	[opencl=$enableval]
 	[opencl=$enableval]
 	)
 	)
-if test "x$opencl" != xno; then
-	# Check for OpenCL (the long way needed on mingw32 due to calling conventions)
-	AC_MSG_CHECKING([for OpenCL])
-	SAVED_LIBS=$LIBS
-	SAVED_CFLAGS=$CFLAGS
-	LIBS="$LIBS $OPENCL_LIBS"
-	CFLAGS="$CFLAGS $OPENCL_FLAGS"
-	AC_LINK_IFELSE(
-	[AC_LANG_PROGRAM([[
-		#ifdef __APPLE_CC__
-		#include <OpenCL/opencl.h>
-		#else
-		#include <CL/cl.h>
-		#endif
-	]],
-	[[return clSetKernelArg(0, 0, 0, 0); ]])],
-	[AC_MSG_RESULT(yes)
-	AC_DEFINE([HAVE_OPENCL], [1], [Defined to 1 if OpenCL is present on the system.])
-	found_opencl=1
-	],
-	[AC_MSG_RESULT(no)
-	OPENCL_FLAGS=
-	OPENCL_LIBS=
-	found_opencl=0])
-	LIBS=$SAVED_LIBS
-	CFLAGS=$SAVED_CFLAGS
-else
-	OPENCL_FLAGS=""
-	OPENCL_LIBS=""
+if test "x$opencl" = xyes; then
+	AC_DEFINE([HAVE_OPENCL], [1], [Defined to 1 if OpenCL support is wanted])
 fi
 fi
+AM_CONDITIONAL([HAVE_OPENCL], [test x$opencl = xyes])
 
 
 AC_CHECK_LIB(pthread, pthread_create, ,
 AC_CHECK_LIB(pthread, pthread_create, ,
         AC_MSG_ERROR([Could not find pthread library - please install libpthread]))
         AC_MSG_ERROR([Could not find pthread library - please install libpthread]))
@@ -173,7 +134,7 @@ AC_ARG_ENABLE([adl],
 	[adl=$enableval]
 	[adl=$enableval]
 	)
 	)
 
 
-if test "$found_opencl" = 1; then
+if test "x$opencl" = xyes; then
 	if test "x$adl" != xno; then
 	if test "x$adl" != xno; then
 		AC_CHECK_FILE([ADL_SDK/adl_sdk.h], have_adl=true, have_adl=false,)
 		AC_CHECK_FILE([ADL_SDK/adl_sdk.h], have_adl=true, have_adl=false,)
 		if test x$have_adl = xtrue
 		if test x$have_adl = xtrue
@@ -371,8 +332,6 @@ AC_DEFINE_UNQUOTED([DIAKGCN_KERNNAME], ["diakgcn120223"], [Filename for diakgcn
 AC_DEFINE_UNQUOTED([DIABLO_KERNNAME], ["diablo120328"], [Filename for diablo kernel])
 AC_DEFINE_UNQUOTED([DIABLO_KERNNAME], ["diablo120328"], [Filename for diablo kernel])
 
 
 
 
-AC_SUBST(OPENCL_LIBS)
-AC_SUBST(OPENCL_FLAGS)
 AC_SUBST(JANSSON_LIBS)
 AC_SUBST(JANSSON_LIBS)
 AC_SUBST(PTHREAD_FLAGS)
 AC_SUBST(PTHREAD_FLAGS)
 AC_SUBST(DLOPEN_FLAGS)
 AC_SUBST(DLOPEN_FLAGS)
@@ -410,33 +369,24 @@ echo
 
 
 echo "  curses.TUI...........: $cursesmsg"
 echo "  curses.TUI...........: $cursesmsg"
 
 
-if test "x$opencl" != xno; then
-	if test $found_opencl = 1; then
-		echo "  OpenCL...............: FOUND. GPU mining support enabled"
-	else
-		echo "  OpenCL...............: NOT FOUND. GPU mining support DISABLED"
-		if test "x$cpumining$bitforce$icarus$ztex" = xnononono; then
-			AC_MSG_ERROR([No mining configured in])
-		fi
-	fi
+echo
+
+if test "x$opencl" = xyes; then
+	echo "  OpenCL...............: Enabled"
 else
 else
-	echo "  OpenCL...............: Detection overrided. GPU mining support DISABLED"
-	if test "x$cpumining$bitforce$icarus$ztex" = xnononono; then
-		AC_MSG_ERROR([No mining configured in])
-	fi
+	echo "  OpenCL...............: Disabled"
 fi
 fi
 
 
 if test "x$adl" != xno; then
 if test "x$adl" != xno; then
 	if test x$have_adl = xtrue; then
 	if test x$have_adl = xtrue; then
-		echo "  ADL..................: SDK found, GPU monitoring support enabled"
+		echo "    ADL................: SDK found, GPU monitoring support enabled"
 	else
 	else
-		echo "  ADL..................: SDK NOT found, GPU monitoring support DISABLED"
+		echo "    ADL................: SDK NOT found, GPU monitoring support DISABLED"
 	fi
 	fi
 else
 else
-	echo "  ADL..................: Detection overrided. GPU monitoring support DISABLED"
+	echo "    ADL................: Detection overrided. GPU monitoring support DISABLED"
 fi
 fi
 
 
-echo
 if test "x$bitforce" = xyes; then
 if test "x$bitforce" = xyes; then
 	echo "  BitForce.FPGAs.......: Enabled"
 	echo "  BitForce.FPGAs.......: Enabled"
 else
 else
@@ -470,7 +420,7 @@ echo "Compilation............: make (or gmake)"
 echo "  CPPFLAGS.............: $CPPFLAGS"
 echo "  CPPFLAGS.............: $CPPFLAGS"
 echo "  CFLAGS...............: $CFLAGS"
 echo "  CFLAGS...............: $CFLAGS"
 echo "  LDFLAGS..............: $LDFLAGS $PTHREAD_FLAGS $USB_FLAGS"
 echo "  LDFLAGS..............: $LDFLAGS $PTHREAD_FLAGS $USB_FLAGS"
-echo "  LDADD................: $DLOPEN_FLAGS $LIBCURL_LIBS $JANSSON_LIBS $PTHREAD_LIBS $OPENCL_LIBS $NCURSES_LIBS $PDCURSES_LIBS $WS2_LIBS $MATH_LIBS $UDEV_LIBS $USB_LIBS"
+echo "  LDADD................: $DLOPEN_FLAGS $LIBCURL_LIBS $JANSSON_LIBS $PTHREAD_LIBS $NCURSES_LIBS $PDCURSES_LIBS $WS2_LIBS $MATH_LIBS $UDEV_LIBS $USB_LIBS"
 echo
 echo
 echo "Installation...........: make install (as root if needed, with 'su' or 'sudo')"
 echo "Installation...........: make install (as root if needed, with 'su' or 'sudo')"
 echo "  prefix...............: $prefix"
 echo "  prefix...............: $prefix"

+ 221 - 0
driver-opencl.c

@@ -15,6 +15,12 @@
 #include <curses.h>
 #include <curses.h>
 #endif
 #endif
 
 
+#ifndef WIN32
+#include <dlfcn.h>
+#else
+#include <windows.h>
+#endif
+
 #include <string.h>
 #include <string.h>
 #include <stdbool.h>
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdint.h>
@@ -26,6 +32,8 @@
 #endif
 #endif
 #include <ccan/opt/opt.h>
 #include <ccan/opt/opt.h>
 
 
+#define OMIT_OPENCL_API
+
 #include "compat.h"
 #include "compat.h"
 #include "miner.h"
 #include "miner.h"
 #include "driver-opencl.h"
 #include "driver-opencl.h"
@@ -35,6 +43,213 @@
 
 
 /* TODO: cleanup externals ********************/
 /* TODO: cleanup externals ********************/
 
 
+
+/* Platform API */
+CL_API_ENTRY cl_int CL_API_CALL
+(*clGetPlatformIDs)(cl_uint          /* num_entries */,
+                 cl_platform_id * /* platforms */,
+                 cl_uint *        /* num_platforms */) CL_API_SUFFIX__VERSION_1_0;
+
+CL_API_ENTRY cl_int CL_API_CALL
+(*clGetPlatformInfo)(cl_platform_id   /* platform */,
+                  cl_platform_info /* param_name */,
+                  size_t           /* param_value_size */,
+                  void *           /* param_value */,
+                  size_t *         /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+/* Device APIs */
+CL_API_ENTRY cl_int CL_API_CALL
+(*clGetDeviceIDs)(cl_platform_id   /* platform */,
+               cl_device_type   /* device_type */,
+               cl_uint          /* num_entries */,
+               cl_device_id *   /* devices */,
+               cl_uint *        /* num_devices */) CL_API_SUFFIX__VERSION_1_0;
+
+CL_API_ENTRY cl_int CL_API_CALL
+(*clGetDeviceInfo)(cl_device_id    /* device */,
+                cl_device_info  /* param_name */,
+                size_t          /* param_value_size */,
+                void *          /* param_value */,
+                size_t *        /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+/* Context APIs  */
+CL_API_ENTRY cl_context CL_API_CALL
+(*clCreateContextFromType)(const cl_context_properties * /* properties */,
+                        cl_device_type          /* device_type */,
+                        void (CL_CALLBACK *     /* pfn_notify*/ )(const char *, const void *, size_t, void *),
+                        void *                  /* user_data */,
+                        cl_int *                /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+CL_API_ENTRY cl_int CL_API_CALL
+(*clReleaseContext)(cl_context /* context */) CL_API_SUFFIX__VERSION_1_0;
+
+/* Command Queue APIs */
+CL_API_ENTRY cl_command_queue CL_API_CALL
+(*clCreateCommandQueue)(cl_context                     /* context */,
+                     cl_device_id                   /* device */,
+                     cl_command_queue_properties    /* properties */,
+                     cl_int *                       /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+CL_API_ENTRY cl_int CL_API_CALL
+(*clReleaseCommandQueue)(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0;
+
+/* Memory Object APIs */
+CL_API_ENTRY cl_mem CL_API_CALL
+(*clCreateBuffer)(cl_context   /* context */,
+               cl_mem_flags /* flags */,
+               size_t       /* size */,
+               void *       /* host_ptr */,
+               cl_int *     /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+/* Program Object APIs  */
+CL_API_ENTRY cl_program CL_API_CALL
+(*clCreateProgramWithSource)(cl_context        /* context */,
+                          cl_uint           /* count */,
+                          const char **     /* strings */,
+                          const size_t *    /* lengths */,
+                          cl_int *          /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+CL_API_ENTRY cl_program CL_API_CALL
+(*clCreateProgramWithBinary)(cl_context                     /* context */,
+                          cl_uint                        /* num_devices */,
+                          const cl_device_id *           /* device_list */,
+                          const size_t *                 /* lengths */,
+                          const unsigned char **         /* binaries */,
+                          cl_int *                       /* binary_status */,
+                          cl_int *                       /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+CL_API_ENTRY cl_int CL_API_CALL
+(*clReleaseProgram)(cl_program /* program */) CL_API_SUFFIX__VERSION_1_0;
+
+CL_API_ENTRY cl_int CL_API_CALL
+(*clBuildProgram)(cl_program           /* program */,
+               cl_uint              /* num_devices */,
+               const cl_device_id * /* device_list */,
+               const char *         /* options */,
+               void (CL_CALLBACK *  /* pfn_notify */)(cl_program /* program */, void * /* user_data */),
+               void *               /* user_data */) CL_API_SUFFIX__VERSION_1_0;
+
+CL_API_ENTRY cl_int CL_API_CALL
+(*clGetProgramInfo)(cl_program         /* program */,
+                 cl_program_info    /* param_name */,
+                 size_t             /* param_value_size */,
+                 void *             /* param_value */,
+                 size_t *           /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+CL_API_ENTRY cl_int CL_API_CALL
+(*clGetProgramBuildInfo)(cl_program            /* program */,
+                      cl_device_id          /* device */,
+                      cl_program_build_info /* param_name */,
+                      size_t                /* param_value_size */,
+                      void *                /* param_value */,
+                      size_t *              /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+/* Kernel Object APIs */
+CL_API_ENTRY cl_kernel CL_API_CALL
+(*clCreateKernel)(cl_program      /* program */,
+               const char *    /* kernel_name */,
+               cl_int *        /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+CL_API_ENTRY cl_int CL_API_CALL
+(*clReleaseKernel)(cl_kernel   /* kernel */) CL_API_SUFFIX__VERSION_1_0;
+
+CL_API_ENTRY cl_int CL_API_CALL
+(*clSetKernelArg)(cl_kernel    /* kernel */,
+               cl_uint      /* arg_index */,
+               size_t       /* arg_size */,
+               const void * /* arg_value */) CL_API_SUFFIX__VERSION_1_0;
+
+/* Flush and Finish APIs */
+CL_API_ENTRY cl_int CL_API_CALL
+(*clFinish)(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0;
+
+/* Enqueued Commands APIs */
+CL_API_ENTRY cl_int CL_API_CALL
+(*clEnqueueReadBuffer)(cl_command_queue    /* command_queue */,
+                    cl_mem              /* buffer */,
+                    cl_bool             /* blocking_read */,
+                    size_t              /* offset */,
+                    size_t              /* size */,
+                    void *              /* ptr */,
+                    cl_uint             /* num_events_in_wait_list */,
+                    const cl_event *    /* event_wait_list */,
+                    cl_event *          /* event */) CL_API_SUFFIX__VERSION_1_0;
+
+CL_API_ENTRY cl_int CL_API_CALL
+(*clEnqueueWriteBuffer)(cl_command_queue   /* command_queue */,
+                     cl_mem             /* buffer */,
+                     cl_bool            /* blocking_write */,
+                     size_t             /* offset */,
+                     size_t             /* size */,
+                     const void *       /* ptr */,
+                     cl_uint            /* num_events_in_wait_list */,
+                     const cl_event *   /* event_wait_list */,
+                     cl_event *         /* event */) CL_API_SUFFIX__VERSION_1_0;
+
+CL_API_ENTRY cl_int CL_API_CALL
+(*clEnqueueNDRangeKernel)(cl_command_queue /* command_queue */,
+                       cl_kernel        /* kernel */,
+                       cl_uint          /* work_dim */,
+                       const size_t *   /* global_work_offset */,
+                       const size_t *   /* global_work_size */,
+                       const size_t *   /* local_work_size */,
+                       cl_uint          /* num_events_in_wait_list */,
+                       const cl_event * /* event_wait_list */,
+                       cl_event *       /* event */) CL_API_SUFFIX__VERSION_1_0;
+
+#ifdef WIN32
+#define dlsym (void*)GetProcAddress
+#define dlclose FreeLibrary
+#endif
+
+#define LOAD_OCL_SYM(sym)  do { \
+	if (!(sym = dlsym(cl, #sym))) {  \
+		applog(LOG_ERR, "Failed to load OpenCL symbol " #sym ", no GPUs usable");  \
+		dlclose(cl);  \
+		return false;  \
+	}  \
+} while(0)
+
+static bool
+load_opencl_symbols() {
+#ifndef WIN32
+	void *cl = dlopen("libOpenCL.so", RTLD_LAZY);
+#else
+	HMODULE cl = LoadLibrary("OpenCL.dll");
+#endif
+	if (!cl)
+	{
+		applog(LOG_ERR, "Failed to load OpenCL library, no GPUs usable");
+		return false;
+	}
+	
+	LOAD_OCL_SYM(clGetPlatformIDs);
+	LOAD_OCL_SYM(clGetPlatformInfo);
+	LOAD_OCL_SYM(clGetDeviceIDs);
+	LOAD_OCL_SYM(clGetDeviceInfo);
+	LOAD_OCL_SYM(clCreateContextFromType);
+	LOAD_OCL_SYM(clReleaseContext);
+	LOAD_OCL_SYM(clCreateCommandQueue);
+	LOAD_OCL_SYM(clReleaseCommandQueue);
+	LOAD_OCL_SYM(clCreateBuffer);
+	LOAD_OCL_SYM(clCreateProgramWithSource);
+	LOAD_OCL_SYM(clCreateProgramWithBinary);
+	LOAD_OCL_SYM(clReleaseProgram);
+	LOAD_OCL_SYM(clBuildProgram);
+	LOAD_OCL_SYM(clGetProgramInfo);
+	LOAD_OCL_SYM(clGetProgramBuildInfo);
+	LOAD_OCL_SYM(clCreateKernel);
+	LOAD_OCL_SYM(clReleaseKernel);
+	LOAD_OCL_SYM(clSetKernelArg);
+	LOAD_OCL_SYM(clFinish);
+	LOAD_OCL_SYM(clEnqueueReadBuffer);
+	LOAD_OCL_SYM(clEnqueueWriteBuffer);
+	LOAD_OCL_SYM(clEnqueueNDRangeKernel);
+	
+	return true;
+}
+
+
 #ifdef HAVE_CURSES
 #ifdef HAVE_CURSES
 extern WINDOW *mainwin, *statuswin, *logwin;
 extern WINDOW *mainwin, *statuswin, *logwin;
 extern void enable_curses(void);
 extern void enable_curses(void);
@@ -1120,6 +1335,12 @@ struct device_api opencl_api;
 
 
 static void opencl_detect()
 static void opencl_detect()
 {
 {
+	if (!load_opencl_symbols()) {
+		nDevs = 0;
+		return;
+	}
+
+
 	int i;
 	int i;
 
 
 	nDevs = clDevicesNum();
 	nDevs = clDevicesNum();

+ 1 - 5
miner.h

@@ -14,11 +14,7 @@
 #include "logging.h"
 #include "logging.h"
 
 
 #ifdef HAVE_OPENCL
 #ifdef HAVE_OPENCL
-#ifdef __APPLE_CC__
-#include <OpenCL/opencl.h>
-#else
-#include <CL/cl.h>
-#endif
+#include "CL/cl.h"
 #endif /* HAVE_OPENCL */
 #endif /* HAVE_OPENCL */
 
 
 #ifdef STDC_HEADERS
 #ifdef STDC_HEADERS

+ 178 - 1
ocl.c

@@ -30,9 +30,186 @@
 #include <sys/stat.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <unistd.h>
 
 
+#define OMIT_OPENCL_API
+
 #include "findnonce.h"
 #include "findnonce.h"
 #include "ocl.h"
 #include "ocl.h"
 
 
+/* Platform API */
+extern
+CL_API_ENTRY cl_int CL_API_CALL
+(*clGetPlatformIDs)(cl_uint          /* num_entries */,
+                 cl_platform_id * /* platforms */,
+                 cl_uint *        /* num_platforms */) CL_API_SUFFIX__VERSION_1_0;
+
+extern
+CL_API_ENTRY cl_int CL_API_CALL
+(*clGetPlatformInfo)(cl_platform_id   /* platform */,
+                  cl_platform_info /* param_name */,
+                  size_t           /* param_value_size */,
+                  void *           /* param_value */,
+                  size_t *         /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+/* Device APIs */
+extern
+CL_API_ENTRY cl_int CL_API_CALL
+(*clGetDeviceIDs)(cl_platform_id   /* platform */,
+               cl_device_type   /* device_type */,
+               cl_uint          /* num_entries */,
+               cl_device_id *   /* devices */,
+               cl_uint *        /* num_devices */) CL_API_SUFFIX__VERSION_1_0;
+
+extern
+CL_API_ENTRY cl_int CL_API_CALL
+(*clGetDeviceInfo)(cl_device_id    /* device */,
+                cl_device_info  /* param_name */,
+                size_t          /* param_value_size */,
+                void *          /* param_value */,
+                size_t *        /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+/* Context APIs  */
+extern
+CL_API_ENTRY cl_context CL_API_CALL
+(*clCreateContextFromType)(const cl_context_properties * /* properties */,
+                        cl_device_type          /* device_type */,
+                        void (CL_CALLBACK *     /* pfn_notify*/ )(const char *, const void *, size_t, void *),
+                        void *                  /* user_data */,
+                        cl_int *                /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+extern
+CL_API_ENTRY cl_int CL_API_CALL
+(*clReleaseContext)(cl_context /* context */) CL_API_SUFFIX__VERSION_1_0;
+
+/* Command Queue APIs */
+extern
+CL_API_ENTRY cl_command_queue CL_API_CALL
+(*clCreateCommandQueue)(cl_context                     /* context */,
+                     cl_device_id                   /* device */,
+                     cl_command_queue_properties    /* properties */,
+                     cl_int *                       /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+extern
+CL_API_ENTRY cl_int CL_API_CALL
+(*clReleaseCommandQueue)(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0;
+
+/* Memory Object APIs */
+extern
+CL_API_ENTRY cl_mem CL_API_CALL
+(*clCreateBuffer)(cl_context   /* context */,
+               cl_mem_flags /* flags */,
+               size_t       /* size */,
+               void *       /* host_ptr */,
+               cl_int *     /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+/* Program Object APIs  */
+extern
+CL_API_ENTRY cl_program CL_API_CALL
+(*clCreateProgramWithSource)(cl_context        /* context */,
+                          cl_uint           /* count */,
+                          const char **     /* strings */,
+                          const size_t *    /* lengths */,
+                          cl_int *          /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+extern
+CL_API_ENTRY cl_program CL_API_CALL
+(*clCreateProgramWithBinary)(cl_context                     /* context */,
+                          cl_uint                        /* num_devices */,
+                          const cl_device_id *           /* device_list */,
+                          const size_t *                 /* lengths */,
+                          const unsigned char **         /* binaries */,
+                          cl_int *                       /* binary_status */,
+                          cl_int *                       /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+extern
+CL_API_ENTRY cl_int CL_API_CALL
+(*clReleaseProgram)(cl_program /* program */) CL_API_SUFFIX__VERSION_1_0;
+
+extern
+CL_API_ENTRY cl_int CL_API_CALL
+(*clBuildProgram)(cl_program           /* program */,
+               cl_uint              /* num_devices */,
+               const cl_device_id * /* device_list */,
+               const char *         /* options */,
+               void (CL_CALLBACK *  /* pfn_notify */)(cl_program /* program */, void * /* user_data */),
+               void *               /* user_data */) CL_API_SUFFIX__VERSION_1_0;
+
+extern
+CL_API_ENTRY cl_int CL_API_CALL
+(*clGetProgramInfo)(cl_program         /* program */,
+                 cl_program_info    /* param_name */,
+                 size_t             /* param_value_size */,
+                 void *             /* param_value */,
+                 size_t *           /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+extern
+CL_API_ENTRY cl_int CL_API_CALL
+(*clGetProgramBuildInfo)(cl_program            /* program */,
+                      cl_device_id          /* device */,
+                      cl_program_build_info /* param_name */,
+                      size_t                /* param_value_size */,
+                      void *                /* param_value */,
+                      size_t *              /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+/* Kernel Object APIs */
+extern
+CL_API_ENTRY cl_kernel CL_API_CALL
+(*clCreateKernel)(cl_program      /* program */,
+               const char *    /* kernel_name */,
+               cl_int *        /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
+
+extern
+CL_API_ENTRY cl_int CL_API_CALL
+(*clReleaseKernel)(cl_kernel   /* kernel */) CL_API_SUFFIX__VERSION_1_0;
+
+extern
+CL_API_ENTRY cl_int CL_API_CALL
+(*clSetKernelArg)(cl_kernel    /* kernel */,
+               cl_uint      /* arg_index */,
+               size_t       /* arg_size */,
+               const void * /* arg_value */) CL_API_SUFFIX__VERSION_1_0;
+
+/* Flush and Finish APIs */
+extern
+CL_API_ENTRY cl_int CL_API_CALL
+(*clFinish)(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0;
+
+/* Enqueued Commands APIs */
+extern
+CL_API_ENTRY cl_int CL_API_CALL
+(*clEnqueueReadBuffer)(cl_command_queue    /* command_queue */,
+                    cl_mem              /* buffer */,
+                    cl_bool             /* blocking_read */,
+                    size_t              /* offset */,
+                    size_t              /* size */,
+                    void *              /* ptr */,
+                    cl_uint             /* num_events_in_wait_list */,
+                    const cl_event *    /* event_wait_list */,
+                    cl_event *          /* event */) CL_API_SUFFIX__VERSION_1_0;
+
+extern
+CL_API_ENTRY cl_int CL_API_CALL
+(*clEnqueueWriteBuffer)(cl_command_queue   /* command_queue */,
+                     cl_mem             /* buffer */,
+                     cl_bool            /* blocking_write */,
+                     size_t             /* offset */,
+                     size_t             /* size */,
+                     const void *       /* ptr */,
+                     cl_uint            /* num_events_in_wait_list */,
+                     const cl_event *   /* event_wait_list */,
+                     cl_event *         /* event */) CL_API_SUFFIX__VERSION_1_0;
+
+extern
+CL_API_ENTRY cl_int CL_API_CALL
+(*clEnqueueNDRangeKernel)(cl_command_queue /* command_queue */,
+                       cl_kernel        /* kernel */,
+                       cl_uint          /* work_dim */,
+                       const size_t *   /* global_work_offset */,
+                       const size_t *   /* global_work_size */,
+                       const size_t *   /* local_work_size */,
+                       cl_uint          /* num_events_in_wait_list */,
+                       const cl_event * /* event_wait_list */,
+                       cl_event *       /* event */) CL_API_SUFFIX__VERSION_1_0;
+
 int opt_platform_id;
 int opt_platform_id;
 
 
 char *file_contents(const char *filename, int *length)
 char *file_contents(const char *filename, int *length)
@@ -316,7 +493,7 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
 	find = strstr(extensions, camo);
 	find = strstr(extensions, camo);
 	if (find)
 	if (find)
 		clState->hasBitAlign = true;
 		clState->hasBitAlign = true;
-		
+
 	/* Check for OpenCL >= 1.0 support, needed for global offset parameter usage. */
 	/* Check for OpenCL >= 1.0 support, needed for global offset parameter usage. */
 	char * devoclver = malloc(1024);
 	char * devoclver = malloc(1024);
 	const char * ocl10 = "OpenCL 1.0";
 	const char * ocl10 = "OpenCL 1.0";

+ 1 - 5
ocl.h

@@ -5,11 +5,7 @@
 
 
 #include <stdbool.h>
 #include <stdbool.h>
 #ifdef HAVE_OPENCL
 #ifdef HAVE_OPENCL
-#ifdef __APPLE_CC__
-#include <OpenCL/opencl.h>
-#else
-#include <CL/cl.h>
-#endif
+#include "CL/cl.h"
 
 
 #include "miner.h"
 #include "miner.h"