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
1 change: 1 addition & 0 deletions easybuild/toolchains/compiler/gcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class Gcc(Compiler):
# no support for -march on POWER; implies -mtune=native
(systemtools.POWER, systemtools.POWER): '-mcpu=native',
(systemtools.POWER, systemtools.POWER_LE): '-mcpu=native',
(systemtools.RISCV64, systemtools.RISCV): '-march=' + systemtools.get_isa_riscv(), # use all extensions
(systemtools.X86_64, systemtools.AMD): '-march=native', # implies -mtune=native
(systemtools.X86_64, systemtools.INTEL): '-march=native', # implies -mtune=native
}
Expand Down
24 changes: 24 additions & 0 deletions easybuild/tools/systemtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,30 @@ def get_cpu_features():
return cpu_feat


def get_isa_riscv():
"""
Get supported ISA string
"""
isa_string = 'rv64imafdc'
os_type = get_os_type()
if os_type == LINUX:
if is_readable(PROC_CPUINFO_FP):
_log.debug("Trying to determine ISA string on Linux via %s", PROC_CPUINFO_FP)
proc_cpuinfo = read_file(PROC_CPUINFO_FP)
isa_regex = re.compile(r"^isa\s*:\s*(.*)")
res = isa_regex.search(proc_cpuinfo)
if res:
isa_string = res.group(1)
_log.debug("Found ISA string using regex '%s': %s", isa_regex.pattern, isa_string)
else:
_log.debug("Failed to determine ISA string from %s", PROC_CPUINFO_FP)
else:
_log.debug("%s not found to determine ISA string", PROC_CPUINFO_FP)
else:
_log.debug("Could not determine ISA string (OS: %s), defaulting to: %s", os_type, isa_string)
return isa_string


def get_gpu_info():
"""
Get the GPU info
Expand Down
44 changes: 44 additions & 0 deletions test/framework/systemtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
from easybuild.tools.systemtools import det_parallelism, det_pypkg_version, get_avail_core_count
from easybuild.tools.systemtools import get_cuda_object_dump_raw, get_cuda_architectures, get_cpu_arch_name
from easybuild.tools.systemtools import get_cpu_architecture, get_cpu_family, get_cpu_features, get_cpu_model
from easybuild.tools.systemtools import get_isa_riscv
from easybuild.tools.systemtools import get_cpu_speed, get_cpu_vendor, get_gcc_version, get_glibc_version, get_os_type
from easybuild.tools.systemtools import get_os_name, get_os_version, get_platform_name, get_shared_lib_ext
from easybuild.tools.systemtools import get_system_info, get_total_memory, get_linked_libs_raw
Expand All @@ -60,6 +61,31 @@

PROC_CPUINFO_TXT = None

PROC_CPUINFO_TXT_RISCV64 = """processor : 0
hart : 2
isa : rv64imafdc
mmu : sv39
uarch : sifive,u74-mc

processor : 1
hart : 1
isa : rv64imafdc
mmu : sv39
uarch : sifive,u74-mc

processor : 2
hart : 3
isa : rv64imafdc
mmu : sv39
uarch : sifive,u74-mc

processor : 3
hart : 4
isa : rv64imafdc
mmu : sv39
uarch : sifive,u74-mc
"""

PROC_CPUINFO_TXT_RASPI2 = """processor : 0
model name : ARMv7 Processor rev 5 (v7l)
BogoMIPS : 57.60
Expand Down Expand Up @@ -720,6 +746,24 @@ def test_cpu_features_darwin(self):
'vme', 'vmx', 'x2apic', 'xd', 'xsave']
self.assertEqual(get_cpu_features(), expected)

def test_isa_native(self):
"""Test getting ISA string."""
isa_string = get_isa_riscv()
self.assertIsInstance(isa_string, str)

def test_isa_linux(self):
"""Test getting ISA string (mocked for Linux)."""
st.get_os_type = lambda: st.LINUX
st.read_file = mocked_read_file
st.is_readable = lambda fp: mocked_is_readable(PROC_CPUINFO_FP, fp)

# tweak global constant used by mocked_read_file
global PROC_CPUINFO_TXT

PROC_CPUINFO_TXT = PROC_CPUINFO_TXT_RISCV64
expected = 'rv64imafdc'
self.assertEqual(get_isa_riscv(), expected)

def test_cpu_architecture_native(self):
"""Test getting the CPU architecture."""
arch = get_cpu_architecture()
Expand Down