Skip to content

Add get include and include headers #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 28, 2020
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
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
include versioneer.py
recursive-include dpctl/include *.h *.hpp
include dpctl/*.pxd
include dpctl/*DPPL*Interface.*
global-exclude *.cpp
28 changes: 18 additions & 10 deletions conda-recipe/bld.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ rmdir /S /Q build_cmake
mkdir build_cmake
cd build_cmake

set "DPCPP_ROOT=%ONEAPI_ROOT%/compiler/latest/windows"
set "DPCPP_ROOT=%ONEAPI_ROOT%\compiler\latest\windows"
set "INSTALL_PREFIX=%cd%\..\install"

rmdir /S /Q "%INSTALL_PREFIX%"

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

cd ..
xcopy install\lib\*.lib dpctl /E /Y
xcopy install\lib\*.dll dpctl /E /Y

mkdir dpctl\include
xcopy backends\include dpctl\include /E /Y


REM required by dpglue
set "DPPL_OPENCL_INTERFACE_LIBDIR=%LIBRARY_PREFIX%/lib"
set "DPPL_OPENCL_INTERFACE_INCLDIR=%LIBRARY_PREFIX%/include"
set "OpenCL_LIBDIR=%DPCPP_ROOT%/lib"
REM required by _opencl_core (dpctl.ocldrv)
set "DPPL_OPENCL_INTERFACE_LIBDIR=dpctl"
set "DPPL_OPENCL_INTERFACE_INCLDIR=dpctl\include"
set "OpenCL_LIBDIR=%DPCPP_ROOT%\lib"

REM required by oneapi_interface
set "DPPL_SYCL_INTERFACE_LIBDIR=%LIBRARY_PREFIX%/lib"
set "DPPL_SYCL_INTERFACE_INCLDIR=%LIBRARY_PREFIX%/include"
REM required by _sycl_core(dpctl)
set "DPPL_SYCL_INTERFACE_LIBDIR=dpctl"
set "DPPL_SYCL_INTERFACE_INCLDIR=dpctl\include"

"%PYTHON%" setup.py clean --all
"%PYTHON%" setup.py build
"%PYTHON%" setup.py install
"%PYTHON%" setup.py build install
IF %ERRORLEVEL% NEQ 0 exit 1
28 changes: 17 additions & 11 deletions conda-recipe/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ fi

rm -rf build_cmake
mkdir build_cmake
cd build_cmake
pushd build_cmake

INSTALL_PREFIX=`pwd`/../install
rm -rf ${INSTALL_PREFIX}

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

cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=${PREFIX} \
-DCMAKE_PREFIX_PATH=${PREFIX} \
-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \
-DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} \
-DDPCPP_ROOT=${DPCPP_ROOT} \
-DPYTHON_INCLUDE_DIR=${PYTHON_INC} \
-DNUMPY_INCLUDE_DIR=${NUMPY_INC} \
../backends

make -j 4 && make install

cd ..
popd
cp install/lib/*.so dpctl/

mkdir -p dpctl/include
cp -r backends/include/* dpctl/include

# required by dpctl.opencl_core
export DPPL_OPENCL_INTERFACE_LIBDIR=${PREFIX}
export DPPL_OPENCL_INTERFACE_INCLDIR=${PREFIX}/include
export DPPL_OPENCL_INTERFACE_LIBDIR=dpctl
export DPPL_OPENCL_INTERFACE_INCLDIR=dpctl/include
export OpenCL_LIBDIR=${DPCPP_ROOT}/lib

# required by dpctl.sycl_core
export DPPL_SYCL_INTERFACE_LIBDIR=${PREFIX}/lib
export DPPL_SYCL_INTERFACE_INCLDIR=${PREFIX}/include
export DPPL_SYCL_INTERFACE_LIBDIR=dpctl
export DPPL_SYCL_INTERFACE_INCLDIR=dpctl/include


# FIXME: How to pass this using setup.py? This flags is needed when
# dpcpp compiles the generated cpp file.
export CFLAGS="-fPIC -O3 ${CFLAGS}"
export LDFLAGS="-L OpenCL_LIBDIR ${LDFLAGS}"
export LDFLAGS="-L ${OpenCL_LIBDIR} ${LDFLAGS}"
${PYTHON} setup.py clean --all
${PYTHON} setup.py build
${PYTHON} setup.py install
${PYTHON} setup.py build install
30 changes: 30 additions & 0 deletions dpctl/__init__.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
##===------------- sycl_core.pxd - dpctl module --------*- Cython -*-------===##
##
## Data Parallel Control (dpCtl)
##
## Copyright 2020 Intel Corporation
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
##===----------------------------------------------------------------------===##
##
## \file
## This file declares the extension types and functions for the Cython API
## implemented in sycl_core.pyx.
##
##===----------------------------------------------------------------------===##

# distutils: language = c++
# cython: language_level=3

from dpctl._sycl_core cimport *
10 changes: 10 additions & 0 deletions dpctl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,15 @@
from ._sycl_core import *
from ._version import get_versions

def get_include():
"""
Return the directory that contains the dpCtl *.h header files.

Extension modules that need to be compiled against dpCtl should use
this function to locate the appropriate include directory.
"""
import os.path
return os.path.join(os.path.dirname(__file__), 'include')

__version__ = get_versions()['version']
del get_versions
7 changes: 6 additions & 1 deletion dpctl/opencl_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,21 @@

ffi_lib_name = "dpctl._opencl_core"

import sys
IS_WIN = sys.platform in ['win32', 'cygwin']
del sys

ffi.set_source(
ffi_lib_name,
"""
#include "dppl_opencl_interface.h" // the C header of the library
""",
include_dirs=[dppl_opencl_interface_incldir],
library_dirs=[dppl_opencl_interface_libdir, opencl_libdir],
extra_link_args=[] if IS_WIN else ['-Wl,-rpath=$ORIGIN'],
libraries=["DPPLOpenCLInterface", "OpenCL"],
) # library name, for the linker

del IS_WIN

if __name__ == "__main__":
ffi.compile(verbose=True)
20 changes: 12 additions & 8 deletions scripts/build_for_develop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ pushd build_cmake
INSTALL_PREFIX=`pwd`/../install
rm -rf ${INSTALL_PREFIX}
export ONEAPI_ROOT=/opt/intel/oneapi
DPCPP_ROOT=${ONEAPI_ROOT}/compiler/latest/linux

PYTHON_INC=`python -c "import distutils.sysconfig; \
print(distutils.sysconfig.get_python_inc())"`
NUMPY_INC=`python -c "import numpy; print(numpy.get_include())"`
DPCPP_ROOT=${ONEAPI_ROOT}/compiler/latest/linux

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

export DPPL_OPENCL_INTERFACE_LIBDIR=${INSTALL_PREFIX}/lib
export DPPL_OPENCL_INTERFACE_INCLDIR=${INSTALL_PREFIX}/include
export OpenCL_LIBDIR=/usr/lib/x86_64-linux-gnu/
export DPPL_SYCL_INTERFACE_LIBDIR=${INSTALL_PREFIX}/lib
export DPPL_SYCL_INTERFACE_INCLDIR=${INSTALL_PREFIX}/include
mkdir -p dpctl/include
cp -r backends/include/* dpctl/include

export DPPL_OPENCL_INTERFACE_LIBDIR=dpctl
export DPPL_OPENCL_INTERFACE_INCLDIR=dpctl/include
# /usr/lib/x86_64-linux-gnu/
export OpenCL_LIBDIR=${DPCPP_ROOT}/lib
export DPPL_SYCL_INTERFACE_LIBDIR=dpctl
export DPPL_SYCL_INTERFACE_INCLDIR=dpctl/include

export CC=clang
export CXX=dpcpp
# FIXME: How to pass this using setup.py? The fPIC flag is needed when
# dpcpp compiles the Cython generated cpp file.
export CFLAGS=-fPIC
python setup.py clean --all
python setup.py build_ext --inplace
python setup.py develop
python setup.py build develop
19 changes: 12 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
### This file builds the dpctl and dpctl.ocldrv extension modules.
##===----------------------------------------------------------------------===##
import os
import os.path
import sys
import versioneer

Expand All @@ -30,7 +31,6 @@

import numpy as np


requirements = [
'cffi>=1.0.0',
'cython',
Expand Down Expand Up @@ -100,22 +100,25 @@ def extensions():
librarys = [dppl_sycl_interface_lib]

if IS_LIN or IS_MAC:
runtime_library_dirs = [os.path.abspath('dpctl')]
runtime_library_dirs = ["$ORIGIN"]
elif IS_WIN:
runtime_library_dirs = []

extension_args = {
"depends": [dppl_sycl_interface_include,],
"include_dirs": [np.get_include(), dppl_sycl_interface_include],
"extra_compile_args": eca + get_other_cxxflags(),
"extra_link_args": ela, "libraries": libs, "library_dirs": librarys,
"runtime_library_dirs": runtime_library_dirs, "language": 'c++',
"extra_link_args": ela,
"libraries": libs,
"library_dirs": librarys,
"runtime_library_dirs": runtime_library_dirs,
"language": 'c++',
}

extensions = [
Extension('dpctl._sycl_core', [os.path.abspath('dpctl/sycl_core.pyx'),],
Extension('dpctl._sycl_core', [os.path.join('dpctl', 'sycl_core.pyx'),],
**extension_args),
Extension('dpctl._memory', [os.path.abspath('dpctl/_memory.pyx'),],
Extension('dpctl._memory', [os.path.join('dpctl', '_memory.pyx'),],
**extension_args),
]

Expand All @@ -130,7 +133,8 @@ def extensions():
license="Apache 2.0",
author="Intel Corporation",
url='https://github.com/IntelPython/dpCtl',
packages=find_packages(include=["dpctl", "dpctl.*"]),
packages=find_packages(include=["*"]),
include_package_data=True,
ext_modules = extensions(),
setup_requires=requirements,
cffi_modules=[
Expand All @@ -142,5 +146,6 @@ def extensions():
"Development Status :: 3 - Alpha",
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
]
)