Skip to content

Improve coverage #818

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
Apr 20, 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
38 changes: 16 additions & 22 deletions .github/workflows/generate-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,7 @@ jobs:
shell: bash -l {0}
run: |
source /opt/intel/oneapi/setvars.sh
export _SAVED_PATH=${PATH}
export PATH=$(dirname $(dirname $(which icx)))/bin-llvm:${PATH}
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
pytest -q -ra --disable-warnings --cov-config pyproject.toml --cov dpctl \
--cov-report term-missing --pyargs dpctl -vv \
--ignore=dpctl/tensor/libtensor/tests
python scripts/gen_coverage.py

- name: Install coverall dependencies
shell: bash -l {0}
Expand All @@ -115,8 +96,21 @@ jobs:
- name: Upload coverage data to coveralls.io
shell: bash -l {0}
run: |
coveralls-lcov -v -n $(find _skbuild -name dpctl.lcov) > dpctl-c-api-coverage.json
coveralls --service=github --merge=dpctl-c-api-coverage.json
coveralls-lcov -v -n \
$(find _skbuild -name dpctl.lcov) > dpctl-c-api-coverage.json
coveralls-lcov -v -n \
$(find . -name dpctl_pytest.lcov) > pytest-dpctl-c-api-coverage.json
# merge json files
python -c "import json; \
fh1 = open('dpctl-c-api-coverage.json', 'r'); \
f1 = json.load(fh1); fh1.close(); \
fh2 = open('pytest-dpctl-c-api-coverage.json', 'r'); \
f2 = json.load(fh2); fh2.close(); \
f3 = {'source_files': f1['source_files'] + f2['source_files']}; \
fh3 = open('combined-dpctl-c-api-coverage.json', 'w'); \
json.dump(f3, fh3); fh3.close()" || exit 1
# merge combined file with coverage data and upload
coveralls --service=github --merge=combined-dpctl-c-api-coverage.json
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_PARALLEL: true
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/generate-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ jobs:
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_C_COMPILER:PATH=icx \
-DCMAKE_CXX_COMPILER:PATH=icpx \
-DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON \
-DDPCTL_GENERATE_DOCS=ON \
-DDPCTL_ENABLE_DOXYREST=ON \
-DDoxyrest_DIR=`pwd`/doxyrest-2.1.2-linux-amd64
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/os-llvm-sycl-build.yml
Original file line number Diff line number Diff line change
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 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 setup.py develop -- -G Ninja -DCMAKE_C_COMPILER:PATH=clang -DCMAKE_CXX_COMPILER:PATH=clang++
python -c "import dpctl; dpctl.lsplatform()" || exit 1
SYCL_ENABLE_HOST_DEVICE=1 python -m pytest -v dpctl/tests
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ project(dpctl
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# Option to generate code coverage report using llvm-cov and lcov.
option(DPCTL_GENERATE_COVERAGE
"Build dpctl with coverage instrumentation"
OFF
)

find_package(IntelDPCPP REQUIRED PATHS ${CMAKE_SOURCE_DIR}/cmake NO_DEFAULT_PATH)

add_subdirectory(libsyclinterface)
Expand Down
2 changes: 1 addition & 1 deletion conda-recipe/bld.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set "LIB=%BUILD_PREFIX%\Library\lib;%BUILD_PREFIX%\compiler\lib;%LIB%"
set "INCLUDE=%BUILD_PREFIX%\include;%INCLUDE%"

"%PYTHON%" setup.py clean --all
set "SKBUILD_ARGS=-- -G Ninja -DDPCTL_DPCPP_HOME_DIR=%BUILD_PREFIX%\Library -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icx -DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON"
set "SKBUILD_ARGS=-- -G Ninja -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icx"
set "SYCL_INCLUDE_DIR_HINT=%BUILD_PREFIX%\Library\lib\clang\14.0.0"

set "PLATFORM_DIR=%PREFIX%\Library\share\cmake-3.22\Modules\Platform"
Expand Down
2 changes: 1 addition & 1 deletion conda-recipe/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export LDFLAGS="$LDFLAGS -Wl,-rpath,$PREFIX/lib"

${PYTHON} setup.py clean --all
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}"
SKBUILD_ARGS="-- -DCMAKE_C_COMPILER:PATH=icx -DCMAKE_CXX_COMPILER:PATH=icpx"
echo "${PYTHON} setup.py install ${SKBUILD_ARGS}"

