Skip to content

Commit

Permalink
compiler: Add oneapi compiler support
Browse files Browse the repository at this point in the history
  • Loading branch information
georgebisbas committed Mar 17, 2023
1 parent 9061a67 commit 6e11659
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 3 deletions.
56 changes: 55 additions & 1 deletion devito/arch/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from codepy.toolchain import GCCToolchain

from devito.arch import (AMDGPUX, Cpu64, M1, NVIDIAX, SKX, POWER8, POWER9, GRAVITON,
get_nvidia_cc, check_cuda_runtime, get_m1_llvm_path)
INTELGPUX, get_nvidia_cc, check_cuda_runtime, get_m1_llvm_path)
from devito.exceptions import CompilationError
from devito.logger import debug, warning, error
from devito.parameters import configuration
Expand Down Expand Up @@ -528,6 +528,58 @@ def __lookup_cmds__(self):
self.MPICXX = 'mpicxx'


class OneapiCompiler(Compiler):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

language = kwargs.pop('language', configuration['language'])
platform = kwargs.pop('platform', configuration['platform'])

self.cflags.append("-xHost")
self.cflags.append("-qopt-zmm-usage=high")

if configuration['safe-math']:
self.cflags.append("-fp-model=strict")
else:
self.cflags.append('-fast')

if language == 'sycl':
self.cflags.append('-fsycl')
if platform is NVIDIAX:
self.cflags.append('-fsycl-targets=nvptx64-cuda')
else:
self.cflags.append('-fsycl-targets=spir64')

if language == 'openmp':
self.cflags.append('-qopenmp')
if platform is NVIDIAX:
self.cflags.append('-fopenmp-targets=nvptx64-cuda')
if platform is INTELGPUX:
self.cflags.append('-fopenmp-targets=spir64')
self.cflags.append('-fopenmp-target-simd')

if platform is INTELGPUX:
self.cflags.remove('-g') # -g disables some optimizations in IGC
self.cflags.append('-gline-tables-only')
self.cflags.append('-fdebug-info-for-profiling')

# Make sure the MPI compiler uses `icx` underneath -- whatever the MPI distro is
if kwargs.get('mpi'):
ver = check_output([self.MPICC, "--version"]).decode("utf-8")
if not ver.startswith("Intel(R) oneAPI"):
warning("The MPI compiler `%s` doesn't use the Intel(R) oneAPI "
"DPC++/C++ compiler underneath" % self.MPICC)

def __lookup_cmds__(self):
# OneAPI HPC ToolKit comes with icpx, which is clang++,
# and icx, which is clang
self.CC = 'icx'
self.CXX = 'icpx'
self.MPICC = 'mpicc'
self.MPICXX = 'mpicxx'


class PGICompiler(Compiler):

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -793,6 +845,8 @@ def __lookup_cmds__(self):
'intel': IntelCompiler,
'icpc': IntelCompiler,
'icc': IntelCompiler,
'icx': OneapiCompiler,
'icpx': OneapiCompiler,
'intel-knl': IntelKNLCompiler,
'knl': IntelKNLCompiler,
'dpcpp': DPCPPCompiler,
Expand Down
12 changes: 10 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from devito import Eq, configuration # noqa
from devito.finite_differences.differentiable import EvalDerivative
from devito.arch import Cpu64, Device, sniff_mpi_distro, Arm
from devito.arch.compiler import compiler_registry, IntelCompiler, NvidiaCompiler
from devito.arch.compiler import (compiler_registry, IntelCompiler, OneapiCompiler,
NvidiaCompiler)
from devito.ir.iet import retrieve_iteration_tree, FindNodes, Iteration, ParallelBlock
from devito.tools import as_tuple

Expand All @@ -23,7 +24,8 @@ def skipif(items, whole_module=False):
# Sanity check
accepted = set()
accepted.update({'device', 'device-C', 'device-openmp', 'device-openacc',
'device-aomp', 'cpu64-icc', 'cpu64-nvc', 'cpu64-arm'})
'device-aomp', 'cpu64-icc', 'cpu64-icpx', 'cpu64-nvc',
'cpu64-arm'})
accepted.update({'nompi', 'nodevice'})
unknown = sorted(set(items) - accepted)
if unknown:
Expand Down Expand Up @@ -69,6 +71,12 @@ def skipif(items, whole_module=False):
isinstance(configuration['platform'], Cpu64):
skipit = "`icc+cpu64` won't work with this test"
break
# Skip if it won't run with OneAPICompiler
if i == 'cpu64-icpx' and \
isinstance(configuration['compiler'], OneapiCompiler) and \
isinstance(configuration['platform'], Cpu64):
skipit = "`icpx+cpu64` won't work with this test"
break
# Skip if it won't run on Arm
if i == 'cpu64-arm' and isinstance(configuration['platform'], Arm):
skipit = "Arm doesn't support x86-specific instructions"
Expand Down
2 changes: 2 additions & 0 deletions tests/test_dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,8 @@ def test_affiness(self):
iterations = [i for i in FindNodes(Iteration).visit(op) if i.dim is not time]
assert all(i.is_Affine for i in iterations)

# Skipping this test with icpx, as it requires safe-math
@skipif('cpu64-icpx')
def test_sparse_time_function(self):
nt = 20

Expand Down
1 change: 1 addition & 0 deletions tests/test_dle.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ def test_incs_no_atomic(self):
assert 'collapse(1)' in str(op1)
assert 'atomic' not in str(op1)

@skipif('cpu64-icpx')
@pytest.mark.parametrize('exprs,simd_level,expected', [
(['Eq(y.symbolic_max, g[0, x], implicit_dims=(t, x))',
'Inc(h1[0, 0], 1, implicit_dims=(t, x, y))'],
Expand Down
1 change: 1 addition & 0 deletions tests/test_dse.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ def test_time_dependent_split(opt):

class TestLifting(object):

@skipif('cpu64-icpx')
@pytest.mark.parametrize('exprs,expected', [
# none (different distance)
(['Eq(y.symbolic_max, g[0, x], implicit_dims=(t, x))',
Expand Down

0 comments on commit 6e11659

Please sign in to comment.