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 2 commits
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
137 changes: 134 additions & 3 deletions sql-plugin/src/main/scala/com/nvidia/spark/rapids/TypeChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2152,6 +2152,23 @@ object SupportedOpsForTools {
private lazy val allSupportedTypes =
TypeSigUtil.getAllSupportedTypes()

// if a string contains what we are going to use for a delimiter, replace
// it with something else
private def replaceDelimiter(str: String, delimiter: String): String = {
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 +2210,129 @@ 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
// We are assigning speed up of 2 to all the Execs supported by the plugin. This can be
// adjusted later.
val allCols = Seq(cpuName, "2")
tgravescs marked this conversation as resolved.
Show resolved Hide resolved
println(s"${allCols.mkString(",")}")
}
}

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
// We are assigning speed up of 3 to all the Exprs supported by the plugin. This can be
// adjusted later.
val allCols = Seq(cpuName, "3")
println(s"${allCols.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
val isConfigDisabled = rule.disabledMsg.isDefined
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")) || isConfigDisabled) "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
val isConfigDisabled = rule.disabledMsg.isDefined
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 isSupportedExpr = Seq(
if (supportLevelOps.forall(_.equals("NS")) || isConfigDisabled) "NS" else "S")
val allCols = (firstCol ++ isSupportedExpr ++ 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 io if io.equals("ioOnly") => outputSupportIO()
case _ => throw new IllegalArgumentException("SupportedOpsForTools: Invalid option. Valid" +
"options are `execs`, `exprs`, `operatorScore` and `ioOnly`")
}
}

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