diff options
author | Igor Oliveira <igor.oliveira@openbossa.org> | 2009-12-09 10:29:34 -0800 |
---|---|---|
committer | Zack Rusin <zackr@vmware.com> | 2010-01-04 09:14:43 -0500 |
commit | b0d796e30f0ad5187e727d5c03e6667027b91690 (patch) | |
tree | 650d216f94a144a6b1fa000bc0c2ad8471610925 | |
parent | fe552119577560a7d842d852f1c37844b14a2e2f (diff) |
PATCH[1/1]: OpenCL: create and implement stub context methods
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/api/api_context.cpp | 60 | ||||
-rw-r--r-- | src/core/context.cpp | 19 | ||||
-rw-r--r-- | src/core/context.h | 15 | ||||
-rw-r--r-- | src/core/device.cpp | 4 |
5 files changed, 89 insertions, 10 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b8ff200..c29f7c6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,6 +16,7 @@ set(CLOVER_SRC_FILES api/api_memory.cpp api/api_profiling.cpp api/api_sampler.cpp api/api_gl.cpp core/device.cpp + core/context.cpp compiler/compiler.cpp cpuwinsys/cpuwinsys.c) diff --git a/src/api/api_context.cpp b/src/api/api_context.cpp index fbf3af9..8393dcb 100644 --- a/src/api/api_context.cpp +++ b/src/api/api_context.cpp @@ -1,5 +1,8 @@ #include <OpenCL/cl.h> +#include "core/context.h" +#include "core/device.h" +#include "cpuwinsys/cpuwinsys.h" // Context APIs @@ -11,7 +14,18 @@ clCreateContext(cl_context_properties properties, void * user_data, cl_int * errcode_ret) { - return 0; + cl_context ret_context = NULL; + cl_device_type type; + cl_device_id device = devices[0]; + cl_int device_info; + + device_info = clGetDeviceInfo(device, CL_DEVICE_TYPE, sizeof(type), &type, NULL); + if (device_info != CL_INVALID_DEVICE) { + ret_context = clCreateContextFromType(properties, type, + pfn_notify, user_data, errcode_ret); + } + + return ret_context; } cl_context @@ -21,19 +35,57 @@ clCreateContextFromType(cl_context_properties properties, void * user_data, cl_int * errcode_ret) { - return 0; + struct pipe_context *context = NULL; + + switch (device_type) { + case CL_DEVICE_TYPE_CPU: + context = + cl_create_context(cpu_winsys()); + + break; + default: + if (errcode_ret) { + *errcode_ret = CL_INVALID_DEVICE_TYPE; + } + goto fail; + } + +fail: + return cl_convert_context(context); } cl_int clRetainContext(cl_context context) { - return 0; + cl_int ret; + + if (context) { + context->id++; + ret = CL_SUCCESS; + } else { + ret = CL_INVALID_CONTEXT; + } + + return ret; } cl_int clReleaseContext(cl_context context) { - return 0; + cl_uint ret; + + if (context) { + if( !context->id ) { + context->pipe.destroy(&context->pipe); + } else { + context->id--; + } + ret = CL_SUCCESS; + } else { + ret = CL_INVALID_CONTEXT; + } + + return ret; } cl_int diff --git a/src/core/context.cpp b/src/core/context.cpp new file mode 100644 index 0000000..891a96e --- /dev/null +++ b/src/core/context.cpp @@ -0,0 +1,19 @@ +#include "context.h" +#include "util/u_memory.h" + +void cl_destroy_context( struct pipe_context *context ) +{ + struct _cl_context *clcontext = cl_convert_context(context); + + FREE(clcontext); +} + +struct pipe_context *cl_create_context( struct pipe_winsys *winsys ) +{ + struct _cl_context *cl_context = CALLOC_STRUCT(_cl_context); + + cl_context->pipe.winsys = winsys; + cl_context->pipe.destroy = cl_destroy_context; + + return &cl_context->pipe; +} diff --git a/src/core/context.h b/src/core/context.h index f74bcdb..00b0f33 100644 --- a/src/core/context.h +++ b/src/core/context.h @@ -2,15 +2,22 @@ #define CONTEXT_H #include "OpenCL/cl.h" - #include "pipe/p_context.h" struct _cl_context { - struct pipe_context *pipe; + struct pipe_context pipe; cl_uint id; }; -void cl_set_current_context(struct _cl_context *ctx); -struct _cl_context *cl_current_context(void); +void cl_set_current_context( struct _cl_context *ctx); +struct _cl_context *cl_current_context( void); + +struct pipe_context *cl_create_context( struct pipe_winsys *winsys ); + +static INLINE struct _cl_context * +cl_convert_context( struct pipe_context *pipe ) +{ + return (struct _cl_context *)pipe; +} #endif diff --git a/src/core/device.cpp b/src/core/device.cpp index 4553d1b..c300f79 100644 --- a/src/core/device.cpp +++ b/src/core/device.cpp @@ -219,8 +219,8 @@ void Device::fillInfo(cl_uint type) m_info.queueProperties = ; #endif - m_info.name = m_screen->get_name(m_screen); - m_info.vendor = m_screen->get_vendor(m_screen); + //m_info.name = m_screen->get_name(m_screen); + //m_info.vendor = m_screen->get_vendor(m_screen); //m_info.driverVersion = ; m_info.profile = "FULL_PROFILE"; //m_info.version = ; |