From 8bc5aa8e9974de226bcb94fa931c54b3d4cf00e2 Mon Sep 17 00:00:00 2001 From: Diptorup Deb Date: Mon, 18 Jan 2021 19:36:20 -0600 Subject: [PATCH 1/9] Cmake build script changes for dpCtl C API. -- Create cmake modules to store logic to search for dpcpp, level zero, llvm-cov, lcov. -- Add new Cmake options to control level zero program creation and code coverage reporting. -- Two new rules llvm-cov and lcov-genhtml to produce code coverage metrics. --- dpctl-capi/CMakeLists.txt | 138 +++++++++++-------- dpctl-capi/cmake/modules/FindDPCPP.cmake | 90 ++++++++++++ dpctl-capi/cmake/modules/FindLLVMCov.cmake | 34 +++++ dpctl-capi/cmake/modules/FindLcov.cmake | 33 +++++ dpctl-capi/cmake/modules/FindLevelZero.cmake | 34 +++++ dpctl-capi/dbg_build.sh | 20 +-- dpctl-capi/include/Config/.gitignore | 1 + dpctl-capi/include/Config/dpctl_config.h.in | 32 +++++ dpctl-capi/tests/CMakeLists.txt | 47 ++++++- scripts/build_backend.py | 2 +- 10 files changed, 358 insertions(+), 73 deletions(-) create mode 100644 dpctl-capi/cmake/modules/FindDPCPP.cmake create mode 100644 dpctl-capi/cmake/modules/FindLLVMCov.cmake create mode 100644 dpctl-capi/cmake/modules/FindLcov.cmake create mode 100644 dpctl-capi/cmake/modules/FindLevelZero.cmake create mode 100644 dpctl-capi/include/Config/.gitignore create mode 100644 dpctl-capi/include/Config/dpctl_config.h.in diff --git a/dpctl-capi/CMakeLists.txt b/dpctl-capi/CMakeLists.txt index b327f271c9..e09be2d630 100644 --- a/dpctl-capi/CMakeLists.txt +++ b/dpctl-capi/CMakeLists.txt @@ -1,45 +1,57 @@ cmake_minimum_required(VERSION 3.10 FATAL_ERROR) -project("dpCtl - A lightweight SYCL wrapper for Python") +project("dpCtl C API - A C wrapper for a subset of SYCL") -# The function checks is DPCPP_ROOT is valid and points to a dpcpp installation -function (check_for_dpcpp) - string(COMPARE EQUAL "${DPCPP_ROOT}" "" no_dpcpp_root) - if(${no_dpcpp_root}) - message(FATAL_ERROR "Set the DPCPP_ROOT argument providing the path to \ - a dpcpp installation.") - endif() +# Option to turn on support for creating Level Zero interoperability programs +# from a SPIR-V binary file. +option(DPCTL_ENABLE_LO_PROGRAM_CREATION + "Enable Level Zero Program creation from SPIR-V" + OFF +) +# Option to generate code coverage report using llvm-cov and lcov. +option(DPCTL_GENERATE_COVERAGE + "Build dpctl C API with coverage instrumentation instrumentation" + OFF +) +# Option to output html coverage report at a specific location. +option(DPCTL_COVERAGE_REPORT_OUTPUT_DIR + "Save the generated lcov html report to the specified location" + OFF +) +# Option to build the Gtests for dpctl C API +option(DPCTL_BUILD_CAPI_TESTS + "Build dpctl C API google tests" + OFF +) - if(WIN32) - set (dpcpp_cmd "${DPCPP_ROOT}/bin/dpcpp") - set (dpcpp_arg "--version") - elseif(UNIX) - set (dpcpp_cmd "${DPCPP_ROOT}/bin/dpcpp") - set (dpcpp_arg "--version") - else() - message(FATAL_ERROR "Unsupported system.") - endif() +# Load our CMake modules to search for DPCPP and Level Zero +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/") +find_package(DPCPP REQUIRED) - # Check if dpcpp is available - execute_process( - COMMAND ${dpcpp_cmd} ${dpcpp_arg} - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} - RESULT_VARIABLE dpcpp_result - OUTPUT_VARIABLE dpcpp_ver - ) +if(DPCTL_ENABLE_LO_PROGRAM_CREATION) + set(DPCTL_ENABLE_LO_PROGRAM_CREATION 1) + find_package(LevelZero REQUIRED) +endif() - if(${dpcpp_result} MATCHES "0") - string(REPLACE "\n" ";" DPCPP_VERSION_LIST "${dpcpp_ver}") - list(GET DPCPP_VERSION_LIST 0 dpcpp_ver_line) - foreach(X ${DPCPP_VERSION_LIST}) - message(STATUS "dpcpp ver[${dpcpp_result}]: ${X}") - endforeach() +# Add the profiling flags if code coverage is required +if(DPCTL_GENERATE_COVERAGE) + # check if llvm-cov and lcov are available + find_package(Lcov REQUIRED) + find_package(LLVMCov REQUIRED) + # Turn on DPCTL_BUILD_CAPI_TESTS + set(DPCTL_BUILD_CAPI_TESTS "ON") + # Add profiling flags + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping") + if(DPCTL_COVERAGE_REPORT_OUTPUT_DIR) + set(COVERAGE_OUTPUT_DIR ${DPCTL_COVERAGE_REPORT_OUTPUT_DIR}) + message(STATUS "Saving coverage report to ${COVERAGE_OUTPUT_DIR}") else() - message(FATAL_ERROR "DPCPP needed to build dpctl_sycl_interface") + set(COVERAGE_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}) + message(STATUS "Saving coverage report to ${COVERAGE_OUTPUT_DIR}") endif() -endfunction() +endif() -# Check for dpcpp in the specified DPCPP_ROOT -check_for_dpcpp() +configure_file(${CMAKE_SOURCE_DIR}/include/Config/dpctl_config.h.in + ${CMAKE_SOURCE_DIR}/include/Config/dpctl_config.h) if(WIN32) set(CMAKE_CXX_COMPILER:PATH "${DPCPP_ROOT}/bin/dpcpp") @@ -54,6 +66,9 @@ if(WIN32) set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG -Qstd=c++17") elseif(UNIX) + set(CMAKE_CXX_COMPILER:PATH "${DPCPP_ROOT}/bin/dpcpp") + set(CMAKE_C_COMPILER:PATH "${DPCPP_ROOT}/bin/clang") + set(CMAKE_LINKER:PATH "${DPCPP_ROOT}/bin/lld") 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") set(WARNING_FLAGS "-Wall -Wextra -Winit-self -Wunused-function -Wuninitialized -Wmissing-declarations -fdiagnostics-color=auto") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} ${SDL_FLAGS}") @@ -80,29 +95,38 @@ add_library( helper/source/dpctl_utils_helper.cpp ) -# Install DPCTLSyclInterface -target_include_directories( - DPCTLSyclInterface - PRIVATE - ${CMAKE_SOURCE_DIR}/include/ - ${CMAKE_SOURCE_DIR}/helper/include/ -) +if(DPCTL_BUILD_WITH_LEVEL_ZERO AND UNIX) + target_include_directories( + DPCTLSyclInterface + PRIVATE + ${CMAKE_SOURCE_DIR}/include/ + ${CMAKE_SOURCE_DIR}/helper/include/ + ${LEVEL_ZERO_INCLUDE_DIR} + ) +else() + target_include_directories( + DPCTLSyclInterface + PRIVATE + ${CMAKE_SOURCE_DIR}/include/ + ${CMAKE_SOURCE_DIR}/helper/include/ + ) +endif() if(WIN32) message( STATUS "SYCL_INCLUDE_DIR: " - ${DPCPP_ROOT}/include/sycl + ${DPCPP_SYCL_INCLUDE_DIR} ) target_include_directories( DPCTLSyclInterface PUBLIC - ${DPCPP_ROOT}/include/sycl + ${DPCPP_SYCL_INCLUDE_DIR} ) target_link_libraries( DPCTLSyclInterface - PRIVATE ${DPCPP_ROOT}/lib/sycl.lib - PRIVATE ${DPCPP_ROOT}/lib/OpenCL.lib + PRIVATE ${DPCPP_SYCL_LIBRARY} + PRIVATE ${DPCPP_OPENCL_LIBRARY} ) endif() @@ -114,34 +138,30 @@ install( ) # Install all headers -file(GLOB HEADERS "${CMAKE_SOURCE_DIR}/include/*.h*") +file(GLOB HEADERS "${CMAKE_SOURCE_DIR}/include/*.h") foreach(HEADER ${HEADERS}) install(FILES "${HEADER}" DESTINATION include) endforeach() # Install all headers in include/Support -file(GLOB HEADERS "${CMAKE_SOURCE_DIR}/include/Support/*.h*") +file(GLOB HEADERS "${CMAKE_SOURCE_DIR}/include/Support/*.h") foreach(HEADER ${HEADERS}) install(FILES "${HEADER}" DESTINATION include/Support) endforeach() # Install all headers in helper/include -file(GLOB HEADERS "${CMAKE_SOURCE_DIR}/helper/include/*.h*") +file(GLOB HEADERS "${CMAKE_SOURCE_DIR}/helper/include/*.h") foreach(HEADER ${HEADERS}) install(FILES "${HEADER}" DESTINATION helper/include) endforeach() -option( - BUILD_CAPI_TESTS - "Build dpctl C API google tests" - OFF -) +# Install all headers in include/Config +file(GLOB HEADERS "${CMAKE_SOURCE_DIR}/include/Config/*.h") +foreach(HEADER ${HEADERS}) + install(FILES "${HEADER}" DESTINATION include/Config) +endforeach() -# Enable to build the dpCtl backend test cases -if(BUILD_CAPI_TESTS) +# Enable to build the dpCtl C API test cases +if(DPCTL_BUILD_CAPI_TESTS) add_subdirectory(tests) endif() - - -# Todo : Add build rules for doxygen -# maybe refer https://devblogs.microsoft.com/cppblog/clear-functional-c-documentation-with-sphinx-breathe-doxygen-cmake/ diff --git a/dpctl-capi/cmake/modules/FindDPCPP.cmake b/dpctl-capi/cmake/modules/FindDPCPP.cmake new file mode 100644 index 0000000000..952510c73a --- /dev/null +++ b/dpctl-capi/cmake/modules/FindDPCPP.cmake @@ -0,0 +1,90 @@ +# Data Parallel Control Library (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. +# +# CMake find_package() module for the DPCPP compiler and development +# environment. +# +# Example usage: +# +# find_package(DPCPP) +# +# If successful, the following variables will be defined: +# DPCPP_FOUND +# DPCPP_VERSION +# DPCPP_INCLUDE_DIR +# DPCPP_SYCL_INCLUDE_DIR +# DPCPP_LIBRARY_DIR +# DPCPP_SYCL_LIBRARY +# DPCPP_OPENCL_LIBRARY + +include( FindPackageHandleStandardArgs ) + +string(COMPARE EQUAL "${DPCPP_INSTALL_DIR}" "" no_dpcpp_root) +if(${no_dpcpp_root}) + message(STATUS "Set the DPCPP_ROOT argument providing the path to \ + a dpcpp installation.") + return() +endif() + +if(WIN32 OR UNIX) + set(dpcpp_cmd "${DPCPP_INSTALL_DIR}/bin/dpcpp") + set(dpcpp_arg "--version") +else() + message(FATAL_ERROR "Unsupported system.") +endif() + +# Check if dpcpp is available +execute_process( + COMMAND ${dpcpp_cmd} ${dpcpp_arg} + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + RESULT_VARIABLE dpcpp_result + OUTPUT_VARIABLE dpcpp_ver +) + +# If dpcpp is found then set then set the package variables +if(${dpcpp_result} MATCHES "0") + string(REPLACE "\n" ";" DPCPP_VERSION_LIST "${dpcpp_ver}") + list(GET DPCPP_VERSION_LIST 0 dpcpp_ver_line) + foreach(X ${DPCPP_VERSION_LIST}) + message(STATUS "dpcpp ver[${dpcpp_result}]: ${X}") + endforeach() + + # set package-level variables + set(DPCPP_ROOT ${DPCPP_INSTALL_DIR}) + list(POP_FRONT DPCPP_VERSION_LIST DPCPP_VERSION) + set(DPCPP_INCLUDE_DIR ${DPCPP_INSTALL_DIR}/include) + set(DPCPP_SYCL_INCLUDE_DIR ${DPCPP_INSTALL_DIR}/include/sycl) + set(DPCPP_LIBRARY_DIR ${DPCPP_INSTALL_DIR}/lib) + if(WIN32) + set(DPCPP_SYCL_LIBRARY ${DPCPP_INSTALL_DIR}/lib/sycl.lib) + set(DPCPP_OPENCL_LIBRARY ${DPCPP_INSTALL_DIR}/lib/OpenCL.lib) + elseif(UNIX) + set(DPCPP_SYCL_LIBRARY ${DPCPP_INSTALL_DIR}/lib/libsycl.so) + set(DPCPP_OPENCL_LIBRARY ${DPCPP_INSTALL_DIR}/lib/libOpenCL.so) + endif() +else() + message(STATUS "DPCPP needed to build dpctl_sycl_interface") + return() +endif() + +find_package_handle_standard_args(DPCPP DEFAULT_MSG + DPCPP_VERSION + DPCPP_INCLUDE_DIR + DPCPP_SYCL_INCLUDE_DIR + DPCPP_LIBRARY_DIR + DPCPP_SYCL_LIBRARY + DPCPP_OPENCL_LIBRARY +) diff --git a/dpctl-capi/cmake/modules/FindLLVMCov.cmake b/dpctl-capi/cmake/modules/FindLLVMCov.cmake new file mode 100644 index 0000000000..4a568829d5 --- /dev/null +++ b/dpctl-capi/cmake/modules/FindLLVMCov.cmake @@ -0,0 +1,34 @@ +# Data Parallel Control Library (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. +# +# CMake find_package() module for llvm-cov. +# +# Example usage: +# +# find_package(LLVMCov) +# +# If successful, the following variables will be defined: +# LLVMCov_BIN - Path to llvm-cov +# LLVMProfdata_BIN - Path to llvm-profdata +# LLVMCov_FOUND + +find_program(LLVMCov_BIN llvm-cov) +find_program(LLVMProfdata_BIN llvm-profdata) + +find_package_handle_standard_args(LLVMCov DEFAULT_MSG + LLVMCov_BIN + LLVMProfdata_BIN +) diff --git a/dpctl-capi/cmake/modules/FindLcov.cmake b/dpctl-capi/cmake/modules/FindLcov.cmake new file mode 100644 index 0000000000..87e999cbf5 --- /dev/null +++ b/dpctl-capi/cmake/modules/FindLcov.cmake @@ -0,0 +1,33 @@ +# Data Parallel Control Library (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. +# +# CMake find_package() module for lcov. +# +# Example usage: +# +# find_package(Lcov) +# +# If successful, the following variables will be defined: +# LCOV_BIN - The path to lcov executable +# LCOV_FOUND + +find_program(LCOV_BIN lcov) +find_program(GENHTML_BIN genhtml) + +find_package_handle_standard_args(Lcov DEFAULT_MSG + LCOV_BIN + GENHTML_BIN +) diff --git a/dpctl-capi/cmake/modules/FindLevelZero.cmake b/dpctl-capi/cmake/modules/FindLevelZero.cmake new file mode 100644 index 0000000000..f58e9e7a2b --- /dev/null +++ b/dpctl-capi/cmake/modules/FindLevelZero.cmake @@ -0,0 +1,34 @@ +# Data Parallel Control Library (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. +# +# CMake find_package() module for the Level Zero loader library and headers. +# +# Example usage: +# +# find_package(LevelZero) +# +# If successful, the following variables will be defined: +# LEVEL_ZERO_INCLUDE_DIR +# LEVEL_ZERO_LIBRARY - the full path to the ze_loader library +# TODO: Add a way to record the version of the level_zero library + +find_library(LEVEL_ZERO_LIBRARY ze_loader) +find_path(LEVEL_ZERO_INCLUDE_DIR NAMES level_zero/zet_api.h) + +find_package_handle_standard_args(LevelZero DEFAULT_MSG + LEVEL_ZERO_INCLUDE_DIR + LEVEL_ZERO_LIBRARY +) diff --git a/dpctl-capi/dbg_build.sh b/dpctl-capi/dbg_build.sh index 953d9d275c..c35c615d17 100755 --- a/dpctl-capi/dbg_build.sh +++ b/dpctl-capi/dbg_build.sh @@ -9,17 +9,21 @@ rm -rf ${INSTALL_PREFIX} export ONEAPI_ROOT=/opt/intel/oneapi DPCPP_ROOT=${ONEAPI_ROOT}/compiler/latest/linux -cmake \ - -DCMAKE_BUILD_TYPE=Debug \ - -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 \ - -DBUILD_CAPI_TESTS=ON \ +cmake \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \ + -DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} \ + -DDPCPP_INSTALL_DIR=${DPCPP_ROOT} \ + -DCMAKE_C_COMPILER:PATH=${DPCPP_ROOT}/bin/clang \ + -DCMAKE_CXX_COMPILER:PATH=${DPCPP_ROOT}/bin/dpcpp \ + -DDPCTL_BUILD_CAPI_TESTS=ON \ + -DDPCTL_GENERATE_COVERAGE=ON \ .. make V=1 -n -j 4 && make check && make install +make llvm-cov +# Turn on to generate coverage report html files +# make genhtml # For more verbose tests use: # cd tests diff --git a/dpctl-capi/include/Config/.gitignore b/dpctl-capi/include/Config/.gitignore new file mode 100644 index 0000000000..ecaeb22660 --- /dev/null +++ b/dpctl-capi/include/Config/.gitignore @@ -0,0 +1 @@ +dpctl_config.h diff --git a/dpctl-capi/include/Config/dpctl_config.h.in b/dpctl-capi/include/Config/dpctl_config.h.in new file mode 100644 index 0000000000..e1e3442fda --- /dev/null +++ b/dpctl-capi/include/Config/dpctl_config.h.in @@ -0,0 +1,32 @@ +//===---- dpctl-capi/Config/dpCtl-config.h - dpctl-C API -------*- C++ -*-===// +// +// Data Parallel Control Library (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 exports a set of dpCtl C API configurations. +/// +//===----------------------------------------------------------------------===// + +#pragma once + +/* Defined when dpCtl was built with level zero program creation enabled. */ +#cmakedefine DPCTL_ENABLE_LO_PROGRAM_CREATION @DPCTL_ENABLE_LO_PROGRAM_CREATION@ + +/* The DPCPP version used to build dpCtl */ +#define DPCTL_DPCPP_VERSION "@DPCPP_VERSION@" diff --git a/dpctl-capi/tests/CMakeLists.txt b/dpctl-capi/tests/CMakeLists.txt index 8c599ce333..7254d52a6a 100644 --- a/dpctl-capi/tests/CMakeLists.txt +++ b/dpctl-capi/tests/CMakeLists.txt @@ -18,10 +18,47 @@ foreach(tf ${spirv-test-files}) file(COPY ${tf} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) endforeach() -file(GLOB_RECURSE sources ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) -add_executable(dpctl_c_api_tests EXCLUDE_FROM_ALL ${sources}) -target_link_libraries( - dpctl_c_api_tests ${CMAKE_THREAD_LIBS_INIT} GTest::GTest DPCTLSyclInterface -) +if(DPCTL_GENERATE_COVERAGE) + file(GLOB_RECURSE sources ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) + file(GLOB_RECURSE dpctl_sources ${CMAKE_CURRENT_SOURCE_DIR}/../source/*.cpp) + + # Add all dpctl sources into a single executable so that we can run coverage + # analysis and generate a report. + add_executable(dpctl_c_api_tests + EXCLUDE_FROM_ALL + ${sources} + ${dpctl_sources} + ) + target_link_libraries(dpctl_c_api_tests + ${CMAKE_THREAD_LIBS_INIT} + GTest::GTest + DPCTLSyclInterface + ${LEVEL_ZERO_LIBRARY} + ${DPCPP_OPENCL_LIBRARY} + ) + add_custom_target(llvm-cov + COMMAND ${CMAKE_MAKE_PROGRAM} dpctl_c_api_tests + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/dpctl_c_api_tests + COMMAND ${LLVMProfdata_BIN} merge -sparse default.profraw -o dpctl.profdata + COMMAND ${LLVMCov_BIN} report ${CMAKE_CURRENT_BINARY_DIR}/dpctl_c_api_tests -instr-profile=dpctl.profdata ${dpctl_sources} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + add_custom_target(genhtml + COMMAND ${CMAKE_MAKE_PROGRAM} llvm-cov + COMMAND ${LLVMCov_BIN} export -format=lcov ${CMAKE_CURRENT_BINARY_DIR}/dpctl_c_api_tests -instr-profile=dpctl.profdata ${dpctl_sources} > dpctl.lcov + COMMAND ${GENHTML_BIN} dpctl.lcov --output-directory ${COVERAGE_OUTPUT_DIR}/dpctl-c-api-coverage + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) +else() + file(GLOB_RECURSE sources ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) + add_executable(dpctl_c_api_tests EXCLUDE_FROM_ALL ${sources}) + target_link_libraries(dpctl_c_api_tests + ${CMAKE_THREAD_LIBS_INIT} + GTest::GTest + DPCTLSyclInterface + ${LEVEL_ZERO_LIBRARY} + ) +endif() + gtest_discover_tests(dpctl_c_api_tests) add_dependencies(check dpctl_c_api_tests) diff --git a/scripts/build_backend.py b/scripts/build_backend.py index ac61a52b98..cd68ab080c 100644 --- a/scripts/build_backend.py +++ b/scripts/build_backend.py @@ -40,7 +40,7 @@ "-DCMAKE_BUILD_TYPE=Release", "-DCMAKE_INSTALL_PREFIX=" + INSTALL_PREFIX, "-DCMAKE_PREFIX_PATH=" + INSTALL_PREFIX, - "-DDPCPP_ROOT=" + DPCPP_ROOT, + "-DDPCPP_INSTALL_DIR=" + 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, From 070e4159c7a6c41ff78f80ec77f12198df7e4762 Mon Sep 17 00:00:00 2001 From: Diptorup Deb Date: Mon, 18 Jan 2021 19:41:55 -0600 Subject: [PATCH 2/9] Rename genhtml to lcov-genhtml to be more intuitive. --- dpctl-capi/dbg_build.sh | 2 +- dpctl-capi/tests/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dpctl-capi/dbg_build.sh b/dpctl-capi/dbg_build.sh index c35c615d17..0a478630e0 100755 --- a/dpctl-capi/dbg_build.sh +++ b/dpctl-capi/dbg_build.sh @@ -23,7 +23,7 @@ cmake \ make V=1 -n -j 4 && make check && make install make llvm-cov # Turn on to generate coverage report html files -# make genhtml +# make lcov-genhtml # For more verbose tests use: # cd tests diff --git a/dpctl-capi/tests/CMakeLists.txt b/dpctl-capi/tests/CMakeLists.txt index 7254d52a6a..09eb8932f2 100644 --- a/dpctl-capi/tests/CMakeLists.txt +++ b/dpctl-capi/tests/CMakeLists.txt @@ -43,7 +43,7 @@ if(DPCTL_GENERATE_COVERAGE) COMMAND ${LLVMCov_BIN} report ${CMAKE_CURRENT_BINARY_DIR}/dpctl_c_api_tests -instr-profile=dpctl.profdata ${dpctl_sources} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) - add_custom_target(genhtml + add_custom_target(lcov-genhtml COMMAND ${CMAKE_MAKE_PROGRAM} llvm-cov COMMAND ${LLVMCov_BIN} export -format=lcov ${CMAKE_CURRENT_BINARY_DIR}/dpctl_c_api_tests -instr-profile=dpctl.profdata ${dpctl_sources} > dpctl.lcov COMMAND ${GENHTML_BIN} dpctl.lcov --output-directory ${COVERAGE_OUTPUT_DIR}/dpctl-c-api-coverage From 9961e2e74ff61107249f10d0d90f362df4c0c8bc Mon Sep 17 00:00:00 2001 From: Diptorup Deb Date: Mon, 18 Jan 2021 20:20:31 -0600 Subject: [PATCH 3/9] Fix error most probably causing Windows build failure. --- dpctl-capi/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpctl-capi/CMakeLists.txt b/dpctl-capi/CMakeLists.txt index e09be2d630..9604e313bc 100644 --- a/dpctl-capi/CMakeLists.txt +++ b/dpctl-capi/CMakeLists.txt @@ -103,7 +103,7 @@ if(DPCTL_BUILD_WITH_LEVEL_ZERO AND UNIX) ${CMAKE_SOURCE_DIR}/helper/include/ ${LEVEL_ZERO_INCLUDE_DIR} ) -else() +elseif(UNIX) target_include_directories( DPCTLSyclInterface PRIVATE From 217c2677420aff7d49c0cea10fd2c9be52039d20 Mon Sep 17 00:00:00 2001 From: Diptorup Deb Date: Mon, 18 Jan 2021 20:41:45 -0600 Subject: [PATCH 4/9] Fix variable name for windows as well. --- scripts/build_backend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build_backend.py b/scripts/build_backend.py index cd68ab080c..102d80130c 100644 --- a/scripts/build_backend.py +++ b/scripts/build_backend.py @@ -61,7 +61,7 @@ "-DCMAKE_BUILD_TYPE=Release", "-DCMAKE_INSTALL_PREFIX=" + INSTALL_PREFIX, "-DCMAKE_PREFIX_PATH=" + INSTALL_PREFIX, - "-DDPCPP_ROOT=" + DPCPP_ROOT, + "-DDPCPP_INSTALL_DIR=" + DPCPP_ROOT, backends, ] subprocess.check_call(cmake_args, stderr=subprocess.STDOUT, shell=True) From d0276b5bed07d03ee905f345c58d936e6812556e Mon Sep 17 00:00:00 2001 From: Diptorup Deb Date: Mon, 18 Jan 2021 21:16:06 -0600 Subject: [PATCH 5/9] Try again... --- dpctl-capi/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpctl-capi/CMakeLists.txt b/dpctl-capi/CMakeLists.txt index 9604e313bc..e09be2d630 100644 --- a/dpctl-capi/CMakeLists.txt +++ b/dpctl-capi/CMakeLists.txt @@ -103,7 +103,7 @@ if(DPCTL_BUILD_WITH_LEVEL_ZERO AND UNIX) ${CMAKE_SOURCE_DIR}/helper/include/ ${LEVEL_ZERO_INCLUDE_DIR} ) -elseif(UNIX) +else() target_include_directories( DPCTLSyclInterface PRIVATE From cf013e0f27f917929aab9a52e433f7979c09d67e Mon Sep 17 00:00:00 2001 From: Diptorup Deb Date: Mon, 18 Jan 2021 22:25:04 -0600 Subject: [PATCH 6/9] Profiling flags added only when fenerating coverage. FindLLVMCov is not needed. --- dpctl-capi/CMakeLists.txt | 38 +++++++++++----------- dpctl-capi/cmake/modules/FindDPCPP.cmake | 25 ++++++++++++++ dpctl-capi/cmake/modules/FindLLVMCov.cmake | 34 ------------------- dpctl-capi/tests/CMakeLists.txt | 9 +++-- 4 files changed, 50 insertions(+), 56 deletions(-) delete mode 100644 dpctl-capi/cmake/modules/FindLLVMCov.cmake diff --git a/dpctl-capi/CMakeLists.txt b/dpctl-capi/CMakeLists.txt index e09be2d630..c501d871df 100644 --- a/dpctl-capi/CMakeLists.txt +++ b/dpctl-capi/CMakeLists.txt @@ -32,24 +32,6 @@ if(DPCTL_ENABLE_LO_PROGRAM_CREATION) find_package(LevelZero REQUIRED) endif() -# Add the profiling flags if code coverage is required -if(DPCTL_GENERATE_COVERAGE) - # check if llvm-cov and lcov are available - find_package(Lcov REQUIRED) - find_package(LLVMCov REQUIRED) - # Turn on DPCTL_BUILD_CAPI_TESTS - set(DPCTL_BUILD_CAPI_TESTS "ON") - # Add profiling flags - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping") - if(DPCTL_COVERAGE_REPORT_OUTPUT_DIR) - set(COVERAGE_OUTPUT_DIR ${DPCTL_COVERAGE_REPORT_OUTPUT_DIR}) - message(STATUS "Saving coverage report to ${COVERAGE_OUTPUT_DIR}") - else() - set(COVERAGE_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}) - message(STATUS "Saving coverage report to ${COVERAGE_OUTPUT_DIR}") - endif() -endif() - configure_file(${CMAKE_SOURCE_DIR}/include/Config/dpctl_config.h.in ${CMAKE_SOURCE_DIR}/include/Config/dpctl_config.h) @@ -161,7 +143,25 @@ foreach(HEADER ${HEADERS}) install(FILES "${HEADER}" DESTINATION include/Config) endforeach() -# Enable to build the dpCtl C API test cases +# Add sub-directory to build the dpCtl C API test cases if(DPCTL_BUILD_CAPI_TESTS) add_subdirectory(tests) endif() + +# Enable code coverage related settings +if(DPCTL_GENERATE_COVERAGE) + # check if llvm-cov and lcov are available + find_package(Lcov REQUIRED) + if(NOT (${LLVM_COV_FOUND} AND ${LLVM_PROFDATA_FOUND})) + message(FATAL_ERROR "llvm-cov and llvm-profdata are needed to generate coverage.") + endif() + # Turn on DPCTL_BUILD_CAPI_TESTS + set(DPCTL_BUILD_CAPI_TESTS "ON") + if(DPCTL_COVERAGE_REPORT_OUTPUT_DIR) + set(COVERAGE_OUTPUT_DIR ${DPCTL_COVERAGE_REPORT_OUTPUT_DIR}) + message(STATUS "Saving coverage report to ${COVERAGE_OUTPUT_DIR}") + else() + set(COVERAGE_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}) + message(STATUS "Saving coverage report to ${COVERAGE_OUTPUT_DIR}") + endif() +endif() diff --git a/dpctl-capi/cmake/modules/FindDPCPP.cmake b/dpctl-capi/cmake/modules/FindDPCPP.cmake index 952510c73a..370dd965af 100644 --- a/dpctl-capi/cmake/modules/FindDPCPP.cmake +++ b/dpctl-capi/cmake/modules/FindDPCPP.cmake @@ -62,6 +62,31 @@ if(${dpcpp_result} MATCHES "0") message(STATUS "dpcpp ver[${dpcpp_result}]: ${X}") endforeach() + # check if llvm-cov and llvm-profdata are packaged as part of dpcpp + find_program(LLVM_COV_EXE + llvm-cov + PATHS ${DPCPP_INSTALL_DIR}/bin + NO_DEFAULT_PATH + ) + + if(LLVM_COV_EXE) + set(LLVM_COV_FOUND TRUE) + else() + set(LLVM_COV_FOUND FALSE) + endif() + + find_program(LLVM_PROFDATA_EXE + llvm-profdata + PATHS ${DPCPP_INSTALL_DIR}/bin + NO_DEFAULT_PATH + ) + + if(LLVM_PROFDATA_EXE) + set(LLVM_PROFDATA_FOUND TRUE) + else() + set(LLVM_PROFDATA_FOUND FALSE) + endif() + # set package-level variables set(DPCPP_ROOT ${DPCPP_INSTALL_DIR}) list(POP_FRONT DPCPP_VERSION_LIST DPCPP_VERSION) diff --git a/dpctl-capi/cmake/modules/FindLLVMCov.cmake b/dpctl-capi/cmake/modules/FindLLVMCov.cmake deleted file mode 100644 index 4a568829d5..0000000000 --- a/dpctl-capi/cmake/modules/FindLLVMCov.cmake +++ /dev/null @@ -1,34 +0,0 @@ -# Data Parallel Control Library (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. -# -# CMake find_package() module for llvm-cov. -# -# Example usage: -# -# find_package(LLVMCov) -# -# If successful, the following variables will be defined: -# LLVMCov_BIN - Path to llvm-cov -# LLVMProfdata_BIN - Path to llvm-profdata -# LLVMCov_FOUND - -find_program(LLVMCov_BIN llvm-cov) -find_program(LLVMProfdata_BIN llvm-profdata) - -find_package_handle_standard_args(LLVMCov DEFAULT_MSG - LLVMCov_BIN - LLVMProfdata_BIN -) diff --git a/dpctl-capi/tests/CMakeLists.txt b/dpctl-capi/tests/CMakeLists.txt index 09eb8932f2..f0fb9c832c 100644 --- a/dpctl-capi/tests/CMakeLists.txt +++ b/dpctl-capi/tests/CMakeLists.txt @@ -22,6 +22,9 @@ if(DPCTL_GENERATE_COVERAGE) file(GLOB_RECURSE sources ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) file(GLOB_RECURSE dpctl_sources ${CMAKE_CURRENT_SOURCE_DIR}/../source/*.cpp) + # Add profiling flags + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping") + # Add all dpctl sources into a single executable so that we can run coverage # analysis and generate a report. add_executable(dpctl_c_api_tests @@ -39,13 +42,13 @@ if(DPCTL_GENERATE_COVERAGE) add_custom_target(llvm-cov COMMAND ${CMAKE_MAKE_PROGRAM} dpctl_c_api_tests COMMAND ${CMAKE_CURRENT_BINARY_DIR}/dpctl_c_api_tests - COMMAND ${LLVMProfdata_BIN} merge -sparse default.profraw -o dpctl.profdata - COMMAND ${LLVMCov_BIN} report ${CMAKE_CURRENT_BINARY_DIR}/dpctl_c_api_tests -instr-profile=dpctl.profdata ${dpctl_sources} + COMMAND ${LLVM_PROFDATA_EXE} merge -sparse default.profraw -o dpctl.profdata + COMMAND ${LLVM_COV_EXE} report ${CMAKE_CURRENT_BINARY_DIR}/dpctl_c_api_tests -instr-profile=dpctl.profdata ${dpctl_sources} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) add_custom_target(lcov-genhtml COMMAND ${CMAKE_MAKE_PROGRAM} llvm-cov - COMMAND ${LLVMCov_BIN} export -format=lcov ${CMAKE_CURRENT_BINARY_DIR}/dpctl_c_api_tests -instr-profile=dpctl.profdata ${dpctl_sources} > dpctl.lcov + COMMAND ${LLVM_PROFDATA_EXE} export -format=lcov ${CMAKE_CURRENT_BINARY_DIR}/dpctl_c_api_tests -instr-profile=dpctl.profdata ${dpctl_sources} > dpctl.lcov COMMAND ${GENHTML_BIN} dpctl.lcov --output-directory ${COVERAGE_OUTPUT_DIR}/dpctl-c-api-coverage WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) From f5bb804663b7b3f9abefce621433d53e0008d01e Mon Sep 17 00:00:00 2001 From: Diptorup Deb Date: Mon, 18 Jan 2021 22:45:00 -0600 Subject: [PATCH 7/9] Enable verbose build inside setup.py. --- scripts/build_backend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build_backend.py b/scripts/build_backend.py index 102d80130c..2708094dd6 100644 --- a/scripts/build_backend.py +++ b/scripts/build_backend.py @@ -46,7 +46,7 @@ backends, ] subprocess.check_call(cmake_args, stderr=subprocess.STDOUT, shell=False) - subprocess.check_call(["make", "-j", "4"]) + subprocess.check_call(["make", "V=1", "-j", "4"]) subprocess.check_call(["make", "install"]) os.chdir(dpctl_dir) From cdab1ac94fc10a09f164150a381b94cc39116586 Mon Sep 17 00:00:00 2001 From: Diptorup Deb Date: Mon, 18 Jan 2021 22:58:41 -0600 Subject: [PATCH 8/9] Improve status message. --- dpctl-capi/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dpctl-capi/CMakeLists.txt b/dpctl-capi/CMakeLists.txt index c501d871df..9cb097d990 100644 --- a/dpctl-capi/CMakeLists.txt +++ b/dpctl-capi/CMakeLists.txt @@ -159,9 +159,9 @@ if(DPCTL_GENERATE_COVERAGE) set(DPCTL_BUILD_CAPI_TESTS "ON") if(DPCTL_COVERAGE_REPORT_OUTPUT_DIR) set(COVERAGE_OUTPUT_DIR ${DPCTL_COVERAGE_REPORT_OUTPUT_DIR}) - message(STATUS "Saving coverage report to ${COVERAGE_OUTPUT_DIR}") + message(STATUS "Coverage reports to be saved at ${COVERAGE_OUTPUT_DIR}") else() set(COVERAGE_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}) - message(STATUS "Saving coverage report to ${COVERAGE_OUTPUT_DIR}") + message(STATUS "Coverage reports to be saved at ${COVERAGE_OUTPUT_DIR}") endif() endif() From 5c00418808b85fd6ee8e205b4ff70c45382edb17 Mon Sep 17 00:00:00 2001 From: Diptorup Deb Date: Tue, 19 Jan 2021 14:48:27 -0600 Subject: [PATCH 9/9] Various small fixes. --- dpctl-capi/CMakeLists.txt | 75 ++++++++++++------------- dpctl-capi/cmake/modules/FindLcov.cmake | 10 ++-- dpctl-capi/dbg_build.sh | 4 +- dpctl-capi/tests/CMakeLists.txt | 4 +- scripts/build_for_develop.sh | 12 +++- 5 files changed, 55 insertions(+), 50 deletions(-) diff --git a/dpctl-capi/CMakeLists.txt b/dpctl-capi/CMakeLists.txt index 9cb097d990..16748f66cf 100644 --- a/dpctl-capi/CMakeLists.txt +++ b/dpctl-capi/CMakeLists.txt @@ -77,39 +77,32 @@ add_library( helper/source/dpctl_utils_helper.cpp ) -if(DPCTL_BUILD_WITH_LEVEL_ZERO AND UNIX) - target_include_directories( - DPCTLSyclInterface - PRIVATE - ${CMAKE_SOURCE_DIR}/include/ - ${CMAKE_SOURCE_DIR}/helper/include/ - ${LEVEL_ZERO_INCLUDE_DIR} - ) -else() - target_include_directories( - DPCTLSyclInterface - PRIVATE - ${CMAKE_SOURCE_DIR}/include/ - ${CMAKE_SOURCE_DIR}/helper/include/ - ) -endif() +target_include_directories(DPCTLSyclInterface + PRIVATE + ${CMAKE_SOURCE_DIR}/include/ + ${CMAKE_SOURCE_DIR}/helper/include/ + ${DPCPP_SYCL_INCLUDE_DIR} +) +target_link_libraries(DPCTLSyclInterface + PRIVATE ${DPCPP_SYCL_LIBRARY} + PRIVATE ${DPCPP_OPENCL_LIBRARY} +) -if(WIN32) - message( - STATUS - "SYCL_INCLUDE_DIR: " - ${DPCPP_SYCL_INCLUDE_DIR} - ) - target_include_directories( - DPCTLSyclInterface - PUBLIC - ${DPCPP_SYCL_INCLUDE_DIR} - ) - target_link_libraries( - DPCTLSyclInterface - PRIVATE ${DPCPP_SYCL_LIBRARY} - PRIVATE ${DPCPP_OPENCL_LIBRARY} - ) +if(DPCTL_ENABLE_LO_PROGRAM_CREATION) + if(UNIX) + target_include_directories(DPCTLSyclInterface + PRIVATE + ${LEVEL_ZERO_INCLUDE_DIR} + ) + target_link_libraries(DPCTLSyclInterface + PRIVATE ${LEVEL_ZERO_LIBRARY} + ) + else() + message(WARNING + "DPCTL support Level Zero program creation not supported " + "on this system." + ) + endif() endif() install( @@ -143,19 +136,18 @@ foreach(HEADER ${HEADERS}) install(FILES "${HEADER}" DESTINATION include/Config) endforeach() -# Add sub-directory to build the dpCtl C API test cases -if(DPCTL_BUILD_CAPI_TESTS) - add_subdirectory(tests) -endif() - # Enable code coverage related settings if(DPCTL_GENERATE_COVERAGE) # check if llvm-cov and lcov are available find_package(Lcov REQUIRED) + # These flags are set inside FindDPCPP if(NOT (${LLVM_COV_FOUND} AND ${LLVM_PROFDATA_FOUND})) - message(FATAL_ERROR "llvm-cov and llvm-profdata are needed to generate coverage.") + message(FATAL_ERROR + "llvm-cov and llvm-profdata are needed to generate coverage." + ) endif() - # Turn on DPCTL_BUILD_CAPI_TESTS + # Turn on DPCTL_BUILD_CAPI_TESTS as building tests is needed to generate + # coverage reports set(DPCTL_BUILD_CAPI_TESTS "ON") if(DPCTL_COVERAGE_REPORT_OUTPUT_DIR) set(COVERAGE_OUTPUT_DIR ${DPCTL_COVERAGE_REPORT_OUTPUT_DIR}) @@ -165,3 +157,8 @@ if(DPCTL_GENERATE_COVERAGE) message(STATUS "Coverage reports to be saved at ${COVERAGE_OUTPUT_DIR}") endif() endif() + +# Add sub-directory to build the dpCtl C API test cases +if(DPCTL_BUILD_CAPI_TESTS) + add_subdirectory(tests) +endif() diff --git a/dpctl-capi/cmake/modules/FindLcov.cmake b/dpctl-capi/cmake/modules/FindLcov.cmake index 87e999cbf5..43666b2618 100644 --- a/dpctl-capi/cmake/modules/FindLcov.cmake +++ b/dpctl-capi/cmake/modules/FindLcov.cmake @@ -21,13 +21,13 @@ # find_package(Lcov) # # If successful, the following variables will be defined: -# LCOV_BIN - The path to lcov executable +# LCOV_EXE- The path to lcov executable # LCOV_FOUND -find_program(LCOV_BIN lcov) -find_program(GENHTML_BIN genhtml) +find_program(LCOV_EXE lcov) +find_program(GENHTML_EXE genhtml) find_package_handle_standard_args(Lcov DEFAULT_MSG - LCOV_BIN - GENHTML_BIN + LCOV_EXE + GENHTML_EXE ) diff --git a/dpctl-capi/dbg_build.sh b/dpctl-capi/dbg_build.sh index 0a478630e0..60c8674a42 100755 --- a/dpctl-capi/dbg_build.sh +++ b/dpctl-capi/dbg_build.sh @@ -21,9 +21,9 @@ cmake \ .. make V=1 -n -j 4 && make check && make install -make llvm-cov + # Turn on to generate coverage report html files -# make lcov-genhtml +make lcov-genhtml # For more verbose tests use: # cd tests diff --git a/dpctl-capi/tests/CMakeLists.txt b/dpctl-capi/tests/CMakeLists.txt index f0fb9c832c..87dd681743 100644 --- a/dpctl-capi/tests/CMakeLists.txt +++ b/dpctl-capi/tests/CMakeLists.txt @@ -48,8 +48,8 @@ if(DPCTL_GENERATE_COVERAGE) ) add_custom_target(lcov-genhtml COMMAND ${CMAKE_MAKE_PROGRAM} llvm-cov - COMMAND ${LLVM_PROFDATA_EXE} export -format=lcov ${CMAKE_CURRENT_BINARY_DIR}/dpctl_c_api_tests -instr-profile=dpctl.profdata ${dpctl_sources} > dpctl.lcov - COMMAND ${GENHTML_BIN} dpctl.lcov --output-directory ${COVERAGE_OUTPUT_DIR}/dpctl-c-api-coverage + COMMAND ${LLVM_COV_EXE} export -format=lcov ${CMAKE_CURRENT_BINARY_DIR}/dpctl_c_api_tests -instr-profile=dpctl.profdata ${dpctl_sources} > dpctl.lcov + COMMAND ${GENHTML_EXE} ${CMAKE_CURRENT_BINARY_DIR}/dpctl.lcov --output-directory ${COVERAGE_OUTPUT_DIR}/dpctl-c-api-coverage WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) else() diff --git a/scripts/build_for_develop.sh b/scripts/build_for_develop.sh index 0154782c9c..bd10d01e25 100755 --- a/scripts/build_for_develop.sh +++ b/scripts/build_for_develop.sh @@ -14,14 +14,22 @@ cmake \ -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \ -DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} \ - -DDPCPP_ROOT=${DPCPP_ROOT} \ + -DDPCPP_INSTALL_DIR=${DPCPP_ROOT} \ -DCMAKE_C_COMPILER:PATH=${DPCPP_ROOT}/bin/clang \ -DCMAKE_CXX_COMPILER:PATH=${DPCPP_ROOT}/bin/dpcpp \ - -DBUILD_CAPI_TESTS=ON \ + -DDPCTL_BUILD_CAPI_TESTS=ON \ + -DDPCTL_GENERATE_COVERAGE=ON \ ../dpctl-capi make V=1 -n -j 4 && make check && make install +if [ $? -ne 0 ]; then + echo "Building of libDPCTLSyclInterface failed. Abort!" + exit 1 +fi + +# To run code coverage for dpctl-c API +make llvm-cov # For more verbose tests use: # cd tests # ctest -V --progress --output-on-failure -j 4