-
Notifications
You must be signed in to change notification settings - Fork 232
/
Plugin.scala
543 lines (489 loc) · 23.7 KB
/
Plugin.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
/*
* Copyright (c) 2019-2023, NVIDIA CORPORATION.
*
* Licensed 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 com.nvidia.spark.rapids
import java.lang.reflect.InvocationTargetException
import java.time.ZoneId
import java.util.Properties
import scala.collection.JavaConverters._
import scala.sys.process._
import scala.util.Try
import ai.rapids.cudf.{Cuda, CudaException, CudaFatalException, CudfException, MemoryCleaner}
import com.nvidia.spark.rapids.filecache.{FileCache, FileCacheLocalityManager, FileCacheLocalityMsg}
import com.nvidia.spark.rapids.python.PythonWorkerSemaphore
import org.apache.commons.lang3.exception.ExceptionUtils
import org.apache.spark.{ExceptionFailure, SparkConf, SparkContext, TaskFailedReason}
import org.apache.spark.api.plugin.{DriverPlugin, ExecutorPlugin, PluginContext, SparkPlugin}
import org.apache.spark.internal.Logging
import org.apache.spark.serializer.{JavaSerializer, KryoSerializer}
import org.apache.spark.sql.catalyst.rules.Rule
import org.apache.spark.sql.execution._
import org.apache.spark.sql.internal.StaticSQLConf
import org.apache.spark.sql.rapids.GpuShuffleEnv
import org.apache.spark.sql.rapids.execution.TrampolineUtil
class PluginException(msg: String) extends RuntimeException(msg)
case class CudfVersionMismatchException(errorMsg: String) extends PluginException(errorMsg)
case class ColumnarOverrideRules() extends ColumnarRule with Logging {
lazy val overrides: Rule[SparkPlan] = GpuOverrides()
lazy val overrideTransitions: Rule[SparkPlan] = new GpuTransitionOverrides()
override def preColumnarTransitions : Rule[SparkPlan] = overrides
override def postColumnarTransitions: Rule[SparkPlan] = overrideTransitions
}
object RapidsPluginUtils extends Logging {
val CUDF_PROPS_FILENAME = "cudf-java-version-info.properties"
val JNI_PROPS_FILENAME = "spark-rapids-jni-version-info.properties"
val PLUGIN_PROPS_FILENAME = "rapids4spark-version-info.properties"
private val SQL_PLUGIN_NAME = classOf[SQLExecPlugin].getName
private val UDF_PLUGIN_NAME = "com.nvidia.spark.udf.Plugin"
private val SQL_PLUGIN_CONF_KEY = StaticSQLConf.SPARK_SESSION_EXTENSIONS.key
private val SERIALIZER_CONF_KEY = "spark.serializer"
private val JAVA_SERIALIZER_NAME = classOf[JavaSerializer].getName
private val KRYO_SERIALIZER_NAME = classOf[KryoSerializer].getName
private val KRYO_REGISTRATOR_KEY = "spark.kryo.registrator"
private val KRYO_REGISTRATOR_NAME = classOf[GpuKryoRegistrator].getName
private val EXECUTOR_CORES_KEY = "spark.executor.cores"
private val TASK_GPU_AMOUNT_KEY = "spark.task.resource.gpu.amount"
private val EXECUTOR_GPU_AMOUNT_KEY = "spark.executor.resource.gpu.amount"
{
val pluginProps = loadProps(RapidsPluginUtils.PLUGIN_PROPS_FILENAME)
logInfo(s"RAPIDS Accelerator build: $pluginProps")
val jniProps = loadProps(RapidsPluginUtils.JNI_PROPS_FILENAME)
logInfo(s"RAPIDS Accelerator JNI build: $jniProps")
val cudfProps = loadProps(RapidsPluginUtils.CUDF_PROPS_FILENAME)
logInfo(s"cudf build: $cudfProps")
val pluginVersion = pluginProps.getProperty("version", "UNKNOWN")
val cudfVersion = cudfProps.getProperty("version", "UNKNOWN")
logWarning(s"RAPIDS Accelerator $pluginVersion using cudf $cudfVersion.")
}
val extraPlugins = getExtraPlugins
def logPluginMode(conf: RapidsConf): Unit = {
if (conf.isSqlEnabled && conf.isSqlExecuteOnGPU) {
logWarning("RAPIDS Accelerator is enabled, to disable GPU " +
s"support set `${RapidsConf.SQL_ENABLED}` to false.")
if (conf.explain != "NONE") {
logWarning(s"spark.rapids.sql.explain is set to `${conf.explain}`. Set it to 'NONE' to " +
"suppress the diagnostics logging about the query placement on the GPU.")
}
} else if (conf.isSqlEnabled && conf.isSqlExplainOnlyEnabled) {
logWarning("RAPIDS Accelerator is in explain only mode, to disable " +
s"set `${RapidsConf.SQL_ENABLED}` to false. To change the mode, " +
s"restart the application and change `${RapidsConf.SQL_MODE}`.")
} else {
logWarning("RAPIDS Accelerator is disabled, to enable GPU " +
s"support set `${RapidsConf.SQL_ENABLED}` to true.")
}
if (conf.isUdfCompilerEnabled) {
logWarning("Experimental RAPIDS UDF compiler is enabled, in case of related failures " +
s"disable it by setting `${RapidsConf.UDF_COMPILER_ENABLED}` to false. " +
"More information is available at https://nvidia.github.io/spark-rapids/docs/FAQ.html#" +
"automatic-translation-of-scala-udfs-to-apache-spark-operations" )
}
}
def estimateCoresOnExec(conf: SparkConf): Int = {
conf.getOption(RapidsPluginUtils.EXECUTOR_CORES_KEY)
.map(_.toInt)
.getOrElse(Runtime.getRuntime.availableProcessors)
}
def fixupConfigsOnDriver(conf: SparkConf): Unit = {
// First add in the SQL executor plugin because that is what we need at a minimum
if (conf.contains(SQL_PLUGIN_CONF_KEY)) {
for (pluginName <- Array(SQL_PLUGIN_NAME, UDF_PLUGIN_NAME)){
val previousValue = conf.get(SQL_PLUGIN_CONF_KEY).split(",").map(_.trim)
if (!previousValue.contains(pluginName)) {
conf.set(SQL_PLUGIN_CONF_KEY, (previousValue :+ pluginName).mkString(","))
} else {
conf.set(SQL_PLUGIN_CONF_KEY, previousValue.mkString(","))
}
}
} else {
conf.set(SQL_PLUGIN_CONF_KEY, Array(SQL_PLUGIN_NAME,UDF_PLUGIN_NAME).mkString(","))
}
val serializer = conf.get(SERIALIZER_CONF_KEY, JAVA_SERIALIZER_NAME)
if (KRYO_SERIALIZER_NAME.equals(serializer)) {
if (conf.contains(KRYO_REGISTRATOR_KEY)) {
if (!KRYO_REGISTRATOR_NAME.equals(conf.get(KRYO_REGISTRATOR_KEY)) ) {
logWarning("The RAPIDS Accelerator when used with Kryo needs to register some " +
s"serializers using $KRYO_REGISTRATOR_NAME. Please call it from your registrator " +
" to let the plugin work properly.")
} // else it is set and we are good to go
} else {
// We cannot set the kryo key here, it is not early enough to be picked up everywhere
throw new UnsupportedOperationException("The RAPIDS Accelerator when used with Kryo " +
"needs to register some serializers. Please set the spark config " +
s"$KRYO_REGISTRATOR_KEY to $KRYO_REGISTRATOR_NAME or some operations may not work " +
"properly.")
}
} else if (!JAVA_SERIALIZER_NAME.equals(serializer)) {
throw new UnsupportedOperationException(s"$serializer is not a supported serializer for " +
s"the RAPIDS Accelerator. Please disable the RAPIDS Accelerator or use a supported " +
s"serializer ($JAVA_SERIALIZER_NAME, $KRYO_SERIALIZER_NAME).")
}
// set driver timezone
conf.set(RapidsConf.DRIVER_TIMEZONE.key, ZoneId.systemDefault().normalized().toString)
// If spark.rapids.sql.multiThreadedRead.numThreads is not set explicitly, then we derive it
// from other settings. Otherwise, we keep the users' setting.
val numThreadsKey = RapidsConf.MULTITHREAD_READ_NUM_THREADS.key
if (!conf.contains(numThreadsKey)) {
// Derive it from spark.executor.cores, since spark.executor.cores is not set on all cluster
// managers by default, we should judge whether if it's set explicitly.
if (conf.contains(EXECUTOR_CORES_KEY)) {
val numThreads = Math.max(RapidsConf.MULTITHREAD_READ_NUM_THREADS_DEFAULT,
conf.get(EXECUTOR_CORES_KEY).toInt).toString
conf.set(numThreadsKey, numThreads)
logWarning(s"$numThreadsKey is set to $numThreads.")
}
}
// If spark.task.resource.gpu.amount is larger than
// (spark.executor.resource.gpu.amount / spark.executor.cores) then GPUs will be the limiting
// resource for task scheduling, but we can only output the warning if executor cores is set
// because this is happening on the driver so the number of cores in the runtime is not
// relevant
if (conf.contains(TASK_GPU_AMOUNT_KEY) &&
conf.contains(EXECUTOR_GPU_AMOUNT_KEY) &&
conf.contains(EXECUTOR_CORES_KEY)) {
val taskGpuAmountSetByUser = conf.get(TASK_GPU_AMOUNT_KEY).toDouble
val executorCores = conf.get(EXECUTOR_CORES_KEY).toDouble
val executorGpuAmount = conf.get(EXECUTOR_GPU_AMOUNT_KEY).toDouble
if (executorCores != 0 && taskGpuAmountSetByUser > executorGpuAmount / executorCores) {
logWarning("The current setting of spark.task.resource.gpu.amount " +
s"($taskGpuAmountSetByUser) is not ideal to get the best performance from the " +
"RAPIDS Accelerator plugin. It's recommended to be 1/{executor core count} unless " +
"you have a special use case.")
}
}
}
def loadProps(resourceName: String): Properties = {
val classLoader = RapidsPluginUtils.getClass.getClassLoader
val resource = classLoader.getResourceAsStream(resourceName)
if (resource == null) {
throw new PluginException(s"Could not find properties file $resourceName in the classpath")
}
val props = new Properties
props.load(resource)
props
}
private def loadExtensions[T <: AnyRef](extClass: Class[T], classes: Seq[String]): Seq[T] = {
classes.flatMap { name =>
try {
val klass = TrampolineUtil.classForName[T](name)
require(extClass.isAssignableFrom(klass),
s"$name is not a subclass of ${extClass.getName()}.")
Some(klass.getConstructor().newInstance())
} catch {
case _: NoSuchMethodException =>
throw new NoSuchMethodException(
s"$name did not have a zero-argument constructor or a" +
" single-argument constructor that accepts SparkConf. Note: if the class is" +
" defined inside of another Scala class, then its constructors may accept an" +
" implicit parameter that references the enclosing class; in this case, you must" +
" define the class as a top-level class in order to prevent this extra" +
" parameter from breaking Spark's ability to find a valid constructor.")
case e: InvocationTargetException =>
e.getCause() match {
case uoe: UnsupportedOperationException =>
logDebug(s"Extension $name not being initialized.", uoe)
logInfo(s"Extension $name not being initialized.")
None
case null => throw e
case cause => throw cause
}
}
}
}
private def getExtraPlugins: Seq[SparkPlugin] = {
val resourceName = "spark-rapids-extra-plugins"
val classLoader = RapidsPluginUtils.getClass.getClassLoader
val resource = classLoader.getResourceAsStream(resourceName)
if (resource == null) {
logDebug(s"Could not find file $resourceName in the classpath, not loading extra plugins")
Seq.empty
} else {
val pluginClasses = scala.io.Source.fromInputStream(resource).getLines().toSeq
loadExtensions(classOf[SparkPlugin], pluginClasses)
}
}
}
/**
* The Spark driver plugin provided by the RAPIDS Spark plugin.
*/
class RapidsDriverPlugin extends DriverPlugin with Logging {
var rapidsShuffleHeartbeatManager: RapidsShuffleHeartbeatManager = null
private lazy val extraDriverPlugins =
RapidsPluginUtils.extraPlugins.map(_.driverPlugin()).filterNot(_ == null)
override def receive(msg: Any): AnyRef = {
msg match {
case m: FileCacheLocalityMsg =>
// handleMsg should not block current thread
FileCacheLocalityManager.get.handleMsg(m)
case RapidsExecutorStartupMsg(id) =>
if (rapidsShuffleHeartbeatManager == null) {
throw new IllegalStateException(
s"Rpc message $msg received, but shuffle heartbeat manager not configured.")
}
rapidsShuffleHeartbeatManager.registerExecutor(id)
case RapidsExecutorHeartbeatMsg(id) =>
if (rapidsShuffleHeartbeatManager == null) {
throw new IllegalStateException(
s"Rpc message $msg received, but shuffle heartbeat manager not configured.")
}
rapidsShuffleHeartbeatManager.executorHeartbeat(id)
case m => throw new IllegalStateException(s"Unknown message $m")
}
}
override def init(
sc: SparkContext, pluginContext: PluginContext): java.util.Map[String, String] = {
val sparkConf = pluginContext.conf
RapidsPluginUtils.fixupConfigsOnDriver(sparkConf)
val conf = new RapidsConf(sparkConf)
RapidsPluginUtils.logPluginMode(conf)
if (GpuShuffleEnv.isRapidsShuffleAvailable(conf)) {
GpuShuffleEnv.initShuffleManager()
if (GpuShuffleEnv.isUCXShuffleAndEarlyStart(conf)) {
rapidsShuffleHeartbeatManager =
new RapidsShuffleHeartbeatManager(
conf.shuffleTransportEarlyStartHeartbeatInterval,
conf.shuffleTransportEarlyStartHeartbeatTimeout)
}
}
FileCacheLocalityManager.init(sc)
logDebug("Loading extra driver plugins: " +
s"${extraDriverPlugins.map(_.getClass.getName).mkString(",")}")
extraDriverPlugins.foreach(_.init(sc, pluginContext))
conf.rapidsConfMap
}
override def registerMetrics(appId: String, pluginContext: PluginContext): Unit = {
extraDriverPlugins.foreach(_.registerMetrics(appId, pluginContext))
}
override def shutdown(): Unit = {
extraDriverPlugins.foreach(_.shutdown())
FileCacheLocalityManager.shutdown()
}
}
/**
* The Spark executor plugin provided by the RAPIDS Spark plugin.
*/
class RapidsExecutorPlugin extends ExecutorPlugin with Logging {
var rapidsShuffleHeartbeatEndpoint: RapidsShuffleHeartbeatEndpoint = null
private lazy val extraExecutorPlugins =
RapidsPluginUtils.extraPlugins.map(_.executorPlugin()).filterNot(_ == null)
override def init(
pluginContext: PluginContext,
extraConf: java.util.Map[String, String]): Unit = {
try {
if (Cuda.getComputeCapabilityMajor < 6) {
throw new RuntimeException(s"GPU compute capability ${Cuda.getComputeCapabilityMajor}" +
" is unsupported, requires 6.0+")
}
// if configured, re-register checking leaks hook.
reRegisterCheckLeakHook()
val sparkConf = pluginContext.conf()
val numCores = RapidsPluginUtils.estimateCoresOnExec(sparkConf)
val conf = new RapidsConf(extraConf.asScala.toMap)
// Compare if the cudf version mentioned in the classpath is equal to the version which
// plugin expects. If there is a version mismatch, throw error. This check can be disabled
// by setting this config spark.rapids.cudfVersionOverride=true
checkCudfVersion(conf)
// Validate driver and executor time zone are same if the driver time zone is supported by
// the plugin.
val driverTimezone = conf.driverTimeZone match {
case Some(value) => ZoneId.of(value)
case None => throw new RuntimeException(s"Driver time zone cannot be determined.")
}
if (TypeChecks.areTimestampsSupported(driverTimezone)) {
val executorTimezone = ZoneId.systemDefault()
if (executorTimezone.normalized() != driverTimezone.normalized()) {
throw new RuntimeException(s" Driver and executor timezone mismatch. " +
s"Driver timezone is $driverTimezone and executor timezone is " +
s"$executorTimezone. Set executor timezone to $driverTimezone.")
}
}
// we rely on the Rapids Plugin being run with 1 GPU per executor so we can initialize
// on executor startup.
if (!GpuDeviceManager.rmmTaskInitEnabled) {
logInfo("Initializing memory from Executor Plugin")
GpuDeviceManager.initializeGpuAndMemory(pluginContext.resources().asScala.toMap, conf,
numCores)
if (GpuShuffleEnv.isRapidsShuffleAvailable(conf)) {
GpuShuffleEnv.initShuffleManager()
if (GpuShuffleEnv.isUCXShuffleAndEarlyStart(conf)) {
logInfo("Initializing shuffle manager heartbeats")
rapidsShuffleHeartbeatEndpoint = new RapidsShuffleHeartbeatEndpoint(pluginContext, conf)
rapidsShuffleHeartbeatEndpoint.registerShuffleHeartbeat()
}
}
}
logDebug("Loading extra executor plugins: " +
s"${extraExecutorPlugins.map(_.getClass.getName).mkString(",")}")
extraExecutorPlugins.foreach(_.init(pluginContext, extraConf))
GpuSemaphore.initialize()
FileCache.init(pluginContext)
} catch {
// Exceptions in executor plugin can cause a single thread to die but the executor process
// sticks around without any useful info until it hearbeat times out. Print what happened
// and exit immediately.
case e: CudaException =>
logError("Exception in the executor plugin, shutting down!", e)
logGpuDebugInfoAndExit(systemExitCode = 1)
case e: Throwable =>
logError("Exception in the executor plugin, shutting down!", e)
System.exit(1)
}
}
/**
* Re-register leaks checking hook if configured.
*/
private def reRegisterCheckLeakHook(): Unit = {
// DEFAULT_SHUTDOWN_THREAD in MemoryCleaner is responsible to check the leaks at shutdown time,
// it expects all other hooks are done before the checking
// as other hooks will close some resources.
if (MemoryCleaner.configuredDefaultShutdownHook) {
// Shutdown hooks are executed concurrently in JVM, and there is no execution order guarantee.
// See the doc of `Runtime.addShutdownHook`.
// Here we should wait Spark hooks to be done, or a false leak will be detected.
// See issue: https://github.com/NVIDIA/spark-rapids/issues/5854
//
// Here use `Spark ShutdownHookManager` to manage hooks with priority.
// 20 priority is small enough, will run after Spark hooks.
TrampolineUtil.addShutdownHook(20, MemoryCleaner.removeDefaultShutdownHook())
}
}
private def checkCudfVersion(conf: RapidsConf): Unit = {
try {
val pluginProps = RapidsPluginUtils.loadProps(RapidsPluginUtils.PLUGIN_PROPS_FILENAME)
logInfo(s"RAPIDS Accelerator build: $pluginProps")
val expectedCudfVersion = Option(pluginProps.getProperty("cudf_version")).getOrElse {
throw CudfVersionMismatchException("Could not find cudf version in " +
RapidsPluginUtils.PLUGIN_PROPS_FILENAME)
}
val cudfProps = RapidsPluginUtils.loadProps(RapidsPluginUtils.CUDF_PROPS_FILENAME)
logInfo(s"cudf build: $cudfProps")
val cudfVersion = Option(cudfProps.getProperty("version")).getOrElse {
throw CudfVersionMismatchException("Could not find cudf version in " +
RapidsPluginUtils.CUDF_PROPS_FILENAME)
}
// compare cudf version in the classpath with the cudf version expected by plugin
if (!RapidsExecutorPlugin.cudfVersionSatisfied(expectedCudfVersion, cudfVersion)) {
throw CudfVersionMismatchException(s"Found cudf version $cudfVersion, RAPIDS Accelerator " +
s"expects $expectedCudfVersion")
}
} catch {
case x: PluginException if conf.cudfVersionOverride =>
logWarning(s"Ignoring error due to ${RapidsConf.CUDF_VERSION_OVERRIDE.key}=true: " +
s"${x.getMessage}")
}
}
// Wait for command spawned via Process
private def waitForProcess(cmd: Process, durationMs: Long): Option[Int] = {
val endTime = System.currentTimeMillis() + durationMs
do {
Thread.sleep(10)
if (!cmd.isAlive()) {
return Some(cmd.exitValue())
}
} while (System.currentTimeMillis() < endTime)
// Timed out
cmd.destroy()
None
}
// Try to run nvidia-smi when task fails due to a cuda exception.
private def logGpuDebugInfoAndExit(systemExitCode: Int) = synchronized {
try {
val nvidiaSmiStdout = new StringBuilder
val nvidiaSmiStderr = new StringBuilder
val cmd = "nvidia-smi".run(
ProcessLogger(s => nvidiaSmiStdout.append(s + "\n"), s => nvidiaSmiStderr.append(s + "\n")))
waitForProcess(cmd, 10000) match {
case Some(exitStatus) =>
if (exitStatus == 0) {
logWarning("nvidia-smi:\n" + nvidiaSmiStdout)
} else {
logWarning("nvidia-smi failed with: " + nvidiaSmiStdout + nvidiaSmiStderr)
}
case None => logWarning("nvidia-smi command timed out")
}
} catch {
case e: Throwable =>
logWarning("nvidia-smi process failed", e)
}
System.exit(systemExitCode)
}
override def shutdown(): Unit = {
GpuSemaphore.shutdown()
PythonWorkerSemaphore.shutdown()
GpuDeviceManager.shutdown()
Option(rapidsShuffleHeartbeatEndpoint).foreach(_.close())
extraExecutorPlugins.foreach(_.shutdown())
FileCache.shutdown()
}
override def onTaskFailed(failureReason: TaskFailedReason): Unit = {
def containsCudaFatalException(e: Throwable): Boolean = {
ExceptionUtils.getThrowableList(e).asScala.exists(e => e.isInstanceOf[CudaFatalException])
}
failureReason match {
case ef: ExceptionFailure =>
ef.exception match {
case Some(e) if containsCudaFatalException(e) =>
logError("Stopping the Executor based on exception being a fatal CUDA error: " +
s"${ef.toErrorString}")
logGpuDebugInfoAndExit(systemExitCode = 20)
case Some(_: CudaException) =>
logDebug(s"Executor onTaskFailed because of a non-fatal CUDA error: " +
s"${ef.toErrorString}")
case Some(_: CudfException) =>
logDebug(s"Executor onTaskFailed because of a CUDF error: ${ef.toErrorString}")
case _ =>
logDebug(s"Executor onTaskFailed: ${ef.toErrorString}")
}
case other =>
logDebug(s"Executor onTaskFailed: ${other.toString}")
}
extraExecutorPlugins.foreach(_.onTaskFailed(failureReason))
}
override def onTaskStart(): Unit = {
extraExecutorPlugins.foreach(_.onTaskStart())
}
override def onTaskSucceeded(): Unit = {
extraExecutorPlugins.foreach(_.onTaskSucceeded())
}
}
object RapidsExecutorPlugin {
/**
* Return true if the expected cudf version is satisfied by the actual version found.
* The version is satisfied if the major and minor versions match exactly. If there is a requested
* patch version then the actual patch version must be greater than or equal.
* For example, version 7.1 is not satisfied by version 7.2, but version 7.1 is satisfied by
* version 7.1.1.
* If the expected cudf version is a specified 'timestamp-seq' one, then it is satisfied by
* the SNAPSHOT version.
* For example, version 7.1-yyyymmdd.hhmmss-seq is satisfied by version 7.1-SNAPSHOT.
*/
def cudfVersionSatisfied(expected: String, actual: String): Boolean = {
val expHyphen = if (expected.indexOf('-') >= 0) expected.indexOf('-') else expected.length
val actHyphen = if (actual.indexOf('-') >= 0) actual.indexOf('-') else actual.length
if (actual.substring(actHyphen) != expected.substring(expHyphen) &&
!(actual.substring(actHyphen) == "-SNAPSHOT" &&
expected.substring(expHyphen).matches("-([0-9]{8}).([0-9]{6})-([1-9][0-9]*)"))) {
return false
}
val (expMajorMinor, expPatch) = expected.substring(0, expHyphen).split('.').splitAt(2)
val (actMajorMinor, actPatch) = actual.substring(0, actHyphen).split('.').splitAt(2)
actMajorMinor.startsWith(expMajorMinor) && {
val expPatchInts = expPatch.map(_.toInt)
val actPatchInts = actPatch.map(v => Try(v.toInt).getOrElse(Int.MinValue))
val zipped = expPatchInts.zipAll(actPatchInts, 0, 0)
zipped.forall { case (e, a) => e <= a }
}
}
}