Skip to content

Cmake cleanup #766

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 10 commits into from
Feb 4, 2022
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
20 changes: 15 additions & 5 deletions .github/workflows/generate-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ jobs:
sudo apt-get install intel-oneapi-compiler-dpcpp-cpp
sudo apt-get install intel-oneapi-tbb

- name: Install CMake
- name: Install CMake and Ninja
run: |
sudo apt-get install cmake
sudo apt-get install cmake ninja-build

- name: Setup Python
uses: actions/setup-python@v2
Expand Down Expand Up @@ -87,8 +87,18 @@ jobs:
source /opt/intel/oneapi/setvars.sh
export _SAVED_PATH=${PATH}
export PATH=$(dirname $(dirname $(which icx)))/bin-llvm:${PATH}
python setup.py develop -- -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icpx -DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON -DDPCTL_GENERATE_COVERAGE=ON -DDPCTL_BUILD_CAPI_TESTS=ON -DDPCTL_COVERAGE_REPORT_OUTPUT_DIR=$(pwd)
make -C $(find _skbuild -name tests) lcov-genhtml
python setup.py develop -- \
-G "Ninja" \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_C_COMPILER:PATH=icx \
-DCMAKE_CXX_COMPILER:PATH=icpx \
-DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON \
-DDPCTL_GENERATE_COVERAGE=ON \
-DDPCTL_BUILD_CAPI_TESTS=ON \
-DDPCTL_COVERAGE_REPORT_OUTPUT_DIR=$(pwd)
pushd $(find _skbuild -name cmake-build)
cmake --build . --target lcov-genhtml || exit 1
popd
export PATH=${_SAVED_PATH}
unset _SAVED_PATH
python -c "import dpctl; print(dpctl.__version__); dpctl.lsplatform()" || exit 1
Expand All @@ -98,7 +108,7 @@ jobs:
shell: bash -l {0}
run: |
sudo gem install coveralls-lcov
pip install coveralls==3.2.0
pip install coveralls

- name: Upload coverage data to coveralls.io
shell: bash -l {0}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/generate-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ jobs:
if: ${{ !github.event.pull_request || github.event.action != 'closed' }}
run: |
sudo apt-get install doxygen
- name: Install CMake
- name: Install CMake and Ninja
if: ${{ !github.event.pull_request || github.event.action != 'closed' }}
run: |
sudo apt-get install cmake
sudo apt-get install cmake ninja-build
- name: Setup Python
if: ${{ !github.event.pull_request || github.event.action != 'closed' }}
uses: actions/setup-python@v2
Expand All @@ -64,7 +64,7 @@ jobs:
wget https://github.com/vovkos/doxyrest/releases/download/doxyrest-2.1.2/doxyrest-2.1.2-linux-amd64.tar.xz
tar xf doxyrest-2.1.2-linux-amd64.tar.xz
python setup.py develop -- \
-G "Unix Makefiles" \
-G "Ninja" \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_C_COMPILER:PATH=icx \
-DCMAKE_CXX_COMPILER:PATH=icpx \
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/os-llvm-sycl-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
- name: Install system components
shell: bash -l {0}
run: |
sudo apt-get install cmake libtinfo5
sudo apt-get install cmake ninja-build libtinfo5

- name: Setup Python
uses: actions/setup-python@v2
Expand Down Expand Up @@ -97,6 +97,6 @@ jobs:
export OCL_ICD_FILENAMES=libintelocl.so:libintelocl_emu.so
clang++ --version
sycl-ls
python setup.py develop -- -G "Unix Makefiles" -DCMAKE_C_COMPILER:PATH=clang -DCMAKE_CXX_COMPILER:PATH=clang++ -DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON -DDPCTL_DPCPP_HOME_DIR=$(dirname $(dirname $(which clang))) -DDPCTL_DPCPP_FROM_ONEAPI=OFF
python setup.py develop -- -G Ninja -DCMAKE_C_COMPILER:PATH=clang -DCMAKE_CXX_COMPILER:PATH=clang++ -DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON -DDPCTL_DPCPP_HOME_DIR=$(dirname $(dirname $(which clang))) -DDPCTL_DPCPP_FROM_ONEAPI=OFF
python -c "import dpctl; dpctl.lsplatform()" || exit 1
SYCL_ENABLE_HOST_DEVICE=1 python -m pytest -v dpctl/tests
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ add_subdirectory(libsyclinterface)
file(GLOB _dpctl_capi_headers dpctl/apis/include/*.h*)
install(FILES ${_dpctl_capi_headers}
DESTINATION dpctl/include
COMPONENT DpctlCAPIHeaders
)

add_subdirectory(dpctl)
Expand Down
2 changes: 1 addition & 1 deletion conda-recipe/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
export LDFLAGS="$LDFLAGS -Wl,-rpath,$PREFIX/lib"

${PYTHON} setup.py clean --all
export CMAKE_GENERATOR="Unix Makefiles"
export CMAKE_GENERATOR="Ninja"
SKBUILD_ARGS="-- -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icpx -DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON -DDPCTL_DPCPP_HOME_DIR=${BUILD_PREFIX}"
echo "${PYTHON} setup.py install ${SKBUILD_ARGS}"

Expand Down
3 changes: 1 addition & 2 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ requirements:
- cython
- cmake >=3.21
- python
- make # [unix]
- ninja # [win]
- ninja
- scikit-build
- numpy 1.19
- wheel
Expand Down
10 changes: 5 additions & 5 deletions docs/docfiles/user_guides/QuickStart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ installed:
- ``numpy``
- ``cmake``
- ``scikit-build``
- ``ninja`` (only on Windows)
- ``ninja``
- ``gtest`` (optional to run C API tests)
- ``gmock`` (optional to run C API tests)
- ``pytest`` (optional to run Python API tests)
Expand All @@ -152,15 +152,15 @@ Once the prerequisites are installed, building using ``scikit-build`` involves t

.. code-block:: bash

python setup.py install -- -G Unix\ Makefiles -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icpx -DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON
python setup.py install -- -G Ninja -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icpx -DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON

, and to develop:

.. code-block:: bash

python setup.py develop -G Unix\ Makefiles -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icpx -DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON
python setup.py develop -G Ninja -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icpx -DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON

On Windows, use ``icx`` for both C and CXX compilers, and use :code:`-G Ninja` for cmake generator.
On Windows, use ``icx`` for both C and CXX compilers.

Developing on Linux can also be done using driver script:

Expand All @@ -180,7 +180,7 @@ Following steps in `Build and install with scikit-build`_ use command line optio

.. code-block:: bash

python setup.py develop -- -G Unix\ Makefiles -DCMAKE_C_COMPILER:PATH=clang -DCMAKE_CXX_COMPILER:PATH=clang++ -DDPCTL_ENABLE_LO_PROGRAM_CREATION=ONE -DDPCTL_DPCPP_HOME_DIR=${DPCPP_ROOT}/llvm/build -DDPCTL_DPCPP_FROM_ONEAPI=OFF
python setup.py develop -- -G Ninja -DCMAKE_C_COMPILER:PATH=clang -DCMAKE_CXX_COMPILER:PATH=clang++ -DDPCTL_ENABLE_LO_PROGRAM_CREATION=ONE -DDPCTL_DPCPP_HOME_DIR=${DPCPP_ROOT}/llvm/build -DDPCTL_DPCPP_FROM_ONEAPI=OFF

Alterantively, the driver script can be used

Expand Down
51 changes: 37 additions & 14 deletions dpctl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
find_package(PythonExtensions REQUIRED)
find_package(NumPy REQUIRED)

set(CYTHON_FLAGS "-w ${CMAKE_SOURCE_DIR}")
set(CYTHON_FLAGS "-t -w ${CMAKE_SOURCE_DIR}")
find_package(Cython REQUIRED)

if(WIN32)
Expand Down Expand Up @@ -78,41 +78,64 @@ add_custom_target(_build_time_create_dpctl_include ALL
DEPENDS DPCTLSyclInterface
)

set(_copied_header_files)
file(GLOB _syclinterface_h ${CMAKE_SOURCE_DIR}/libsyclinterface/include/*.h)
foreach(hf ${_syclinterface_h})
add_custom_command(TARGET _build_time_create_dpctl_include
COMMAND ${CMAKE_COMMAND} -E copy ${hf} ${DPCTL_INCLUDE_DIR}/syclinterface
)
get_filename_component(_header_name ${hf} NAME)
set(_target_header_file ${DPCTL_INCLUDE_DIR}/syclinterface/${_header_name})
list(APPEND _copied_header_files ${_target_header_file})
add_custom_command(OUTPUT ${_target_header_file}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${hf} ${_target_header_file}
DEPENDS ${hf} _build_time_create_dpctl_include
VERBATIM
)
endforeach()

file(GLOB _syclinterface_Support_h ${CMAKE_SOURCE_DIR}/libsyclinterface/include/Support/*.h)
foreach(hf ${_syclinterface_Support_h})
add_custom_command(TARGET _build_time_create_dpctl_include
COMMAND ${CMAKE_COMMAND} -E copy ${hf} ${DPCTL_INCLUDE_DIR}/syclinterface/Support
)
get_filename_component(_header_name ${hf} NAME)
set(_target_header_file ${DPCTL_INCLUDE_DIR}/syclinterface/Support/${_header_name})
list(APPEND _copied_header_files ${_target_header_file})
add_custom_command(OUTPUT ${_target_header_file}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${hf} ${_target_header_file}
DEPENDS ${hf} _build_time_create_dpctl_include
)
endforeach()

file(GLOB _syclinterface_Config_h ${CMAKE_SOURCE_DIR}/libsyclinterface/include/Config/*.h)
foreach(hf ${_syclinterface_Config_h})
add_custom_command(TARGET _build_time_create_dpctl_include
COMMAND ${CMAKE_COMMAND} -E copy ${hf} ${DPCTL_INCLUDE_DIR}/syclinterface/Config
)
get_filename_component(_header_name ${hf} NAME)
set(_target_header_file ${DPCTL_INCLUDE_DIR}/syclinterface/Config/${_header_name})
list(APPEND _copied_header_files ${_target_header_file})
add_custom_command(OUTPUT ${_target_header_file}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${hf} ${_target_header_file}
DEPENDS ${hf} _build_time_create_dpctl_include
)
endforeach()

file(GLOB _apis_h ${CMAKE_CURRENT_SOURCE_DIR}/apis/include/*)
foreach(hf ${_apis_h})
add_custom_command(TARGET _build_time_create_dpctl_include
COMMAND ${CMAKE_COMMAND} -E copy ${hf} ${DPCTL_INCLUDE_DIR}
)
get_filename_component(_header_name ${hf} NAME)
set(_target_header_file ${DPCTL_INCLUDE_DIR}/${_header_name})
list(APPEND _copied_header_files ${_target_header_file})
add_custom_command(OUTPUT ${_target_header_file}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${hf} ${_target_header_file}
DEPENDS ${hf} _build_time_create_dpctl_include
)
endforeach()

add_custom_target(
_build_time_create_dpctl_include_copy ALL
DEPENDS ${_copied_header_files}
)

set(CMAKE_INSTALL_RPATH "$ORIGIN")

function(build_dpctl_ext _trgt _src _dest)
add_cython_target(${_trgt} ${_src} CXX OUTPUT_VAR _generated_src)
add_library(${_trgt} MODULE ${_generated_src})
target_include_directories(${_trgt} PRIVATE ${NumPy_INCLUDE_DIR} ${DPCTL_INCLUDE_DIR})
add_dependencies(${_trgt} _build_time_create_dpctl_include)
add_dependencies(${_trgt} _build_time_create_dpctl_include_copy)
if (DPCTL_GENERATE_COVERAGE)
target_compile_definitions(${_trgt} PRIVATE CYTHON_TRACE=1 CYTHON_TRACE_NOGIL=1)
target_compile_options(${_trgt} PRIVATE -fno-sycl-use-footer)
Expand Down
8 changes: 5 additions & 3 deletions libsyclinterface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,13 @@ file(GLOB MAIN_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
file(GLOB SUPPORT_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/Support/*.h")
file(GLOB CONFIG_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/Config/*.h")

set(ALL_HEADERS "${MAIN_HEADERS}")
list(APPEND ALL_HEADERS "${SUPPORT_HEADERS}")
list(APPEND ALL_HEADERS "${CONFIG_HEADERS}")

set_target_properties(DPCTLSyclInterface
PROPERTIES PUBLIC_HEADER
"${MAIN_HEADERS}"
"${ALL_HEADERS}"
)

if (SKBUILD)
Expand All @@ -241,12 +245,10 @@ install(TARGETS
install(
FILES ${SUPPORT_HEADERS}
DESTINATION ${_include_destination}/Support
COMPONENT SupportHeaders
)
install(
FILES ${CONFIG_HEADERS}
DESTINATION ${_include_destination}/Config
COMPONENT ConfigHeaders
)

# Enable code coverage related settings
Expand Down
4 changes: 2 additions & 2 deletions libsyclinterface/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ if(DPCTL_GENERATE_COVERAGE)
${CMAKE_DL_LIBS}
)
add_custom_target(llvm-cov
COMMAND ${CMAKE_MAKE_PROGRAM} dpctl_c_api_tests
COMMAND ${CMAKE_COMMAND} -E env DPCTL_VERBOSITY=warning ${CMAKE_CURRENT_BINARY_DIR}/dpctl_c_api_tests
COMMAND ${LLVMProfdata_EXE}
merge
Expand All @@ -75,10 +74,10 @@ if(DPCTL_GENERATE_COVERAGE)
${dpctl_sources}
${helper_sources}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS dpctl_c_api_tests
)

add_custom_target(lcov-genhtml
COMMAND ${CMAKE_MAKE_PROGRAM} llvm-cov
COMMAND ${LLVMCov_EXE}
export
-format=lcov
Expand All @@ -91,6 +90,7 @@ if(DPCTL_GENERATE_COVERAGE)
--output-directory
${COVERAGE_OUTPUT_DIR}/dpctl-c-api-coverage
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS llvm-cov
)
else()
file(GLOB_RECURSE sources ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_locally.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def run(
build_system = None

if "linux" in sys.platform:
build_system = "Unix Makefiles"
build_system = "Ninja"
elif sys.platform in ["win32", "cygwin"]:
build_system = "Ninja"
else:
Expand Down
19 changes: 15 additions & 4 deletions scripts/gen_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def run(
compiler_root=None,
run_pytest=False,
bin_llvm=None,
gtest_config=None,
):
IS_LIN = False

Expand All @@ -48,7 +49,7 @@ def run(
"develop",
"--",
"-G",
"Unix Makefiles",
"Ninja",
"-DCMAKE_BUILD_TYPE=Debug",
"-DCMAKE_C_COMPILER:PATH=" + c_compiler,
"-DCMAKE_CXX_COMPILER:PATH=" + cxx_compiler,
Expand All @@ -66,18 +67,22 @@ def run(
if bin_llvm:
env = {
"PATH": ":".join((os.environ.get("PATH", ""), bin_llvm)),
"LLVM_TOOLS_HOME": bin_llvm,
}
env.update({k: v for k, v in os.environ.items() if k != "PATH"})
if gtest_config:
cmake_args += ["-DCMAKE_PREFIX_PATH=" + gtest_config]
subprocess.check_call(cmake_args, shell=False, cwd=setup_dir, env=env)
test_dir = (
cmake_build_dir = (
subprocess.check_output(
["find", "_skbuild", "-name", "tests"], cwd=setup_dir
["find", "_skbuild", "-name", "cmake-build"], cwd=setup_dir
)
.decode("utf-8")
.strip("\n")
)
subprocess.check_call(
["make", "-C", test_dir, "lcov-genhtml"], cwd=setup_dir
["cmake", "--build", ".", "--target", "lcov-genhtml"],
cwd=cmake_build_dir,
)
subprocess.check_call(
[
Expand Down Expand Up @@ -135,6 +140,11 @@ def run(
driver.add_argument(
"--bin-llvm", help="Path to folder where llvm-cov can be found"
)
driver.add_argument(
"--gtest-config",
help="Path to the GTestConfig.cmake file to locate a "
+ "custom GTest installation.",
)
args = parser.parse_args()

if args.oneapi:
Expand Down Expand Up @@ -170,4 +180,5 @@ def run(
compiler_root=args.compiler_root,
run_pytest=args.run_pytest,
bin_llvm=args.bin_llvm,
gtest_config=args.gtest_config,
)
2 changes: 1 addition & 1 deletion scripts/gen_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def run(
"develop",
"--",
"-G",
"Unix Makefiles",
"Ninja",
"-DCMAKE_BUILD_TYPE=Debug",
"-DCMAKE_C_COMPILER:PATH=" + c_compiler,
"-DCMAKE_CXX_COMPILER:PATH=" + cxx_compiler,
Expand Down