From a51e4bd38a4727cd83bfd29f4b00687145802b8f Mon Sep 17 00:00:00 2001 From: etotmeni Date: Tue, 3 Nov 2020 09:59:20 -0600 Subject: [PATCH 01/18] add scripts --- conda-recipe/bld.bat | 76 +++++++++++++++++++-------------------- conda-recipe/build.sh | 76 +++++++++++++++++++-------------------- scripts/build_backend.bat | 47 ++++++++++++++++++++++++ scripts/build_backend.sh | 53 +++++++++++++++++++++++++++ setup.py | 29 +++++++++++++++ 5 files changed, 205 insertions(+), 76 deletions(-) create mode 100644 scripts/build_backend.bat create mode 100755 scripts/build_backend.sh diff --git a/conda-recipe/bld.bat b/conda-recipe/bld.bat index 8cdffe2cfe..934fbd477c 100644 --- a/conda-recipe/bld.bat +++ b/conda-recipe/bld.bat @@ -1,41 +1,41 @@ -call "%ONEAPI_ROOT%\compiler\latest\env\vars.bat" -IF %ERRORLEVEL% NEQ 0 ( - echo "oneAPI compiler activation failed" - exit /b 1 -) -REM conda uses %ERRORLEVEL% but FPGA scripts can set it. So it should be reseted. -set ERRORLEVEL= - -set "CC=clang-cl.exe" -set "CXX=dpcpp.exe" - -rmdir /S /Q build_cmake -mkdir build_cmake -cd build_cmake - -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 ^ - "-DCMAKE_INSTALL_PREFIX=%INSTALL_PREFIX%" ^ - "-DCMAKE_PREFIX_PATH=%LIBRARY_PREFIX%" ^ - "-DDPCPP_ROOT=%DPCPP_ROOT%" ^ - "%SRC_DIR%\backends" -IF %ERRORLEVEL% NEQ 0 exit /b 1 - -ninja -n -ninja install -IF %ERRORLEVEL% NEQ 0 exit /b 1 - -cd .. -xcopy install\lib\*.lib dpctl /E /Y -xcopy install\bin\*.dll dpctl /E /Y - -mkdir dpctl\include -xcopy backends\include dpctl\include /E /Y +@REM call "%ONEAPI_ROOT%\compiler\latest\env\vars.bat" +@REM IF %ERRORLEVEL% NEQ 0 ( +@REM echo "oneAPI compiler activation failed" +@REM exit /b 1 +@REM ) +@REM REM conda uses %ERRORLEVEL% but FPGA scripts can set it. So it should be reseted. +@REM set ERRORLEVEL= + +@REM set "CC=clang-cl.exe" +@REM set "CXX=dpcpp.exe" + +@REM rmdir /S /Q build_cmake +@REM mkdir build_cmake +@REM cd build_cmake + +@REM set "DPCPP_ROOT=%ONEAPI_ROOT%\compiler\latest\windows" +@REM set "INSTALL_PREFIX=%cd%\..\install" + +@REM rmdir /S /Q "%INSTALL_PREFIX%" + +@REM cmake -G Ninja ^ +@REM -DCMAKE_BUILD_TYPE=Release ^ +@REM "-DCMAKE_INSTALL_PREFIX=%INSTALL_PREFIX%" ^ +@REM "-DCMAKE_PREFIX_PATH=%LIBRARY_PREFIX%" ^ +@REM "-DDPCPP_ROOT=%DPCPP_ROOT%" ^ +@REM "%SRC_DIR%\backends" +@REM IF %ERRORLEVEL% NEQ 0 exit /b 1 + +@REM ninja -n +@REM ninja install +@REM IF %ERRORLEVEL% NEQ 0 exit /b 1 + +@REM cd .. +@REM xcopy install\lib\*.lib dpctl /E /Y +@REM xcopy install\bin\*.dll dpctl /E /Y + +@REM mkdir dpctl\include +@REM xcopy backends\include dpctl\include /E /Y REM required by _sycl_core(dpctl) diff --git a/conda-recipe/build.sh b/conda-recipe/build.sh index 607da35268..ce00a52776 100755 --- a/conda-recipe/build.sh +++ b/conda-recipe/build.sh @@ -1,44 +1,44 @@ #!/bin/bash # We need dpcpp to compile dppl_sycl_interface -if [ ! -z "${ONEAPI_ROOT}" ]; then - # Suppress error b/c it could fail on Ubuntu 18.04 - source ${ONEAPI_ROOT}/compiler/latest/env/vars.sh || true - export CC=clang - export CXX=clang++ -else - echo "DPCPP is needed to build DPPL. Abort!" - exit 1 -fi - -rm -rf build_cmake -mkdir 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())"` -NUMPY_INC=`${PYTHON} -c "import numpy; print(numpy.get_include())"` -DPCPP_ROOT=${ONEAPI_ROOT}/compiler/latest/linux/ - -cmake \ - -DCMAKE_BUILD_TYPE=Release \ - -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 - -popd -cp install/lib/*.so dpctl/ - -mkdir -p dpctl/include -cp -r backends/include/* dpctl/include +# if [ ! -z "${ONEAPI_ROOT}" ]; then +# # Suppress error b/c it could fail on Ubuntu 18.04 +# source ${ONEAPI_ROOT}/compiler/latest/env/vars.sh || true +# export CC=clang +# export CXX=clang++ +# else +# echo "DPCPP is needed to build DPPL. Abort!" +# exit 1 +# fi + +# rm -rf build_cmake +# mkdir 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())"` +# NUMPY_INC=`${PYTHON} -c "import numpy; print(numpy.get_include())"` +# DPCPP_ROOT=${ONEAPI_ROOT}/compiler/latest/linux/ + +# cmake \ +# -DCMAKE_BUILD_TYPE=Release \ +# -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 + +# popd +# cp install/lib/*.so dpctl/ + +# mkdir -p dpctl/include +# cp -r backends/include/* dpctl/include # required by dpctl.sycl_core diff --git a/scripts/build_backend.bat b/scripts/build_backend.bat new file mode 100644 index 0000000000..4d4cd43388 --- /dev/null +++ b/scripts/build_backend.bat @@ -0,0 +1,47 @@ +call "%ONEAPI_ROOT%\compiler\latest\env\vars.bat" +IF %ERRORLEVEL% NEQ 0 ( + echo "oneAPI compiler activation failed" + exit /b 1 +) +REM conda uses %ERRORLEVEL% but FPGA scripts can set it. So it should be reseted. +set ERRORLEVEL= + +set "CC=clang-cl.exe" +set "CXX=dpcpp.exe" + +rmdir /S /Q build_cmake +mkdir build_cmake +cd build_cmake + +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 ^ + "-DCMAKE_INSTALL_PREFIX=%INSTALL_PREFIX%" ^ + "-DCMAKE_PREFIX_PATH=%LIBRARY_PREFIX%" ^ + "-DDPCPP_ROOT=%DPCPP_ROOT%" ^ + "%SRC_DIR%\backends" +IF %ERRORLEVEL% NEQ 0 exit /b 1 + +ninja -n +ninja install +IF %ERRORLEVEL% NEQ 0 exit /b 1 + +cd .. +xcopy install\lib\*.lib dpctl /E /Y +xcopy install\bin\*.dll dpctl /E /Y + +mkdir dpctl\include +xcopy backends\include dpctl\include /E /Y + + +REM required by _sycl_core(dpctl) +@REM set "DPPL_SYCL_INTERFACE_LIBDIR=dpctl" +@REM set "DPPL_SYCL_INTERFACE_INCLDIR=dpctl\include" + +@REM "%PYTHON%" setup.py clean --all +@REM "%PYTHON%" setup.py build install +@REM IF %ERRORLEVEL% NEQ 0 exit /b 1 diff --git a/scripts/build_backend.sh b/scripts/build_backend.sh new file mode 100755 index 0000000000..2055076f15 --- /dev/null +++ b/scripts/build_backend.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +# We need dpcpp to compile dppl_sycl_interface +if [ ! -z "${ONEAPI_ROOT}" ]; then + # Suppress error b/c it could fail on Ubuntu 18.04 + source ${ONEAPI_ROOT}/compiler/latest/env/vars.sh || true + export CC=clang + export CXX=clang++ +else + echo "DPCPP is needed to build DPPL. Abort!" + exit 1 +fi + +rm -rf build_cmake +mkdir 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())"` +NUMPY_INC=`${PYTHON} -c "import numpy; print(numpy.get_include())"` +DPCPP_ROOT=${ONEAPI_ROOT}/compiler/latest/linux/ + +cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -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 + +popd +cp install/lib/*.so dpctl/ + +mkdir -p dpctl/include +cp -r backends/include/* dpctl/include + + +# required by dpctl.sycl_core +# 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}" +# ${PYTHON} setup.py clean --all +# ${PYTHON} setup.py build install diff --git a/setup.py b/setup.py index ba9fbd0f21..98954c6b7d 100644 --- a/setup.py +++ b/setup.py @@ -25,6 +25,7 @@ import os.path import sys import versioneer +import subprocess from setuptools import setup, Extension, find_packages from Cython.Build import cythonize @@ -48,6 +49,26 @@ else: assert False, sys.platform + " not supported" +if IS_LIN: + os.environ["CC"] = "clang" + os.environ["CXX"] = "clang++" + os.environ["DPCPP_ROOT"] = os.environ["ONEAPI_ROOT"] + "/compiler/latest/linux/" + os.environ["DPPL_OPENCL_INTERFACE_LIBDIR"] = "dpctl" + os.environ["DPPL_OPENCL_INTERFACE_INCLDIR"] = "dpctl/include" + os.environ["OpenCL_LIBDIR"] = os.environ["DPCPP_ROOT"] + "/lib" + os.environ["DPPL_SYCL_INTERFACE_LIBDIR"] = "dpctl" + os.environ["DPPL_SYCL_INTERFACE_INCLDIR"] = "dpctl/include" + +elif IS_WIN: + os.environ["CC"] = "clang-cl.exe" + os.environ["CXX"] = "dpcpp.exe" + os.environ["DPCPP_ROOT"] = "%ONEAPI_ROOT%\compiler\latest\windows" + os.environ["DPPL_OPENCL_INTERFACE_LIBDIR"] = "dpctl" + os.environ["DPPL_OPENCL_INTERFACE_INCLDIR"] = "dpctl\include" + os.environ["OpenCL_LIBDIR"] = os.environ["DPCPP_ROOT"] + "\lib" + os.environ["DPPL_SYCL_INTERFACE_LIBDIR"] = "dpctl" + os.environ["DPPL_SYCL_INTERFACE_INCLDIR"] = "dpctl\include" + dppl_sycl_interface_lib = os.environ["DPPL_SYCL_INTERFACE_LIBDIR"] dppl_sycl_interface_include = os.environ["DPPL_SYCL_INTERFACE_INCLDIR"] sycl_lib = os.environ["ONEAPI_ROOT"] + "\compiler\latest\windows\lib" @@ -99,7 +120,15 @@ def get_suppressed_warning_flags(): return [] +def build_backend(): + if IS_LIN: + subprocess.check_call(["/bin/bash", "-c", "scripts/build_backend.sh"]) + elif IS_WIN: + subprocess.check_call(["cmd.exe", "/c", "scripts\\build_backend.bat"]) + + def extensions(): + build_backend() # Security flags eca = get_sdl_cflags() ela = get_sdl_ldflags() From b2928e66e2edab02c6f5fc15f8adcfe407e5ca6d Mon Sep 17 00:00:00 2001 From: etotmeni Date: Thu, 5 Nov 2020 04:48:49 -0600 Subject: [PATCH 02/18] wip --- conda-recipe/build.sh | 82 ++++++++++++++++++++-------------------- scripts/build_backend.sh | 6 +-- setup.py | 42 ++++++++++---------- 3 files changed, 66 insertions(+), 64 deletions(-) diff --git a/conda-recipe/build.sh b/conda-recipe/build.sh index ce00a52776..4e9c131436 100755 --- a/conda-recipe/build.sh +++ b/conda-recipe/build.sh @@ -1,47 +1,47 @@ #!/bin/bash # We need dpcpp to compile dppl_sycl_interface -# if [ ! -z "${ONEAPI_ROOT}" ]; then -# # Suppress error b/c it could fail on Ubuntu 18.04 -# source ${ONEAPI_ROOT}/compiler/latest/env/vars.sh || true -# export CC=clang -# export CXX=clang++ -# else -# echo "DPCPP is needed to build DPPL. Abort!" -# exit 1 -# fi - -# rm -rf build_cmake -# mkdir 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())"` -# NUMPY_INC=`${PYTHON} -c "import numpy; print(numpy.get_include())"` -# DPCPP_ROOT=${ONEAPI_ROOT}/compiler/latest/linux/ - -# cmake \ -# -DCMAKE_BUILD_TYPE=Release \ -# -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 - -# popd -# cp install/lib/*.so dpctl/ - -# mkdir -p dpctl/include -# cp -r backends/include/* dpctl/include - - -# required by dpctl.sycl_core +if [ ! -z "${ONEAPI_ROOT}" ]; then + # Suppress error b/c it could fail on Ubuntu 18.04 + source ${ONEAPI_ROOT}/compiler/latest/env/vars.sh || true + export CC=clang + export CXX=clang++ +else + echo "DPCPP is needed to build DPPL. Abort!" + exit 1 +fi + +rm -rf build_cmake +mkdir 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())"` +NUMPY_INC=`${PYTHON} -c "import numpy; print(numpy.get_include())"` +DPCPP_ROOT=${ONEAPI_ROOT}/compiler/latest/linux/ + +cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -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 + +popd +cp install/lib/*.so dpctl/ + +mkdir -p dpctl/include +cp -r backends/include/* dpctl/include + + +required by dpctl.sycl_core export DPPL_SYCL_INTERFACE_LIBDIR=dpctl export DPPL_SYCL_INTERFACE_INCLDIR=dpctl/include diff --git a/scripts/build_backend.sh b/scripts/build_backend.sh index 2055076f15..230620b3f4 100755 --- a/scripts/build_backend.sh +++ b/scripts/build_backend.sh @@ -42,12 +42,12 @@ cp -r backends/include/* dpctl/include # required by dpctl.sycl_core -# export DPPL_SYCL_INTERFACE_LIBDIR=dpctl -# export DPPL_SYCL_INTERFACE_INCLDIR=dpctl/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 CFLAGS="-fPIC -O3 ${CFLAGS}" # ${PYTHON} setup.py clean --all # ${PYTHON} setup.py build install diff --git a/setup.py b/setup.py index 98954c6b7d..0865620e94 100644 --- a/setup.py +++ b/setup.py @@ -49,25 +49,26 @@ else: assert False, sys.platform + " not supported" -if IS_LIN: - os.environ["CC"] = "clang" - os.environ["CXX"] = "clang++" - os.environ["DPCPP_ROOT"] = os.environ["ONEAPI_ROOT"] + "/compiler/latest/linux/" - os.environ["DPPL_OPENCL_INTERFACE_LIBDIR"] = "dpctl" - os.environ["DPPL_OPENCL_INTERFACE_INCLDIR"] = "dpctl/include" - os.environ["OpenCL_LIBDIR"] = os.environ["DPCPP_ROOT"] + "/lib" - os.environ["DPPL_SYCL_INTERFACE_LIBDIR"] = "dpctl" - os.environ["DPPL_SYCL_INTERFACE_INCLDIR"] = "dpctl/include" - -elif IS_WIN: - os.environ["CC"] = "clang-cl.exe" - os.environ["CXX"] = "dpcpp.exe" - os.environ["DPCPP_ROOT"] = "%ONEAPI_ROOT%\compiler\latest\windows" - os.environ["DPPL_OPENCL_INTERFACE_LIBDIR"] = "dpctl" - os.environ["DPPL_OPENCL_INTERFACE_INCLDIR"] = "dpctl\include" - os.environ["OpenCL_LIBDIR"] = os.environ["DPCPP_ROOT"] + "\lib" - os.environ["DPPL_SYCL_INTERFACE_LIBDIR"] = "dpctl" - os.environ["DPPL_SYCL_INTERFACE_INCLDIR"] = "dpctl\include" +# if IS_LIN: +# os.environ["CC"] = "clang" +# os.environ["CXX"] = "clang++" +# os.environ["DPCPP_ROOT"] = os.environ["ONEAPI_ROOT"] + "/compiler/latest/linux/" +# os.environ["DPPL_OPENCL_INTERFACE_LIBDIR"] = "dpctl" +# os.environ["DPPL_OPENCL_INTERFACE_INCLDIR"] = "dpctl/include" +# os.environ["OpenCL_LIBDIR"] = os.environ["DPCPP_ROOT"] + "/lib" +# os.environ["DPPL_SYCL_INTERFACE_LIBDIR"] = "dpctl" +# os.environ["DPPL_SYCL_INTERFACE_INCLDIR"] = "dpctl/include" +# os.environ["CFLAGS"] = "-fPIC -O3 " + os.environ["CFLAGS"] + +# elif IS_WIN: +# os.environ["CC"] = "clang-cl.exe" +# os.environ["CXX"] = "dpcpp.exe" +# os.environ["DPCPP_ROOT"] = "%ONEAPI_ROOT%\compiler\latest\windows" +# os.environ["DPPL_OPENCL_INTERFACE_LIBDIR"] = "dpctl" +# os.environ["DPPL_OPENCL_INTERFACE_INCLDIR"] = "dpctl\include" +# os.environ["OpenCL_LIBDIR"] = os.environ["DPCPP_ROOT"] + "\lib" +# os.environ["DPPL_SYCL_INTERFACE_LIBDIR"] = "dpctl" +# os.environ["DPPL_SYCL_INTERFACE_INCLDIR"] = "dpctl\include" dppl_sycl_interface_lib = os.environ["DPPL_SYCL_INTERFACE_LIBDIR"] dppl_sycl_interface_include = os.environ["DPPL_SYCL_INTERFACE_INCLDIR"] @@ -128,7 +129,7 @@ def build_backend(): def extensions(): - build_backend() + # build_backend() # Security flags eca = get_sdl_cflags() ela = get_sdl_ldflags() @@ -190,6 +191,7 @@ def extensions(): return exts +# build_backend() setup( name="dpctl", version=versioneer.get_version(), From 6df1acbf5238e5f0150dacdee548b6ff087741b7 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Thu, 5 Nov 2020 08:21:27 -0600 Subject: [PATCH 03/18] Fixes for scripts --- conda-recipe/bld.bat | 48 ++++----------------------------------- conda-recipe/build.sh | 40 -------------------------------- scripts/build_backend.bat | 14 ------------ scripts/build_backend.sh | 23 ------------------- setup.py | 35 +++++++++++----------------- 5 files changed, 18 insertions(+), 142 deletions(-) diff --git a/conda-recipe/bld.bat b/conda-recipe/bld.bat index 934fbd477c..bede6323bf 100644 --- a/conda-recipe/bld.bat +++ b/conda-recipe/bld.bat @@ -1,46 +1,8 @@ -@REM call "%ONEAPI_ROOT%\compiler\latest\env\vars.bat" -@REM IF %ERRORLEVEL% NEQ 0 ( -@REM echo "oneAPI compiler activation failed" -@REM exit /b 1 -@REM ) -@REM REM conda uses %ERRORLEVEL% but FPGA scripts can set it. So it should be reseted. -@REM set ERRORLEVEL= - -@REM set "CC=clang-cl.exe" -@REM set "CXX=dpcpp.exe" - -@REM rmdir /S /Q build_cmake -@REM mkdir build_cmake -@REM cd build_cmake - -@REM set "DPCPP_ROOT=%ONEAPI_ROOT%\compiler\latest\windows" -@REM set "INSTALL_PREFIX=%cd%\..\install" - -@REM rmdir /S /Q "%INSTALL_PREFIX%" - -@REM cmake -G Ninja ^ -@REM -DCMAKE_BUILD_TYPE=Release ^ -@REM "-DCMAKE_INSTALL_PREFIX=%INSTALL_PREFIX%" ^ -@REM "-DCMAKE_PREFIX_PATH=%LIBRARY_PREFIX%" ^ -@REM "-DDPCPP_ROOT=%DPCPP_ROOT%" ^ -@REM "%SRC_DIR%\backends" -@REM IF %ERRORLEVEL% NEQ 0 exit /b 1 - -@REM ninja -n -@REM ninja install -@REM IF %ERRORLEVEL% NEQ 0 exit /b 1 - -@REM cd .. -@REM xcopy install\lib\*.lib dpctl /E /Y -@REM xcopy install\bin\*.dll dpctl /E /Y - -@REM mkdir dpctl\include -@REM xcopy backends\include dpctl\include /E /Y - - -REM required by _sycl_core(dpctl) -set "DPPL_SYCL_INTERFACE_LIBDIR=dpctl" -set "DPPL_SYCL_INTERFACE_INCLDIR=dpctl\include" +call "%ONEAPI_ROOT%\compiler\latest\env\vars.bat" +IF %ERRORLEVEL% NEQ 0 ( + echo "oneAPI compiler activation failed" + exit /b 1 +) "%PYTHON%" setup.py clean --all "%PYTHON%" setup.py build install diff --git a/conda-recipe/build.sh b/conda-recipe/build.sh index 4e9c131436..f0bd0cfd62 100755 --- a/conda-recipe/build.sh +++ b/conda-recipe/build.sh @@ -4,50 +4,10 @@ if [ ! -z "${ONEAPI_ROOT}" ]; then # Suppress error b/c it could fail on Ubuntu 18.04 source ${ONEAPI_ROOT}/compiler/latest/env/vars.sh || true - export CC=clang - export CXX=clang++ else echo "DPCPP is needed to build DPPL. Abort!" exit 1 fi -rm -rf build_cmake -mkdir 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())"` -NUMPY_INC=`${PYTHON} -c "import numpy; print(numpy.get_include())"` -DPCPP_ROOT=${ONEAPI_ROOT}/compiler/latest/linux/ - -cmake \ - -DCMAKE_BUILD_TYPE=Release \ - -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 - -popd -cp install/lib/*.so dpctl/ - -mkdir -p dpctl/include -cp -r backends/include/* dpctl/include - - -required by dpctl.sycl_core -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}" ${PYTHON} setup.py clean --all ${PYTHON} setup.py build install diff --git a/scripts/build_backend.bat b/scripts/build_backend.bat index 4d4cd43388..2c11d5ee31 100644 --- a/scripts/build_backend.bat +++ b/scripts/build_backend.bat @@ -1,8 +1,3 @@ -call "%ONEAPI_ROOT%\compiler\latest\env\vars.bat" -IF %ERRORLEVEL% NEQ 0 ( - echo "oneAPI compiler activation failed" - exit /b 1 -) REM conda uses %ERRORLEVEL% but FPGA scripts can set it. So it should be reseted. set ERRORLEVEL= @@ -36,12 +31,3 @@ xcopy install\bin\*.dll dpctl /E /Y mkdir dpctl\include xcopy backends\include dpctl\include /E /Y - - -REM required by _sycl_core(dpctl) -@REM set "DPPL_SYCL_INTERFACE_LIBDIR=dpctl" -@REM set "DPPL_SYCL_INTERFACE_INCLDIR=dpctl\include" - -@REM "%PYTHON%" setup.py clean --all -@REM "%PYTHON%" setup.py build install -@REM IF %ERRORLEVEL% NEQ 0 exit /b 1 diff --git a/scripts/build_backend.sh b/scripts/build_backend.sh index 230620b3f4..2f3aa73b13 100755 --- a/scripts/build_backend.sh +++ b/scripts/build_backend.sh @@ -1,16 +1,5 @@ #!/bin/bash -# We need dpcpp to compile dppl_sycl_interface -if [ ! -z "${ONEAPI_ROOT}" ]; then - # Suppress error b/c it could fail on Ubuntu 18.04 - source ${ONEAPI_ROOT}/compiler/latest/env/vars.sh || true - export CC=clang - export CXX=clang++ -else - echo "DPCPP is needed to build DPPL. Abort!" - exit 1 -fi - rm -rf build_cmake mkdir build_cmake pushd build_cmake @@ -39,15 +28,3 @@ cp install/lib/*.so dpctl/ mkdir -p dpctl/include cp -r backends/include/* dpctl/include - - -# required by dpctl.sycl_core -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}" -# ${PYTHON} setup.py clean --all -# ${PYTHON} setup.py build install diff --git a/setup.py b/setup.py index 0865620e94..b28be1dcc8 100644 --- a/setup.py +++ b/setup.py @@ -49,26 +49,18 @@ else: assert False, sys.platform + " not supported" -# if IS_LIN: -# os.environ["CC"] = "clang" -# os.environ["CXX"] = "clang++" -# os.environ["DPCPP_ROOT"] = os.environ["ONEAPI_ROOT"] + "/compiler/latest/linux/" -# os.environ["DPPL_OPENCL_INTERFACE_LIBDIR"] = "dpctl" -# os.environ["DPPL_OPENCL_INTERFACE_INCLDIR"] = "dpctl/include" -# os.environ["OpenCL_LIBDIR"] = os.environ["DPCPP_ROOT"] + "/lib" -# os.environ["DPPL_SYCL_INTERFACE_LIBDIR"] = "dpctl" -# os.environ["DPPL_SYCL_INTERFACE_INCLDIR"] = "dpctl/include" -# os.environ["CFLAGS"] = "-fPIC -O3 " + os.environ["CFLAGS"] - -# elif IS_WIN: -# os.environ["CC"] = "clang-cl.exe" -# os.environ["CXX"] = "dpcpp.exe" -# os.environ["DPCPP_ROOT"] = "%ONEAPI_ROOT%\compiler\latest\windows" -# os.environ["DPPL_OPENCL_INTERFACE_LIBDIR"] = "dpctl" -# os.environ["DPPL_OPENCL_INTERFACE_INCLDIR"] = "dpctl\include" -# os.environ["OpenCL_LIBDIR"] = os.environ["DPCPP_ROOT"] + "\lib" -# os.environ["DPPL_SYCL_INTERFACE_LIBDIR"] = "dpctl" -# os.environ["DPPL_SYCL_INTERFACE_INCLDIR"] = "dpctl\include" +if IS_LIN: + os.environ["CC"] = "clang" + os.environ["CXX"] = "clang++" + os.environ["DPPL_SYCL_INTERFACE_LIBDIR"] = "dpctl" + os.environ["DPPL_SYCL_INTERFACE_INCLDIR"] = "dpctl/include" + os.environ["CFLAGS"] = "-fPIC -O3 " + os.environ["CFLAGS"] + +elif IS_WIN: + os.environ["CC"] = "clang-cl.exe" + os.environ["CXX"] = "dpcpp.exe" + os.environ["DPPL_SYCL_INTERFACE_LIBDIR"] = "dpctl" + os.environ["DPPL_SYCL_INTERFACE_INCLDIR"] = "dpctl\include" dppl_sycl_interface_lib = os.environ["DPPL_SYCL_INTERFACE_LIBDIR"] dppl_sycl_interface_include = os.environ["DPPL_SYCL_INTERFACE_INCLDIR"] @@ -129,7 +121,6 @@ def build_backend(): def extensions(): - # build_backend() # Security flags eca = get_sdl_cflags() ela = get_sdl_ldflags() @@ -191,7 +182,7 @@ def extensions(): return exts -# build_backend() +build_backend() setup( name="dpctl", version=versioneer.get_version(), From 1815217b2813be38efaf6ecff56136168bd59a28 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Tue, 10 Nov 2020 04:07:29 -0600 Subject: [PATCH 04/18] Some fixes --- scripts/build_backend.sh | 7 ++----- setup.py | 23 ++++++++++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/scripts/build_backend.sh b/scripts/build_backend.sh index 2f3aa73b13..9947f6bd48 100755 --- a/scripts/build_backend.sh +++ b/scripts/build_backend.sh @@ -7,9 +7,6 @@ pushd build_cmake INSTALL_PREFIX=`pwd`/../install rm -rf ${INSTALL_PREFIX} -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 \ @@ -17,8 +14,8 @@ cmake \ -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \ -DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} \ -DDPCPP_ROOT=${DPCPP_ROOT} \ - -DPYTHON_INCLUDE_DIR=${PYTHON_INC} \ - -DNUMPY_INCLUDE_DIR=${NUMPY_INC} \ + -DCMAKE_C_COMPILER:PATH=${DPCPP_ROOT}/bin/clang \ + -DCMAKE_CXX_COMPILER:PATH=${DPCPP_ROOT}/bin/dpcpp \ ../backends make -j 4 && make install diff --git a/setup.py b/setup.py index b28be1dcc8..f6e3bf106d 100644 --- a/setup.py +++ b/setup.py @@ -28,6 +28,7 @@ import subprocess from setuptools import setup, Extension, find_packages +from setuptools.command.build_py import build_py as _build_py from Cython.Build import cythonize import numpy as np @@ -50,11 +51,12 @@ assert False, sys.platform + " not supported" if IS_LIN: - os.environ["CC"] = "clang" - os.environ["CXX"] = "clang++" + DPCPP_ROOT = os.environ["ONEAPI_ROOT"] + "/compiler/latest/linux" + os.environ["CC"] = DPCPP_ROOT + "/bin/clang" + os.environ["CXX"] = DPCPP_ROOT + "/bin/dpcpp" os.environ["DPPL_SYCL_INTERFACE_LIBDIR"] = "dpctl" os.environ["DPPL_SYCL_INTERFACE_INCLDIR"] = "dpctl/include" - os.environ["CFLAGS"] = "-fPIC -O3 " + os.environ["CFLAGS"] + os.environ["CFLAGS"] = "-fPIC" elif IS_WIN: os.environ["CC"] = "clang-cl.exe" @@ -182,11 +184,22 @@ def extensions(): return exts -build_backend() +class build_py(_build_py): + def run(self): + build_backend() + return super().run() + + +def _get_cmdclass(): + cmdclass = versioneer.get_cmdclass() + cmdclass["build_py"] = build_py + return cmdclass + + setup( name="dpctl", version=versioneer.get_version(), - cmdclass=versioneer.get_cmdclass(), + cmdclass=_get_cmdclass(), description="A lightweight Python wrapper for a subset of OpenCL and SYCL.", license="Apache 2.0", author="Intel Corporation", From c53d32ae83e3851c8d5c123f988885c55514f437 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Tue, 10 Nov 2020 07:04:46 -0600 Subject: [PATCH 05/18] Add python backend script --- scripts/build_backend.py | 97 ++++++++++++++++++++++++++++++++++++++++ setup.py | 7 ++- 2 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 scripts/build_backend.py diff --git a/scripts/build_backend.py b/scripts/build_backend.py new file mode 100644 index 0000000000..8d81bf26c2 --- /dev/null +++ b/scripts/build_backend.py @@ -0,0 +1,97 @@ +import os +import sys +import subprocess +import shutil + +IS_WIN = False +IS_LIN = False + +if "linux" in sys.platform: + IS_LIN = True +elif sys.platform in ["win32", "cygwin"]: + IS_WIN = True +else: + assert False, sys.platform + " not supported" + +ONEAPI_ROOT = os.environ.get("ONEAPI_ROOT") + +if IS_LIN: + DPCPP_ROOT = os.path.join(ONEAPI_ROOT, "compiler/latest/linux") +if IS_WIN: + os.environ["ERRORLEVEL"] = "" + DPCPP_ROOT = os.path.join(ONEAPI_ROOT, "compiler\latest\windows") + +dpctl_dir = os.getcwd() +build_cmake_dir = os.path.join(dpctl_dir, "build_cmake") +if os.path.exists(build_cmake_dir): + shutil.rmtree(build_cmake_dir) +os.mkdir(build_cmake_dir) +os.chdir(build_cmake_dir) + +INSTALL_PREFIX = os.path.join(dpctl_dir, "install") +if os.path.exists(INSTALL_PREFIX): + shutil.rmtree(INSTALL_PREFIX) + +backends_dir = os.path.join(dpctl_dir, "backends") + +if IS_LIN: + subprocess.check_call( + [ + "cmake", + "-DCMAKE_BUILD_TYPE=Release", + "-DCMAKE_INSTALL_PREFIX=" + INSTALL_PREFIX, + "-DCMAKE_PREFIX_PATH=" + INSTALL_PREFIX, + "-DDPCPP_ROOT=" + DPCPP_ROOT, + "-DCMAKE_C_COMPILER:PATH=" + os.path.join(DPCPP_ROOT, "bin/clang"), + "-DCMAKE_CXX_COMPILER:PATH=" + os.path.join(DPCPP_ROOT, "bin/dpcpp"), + backends_dir, + ], + stderr=subprocess.STDOUT, + shell=False, + ) + + subprocess.check_call(["make", "-j", "4"]) + subprocess.check_call(["make", "install"]) + + os.chdir(dpctl_dir) + os.system("cp " + dpctl_dir + "/install/lib/*.so " + dpctl_dir + "/dpctl/") + + include_dir = os.path.join(dpctl_dir, "dpctl/include") + if os.path.exists(include_dir): + shutil.rmtree(include_dir) + + shutil.copytree(os.path.join(dpctl_dir, "backends/include"), include_dir) + +if IS_WIN: + subprocess.check_call( + [ + "cmake", + "-G", + "Ninja", + "-DCMAKE_BUILD_TYPE=Release", + "-DCMAKE_INSTALL_PREFIX=" + INSTALL_PREFIX, + "-DCMAKE_PREFIX_PATH=" + INSTALL_PREFIX, + "-DDPCPP_ROOT=" + DPCPP_ROOT, + backends_dir, + ], + stderr=subprocess.STDOUT, + shell=True, + ) + + if os.environ["ERRORLEVEL"] != 0: + assert 1, "cmake failed" + + subprocess.check_call(["ninja", "-n"]) + subprocess.check_call(["ninja", "install"]) + if os.environ["ERRORLEVEL"] != 0: + assert 1, "install failed" + + os.chdir(dpctl_dir) + os.system("cp " + dpctl_dir + "install\\lib\\*.lib " + dpctl_dir + "\\dpctl\\") + os.system("cp " + dpctl_dir + "install\\bin\\*.dll " + dpctl_dir + "\\dpctl\\") + + include_dir = os.path.join(dpctl_dir, "dpctl\\include") + if os.path.exists(include_dir): + shutil.rmtree(include_dir) + + shutil.copytree(os.path.join(dpctl_dir, "backends\\include"), include_dir) diff --git a/setup.py b/setup.py index f6e3bf106d..90c88aa142 100644 --- a/setup.py +++ b/setup.py @@ -116,10 +116,13 @@ def get_suppressed_warning_flags(): def build_backend(): + dpctl_dir = os.getcwd() if IS_LIN: - subprocess.check_call(["/bin/bash", "-c", "scripts/build_backend.sh"]) + build_backend_py = os.path.join(dpctl_dir, "scripts/build_backend.py") + subprocess.check_call([sys.executable, build_backend_py]) elif IS_WIN: - subprocess.check_call(["cmd.exe", "/c", "scripts\\build_backend.bat"]) + build_backend_py = os.path.join(dpctl_dir, "scripts\\build_backend.py") + subprocess.check_call([sys.executable, build_backend_py]) def extensions(): From ef7e77fa3221eed9336bf91d941f91b1ced4dfd5 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Tue, 10 Nov 2020 07:41:27 -0600 Subject: [PATCH 06/18] Fix win build --- scripts/build_backend.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/scripts/build_backend.py b/scripts/build_backend.py index 8d81bf26c2..b2dac2c100 100644 --- a/scripts/build_backend.py +++ b/scripts/build_backend.py @@ -87,8 +87,22 @@ assert 1, "install failed" os.chdir(dpctl_dir) - os.system("cp " + dpctl_dir + "install\\lib\\*.lib " + dpctl_dir + "\\dpctl\\") - os.system("cp " + dpctl_dir + "install\\bin\\*.dll " + dpctl_dir + "\\dpctl\\") + os.system( + "xcopy " + + dpctl_dir + + "install\\lib\\*.lib " + + dpctl_dir + + "\\dpctl\\" + + " /E /Y" + ) + os.system( + "xcopy " + + dpctl_dir + + "install\\bin\\*.dll " + + dpctl_dir + + "\\dpctl\\" + + " /E /Y" + ) include_dir = os.path.join(dpctl_dir, "dpctl\\include") if os.path.exists(include_dir): From 5eb22035d59ca69d7052b544551076648528e89c Mon Sep 17 00:00:00 2001 From: etotmeni Date: Tue, 10 Nov 2020 08:00:12 -0600 Subject: [PATCH 07/18] Fix win --- scripts/build_backend.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/build_backend.py b/scripts/build_backend.py index b2dac2c100..dfd16f5354 100644 --- a/scripts/build_backend.py +++ b/scripts/build_backend.py @@ -90,7 +90,7 @@ os.system( "xcopy " + dpctl_dir - + "install\\lib\\*.lib " + + "\\install\\lib\\*.lib " + dpctl_dir + "\\dpctl\\" + " /E /Y" @@ -98,7 +98,7 @@ os.system( "xcopy " + dpctl_dir - + "install\\bin\\*.dll " + + "\\install\\bin\\*.dll " + dpctl_dir + "\\dpctl\\" + " /E /Y" From 745d6e4762b422abccc6d2eb86a966f3a8c55fdb Mon Sep 17 00:00:00 2001 From: etotmeni Date: Tue, 10 Nov 2020 08:18:49 -0600 Subject: [PATCH 08/18] Del build_backend sh+bat --- scripts/build_backend.bat | 33 --------------------------------- scripts/build_backend.sh | 27 --------------------------- 2 files changed, 60 deletions(-) delete mode 100644 scripts/build_backend.bat delete mode 100755 scripts/build_backend.sh diff --git a/scripts/build_backend.bat b/scripts/build_backend.bat deleted file mode 100644 index 2c11d5ee31..0000000000 --- a/scripts/build_backend.bat +++ /dev/null @@ -1,33 +0,0 @@ -REM conda uses %ERRORLEVEL% but FPGA scripts can set it. So it should be reseted. -set ERRORLEVEL= - -set "CC=clang-cl.exe" -set "CXX=dpcpp.exe" - -rmdir /S /Q build_cmake -mkdir build_cmake -cd build_cmake - -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 ^ - "-DCMAKE_INSTALL_PREFIX=%INSTALL_PREFIX%" ^ - "-DCMAKE_PREFIX_PATH=%LIBRARY_PREFIX%" ^ - "-DDPCPP_ROOT=%DPCPP_ROOT%" ^ - "%SRC_DIR%\backends" -IF %ERRORLEVEL% NEQ 0 exit /b 1 - -ninja -n -ninja install -IF %ERRORLEVEL% NEQ 0 exit /b 1 - -cd .. -xcopy install\lib\*.lib dpctl /E /Y -xcopy install\bin\*.dll dpctl /E /Y - -mkdir dpctl\include -xcopy backends\include dpctl\include /E /Y diff --git a/scripts/build_backend.sh b/scripts/build_backend.sh deleted file mode 100755 index 9947f6bd48..0000000000 --- a/scripts/build_backend.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -rm -rf build_cmake -mkdir build_cmake -pushd build_cmake - -INSTALL_PREFIX=`pwd`/../install -rm -rf ${INSTALL_PREFIX} - -DPCPP_ROOT=${ONEAPI_ROOT}/compiler/latest/linux/ - -cmake \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \ - -DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} \ - -DDPCPP_ROOT=${DPCPP_ROOT} \ - -DCMAKE_C_COMPILER:PATH=${DPCPP_ROOT}/bin/clang \ - -DCMAKE_CXX_COMPILER:PATH=${DPCPP_ROOT}/bin/dpcpp \ - ../backends - -make -j 4 && make install - -popd -cp install/lib/*.so dpctl/ - -mkdir -p dpctl/include -cp -r backends/include/* dpctl/include From 20352b8b77bbb8e5f630dbe708ace9bd671b0f76 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Wed, 11 Nov 2020 06:31:20 -0600 Subject: [PATCH 09/18] Small fixes --- scripts/build_backend.py | 53 ++++++++++++---------------------------- setup.py | 8 ++---- 2 files changed, 18 insertions(+), 43 deletions(-) diff --git a/scripts/build_backend.py b/scripts/build_backend.py index dfd16f5354..5d7e788ccd 100644 --- a/scripts/build_backend.py +++ b/scripts/build_backend.py @@ -2,6 +2,7 @@ import sys import subprocess import shutil +import glob IS_WIN = False IS_LIN = False @@ -16,10 +17,9 @@ ONEAPI_ROOT = os.environ.get("ONEAPI_ROOT") if IS_LIN: - DPCPP_ROOT = os.path.join(ONEAPI_ROOT, "compiler/latest/linux") + DPCPP_ROOT = os.path.join(ONEAPI_ROOT, "compiler", "latest", "linux") if IS_WIN: - os.environ["ERRORLEVEL"] = "" - DPCPP_ROOT = os.path.join(ONEAPI_ROOT, "compiler\latest\windows") + DPCPP_ROOT = os.path.join(ONEAPI_ROOT, "compiler" "latest" "windows") dpctl_dir = os.getcwd() build_cmake_dir = os.path.join(dpctl_dir, "build_cmake") @@ -42,8 +42,8 @@ "-DCMAKE_INSTALL_PREFIX=" + INSTALL_PREFIX, "-DCMAKE_PREFIX_PATH=" + INSTALL_PREFIX, "-DDPCPP_ROOT=" + DPCPP_ROOT, - "-DCMAKE_C_COMPILER:PATH=" + os.path.join(DPCPP_ROOT, "bin/clang"), - "-DCMAKE_CXX_COMPILER:PATH=" + os.path.join(DPCPP_ROOT, "bin/dpcpp"), + "-DCMAKE_C_COMPILER:PATH=" + os.path.join(DPCPP_ROOT, "bin", "clang"), + "-DCMAKE_CXX_COMPILER:PATH=" + os.path.join(DPCPP_ROOT, "bin", "dpcpp"), backends_dir, ], stderr=subprocess.STDOUT, @@ -54,13 +54,8 @@ subprocess.check_call(["make", "install"]) os.chdir(dpctl_dir) - os.system("cp " + dpctl_dir + "/install/lib/*.so " + dpctl_dir + "/dpctl/") - - include_dir = os.path.join(dpctl_dir, "dpctl/include") - if os.path.exists(include_dir): - shutil.rmtree(include_dir) - - shutil.copytree(os.path.join(dpctl_dir, "backends/include"), include_dir) + for file in glob.glob(os.path.join(dpctl_dir, "install", "lib", "*.so")): + shutil.copy(file, os.path.join(dpctl_dir, "dpctl")) if IS_WIN: subprocess.check_call( @@ -78,34 +73,18 @@ shell=True, ) - if os.environ["ERRORLEVEL"] != 0: - assert 1, "cmake failed" - subprocess.check_call(["ninja", "-n"]) subprocess.check_call(["ninja", "install"]) - if os.environ["ERRORLEVEL"] != 0: - assert 1, "install failed" os.chdir(dpctl_dir) - os.system( - "xcopy " - + dpctl_dir - + "\\install\\lib\\*.lib " - + dpctl_dir - + "\\dpctl\\" - + " /E /Y" - ) - os.system( - "xcopy " - + dpctl_dir - + "\\install\\bin\\*.dll " - + dpctl_dir - + "\\dpctl\\" - + " /E /Y" - ) + for file in glob.glob(os.path.join(dpctl_dir, "install", "lib", "*.lib")): + shutil.copy(file, os.path.join(dpctl_dir, "dpctl")) + + for file in glob.glob(os.path.join(dpctl_dir, "install", "bin", "*.dll")): + shutil.copy(file, os.path.join(dpctl_dir, "dpctl")) - include_dir = os.path.join(dpctl_dir, "dpctl\\include") - if os.path.exists(include_dir): - shutil.rmtree(include_dir) +include_dir = os.path.join(dpctl_dir, "dpctl", "include") +if os.path.exists(include_dir): + shutil.rmtree(include_dir) - shutil.copytree(os.path.join(dpctl_dir, "backends\\include"), include_dir) +shutil.copytree(os.path.join(dpctl_dir, "backends", "include"), include_dir) diff --git a/setup.py b/setup.py index 90c88aa142..dee65add8f 100644 --- a/setup.py +++ b/setup.py @@ -117,12 +117,8 @@ def get_suppressed_warning_flags(): def build_backend(): dpctl_dir = os.getcwd() - if IS_LIN: - build_backend_py = os.path.join(dpctl_dir, "scripts/build_backend.py") - subprocess.check_call([sys.executable, build_backend_py]) - elif IS_WIN: - build_backend_py = os.path.join(dpctl_dir, "scripts\\build_backend.py") - subprocess.check_call([sys.executable, build_backend_py]) + build_script = os.path.join(dpctl_dir, "scripts", "build_backend.py") + subprocess.check_call([sys.executable, build_script]) def extensions(): From 0a1991e17367715eb54bb120d3590a588e949449 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Wed, 11 Nov 2020 06:59:31 -0600 Subject: [PATCH 10/18] Fix path --- scripts/build_backend.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/build_backend.py b/scripts/build_backend.py index 5d7e788ccd..be960a0961 100644 --- a/scripts/build_backend.py +++ b/scripts/build_backend.py @@ -17,9 +17,9 @@ ONEAPI_ROOT = os.environ.get("ONEAPI_ROOT") if IS_LIN: - DPCPP_ROOT = os.path.join(ONEAPI_ROOT, "compiler", "latest", "linux") + DPCPP_ROOT = os.path.join(ONEAPI_ROOT, "compiler/latest/linux") if IS_WIN: - DPCPP_ROOT = os.path.join(ONEAPI_ROOT, "compiler" "latest" "windows") + DPCPP_ROOT = os.path.join(ONEAPI_ROOT, "compiler\latest\windows") dpctl_dir = os.getcwd() build_cmake_dir = os.path.join(dpctl_dir, "build_cmake") From ff655bc7202465d52eb654a8f50d41e0052229d5 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Wed, 11 Nov 2020 07:34:09 -0600 Subject: [PATCH 11/18] Move build to install\develop command --- conda-recipe/build.sh | 2 +- setup.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/conda-recipe/build.sh b/conda-recipe/build.sh index f0bd0cfd62..59f7ac2ae1 100755 --- a/conda-recipe/build.sh +++ b/conda-recipe/build.sh @@ -10,4 +10,4 @@ else fi ${PYTHON} setup.py clean --all -${PYTHON} setup.py build install +${PYTHON} setup.py install diff --git a/setup.py b/setup.py index dee65add8f..544bda2a7e 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,8 @@ import subprocess from setuptools import setup, Extension, find_packages -from setuptools.command.build_py import build_py as _build_py +from setuptools.command.install import install as _install +from setuptools.command.develop import develop as _develop from Cython.Build import cythonize import numpy as np @@ -183,7 +184,13 @@ def extensions(): return exts -class build_py(_build_py): +class install(_install): + def run(self): + build_backend() + return super().run() + + +class develop(_develop): def run(self): build_backend() return super().run() @@ -191,7 +198,8 @@ def run(self): def _get_cmdclass(): cmdclass = versioneer.get_cmdclass() - cmdclass["build_py"] = build_py + cmdclass["install"] = install + cmdclass["develop"] = develop return cmdclass From 3f91ac130264ed8f694f26f19f96764c46f7c40a Mon Sep 17 00:00:00 2001 From: etotmeni Date: Wed, 11 Nov 2020 09:14:56 -0600 Subject: [PATCH 12/18] Del build from bat --- conda-recipe/bld.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conda-recipe/bld.bat b/conda-recipe/bld.bat index bede6323bf..2ae65b552a 100644 --- a/conda-recipe/bld.bat +++ b/conda-recipe/bld.bat @@ -5,5 +5,5 @@ IF %ERRORLEVEL% NEQ 0 ( ) "%PYTHON%" setup.py clean --all -"%PYTHON%" setup.py build install +"%PYTHON%" setup.py install IF %ERRORLEVEL% NEQ 0 exit /b 1 From 5c01e9f1161a66d75aaf945a7cbd88289178c0e2 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Thu, 12 Nov 2020 02:39:58 -0600 Subject: [PATCH 13/18] Small fixes --- scripts/build_backend.py | 52 +++++++++++++++++----------------------- setup.py | 2 +- 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/scripts/build_backend.py b/scripts/build_backend.py index be960a0961..c0a12c9ec9 100644 --- a/scripts/build_backend.py +++ b/scripts/build_backend.py @@ -35,21 +35,17 @@ backends_dir = os.path.join(dpctl_dir, "backends") if IS_LIN: - subprocess.check_call( - [ - "cmake", - "-DCMAKE_BUILD_TYPE=Release", - "-DCMAKE_INSTALL_PREFIX=" + INSTALL_PREFIX, - "-DCMAKE_PREFIX_PATH=" + INSTALL_PREFIX, - "-DDPCPP_ROOT=" + DPCPP_ROOT, - "-DCMAKE_C_COMPILER:PATH=" + os.path.join(DPCPP_ROOT, "bin", "clang"), - "-DCMAKE_CXX_COMPILER:PATH=" + os.path.join(DPCPP_ROOT, "bin", "dpcpp"), - backends_dir, - ], - stderr=subprocess.STDOUT, - shell=False, - ) - + cmake = [ + "cmake", + "-DCMAKE_BUILD_TYPE=Release", + "-DCMAKE_INSTALL_PREFIX=" + INSTALL_PREFIX, + "-DCMAKE_PREFIX_PATH=" + INSTALL_PREFIX, + "-DDPCPP_ROOT=" + DPCPP_ROOT, + "-DCMAKE_C_COMPILER:PATH=" + os.path.join(DPCPP_ROOT, "bin", "clang"), + "-DCMAKE_CXX_COMPILER:PATH=" + os.path.join(DPCPP_ROOT, "bin", "clang++"), + backends_dir, + ] + subprocess.check_call(cmake, stderr=subprocess.STDOUT, shell=False) subprocess.check_call(["make", "-j", "4"]) subprocess.check_call(["make", "install"]) @@ -58,21 +54,17 @@ shutil.copy(file, os.path.join(dpctl_dir, "dpctl")) if IS_WIN: - subprocess.check_call( - [ - "cmake", - "-G", - "Ninja", - "-DCMAKE_BUILD_TYPE=Release", - "-DCMAKE_INSTALL_PREFIX=" + INSTALL_PREFIX, - "-DCMAKE_PREFIX_PATH=" + INSTALL_PREFIX, - "-DDPCPP_ROOT=" + DPCPP_ROOT, - backends_dir, - ], - stderr=subprocess.STDOUT, - shell=True, - ) - + cmake = [ + "cmake", + "-G", + "Ninja", + "-DCMAKE_BUILD_TYPE=Release", + "-DCMAKE_INSTALL_PREFIX=" + INSTALL_PREFIX, + "-DCMAKE_PREFIX_PATH=" + INSTALL_PREFIX, + "-DDPCPP_ROOT=" + DPCPP_ROOT, + backends_dir, + ] + subprocess.check_call(cmake, stderr=subprocess.STDOUT, shell=True) subprocess.check_call(["ninja", "-n"]) subprocess.check_call(["ninja", "install"]) diff --git a/setup.py b/setup.py index 544bda2a7e..3eac3e8076 100644 --- a/setup.py +++ b/setup.py @@ -27,9 +27,9 @@ import versioneer import subprocess -from setuptools import setup, Extension, find_packages from setuptools.command.install import install as _install from setuptools.command.develop import develop as _develop +from setuptools import setup, Extension, find_packages from Cython.Build import cythonize import numpy as np From 5d040bc7fd35aacb98d877ff812008cd42760e59 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Thu, 12 Nov 2020 02:48:06 -0600 Subject: [PATCH 14/18] Change compiler to clang++ --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 3eac3e8076..3234dfeb2a 100644 --- a/setup.py +++ b/setup.py @@ -54,7 +54,7 @@ if IS_LIN: DPCPP_ROOT = os.environ["ONEAPI_ROOT"] + "/compiler/latest/linux" os.environ["CC"] = DPCPP_ROOT + "/bin/clang" - os.environ["CXX"] = DPCPP_ROOT + "/bin/dpcpp" + os.environ["CXX"] = DPCPP_ROOT + "/bin/clang++" os.environ["DPPL_SYCL_INTERFACE_LIBDIR"] = "dpctl" os.environ["DPPL_SYCL_INTERFACE_INCLDIR"] = "dpctl/include" os.environ["CFLAGS"] = "-fPIC" From 6011ab2beacde186fd5a0805a246ba5ce67e9f5e Mon Sep 17 00:00:00 2001 From: etotmeni Date: Thu, 12 Nov 2020 03:44:52 -0600 Subject: [PATCH 15/18] Small fixes --- scripts/build_backend.py | 8 ++++---- setup.py | 11 +++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/scripts/build_backend.py b/scripts/build_backend.py index c0a12c9ec9..57d9cd3ef0 100644 --- a/scripts/build_backend.py +++ b/scripts/build_backend.py @@ -35,7 +35,7 @@ backends_dir = os.path.join(dpctl_dir, "backends") if IS_LIN: - cmake = [ + cmake_args = [ "cmake", "-DCMAKE_BUILD_TYPE=Release", "-DCMAKE_INSTALL_PREFIX=" + INSTALL_PREFIX, @@ -45,7 +45,7 @@ "-DCMAKE_CXX_COMPILER:PATH=" + os.path.join(DPCPP_ROOT, "bin", "clang++"), backends_dir, ] - subprocess.check_call(cmake, stderr=subprocess.STDOUT, shell=False) + subprocess.check_call(cmake_args, stderr=subprocess.STDOUT, shell=False) subprocess.check_call(["make", "-j", "4"]) subprocess.check_call(["make", "install"]) @@ -54,7 +54,7 @@ shutil.copy(file, os.path.join(dpctl_dir, "dpctl")) if IS_WIN: - cmake = [ + cmake_args = [ "cmake", "-G", "Ninja", @@ -64,7 +64,7 @@ "-DDPCPP_ROOT=" + DPCPP_ROOT, backends_dir, ] - subprocess.check_call(cmake, stderr=subprocess.STDOUT, shell=True) + subprocess.check_call(cmake_args, stderr=subprocess.STDOUT, shell=True) subprocess.check_call(["ninja", "-n"]) subprocess.check_call(["ninja", "install"]) diff --git a/setup.py b/setup.py index 3234dfeb2a..c677a98a40 100644 --- a/setup.py +++ b/setup.py @@ -27,8 +27,8 @@ import versioneer import subprocess -from setuptools.command.install import install as _install -from setuptools.command.develop import develop as _develop +from setuptools.command.install import install as orig_install +from setuptools.command.develop import develop as orig_develop from setuptools import setup, Extension, find_packages from Cython.Build import cythonize @@ -117,8 +117,7 @@ def get_suppressed_warning_flags(): def build_backend(): - dpctl_dir = os.getcwd() - build_script = os.path.join(dpctl_dir, "scripts", "build_backend.py") + build_script = os.path.join(os.getcwd(), "scripts", "build_backend.py") subprocess.check_call([sys.executable, build_script]) @@ -184,13 +183,13 @@ def extensions(): return exts -class install(_install): +class install(orig_install): def run(self): build_backend() return super().run() -class develop(_develop): +class develop(orig_develop): def run(self): build_backend() return super().run() From 517845b2d95d4b97ffd33c4546d980674acf2c65 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Thu, 12 Nov 2020 04:20:57 -0600 Subject: [PATCH 16/18] Change changelog + readme --- CHANGELOG.md | 1 + README.md | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8d7935f1d..e4d36a51a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. - Device descriptors "max_compute_units", "max_work_item_dimensions", "max_work_item_sizes", "max_work_group_size", "max_num_sub_groups" and "aspects" for int64 atomics inside dpctl C API and inside the dpctl.SyclDevice class. - MemoryUSM* classes moved to `dpctl.memory` module, added support for aligned allocation, added support for `prefetch` and `mem_advise` (sychronous) methods, implemented `copy_to_host`, `copy_from_host` and `copy_from_device` methods, pickling support, and zero-copy interoperability with Python objects which implement `__sycl_usm_array_inerface__` protocol. - Helper scripts to generate API documentation for both C API and Python. +- Opportunity to build and install project with setuptools. ### Fixed - Compiler warnings when building libDPPLSyclInterface and the Cython extensions. diff --git a/README.md b/README.md index fd54be2f92..662f7cefa4 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,20 @@ conda build --croot=C:/tmp conda-recipe conda install dpctl ``` +Build and Install with setuptools +=========== +dpCtl relies on DPC++ runtime. With Intel oneAPI installed you should activate it. + +For install: +```cmd +python setup.py install +``` + +For development: +```cmd +python setup.py develop +``` + Using dpCtl =========== dpCtl relies on DPC++ runtime. With Intel oneAPI installed you should activate it. From b79358ca2c38c33d41b28c00dc8df31fe327c5fb Mon Sep 17 00:00:00 2001 From: etotmeni Date: Thu, 12 Nov 2020 04:43:10 -0600 Subject: [PATCH 17/18] Small fixes --- CHANGELOG.md | 2 +- setup.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4d36a51a8..2ae3ac0b0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file. - Device descriptors "max_compute_units", "max_work_item_dimensions", "max_work_item_sizes", "max_work_group_size", "max_num_sub_groups" and "aspects" for int64 atomics inside dpctl C API and inside the dpctl.SyclDevice class. - MemoryUSM* classes moved to `dpctl.memory` module, added support for aligned allocation, added support for `prefetch` and `mem_advise` (sychronous) methods, implemented `copy_to_host`, `copy_from_host` and `copy_from_device` methods, pickling support, and zero-copy interoperability with Python objects which implement `__sycl_usm_array_inerface__` protocol. - Helper scripts to generate API documentation for both C API and Python. -- Opportunity to build and install project with setuptools. +- setup.py builds C++ backend for develop and install commands. ### Fixed - Compiler warnings when building libDPPLSyclInterface and the Cython extensions. diff --git a/setup.py b/setup.py index c677a98a40..f358b4ed43 100644 --- a/setup.py +++ b/setup.py @@ -27,8 +27,8 @@ import versioneer import subprocess -from setuptools.command.install import install as orig_install -from setuptools.command.develop import develop as orig_develop +import setuptools.command.install as orig_install +import setuptools.command.develop as orig_develop from setuptools import setup, Extension, find_packages from Cython.Build import cythonize @@ -183,13 +183,13 @@ def extensions(): return exts -class install(orig_install): +class install(orig_install.install): def run(self): build_backend() return super().run() -class develop(orig_develop): +class develop(orig_develop.develop): def run(self): build_backend() return super().run() From 776729c25887dfd6cdee1c14615dc0cc60956e62 Mon Sep 17 00:00:00 2001 From: etotmeni Date: Thu, 12 Nov 2020 04:47:04 -0600 Subject: [PATCH 18/18] Fix readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 662f7cefa4..8c5fcfa015 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ conda install dpctl ``` Build and Install with setuptools -=========== +================================= dpCtl relies on DPC++ runtime. With Intel oneAPI installed you should activate it. For install: