From d9f1b0b16edeb59281355a855e18a8be343fc33c Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Fri, 08 Aug 2014 19:04:15 +0000
Subject: [PATCH] probably how maxpool layers should be

---
 src/opencl.c |   46 +++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 45 insertions(+), 1 deletions(-)

diff --git a/src/opencl.c b/src/opencl.c
index 08bc8a7..8f9edd3 100644
--- a/src/opencl.c
+++ b/src/opencl.c
@@ -1,3 +1,4 @@
+#ifdef GPU
 #include "opencl.h"
 #include <stdio.h>
 #include <stdlib.h>
@@ -12,6 +13,7 @@
 {
     if (info.error != CL_SUCCESS) {
         printf("\n Error number %d", info.error);
+        exit(1);
     }
 }
 
@@ -30,7 +32,8 @@
     if(num_devices > MAX_DEVICES) num_devices = MAX_DEVICES;
     int index = getpid()%num_devices;
     printf("%d rand, %d devices, %d index\n", getpid(), num_devices, index);
-    info.device = devices[index];
+    //info.device = devices[index];
+    info.device = devices[1];
     fprintf(stderr, "Found %d device(s)\n", num_devices);
     check_error(info);
 
@@ -66,6 +69,7 @@
 		clGetProgramBuildInfo( prog, info.device, CL_PROGRAM_BUILD_LOG, 4096, build_c, 0);
 		fprintf(stderr, "Build Log for %s program:\n%s\n", filename, build_c);
 	}
+	check_error(info);
 	return prog;
 }
 
@@ -85,4 +89,44 @@
 	return kernel;
 }
 
+void cl_read_array(cl_mem mem, float *x, int n)
+{
+    cl_setup();
+    clEnqueueReadBuffer(cl.queue, mem, CL_TRUE, 0, sizeof(float)*n,x,0,0,0);
+    check_error(cl);
+}
 
+void cl_write_array(cl_mem mem, float *x, int n)
+{
+    cl_setup();
+    clEnqueueWriteBuffer(cl.queue, mem, CL_TRUE, 0,sizeof(float)*n,x,0,0,0);
+    check_error(cl);
+}
+
+void cl_copy_array(cl_mem src, cl_mem dst, int n)
+{
+    cl_setup();
+    clEnqueueCopyBuffer(cl.queue, src, dst, 0, 0, sizeof(float)*n,0,0,0);
+    check_error(cl);
+}
+
+cl_mem cl_sub_array(cl_mem src, int offset, int size)
+{
+    cl_buffer_region r;
+    r.origin = offset*sizeof(float);
+    r.size = size*sizeof(float);
+    cl_mem sub = clCreateSubBuffer(src, CL_MEM_USE_HOST_PTR, CL_BUFFER_CREATE_TYPE_REGION, &r, 0);
+    return sub;
+}
+
+cl_mem cl_make_array(float *x, int n)
+{
+    cl_setup();
+    cl_mem mem = clCreateBuffer(cl.context,
+            CL_MEM_READ_WRITE|CL_MEM_COPY_HOST_PTR,
+            sizeof(float)*n, x, &cl.error);
+    check_error(cl);
+    return mem;
+}
+
+#endif

--
Gitblit v1.10.0