Skip to content

Commit

Permalink
fix(scripts): use guestCpus instead of parsed third term
Browse files Browse the repository at this point in the history
Normal machine types follow <family>-<class>-<cpus>.

Accelerator optimized machines follow <family>-<class>-<gpus>.

fix(scripts): accelerator optimized machine type socket handling

fix: simplify fetching template.machine_info
  • Loading branch information
SkylerMalinowski authored and bsngardner committed Aug 7, 2023
1 parent 7e596c0 commit bfb6953
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file.
## \[5.7.6\]

- Prefix user visible errors with its source.
- Fix accelerator optimized machine type SMT handling.
- Fix accelerator optimized machine type socket handling.

## \[5.7.5\]

Expand Down
18 changes: 6 additions & 12 deletions scripts/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,22 +1067,16 @@ def get_insert_operations(group_ids, flt=None, project=None, compute=compute):


def machine_type_sockets(template):
pattern = re.compile("^(?P<family>[^-]+)-(?P<type>[^-]+)-(?P<core>[^-]+)$")
pattern = re.compile("^(?P<family>[^-]+)")
m = pattern.match(template.machineType)
if not m:
raise Exception(f"template {template} does not match expected regex")
family = m.group("family")
try:
core_count = int(m.group("core"))
except ValueError:
log.warning(
f"core count in machine type {template.machineType} is not an integer. Default to 1 socket."
)
return 1
guestCpus: int = int(template.machine_info.guestCpus)
socket_count = dict.get(
{
"h3": 2,
"c2d": 2 if core_count > 56 else 1,
"c2d": 2 if guestCpus > 56 else 1,
},
family,
1, # assume 1 socket for all other families
Expand All @@ -1092,11 +1086,11 @@ def machine_type_sockets(template):

def isSmt(template):
machineType: str = template.machineType
guestCpus: int = int(template.machine_info.guestCpus)

pattern = re.compile("^(?P<family>[^-]+)-(?P<type>[^-]+)-(?P<core>[^-]+)$")
pattern = re.compile("^(?P<family>[^-]+)")
matches = pattern.match(machineType)
machineTypeFamily: str = matches["family"]
machineTypeCore: int = int(matches["core"])

# https://cloud.google.com/compute/docs/cpu-platforms
noSmtFamily = [
Expand All @@ -1106,7 +1100,7 @@ def isSmt(template):
]
if machineTypeFamily in noSmtFamily:
return False
elif machineTypeCore == 1:
elif guestCpus == 1:
return False
return True

Expand Down

0 comments on commit bfb6953

Please sign in to comment.