Skip to content

Modified gen_coverage to also collect data from Pybind11 modules #1476

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 11 commits into from
Dec 13, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/generate-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
shell: bash -l {0}
run: |
source /opt/intel/oneapi/setvars.sh
python scripts/gen_coverage.py
python scripts/gen_coverage.py --verbose

- name: Install coverall dependencies
shell: bash -l {0}
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ option(DPCTL_GENERATE_COVERAGE
"Build dpctl with coverage instrumentation"
OFF
)
option(DPCTL_GENERATE_COVERAGE_FOR_PYBIND11_EXTENSIONS
"Build dpctl pybind11 offloading extensions with coverage instrumentation"
OFF
)
option(DPCTL_TARGET_CUDA
"Build DPCTL to target CUDA devices"
OFF
Expand Down
2 changes: 1 addition & 1 deletion dpctl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function(build_dpctl_ext _trgt _src _dest)
add_dependencies(${_trgt} _build_time_create_dpctl_include_copy ${_cythonize_trgt})
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)
# target_compile_options(${_trgt} PRIVATE -fno-sycl-use-footer)
endif()
target_link_libraries(${_trgt} PRIVATE DPCTLSyclInterface)
set(_linker_options "LINKER:${DPCTL_LDFLAGS}")
Expand Down
10 changes: 10 additions & 0 deletions dpctl/tensor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ foreach(python_module_name ${_py_trgts})
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/
)
target_link_options(${python_module_name} PRIVATE ${_linker_options})
if(DPCTL_GENERATE_COVERAGE)
if(DPCTL_GENERATE_COVERAGE_FOR_PYBIND11_EXTENSIONS)
target_compile_options(${python_module_name}
PRIVATE -fprofile-instr-generate -fcoverage-mapping
)
endif()
target_link_options(${python_module_name}
PRIVATE -fprofile-instr-generate -fcoverage-mapping
)
endif()
if(_dpctl_sycl_targets)
# make fat binary
target_compile_options(
Expand Down
10 changes: 10 additions & 0 deletions dpctl/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ pybind11_add_module(${python_module_name} MODULE
${_module_src}
)
add_sycl_to_target(TARGET ${python_module_name} SOURCES ${_module_src})
if(DPCTL_GENERATE_COVERAGE)
if(DPCTL_GENERATE_COVERAGE_FOR_PYBIND11_EXTENSIONS)
target_compile_options(${python_module_name}
PRIVATE -fprofile-instr-generate -fcoverage-mapping
)
endif()
target_link_options(${python_module_name}
PRIVATE -fprofile-instr-generate -fcoverage-mapping
)
endif()
if(_dpctl_sycl_targets)
# make fat binary
target_compile_options(
Expand Down
2 changes: 1 addition & 1 deletion libsyclinterface/cmake/modules/SetupCoverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function(setup_coverage_generation)
string(CONCAT PROFILE_FLAGS
"-fprofile-instr-generate "
"-fcoverage-mapping "
"-fno-sycl-use-footer "
# "-fno-sycl-use-footer "
# "-save-temps=obj "
)

Expand Down
4 changes: 2 additions & 2 deletions libsyclinterface/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ if (_dpctl_sycl_targets)
target_compile_options(
dpctl_c_api_tests
PRIVATE
-fsycl-targets=nvptx64-nvidia-cuda,spir64-unknown-unknown
-fsycl-targets=${_dpctl_sycl_targets}
)
target_link_options(
dpctl_c_api_tests
PRIVATE
-fsycl-targets=nvptx64-nvidia-cuda,spir64-unknown-unknown
-fsycl-targets=${_dpctl_sycl_targets}
)
endif()

Expand Down
33 changes: 24 additions & 9 deletions scripts/gen_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
# limitations under the License.

import os
import re
import subprocess
import sys
import sysconfig


def run(
Expand All @@ -28,6 +30,7 @@ def run(
run_pytest=False,
bin_llvm=None,
gtest_config=None,
verbose=False,
):
IS_LIN = False

Expand Down Expand Up @@ -66,6 +69,10 @@ def run(
env.update({k: v for k, v in os.environ.items() if k != "PATH"})
if gtest_config:
cmake_args += ["-DCMAKE_PREFIX_PATH=" + gtest_config]
if verbose:
cmake_args += [
"-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON",
]
subprocess.check_call(cmake_args, shell=False, cwd=setup_dir, env=env)
cmake_build_dir = (
subprocess.check_output(
Expand Down Expand Up @@ -105,19 +112,20 @@ def find_objects():
import os

objects = []
for root, _, files in os.walk("_skbuild"):
sfx_regexp = sysconfig.get_config_var("EXT_SUFFIX").replace(".", r"\.")
regexp1 = re.compile(r"^_tensor_.*impl" + sfx_regexp)
regexp2 = re.compile(r"^^_device_queries" + sfx_regexp)

def is_py_ext(fn):
return re.match(regexp1, fn) or re.match(regexp2, fn)

for root, _, files in os.walk("dpctl"):
for file in files:
if not file.endswith(".so"):
continue
if os.path.join("libsyclinterface", "tests") in root:
continue
if any(
match in root
for match in [
"libsyclinterface",
]
):
if is_py_ext(file) or file.find("DPCTLSyclInterface") != -1:
objects.extend(["-object", os.path.join(root, file)])
print("Using objects: ", objects)
return objects

objects = find_objects()
Expand Down Expand Up @@ -183,6 +191,12 @@ def find_objects():
driver.add_argument(
"--bin-llvm", help="Path to folder where llvm-cov can be found"
)
driver.add_argument(
"--verbose",
help="Build using vebose makefile mode",
dest="verbose",
action="store_true",
)
driver.add_argument(
"--gtest-config",
help="Path to the GTestConfig.cmake file to locate a "
Expand Down Expand Up @@ -230,4 +244,5 @@ def find_objects():
run_pytest=args.run_pytest,
bin_llvm=args.bin_llvm,
gtest_config=args.gtest_config,
verbose=args.verbose,
)