func allocateGPUs(mpiJob *kubeflow.MPIJob, gpusPerNode int, done bool) (workerReplicas int, gpusPerWorker int, err error) {
	workerReplicas = 0
	gpusPerWorker = 0
	err = nil
	if mpiJob.Spec.GPUs != nil {
		totalGPUs := int(*mpiJob.Spec.GPUs)
		if totalGPUs < gpusPerNode {
			workerReplicas = 1
			gpusPerWorker = totalGPUs
		} else if totalGPUs%gpusPerNode == 0 {
			workerReplicas = totalGPUs / gpusPerNode
			gpusPerWorker = gpusPerNode
		} else {
			err = fmt.Errorf("specified #GPUs is not a multiple of GPUs per node (%d)", gpusPerNode)
		}
	} else if mpiJob.Spec.Replicas != nil {
		workerReplicas = int(*mpiJob.Spec.Replicas)
		container := mpiJob.Spec.Template.Spec.Containers[0]
		if container.Resources.Limits != nil {
			if val, ok := container.Resources.Limits[gpuResourceName]; ok {
				gpus, _ := val.AsInt64()
				gpusPerWorker = int(gpus)
			}
		}
	}
	if done {
		workerReplicas = 0
	}
	return workerReplicas, gpusPerWorker, err
}
// allocateGPUs allocates the worker replicas and GPUs per worker.
allocateGPUs allocates the worker replicas and GPUs per worker.
// allocateGPUs allocates the worker replicas and GPUs per worker .
func allocateGPUs(mpiJob *kubeflow.MPIJob, gpusPerNode int, done bool) (workerReplicas int, gpusPerWorker int, err error) {
	workerReplicas = 0
	gpusPerWorker = 0
	err = nil
	if mpiJob.Spec.GPUs != nil {
		totalGPUs := int(*mpiJob.Spec.GPUs)
		if totalGPUs < gpusPerNode {
			workerReplicas = 1
			gpusPerWorker = totalGPUs
		} else if totalGPUs%gpusPerNode == 0 {
			workerReplicas = totalGPUs / gpusPerNode
			gpusPerWorker = gpusPerNode
		} else {
			err = fmt.Errorf("specified #GPUs is not a multiple of GPUs per node (%d)", gpusPerNode)
		}
	} else if mpiJob.Spec.Replicas != nil {
		workerReplicas = int(*mpiJob.Spec.Replicas)
		container := mpiJob.Spec.Template.Spec.Containers[0]
		if container.Resources.Limits != nil {
			if val, ok := container.Resources.Limits[gpuResourceName]; ok {
				gpus, _ := val.AsInt64()
				gpusPerWorker = int(gpus)
			}
		}
	}
	if done {
		workerReplicas = 0
	}
	return workerReplicas, gpusPerWorker, err
}
func allocateGPUs ( mpiJob * kubeflow . MPIJob , gpusPerNode int , done bool ) ( workerReplicas int , gpusPerWorker int , err error ) { workerReplicas = 0 gpusPerWorker = 0 err = nil if mpiJob . Spec . GPUs != nil { totalGPUs := int ( * mpiJob . Spec . GPUs ) if totalGPUs < gpusPerNode { workerReplicas = 1 gpusPerWorker = totalGPUs } else if totalGPUs % gpusPerNode == 0 { workerReplicas = totalGPUs / gpusPerNode gpusPerWorker = gpusPerNode } else { err = fmt . Errorf ( " " , gpusPerNode ) } } else if mpiJob . Spec . Replicas != nil { workerReplicas = int ( * mpiJob . Spec . Replicas ) container := mpiJob . Spec . Template . Spec . Containers [ 0 ] if container . Resources . Limits != nil { if val , ok := container . Resources . Limits [ gpuResourceName ] ; ok { gpus , _ := val . AsInt64 ( ) gpusPerWorker = int ( gpus ) } } } if done { workerReplicas = 0 } return workerReplicas , gpusPerWorker , err }
allocateGPUs allocates the worker replicas and GPUs per worker.
allocateGPUs allocates the worker replicas and GPUs per worker .