Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions conda-recipe/bld.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
call "%ONEAPI_ROOT%compiler\latest\env\vars.bat"
set "CC=dpcpp-cl.exe"
set "CXX=dpcpp-cl.exe"

rmdir /S /Q build_cmake
mkdir build_cmake
cd build_cmake

set "DPCPP_ROOT=%ONEAPI_ROOT%/compiler/latest/windows"

cmake -G Ninja ^
-DCMAKE_BUILD_TYPE=Release ^
"-DCMAKE_INSTALL_PREFIX=%LIBRARY_PREFIX%" ^
"-DCMAKE_PREFIX_PATH=%LIBRARY_PREFIX%" ^
"-DDPCPP_ROOT=%DPCPP_ROOT%" ^
"%SRC_DIR%/oneapi_wrapper"
IF %ERRORLEVEL% NEQ 0 exit 1

ninja -n
ninja install
IF %ERRORLEVEL% NEQ 0 exit 1

cd ..

REM required by dpglue
set "DP_GLUE_LIBDIR=%LIBRARY_PREFIX%/lib"
set "DP_GLUE_INCLDIR=%LIBRARY_PREFIX%/include"
set "OpenCL_LIBDIR=%DPCPP_ROOT%/lib"
REM required by oneapi_interface
set "DPPL_ONEAPI_INTERFACE_LIBDIR=%LIBRARY_PREFIX%/lib"
set "DPPL_ONEAPI_INTERFACE_INCLDIR=%LIBRARY_PREFIX%/include"

"%PYTHON%" setup.py clean --all
"%PYTHON%" setup.py build
"%PYTHON%" setup.py install
IF %ERRORLEVEL% NEQ 0 exit 1
5 changes: 3 additions & 2 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ source:

build:
number: 0
skip: True # [not linux]
script_env:
- ONEAPI_ROOT

Expand All @@ -22,7 +21,8 @@ requirements:
- cython
- cmake
- python
- make
- make # [unix]
- ninja # [win]
- numpy >=1.17
run:
- python
Expand All @@ -36,3 +36,4 @@ about:
extra:
recipe-maintainers:
- diptorup deb
- PokhodenkoSA
8 changes: 8 additions & 0 deletions conda-recipe/run_test.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
call "%ONEAPI_ROOT%/compiler/latest/env/vars.bat"
REM IF %ERRORLEVEL% NEQ 0 exit 1

"%PYTHON%" -c "import dppl"
IF %ERRORLEVEL% NEQ 0 exit 1

"%PYTHON%" -c "import dppl.ocldrv"
IF %ERRORLEVEL% NEQ 0 exit 1
2 changes: 1 addition & 1 deletion dppl/driverapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
glue_h = ''.join(list(filter(lambda x: len(x) > 0 and x[0] != "#",
open(dpglue_incldir +
'/dppl_opencl_interface.h', 'r')
.readlines())))
.readlines()))).replace('DPPL_API', '')

# cdef() expects a single string declaring the C types, functions and
# globals needed to use the shared object. It must be in valid C syntax.
Expand Down
2 changes: 1 addition & 1 deletion oneapi_wrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ if(WIN32)
target_link_libraries(
DPPLOpenCLInterface
PRIVATE
${OpenCL_INCLUDE_DIR}/../lib/x64/OpenCL.lib
${DPCPP_ROOT}/lib/OpenCL.lib
)
endif()

Expand Down
19 changes: 19 additions & 0 deletions oneapi_wrapper/include/dppl_oneapi_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
#include <cstdlib>
#include <deque>

#ifdef _WIN32
# ifdef DPPLOneapiInterface_EXPORTS
# define DPPL_API __declspec(dllexport)
# else
# define DPPL_API __declspec(dllimport)
# endif
#else
# define DPPL_API
#endif

namespace dppl
{

Expand Down Expand Up @@ -59,26 +69,35 @@ enum class sycl_device_type : unsigned int
class DpplOneAPIRuntime
{
public:
DPPL_API
int64_t getNumPlatforms (size_t *platforms) const;
DPPL_API
int64_t getCurrentQueue (void **Q) const;
DPPL_API
int64_t getQueue (void **Q,
dppl::sycl_device_type DeviceTy,
size_t DNum = 0) const;
DPPL_API
int64_t resetGlobalQueue (dppl::sycl_device_type DeviceTy,
size_t DNum = 0);
/*!
* Push a new sycl queue to the top of the activate_queues deque. The
* newly activated queue is returned to caller inside the Q object.
*/
DPPL_API
int64_t activateQueue (void **Q,
dppl::sycl_device_type DeviceTy,
size_t DNum);
DPPL_API
int64_t deactivateCurrentQueue ();
DPPL_API
int64_t dump () const;
DPPL_API
int64_t dump_queue (const void *Q) const;
};


DPPL_API
int64_t deleteQueue (void *Q);

} /* end of namespace dppl */
32 changes: 32 additions & 0 deletions oneapi_wrapper/include/dppl_opencl_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
#include <stdbool.h>
#include <stdlib.h>


#ifdef _WIN32
# ifdef DPPLOpenCLInterface_EXPORTS
# define DPPL_API __declspec(dllexport)
# else
# define DPPL_API __declspec(dllimport)
# endif
#else
# define DPPL_API
#endif


