Skip to content
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

example: small cleanup of tti for easier reuse #2294

Merged
merged 3 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 13 additions & 2 deletions devito/arch/archinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
'INTEL64', 'SNB', 'IVB', 'HSW', 'BDW', 'KNL', 'KNL7210',
'SKX', 'KLX', 'CLX', 'CLK', 'SPR',
# ARM CPUs
'AMD', 'ARM', 'M1', 'GRAVITON',
'AMD', 'ARM', 'AppleArm', 'M1', 'M2', 'M3', 'GRAVITON',
# Other legacy CPUs
'POWER8', 'POWER9',
# Generic GPUs
Expand Down Expand Up @@ -709,6 +709,15 @@ class Arm(Cpu64):
known_isas = ('fp', 'asimd', 'asimdrdm')


class AppleArm(Arm):

@cached_property
def march(self):
sysinfo = run(["sysctl", "-n", "machdep.cpu.brand_string"],
stdout=PIPE, stderr=DEVNULL).stdout.decode("utf-8")
return sysinfo.split(' ')[1].lower()


class Amd(Cpu64):

known_isas = ('cpp', 'sse', 'avx', 'avx2')
Expand Down Expand Up @@ -839,7 +848,9 @@ def march(cls):

ARM = Arm('arm')
GRAVITON = Arm('graviton')
M1 = Arm('m1')
M1 = AppleArm('m1')
M2 = AppleArm('m2')
M3 = AppleArm('m3')

AMD = Amd('amd')

Expand Down
12 changes: 7 additions & 5 deletions devito/arch/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from codepy.toolchain import (GCCToolchain,
call_capture_output as _call_capture_output)

from devito.arch import (AMDGPUX, Cpu64, M1, NVIDIAX, POWER8, POWER9, GRAVITON,
from devito.arch import (AMDGPUX, Cpu64, AppleArm, NVIDIAX, POWER8, POWER9, GRAVITON,
IntelDevice, get_nvidia_cc, check_cuda_runtime,
get_m1_llvm_path)
from devito.exceptions import CompilationError
Expand Down Expand Up @@ -486,14 +486,16 @@ def __init_finalize__(self, **kwargs):
'-fopenmp-targets=amdgcn-amd-amdhsa',
'-Xopenmp-target=amdgcn-amd-amdhsa']
self.ldflags += ['-march=%s' % platform.march]
elif platform is M1:
elif isinstance(platform, AppleArm):
# NOTE:
# Apple M1 supports OpenMP through Apple's LLVM compiler.
# Apple Mx supports OpenMP through Apple's LLVM compiler.
# The compiler can be installed with Homebrew or can be built from scratch.
# Check if installed and set compiler flags accordingly
llvmm1 = get_m1_llvm_path(language)
if llvmm1 and language == 'openmp':
self.ldflags += ['-mcpu=apple-m1', '-fopenmp', '-L%s' % llvmm1['libs']]
mx = platform.march
self.ldflags += ['-mcpu=apple-%s' % mx,
'-fopenmp', '-L%s' % llvmm1['libs']]
self.cflags += ['-Xclang', '-I%s' % llvmm1['include']]
else:
if platform in [POWER8, POWER9]:
Expand Down Expand Up @@ -895,7 +897,7 @@ def __new__(cls, *args, **kwargs):
platform = kwargs.pop('platform', configuration['platform'])
language = kwargs.pop('language', configuration['language'])

if platform is M1:
if isinstance(platform, AppleArm):
_base = ClangCompiler
elif isinstance(platform, IntelDevice):
_base = OneapiCompiler
Expand Down
2 changes: 1 addition & 1 deletion devito/types/dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ def _arg_defaults(self, _min=None, size=None, alias=None):
except AttributeError:
factor = dim._factor

defaults[dim.parent.max_name] = range(1, factor*size - 1)
defaults[dim.parent.max_name] = range(0, factor*size - 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpicking: you can omit the 0, part

why was there a 1 before?
is it worth adding a test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the 1 was there for any specific reason, just a "run at least one step" but not really needed


return defaults

Expand Down
8 changes: 4 additions & 4 deletions examples/seismic/preset_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,12 @@ def demo_model(preset, **kwargs):
for i in range(1, nlayers):
v[..., i*int(shape[-1] / nlayers):] = vp_i[i] # Bottom velocity

epsilon = .3*(v - 1.5)
delta = .2*(v - 1.5)
theta = .5*(v - 1.5)
epsilon = .1*(v - vp_top)
delta = .05*(v - vp_top)
theta = .5*(v - vp_top)
phi = None
if len(shape) > 2 and preset.lower() not in ['layers-tti-noazimuth']:
phi = .25*(v - 1.5)
phi = .25*(v - vp_top)

if density:
kwargs['b'] = Gardners(v)
Expand Down
Loading
Loading