Skip to content

Commit b29a9d7

Browse files
Merge pull request #1476 from IntelPython/coverage-for-pybind11-extensions
Modified gen_coverage to also collect data from Pybind11 modules
2 parents 46583b8 + 644eadc commit b29a9d7

File tree

8 files changed

+53
-14
lines changed

8 files changed

+53
-14
lines changed

.github/workflows/generate-coverage.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ jobs:
9494
shell: bash -l {0}
9595
run: |
9696
source /opt/intel/oneapi/setvars.sh
97-
python scripts/gen_coverage.py
97+
python scripts/gen_coverage.py --verbose
9898
9999
- name: Install coverall dependencies
100100
shell: bash -l {0}

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ option(DPCTL_GENERATE_COVERAGE
1717
"Build dpctl with coverage instrumentation"
1818
OFF
1919
)
20+
option(DPCTL_GENERATE_COVERAGE_FOR_PYBIND11_EXTENSIONS
21+
"Build dpctl pybind11 offloading extensions with coverage instrumentation"
22+
OFF
23+
)
2024
option(DPCTL_TARGET_CUDA
2125
"Build DPCTL to target CUDA devices"
2226
OFF

dpctl/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ function(build_dpctl_ext _trgt _src _dest)
162162
add_dependencies(${_trgt} _build_time_create_dpctl_include_copy ${_cythonize_trgt})
163163
if (DPCTL_GENERATE_COVERAGE)
164164
target_compile_definitions(${_trgt} PRIVATE CYTHON_TRACE=1 CYTHON_TRACE_NOGIL=1)
165-
target_compile_options(${_trgt} PRIVATE -fno-sycl-use-footer)
165+
# target_compile_options(${_trgt} PRIVATE -fno-sycl-use-footer)
166166
endif()
167167
target_link_libraries(${_trgt} PRIVATE DPCTLSyclInterface)
168168
set(_linker_options "LINKER:${DPCTL_LDFLAGS}")

dpctl/tensor/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,16 @@ foreach(python_module_name ${_py_trgts})
216216
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/
217217
)
218218
target_link_options(${python_module_name} PRIVATE ${_linker_options})
219+
if(DPCTL_GENERATE_COVERAGE)
220+
if(DPCTL_GENERATE_COVERAGE_FOR_PYBIND11_EXTENSIONS)
221+
target_compile_options(${python_module_name}
222+
PRIVATE -fprofile-instr-generate -fcoverage-mapping
223+
)
224+
endif()
225+
target_link_options(${python_module_name}
226+
PRIVATE -fprofile-instr-generate -fcoverage-mapping
227+
)
228+
endif()
219229
if(_dpctl_sycl_targets)
220230
# make fat binary
221231
target_compile_options(

dpctl/utils/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ pybind11_add_module(${python_module_name} MODULE
2121
${_module_src}
2222
)
2323
add_sycl_to_target(TARGET ${python_module_name} SOURCES ${_module_src})
24+
if(DPCTL_GENERATE_COVERAGE)
25+
if(DPCTL_GENERATE_COVERAGE_FOR_PYBIND11_EXTENSIONS)
26+
target_compile_options(${python_module_name}
27+
PRIVATE -fprofile-instr-generate -fcoverage-mapping
28+
)
29+
endif()
30+
target_link_options(${python_module_name}
31+
PRIVATE -fprofile-instr-generate -fcoverage-mapping
32+
)
33+
endif()
2434
if(_dpctl_sycl_targets)
2535
# make fat binary
2636
target_compile_options(

libsyclinterface/cmake/modules/SetupCoverage.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function(setup_coverage_generation)
2525
string(CONCAT PROFILE_FLAGS
2626
"-fprofile-instr-generate "
2727
"-fcoverage-mapping "
28-
"-fno-sycl-use-footer "
28+
# "-fno-sycl-use-footer "
2929
# "-save-temps=obj "
3030
)
3131

libsyclinterface/tests/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ if (_dpctl_sycl_targets)
5757
target_compile_options(
5858
dpctl_c_api_tests
5959
PRIVATE
60-
-fsycl-targets=nvptx64-nvidia-cuda,spir64-unknown-unknown
60+
-fsycl-targets=${_dpctl_sycl_targets}
6161
)
6262
target_link_options(
6363
dpctl_c_api_tests
6464
PRIVATE
65-
-fsycl-targets=nvptx64-nvidia-cuda,spir64-unknown-unknown
65+
-fsycl-targets=${_dpctl_sycl_targets}
6666
)
6767
endif()
6868

scripts/gen_coverage.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
# limitations under the License.
1616

1717
import os
18+
import re
1819
import subprocess
1920
import sys
21+
import sysconfig
2022

2123

2224
def run(
@@ -28,6 +30,7 @@ def run(
2830
run_pytest=False,
2931
bin_llvm=None,
3032
gtest_config=None,
33+
verbose=False,
3134
):
3235
IS_LIN = False
3336

@@ -66,6 +69,10 @@ def run(
6669
env.update({k: v for k, v in os.environ.items() if k != "PATH"})
6770
if gtest_config:
6871
cmake_args += ["-DCMAKE_PREFIX_PATH=" + gtest_config]
72+
if verbose:
73+
cmake_args += [
74+
"-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON",
75+
]
6976
subprocess.check_call(cmake_args, shell=False, cwd=setup_dir, env=env)
7077
cmake_build_dir = (
7178
subprocess.check_output(
@@ -105,19 +112,20 @@ def find_objects():
105112
import os
106113

107114
objects = []
108-
for root, _, files in os.walk("_skbuild"):
115+
sfx_regexp = sysconfig.get_config_var("EXT_SUFFIX").replace(".", r"\.")
116+
regexp1 = re.compile(r"^_tensor_.*impl" + sfx_regexp)
117+
regexp2 = re.compile(r"^^_device_queries" + sfx_regexp)
118+
119+
def is_py_ext(fn):
120+
return re.match(regexp1, fn) or re.match(regexp2, fn)
121+
122+
for root, _, files in os.walk("dpctl"):
109123
for file in files:
110124
if not file.endswith(".so"):
111125
continue
112-
if os.path.join("libsyclinterface", "tests") in root:
113-
continue
114-
if any(
115-
match in root
116-
for match in [
117-
"libsyclinterface",
118-
]
119-
):
126+
if is_py_ext(file) or file.find("DPCTLSyclInterface") != -1:
120127
objects.extend(["-object", os.path.join(root, file)])
128+
print("Using objects: ", objects)
121129
return objects
122130

123131
objects = find_objects()
@@ -183,6 +191,12 @@ def find_objects():
183191
driver.add_argument(
184192
"--bin-llvm", help="Path to folder where llvm-cov can be found"
185193
)
194+
driver.add_argument(
195+
"--verbose",
196+
help="Build using vebose makefile mode",
197+
dest="verbose",
198+
action="store_true",
199+
)
186200
driver.add_argument(
187201
"--gtest-config",
188202
help="Path to the GTestConfig.cmake file to locate a "
@@ -230,4 +244,5 @@ def find_objects():
230244
run_pytest=args.run_pytest,
231245
bin_llvm=args.bin_llvm,
232246
gtest_config=args.gtest_config,
247+
verbose=args.verbose,
233248
)

0 commit comments

Comments
 (0)