Skip to content

Commit

Permalink
Now using python native grep function instead of external command
Browse files Browse the repository at this point in the history
  • Loading branch information
PalNilsson committed Oct 17, 2024
1 parent e4e9696 commit 45a5131
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion PILOTVERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.9.1.8
3.9.1.9
30 changes: 28 additions & 2 deletions pilot/util/auxiliary.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# under the License.
#
# Authors:
# - Paul Nilsson, [email protected], 2017-23
# - Paul Nilsson, [email protected], 2017-24

"""Auxiliary functions."""

Expand Down Expand Up @@ -45,7 +45,10 @@
)
from pilot.common.errorcodes import ErrorCodes
from pilot.util.container import execute
from pilot.util.filehandling import dump
from pilot.util.filehandling import (
dump,
grep
)

zero_depth_bases = (str, bytes, Number, range, bytearray)
iteritems = 'items'
Expand Down Expand Up @@ -484,6 +487,29 @@ def cut_output(txt: str, cutat: int = 1024, separator: str = '\n[...]\n') -> str


def has_instruction_sets(instruction_sets: list) -> str:
"""
Determine whether a given CPU instruction set is available.
The function will use grep to search in /proc/cpuinfo (both in upper and lower case).
Example: instruction_sets = ['AVX', 'AVX2', 'SSE4_2', 'XXX'] -> "AVX|AVX2|SSE4_2"
:param instruction_sets: instruction set (e.g. AVX2) (list)
:return: string of pipe-separated instruction sets (str).
"""
ret = ""

for instr in instruction_sets:
pattern = re.compile(fr'{instr.lower()}[^ ]*', re.IGNORECASE)
out = grep(patterns=[pattern], file_name="/proc/cpuinfo")

for stdout in out:
if instr.upper() not in ret and (instr.lower() in stdout.split() or instr.upper() in stdout.split()):
ret += f'|{instr.upper()}' if ret else instr.upper()

return ret


def has_instruction_sets_old(instruction_sets: list) -> str:
"""
Determine whether a given list of CPU instruction sets is available.
Expand Down
2 changes: 1 addition & 1 deletion pilot/util/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
RELEASE = '3' # released number should be fixed at 3 for Pilot 3
VERSION = '9' # version number is '1' for first release, '0' until then, increased for bigger updates
REVISION = '1' # revision number should be reset to '0' for every new version release, increased for small updates
BUILD = '8' # build number should be reset to '1' for every new development cycle
BUILD = '9' # build number should be reset to '1' for every new development cycle

SUCCESS = 0
FAILURE = 1
Expand Down

0 comments on commit 45a5131

Please sign in to comment.