Skip to content

Commit 11e6192

Browse files
Windows test (#13)
* Remove build/skip * Add bld.bat * Fix OpenCL.lib path * Fix runtime_library_dirs * Add DPPL_API to dppl_oneapi_interface.hppdppl_oneapi_interface.hpp * Add DPPL_API to dppl_opencl_interface.h * Remove DPPL_API from dppl_opencl_interface.h for CFFI * Add run_test.bat * Add clean to bld.bat * Create singleton function for gRtHelper * Fix defining DPPL_API * Source oneAPI in Windows tests * Use make and ninja on unix and win * Use -DCMAKE_PREFIX_PATH=%LIBRARY_PREFIX% * Update oneapi_wrapper/source/dppl_oneapi_interface.cpp Co-authored-by: Diptorup Deb <[email protected]>
1 parent 5e83ed8 commit 11e6192

File tree

9 files changed

+115
-6
lines changed

9 files changed

+115
-6
lines changed

conda-recipe/bld.bat

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
call "%ONEAPI_ROOT%compiler\latest\env\vars.bat"
2+
set "CC=dpcpp-cl.exe"
3+
set "CXX=dpcpp-cl.exe"
4+
5+
rmdir /S /Q build_cmake
6+
mkdir build_cmake
7+
cd build_cmake
8+
9+
set "DPCPP_ROOT=%ONEAPI_ROOT%/compiler/latest/windows"
10+
11+
cmake -G Ninja ^
12+
-DCMAKE_BUILD_TYPE=Release ^
13+
"-DCMAKE_INSTALL_PREFIX=%LIBRARY_PREFIX%" ^
14+
"-DCMAKE_PREFIX_PATH=%LIBRARY_PREFIX%" ^
15+
"-DDPCPP_ROOT=%DPCPP_ROOT%" ^
16+
"%SRC_DIR%/oneapi_wrapper"
17+
IF %ERRORLEVEL% NEQ 0 exit 1
18+
19+
ninja -n
20+
ninja install
21+
IF %ERRORLEVEL% NEQ 0 exit 1
22+
23+
cd ..
24+
25+
REM required by dpglue
26+
set "DP_GLUE_LIBDIR=%LIBRARY_PREFIX%/lib"
27+
set "DP_GLUE_INCLDIR=%LIBRARY_PREFIX%/include"
28+
set "OpenCL_LIBDIR=%DPCPP_ROOT%/lib"
29+
REM required by oneapi_interface
30+
set "DPPL_ONEAPI_INTERFACE_LIBDIR=%LIBRARY_PREFIX%/lib"
31+
set "DPPL_ONEAPI_INTERFACE_INCLDIR=%LIBRARY_PREFIX%/include"
32+
33+
"%PYTHON%" setup.py clean --all
34+
"%PYTHON%" setup.py build
35+
"%PYTHON%" setup.py install
36+
IF %ERRORLEVEL% NEQ 0 exit 1

conda-recipe/meta.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ source:
99

1010
build:
1111
number: 0
12-
skip: True # [not linux]
1312
script_env:
1413
- ONEAPI_ROOT
1514

@@ -22,7 +21,8 @@ requirements:
2221
- cython
2322
- cmake
2423
- python
25-
- make
24+
- make # [unix]
25+
- ninja # [win]
2626
- numpy >=1.17
2727
run:
2828
- python
@@ -36,3 +36,4 @@ about:
3636
extra:
3737
recipe-maintainers:
3838
- diptorup deb
39+
- PokhodenkoSA

conda-recipe/run_test.bat

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
call "%ONEAPI_ROOT%/compiler/latest/env/vars.bat"
2+
REM IF %ERRORLEVEL% NEQ 0 exit 1
3+
4+
"%PYTHON%" -c "import dppl"
5+
IF %ERRORLEVEL% NEQ 0 exit 1
6+
7+
"%PYTHON%" -c "import dppl.ocldrv"
8+
IF %ERRORLEVEL% NEQ 0 exit 1

dppl/driverapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
glue_h = ''.join(list(filter(lambda x: len(x) > 0 and x[0] != "#",
5050
open(dpglue_incldir +
5151
'/dppl_opencl_interface.h', 'r')
52-
.readlines())))
52+
.readlines()))).replace('DPPL_API', '')
5353

5454
# cdef() expects a single string declaring the C types, functions and
5555
# globals needed to use the shared object. It must be in valid C syntax.

