Skip to content

Commit bea4c9c

Browse files
authored
Install OneAPI compiler for coverage GitHub action (#1777)
* Install OneAPI compiler for coverage GH action * Updated coverage script to handle OneAPI compiler
1 parent 35f04f3 commit bea4c9c

File tree

2 files changed

+98
-16
lines changed

2 files changed

+98
-16
lines changed

.github/workflows/generate_coverage.yaml

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ jobs:
2121

2222
env:
2323
python-ver: '3.10'
24-
CHANNELS: '-c dppy/label/coverage -c intel -c conda-forge --override-channels'
24+
CHANNELS: '-c dppy/label/dev -c intel -c conda-forge --override-channels'
25+
# Install the latest oneAPI compiler to work around an issue
26+
INSTALL_ONE_API: 'yes'
2527

2628
steps:
2729
- name: Cancel Previous Runs
@@ -34,6 +36,26 @@ jobs:
3436
with:
3537
fetch-depth: 0
3638

39+
- name: Add Intel repository
40+
if: env.INSTALL_ONE_API == 'yes'
41+
run: |
42+
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
43+
sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
44+
rm GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
45+
sudo add-apt-repository "deb https://apt.repos.intel.com/oneapi all main"
46+
sudo apt-get update
47+
48+
- name: Install latest Intel OneAPI
49+
if: env.INSTALL_ONE_API == 'yes'
50+
run: |
51+
sudo apt-get install intel-oneapi-compiler-dpcpp-cpp
52+
sudo apt-get install intel-oneapi-mkl-devel
53+
sudo apt-get install intel-oneapi-tbb-devel
54+
55+
- name: Install Lcov
56+
run: |
57+
sudo apt-get install lcov
58+
3759
- name: Setup miniconda
3860
uses: conda-incubator/setup-miniconda@030178870c779d9e5e1b4e563269f3aa69b04081 # v3.0.3
3961
with:
@@ -42,14 +64,17 @@ jobs:
4264
miniconda-version: 'latest'
4365
activate-environment: 'coverage'
4466

45-
- name: Install Lcov
67+
- name: Install dpnp dependencies
68+
if: env.INSTALL_ONE_API == 'yes'
4669
run: |
47-
sudo apt-get install lcov
70+
conda install cython llvm cmake">=3.21" scikit-build ninja pytest pytest-cov coverage[toml] \
71+
dpctl">=0.17.0dev0" onedpl-devel ${{ env.CHANNELS }}
4872
4973
- name: Install dpnp dependencies
74+
if: env.INSTALL_ONE_API != 'yes'
5075
run: |
5176
conda install cython llvm cmake">=3.21" scikit-build ninja pytest pytest-cov coverage[toml] \
52-
dpctl">=0.17.0dev0" dpctl dpcpp_linux-64 mkl-devel-dpcpp tbb-devel onedpl-devel ${{ env.CHANNELS }}
77+
dpctl">=0.17.0dev0" dpcpp_linux-64 mkl-devel-dpcpp tbb-devel onedpl-devel ${{ env.CHANNELS }}
5378
5479
- name: Conda info
5580
run: |
@@ -67,8 +92,9 @@ jobs:
6792
command: |
6893
. $CONDA/etc/profile.d/conda.sh
6994
conda activate coverage
95+
[ -f /opt/intel/oneapi/setvars.sh ] && source /opt/intel/oneapi/setvars.sh
7096
git clean -fxd
71-
python scripts/gen_coverage.py --pytest-opts="--ignore tests/test_random.py"
97+
python scripts/gen_coverage.py --pytest-opts="--ignore tests/test_random.py" --verbose
7298
7399
- name: Total number of coverage attempts
74100
run: |

scripts/gen_coverage.py

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44

55

66
def run(
7+
use_oneapi=True,
78
c_compiler=None,
89
cxx_compiler=None,
10+
compiler_root=None,
911
bin_llvm=None,
1012
pytest_opts="",
13+
verbose=False,
1114
):
1215
IS_LIN = False
1316

@@ -29,11 +32,10 @@ def run(
2932
sys.executable,
3033
"setup.py",
3134
"develop",
32-
"-G=Ninja",
35+
"--generator=Ninja",
3336
"--",
3437
"-DCMAKE_C_COMPILER:PATH=" + c_compiler,
3538
"-DCMAKE_CXX_COMPILER:PATH=" + cxx_compiler,
36-
"-DCMAKE_VERBOSE_MAKEFILE=ON",
3739
"-DDPNP_GENERATE_COVERAGE=ON",
3840
]
3941

@@ -47,6 +49,11 @@ def run(
4749
# extend with global enviroment variables
4850
env.update({k: v for k, v in os.environ.items() if k != "PATH"})
4951

52+
if verbose:
53+
cmake_args += [
54+
"-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON",
55+
]
56+
5057
subprocess.check_call(cmake_args, shell=False, cwd=setup_dir, env=env)
5158

5259
env["LLVM_PROFILE_FILE"] = "dpnp_pytest.profraw"
@@ -125,25 +132,74 @@ def find_objects():
125132
description="Driver to build dpnp and generate coverage"
126133
)
127134
driver = parser.add_argument_group(title="Coverage driver arguments")
135+
driver.add_argument("--c-compiler", help="Name of C compiler", default=None)
136+
driver.add_argument(
137+
"--cxx-compiler", help="Name of C++ compiler", default=None
138+
)
139+
driver.add_argument(
140+
"--not-oneapi",
141+
help="Is one-API installation",
142+
dest="oneapi",
143+
action="store_false",
144+
)
145+
driver.add_argument(
146+
"--compiler-root", type=str, help="Path to compiler home directory"
147+
)
148+
driver.add_argument(
149+
"--bin-llvm", help="Path to folder where llvm-cov can be found"
150+
)
128151
driver.add_argument(
129152
"--pytest-opts",
130153
help="Channels through additional pytest options",
131154
dest="pytest_opts",
132155
default="",
133156
type=str,
134157
)
135-
158+
driver.add_argument(
159+
"--verbose",
160+
help="Build using vebose makefile mode",
161+
dest="verbose",
162+
action="store_true",
163+
)
136164
args = parser.parse_args()
137165

138-
c_compiler = "icx"
139-
cxx_compiler = "icpx"
140-
icx_path = subprocess.check_output(["which", "icx"])
141-
bin_dir = os.path.dirname(os.path.dirname(icx_path))
142-
bin_llvm = os.path.join(bin_dir.decode("utf-8"), "bin-llvm")
166+
if args.oneapi:
167+
args.c_compiler = "icx"
168+
args.cxx_compiler = "icpx"
169+
args.compiler_root = None
170+
icx_path = subprocess.check_output(["which", "icx"])
171+
bin_dir = os.path.dirname(icx_path)
172+
compiler_dir = os.path.join(bin_dir.decode("utf-8"), "compiler")
173+
if os.path.exists(compiler_dir):
174+
args.bin_llvm = os.path.join(bin_dir.decode("utf-8"), "compiler")
175+
else:
176+
bin_dir = os.path.dirname(bin_dir)
177+
args.bin_llvm = os.path.join(bin_dir.decode("utf-8"), "bin-llvm")
178+
assert os.path.exists(args.bin_llvm)
179+
else:
180+
args_to_validate = [
181+
"c_compiler",
182+
"cxx_compiler",
183+
"compiler_root",
184+
"bin_llvm",
185+
]
186+
for p in args_to_validate:
187+
arg = getattr(args, p, None)
188+
if not isinstance(arg, str):
189+
opt_name = p.replace("_", "-")
190+
raise RuntimeError(
191+
f"Option {opt_name} must be provided is "
192+
"using non-default DPC++ layout"
193+
)
194+
if not os.path.exists(arg):
195+
raise RuntimeError(f"Path {arg} must exist")
143196

144197
run(
145-
c_compiler=c_compiler,
146-
cxx_compiler=cxx_compiler,
147-
bin_llvm=bin_llvm,
198+
use_oneapi=args.oneapi,
199+
c_compiler=args.c_compiler,
200+
cxx_compiler=args.cxx_compiler,
201+
compiler_root=args.compiler_root,
202+
bin_llvm=args.bin_llvm,
148203
pytest_opts=args.pytest_opts,
204+
verbose=args.verbose,
149205
)

0 commit comments

Comments
 (0)