forked from rsky/php-opencl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparams.c
71 lines (61 loc) · 1.5 KB
/
params.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* 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 "params.h"
/* {{{ phpcl_is_callable() */
PHPCL_LOCAL zend_bool
phpcl_is_callable(zval *zv, int argno TSRMLS_DC)
{
if (!zend_is_callable(zv, 0, NULL TSRMLS_CC)) {
if (argno > 0) {
php_error(E_WARNING,
"%s() expects parameter %d to be a valid callback",
get_active_function_name(TSRMLS_C), argno);
}
return 0;
}
return 1;
}
/* }}} */
/* {{{ phpcl_get_devicecs() */
PHPCL_LOCAL cl_device_id *
phpcl_get_devicecs(zval *zv, int argno, cl_uint *num_devices_ret TSRMLS_DC)
{
cl_device_id *devices = NULL;
cl_uint num_devices = 0;
if (Z_TYPE_P(zv) == IS_RESOURCE) {
cl_device_id device = NULL;
ZEND_FETCH_RESOURCE_NO_RETURN(device, cl_device_id, &zv, -1,
"cl_device", phpcl_le_device());
if (device) {
devices = emalloc(sizeof(cl_device_id));
devices[0] = device;
num_devices = 1;
}
} else {
/* TODO: support multiple devices */
if (argno > 0) {
php_error(E_WARNING,
"%s() expects parameter %d to be a valid resource",
get_active_function_name(TSRMLS_C), argno);
}
}
if (num_devices_ret) {
*num_devices_ret = num_devices;
}
return devices;
}
/* }}} */
/*
* 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
*/