Skip to content
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

Qualification tool: Operator mapping from plugin to CSV file #5298

Merged
merged 3 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,18 @@
<java classname="com.nvidia.spark.rapids.SupportedOpsForTools" failonerror="true">
<arg value="${project.basedir}/../tools/src/main/resources/supportedDataSource.csv"/>
</java>
<java classname="com.nvidia.spark.rapids.SupportedOpsForTools" failonerror="true">
<arg value="${project.basedir}/../tools/src/main/resources/operatorsScore.csv"/>
<arg value="operatorScore"/>
</java>
<java classname="com.nvidia.spark.rapids.SupportedOpsForTools" failonerror="true">
<arg value="${project.basedir}/../tools/src/main/resources/supportedExecs.csv"/>
<arg value="execs"/>
</java>
<java classname="com.nvidia.spark.rapids.SupportedOpsForTools" failonerror="true">
<arg value="${project.basedir}/../tools/src/main/resources/supportedExprs.csv"/>
<arg value="exprs"/>
</java>
</ac:then>
</ac:if>
</target>
Expand Down
130 changes: 126 additions & 4 deletions sql-plugin/src/main/scala/com/nvidia/spark/rapids/TypeChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import java.time.ZoneId
import ai.rapids.cudf.DType
import com.nvidia.spark.rapids.shims.{GpuTypeShims, TypeSigUtil}

import org.apache.spark.internal.Logging
import org.apache.spark.sql.catalyst.expressions.{Attribute, Expression, UnaryExpression, WindowSpecDefinition}
import org.apache.spark.sql.types._

Expand Down Expand Up @@ -2147,11 +2148,28 @@ object SupportedOpsDocs {
}
}