oneapi_wrapper/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ if(WIN32)
150150
target_link_libraries(
151151
DPPLOpenCLInterface
152152
PRIVATE
153-
${OpenCL_INCLUDE_DIR}/../lib/x64/OpenCL.lib
153+
${DPCPP_ROOT}/lib/OpenCL.lib
154154
)
155155
endif()
156156

oneapi_wrapper/include/dppl_oneapi_interface.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@
2929
#include <cstdlib>
3030
#include <deque>
3131

32+
#ifdef _WIN32
33+
# ifdef DPPLOneapiInterface_EXPORTS
34+
# define DPPL_API __declspec(dllexport)
35+
# else
36+
# define DPPL_API __declspec(dllimport)
37+
# endif
38+
#else
39+
# define DPPL_API
40+
#endif
41+
3242
namespace dppl
3343
{
3444

@@ -59,26 +69,35 @@ enum class sycl_device_type : unsigned int
5969
class DpplOneAPIRuntime
6070
{
6171
public:
72+
DPPL_API
6273
int64_t getNumPlatforms (size_t *platforms) const;
74+
DPPL_API
6375
int64_t getCurrentQueue (void **Q) const;
76+
DPPL_API
6477
int64_t getQueue (void **Q,
6578
dppl::sycl_device_type DeviceTy,
6679
size_t DNum = 0) const;
80+
DPPL_API
6781
int64_t resetGlobalQueue (dppl::sycl_device_type DeviceTy,
6882
size_t DNum = 0);
6983
/*!
7084
* Push a new sycl queue to the top of the activate_queues deque. The
7185
* newly activated queue is returned to caller inside the Q object.
7286
*/
87+
DPPL_API
7388
int64_t activateQueue (void **Q,
7489
dppl::sycl_device_type DeviceTy,
7590
size_t DNum);
91+
DPPL_API
7692
int64_t deactivateCurrentQueue ();
93+
DPPL_API
7794
int64_t dump () const;
95+
DPPL_API
7896
int64_t dump_queue (const void *Q) const;
7997
};
8098

8199

100+
DPPL_API
82101
int64_t deleteQueue (void *Q);
83102

84103
} /* end of namespace dppl */

oneapi_wrapper/include/dppl_opencl_interface.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@
2929
#include <stdbool.h>
3030
#include <stdlib.h>
3131

