Skip to content
Open
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
13 changes: 11 additions & 2 deletions devito/arch/archinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,15 @@ def lscpu():
return {}


def get_apple_platform(brand):
"""
The registered AppleArm matching an Apple-silicon brand string, e.g.
"Apple M2 Pro". Chips not registered yet map to the newest registered one.
"""
key = brand.lower().split('apple ')[1].split()[0]
return platform_registry.get(key, platform_registry['m3'])


@memoized_func
def get_platform():
"""Attempt Platform autodetection."""
Expand Down Expand Up @@ -753,8 +762,8 @@ def get_platform():
return platform_registry['power8']
elif 'arm' in brand:
return platform_registry['arm']
elif 'm1' in brand:
return platform_registry['m1']
elif 'apple m' in brand:
return get_apple_platform(brand)
elif 'amd' in brand:
return platform_registry['amd']
except:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from devito import configuration, switchconfig
from devito.arch import BLACKWELL, NVIDIAX
from devito.arch.archinfo import AppleArm, get_apple_platform
from devito.arch.compiler import (
CudaCompiler, GNUCompiler, compiler_registry, sniff_compiler_version
)
Expand All @@ -25,6 +26,20 @@ def test_gcc(cc):
assert cc in compiler_registry


@pytest.mark.parametrize("brand, expected", [
("Apple M1", 'm1'),
("Apple M1 (Virtual)", 'm1'),
("Apple M2 Pro", 'm2'),
("Apple M3 Max", 'm3'),
("Apple M4 Max", 'm3'),
("Apple M5", 'm3'),
])
def test_apple_platform(brand, expected):
platform = get_apple_platform(brand)
assert isinstance(platform, AppleArm)
assert platform.name == expected


def test_switcharch():
old_compiler = configuration['compiler']
with switchconfig(compiler='gcc-4.9'):
Expand Down
Loading