Revision: 56622
          http://sourceforge.net/p/brlcad/code/56622
Author:   ejno
Date:     2013-08-06 14:08:32 +0000 (Tue, 06 Aug 2013)
Log Message:
-----------
configure with cmake and compile successfully

Modified Paths:
--------------
    brlcad/branches/opencl/src/librt/CMakeLists.txt
    brlcad/branches/opencl/src/librt/primitives/sph/sph.c

Modified: brlcad/branches/opencl/src/librt/CMakeLists.txt
===================================================================
--- brlcad/branches/opencl/src/librt/CMakeLists.txt     2013-08-06 13:48:47 UTC 
(rev 56621)
+++ brlcad/branches/opencl/src/librt/CMakeLists.txt     2013-08-06 14:08:32 UTC 
(rev 56622)
@@ -289,8 +289,7 @@
   set(LIBRT_SOURCES ${LIBRT_SOURCES} timer42.c)
 endif(MSVC)
 
-FIND_LIBRARY(OPENCL_LIBRARY, OpenCL)
-FIND_PATH(OPENCL_INCLUDE_DIR cl.h)
+set(OPENCL_LIBRARY /System/Library/Frameworks/OpenCL.framework/OpenCL)
 
 BRLCAD_ADDLIB(librt "${LIBRT_SOURCES}" 
"${OPENCL_LIBRARY};${LIBGDIAM_LIBRARY};${LIBVDS_LIBRARY};libbn;libbu;${OPENNURBS_LIBRARY};${P2T_LIBRARY};libbrep;${REGEX_LIBRARY};${ZLIB_LIBRARY};${WINSOCK_LIB};${RPCRT_LIB};${STDCXX_LIBRARIES}"
 NO_STRICT_CXX)
 
@@ -303,7 +302,6 @@
 
 
 include_directories(
-  ${OPENCL_INCLUDE_DIR}
   ${CMAKE_SOURCE_DIR}/src/other/Eigen
   ${CMAKE_CURRENT_SOURCE_DIR}/../libbrep
   )

Modified: brlcad/branches/opencl/src/librt/primitives/sph/sph.c
===================================================================
--- brlcad/branches/opencl/src/librt/primitives/sph/sph.c       2013-08-06 
13:48:47 UTC (rev 56621)
+++ brlcad/branches/opencl/src/librt/primitives/sph/sph.c       2013-08-06 
14:08:32 UTC (rev 56622)
@@ -32,6 +32,8 @@
 #include <stdio.h>
 #include <string.h>
 #include <math.h>
+
+#include <OpenCL/cl.h>
 #include "bio.h"
 
 #include "vmath.h"
@@ -72,12 +74,6 @@
 
 
 #ifdef OPENCL
-static int clt_initialized = 0;
-static cl_device_id clt_device;
-static cl_context clt_context;
-static cl_command_queue clt_queue;
-static cl_program clt_program;
-static cl_kernel kernel;
 
 
 /* FIXME: this needs alignment */
@@ -89,7 +85,28 @@
 };
 
 
-/* just spheres at present  */
+static int clt_initialized = 0;
+static cl_device_id clt_device;
+static cl_context clt_context;
+static cl_command_queue clt_queue;
+static cl_program clt_program;
+static cl_kernel clt_kernel;
+
+
+static void
+clt_cleanup()
+{
+    if (!clt_initialized) return;
+
+    clReleaseKernel(clt_kernel);
+    clReleaseCommandQueue(clt_queue);
+    clReleaseProgram(clt_program);
+    clReleaseContext(clt_context);
+
+    clt_initialized = 0;
+}
+
+
 const char * const clt_program_code = "\
 typedef struct\
 {\
@@ -125,7 +142,7 @@
     cl_platform_id platform;
     cl_device_id device;
 
-    error = clGetPlatformIDs(1, &platform, nullptr);
+    error = clGetPlatformIDs(1, &platform, NULL);
     if (error != CL_SUCCESS) bu_bomb("failed to find an OpenCL platform");
 
     error = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, NULL);
@@ -144,7 +161,7 @@
     cl_program program;
     size_t code_size = strnlen(code, 2<<20);
 
-    cl_program program = clCreateProgramWithSource(context, 1, &code, 
&code_size, &error);
+    program = clCreateProgramWithSource(context, 1, &code, &code_size, &error);
     if (error != CL_SUCCESS) bu_bomb("failed to create OpenCL program");
 
     error = clBuildProgram(program, 0, NULL, NULL, NULL, NULL);
@@ -152,15 +169,17 @@
        size_t log_size;
        char *log_data;
        clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, 0, NULL, 
&log_size);
-       log_data = bu_malloc(log_size*sizeof(char));
+       log_data = bu_malloc(log_size*sizeof(char), "failed to allocate memory 
for log");
        clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, 
log_size+1, log_data, NULL);
-       bu_bomb("failed to build program\nBUILD LOG:\n%s\n", log_data);
+       bu_log("BUILD LOG:\n%s\n", log_data);
+       bu_bomb("failed to build OpenCL program");
     }
 
     return program;
 }
 
 
+
 static void
 clt_init()
 {
@@ -178,24 +197,12 @@
     clt_queue = clCreateCommandQueue(clt_context, clt_device, 0, &error);
     if (error != CL_SUCCESS) bu_bomb("failed to create an OpenCL command 
queue");
 
-    clt_program = clt_get_program();
+    clt_program = clt_get_program(clt_context, clt_device, clt_program_code);
 
-    clt_kernel = clCreateKernel(program, "ell_shot", &error);
+    clt_kernel = clCreateKernel(clt_program, "ell_shot", &error);
     if (error != CL_SUCCESS) bu_bomb("failed to create an OpenCL kernel");
-}
 
-
-static void
-clt_cleanup()
-{
-    if (!clt_initialized) return;
-
-    clReleaseKernel(clt_kernel);
-    clReleaseCommandQueue(clt_queue);
-    clReleaseProgram(clt_program);
-    clReleaseContext(clt_context);
-
-    clt_initialized = 0;
+    bu_log("initialized OpenCL");
 }
 
 
@@ -228,7 +235,7 @@
 int
 rt_sph_prep(struct soltab *stp, struct rt_db_internal *ip, struct rt_i *rtip)
 {
-#ifdef OPENCL
+#ifdef OPENCL_D
     clt_init();
     return 0;
 #else
@@ -237,7 +244,7 @@
     vect_t Au, Bu, Cu; /* A, B, C with unit length */
     fastf_t f;
     struct rt_ell_internal *eip;
-
+clt_init();
     eip = (struct rt_ell_internal *)ip->idb_ptr;
     RT_ELL_CK_MAGIC(eip);
 
@@ -361,7 +368,7 @@
 int
 rt_sph_shot(struct soltab *stp, register struct xray *rp, struct application 
*ap, struct seg *seghead)
 {
-#ifdef OPENCL
+#ifdef OPENCL_D
 #else
     register struct sph_specific *sph =
        (struct sph_specific *)stp->st_specific;

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent 
caught up. So what steps can you take to put your SQL databases under 
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to