object SupportedOpsForTools {
object SupportedOpsForTools extends Logging {
tgravescs marked this conversation as resolved.
Show resolved Hide resolved

private lazy val allSupportedTypes =
TypeSigUtil.getAllSupportedTypes()

// if a string contains what we are going to use for a delimiter, replace
// it with something else
def replaceDelimiter(str: String, delimiter: String): String = {
tgravescs marked this conversation as resolved.
Show resolved Hide resolved
if (str != null && str.contains(delimiter)) {
val replaceWith = if (delimiter.equals(",")) {
";"
} else if (delimiter.equals(";")) {
":"
} else {
";"
}
str.replace(delimiter, replaceWith)
} else {
str
}
}

private def outputSupportIO() {
// Look at what we have for defaults for some configs because if the configs are off
// it likely means something isn't completely compatible.
Expand Down Expand Up @@ -2193,15 +2211,119 @@ object SupportedOpsForTools {
}
}

def help(): Unit = {
outputSupportIO()
private def operatorMappingWithScore(): Unit = {
val header = Seq("CPUOperator", "Score")
println(header.mkString(","))
GpuOverrides.execs.values.toSeq.sortBy(_.tag.toString).foreach { rule =>
val checks = rule.getChecks
if (rule.isVisible && checks.forall(_.shown)) {
val cpuName = rule.tag.runtimeClass.getSimpleName
val allCols = Seq(cpuName, "2")
tgravescs marked this conversation as resolved.
Show resolved Hide resolved
println(s"${allCols.map(replaceDelimiter(_, ",")).mkString(",")}")
tgravescs marked this conversation as resolved.
Show resolved Hide resolved
}
}

GpuOverrides.expressions.values.toSeq.sortBy(_.tag.runtimeClass.getSimpleName).foreach { rule =>
val checks = rule.getChecks
if (rule.isVisible && checks.forall(_.shown)) {
val cpuName = rule.tag.runtimeClass.getSimpleName
val allCols = Seq(cpuName, "3")
println(s"${allCols.map(replaceDelimiter(_, ",")).mkString(",")}")
}
}
}

private def outputSupportedExecs(): Unit = {
// TODO Look at what we have for defaults for some configs because if the configs are off
tgravescs marked this conversation as resolved.
Show resolved Hide resolved
// it likely means something isn't completely compatible.
val conf = new RapidsConf(Map.empty[String, String])
val types = allSupportedTypes.toSeq
val header = Seq("Exec", "Supported", "Notes", "Params") ++ types
println(header.mkString(","))
GpuOverrides.execs.values.toSeq.sortBy(_.tag.toString).foreach { rule =>
val checks = rule.getChecks
if (rule.isVisible && checks.forall(_.shown)) {
val execChecks = checks.get.asInstanceOf[ExecChecks]
val allData = allSupportedTypes.map { t =>
(t, execChecks.support(t))
}.toMap

val notes = execChecks.supportNotes
val inputs = allData.values.head.keys

val firstCol = Seq(rule.tag.runtimeClass.getSimpleName)
val thirdCol = Seq(rule.notes().getOrElse("None"))
inputs.foreach { input =>
val named = notes.get(input)
.map(l => input + "(" + l.mkString(";") + ")")
.getOrElse(input)
val supportLevelOps = allSupportedTypes.toSeq.map { t =>
allData(t)(input).text
}
val isSupportedExec = Seq(if (supportLevelOps.forall(_.equals("NS"))) "NS" else "S")
val allCols = (firstCol ++ isSupportedExec ++ thirdCol ++ Seq(named) ++ supportLevelOps)
println(s"${allCols.map(replaceDelimiter(_, ",")).mkString(",")}")
}
}
}
}

private def outputSupportedExpressions(): Unit = {
// TODO Look at what we have for defaults for some configs because if the configs are off
// it likely means something isn't completely compatible.
val conf = new RapidsConf(Map.empty[String, String])
val types = allSupportedTypes.toSeq
val header = Seq("Expression", "Supported", "SQL Func", "Notes", "Context", "Params") ++ types
println(header.mkString(","))
GpuOverrides.expressions.values.toSeq.sortBy(_.tag.toString).foreach { rule =>
val checks = rule.getChecks
if (rule.isVisible && checks.isDefined && checks.forall(_.shown)) {
val sqlFunctions =
ConfHelper.getSqlFunctionsForClass(rule.tag.runtimeClass).map(_.mkString(", "))
val exprChecks = checks.get.asInstanceOf[ExprChecks]
// Params can change between contexts, but should not
val allData = allSupportedTypes.map { t =>
(t, exprChecks.support(t))
}.toMap
val representative = allData.values.head
val firstCol = Seq(rule.tag.runtimeClass.getSimpleName)
val staticCols = Seq(sqlFunctions.getOrElse(" "), rule.notes().getOrElse("None"))

representative.foreach {
case (context, data) =>
data.keys.foreach { param =>
val supportLevelOps = allSupportedTypes.toSeq.map { t =>
allData(t)(context)(param).text
}
val isSupportedExec = Seq(if (supportLevelOps.forall(_.equals("NS"))) "NS" else "S")
tgravescs marked this conversation as resolved.
Show resolved Hide resolved
val allCols = (firstCol ++ isSupportedExec ++ staticCols ++ Seq(context.toString)
++ Seq(param) ++ supportLevelOps)
println(s"${allCols.map(replaceDelimiter(_, ",")).mkString(",")}")
}
}
}
}
}

def help(printType: String): Unit = {
printType match {
case a if a.equals("execs") => outputSupportedExecs()
case expr if (expr.equals("exprs")) => outputSupportedExpressions()
case score if (score.equals("operatorScore")) => operatorMappingWithScore()
case _ => outputSupportIO()
tgravescs marked this conversation as resolved.
Show resolved Hide resolved
}
}

def main(args: Array[String]): Unit = {
val out = new FileOutputStream(new File(args(0)))
val printType = if (args.size > 1) {
args(1)
} else {
"ioOnly"
}
Console.withOut(out) {
Console.withErr(out) {
SupportedOpsForTools.help()
SupportedOpsForTools.help(printType)
}
}
}
Expand Down
Loading