# Workaround for:
Expand Down
11 changes: 5 additions & 6 deletions docs/docfiles/user_guides/QuickStart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,21 @@ Once the prerequisites are installed, building using ``scikit-build`` involves t

.. code-block:: bash

python setup.py install -- -G Ninja -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

, and to develop:

.. code-block:: bash

python setup.py develop -G Ninja -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

On Windows, use ``icx`` for both C and CXX compilers.

Developing on Linux can also be done using driver script:

.. code-block:: bash

python scripts/build_locally.py --oneapi
python scripts/build_locally.py


Building using custom dpcpp
Expand All @@ -180,13 +180,13 @@ Following steps in `Build and install with scikit-build`_ use command line optio

.. code-block:: bash

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
python setup.py develop -- -G Ninja -DCMAKE_C_COMPILER:PATH=$(which clang) -DCMAKE_CXX_COMPILER:PATH=$(which clang++)

Alterantively, the driver script can be used

.. code-block:: bash

python scripts/build_locally.py --c-compiler=clang --cxx-compiler=clang++ --compiler-root=${DPCPP_ROOT}/llvm/build
python scripts/build_locally.py --c-compiler=$(which clang) --cxx-compiler=$(which clang++)

Available options and their descriptions can be retrieved using option
:code:`--help`.
Expand Down Expand Up @@ -264,7 +264,6 @@ library.
-DDPCPP_INSTALL_DIR=${DPCPP_ROOT} \
-DCMAKE_C_COMPILER:PATH=${DPCPP_ROOT}/bin/icx \
-DCMAKE_CXX_COMPILER:PATH=${DPCPP_ROOT}/bin/dpcpp \
-DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON \
-DDPCTL_BUILD_CAPI_TESTS=ON \
..

