@@ -4,6 +4,7 @@ import scala.collection.JavaConverters._
4
4
import java .nio .{ByteBuffer , IntBuffer }
5
5
import java .util .concurrent .{ConcurrentHashMap , Executors }
6
6
import java .util .concurrent .atomic .AtomicReference
7
+ import java .util .regex .Pattern
7
8
8
9
import com .typesafe .scalalogging .{CanLog , Logger , StrictLogging }
9
10
import org .lwjgl .opencl ._
@@ -55,7 +56,21 @@ object OpenCL {
55
56
56
57
final case class PlatformId [Owner <: Singleton with OpenCL ](handle : Long ) extends AnyVal {
57
58
58
- final def deviceIdsByType (deviceType : Int ): Seq [DeviceId [Owner ]] = {
59
+ def name : String = {
60
+ val stack = stackPush()
61
+ try {
62
+ val sizeBuffer = stack.mallocPointer(1 )
63
+ checkErrorCode(clGetPlatformInfo(handle, CL_PLATFORM_NAME , null : ByteBuffer , sizeBuffer))
64
+ val size = sizeBuffer.get(0 ).toInt
65
+ val nameBuffer = stack.malloc(size)
66
+ checkErrorCode(clGetPlatformInfo(handle, CL_PLATFORM_NAME , nameBuffer, null ))
67
+ memUTF8(nameBuffer)
68
+ } finally {
69
+ stack.close()
70
+ }
71
+ }
72
+
73
+ def deviceIdsByType (deviceType : Int ): Seq [DeviceId [Owner ]] = {
59
74
val Array (numberOfDevices) = {
60
75
val a = Array (0 )
61
76
checkErrorCode(clGetDeviceIDs(handle, deviceType, null , a))
@@ -358,8 +373,10 @@ object OpenCL {
358
373
359
374
}
360
375
376
+ private val AmdOrIntelRegex = """ AMD|Intel""" .r
377
+
361
378
/**
362
- * @note [[HandleEventInExecutionContext ]] __should__ be unnecessary because
379
+ * @note [[HandleEventInExecutionContextForIntelAndAMDPlatform ]] __should__ be unnecessary because
363
380
* only OpenCL calls to create contexts or command-queues, or blocking OpenCL operations are undefined behavior,
364
381
* according to https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/clSetEventCallback.html
365
382
* and we don't use those forbidden functions.
@@ -370,18 +387,27 @@ object OpenCL {
370
387
*
371
388
* There is also similar bug in Intel's OpenCL implementation
372
389
*
373
- * As a workaround, always enable this [[HandleEventInExecutionContext ]] for
390
+ * As a workaround, always enable this [[HandleEventInExecutionContextForIntelAndAMDPlatform ]] for
374
391
* Intel's and AMD's OpenCL implementation.
375
392
*/
376
- trait HandleEventInExecutionContext extends OpenCL {
393
+ trait HandleEventInExecutionContextForIntelAndAMDPlatform extends OpenCL {
377
394
378
395
// FIXME: this plug-in will cause Nvidia OpenCL hang up. Need investigation.
379
396
380
397
protected val executionContext : ExecutionContext
381
398
399
+ @ transient
400
+ private lazy val isEnabled = {
401
+ AmdOrIntelRegex .findAllMatchIn(platformId.name).nonEmpty
402
+ }
403
+
382
404
override protected def waitForStatus (event : Event , callbackType : Status ): UnitContinuation [Status ] =
383
- super .waitForStatus(event, callbackType).flatMap { status =>
384
- UnitContinuation .execute(status)(executionContext)
405
+ if (isEnabled) {
406
+ super .waitForStatus(event, callbackType).flatMap { status =>
407
+ UnitContinuation .execute(status)(executionContext)
408
+ }
409
+ } else {
410
+ super .waitForStatus(event, callbackType)
385
411
}
386
412
}
387
413
0 commit comments