Skip to content

Commit 304931b

Browse files
Merge pull request #69 from IntelPython/add-get-include-and-include-headers
Add get include and include headers
2 parents f372028 + aa71c98 commit 304931b

File tree

8 files changed

+109
-37
lines changed

8 files changed

+109
-37
lines changed

MANIFEST.in

+4
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
include versioneer.py
2+
recursive-include dpctl/include *.h *.hpp
3+
include dpctl/*.pxd
4+
include dpctl/*DPPL*Interface.*
5+
global-exclude *.cpp

conda-recipe/bld.bat

+18-10
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ rmdir /S /Q build_cmake
1010
mkdir build_cmake
1111
cd build_cmake
1212

13-
set "DPCPP_ROOT=%ONEAPI_ROOT%/compiler/latest/windows"
13+
set "DPCPP_ROOT=%ONEAPI_ROOT%\compiler\latest\windows"
14+
set "INSTALL_PREFIX=%cd%\..\install"
15+
16+
rmdir /S /Q "%INSTALL_PREFIX%"
1417

1518
cmake -G Ninja ^
1619
-DCMAKE_BUILD_TYPE=Release ^
@@ -25,17 +28,22 @@ ninja install
2528
IF %ERRORLEVEL% NEQ 0 exit 1
2629

2730
cd ..
31+
xcopy install\lib\*.lib dpctl /E /Y
32+
xcopy install\lib\*.dll dpctl /E /Y
33+
34+
mkdir dpctl\include
35+
xcopy backends\include dpctl\include /E /Y
36+
2837

29-
REM required by dpglue
30-
set "DPPL_OPENCL_INTERFACE_LIBDIR=%LIBRARY_PREFIX%/lib"
31-
set "DPPL_OPENCL_INTERFACE_INCLDIR=%LIBRARY_PREFIX%/include"
32-
set "OpenCL_LIBDIR=%DPCPP_ROOT%/lib"
38+
REM required by _opencl_core (dpctl.ocldrv)
39+
set "DPPL_OPENCL_INTERFACE_LIBDIR=dpctl"
40+
set "DPPL_OPENCL_INTERFACE_INCLDIR=dpctl\include"
41+
set "OpenCL_LIBDIR=%DPCPP_ROOT%\lib"
3342

34-
REM required by oneapi_interface
35-
set "DPPL_SYCL_INTERFACE_LIBDIR=%LIBRARY_PREFIX%/lib"
36-
set "DPPL_SYCL_INTERFACE_INCLDIR=%LIBRARY_PREFIX%/include"
43+
REM required by _sycl_core(dpctl)
44+
set "DPPL_SYCL_INTERFACE_LIBDIR=dpctl"
45+
set "DPPL_SYCL_INTERFACE_INCLDIR=dpctl\include"
3746

3847
"%PYTHON%" setup.py clean --all
39-
"%PYTHON%" setup.py build
40-
"%PYTHON%" setup.py install
48+
"%PYTHON%" setup.py build install
4149
IF %ERRORLEVEL% NEQ 0 exit 1

conda-recipe/build.sh

+17-11
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ fi
1313

1414
rm -rf build_cmake
1515
mkdir build_cmake
16-
cd build_cmake
16+
pushd build_cmake
17+
18+
INSTALL_PREFIX=`pwd`/../install
19+
rm -rf ${INSTALL_PREFIX}
1720

1821
PYTHON_INC=`${PYTHON} -c "import distutils.sysconfig; \
1922
print(distutils.sysconfig.get_python_inc())"`
@@ -22,31 +25,34 @@ DPCPP_ROOT=${ONEAPI_ROOT}/compiler/latest/linux/
2225

2326
cmake \
2427
-DCMAKE_BUILD_TYPE=Release \
25-
-DCMAKE_INSTALL_PREFIX=${PREFIX} \
26-
-DCMAKE_PREFIX_PATH=${PREFIX} \
28+
-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \
29+
-DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} \
2730
-DDPCPP_ROOT=${DPCPP_ROOT} \
2831
-DPYTHON_INCLUDE_DIR=${PYTHON_INC} \
2932
-DNUMPY_INCLUDE_DIR=${NUMPY_INC} \
3033
../backends
3134

3235
make -j 4 && make install
3336

34-
cd ..
37+
popd
38+
cp install/lib/*.so dpctl/
39+
40+
mkdir -p dpctl/include
41+
cp -r backends/include/* dpctl/include
3542

3643
# required by dpctl.opencl_core
37-
export DPPL_OPENCL_INTERFACE_LIBDIR=${PREFIX}
38-
export DPPL_OPENCL_INTERFACE_INCLDIR=${PREFIX}/include
44+
export DPPL_OPENCL_INTERFACE_LIBDIR=dpctl
45+
export DPPL_OPENCL_INTERFACE_INCLDIR=dpctl/include
3946
export OpenCL_LIBDIR=${DPCPP_ROOT}/lib
4047

4148
# required by dpctl.sycl_core
42-
export DPPL_SYCL_INTERFACE_LIBDIR=${PREFIX}/lib
43-
export DPPL_SYCL_INTERFACE_INCLDIR=${PREFIX}/include
49+
export DPPL_SYCL_INTERFACE_LIBDIR=dpctl
50+
export DPPL_SYCL_INTERFACE_INCLDIR=dpctl/include
4451

4552

4653
# FIXME: How to pass this using setup.py? This flags is needed when
4754
# dpcpp compiles the generated cpp file.
4855
export CFLAGS="-fPIC -O3 ${CFLAGS}"
49-
export LDFLAGS="-L OpenCL_LIBDIR ${LDFLAGS}"
56+
export LDFLAGS="-L ${OpenCL_LIBDIR} ${LDFLAGS}"
5057
${PYTHON} setup.py clean --all
51-
${PYTHON} setup.py build
52-
${PYTHON} setup.py install
58+
${PYTHON} setup.py build install

dpctl/__init__.pxd

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
##===------------- sycl_core.pxd - dpctl module --------*- Cython -*-------===##
2+
##
3+
## Data Parallel Control (dpCtl)
4+
##
5+
## Copyright 2020 Intel Corporation
6+
##
7+
## Licensed under the Apache License, Version 2.0 (the "License");
8+
## you may not use this file except in compliance with the License.
9+
## You may obtain a copy of the License at
10+
##
11+
## http://www.apache.org/licenses/LICENSE-2.0
12+
##
13+
## Unless required by applicable law or agreed to in writing, software
14+
## distributed under the License is distributed on an "AS IS" BASIS,
15+
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
## See the License for the specific language governing permissions and
17+
## limitations under the License.
18+
##
19+
##===----------------------------------------------------------------------===##
20+
##
21+
## \file
22+
## This file declares the extension types and functions for the Cython API
23+
## implemented in sycl_core.pyx.
24+
##
25+
##===----------------------------------------------------------------------===##
26+
27+
# distutils: language = c++
28+
# cython: language_level=3
29+
30+
from dpctl._sycl_core cimport *

dpctl/__init__.py

+10
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,15 @@
4949
from ._sycl_core import *
5050
from ._version import get_versions
5151

52+
def get_include():
53+
"""
54+
Return the directory that contains the dpCtl *.h header files.
55+
56+
Extension modules that need to be compiled against dpCtl should use
57+
this function to locate the appropriate include directory.
58+
"""
59+
import os.path
60+
return os.path.join(os.path.dirname(__file__), 'include')
61+
5262
__version__ = get_versions()['version']
5363
del get_versions

dpctl/opencl_core.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,21 @@
5959

6060
ffi_lib_name = "dpctl._opencl_core"
6161

62+
import sys
63+
IS_WIN = sys.platform in ['win32', 'cygwin']
64+
del sys
65+
6266
ffi.set_source(
6367
ffi_lib_name,
6468
"""
6569
#include "dppl_opencl_interface.h" // the C header of the library
6670
""",
6771
include_dirs=[dppl_opencl_interface_incldir],
6872
library_dirs=[dppl_opencl_interface_libdir, opencl_libdir],
73+
extra_link_args=[] if IS_WIN else ['-Wl,-rpath=$ORIGIN'],
6974
libraries=["DPPLOpenCLInterface", "OpenCL"],
7075
) # library name, for the linker
71-
76+
del IS_WIN
7277

7378
if __name__ == "__main__":
7479
ffi.compile(verbose=True)

scripts/build_for_develop.sh

+12-8
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ pushd build_cmake
77
INSTALL_PREFIX=`pwd`/../install
88
rm -rf ${INSTALL_PREFIX}
99
export ONEAPI_ROOT=/opt/intel/oneapi
10-
DPCPP_ROOT=${ONEAPI_ROOT}/compiler/latest/linux
10+
1111
PYTHON_INC=`python -c "import distutils.sysconfig; \
1212
print(distutils.sysconfig.get_python_inc())"`
1313
NUMPY_INC=`python -c "import numpy; print(numpy.get_include())"`
14+
DPCPP_ROOT=${ONEAPI_ROOT}/compiler/latest/linux
1415

1516
cmake \
1617
-DCMAKE_BUILD_TYPE=Debug \
@@ -28,17 +29,20 @@ make V=1 -n -j 4 && make install
2829
popd
2930
cp install/lib/*.so dpctl/
3031

31-
export DPPL_OPENCL_INTERFACE_LIBDIR=${INSTALL_PREFIX}/lib
32-
export DPPL_OPENCL_INTERFACE_INCLDIR=${INSTALL_PREFIX}/include
33-
export OpenCL_LIBDIR=/usr/lib/x86_64-linux-gnu/
34-
export DPPL_SYCL_INTERFACE_LIBDIR=${INSTALL_PREFIX}/lib
35-
export DPPL_SYCL_INTERFACE_INCLDIR=${INSTALL_PREFIX}/include
32+
mkdir -p dpctl/include
33+
cp -r backends/include/* dpctl/include
34+
35+
export DPPL_OPENCL_INTERFACE_LIBDIR=dpctl
36+
export DPPL_OPENCL_INTERFACE_INCLDIR=dpctl/include
37+
# /usr/lib/x86_64-linux-gnu/
38+
export OpenCL_LIBDIR=${DPCPP_ROOT}/lib
39+
export DPPL_SYCL_INTERFACE_LIBDIR=dpctl
40+
export DPPL_SYCL_INTERFACE_INCLDIR=dpctl/include
3641

3742
export CC=clang
3843
export CXX=dpcpp
3944
# FIXME: How to pass this using setup.py? The fPIC flag is needed when
4045
# dpcpp compiles the Cython generated cpp file.
4146
export CFLAGS=-fPIC
4247
python setup.py clean --all
43-
python setup.py build_ext --inplace
44-
python setup.py develop
48+
python setup.py build develop

setup.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
### This file builds the dpctl and dpctl.ocldrv extension modules.
2323
##===----------------------------------------------------------------------===##
2424
import os
25+
import os.path
2526
import sys
2627
import versioneer
2728

@@ -30,7 +31,6 @@
3031

3132
import numpy as np
3233

33-
3434
requirements = [
3535
'cffi>=1.0.0',
3636
'cython',
@@ -100,22 +100,25 @@ def extensions():
100100
librarys = [dppl_sycl_interface_lib]
101101

102102
if IS_LIN or IS_MAC:
103-
runtime_library_dirs = [os.path.abspath('dpctl')]
103+
runtime_library_dirs = ["$ORIGIN"]
104104
elif IS_WIN:
105105
runtime_library_dirs = []
106106

107107
extension_args = {
108108
"depends": [dppl_sycl_interface_include,],
109109
"include_dirs": [np.get_include(), dppl_sycl_interface_include],
110110
"extra_compile_args": eca + get_other_cxxflags(),
111-
"extra_link_args": ela, "libraries": libs, "library_dirs": librarys,
112-
"runtime_library_dirs": runtime_library_dirs, "language": 'c++',
111+
"extra_link_args": ela,
112+
"libraries": libs,
113+
"library_dirs": librarys,
114+
"runtime_library_dirs": runtime_library_dirs,
115+
"language": 'c++',
113116
}
114117

115118
extensions = [
116-
Extension('dpctl._sycl_core', [os.path.abspath('dpctl/sycl_core.pyx'),],
119+
Extension('dpctl._sycl_core', [os.path.join('dpctl', 'sycl_core.pyx'),],
117120
**extension_args),
118-
Extension('dpctl._memory', [os.path.abspath('dpctl/_memory.pyx'),],
121+
Extension('dpctl._memory', [os.path.join('dpctl', '_memory.pyx'),],
119122
**extension_args),
120123
]
121124

@@ -130,7 +133,8 @@ def extensions():
130133
license="Apache 2.0",
131134
author="Intel Corporation",
132135
url='https://github.com/IntelPython/dpCtl',
133-
packages=find_packages(include=["dpctl", "dpctl.*"]),
136+
packages=find_packages(include=["*"]),
137+
include_package_data=True,
134138
ext_modules = extensions(),
135139
setup_requires=requirements,
136140
cffi_modules=[
@@ -142,5 +146,6 @@ def extensions():
142146
"Development Status :: 3 - Alpha",
143147
'Programming Language :: Python :: 3.6',
144148
'Programming Language :: Python :: 3.7',
149+
'Programming Language :: Python :: 3.8',
145150
]
146151
)

0 commit comments

Comments
 (0)