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

LAMMPS: generate version from the source files when using software-commit #3485

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Changes from 9 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
92 changes: 53 additions & 39 deletions easybuild/easyblocks/l/lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,8 @@
_log = fancylogger.getLogger('easyblocks.lammps')


def translate_lammps_version(version):
def translate_lammps_version(version, path=""):
"""Translate the LAMMPS version into something that can be used in a comparison"""
items = [x for x in re.split('(\\d+)', version) if x]
if len(items) < 3:
raise ValueError("Version %s does not have (at least) 3 elements" % version)
month_map = {
"JAN": '01',
"FEB": '02',
Expand All @@ -178,7 +175,24 @@ def translate_lammps_version(version):
"NOV": '11',
"DEC": '12'
}
return '.'.join([items[2], month_map[items[1].upper()], '%02d' % int(items[0])])
items = [x for x in re.split('(\\d+)', version) if x]
if len(items) < 3:
raise ValueError("Version %s does not have (at least) 3 elements" % version)
try:
return '.'.join([items[2], month_map[items[1].upper()], '%02d' % int(items[0])])
except KeyError:
# avoid failing miserably under --module-only --force
if os.path.exists(path) and os.listdir(path):
with open("%ssrc/version.h" % (path)) as file:
laraPPr marked this conversation as resolved.
Show resolved Hide resolved
file_contents = file.read()
laraPPr marked this conversation as resolved.
Show resolved Hide resolved
lines = re.split('\n', file_contents)
regex = r'\d+ \S+ \d+'
result = re.search(regex, lines[0])
gen_version = result.group()
items = [x for x in re.split(' ', gen_version) if x]
return '.'.join([items[2], month_map[items[1].upper()], '%02d' % int(items[0])])
boegel marked this conversation as resolved.
Show resolved Hide resolved
else:
raise ValueError("Version %s cannot be generated" % version)


class EB_LAMMPS(CMakeMake):
Expand All @@ -194,28 +208,19 @@ def __init__(self, *args, **kwargs):
cuda_toolchain = hasattr(self.toolchain, 'COMPILER_CUDA_FAMILY')
self.cuda = cuda_dep or cuda_toolchain

# version 1.3.2 is used in the test suite to check easyblock can be initialised
if self.version != '1.3.2':
self.cur_version = translate_lammps_version(self.version)
else:
self.cur_version = self.version
self.ref_version = translate_lammps_version(ref_version)

self.pkg_prefix = 'PKG_'
if LooseVersion(self.cur_version) >= LooseVersion(self.ref_version):
self.pkg_user_prefix = self.pkg_prefix
else:
self.pkg_user_prefix = self.pkg_prefix + 'USER-'
def update_kokkos_cpu_mapping(self):
"""Add new kokkos_cpu_mapping to the list based on in which version they were added to LAMMPS"""
if LooseVersion(self.cur_version) >= LooseVersion(translate_lammps_version('31Mar2017')):
self.kokkos_cpu_mapping['neoverse_n1'] = 'ARMV81'
self.kokkos_cpu_mapping['neoverse_v1'] = 'ARMV81'

if LooseVersion(self.cur_version) >= LooseVersion(self.ref_version):
self.kokkos_prefix = 'Kokkos'
else:
self.kokkos_prefix = 'KOKKOS'
for cc in KOKKOS_GPU_ARCH_TABLE.keys():
KOKKOS_GPU_ARCH_TABLE[cc] = KOKKOS_GPU_ARCH_TABLE[cc].lower().title()
if LooseVersion(self.cur_version) >= LooseVersion(translate_lammps_version('21sep2021')):
self.kokkos_cpu_mapping['a64fx'] = 'A64FX'
self.kokkos_cpu_mapping['zen4'] = 'ZEN3'

self.kokkos_cpu_mapping = copy.deepcopy(KOKKOS_CPU_MAPPING)
self.update_kokkos_cpu_mapping()
if LooseVersion(self.cur_version) >= LooseVersion(translate_lammps_version('2Aug2023')):
self.kokkos_cpu_mapping['icelake'] = 'ICX'
self.kokkos_cpu_mapping['sapphirerapids'] = 'SPR'

@staticmethod
def extra_options(**kwargs):
Expand All @@ -231,23 +236,32 @@ def extra_options(**kwargs):
extra_vars['separate_build_dir'][0] = True
return extra_vars

def update_kokkos_cpu_mapping(self):
def prepare_step(self, *args, **kwargs):
"""Custom prepare step for LAMMPS."""
super(EB_LAMMPS, self).prepare_step(*args, **kwargs)

if LooseVersion(self.cur_version) >= LooseVersion(translate_lammps_version('31Mar2017')):
self.kokkos_cpu_mapping['neoverse_n1'] = 'ARMV81'
self.kokkos_cpu_mapping['neoverse_v1'] = 'ARMV81'
# version 1.3.2 is used in the test suite to check easyblock can be initialised
if self.version != '1.3.2':
self.cur_version = translate_lammps_version(self.version, path=self.start_dir)
else:
self.cur_version = self.version
self.ref_version = translate_lammps_version(ref_version)

if LooseVersion(self.cur_version) >= LooseVersion(translate_lammps_version('21sep2021')):
self.kokkos_cpu_mapping['a64fx'] = 'A64FX'
self.kokkos_cpu_mapping['zen4'] = 'ZEN3'
self.pkg_prefix = 'PKG_'
ocaisa marked this conversation as resolved.
Show resolved Hide resolved
if LooseVersion(self.cur_version) >= LooseVersion(self.ref_version):
self.pkg_user_prefix = self.pkg_prefix
else:
self.pkg_user_prefix = self.pkg_prefix + 'USER-'

if LooseVersion(self.cur_version) >= LooseVersion(translate_lammps_version('2Aug2023')):
self.kokkos_cpu_mapping['icelake'] = 'ICX'
self.kokkos_cpu_mapping['sapphirerapids'] = 'SPR'
if LooseVersion(self.cur_version) >= LooseVersion(self.ref_version):
self.kokkos_prefix = 'Kokkos'
else:
self.kokkos_prefix = 'KOKKOS'
for cc in KOKKOS_GPU_ARCH_TABLE.keys():
KOKKOS_GPU_ARCH_TABLE[cc] = KOKKOS_GPU_ARCH_TABLE[cc].lower().title()

def prepare_step(self, *args, **kwargs):
"""Custom prepare step for LAMMPS."""
super(EB_LAMMPS, self).prepare_step(*args, **kwargs)
self.kokkos_cpu_mapping = copy.deepcopy(KOKKOS_CPU_MAPPING)
self.update_kokkos_cpu_mapping()

# Unset LIBS when using both KOKKOS and CUDA - it will mix lib paths otherwise
if self.cfg['kokkos'] and self.cuda:
Expand Down Expand Up @@ -480,7 +494,7 @@ def install_step(self):

mkdir(site_packages, parents=True)

self.lammpsdir = os.path.join(self.builddir, '%s-*_%s' % (self.name.lower(), self.version))
self.lammpsdir = os.path.join(self.builddir, '%s-*%s' % (self.name.lower(), self.version))
smoors marked this conversation as resolved.
Show resolved Hide resolved
self.python_dir = os.path.join(self.lammpsdir, 'python')

# The -i flag is added through a patch to the lammps source file python/install.py
Expand Down