Browse Source

opencl: Search all the same kernel paths when setting kernel

Luke Dashjr 11 years ago
parent
commit
b313e2f1f2
3 changed files with 19 additions and 4 deletions
  1. 4 1
      driver-opencl.c
  2. 12 3
      ocl.c
  3. 3 0
      ocl.h

+ 4 - 1
driver-opencl.c

@@ -411,6 +411,7 @@ const char *opencl_get_default_kernel_filename(const enum cl_kernels kern)
 static
 static
 bool _set_kernel(struct cgpu_info * const cgpu, const char *_val)
 bool _set_kernel(struct cgpu_info * const cgpu, const char *_val)
 {
 {
+	FILE *F;
 	const enum cl_kernels kern = select_kernel(_val);
 	const enum cl_kernels kern = select_kernel(_val);
 	struct opencl_device_data * const data = cgpu->device_data;
 	struct opencl_device_data * const data = cgpu->device_data;
 	{
 	{
@@ -423,8 +424,10 @@ bool _set_kernel(struct cgpu_info * const cgpu, const char *_val)
 	char filename[knamelen + 3 + 1];
 	char filename[knamelen + 3 + 1];
 	sprintf(filename, "%s.cl", _val);
 	sprintf(filename, "%s.cl", _val);
 	
 	
-	if (access(filename, R_OK))
+	F = opencl_open_kernel(filename);
+	if (!F)
 		return false;
 		return false;
+	fclose(F);
 	
 	
 	free(data->kernel_file);
 	free(data->kernel_file);
 	data->kernel_file = strdup(_val);
 	data->kernel_file = strdup(_val);

+ 12 - 3
ocl.c

@@ -211,10 +211,9 @@ CL_API_ENTRY cl_int CL_API_CALL
 
 
 int opt_platform_id = -1;
 int opt_platform_id = -1;
 
 
-char *file_contents(const char *filename, int *length)
+FILE *opencl_open_kernel(const char * const filename)
 {
 {
 	char *fullpath = alloca(PATH_MAX);
 	char *fullpath = alloca(PATH_MAX);
-	void *buffer;
 	FILE *f;
 	FILE *f;
 
 
 	/* Try in the optional kernel path or installed prefix first */
 	/* Try in the optional kernel path or installed prefix first */
@@ -228,9 +227,19 @@ char *file_contents(const char *filename, int *length)
 	/* Finally try opening it directly */
 	/* Finally try opening it directly */
 	if (!f)
 	if (!f)
 		f = fopen(filename, "rb");
 		f = fopen(filename, "rb");
+	
+	return f;
+}
+
+char *file_contents(const char *filename, int *length)
+{
+	void *buffer;
+	FILE *f;
+
+	f = opencl_open_kernel(filename);
 
 
 	if (!f) {
 	if (!f) {
-		applog(LOG_ERR, "Unable to open %s or %s for reading", filename, fullpath);
+		applog(LOG_ERR, "Unable to open %s for reading", filename);
 		return NULL;
 		return NULL;
 	}
 	}
 
 

+ 3 - 0
ocl.h

@@ -4,6 +4,8 @@
 #include "config.h"
 #include "config.h"
 
 
 #include <stdbool.h>
 #include <stdbool.h>
+#include <stdio.h>
+
 #ifdef HAVE_OPENCL
 #ifdef HAVE_OPENCL
 #include "CL/cl.h"
 #include "CL/cl.h"
 
 
@@ -31,6 +33,7 @@ typedef struct {
 	enum cl_kernels chosen_kernel;
 	enum cl_kernels chosen_kernel;
 } _clState;
 } _clState;
 
 
+extern FILE *opencl_open_kernel(const char *filename);
 extern char *file_contents(const char *filename, int *length);
 extern char *file_contents(const char *filename, int *length);
 extern int clDevicesNum(void);
 extern int clDevicesNum(void);
 extern _clState *initCl(unsigned int gpu, char *name, size_t nameSize);
 extern _clState *initCl(unsigned int gpu, char *name, size_t nameSize);