32+
33+
#ifdef _WIN32
34+
# ifdef DPPLOpenCLInterface_EXPORTS
35+
# define DPPL_API __declspec(dllexport)
36+
# else
37+
# define DPPL_API __declspec(dllimport)
38+
# endif
39+
#else
40+
# define DPPL_API
41+
#endif
42+
43+
3244
enum DP_GLUE_ERROR_CODES
3345
{
3446
DP_GLUE_SUCCESS = 0,
@@ -122,6 +134,7 @@ struct dp_runtime
122134

123135
typedef struct dp_runtime* runtime_t;
124136

137+
DPPL_API
125138
int set_curr_env (runtime_t rt, env_t env);
126139

127140
/*!
@@ -133,6 +146,7 @@ int set_curr_env (runtime_t rt, env_t env);
133146
* @return An error code indicating if the runtime_t object was successfully
134147
* initialized.
135148
*/
149+
DPPL_API
136150
int create_dp_runtime (runtime_t *rt);
137151

138152

@@ -143,21 +157,25 @@ int create_dp_runtime (runtime_t *rt);
143157
*
144158
* @return An error code indicating if resource freeing was successful.
145159
*/
160+
DPPL_API
146161
int destroy_dp_runtime (runtime_t *rt);
147162

148163

149164
/*!
150165
*
151166
*/
167+
DPPL_API
152168
int create_dp_rw_mem_buffer (env_t env_t_ptr, size_t buffsize, buffer_t *buff);
153169

154170

171+
DPPL_API
155172
int destroy_dp_rw_mem_buffer (buffer_t *buff);
156173

157174

158175
/*!
159176
*
160177
*/
178+
DPPL_API
161179
int write_dp_mem_buffer_to_device (env_t env_t_ptr,
162180
buffer_t buff,
163181
bool blocking_copy,
@@ -169,6 +187,7 @@ int write_dp_mem_buffer_to_device (env_t env_t_ptr,
169187
/*!
170188
*
171189
*/
190+
DPPL_API
172191
int read_dp_mem_buffer_from_device (env_t env_t_ptr,
173192
buffer_t buff,
174193
bool blocking_copy,
@@ -180,6 +199,7 @@ int read_dp_mem_buffer_from_device (env_t env_t_ptr,
180199
/*!
181200
*
182201
*/
202+
DPPL_API
183203
int create_dp_program_from_spirv (env_t env_t_ptr,
184204
const void *il,
185205
size_t length,
@@ -189,6 +209,7 @@ int create_dp_program_from_spirv (env_t env_t_ptr,
189209
/*!
190210
*
191211
*/
212+
DPPL_API
192213
int create_dp_program_from_source (env_t env_t_ptr,
193214
unsigned int count,
194215
const char **strings,
@@ -198,26 +219,31 @@ int create_dp_program_from_source (env_t env_t_ptr,
198219
/*!
199220
*
200221
*/
222+
DPPL_API
201223
int destroy_dp_program (program_t *program_t_ptr);
202224

203225

226+
DPPL_API
204227
int build_dp_program (env_t env_t_ptr, program_t program_t_ptr);
205228

206229
/*!
207230
*
208231
*/
232+
DPPL_API
209233
int create_dp_kernel (env_t env_t_ptr,
210234
program_t program_ptr,
211235
const char *kernel_name,
212236
kernel_t *kernel_ptr);
213237

214238

239+
DPPL_API
215240
int destroy_dp_kernel (kernel_t *kernel_ptr);
216241

217242

218243
/*!
219244
*
220245
*/
246+
DPPL_API
221247
int create_dp_kernel_arg (const void *arg_value,
222248
size_t arg_size,
223249
kernel_arg_t *kernel_arg_t_ptr);
@@ -226,19 +252,22 @@ int create_dp_kernel_arg (const void *arg_value,
226252
/*!
227253
*
228254
*/
255+
DPPL_API
229256
int create_dp_kernel_arg_from_buffer (buffer_t *buffer_t_ptr,
230257
kernel_arg_t *kernel_arg_t_ptr);
231258

232259

233260
/*!
234261
*
235262
*/
263+
DPPL_API
236264
int destroy_dp_kernel_arg (kernel_arg_t *kernel_arg_t_ptr);
237265

238266

239267
/*!
240268
*
241269
*/
270+
DPPL_API
242271
int set_args_and_enqueue_dp_kernel (env_t env_t_ptr,
243272
kernel_t kernel_t_ptr,
244273
size_t nargs,
@@ -252,6 +281,7 @@ int set_args_and_enqueue_dp_kernel (env_t env_t_ptr,
252281
/*!
253282
*
254283
*/
284+
DPPL_API
255285
int set_args_and_enqueue_dp_kernel_auto_blocking (env_t env_t_ptr,
256286
kernel_t kernel_t_ptr,
257287
size_t nargs,
@@ -264,12 +294,14 @@ int set_args_and_enqueue_dp_kernel_auto_blocking (env_t env_t_ptr,
264294
/*!
265295
*
266296
*/
297+
DPPL_API
267298
int retain_dp_context (env_t env_t_ptr);
268299

269300

270301
/*!
271302
*
272303
*/
304+
DPPL_API
273305
int release_dp_context (env_t env_t_ptr);
274306

275307

oneapi_wrapper/source/dppl_oneapi_interface.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,15 @@ class DpplOneAPIRuntimeHelper
106106
friend dppl::DpplOneAPIRuntime;
107107
};
108108

109-
DpplOneAPIRuntimeHelper gRtHelper;
109+
// This singleton function is needed to create the DpplOneAPIRuntimeHelper object
110+
// in a predictable manner without which there is a chance of segfault.
111+
DpplOneAPIRuntimeHelper& get_gRtHelper()
112+
{
113+
static DpplOneAPIRuntimeHelper * helper = new DpplOneAPIRuntimeHelper();
114+
return *helper;
115+
}
116+
117+
#define gRtHelper get_gRtHelper()
110118

111119
} /* end of anonymous namespace */
112120

setup.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ def getpyexts():
9999
elif IS_MAC:
100100
librarys = [dppl_oneapi_interface_lib]
101101

102+
if IS_LIN or IS_MAC:
103+
runtime_library_dirs = [os.path.abspath('dppl')]
104+
elif IS_WIN:
105+
runtime_library_dirs = []
106+
102107
exts = cythonize(Extension('dppl._oneapi_interface',
103108
[os.path.abspath('dppl/oneapi_interface.pyx'),],
104109
depends=[dppl_oneapi_interface_include,],
@@ -108,7 +113,7 @@ def getpyexts():
108113
extra_link_args=ela,
109114
libraries=libs,
110115
library_dirs=librarys,
111-
runtime_library_dirs=[os.path.abspath('dppl')],
116+
runtime_library_dirs=runtime_library_dirs,
112117
language='c++'))
113118
return exts
114119

0 commit comments

Comments
 (0)