Started to inject the new compiler API
authorBenjamin Segovia <segovia.benjamin@gmail.com>
Wed, 21 Mar 2012 18:07:40 +0000 (18:07 +0000)
committerKeith Packard <keithp@keithp.com>
Fri, 10 Aug 2012 23:15:49 +0000 (16:15 -0700)
include/CL/cl_intel.h
src/cl_api.c
src/cl_command_queue_gen7.c
src/cl_program.c
src/cl_program.h

index 9239bb5..680f948 100644 (file)
@@ -52,9 +52,11 @@ clIntelGetGenVersion(cl_device_id device, cl_int *ver);
 
 /* Create a program from a LLVM source file */
 extern CL_API_ENTRY cl_program CL_API_CALL
-clCreateProgramWithLLVM(cl_context        /* context */,
-                       const char *      /* file */,
-                       cl_int *          /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
+clCreateProgramWithLLVM(cl_context              /* context */,
+                        cl_uint                 /* num_devices */,
+                        const cl_device_id *    /* device_list */,
+                        const char *            /* file */,
+                        cl_int *                /* errcode_ret */);
 
 #ifdef __cplusplus
 }
index c808b97..6c8b69f 100644 (file)
@@ -1171,3 +1171,17 @@ clIntelGetGenVersion(cl_device_id device, cl_int *ver)
   return cl_device_get_version(device, ver);
 }
 
+cl_program
+clCreateProgramWithLLVM(cl_context              context,
+                        cl_uint                 num_devices,
+                        const cl_device_id *    devices,
+                        const char *            filename,
+                        cl_int *                errcode_ret)
+{
+  return cl_program_create_from_llvm(context,
+                                     num_devices,
+                                     devices,
+                                     filename,
+                                     errcode_ret);
+}
+
index 4597026..8eda934 100644 (file)
@@ -48,6 +48,7 @@ cl_kernel_compute_batch_sz(cl_kernel k)
   return sz;
 }
 
+#if 0
 static cl_int
 cl_set_local_ids(char *data,
                  const size_t *local_wk_sz,
@@ -92,6 +93,7 @@ error:
     cl_free(ids[i]);
   return err;
 }
+#endif
 
 LOCAL cl_int
 cl_command_queue_ND_range_gen7(cl_command_queue queue,
index cb93d2c..e36010f 100644 (file)
@@ -23,8 +23,8 @@
 #include "cl_context.h"
 #include "cl_alloc.h"
 #include "cl_utils.h"
-
 #include "CL/cl.h"
+#include "gen/program.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -63,6 +63,9 @@ cl_program_delete(cl_program p)
   /* Program belongs to their parent context */
   cl_context_delete(p->ctx);
 
+  /* Free the program as allocated by the compiler */
+  if (p->gen_program) GenProgramDelete(p->gen_program);
+
   p->magic = CL_MAGIC_DEAD_HEADER; /* For safety */
   cl_free(p);
 }
@@ -104,7 +107,76 @@ cl_program_create_from_binary(cl_context             ctx,
                               cl_int *               binary_status,
                               cl_int *               errcode_ret)
 {
-  return NULL;
+#if 0
+  cl_program program = NULL;
+  cl_int err = CL_SUCCESS;
+
+  assert(ctx);
+  INVALID_DEVICE_IF (num_devices != 1);
+  INVALID_DEVICE_IF (devices == NULL);
+  INVALID_DEVICE_IF (devices[0] != ctx->device);
+  INVALID_VALUE_IF (binaries == NULL);
+  INVALID_VALUE_IF (lengths == NULL);
+
+  if (binaries[0] == NULL) {
+    err = CL_INVALID_VALUE;
+    if (binary_status)
+      binary_status[0] = CL_INVALID_VALUE;
+    goto error;
+  }
+
+  if (lengths[0] == 0) {
+    err = CL_INVALID_VALUE;
+    if (binary_status)
+      binary_status[0] = CL_INVALID_VALUE;
+    goto error;
+  }
+
+  // TRY_ALLOC (program, cl_program_new(ctx, (const char *) binaries[0], lengths[0]));
+
+exit:
+  if (errcode_ret)
+    *errcode_ret = err;
+  return program;
+error:
+  cl_program_delete(program);
+  program = NULL;
+  goto exit;
+#endif
+  NOT_IMPLEMENTED;
+  return CL_SUCCESS;
+}
+
+LOCAL cl_program
+cl_program_create_from_llvm(cl_context ctx,
+                            cl_uint num_devices,
+                            const cl_device_id *devices,
+                            const char *file_name,
+                            cl_int *errcode_ret)
+{
+  cl_program program = NULL;
+  cl_int err = CL_SUCCESS;
+
+  assert(ctx);
+  INVALID_DEVICE_IF (num_devices != 1);
+  INVALID_DEVICE_IF (devices == NULL);
+  INVALID_DEVICE_IF (devices[0] != ctx->device);
+  INVALID_VALUE_IF (file_name == NULL);
+
+  program->gen_program = GenProgramNewFromLLVM(file_name, 0, NULL, NULL);
+  if (program->gen_program == NULL) {
+    err = CL_INVALID_PROGRAM;
+    goto error;
+  }
+
+exit:
+  if (errcode_ret)
+    *errcode_ret = err;
+  return program;
+error:
+  cl_program_delete(program);
+  program = NULL;
+  goto exit;
 }
 
 LOCAL cl_kernel
index 53e182d..1544a8c 100644 (file)
 #include <stdint.h>
 #include <stdlib.h>
 
+// This is the structure ouput by the compiler
+struct GenProgram;
+
 /* This maps an OCL file containing some kernels */
 struct _cl_program {
-  uint64_t magic;           /* To identify it as a program */
-  volatile int ref_n;       /* We reference count this object */
+  uint64_t magic;                  /* To identify it as a program */
+  volatile int ref_n;              /* We reference count this object */
+  struct GenProgram *gen_program;  /* Program as ouput by the compiler */
   cl_kernel *ker;           /* All kernels included by the OCL file */
   cl_program prev, next;    /* We chain the programs together */
   cl_context ctx;           /* Its parent context */