Skip to content

Commit 4e40659

Browse files
author
Diptorup Deb
committed
Changes to build scripts to enable building dpctl with a custom DPC++.
1 parent 5db1d6f commit 4e40659

File tree

8 files changed

+60
-83
lines changed

8 files changed

+60
-83
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,28 @@ conda install dpctl
4141

4242
Build and Install with setuptools
4343
=================================
44-
dpCtl relies on DPC++ runtime. With Intel oneAPI installed you should activate it.
44+
`dpctl` relies on DPC++ runtime. With Intel oneAPI installed you should activate it.
4545
`setup.py` requires environment variable `ONEAPI_ROOT` and following packages
4646
installed:
4747
- `cython`
4848
- `numpy`
4949
- `cmake` - for building C API
5050
- `ninja` - only on Windows
5151

52-
Activate DPC++ compiler:
52+
You need `DPC++` to build `dpctl`. If you want to build using the `DPC++` in a
53+
oneAPI distribution, activate DPC++ compiler as follows:
5354
```bash
5455
export ONEAPI_ROOT=/opt/intel/oneapi
5556
source ${ONEAPI_ROOT}/compiler/latest/env/vars.sh
5657
```
58+
To use a custom built `DPC++`, you need to create an environment variable called
59+
`DPCPP_HOME` that points to the root directory of the custom `DPC++` install
60+
path. Note that if you set the `DPCPP_HOME` environment variable, `setup.py`
61+
will ignore any oneAPI installation.
62+
63+
```bash
64+
export DPCPP_HOME=PATH_TO_YOUR_CUSTOM_DPCPP
65+
```
5766

