Permalink
Browse files

Add context, etc.

  • Loading branch information...
1 parent 848c879 commit 675d59a4e5e961ffe02ff8bae0943ef30ef01234 @rsky committed Sep 1, 2012
Showing with 1,150 additions and 164 deletions.
  1. +3 −1 config.m4
  2. +116 −0 context.c
  3. +26 −0 context.h
  4. +27 −27 device.c
  5. +116 −0 event.c
  6. +26 −0 event.h
  7. +116 −0 kernel.c
  8. +26 −0 kernel.h
  9. +118 −0 memory.c
  10. +27 −0 memory.h
  11. +97 −82 opencl.c
  12. +0 −28 php_opencl.h
  13. +26 −26 platform.c
  14. +116 −0 program.c
  15. +26 −0 program.h
  16. +116 −0 queue.c
  17. +26 −0 queue.h
  18. +116 −0 sampler.c
  19. +26 −0 sampler.h
View
@@ -37,6 +37,8 @@ if test "$PHP_OPENCL" != "no"; then
export LIBS="$OLD_LIBS"
+ PHPCL_SOURCES="opencl.c platform.c device.c context.c queue.c memory.c"
+ PHPCL_SOURCES="$PHPCL_SOURCES program.c kernel.c event.c sampler.c"
PHP_SUBST(OPENCL_SHARED_LIBADD)
- PHP_NEW_EXTENSION(opencl, opencl.c platform.c device.c, $ext_shared)
+ PHP_NEW_EXTENSION(opencl, $PHPCL_SOURCES, $ext_shared)
fi
View
116 context.c
@@ -0,0 +1,116 @@
+/**
+ * The OpenCL PHP extension
+ *
+ * @package php-opencl
+ * @author Ryusuke SEKIYAMA <rsky0711@gmail.com>
+ * @copyright 2012 Ryusuke SEKIYAMA
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ */
+
+#include "context.h"
+
+#define get_info ((phpcl_get_info_func_t)_get_context_info)
+#define get_info_ex NULL
+
+/* {{{ globals */
+
+static const phpcl_info_param_t context_info_params[] = {
+ { NULL, 0, 0 }
+};
+
+/* }}} */
+/* {{{ _get_context_info() */
+
+static cl_int _get_context_info(cl_context context,
+ void *reserved __attribute__ ((unused)),
+ cl_context_info name,
+ size_t value_size,
+ void *value,
+ size_t *value_size_ret)
+{
+ return clGetContextInfo(context, name, value_size, value, value_size_ret);
+}
+
+/* }}} */
+/* {{{ _get_context_info_all() */
+
+static void _get_context_info_all(INTERNAL_FUNCTION_PARAMETERS,
+ cl_context context)
+{
+ const phpcl_info_param_t *param = context_info_params;
+ char buf[32] = {0};
+
+ array_init_size(return_value, 8);
+ snprintf(buf, sizeof(buf), "%p", context);
+ add_assoc_string(return_value, "id", buf, 1);
+
+ while (param->key != NULL) {
+ zval *entry = phpcl_get_info(get_info, get_info_ex,
+ context, NULL, param TSRMLS_CC);
+ if (entry) {
+ add_assoc_zval(return_value, param->key, entry);
+ } else {
+ add_assoc_null(return_value, param->key);
+ }
+ param++;
+ }
+}
+
+/* }}} */
+/* {{{ _get_context_info_by_name() */
+
+static void _get_context_info_by_name(INTERNAL_FUNCTION_PARAMETERS,
+ cl_context context, cl_int name)
+{
+ const phpcl_info_param_t *param = context_info_params;
+
+ RETVAL_NULL();
+
+ while (param->key != NULL) {
+ if (param->name == name) {
+ zval *entry = phpcl_get_info(get_info, get_info_ex,
+ context, NULL, param TSRMLS_CC);
+ if (entry) {
+ RETVAL_ZVAL(entry, 0, 1);
+ }
+ return;
+ }
+ param++;
+ }
+}
+
+/* }}} */
+/* {{{ mixed cl_get_context_info(resource cl_context context[, int name]) */
+
+PHP_FUNCTION(cl_get_context_info)
+{
+ zval *zid = NULL;
+ cl_context context = NULL;
+ long name = 0;
+
+ RETVAL_FALSE;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
+ "r|l", &zid, &name) == FAILURE) {
+ return;
+ }
+ ZEND_FETCH_RESOURCE(context, cl_context, &zid, -1,
+ "cl_context", phpcl_le_context());
+
+ if (ZEND_NUM_ARGS() == 2) {
+ _get_context_info_by_name(INTERNAL_FUNCTION_PARAM_PASSTHRU, context, (cl_int)name);
+ } else {
+ _get_context_info_all(INTERNAL_FUNCTION_PARAM_PASSTHRU, context);
+ }
+}
+
+/* }}} */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
View
@@ -0,0 +1,26 @@
+/**
+ * The OpenCL PHP extension
+ *
+ * @package php-opencl
+ * @author Ryusuke SEKIYAMA <rsky0711@gmail.com>
+ * @copyright 2012 Ryusuke SEKIYAMA
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ */
+
+#include "php_opencl.h"
+
+#ifndef PHPCL_CONTEXT_H
+#define PHPCL_CONTEXT_H
+
+PHP_FUNCTION(cl_get_context_info);
+
+#endif
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
View
@@ -197,7 +197,32 @@ static void _get_device_info_by_name(INTERNAL_FUNCTION_PARAMETERS,
}
/* }}} */
-/* {{{ array cl_get_device_ids([resource cl_platform_id platform[, int device_type]]) */
+/* {{{ mixed cl_get_device_info(resource cl_device device[, int name]) */
+
+PHP_FUNCTION(cl_get_device_info)
+{
+ zval *zid = NULL;
+ cl_device_id device = NULL;
+ long name = 0;
+
+ RETVAL_FALSE;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
+ "r|l", &zid, &name) == FAILURE) {
+ return;
+ }
+ ZEND_FETCH_RESOURCE(device, cl_device_id, &zid, -1,
+ "cl_device", phpcl_le_device());
+
+ if (ZEND_NUM_ARGS() == 2) {
+ _get_device_info_by_name(INTERNAL_FUNCTION_PARAM_PASSTHRU, device, (cl_int)name);
+ } else {
+ _get_device_info_all(INTERNAL_FUNCTION_PARAM_PASSTHRU, device);
+ }
+}
+
+/* }}} */
+/* {{{ array cl_get_device_ids([resource cl_platform platform[, int device_type]]) */
PHP_FUNCTION(cl_get_device_ids)
{
@@ -219,7 +244,7 @@ PHP_FUNCTION(cl_get_device_ids)
}
if (zid) {
ZEND_FETCH_RESOURCE(platform, cl_platform_id, &zid, -1,
- "cl_platform_id", phpcl_le_platform());
+ "cl_platform", phpcl_le_platform());
}
if (ZEND_NUM_ARGS() == 2) {
device_type = (cl_device_type)ltype;
@@ -259,31 +284,6 @@ PHP_FUNCTION(cl_get_device_ids)
efree(devices);
}
-/* }}} */
-/* {{{ mixed cl_get_device_info(resource cl_device_id device[, int name]) */
-
-PHP_FUNCTION(cl_get_device_info)
-{
- zval *zid = NULL;
- cl_device_id device = NULL;
- long name = 0;
-
- RETVAL_FALSE;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
- "r|l", &zid, &name) == FAILURE) {
- return;
- }
- ZEND_FETCH_RESOURCE(device, cl_device_id, &zid, -1,
- "cl_device_id", phpcl_le_device());
-
- if (ZEND_NUM_ARGS() == 2) {
- _get_device_info_by_name(INTERNAL_FUNCTION_PARAM_PASSTHRU, device, (cl_int)name);
- } else {
- _get_device_info_all(INTERNAL_FUNCTION_PARAM_PASSTHRU, device);
- }
-}
-
/* }}} */
/*
View
116 event.c
@@ -0,0 +1,116 @@
+/**
+ * The OpenCL PHP extension
+ *
+ * @package php-opencl
+ * @author Ryusuke SEKIYAMA <rsky0711@gmail.com>
+ * @copyright 2012 Ryusuke SEKIYAMA
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ */
+
+#include "event.h"
+
+#define get_info ((phpcl_get_info_func_t)_get_event_info)
+#define get_info_ex NULL
+
+/* {{{ globals */
+
+static const phpcl_info_param_t event_info_params[] = {
+ { NULL, 0 }
+};
+
+/* }}} */
+/* {{{ _get_event_info() */
+
+static cl_int _get_event_info(cl_event event,
+ void *reserved __attribute__ ((unused)),
+ cl_event_info name,
+ size_t value_size,
+ void *value,
+ size_t *value_size_ret)
+{
+ return clGetEventInfo(event, name, value_size, value, value_size_ret);
+}
+
+/* }}} */
+/* {{{ _get_event_info_all() */
+
+static void _get_event_info_all(INTERNAL_FUNCTION_PARAMETERS,
+ cl_event event)
+{
+ const phpcl_info_param_t *param = event_info_params;
+ char buf[32] = {0};
+
+ array_init_size(return_value, 8);
+ snprintf(buf, sizeof(buf), "%p", event);
+ add_assoc_string(return_value, "id", buf, 1);
+
+ while (param->key != NULL) {
+ zval *entry = phpcl_get_info(get_info, get_info_ex,
+ event, NULL, param TSRMLS_CC);
+ if (entry) {
+ add_assoc_zval(return_value, param->key, entry);
+ } else {
+ add_assoc_null(return_value, param->key);
+ }
+ param++;
+ }
+}
+
+/* }}} */
+/* {{{ _get_event_info_by_name() */
+
+static void _get_event_info_by_name(INTERNAL_FUNCTION_PARAMETERS,
+ cl_event event, cl_int name)
+{
+ const phpcl_info_param_t *param = event_info_params;
+
+ RETVAL_NULL();
+
+ while (param->key != NULL) {
+ if (param->name == name) {
+ zval *entry = phpcl_get_info(get_info, get_info_ex,
+ event, NULL, param TSRMLS_CC);
+ if (entry) {
+ RETVAL_ZVAL(entry, 0, 1);
+ }
+ return;
+ }
+ param++;
+ }
+}
+
+/* }}} */
+/* {{{ mixed cl_get_event_info(resource cl_event event[, int name]) */
+
+PHP_FUNCTION(cl_get_event_info)
+{
+ zval *zid = NULL;
+ cl_event event = NULL;
+ long name = 0;
+
+ RETVAL_FALSE;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
+ "r|l", &zid, &name) == FAILURE) {
+ return;
+ }
+ ZEND_FETCH_RESOURCE(event, cl_event, &zid, -1,
+ "cl_event", phpcl_le_event());
+
+ if (ZEND_NUM_ARGS() == 2) {
+ _get_event_info_by_name(INTERNAL_FUNCTION_PARAM_PASSTHRU, event, (cl_int)name);
+ } else {
+ _get_event_info_all(INTERNAL_FUNCTION_PARAM_PASSTHRU, event);
+ }
+}
+
+/* }}} */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
View
26 event.h
@@ -0,0 +1,26 @@
+/**
+ * The OpenCL PHP extension
+ *
+ * @package php-opencl
+ * @author Ryusuke SEKIYAMA <rsky0711@gmail.com>
+ * @copyright 2012 Ryusuke SEKIYAMA
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ */
+
+#include "php_opencl.h"
+
+#ifndef PHPCL_EVENT_H
+#define PHPCL_EVENT_H
+
+PHP_FUNCTION(cl_get_event_info);
+
+#endif
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
Oops, something went wrong.

0 comments on commit 675d59a

Please sign in to comment.