Skip to content
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

[CI, enhancement] Add ability to build with gcov, adding C++ code coverage for the onedal folder in codecov #2249

Merged
merged 74 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
2899fb3
Update ci.yml
icfaust Jan 9, 2025
1b2302b
Update ci.yml
icfaust Jan 9, 2025
ec3953e
Update ci.yml
icfaust Jan 9, 2025
3563133
Update ci.yml
icfaust Jan 9, 2025
ad933e2
Update ci.yml
icfaust Jan 9, 2025
6f0ed12
force use of coverage to start
icfaust Jan 10, 2025
8915d24
try again
icfaust Jan 10, 2025
cd4f95e
attempt again
icfaust Jan 10, 2025
765fa20
add -Xarch_host
icfaust Jan 10, 2025
e5ca42d
further checking
icfaust Jan 10, 2025
ca44fb7
make verbose
icfaust Jan 10, 2025
adfa455
attempts at integration
icfaust Jan 10, 2025
228f6e3
add echos for testing
icfaust Jan 10, 2025
9a6a704
move installation
icfaust Jan 10, 2025
b22c8a9
ignore error induced by numpy switch
icfaust Jan 10, 2025
f1a2299
Update generate_coverage_reports.sh
icfaust Jan 10, 2025
7db1eb5
Update generate_coverage_reports.sh
icfaust Jan 10, 2025
6bbba03
Update generate_coverage_reports.sh
icfaust Jan 10, 2025
65c4cf2
Update generate_coverage_reports.sh
icfaust Jan 10, 2025
3878f8b
Update ci.yml
icfaust Jan 11, 2025
84bd99d
Update ci.yml
icfaust Jan 11, 2025
b301863
Update ci.yml
icfaust Jan 11, 2025
df19a3f
Update generate_coverage_reports.sh
icfaust Jan 11, 2025
de9d701
Update ci.yml
icfaust Jan 11, 2025
c2a6f12
Update generate_coverage_reports.sh
icfaust Jan 11, 2025
5b5caa0
Update generate_coverage_reports.sh
icfaust Jan 11, 2025
10c1ad8
Update ci.yml
icfaust Jan 11, 2025
613a6bf
Update run_test.bat
icfaust Jan 11, 2025
c75446a
Update run_test.sh
icfaust Jan 11, 2025
a2309a4
Merge branch 'uxlfoundation:main' into dev/c_plus_plus_coverage
icfaust Jan 11, 2025
036af4d
Update ci.yml
icfaust Jan 12, 2025
12b0480
Update ci.yml
icfaust Jan 12, 2025
45b597b
Update generate_coverage_reports.sh
icfaust Jan 12, 2025
a3f3324
Update ci.yml
icfaust Jan 12, 2025
0cbf97e
Update ci.yml
icfaust Jan 12, 2025
d0dfa5c
Update generate_coverage_reports.sh
icfaust Jan 12, 2025
2b4e8c4
Update ci.yml
icfaust Jan 12, 2025
3a41467
Update generate_coverage_reports.sh
icfaust Jan 12, 2025
60d1ff8
Update generate_coverage_reports.sh
icfaust Jan 12, 2025
79307eb
Update generate_coverage_reports.sh
icfaust Jan 12, 2025
fe7a927
Update run_sklearn_tests.py
icfaust Jan 12, 2025
b02aac9
Update generate_coverage_reports.sh
icfaust Jan 12, 2025
5e45731
Update ci.yml
icfaust Jan 12, 2025
a70a290
Update generate_coverage_reports.sh
icfaust Jan 12, 2025
3e2c671
Update build_backend.py
icfaust Jan 12, 2025
6d7d841
Update CMakeLists.txt
icfaust Jan 12, 2025
462196b
Update generate_coverage_reports.sh
icfaust Jan 12, 2025
806ec60
Update CMakeLists.txt
icfaust Jan 12, 2025
b4a9a33
Update ci.yml
icfaust Jan 12, 2025
945e802
Update generate_coverage_reports.sh
icfaust Jan 12, 2025
7924ef9
Update ci.yml
icfaust Jan 12, 2025
3374015
Update CMakeLists.txt
icfaust Jan 12, 2025
82608c1
Update ci.yml
icfaust Jan 12, 2025
1bf7677
Update ci.yml
icfaust Jan 12, 2025
52b0200
Update ci.yml
icfaust Jan 12, 2025
d0b8a74
Update generate_coverage_reports.sh
icfaust Jan 12, 2025
436e306
Update generate_coverage_reports.sh
icfaust Jan 12, 2025
9cba3b1
Update CMakeLists.txt
icfaust Jan 12, 2025
d20dc6f
Update CMakeLists.txt
icfaust Jan 12, 2025
9bc5eb4
Update CMakeLists.txt
icfaust Jan 12, 2025
ac5c25a
Update CMakeLists.txt
icfaust Jan 12, 2025
d725fbf
Update CMakeLists.txt
icfaust Jan 12, 2025
58774c4
Update build_backend.py
icfaust Jan 13, 2025
dbf8114
Update CMakeLists.txt
icfaust Jan 13, 2025
862141b
Update ci.yml
icfaust Jan 13, 2025
b772d97
Update generate_coverage_reports.sh
icfaust Jan 13, 2025
a737345
Update build_backend.py
icfaust Jan 13, 2025
728b83e
Update CMakeLists.txt
icfaust Jan 13, 2025
d1e55b1
Update ci.yml
icfaust Jan 13, 2025
0290055
Update CMakeLists.txt
icfaust Jan 13, 2025
e5ecf2a
Update CMakeLists.txt
icfaust Jan 13, 2025
ea702e4
Merge branch 'uxlfoundation:main' into dev/c_plus_plus_coverage
icfaust Jan 13, 2025
9b73ea6
switch azure to lcov
icfaust Jan 13, 2025
d085abe
Update .github/scripts/generate_coverage_reports.sh
icfaust Jan 13, 2025
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
4 changes: 2 additions & 2 deletions .ci/pipeline/codecov-lnx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ steps:
. /usr/share/miniconda/etc/profile.d/conda.sh
conda activate CB
coverage combine .coverage.sklearnex .coverage.sklearn
coverage json -o coverage.json
coverage lcov -o coverage.info
displayName: "Create coverage report"
- script: |
curl -Os https://cli.codecov.io/latest/linux/codecov
chmod +x codecov
export VARARGS="-n azure-${AGENT_OS}-$(PYTHON_VERSION)-$(SKLEARN_VERSION)"
./codecov -v upload-process -Z -t ${CODECOV_TOKEN} "${VARARGS}" -F azure -f coverage.json
./codecov -v upload-process -Z -t ${CODECOV_TOKEN} "${VARARGS}" -F azure -f coverage.info
displayName: "Upload to codecov"
env:
CODECOV_TOKEN: $(CODECOV_TOKEN)
4 changes: 2 additions & 2 deletions .ci/pipeline/codecov-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ steps:
- script: |
call activate CB
coverage combine .coverage.sklearnex .coverage.sklearn
coverage json -o coverage.json
coverage lcov -o coverage.info
displayName: "Create coverage report"
- script: |
set PATH=C:\msys64\usr\bin;%PATH%
curl -Os https://cli.codecov.io/latest/windows/codecov.exe
set VARARGS=-n azure-%AGENT_OS%-$(PYTHON_VERSION)-$(SKLEARN_VERSION)
.\codecov.exe -v upload-process -Z -t %CODECOV_TOKEN% %VARARGS% -F azure -f coverage.json
.\codecov.exe -v upload-process -Z -t %CODECOV_TOKEN% %VARARGS% -F azure -f coverage.info
displayName: "Upload to codecov"
env:
CODECOV_TOKEN: $(CODECOV_TOKEN)
1 change: 1 addition & 0 deletions .ci/scripts/run_sklearn_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
pytest_args += (
"--cov=onedal",
"--cov=sklearnex",
"--cov-branch",
f"--cov-config={rc}",
"--cov-report=",
)
Expand Down
46 changes: 46 additions & 0 deletions .github/scripts/generate_coverage_reports.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#===============================================================================
# Copyright Contributors to the oneDAL project
#
# 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.
#===============================================================================