Expand Down
69 changes: 35 additions & 34 deletions libsyclinterface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,22 @@ project(

# Load our CMake modules to search for DPCPP and Level Zero
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/")

find_package(Git REQUIRED)

option(DPCTL_DPCPP_HOME_DIR
"The installation home for the DPC++ toolchain compiler."
OFF
)
option(DPCTL_DPCPP_FROM_ONEAPI
"Indicates whether DPCTL_DPCPP_HOME_DIR points to a oneAPI installation."
ON
)
if(NOT DEFINED IntelDPCPP_FOUND OR NOT IntelDPCPP_FOUND)
find_package(IntelDPCPP REQUIRED)
endif()

# Option to turn on support for creating Level Zero interoperability programs
# from a SPIR-V binary file.
option(DPCTL_ENABLE_LO_PROGRAM_CREATION
option(DPCTL_ENABLE_L0_PROGRAM_CREATION
"Enable Level Zero Program creation from SPIR-V"
OFF
ON
)
# Option to generate code coverage report using llvm-cov and lcov.
option(DPCTL_GENERATE_COVERAGE
"Build dpctl C API with coverage instrumentation instrumentation"
"Build dpctl C API with coverage instrumentation"
OFF
)
# Option to output html coverage report at a specific location.
Expand All @@ -45,14 +42,15 @@ option(DPCTL_ENABLE_GLOG
)

# Minimum version requirement only when oneAPI dpcpp is used.
find_package(IntelDPCPP REQUIRED)
if(DPCTL_DPCPP_FROM_ONEAPI)
find_package(IntelSycl 2021.3.0 REQUIRED)
else()
find_package(IntelSycl REQUIRED)
endif()

if(DPCTL_ENABLE_LO_PROGRAM_CREATION)
set(DPCTL_ENABLE_LO_PROGRAM_CREATION 1)
if(DPCTL_ENABLE_L0_PROGRAM_CREATION)
set(DPCTL_ENABLE_L0_PROGRAM_CREATION 1)
include(GetLevelZeroHeaders)
get_level_zero_headers()
if (UNIX)
Expand Down Expand Up @@ -156,20 +154,42 @@ file(GLOB_RECURSE helper_sources
${CMAKE_CURRENT_SOURCE_DIR}/helper/source/*.cpp
)

# Enable code coverage related settings
if(DPCTL_GENERATE_COVERAGE)
include(SetupCoverage)
setup_coverage_generation()

# 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})
else()
set(COVERAGE_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
endif()
message(STATUS "Coverage reports to be saved at ${COVERAGE_OUTPUT_DIR}")
endif()

add_library(DPCTLSyclInterface
SHARED
${sources}
${helper_sources}
)

if(DPCTL_GENERATE_COVERAGE)
target_link_options(DPCTLSyclInterface
PRIVATE -fprofile-instr-generate -fcoverage-mapping
)
endif()

target_include_directories(DPCTLSyclInterface
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include/
${CMAKE_CURRENT_SOURCE_DIR}/include/Support
${CMAKE_CURRENT_SOURCE_DIR}/include/Config
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/helper/include/
${IntelSycl_SYCL_INCLUDE_DIR}
${SYCL_INCLUDE_DIR}
)
target_link_libraries(DPCTLSyclInterface
PRIVATE ${IntelSycl_SYCL_LIBRARY}
Expand Down Expand Up @@ -201,7 +221,7 @@ set_target_properties(DPCTLSyclInterface
SOVERSION ${VERSION_MAJOR}
)

if(DPCTL_ENABLE_LO_PROGRAM_CREATION)
if(DPCTL_ENABLE_L0_PROGRAM_CREATION)
target_include_directories(DPCTLSyclInterface
PRIVATE
${LEVEL_ZERO_INCLUDE_DIR}
Expand Down Expand Up @@ -247,25 +267,6 @@ install(
DESTINATION ${_include_destination}/Config
)

# Enable code coverage related settings
if(DPCTL_GENERATE_COVERAGE)
# check if lcov is available
find_package(Lcov REQUIRED)
# check if llvm-cov version 11 is available
find_package(LLVMCov 11 REQUIRED)
# check if llvm-profdata is available
find_package(LLVMProfdata REQUIRED)
# 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})
else()
set(COVERAGE_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
endif()
message(STATUS "Coverage reports to be saved at ${COVERAGE_OUTPUT_DIR}")
endif()

# Add sub-directory to build the dpctl C API test cases
if(DPCTL_BUILD_CAPI_TESTS)
add_subdirectory(tests)
Expand Down
40 changes: 6 additions & 34 deletions libsyclinterface/cmake/modules/FindIntelSycl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,7 @@
# IntelSycl_OPENCL_LIBRARY

include(FindPackageHandleStandardArgs)

# Check if a specific DPC++ installation directory was provided then set
# IntelSycl_ROOT to that path.
if(DPCTL_DPCPP_HOME_DIR)
set(IntelSycl_ROOT ${DPCTL_DPCPP_HOME_DIR})
if(NOT DPCTL_DPCPP_FROM_ONEAPI)
message(STATUS
"Not using standard oneAPI installation, but IntelSycl at "
${IntelSycl_ROOT}
)
endif()
# If DPC++ installation was not specified, check for ONEAPI_ROOT
elseif(DEFINED ENV{ONEAPI_ROOT})
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(IntelSycl_ROOT $ENV{ONEAPI_ROOT}/compiler/latest/windows)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(IntelSycl_ROOT $ENV{ONEAPI_ROOT}/compiler/latest/linux)
else()
message(FATAL_ERROR "Unsupported system.")
endif()
else()
message(FATAL_ERROR
"Could not locate a DPC++ installation. Either pass the path to a "
"custom location using DPCTL_DPCPP_HOME_DIR or set the "
" ONEAPI_ROOT environment variable."
)
return()
endif()
find_package(IntelDPCPP REQUIRED)

# We will extract the version information from the compiler
set(clangxx_cmd "${CMAKE_CXX_COMPILER}")
Expand Down Expand Up @@ -96,13 +69,13 @@ if(${clangxx_result} MATCHES "0")
list(GET IntelSycl_VERSION_LIST1 0 IntelSycl_VERSION_MAJOR)
list(GET IntelSycl_VERSION_LIST1 1 IntelSycl_VERSION_MINOR)
list(GET IntelSycl_VERSION_LIST1 2 IntelSycl_VERSION_PATCH)
set(IntelSycl_INCLUDE_DIR ${IntelSycl_ROOT}/include)
set(IntelSycl_SYCL_INCLUDE_DIR ${IntelSycl_ROOT}/include/sycl)
set(IntelSycl_LIBRARY_DIR ${IntelSycl_ROOT}/lib)
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(IntelSycl_INCLUDE_DIR ${SYCL_INCLUDE_DIR})
set(IntelSycl_SYCL_INCLUDE_DIR ${SYCL_INCLUDE_DIR}/sycl)
set(IntelSycl_LIBRARY_DIR ${SYCL_LIBRARY_DIR})
if("x${CMAKE_SYSTEM_NAME}" STREQUAL "xWindows")
set(IntelSycl_SYCL_LIBRARY ${IntelSycl_LIBRARY_DIR}/sycl.lib)
set(IntelSycl_OPENCL_LIBRARY ${IntelSycl_LIBRARY_DIR}/OpenCL.lib)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
elseif("x${CMAKE_SYSTEM_NAME}" STREQUAL "xLinux")
set(IntelSycl_SYCL_LIBRARY ${IntelSycl_LIBRARY_DIR}/libsycl.so)
set(IntelSycl_OPENCL_LIBRARY ${IntelSycl_LIBRARY_DIR}/libOpenCL.so)
endif()
Expand All @@ -125,7 +98,6 @@ else()
endif()

find_package_handle_standard_args(IntelSycl DEFAULT_MSG
IntelSycl_ROOT
IntelSycl_FOUND
IntelSycl_VERSION
IntelSycl_INCLUDE_DIR
Expand Down
22 changes: 22 additions & 0 deletions libsyclinterface/cmake/modules/SetupCoverage.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

function(setup_coverage_generation)
# check if lcov is available
find_package(Lcov REQUIRED)
# check if llvm-cov version 11 is available
find_package(LLVMCov 11 REQUIRED)
# check if llvm-profdata is available
find_package(LLVMProfdata REQUIRED)

string(CONCAT PROFILE_FLAGS
"-fprofile-instr-generate "
"-fcoverage-mapping "
"-fno-sycl-use-footer "
"-DDPCTL_COVERAGE "
)

# Add profiling flags
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} ${PROFILE_FLAGS}"
PARENT_SCOPE
)
endfunction(setup_coverage_generation)
2 changes: 1 addition & 1 deletion libsyclinterface/dbg_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cmake \
-DCMAKE_CXX_COMPILER=dpcpp \
-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \
-DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} \
-DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON \
-DDPCTL_ENABLE_L0_PROGRAM_CREATION=ON \
-DDPCTL_BUILD_CAPI_TESTS=ON \
-DDPCTL_GENERATE_COVERAGE=ON \
..
Expand Down
2 changes: 1 addition & 1 deletion libsyclinterface/dbg_build_custom.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cmake \
-DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} \
-DDPCTL_CUSTOM_DPCPP_INSTALL_DIR=${DPCPP_HOME} \
-DCMAKE_LINKER:PATH=${DPCPP_HOME}/bin/lld \
-DDPCTL_ENABLE_LO_PROGRAM_CREATION=${USE_LO_HEADERS} \
-DDPCTL_ENABLE_L0_PROGRAM_CREATION=${USE_LO_HEADERS} \
-DDPCTL_BUILD_CAPI_TESTS=ON \
-DDPCTL_GENERATE_COVERAGE=ON \
..
Expand Down
2 changes: 1 addition & 1 deletion libsyclinterface/include/Config/dpctl_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#pragma once

/* Defined when dpctl was built with level zero program creation enabled. */
#cmakedefine DPCTL_ENABLE_LO_PROGRAM_CREATION @DPCTL_ENABLE_LO_PROGRAM_CREATION@
#cmakedefine DPCTL_ENABLE_L0_PROGRAM_CREATION @DPCTL_ENABLE_L0_PROGRAM_CREATION@

/* The DPCPP version used to build dpctl */
#define DPCTL_DPCPP_VERSION "@IntelSycl_VERSION@"
Expand Down
Loading