-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrindow_clblast.c
More file actions
167 lines (150 loc) · 4.54 KB
/
Copy pathrindow_clblast.c
File metadata and controls
167 lines (150 loc) · 4.54 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/* rindow_clblast extension for PHP */
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <php.h>
#include <Zend/zend_interfaces.h>
#include <Zend/zend_exceptions.h>
#include <ext/spl/spl_iterators.h>
#include <ext/spl/spl_exceptions.h>
#include "ext/standard/info.h"
#define CL_TARGET_OPENCL_VERSION 120
#include <CL/opencl.h>
#include <Rindow/OpenCL/EventList.h>
#include <Interop/Polite/Math/Matrix.h>
#include "php_rindow_clblast.h"
#if _MSC_VER
extern int rindow_load_clblast_dll();
extern void rindow_unload_clblast_dll();
#endif
/* For compatibility with older PHP versions */
#ifndef ZEND_PARSE_PARAMETERS_NONE
#define ZEND_PARSE_PARAMETERS_NONE() \
ZEND_PARSE_PARAMETERS_START(0, 0) \
ZEND_PARSE_PARAMETERS_END()
#endif
int php_rindow_clblast_append_event(zval* event_list_obj_p, cl_event* event)
{
php_rindow_opencl_event_list_t *events;
if(event==NULL || event_list_obj_p==NULL || Z_TYPE_P(event_list_obj_p) != IS_OBJECT) {
return 0;
}
events = Z_RINDOW_OPENCL_EVENT_LIST_OBJ_P(event_list_obj_p);
events->events = erealloc(events->events, (events->num + 1)*sizeof(cl_event));
if(events->events==NULL) {
zend_throw_exception(spl_ce_RuntimeException, "EventList reallocate error", 0);
return -1;
}
memcpy(&(events->events[events->num]),event,sizeof(cl_event));
events->num++;
return 0;
}
int php_rindow_clblast_assert_opencl_buffer_type(
php_rindow_opencl_buffer_t *buffer,
char* name)
{
if(buffer->signature!=PHP_RINDOW_OPENCL_BUFFER_SIGNATURE) {
zend_throw_exception_ex(zend_ce_type_error, 0, "%s must implement interface %s",
name,PHP_RINDOW_OPENCL_BUFFER_CLASSNAME);
return 1;
}
return 0;
}
int php_rindow_clblast_assert_opencl_command_queue_type(
php_rindow_opencl_command_queue_t *queue,
char* name)
{
if(queue->signature!=PHP_RINDOW_OPENCL_COMMAND_QUEUE_SIGNATURE) {
zend_throw_exception_ex(zend_ce_type_error, 0, "%s must implement interface %s",
name,PHP_RINDOW_OPENCL_COMMAND_QUEUE_CLASSNAME);
return 1;
}
return 0;
}
int php_rindow_clblast_assert_opencl_event_list_type(
php_rindow_opencl_event_list_t *events,
char* name)
{
if(events->signature!=PHP_RINDOW_OPENCL_EVENT_LIST_SIGNATURE) {
zend_throw_exception_ex(zend_ce_type_error, 0, "%s must implement interface %s",
name,PHP_RINDOW_OPENCL_EVENT_LIST_CLASSNAME);
return 1;
}
return 0;
}
int php_rindow_clblast_assert_host_buffer_type(
php_interop_polite_math_matrix_linear_buffer_t *buffer,
char* name)
{
if(!php_interop_polite_math_matrix_is_linear_buffer(buffer)) {
zend_throw_exception_ex(zend_ce_type_error, 0, "%s must implement interface %s",
name,PHP_INTEROP_POLITE_MATH_MATRIX_LINEAR_BUFFER_CLASSNAME);
return 1;
}
return 0;
}
/* {{{ PHP_RINIT_FUNCTION
*/
PHP_RINIT_FUNCTION(rindow_clblast)
{
#if defined(ZTS) && defined(COMPILE_DL_RINDOW_CLBLAST)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION
*/
PHP_MINFO_FUNCTION(rindow_clblast)
{
php_info_print_table_start();
php_info_print_table_header(2, "rindow_clblast support", "enabled");
php_info_print_table_end();
}
/* }}} */
/* {{{ rindow_clblast_functions[]
*/
//static const zend_function_entry rindow_clblast_functions[] = {
//};
/* }}} */
PHP_MINIT_FUNCTION(rindow_clblast)
{
#if _MSC_VER
int rc=rindow_load_clblast_dll();
if(rc!=0) {
rindow_unload_clblast_dll();
return FAILURE;
}
#endif
php_rindow_clblast_blas_init_ce(INIT_FUNC_ARGS_PASSTHRU);
php_rindow_clblast_math_init_ce(INIT_FUNC_ARGS_PASSTHRU);
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(rindow_clblast)
{
#if _MSC_VER
rindow_unload_clblast_dll();
#endif
return SUCCESS;
}
/* {{{ php_rindow_clblast_module_entry
*/
zend_module_entry rindow_clblast_module_entry = {
STANDARD_MODULE_HEADER,
"rindow_clblast", /* Extension name */
NULL, /* zend_function_entry */
PHP_MINIT(rindow_clblast), /* PHP_MINIT - Module initialization */
PHP_MSHUTDOWN(rindow_clblast), /* PHP_MSHUTDOWN - Module shutdown */
PHP_RINIT(rindow_clblast), /* PHP_RINIT - Request initialization */
NULL, /* PHP_RSHUTDOWN - Request shutdown */
PHP_MINFO(rindow_clblast), /* PHP_MINFO - Module info */
PHP_RINDOW_CLBLAST_VERSION, /* Version */
STANDARD_MODULE_PROPERTIES
};
/* }}} */
#ifdef COMPILE_DL_RINDOW_CLBLAST
# ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE()
# endif
ZEND_GET_MODULE(rindow_clblast)
#endif