ci_dir=$(dirname $(dirname $(dirname "${BASH_SOURCE[0]}")))
cd $ci_dir

# create coverage.py report
coverage combine .coverage.sklearnex .coverage.sklearn
coverage lcov -o coverage_py_"${1}".info

# create gcov report (lcov format)
if [[ -n "${SKLEARNEX_GCOV}" ]]; then
# extract llvm tool for gcov processing
if [[ -z "$2" ]]; then
GCOV_EXE="$(dirname $(type -P -a icx))/compiler/llvm-cov gcov"
else
GCOV_EXE="gcov"
fi
echo $GCOV_EXE
FILTER=$(realpath ./onedal).*
echo $FILTER

NUMPY_TEST=$(python -m pip freeze | grep numpy)
# install dependencies
# proper operation of gcov with sklearnex requires the header files from
# the build numpy, this must be previously set as NUMPY_BUILD
python -m pip install gcovr $NUMPY_BUILD

gcovr --gcov-executable "${GCOV_EXE}" -r . -v --lcov --filter "${FILTER}" -o coverage_cpp_"${1}".info

# reinstall previous numpy
python -m pip install $NUMPY_TEST
fi
24 changes: 17 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ jobs:
echo "DPCFLAG=${DPCFLAG}" >> "$GITHUB_OUTPUT"
# enable coverage report generation
echo "COVERAGE_RCFILE=$(readlink -f .coveragerc)" >> "$GITHUB_ENV"
if [[ -z $DPCFLAG ]]; then echo "SKLEARNEX_GCOV=1" >> "$GITHUB_ENV"; fi
- name: apt-get
run: sudo apt-get update && sudo apt-get install -y clang-format
- name: dpcpp installation
Expand All @@ -111,6 +112,7 @@ jobs:
source venv/bin/activate
pip install -r dependencies-dev
pip list
echo "NUMPY_BUILD=$(python -m pip freeze | grep numpy)" >> "$GITHUB_ENV"
- name: Build daal4py/sklearnex
run: |
source venv/bin/activate
Expand Down Expand Up @@ -142,13 +144,14 @@ jobs:
- name: Create coverage report
run: |
source venv/bin/activate
coverage combine .coverage.sklearnex .coverage.sklearn
coverage json -o coverage.lnx${{ matrix.PYTHON_VERSION }}_${{ matrix.SKLEARN_VERSION }}.json
source .github/scripts/activate_components.sh ${{ steps.set-env.outputs.DPCFLAG }}
bash .github/scripts/generate_coverage_reports.sh lnx${{ matrix.PYTHON_VERSION }}_${{ matrix.SKLEARN_VERSION }} ${{ steps.set-env.outputs.DPCFLAG }}
- name: Archive coverage report
uses: actions/upload-artifact@v4
with:
name: coverage_lnx_Py${{ matrix.PYTHON_VERSION }}_${{ matrix.SKLEARN_VERSION }}
path: coverage.lnx${{ matrix.PYTHON_VERSION }}_${{ matrix.SKLEARN_VERSION }}.json
path: |
*_lnx${{ matrix.PYTHON_VERSION }}_${{ matrix.SKLEARN_VERSION }}.info
- name: Sklearn testing [preview]
run: |
source venv/bin/activate
Expand Down Expand Up @@ -218,7 +221,12 @@ jobs:
echo C:\msys64\usr\bin;>> %GITHUB_PATH%
echo NO_DIST=YES>> %GITHUB_ENV%
set DPCTL_TEMP="${{ env.DPCTL_PY_VERSIONS }}"
if not %DPCTL_TEMP:${{ matrix.PYTHON_VERSION }}=%==%DPCTL_TEMP% (echo DPCFLAG=>> %GITHUB_OUTPUT%) else (echo DPCFLAG="0">> %GITHUB_OUTPUT%)
if not %DPCTL_TEMP:${{ matrix.PYTHON_VERSION }}=%==%DPCTL_TEMP% (
echo DPCFLAG=>> %GITHUB_OUTPUT%
echo SKLEARNEX_GCOV=YES>> %GITHUB_ENV%
) else (
echo DPCFLAG="0">> %GITHUB_OUTPUT%
)
echo COVERAGE_RCFILE=%cd%\.coveragerc>> %GITHUB_ENV%
- name: Download Intel OpenCL CPU Runtime artifact
if: ${{ steps.set-env.outputs.DPCFLAG == '' }}
Expand All @@ -242,6 +250,7 @@ jobs:
pip install --upgrade setuptools
pip install cpufeature clang-format pyyaml
pip install -r dependencies-dev
for /f "delims=" %%c in ('python -m pip freeze ^| grep numpy') do echo NUMPY_BUILD=%%c>> %GITHUB_ENV%
- name: System info
shell: cmd
run: |
Expand Down Expand Up @@ -288,13 +297,14 @@ jobs:
shell: cmd
run: |
call .\venv\Scripts\activate.bat
coverage combine .coverage.sklearnex .coverage.sklearn
coverage json -o coverage.win${{ matrix.PYTHON_VERSION }}_${{ matrix.SKLEARN_VERSION }}.json
call .\.github\scripts\activate_components.bat ${{ steps.set-env.outputs.DPCFLAG }}
bash .github/scripts/generate_coverage_reports.sh win${{ matrix.PYTHON_VERSION }}_${{ matrix.SKLEARN_VERSION }}
- name: Archive coverage report
uses: actions/upload-artifact@v4
with:
name: coverage_win_Py${{ matrix.PYTHON_VERSION }}_${{ matrix.SKLEARN_VERSION }}
path: coverage.win${{ matrix.PYTHON_VERSION }}_${{ matrix.SKLEARN_VERSION }}.json
path: |
*_win${{ matrix.PYTHON_VERSION }}_${{ matrix.SKLEARN_VERSION }}.info
- name: Sklearn testing [preview]
shell: cmd
run: |
Expand Down
2 changes: 1 addition & 1 deletion conda-recipe/run_test.bat
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if "%PYTHON%"=="python" (

set "PYTEST_ARGS= "

IF DEFINED COVERAGE_RCFILE (set "PYTEST_ARGS=--cov=onedal --cov=sklearnex --cov-config=%COVERAGE_RCFILE% --cov-append --cov-report= %PYTEST_ARGS%")
IF DEFINED COVERAGE_RCFILE (set "PYTEST_ARGS=--cov=onedal --cov=sklearnex --cov-config=%COVERAGE_RCFILE% --cov-append --cov-branch --cov-report= %PYTEST_ARGS%")

rem Note: execute with argument --json-report as second argument
rem in order to produce a JSON report under folder '.pytest_reports'.
Expand Down
2 changes: 1 addition & 1 deletion conda-recipe/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function generate_pytest_args {
ARGS+=("--json-report-file=.pytest_reports/$1_report.json")
fi
if [ -n "${COVERAGE_RCFILE}" ]; then
ARGS+=(--cov=onedal --cov=sklearnex --cov-config="${COVERAGE_RCFILE}" --cov-append --cov-report=)
ARGS+=(--cov=onedal --cov=sklearnex --cov-config="${COVERAGE_RCFILE}" --cov-append --cov-branch --cov-report=)
fi
printf -- "${ARGS[*]}"
}
Expand Down
37 changes: 35 additions & 2 deletions scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ set(CMAKE_CXX_EXTENSIONS OFF)
option(ADD_ONEDAL_RPATH "Adds oneDAL's file paths to the RPATH here" OFF)
message(STATUS "ADD_ONEDAL_RPATH:" ${ADD_ONEDAL_RPATH})

option(SKLEARNEX_GCOV "Compile with gcov" OFF)
message(STATUS "SKLEARNEX_GCOV:" ${SKLEARNEX_GCOV})

if(WIN32)
# hint CMake to get python from PYTHON env. variable if defined
if(DEFINED ENV{PYTHON})
Expand Down Expand Up @@ -122,6 +125,23 @@ if(IFACE STREQUAL "host")
endif()
endif()

if(SKLEARNEX_GCOV)
if(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM" OR CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
if(WIN32)
set(CMAKE_CXX_FLAGS "/clang:--coverage ${CMAKE_CXX_FLAGS}")
list(APPEND ONEDAL_LIBRARIES "clang_rt.profile-x86_64.lib")
else()
set(CMAKE_CXX_FLAGS "--coverage ${CMAKE_CXX_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "--coverage ${CMAKE_SHARED_LINKER_FLAGS}")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "--coverage ${CMAKE_CXX_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "--coverage ${CMAKE_SHARED_LINKER_FLAGS}")
else()
message(WARNING "Code coverage will not be generated for target: host")
endif()
endif()

list(APPEND COMPILE_DEFINITIONS "NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION")

elseif(IFACE_IS_DPC OR IFACE_IS_SPMD_DPC)
Expand All @@ -137,11 +157,12 @@ elseif(IFACE_IS_DPC OR IFACE_IS_SPMD_DPC)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)
endif()

if(CMAKE_CXX_COMPILER MATCHES ".*icpx" OR CMAKE_CXX_COMPILER MATCHES ".*icx")
if(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
set(CMAKE_CXX_FLAGS "-fsycl ${CMAKE_CXX_FLAGS}")

endif()

if(CMAKE_C_COMPILER MATCHES ".*icpx" OR CMAKE_C_COMPILER MATCHES ".*icx")
if(CMAKE_C_COMPILER_ID STREQUAL "IntelLLVM")
set(CMAKE_C_FLAGS "-fsycl ${CMAKE_C_FLAGS}")
endif()

Expand Down Expand Up @@ -169,6 +190,18 @@ elseif(IFACE_IS_DPC OR IFACE_IS_SPMD_DPC)
endif()
endif()

if(SKLEARNEX_GCOV)
if(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM" AND WIN32)
set(CMAKE_CXX_FLAGS "/clang:-Xarch_host /clang:--coverage ${CMAKE_CXX_FLAGS}")
list(APPEND ONEDAL_LIBRARIES "clang_rt.profile-x86_64.lib")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM" AND UNIX)
set(CMAKE_CXX_FLAGS "-Xarch_host --coverage ${CMAKE_CXX_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "-Xarch_host --coverage ${CMAKE_SHARED_LINKER_FLAGS}")
else()
message(WARNING "Code coverage will not be generated for target: " ${IFACE})
endif()
endif()

if(IFACE_IS_SPMD_DPC)
set(MPI_LIBRARY ${MPI_LIBS})
endif()
Expand Down
4 changes: 4 additions & 0 deletions scripts/build_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def custom_build_cmake_clib(
no_dist=True,
use_parameters_lib=True,
use_abs_rpath=False,
use_gcov=False,
):
import pybind11

Expand Down Expand Up @@ -130,6 +131,9 @@ def custom_build_cmake_clib(
if use_abs_rpath:
cmake_args += ["-DADD_ONEDAL_RPATH=ON"]

if use_gcov:
cmake_args += ["-DSKLEARNEX_GCOV=ON"]

cpu_count = multiprocessing.cpu_count()
# limit parallel cmake jobs if memory size is insufficient
# TODO: add on all platforms
Expand Down
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
no_dist = True if "NO_DIST" in os.environ and os.environ["NO_DIST"] in trues else False
no_dpc = True if "NO_DPC" in os.environ and os.environ["NO_DPC"] in trues else False
no_stream = "NO_STREAM" in os.environ and os.environ["NO_STREAM"] in trues
use_gcov = "SKLEARNEX_GCOV" in os.environ and os.environ["SKLEARNEX_GCOV"] in trues
debug_build = os.getenv("DEBUG_BUILD") == "1"
mpi_root = None if no_dist else os.environ["MPIROOT"]
dpcpp = (
Expand Down Expand Up @@ -426,6 +427,7 @@ def run(self):
no_dist=no_dist,
use_parameters_lib=use_parameters_lib,
use_abs_rpath=USE_ABS_RPATH,
use_gcov=use_gcov,
)
if dpcpp:
if is_onedal_iface:
Expand All @@ -435,6 +437,7 @@ def run(self):
no_dist=no_dist,
use_parameters_lib=use_parameters_lib,
use_abs_rpath=USE_ABS_RPATH,
use_gcov=use_gcov,
)
if build_distribute:
build_backend.custom_build_cmake_clib(
Expand All @@ -443,6 +446,7 @@ def run(self):
no_dist=no_dist,
use_parameters_lib=use_parameters_lib,
use_abs_rpath=USE_ABS_RPATH,
use_gcov=use_gcov,
)

def post_build(self):
Expand Down
Loading