Skip to content

Commit 8ddb4d9

Browse files
Deb, DiptorupPokhodenkoSA
authored andcommitted
CMakeList.txt changes to include NumPy and few other minor cleanups
1 parent af5b75e commit 8ddb4d9

File tree

4 files changed

+114
-111
lines changed

4 files changed

+114
-111
lines changed

CMakeLists.txt

Lines changed: 76 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,84 @@
11
cmake_minimum_required(VERSION 3.3.2 FATAL_ERROR)
2-
project("DPPPY-Oneapi-Interface - A lightweight SYCL wrapper for Python")
3-
4-
set(ONEAPI_ROOT "$ENV{ONEAPI_ROOT}")
5-
string(COMPARE EQUAL "${ONEAPI_ROOT}" "" ONEAPI_ROOT_EMPTY)
6-
if(${ONEAPI_ROOT_EMPTY})
7-
message(FATAL_ERROR "Please set an environment varaible ONEAPI_ROOT \
8-
pointing to you oneAPI install directory.")
9-
else()
10-
message(STATUS "oneAPI Root: ${ONEAPI_ROOT}")
11-
endif()
12-
13-
if(WIN32)
14-
set(DPCPP_ROOT "${ONEAPI_ROOT}/compiler/latest/windows")
15-
elseif(UNIX)
16-
set(DPCPP_ROOT "${ONEAPI_ROOT}/compiler/latest/linux")
17-
endif()
18-
19-
if(WIN32)
20-
set (dpcpp_cmd "${DPCPP_ROOT}/bin/dpcpp-cl")
21-
set (dpcpp_arg "--version")
22-
elseif(UNIX)
23-
set (dpcpp_cmd "${DPCPP_ROOT}/bin/dpcpp")
24-
set (dpcpp_arg "--version")
25-
else()
26-
message(FATAL_ERROR "Unsupported system.")
27-
endif()
2+
project("PyDPPL - A lightweight SYCL wrapper for Python")
3+
4+
# The function checks is DPCPP_ROOT is valid and points to a dpcpp installation
5+
function (check_for_dpcpp)
6+
string(COMPARE EQUAL "${DPCPP_ROOT}" "" no_dpcpp_root)
7+
if(${no_dpcpp_root})
8+
message(FATAL_ERROR "Set the DPCPP_ROOT argument providing the path to \
9+
a dpcpp installation.")
10+
endif()
11+
12+
if(WIN32)
13+
set (dpcpp_cmd "${DPCPP_ROOT}/bin/dpcpp-cl")
14+
set (dpcpp_arg "--version")
15+
elseif(UNIX)
16+
set (dpcpp_cmd "${DPCPP_ROOT}/bin/dpcpp")
17+
set (dpcpp_arg "--version")
18+
else()
19+
message(FATAL_ERROR "Unsupported system.")
20+
endif()
21+
22+
# Check if dpcpp is available
23+
execute_process(
24+
COMMAND ${dpcpp_cmd} ${dpcpp_arg}
25+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
26+
RESULT_VARIABLE dpcpp_result
27+
OUTPUT_VARIABLE dpcpp_ver
28+
)
2829

29-
execute_process(
30-
COMMAND ${dpcpp_cmd} ${dpcpp_arg}
31-
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
32-
RESULT_VARIABLE dpcpp_result
33-
OUTPUT_VARIABLE dpcpp_ver)
34-
35-
if(${dpcpp_result} MATCHES "0")
36-
string(REPLACE "\n" ";" DPCPP_VERSION_LIST "${dpcpp_ver}")
37-
list(GET DPCPP_VERSION_LIST 0 dpcpp_ver_line)
38-
foreach(X ${DPCPP_VERSION_LIST})
39-
message(STATUS "dpcpp ver[${dpcpp_result}]: ${X}")
40-
endforeach()
41-
else()
42-
message(FATAL_MESSAGE "DPCPP needed to build DPPL-Oneapi-Interface")
43-
endif()
30+
if(${dpcpp_result} MATCHES "0")
31+
string(REPLACE "\n" ";" DPCPP_VERSION_LIST "${dpcpp_ver}")
32+
list(GET DPCPP_VERSION_LIST 0 dpcpp_ver_line)
33+
foreach(X ${DPCPP_VERSION_LIST})
34+
message(STATUS "dpcpp ver[${dpcpp_result}]: ${X}")
35+
endforeach()
36+
else()
37+
message(FATAL_MESSAGE "DPCPP needed to build dppl_oneapi_interface")
38+
endif()
39+
endfunction()
40+
41+
function (check_for_numpy_inc)
42+
string(COMPARE EQUAL "${NUMPY_INCLUDE_DIR}" "" no_numpy_inc)
43+
if(${no_dpcpp_root})
44+
message(FATAL_ERROR "Set the NUMPY_INCLUDE_DIR argument providing the \
45+
path to NumPy Headers.")
46+
else()
47+
message(STATUS "NUMPY_INCLUDE_DIR: ${NUMPY_INCLUDE_DIR}")
48+
endif()
49+
50+
string(COMPARE EQUAL "${PYTHON_INCLUDE_DIR}" "" no_python_inc)
51+
if(${no_dpcpp_root})
52+
message(FATAL_ERROR "Set the PYTHON_INCLUDE_DIR argument providing the \
53+
path to Python Headers.")
54+
else()
55+
message(STATUS "PYTHON_INCLUDE_DIR: ${PYTHON_INCLUDE_DIR}")
56+
endif()
57+
endfunction()
58+
59+
# Check for dpcpp in the specified DPCPP_ROOT
60+
check_for_dpcpp()
61+
# Check if the locations of Numpy and Python headers were provided
62+
check_for_numpy_inc()
4463

4564
if(WIN32)
4665
set(CMAKE_CXX_COMPILER:PATH "${DPCPP_ROOT}/bin/dpcpp-cl")
4766
set(CMAKE_C_COMPILER:PATH "${DPCPP_ROOT}/bin/clang-cl")
4867
set(CMAKE_LINKER:PATH "${DPCPP_ROOT}/bin/lld-link")
68+
message(STATUS "Resetting CXX compiler to: " ${CMAKE_CXX_COMPILER})
69+
message(STATUS "Resetting C compiler to: " ${CMAKE_C_COMPILER})
70+
message(STATUS "Resetting Linker to: " ${CMAKE_LINK})
71+
4972
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
5073
-Wall -Wextra -Winit-self -Wuninitialized -Wmissing-declarations \
5174
-fdiagnostics-color=auto -O3 \
5275
")
5376
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
5477
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb3 -DDEBUG ")
55-
message(STATUS "Resetting CXX compiler to: " ${CMAKE_CXX_COMPILER})
56-
message(STATUS "Resetting C compiler to: " ${CMAKE_C_COMPILER})
57-
message(STATUS "Resetting Linker to: " ${CMAKE_LINK})
5878
elseif(UNIX)
59-
set(CMAKE_CXX_COMPILER "${DPCPP_ROOT}/bin/dpcpp")
60-
set(CMAKE_C_COMPILER "${DPCPP_ROOT}/bin/clang")
79+
set(CMAKE_CXX_COMPILER "dpcpp")
80+
set(CMAKE_C_COMPILER "clang")
81+
6182
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
6283
-Wall -Wextra -Winit-self -Wuninitialized -Wmissing-declarations \
6384
-fdiagnostics-color=auto -O3 \
@@ -69,28 +90,8 @@ else()
6990
endif()
7091

7192

72-
#set(OPENCL_LIBDIR "$ENV{OpenCL_LIBDIR}")
73-
#string(COMPARE EQUAL "${OPENCL_LIBDIR}" "" OPENCL_LIBDIR_EMPTY)
74-
75-
# This is a temporary hack to pass in the OpenCL install directory
76-
# using an environment variable. We are doing this as we want to pass
77-
# OpenCL_LIBDR to build.sh.
78-
79-
# if(${OPENCL_LIBDIR_EMPTY})
80-
# message(FATAL_ERROR "Set the OpenCL_LIBDIR and OpenCL_INCLUDE_DIR \
81-
# environment variables to point to an OpenCL installation.")
82-
# endif()
83-
84-
#---- We need OpenCL
85-
# find_package(OpenCL REQUIRED)
86-
# if(WIN32)
87-
# set(OpenCL_LIBRARY ${OpenCL_LIBDIR}/libOpenCL.lib)
88-
# elseif(UNIX)
89-
# set(OpenCL_LIBRARY ${OpenCL_LIBDIR}/libOpenCL.so)
90-
# endif()
91-
92-
set(OpenCL_INCLUDE_DIR "${ONEAPI_ROOT}/compiler/latest/linux/include/sycl")
93-
set(OpenCL_LIBRARY "${ONEAPI_ROOT}/compiler/latest/linux/lib/libOpenCL.so")
93+
set(OpenCL_INCLUDE_DIR "${DPCPP_ROOT}/include/sycl")
94+
set(OpenCL_LIBRARY "${DPCPP_ROOT}/lib/libOpenCL.so")
9495

9596
message(STATUS "OpenCL_INCLUDE_DIR: ${OpenCL_INCLUDE_DIR}")
9697
message(STATUS "OpenCL_LIBRARY: ${OpenCL_LIBRARY}")
@@ -105,17 +106,20 @@ add_library(
105106
source/dppl_oneapi_interface.cpp
106107
)
107108

108-
# Install DPPLOpenCLInterface as a separate library to be removed later
109+
# Install DPPLOpenCLInterface
109110
add_library(
110111
DPPLOpenCLInterface
111112
SHARED
112113
source/dppl_opencl_interface.c
113114
)
114115

116+
# Install DPPLOneAPIInterface
115117
target_include_directories(
116118
DPPLOneapiInterface
117119
PRIVATE
118120
${CMAKE_SOURCE_DIR}/include/
121+
${PYTHON_INCLUDE_DIR}
122+
${NUMPY_INCLUDE_DIR}
119123
)
120124

121125
target_include_directories(
@@ -134,34 +138,23 @@ if(WIN32)
134138
message(
135139
STATUS
136140
"SYCL_INCLUDE_DIR: "
137-
${ONEAPI_ROOT}/compiler/latest/windows/include/sycl
141+
${DPCPP_ROOT}/include/sycl
138142
)
139143
target_include_directories(
140144
DPPLOneapiInterface
141145
PUBLIC
142-
${ONEAPI_ROOT}/compiler/latest/windows/include/sycl
146+
${DPCPP_ROOT}/include/sycl
143147
)
144148
target_link_libraries(
145149
DPPLOneapiInterface
146150
PRIVATE
147-
${ONEAPI_ROOT}/compiler/latest/windows/lib/sycl.lib
151+
${DPCPP_ROOT}/lib/sycl.lib
148152
)
149153
target_link_libraries(
150154
DPPLOpenCLInterface
151155
PRIVATE
152156
${OpenCL_INCLUDE_DIR}/../lib/x64/OpenCL.lib
153157
)
154-
elseif(UNIX)
155-
message(
156-
STATUS
157-
"SYCL_INCLUDE_DIR: "
158-
${ONEAPI_ROOT}/compiler/latest/linux/include/sycl
159-
)
160-
#target_include_directories(
161-
# DPPLOneapiInterface
162-
# SYSTEM PUBLIC
163-
# /opt/intel/inteloneapi/compiler/latest/linux/include/sycl
164-
#)
165158
endif()
166159

167160
install(

build_for_conda.sh

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,20 @@ if [[ conda_build_ret -ne 0 ]]; then
1717
read ok
1818
shopt -s nocasematch
1919
case "$ok" in
20-
"y" )
21-
conda install conda-build ${CHANNELS}
22-
;;
23-
*)
24-
echo "Aborting dp-glue setup"
25-
exit 1
26-
;;
20+
"y" )
21+
conda install conda-build ${CHANNELS}
22+
;;
23+
*)
24+
echo "Aborting PyDPPL setup"
25+
exit 1
26+
;;
2727
esac
2828
fi
2929

3030
export ONEAPI_ROOT="/opt/intel/inteloneapi"
3131

3232
conda build --output-folder ${CONDA_PKG_DIR} ${CHANNELS} conda.recipe
3333

34-
# Commented because main goal of this script is building the package.
35-
# You can run the following commands manually if you want to install the package
36-
# to your current conda environment.
34+
# To install the package in your current conda environment, execute
3735

38-
# conda install dppl -c ${CONDA_PKG_DIR} ${CHANNELS}
39-
40-
# Indexing is commented because conda-build indexes the output folder.
41-
# Aslo, the current script clears any old build directories.
42-
43-
# echo "conda index"
44-
# conda index ${CONDA_PKG_DIR}
36+
# conda install pydppl -c ${CONDA_PKG_DIR} ${CHANNELS}

build_for_develop.sh

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
#!/bin/bash
2+
set +xe
23
rm -rf build
34
mkdir build
4-
cd build
5+
pushd build
56

6-
INSTALL_PREFIX=`pwd`/install
7+
INSTALL_PREFIX=`pwd`/../install
78
export ONEAPI_ROOT=/opt/intel/inteloneapi
8-
#export OpenCL_LIBDIR="/usr/lib/x86_64-linux-gnu"
9-
DPCPP_ROOT=${ONEAPI_ROOT}/compiler/latest
9+
DPCPP_ROOT=${ONEAPI_ROOT}/compiler/latest/linux
10+
PYTHON_INC=`python -c "import distutils.sysconfig; \
11+
print(distutils.sysconfig.get_python_inc())"`
12+
NUMPY_INC=`python -c "import numpy; print(numpy.get_include())"`
1013

1114
cmake \
1215
-DCMAKE_BUILD_TYPE=Release \
1316
-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \
1417
-DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} \
15-
-DCMAKE_C_COMPILER:PATH=${DPCPP_ROOT}/linux/bin/clang \
16-
-DCMAKE_CXX_COMPILER:PATH=${DPCPP_ROOT}/linux/bin/dpcpp \
18+
-DDPCPP_ROOT=${DPCPP_ROOT} \
19+
-DCMAKE_C_COMPILER:PATH=${DPCPP_ROOT}/bin/clang \
20+
-DCMAKE_CXX_COMPILER:PATH=${DPCPP_ROOT}/bin/dpcpp \
21+
-DPYTHON_INCLUDE_DIR=${PYTHON_INC} \
22+
-DNUMPY_INCLUDE_DIR=${NUMPY_INC} \
1723
..
1824

1925
make V=1 -n -j 4 && make install
@@ -33,3 +39,5 @@ export CFLAGS=-fPIC
3339
python setup.py clean --all
3440
python setup.py build_ext --inplace
3541
python setup.py develop
42+
43+
popd

conda.recipe/build.sh

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,20 @@ rm -rf build
1515
mkdir build
1616
cd build
1717

18-
cmake \
19-
-DCMAKE_BUILD_TYPE=Release \
20-
-DCMAKE_INSTALL_PREFIX=${PREFIX} \
21-
-DCMAKE_PREFIX_PATH=${PREFIX} \
18+
PYTHON_INC=`${PYTHON} -c "import distutils.sysconfig; \
19+
print(distutils.sysconfig.get_python_inc())"`
20+
NUMPY_INC=`${PYTHON} -c "import numpy; print(numpy.get_include())"`
21+
DPCPP_ROOT=${ONEAPI_ROOT}/compiler/latest/linux/
22+
23+
cmake \
24+
-DCMAKE_BUILD_TYPE=Release \
25+
-DCMAKE_INSTALL_PREFIX=${PREFIX} \
26+
-DCMAKE_PREFIX_PATH=${PREFIX} \
27+
-DDPCPP_ROOT=${DPCPP_ROOT} \
28+
-DCMAKE_C_COMPILER:PATH=${DPCPP_ROOT}/bin/clang \
29+
-DCMAKE_CXX_COMPILER:PATH=${DPCPP_ROOT}/bin/dpcpp \
30+
-DPYTHON_INCLUDE_DIR=${PYTHON_INC} \
31+
-DNUMPY_INCLUDE_DIR=${NUMPY_INC} \
2232
..
2333

2434
make -j 4 && make install
@@ -28,7 +38,7 @@ cd ../python_binding
2838
# required by dpglue
2939
export DP_GLUE_LIBDIR=${PREFIX}
3040
export DP_GLUE_INCLDIR=${PREFIX}/include
31-
export OpenCL_LIBDIR=${ONEAPI_ROOT}/compiler/latest/linux/lib
41+
export OpenCL_LIBDIR=${DPCPP_ROOT}/lib
3242
# required by oneapi_interface
3343
export DPPL_ONEAPI_INTERFACE_LIBDIR=${INSTALL_PREFIX}/lib
3444
export DPPL_ONEAPI_INTERFACE_INCLDIR=${INSTALL_PREFIX}/include

0 commit comments

Comments
 (0)