5867
For install:
5968
```cmd

dpctl-capi/CMakeLists.txt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,12 @@ configure_file(${CMAKE_SOURCE_DIR}/include/Config/dpctl_config.h.in
3636
${CMAKE_SOURCE_DIR}/include/Config/dpctl_config.h)
3737

3838
if(WIN32)
39-
set(CMAKE_CXX_COMPILER:PATH "${DPCPP_ROOT}/bin/dpcpp")
40-
set(CMAKE_C_COMPILER:PATH "${DPCPP_ROOT}/bin/clang-cl")
41-
set(CMAKE_LINKER:PATH "${DPCPP_ROOT}/bin/lld-link")
42-
message(STATUS "Resetting CXX compiler to: " ${CMAKE_CXX_COMPILER})
43-
message(STATUS "Resetting C compiler to: " ${CMAKE_C_COMPILER})
44-
message(STATUS "Resetting Linker to: " ${CMAKE_LINKER})
4539
set(WARNING_FLAGS "-Wall -Wextra -Winit-self -Wunused-function -Wuninitialized -Wmissing-declarations")
4640
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS}")
4741
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} -Qstd=c++17")
4842
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG")
4943
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG -Qstd=c++17")
5044
elseif(UNIX)
51-
set(CMAKE_CXX_COMPILER:PATH "${DPCPP_ROOT}/bin/dpcpp")
52-
set(CMAKE_C_COMPILER:PATH "${DPCPP_ROOT}/bin/clang")
53-
set(CMAKE_LINKER:PATH "${DPCPP_ROOT}/bin/lld")
5445
set(SDL_FLAGS "-fstack-protector -fstack-protector-all -fpic -fPIC -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -fno-strict-overflow -fno-delete-null-pointer-checks")
5546
set(WARNING_FLAGS "-Wall -Wextra -Winit-self -Wunused-function -Wuninitialized -Wmissing-declarations -fdiagnostics-color=auto")
5647
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} ${SDL_FLAGS}")
@@ -156,3 +147,4 @@ endif()
156147
if(DPCTL_BUILD_CAPI_TESTS)
157148
add_subdirectory(tests)
158149
endif()
150+

dpctl-capi/cmake/modules/FindDPCPP.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ include( FindPackageHandleStandardArgs )
3434

3535
string(COMPARE EQUAL "${DPCPP_INSTALL_DIR}" "" no_dpcpp_root)
3636
if(${no_dpcpp_root})
37-
message(STATUS "Set the DPCPP_ROOT argument providing the path to \
38-
a dpcpp installation.")
37+
message(STATUS
38+
"Set the DPCPP_INSTALL_DIR variable to provide a path to a dpcpp "
39+
"installation."
40+
)
3941
return()
4042
endif()
4143

dpctl-capi/dbg_build.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,23 @@ pushd build
66

77
INSTALL_PREFIX=`pwd`/../install
88
rm -rf ${INSTALL_PREFIX}
9-
export ONEAPI_ROOT=/opt/intel/oneapi
10-
DPCPP_ROOT=${ONEAPI_ROOT}/compiler/latest/linux
9+
10+
if [[ -z "${DPCPP_HOME}" ]]; then
11+
ONEAPI_ROOT=/opt/intel/oneapi
12+
DPCPP_ROOT=${ONEAPI_ROOT}/compiler/latest/linux
13+
else
14+
DPCPP_ROOT=${DPCPP_HOME}
15+
fi
1116

1217
cmake \
1318
-DCMAKE_BUILD_TYPE=Debug \
1419
-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \
1520
-DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} \
1621
-DDPCPP_INSTALL_DIR=${DPCPP_ROOT} \
1722
-DCMAKE_C_COMPILER:PATH=${DPCPP_ROOT}/bin/clang \
18-
-DCMAKE_CXX_COMPILER:PATH=${DPCPP_ROOT}/bin/dpcpp \
23+
-DCMAKE_CXX_COMPILER:PATH=${DPCPP_ROOT}/bin/clang++ \
24+
-DCMAKE_CMAKE_LINKER:PATH=${DPCPP_ROOT}/bin/lld \
25+
-DCMAKE_CXX_FLAGS=" -fsycl " \
1926
-DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON \
2027
-DDPCTL_BUILD_CAPI_TESTS=ON \
2128
-DDPCTL_GENERATE_COVERAGE=ON \
@@ -32,3 +39,4 @@ make lcov-genhtml
3239
# cd ..
3340

3441
popd
42+

dpctl-capi/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,4 @@ endif()
7171

7272
gtest_discover_tests(dpctl_c_api_tests)
7373
add_dependencies(check dpctl_c_api_tests)
74+

scripts/build_backend.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@
3434
else:
3535
assert False, sys.platform + " not supported"
3636

37-
ONEAPI_ROOT = os.environ.get("ONEAPI_ROOT")
3837
CODE_COVERAGE = os.environ.get("CODE_COVERAGE")
39-
40-
if IS_LIN:
41-
DPCPP_ROOT = os.path.join(ONEAPI_ROOT, "compiler/latest/linux")
42-
if IS_WIN:
43-
DPCPP_ROOT = os.path.join(ONEAPI_ROOT, "compiler\latest\windows")
38+
DPCPP_HOME = os.environ.get("DPCPP_HOME")
39+
if not DPCPP_HOME:
40+
ONEAPI_ROOT = os.environ.get("ONEAPI_ROOT")
41+
if IS_LIN:
42+
DPCPP_HOME = os.path.join(ONEAPI_ROOT, "compiler/latest/linux")
43+
elif IS_WIN:
44+
DPCPP_HOME = os.path.join(ONEAPI_ROOT, "compiler\latest\windows")
45+
print("DPCPP_HOME", DPCPP_HOME)
46+
else:
47+
assert False, sys.platform + " not supported"
4448

4549
dpctl_dir = os.getcwd()
4650
build_cmake_dir = os.path.join(dpctl_dir, "build_cmake")
@@ -62,9 +66,11 @@
6266
"-DCMAKE_BUILD_TYPE=Debug",
6367
"-DCMAKE_INSTALL_PREFIX=" + INSTALL_PREFIX,
6468
"-DCMAKE_PREFIX_PATH=" + INSTALL_PREFIX,
65-
"-DDPCPP_INSTALL_DIR=" + DPCPP_ROOT,
66-
"-DCMAKE_C_COMPILER:PATH=" + os.path.join(DPCPP_ROOT, "bin", "clang"),
67-
"-DCMAKE_CXX_COMPILER:PATH=" + os.path.join(DPCPP_ROOT, "bin", "dpcpp"),
69+
"-DDPCPP_INSTALL_DIR=" + DPCPP_HOME,
70+
"-DCMAKE_C_COMPILER:PATH=" + os.path.join(DPCPP_HOME, "bin", "clang"),
71+
"-DCMAKE_CXX_COMPILER:PATH=" + os.path.join(DPCPP_HOME, "bin", "clang++"),
72+
"-DCMAKE_LINKER:PATH= " + os.path.join(DPCPP_HOME, "bin", "lld"),
73+
"-DCMAKE_CXX_FLAGS=-fsycl",
6874
"-DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON",
6975
"-DDPCTL_BUILD_CAPI_TESTS=ON",
7076
"-DDPCTL_GENERATE_COVERAGE=ON",
@@ -82,9 +88,11 @@
8288
"-DCMAKE_BUILD_TYPE=Release",
8389
"-DCMAKE_INSTALL_PREFIX=" + INSTALL_PREFIX,
8490
"-DCMAKE_PREFIX_PATH=" + INSTALL_PREFIX,
85-
"-DDPCPP_INSTALL_DIR=" + DPCPP_ROOT,
86-
"-DCMAKE_C_COMPILER:PATH=" + os.path.join(DPCPP_ROOT, "bin", "clang"),
87-
"-DCMAKE_CXX_COMPILER:PATH=" + os.path.join(DPCPP_ROOT, "bin", "dpcpp"),
91+
"-DDPCPP_INSTALL_DIR=" + DPCPP_HOME,
92+
"-DCMAKE_C_COMPILER:PATH=" + os.path.join(DPCPP_HOME, "bin", "clang"),
93+
"-DCMAKE_CXX_COMPILER:PATH=" + os.path.join(DPCPP_HOME, "bin", "clang++"),
94+
"-DCMAKE_LINKER:PATH= " + os.path.join(DPCPP_HOME, "bin", "lld"),
95+
"-DCMAKE_CXX_FLAGS=-fsycl",
8896
"-DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON",
8997
backends,
9098
]
@@ -104,9 +112,10 @@
104112
"-DCMAKE_BUILD_TYPE=Release",
105113
"-DCMAKE_INSTALL_PREFIX=" + INSTALL_PREFIX,
106114
"-DCMAKE_PREFIX_PATH=" + INSTALL_PREFIX,
107-
"-DDPCPP_INSTALL_DIR=" + DPCPP_ROOT,
108-
"-DCMAKE_C_COMPILER:PATH=" + os.path.join(DPCPP_ROOT, "bin", "clang-cl.exe"),
109-
"-DCMAKE_CXX_COMPILER:PATH=" + os.path.join(DPCPP_ROOT, "bin", "dpcpp.exe"),
115+
"-DDPCPP_INSTALL_DIR=" + DPCPP_HOME,
116+
"-DCMAKE_C_COMPILER:PATH=" + os.path.join(DPCPP_HOME, "bin", "clang-cl.exe"),
117+
"-DCMAKE_CXX_COMPILER:PATH=" + os.path.join(DPCPP_HOME, "bin", "dpcpp.exe"),
118+
"-DCMAKE_LINKER:PATH=" + os.path.join(DPCPP_HOME, "bin", "lld-link.exe"),
110119
backends,
111120
]
112121
subprocess.check_call(cmake_args, stderr=subprocess.STDOUT, shell=False)

scripts/build_for_develop.sh

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,8 @@
11
#!/bin/bash
22
set +xe
3-
rm -rf build_cmake
4-
mkdir build_cmake
5-
pushd build_cmake
63

7-
INSTALL_PREFIX=`pwd`/../install
8-
rm -rf ${INSTALL_PREFIX}
9-
export ONEAPI_ROOT=/opt/intel/oneapi
10-
11-
DPCPP_ROOT=${ONEAPI_ROOT}/compiler/latest/linux
12-
13-
cmake \
14-
-DCMAKE_BUILD_TYPE=Debug \
15-
-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \
16-
-DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} \
17-
-DDPCPP_INSTALL_DIR=${DPCPP_ROOT} \
18-
-DCMAKE_C_COMPILER:PATH=${DPCPP_ROOT}/bin/clang \
19-
-DCMAKE_CXX_COMPILER:PATH=${DPCPP_ROOT}/bin/dpcpp \
20-
-DDPCTL_BUILD_CAPI_TESTS=ON \
21-
-DDPCTL_GENERATE_COVERAGE=ON \
22-
../dpctl-capi
23-
24-
make V=1 -n -j 4 && make check && make install
25-
26-
if [ $? -ne 0 ]; then
27-
echo "Building of libDPCTLSyclInterface failed. Abort!"
28-
exit 1
29-
fi
30-
31-
# To run code coverage for dpctl-c API
32-
make llvm-cov
33-
# For more verbose tests use:
34-
# cd tests
35-
# ctest -V --progress --output-on-failure -j 4
36-
# cd ..
37-
38-
popd
39-
cp install/lib/*.so dpctl/
40-
41-
mkdir -p dpctl/include
42-
cp -r dpctl-capi/include/* dpctl/include
43-
44-
export DPCTL_SYCL_INTERFACE_LIBDIR=dpctl
45-
export DPCTL_SYCL_INTERFACE_INCLDIR=dpctl/include
46-
47-
export CC=${DPCPP_ROOT}/bin/clang
48-
export CXX=${DPCPP_ROOT}/bin/dpcpp
49-
# FIXME: How to pass this using setup.py? The fPIC flag is needed when
50-
# dpcpp compiles the Cython generated cpp file.
51-
export CFLAGS=-fPIC
4+
export CODE_COVERAGE=ON
525
python setup.py clean --all
536
python setup.py build develop
54-
python -m unittest -v dpctl.tests
7+
pytest --pyargs dpctl -vv
8+

setup.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,20 @@
4242
assert False, sys.platform + " not supported"
4343

4444
if IS_LIN:
45-
DPCPP_ROOT = os.environ["ONEAPI_ROOT"] + "/compiler/latest/linux"
4645
os.environ["DPCTL_SYCL_INTERFACE_LIBDIR"] = "dpctl"
4746
os.environ["DPCTL_SYCL_INTERFACE_INCLDIR"] = "dpctl/include"
4847
os.environ["CFLAGS"] = "-fPIC"
49-
5048
elif IS_WIN:
5149
os.environ["DPCTL_SYCL_INTERFACE_LIBDIR"] = "dpctl"
5250
os.environ["DPCTL_SYCL_INTERFACE_INCLDIR"] = "dpctl\include"
51+
DPCPP_HOME = os.environ.get("DPCPP_HOME")
52+
if DPCPP_HOME:
53+
sycl_lib = os.environ["DPCPP_HOME"] + "\lib"
54+
else:
55+
sycl_lib = os.environ["ONEAPI_ROOT"] + "\compiler\latest\windows\lib"
5356

5457
dpctl_sycl_interface_lib = os.environ["DPCTL_SYCL_INTERFACE_LIBDIR"]
5558
dpctl_sycl_interface_include = os.environ["DPCTL_SYCL_INTERFACE_INCLDIR"]
56-
sycl_lib = os.environ["ONEAPI_ROOT"] + "\compiler\latest\windows\lib"
5759

5860

5961
def get_sdl_cflags():

0 commit comments

Comments
 (0)