-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding params for optimization level and device type; adding support …
…for distributing loads on multiple GPUs
- Loading branch information
Showing
3 changed files
with
80 additions
and
19 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
deep-learning/src/main/scala/com/microsoft/ml/spark/GPUUtils.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.microsoft.ml.spark | ||
|
||
import org.apache.spark.TaskContext | ||
|
||
import scala.util.Random | ||
|
||
object GPUUtils { | ||
@transient | ||
private val Rand = new Random() | ||
|
||
/** | ||
* Select a random GPU device on an executor node. | ||
* @return None if there is no GPU devices found; a randomly selected device id otherwise. | ||
*/ | ||
def selectRandomGpu: Option[Int] = { | ||
TaskContext.get().resources().get("gpu").map{ | ||
resource => | ||
val addresses = resource.addresses.map(_.toInt) | ||
val i = Rand.nextInt() % addresses.length | ||
addresses(i) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters