-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-27024] Executor interface for cluster managers to support GPU and other resources #24394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
core/src/main/scala/org/apache/spark/ResourceDiscoverer.scala
This file contains hidden or 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,100 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark | ||
|
|
||
| import java.io.File | ||
|
|
||
| import org.apache.spark.internal.Logging | ||
| import org.apache.spark.internal.config._ | ||
| import org.apache.spark.util.Utils.executeAndGetOutput | ||
|
|
||
| /** | ||
| * Discovers resources (GPUs/FPGAs/etc). | ||
| * This class find resources by running and parses the output of the user specified script | ||
| * from the config spark.{driver/executor}.{resourceType}.discoveryScript. | ||
| * The output of the script it runs is expected to be a String that is in the format of | ||
| * count:unit:comma-separated list of addresses, where the list of addresses is | ||
| * specific for that resource type. The user is responsible for interpreting the address. | ||
| */ | ||
| private[spark] object ResourceDiscoverer extends Logging { | ||
|
|
||
| def findResources(sparkconf: SparkConf, isDriver: Boolean): Map[String, ResourceInformation] = { | ||
| val prefix = if (isDriver) { | ||
| SPARK_DRIVER_RESOURCE_PREFIX | ||
| } else { | ||
| SPARK_EXECUTOR_RESOURCE_PREFIX | ||
| } | ||
| // get unique resource types | ||
| val resourceTypes = sparkconf.getAllWithPrefix(prefix).map(x => x._1.split('.')(0)).toSet | ||
| resourceTypes.map{ rtype => { | ||
| val rInfo = getResourceAddrsForType(sparkconf, prefix, rtype) | ||
| (rtype -> rInfo) | ||
| }}.toMap | ||
| } | ||
|
|
||
| private def getResourceAddrsForType( | ||
| sparkconf: SparkConf, | ||
| prefix: String, | ||
| resourceType: String): ResourceInformation = { | ||
| val discoveryConf = prefix + resourceType + SPARK_RESOURCE_DISCOVERY_SCRIPT_POSTFIX | ||
| val script = sparkconf.getOption(discoveryConf) | ||
| val result = if (script.nonEmpty) { | ||
| val scriptFile = new File(script.get) | ||
| // check that script exists and try to execute | ||
| if (scriptFile.exists()) { | ||
| try { | ||
| val output = executeAndGetOutput(Seq(script.get), new File(".")) | ||
| parseResourceTypeString(resourceType, output) | ||
| } catch { | ||
| case e @ (_: SparkException | _: NumberFormatException) => | ||
| throw new SparkException(s"Error running the resource discovery script: $scriptFile" + | ||
| s" for $resourceType", e) | ||
| } | ||
| } else { | ||
| throw new SparkException(s"Resource script: $scriptFile to discover $resourceType" + | ||
| s" doesn't exist!") | ||
| } | ||
| } else { | ||
| throw new SparkException(s"User is expecting to use $resourceType resources but " + | ||
| s"didn't specify a script via conf: $discoveryConf, to find them!") | ||
| } | ||
| result | ||
| } | ||
|
|
||
| // this parses a resource information string in the format: | ||
| // count:unit:comma-separated list of addresses | ||
| // The units and addresses are optional. The idea being if the user has something like | ||
| // memory you don't have addresses to assign out. | ||
| def parseResourceTypeString(rtype: String, rInfoStr: String): ResourceInformation = { | ||
| // format should be: count:unit:addr1,addr2,addr3 | ||
| val singleResourceType = rInfoStr.split(':') | ||
| if (singleResourceType.size < 3) { | ||
| throw new SparkException("Format of the resourceAddrs parameter is invalid," + | ||
| " please specify all of count, unit, and addresses in the format:" + | ||
| " count:unit:addr1,addr2,addr3") | ||
| } | ||
| // format should be: addr1,addr2,addr3 | ||
| val splitAddrs = singleResourceType(2).split(',').map(_.trim()) | ||
| val retAddrs = if (splitAddrs.size == 1 && splitAddrs(0).isEmpty()) { | ||
| Array.empty[String] | ||
| } else { | ||
| splitAddrs | ||
| } | ||
| new ResourceInformation(rtype, singleResourceType(1), singleResourceType(0).toLong, retAddrs) | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletions
46
core/src/main/scala/org/apache/spark/ResourceInformation.scala
This file contains hidden or 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,46 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark | ||
|
|
||
| import org.apache.spark.annotation.Evolving | ||
|
|
||
| /** | ||
| * Class to hold information about a type of Resource. A resource could be a GPU, FPGA, etc. | ||
| * The array of addresses are resource specific and its up to the user to interpret the address. | ||
| * The units and addresses could be empty if they doesn't apply to that resource. | ||
| * | ||
| * One example is GPUs, where the addresses would be the indices of the GPUs, the count would be the | ||
| * number of GPUs and the units would be an empty string. | ||
| * | ||
| * @param name the name of the resource | ||
| * @param units the units of the resources, can be an empty string if units don't apply | ||
| * @param count the number of resources available | ||
| * @param addresses an optional array of strings describing the addresses of the resource | ||
| */ | ||
| @Evolving | ||
| case class ResourceInformation( | ||
| private val name: String, | ||
| private val units: String, | ||
| private val count: Long, | ||
| private val addresses: Array[String] = Array.empty) { | ||
|
|
||
| def getName(): String = name | ||
| def getUnits(): String = units | ||
| def getCount(): Long = count | ||
| def getAddresses(): Array[String] = addresses | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -185,7 +185,8 @@ class CoarseGrainedSchedulerBackend(scheduler: TaskSchedulerImpl, val rpcEnv: Rp | |
|
|
||
| override def receiveAndReply(context: RpcCallContext): PartialFunction[Any, Unit] = { | ||
|
|
||
| case RegisterExecutor(executorId, executorRef, hostname, cores, logUrls, attributes) => | ||
| case RegisterExecutor(executorId, executorRef, hostname, cores, logUrls, | ||
| attributes, resources) => | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realize this isn't used anywhere at this point, the follow on jiras for scheduler will use it, this seemed like a good point to split the functionality. |
||
| if (executorDataMap.contains(executorId)) { | ||
| executorRef.send(RegisterExecutorFailed("Duplicate executor ID: " + executorId)) | ||
| context.reply(true) | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thinking about this some more I think I should make this json format so its more extensible in the future and not as ugly on the command line.