iprbench/iprbench/targethosts.py

67 lines
3.3 KiB
Python

from typing import Set
from .core import ITargetHost
import subprocess
import re
import logging
class GraffyWs2(ITargetHost):
host_name: str
available_packages: Set[str]
def __init__(self):
self.host_name = 'graffy-ws2'
self.available_packages = {'gfortran'}
def get_package_default_version(self, package_id: str) -> str:
if package_id not in self.available_packages:
raise ValueError(f'ifort is not available on {self.host_name}')
elif package_id == 'gfortran':
completed_process = subprocess.run('gfortran --version', capture_output=True, check=False, shell=True)
if completed_process.returncode != 0:
raise ValueError(f'gfortran is not available on {self.host_name}')
else:
# GNU Fortran (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
# Copyright (C) 2019 Free Software Foundation, Inc.
# This is free software; see the source for copying conditions. There is NO
# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
first_line = completed_process.stdout.decode('utf-8').split('\n')[0]
logging.debug('first line: %s', first_line)
gfortran_version = first_line.split(' ')[-1]
assert re.match(r'[0-9]+\.[0-9]+\.[0-9]+', gfortran_version), f'unexpected format for gfortran version {gfortran_version}'
return gfortran_version
else:
assert False, f'unhandled package: {package_id}'
def get_package_activation_command(self, package_id: str, package_version: str) -> str:
if package_id not in self.available_packages:
raise ValueError(f'ifort is not available on {self.host_name}')
elif package_id == 'gfortran':
current_version = self.get_package_default_version(package_id)
if current_version != package_version:
raise ValueError(f'gfortran version {package_version} only gfortran version {current_version} is available on {self.host_name}')
return '' # no special instructions are required to activate the current gfortran version
else:
assert False, f'unhandled package: {package_id}'
class IprClusterNode(ITargetHost):
def get_latest_version_for_env_module(self, package_env_module: str):
# package_env_module: eg compilers/ifort
# graffy@alambix-frontal:~$ module help compilers/ifort/latest
# -------------------------------------------------------------------
# Module Specific Help for /usr/share/modules/modulefiles/compilers/ifort/latest:
# Provides the same functionality as the command '/opt/intel/oneapi-2024.2.1/compiler/latest/env/vars.sh intel64'
# -------------------------------------------------------------------
# graffy@alambix-frontal:~$ ls -l /usr/share/modules/modulefiles/compilers/ifort/latest
# lrwxrwxrwx 1 root root 9 18 nov. 02:11 /usr/share/modules/modulefiles/compilers/ifort/latest -> 2021.13.1
raise NotImplementedError()
def get_package_default_version(self, package_id: str) -> str:
if package_id == 'ifort':
return self.get_latest_version_for_env_module('compilers/ifort')
else:
assert False, f'unhandled package: {package_id}'