From 1610adf2fe25978f1116014530104e41943a637c Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Fri, 24 Nov 2023 04:10:26 -0600 Subject: [PATCH 01/11] Modified gen_coverage to also collect data from Pybind11 modules This will provide coverage for the host portion of offloading Pybind11 extensions. --- scripts/gen_coverage.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/gen_coverage.py b/scripts/gen_coverage.py index 538b93adbb..fbdba031c4 100644 --- a/scripts/gen_coverage.py +++ b/scripts/gen_coverage.py @@ -15,8 +15,10 @@ # limitations under the License. import os +import re import subprocess import sys +import sysconfig def run( @@ -105,6 +107,13 @@ def find_objects(): import os objects = [] + 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("_skbuild"): for file in files: if not file.endswith(".so"): @@ -116,7 +125,7 @@ def find_objects(): for match in [ "libsyclinterface", ] - ): + ) or is_py_ext(file): objects.extend(["-object", os.path.join(root, file)]) return objects From 74800beb8082d6e2260cd3c99c0a27be943d7668 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Fri, 24 Nov 2023 09:31:14 -0600 Subject: [PATCH 02/11] Added print statement for debugging --- scripts/gen_coverage.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/gen_coverage.py b/scripts/gen_coverage.py index fbdba031c4..b3d657fdab 100644 --- a/scripts/gen_coverage.py +++ b/scripts/gen_coverage.py @@ -109,7 +109,7 @@ def find_objects(): objects = [] 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) + regexp2 = re.compile(r"^^_device_queries" + sfx_regexp) def is_py_ext(fn): return re.match(regexp1, fn) or re.match(regexp2, fn) @@ -127,6 +127,7 @@ def is_py_ext(fn): ] ) or is_py_ext(file): objects.extend(["-object", os.path.join(root, file)]) + print("Using objects: ", objects) return objects objects = find_objects() From c2842412dc38726277b38e303f6a47926f0734e8 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Fri, 24 Nov 2023 10:50:27 -0600 Subject: [PATCH 03/11] Search in dpctl, not in _sklearn folder --- scripts/gen_coverage.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/scripts/gen_coverage.py b/scripts/gen_coverage.py index b3d657fdab..cb43299168 100644 --- a/scripts/gen_coverage.py +++ b/scripts/gen_coverage.py @@ -114,18 +114,11 @@ def find_objects(): def is_py_ext(fn): return re.match(regexp1, fn) or re.match(regexp2, fn) - for root, _, files in os.walk("_skbuild"): + 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", - ] - ) or is_py_ext(file): + if is_py_ext(file) or file.find("DPCTLSyclInterface") != -1: objects.extend(["-object", os.path.join(root, file)]) print("Using objects: ", objects) return objects From b2604e6d28faab86d6691f407993fab6a2d09fbb Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Sun, 10 Dec 2023 19:03:04 -0600 Subject: [PATCH 04/11] Corrected use of hard-coded sycl-targets --- libsyclinterface/tests/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsyclinterface/tests/CMakeLists.txt b/libsyclinterface/tests/CMakeLists.txt index 5a672e312f..13f36c39d7 100644 --- a/libsyclinterface/tests/CMakeLists.txt +++ b/libsyclinterface/tests/CMakeLists.txt @@ -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() From 1500a0658e29763014e9f705d3035d52a4931264 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Sun, 10 Dec 2023 19:03:41 -0600 Subject: [PATCH 05/11] pybind11 extensions in dpctl.tensor set linker flags for coverage generation --- dpctl/tensor/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dpctl/tensor/CMakeLists.txt b/dpctl/tensor/CMakeLists.txt index e36cfe1914..add6cb4fe9 100644 --- a/dpctl/tensor/CMakeLists.txt +++ b/dpctl/tensor/CMakeLists.txt @@ -216,6 +216,11 @@ 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) + target_link_options(${python_module_name} + PRIVATE -fprofile-instr-generate -fcoverage-mapping + ) + endif() if(_dpctl_sycl_targets) # make fat binary target_compile_options( From d34a2aadab5d75b5e53d627c3d1fea765f2ad10d Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Sun, 10 Dec 2023 19:05:41 -0600 Subject: [PATCH 06/11] _device_queries pybind11 extension also uses coverege linker flags --- dpctl/utils/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dpctl/utils/CMakeLists.txt b/dpctl/utils/CMakeLists.txt index e7d3951e5b..4fc3c323c4 100644 --- a/dpctl/utils/CMakeLists.txt +++ b/dpctl/utils/CMakeLists.txt @@ -21,6 +21,11 @@ pybind11_add_module(${python_module_name} MODULE ${_module_src} ) add_sycl_to_target(TARGET ${python_module_name} SOURCES ${_module_src}) +if(DPCTL_GENERATE_COVERAGE) + target_link_options(${python_module_name} + PRIVATE -fprofile-instr-generate -fcoverage-mapping + ) +endif() if(_dpctl_sycl_targets) # make fat binary target_compile_options( From d010a40422a229e7afaeba957c2dadfe247f130d Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Sun, 10 Dec 2023 20:03:08 -0600 Subject: [PATCH 07/11] Add support for verbose option in gen_coverage --- scripts/gen_coverage.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/gen_coverage.py b/scripts/gen_coverage.py index cb43299168..0f54411d39 100644 --- a/scripts/gen_coverage.py +++ b/scripts/gen_coverage.py @@ -30,6 +30,7 @@ def run( run_pytest=False, bin_llvm=None, gtest_config=None, + verbose=False, ): IS_LIN = False @@ -68,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( @@ -186,6 +191,12 @@ def is_py_ext(fn): 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 " @@ -233,4 +244,5 @@ def is_py_ext(fn): run_pytest=args.run_pytest, bin_llvm=args.bin_llvm, gtest_config=args.gtest_config, + verbose=args.verbose, ) From d0404376b23a2285b252f61373fdc5ebd42a23a2 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Sun, 10 Dec 2023 20:03:44 -0600 Subject: [PATCH 08/11] Do not use -fno-sycl-use-footer --- dpctl/CMakeLists.txt | 2 +- libsyclinterface/cmake/modules/SetupCoverage.cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dpctl/CMakeLists.txt b/dpctl/CMakeLists.txt index 616f270ad3..3125eae07d 100644 --- a/dpctl/CMakeLists.txt +++ b/dpctl/CMakeLists.txt @@ -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}") diff --git a/libsyclinterface/cmake/modules/SetupCoverage.cmake b/libsyclinterface/cmake/modules/SetupCoverage.cmake index ba7017ed79..e81321e849 100644 --- a/libsyclinterface/cmake/modules/SetupCoverage.cmake +++ b/libsyclinterface/cmake/modules/SetupCoverage.cmake @@ -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 " ) From ee333f7df220cd345ca7c314d63b20887f4a3403 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Sun, 10 Dec 2023 20:04:16 -0600 Subject: [PATCH 09/11] Use gen_coverage.py --verbose --- .github/workflows/generate-coverage.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/generate-coverage.yaml b/.github/workflows/generate-coverage.yaml index d739e32ad7..0eea5f32e8 100644 --- a/.github/workflows/generate-coverage.yaml +++ b/.github/workflows/generate-coverage.yaml @@ -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} From 1acdc2c28c85224b92db634202aba26468f86fd3 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Mon, 11 Dec 2023 08:04:09 -0600 Subject: [PATCH 10/11] Use profile instrumentation compile flags for pybind11 extensions --- dpctl/tensor/CMakeLists.txt | 3 +++ dpctl/utils/CMakeLists.txt | 3 +++ 2 files changed, 6 insertions(+) diff --git a/dpctl/tensor/CMakeLists.txt b/dpctl/tensor/CMakeLists.txt index add6cb4fe9..c8fcbc28a6 100644 --- a/dpctl/tensor/CMakeLists.txt +++ b/dpctl/tensor/CMakeLists.txt @@ -217,6 +217,9 @@ foreach(python_module_name ${_py_trgts}) ) target_link_options(${python_module_name} PRIVATE ${_linker_options}) if(DPCTL_GENERATE_COVERAGE) + target_compile_options(${python_module_name} + PRIVATE -fprofile-instr-generate -fcoverage-mapping + ) target_link_options(${python_module_name} PRIVATE -fprofile-instr-generate -fcoverage-mapping ) diff --git a/dpctl/utils/CMakeLists.txt b/dpctl/utils/CMakeLists.txt index 4fc3c323c4..c10e4ab824 100644 --- a/dpctl/utils/CMakeLists.txt +++ b/dpctl/utils/CMakeLists.txt @@ -22,6 +22,9 @@ pybind11_add_module(${python_module_name} MODULE ) add_sycl_to_target(TARGET ${python_module_name} SOURCES ${_module_src}) if(DPCTL_GENERATE_COVERAGE) + target_compile_options(${python_module_name} + PRIVATE -fprofile-instr-generate -fcoverage-mapping + ) target_link_options(${python_module_name} PRIVATE -fprofile-instr-generate -fcoverage-mapping ) From 644eadc594b4b1a031b8521fbcb0cd731153c9a0 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Mon, 11 Dec 2023 16:25:47 -0600 Subject: [PATCH 11/11] Turn coverage collection for pybind11 extensions off by default To turn it on, set `-DDPCTL_GENERATE_COVERAGE` and `-DDPCTL_GENERATE_COVERAGE_FOR_PYBIND11_EXTENSIONS` --- CMakeLists.txt | 4 ++++ dpctl/tensor/CMakeLists.txt | 8 +++++--- dpctl/utils/CMakeLists.txt | 8 +++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index adfb4fbddd..7688ff040c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/dpctl/tensor/CMakeLists.txt b/dpctl/tensor/CMakeLists.txt index c8fcbc28a6..de8be6fae0 100644 --- a/dpctl/tensor/CMakeLists.txt +++ b/dpctl/tensor/CMakeLists.txt @@ -217,9 +217,11 @@ foreach(python_module_name ${_py_trgts}) ) target_link_options(${python_module_name} PRIVATE ${_linker_options}) if(DPCTL_GENERATE_COVERAGE) - target_compile_options(${python_module_name} - PRIVATE -fprofile-instr-generate -fcoverage-mapping - ) + 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 ) diff --git a/dpctl/utils/CMakeLists.txt b/dpctl/utils/CMakeLists.txt index c10e4ab824..8830b74b86 100644 --- a/dpctl/utils/CMakeLists.txt +++ b/dpctl/utils/CMakeLists.txt @@ -22,9 +22,11 @@ pybind11_add_module(${python_module_name} MODULE ) add_sycl_to_target(TARGET ${python_module_name} SOURCES ${_module_src}) if(DPCTL_GENERATE_COVERAGE) - target_compile_options(${python_module_name} - PRIVATE -fprofile-instr-generate -fcoverage-mapping - ) + 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 )