diff --git a/easybuild/toolchains/compiler/gcc.py b/easybuild/toolchains/compiler/gcc.py index 6a75a9e877..663b6385f6 100644 --- a/easybuild/toolchains/compiler/gcc.py +++ b/easybuild/toolchains/compiler/gcc.py @@ -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 } diff --git a/easybuild/tools/systemtools.py b/easybuild/tools/systemtools.py index 3fefc1f95e..126bbb68c0 100644 --- a/easybuild/tools/systemtools.py +++ b/easybuild/tools/systemtools.py @@ -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 diff --git a/test/framework/systemtools.py b/test/framework/systemtools.py index 73831b6bdb..36aec5a88b 100644 --- a/test/framework/systemtools.py +++ b/test/framework/systemtools.py @@ -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 @@ -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 @@ -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()