enum DP_GLUE_ERROR_CODES
{
DP_GLUE_SUCCESS = 0,
Expand Down Expand Up @@ -122,6 +134,7 @@ struct dp_runtime

typedef struct dp_runtime* runtime_t;

DPPL_API
int set_curr_env (runtime_t rt, env_t env);

/*!
Expand All @@ -133,6 +146,7 @@ int set_curr_env (runtime_t rt, env_t env);
* @return An error code indicating if the runtime_t object was successfully
* initialized.
*/
DPPL_API
int create_dp_runtime (runtime_t *rt);


Expand All @@ -143,21 +157,25 @@ int create_dp_runtime (runtime_t *rt);
*
* @return An error code indicating if resource freeing was successful.
*/
DPPL_API
int destroy_dp_runtime (runtime_t *rt);


/*!
*
*/
DPPL_API
int create_dp_rw_mem_buffer (env_t env_t_ptr, size_t buffsize, buffer_t *buff);


DPPL_API
int destroy_dp_rw_mem_buffer (buffer_t *buff);


/*!
*
*/
DPPL_API
int write_dp_mem_buffer_to_device (env_t env_t_ptr,
buffer_t buff,
bool blocking_copy,
Expand All @@ -169,6 +187,7 @@ int write_dp_mem_buffer_to_device (env_t env_t_ptr,
/*!
*
*/
DPPL_API
int read_dp_mem_buffer_from_device (env_t env_t_ptr,
buffer_t buff,
bool blocking_copy,
Expand All @@ -180,6 +199,7 @@ int read_dp_mem_buffer_from_device (env_t env_t_ptr,
/*!
*
*/
DPPL_API
int create_dp_program_from_spirv (env_t env_t_ptr,
const void *il,
size_t length,
Expand All @@ -189,6 +209,7 @@ int create_dp_program_from_spirv (env_t env_t_ptr,
/*!
*
*/
DPPL_API
int create_dp_program_from_source (env_t env_t_ptr,
unsigned int count,
const char **strings,
Expand All @@ -198,26 +219,31 @@ int create_dp_program_from_source (env_t env_t_ptr,
/*!
*
*/
DPPL_API
int destroy_dp_program (program_t *program_t_ptr);


DPPL_API
int build_dp_program (env_t env_t_ptr, program_t program_t_ptr);

/*!
*
*/
DPPL_API
int create_dp_kernel (env_t env_t_ptr,
program_t program_ptr,
const char *kernel_name,
kernel_t *kernel_ptr);


DPPL_API
int destroy_dp_kernel (kernel_t *kernel_ptr);


/*!
*
*/
DPPL_API
int create_dp_kernel_arg (const void *arg_value,
size_t arg_size,
kernel_arg_t *kernel_arg_t_ptr);
Expand All @@ -226,19 +252,22 @@ int create_dp_kernel_arg (const void *arg_value,
/*!
*
*/
DPPL_API
int create_dp_kernel_arg_from_buffer (buffer_t *buffer_t_ptr,
kernel_arg_t *kernel_arg_t_ptr);


/*!
*
*/
DPPL_API
int destroy_dp_kernel_arg (kernel_arg_t *kernel_arg_t_ptr);


/*!
*
*/
DPPL_API
int set_args_and_enqueue_dp_kernel (env_t env_t_ptr,
kernel_t kernel_t_ptr,
size_t nargs,
Expand All @@ -252,6 +281,7 @@ int set_args_and_enqueue_dp_kernel (env_t env_t_ptr,
/*!
*
*/
DPPL_API
int set_args_and_enqueue_dp_kernel_auto_blocking (env_t env_t_ptr,
kernel_t kernel_t_ptr,
size_t nargs,
Expand All @@ -264,12 +294,14 @@ int set_args_and_enqueue_dp_kernel_auto_blocking (env_t env_t_ptr,
/*!
*
*/
DPPL_API
int retain_dp_context (env_t env_t_ptr);


/*!
*
*/
DPPL_API
int release_dp_context (env_t env_t_ptr);


Expand Down
10 changes: 9 additions & 1 deletion oneapi_wrapper/source/dppl_oneapi_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,15 @@ class DpplOneAPIRuntimeHelper
friend dppl::DpplOneAPIRuntime;
};

DpplOneAPIRuntimeHelper gRtHelper;
// This singleton function is needed to create the DpplOneAPIRuntimeHelper object
// in a predictable manner without which there is a chance of segfault.
DpplOneAPIRuntimeHelper& get_gRtHelper()
{
static DpplOneAPIRuntimeHelper * helper = new DpplOneAPIRuntimeHelper();
return *helper;
}

#define gRtHelper get_gRtHelper()

} /* end of anonymous namespace */

Expand Down
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ def getpyexts():
elif IS_MAC:
librarys = [dppl_oneapi_interface_lib]

if IS_LIN or IS_MAC:
runtime_library_dirs = [os.path.abspath('dppl')]
elif IS_WIN:
runtime_library_dirs = []

exts = cythonize(Extension('dppl._oneapi_interface',
[os.path.abspath('dppl/oneapi_interface.pyx'),],
depends=[dppl_oneapi_interface_include,],
Expand All @@ -108,7 +113,7 @@ def getpyexts():
extra_link_args=ela,
libraries=libs,
library_dirs=librarys,
runtime_library_dirs=[os.path.abspath('dppl')],
runtime_library_dirs=runtime_library_dirs,
language='c++'))
return exts

Expand Down