Skip to content

Commit

Permalink
feat: Support passing standard machine types to Google Batch by reusi…
Browse files Browse the repository at this point in the history
…ng the cpuPlatform field in the RuntimeAttributes
  • Loading branch information
javiergaitan committed Sep 17, 2024
1 parent 081318d commit 8b20d18
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,10 @@ class GcpBatchRequestFactoryImpl()(implicit gcsTransferConfiguration: GcsTransfe
googleLegacyMachineSelection = false,
jobLogger = jobLogger
)
// Don't set cpuPlatform if the field was used to specify standard machine type when submitting the GCP Batch request
val cpuPlatformBatchRequest = if (GcpBatchMachineConstraints.isStandardMachineType(cpuPlatform)) "" else cpuPlatform
val instancePolicy =
createInstancePolicy(cpuPlatform = cpuPlatform, spotModel, accelerators, allDisks, machineType = machineType)
createInstancePolicy(cpuPlatform = cpuPlatformBatchRequest, spotModel, accelerators, allDisks, machineType = machineType)
val locationPolicy = LocationPolicy.newBuilder.addAllowedLocations(zones).build
val allocationPolicy =
createAllocationPolicy(data, locationPolicy, instancePolicy.build, networkPolicy, gcpSa, accelerators)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import wom.format.MemorySize

import scala.math.{log, pow}

case class StandardMachineType(machineType: String) {}

/**
* Adjusts memory and cpu for custom machine types.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,28 @@ import cromwell.backend.google.batch.models.{
GcpBatchRuntimeAttributes,
N1CustomMachineType,
N2CustomMachineType,
N2DCustomMachineType
N2DCustomMachineType,
StandardMachineType
}
import cromwell.core.logging.JobLogger
import eu.timepit.refined.api.Refined
import eu.timepit.refined.numeric.Positive
import scala.util.matching.Regex
import wdl4s.parser.MemoryUnit
import wom.format.MemorySize

object GcpBatchMachineConstraints {
private val machineTypePattern: Regex = """^\w{2}\w?-\w+-\w+$""".r

def machineType(memory: MemorySize,
cpu: Int Refined Positive,
cpuPlatformOption: Option[String],
googleLegacyMachineSelection: Boolean,
jobLogger: JobLogger
): String =
if (googleLegacyMachineSelection) {
if (isStandardMachineType(cpuPlatformOption.getOrElse(""))) {
StandardMachineType(cpuPlatformOption.getOrElse("")).machineType
} else if (googleLegacyMachineSelection) {
s"predefined-$cpu-${memory.to(MemoryUnit.MB).amount.intValue()}"
} else {
// If someone requests Intel Cascade Lake or Intel Ice Lake as their CPU platform then switch the machine type to n2.
Expand All @@ -33,4 +39,6 @@ object GcpBatchMachineConstraints {
}
customMachineType.machineType(memory, cpu, jobLogger)
}

def isStandardMachineType(machineType: String): Boolean = machineTypePattern.matches(machineType)
}

0 comments on commit 8b20d18

Please sign in to comment.