Object

com.thoughtworks.compute

cpu

Related Doc: package compute

Permalink

object cpu extends StrictLogging with UnsafeMathOptimizations with LogContextNotification with GlobalExecutionContext with CommandQueuePool with UseAllCpuDevices with DontReleaseEventTooEarly with SynchronizedCreatingKernel with HandleEventInExecutionContextForIntelAndAMDPlatform with WangHashingRandomNumberGenerator

Contains N-dimensional array types on CPU.

You may want to import Tensor, which is the base type of N-dimensional arrays:

import com.thoughtworks.compute.cpu.Tensor
Source
cpu.scala
Examples:
  1. A Tensor of scalar value can be broadcast to N-dimensional arrays.

    val s = Tensor.scalar(42.0f)
    val b = s.broadcast(Array(2, 3))
    b.toString should be("[[42.0,42.0,42.0],[42.0,42.0,42.0]]")
  2. ,
  3. Multiple Tensors of the same shape can be merged into a larger Tensor via the Tensor.join function. Given a Seq of three 2x2 Tensors,

    val mySubtensors: Seq[Tensor] = Seq(
      Tensor(Seq(Seq(1.0f, 2.0f), Seq(3.0f, 4.0f))),
      Tensor(Seq(Seq(5.0f, 6.0f), Seq(7.0f, 8.0f))),
      Tensor(Seq(Seq(9.0f, 10.0f), Seq(11.0f, 12.0f))),
    )

    when joining them,

    val merged: Tensor = Tensor.join(mySubtensors)

    then the result should be a 2x2x3 Tensor.

    merged.toString should be("[[[1.0,5.0,9.0],[2.0,6.0,10.0]],[[3.0,7.0,11.0],[4.0,8.0,12.0]]]")
    merged.shape should be(Array(2, 2, 3))
  4. ,
  5. A Tensor can be split into small Tensors on the direction of a specific dimension. Given a 3D tensor whose shape is 2x3x4,

    val my3DTensor = Tensor((0.0f until 24.0f by 1.0f).grouped(4).toSeq.grouped(3).toSeq)
    my3DTensor.shape should be(Array(2, 3, 4))

    when split it at the dimension #0,

    val subtensors0 = my3DTensor.split(dimension = 0)

    then the result should be a Seq of two 3x4 tensors.

    subtensors0.toString should be("TensorSeq([[0.0,1.0,2.0,3.0],[4.0,5.0,6.0,7.0],[8.0,9.0,10.0,11.0]], [[12.0,13.0,14.0,15.0],[16.0,17.0,18.0,19.0],[20.0,21.0,22.0,23.0]])")
    inside(subtensors0) {
      case Seq(subtensor0, subtensor1) =>
        subtensor0.shape should be(Array(3, 4))
        subtensor1.shape should be(Array(3, 4))
    }

    When split it at the dimension #1,

    val subtensors1 = my3DTensor.split(dimension = 1)

    then the result should be a Seq of three 2x4 tensors.

    subtensors1.toString should be("TensorSeq([[0.0,1.0,2.0,3.0],[12.0,13.0,14.0,15.0]], [[4.0,5.0,6.0,7.0],[16.0,17.0,18.0,19.0]], [[8.0,9.0,10.0,11.0],[20.0,21.0,22.0,23.0]])")
    inside(subtensors1) {
      case Seq(subtensor0, subtensor1, subtensor2) =>
        subtensor0.shape should be(Array(2, 4))
        subtensor1.shape should be(Array(2, 4))
        subtensor2.shape should be(Array(2, 4))
    }
  6. ,
  7. In Compute.scala, an N-dimensional array is typed as Tensor, which can be created from scala.collection.Seq or scala.Array.

    val my2DArray: Tensor = Tensor(Array(Seq(1.0f, 2.0f), Seq(3.0f, 4.0f)))
    my2DArray.toString should be("[[1.0,2.0],[3.0,4.0]]")
Linear Supertypes
Content Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. cpu
  2. WangHashingRandomNumberGenerator
  3. Tensors
  4. HandleEventInExecutionContextForIntelAndAMDPlatform
  5. SynchronizedCreatingKernel
  6. DontReleaseEventTooEarly
  7. UseAllCpuDevices
  8. UseAllDevicesByType
  9. CommandQueuePool
  10. GlobalExecutionContext
  11. LogContextNotification
  12. UnsafeMathOptimizations
  13. OpenCL
  14. DefaultCloseable
  15. MonadicCloseable
  16. StrictLogging
  17. AnyRef
  18. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. trait CachedTensor extends NonInlineTensor

    Permalink
    Definition Classes
    Tensors
  2. type CommandQueue = OpenCL.CommandQueue[cpu.this.type]

    Permalink
    Attributes
    protected
    Definition Classes
    OpenCL
  3. trait CompiledKernel extends MonadicCloseable[UnitContinuation]

    Permalink
    Attributes
    protected
    Definition Classes
    Tensors
  4. type DeviceBuffer[Element] = OpenCL.DeviceBuffer[cpu.this.type, Element]

    Permalink
    Attributes
    protected
    Definition Classes
    OpenCL
  5. type DeviceId = OpenCL.DeviceId[cpu.this.type]

    Permalink
    Attributes
    protected
    Definition Classes
    OpenCL
  6. type Event = OpenCL.Event[cpu.this.type]

    Permalink
    Attributes
    protected
    Definition Classes
    OpenCL
  7. final case class EventBuffer[JvmType](buffer: Tensors.DeviceBuffer[JvmType], event: Tensors.Event) extends PendingBuffer[JvmType] with Product with Serializable

    Permalink
    Attributes
    protected
    Definition Classes
    Tensors
    Annotations
    @silent()
  8. trait FillTensor extends InlineTensor

    Permalink
    Definition Classes
    Tensors
  9. trait InlineTensor extends Tensor

    Permalink

    An intermediate expression of tensor that can be composed into a more complex expression.

    An intermediate expression of tensor that can be composed into a more complex expression.

    Definition Classes
    Tensors
  10. type Kernel = OpenCL.Kernel[cpu.this.type]

    Permalink
    Attributes
    protected
    Definition Classes
    OpenCL
  11. trait MonoidPrograms extends AnyRef

    Permalink
    Attributes
    protected
    Definition Classes
    Tensors
  12. trait NonInlineTensor extends Tensor

    Permalink

    A Tensor that is associated with a non-inline kernel program (i.e.

    A Tensor that is associated with a non-inline kernel program (i.e. never merged into a larger kernel).

    Definition Classes
    Tensors
  13. sealed trait PendingBuffer[JvmType] extends AnyRef

    Permalink
    Attributes
    protected
    Definition Classes
    Tensors
  14. type PlatformId = OpenCL.PlatformId[cpu.this.type]

    Permalink
    Attributes
    protected
    Definition Classes
    OpenCL
  15. type Program = OpenCL.Program[cpu.this.type]

    Permalink
    Attributes
    protected
    Definition Classes
    OpenCL
  16. final case class ReadyBuffer[JvmType](buffer: Tensors.DeviceBuffer[JvmType]) extends PendingBuffer[JvmType] with Product with Serializable

    Permalink
    Attributes
    protected
    Definition Classes
    Tensors
    Annotations
    @silent()
  17. sealed trait Tensor extends AnyRef

    Permalink

    Definition Classes
    Tensors
    Note

    There are three kinds of Tensor.

    • InlineTensor and TransformedTensor are like a @inline def, which can be merged into a larger kernel and will be recalculated whenever a slow action is performed.
    • NonInlineTensor is like a @noinline def, which is never merged into a larger kernel and will be recalculated whenever a slow action is performed.
    • CachedTensor is like a lazy val, which has an associated data buffer on the compute device and will be calculated only once even when slow actions are performed more than once.
  18. trait TransformedTensor extends InlineTensor

    Permalink
    Definition Classes
    Tensors

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. object PlusPrograms extends MonoidPrograms

    Permalink
    Attributes
    protected
    Definition Classes
    Tensors
  5. object Tensor

    Permalink
    Definition Classes
    Tensors
  6. lazy val acquireCommandQueue: Do[CommandQueue]

    Permalink
    Attributes
    protected
    Definition Classes
    CommandQueuePoolOpenCL
  7. def allocateBuffer[Element](size: Long)(implicit memory: Memory[Element]): Do[DeviceBuffer[Element]]

    Permalink

    Returns an uninitialized buffer of Element on device.

    Returns an uninitialized buffer of Element on device.

    Attributes
    protected
    Definition Classes
    OpenCL
  8. def allocateBufferFrom[Element, HostBuffer](hostBuffer: HostBuffer)(implicit memory: Aux[Element, HostBuffer]): Do[DeviceBuffer[Element]]

    Permalink

    Returns a buffer of Element on device whose content is copied from hostBuffer.

    Returns a buffer of Element on device whose content is copied from hostBuffer.

    Attributes
    protected
    Definition Classes
    OpenCL
  9. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  10. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  11. lazy val context: Long

    Permalink
    Attributes
    protected
    Definition Classes
    OpenCL
  12. def createCommandQueue(deviceId: DeviceId, properties: Map[Int, Long]): CommandQueue

    Permalink
    Attributes
    protected
    Definition Classes
    OpenCL
  13. def createKernel(program: Program): Kernel

    Permalink

    Creates single kernel from this Program.

    Creates single kernel from this Program.

    Attributes
    protected
    Definition Classes
    SynchronizedCreatingKernelOpenCL
    Exceptions thrown

    com.thoughtworks.compute.OpenCL.Exceptions.InvalidValue if the this Program has more than one kernel.

  14. def createKernels(program: Program): Seq[Kernel]

    Permalink
    Attributes
    protected
    Definition Classes
    SynchronizedCreatingKernelOpenCL
  15. def createProgramWithSource(sourceCode: TraversableOnce[CharSequence]): Program

    Permalink
    Attributes
    protected
    Definition Classes
    OpenCL
  16. def defaultProgramOptions: CharSequence

    Permalink
    Attributes
    protected
    Definition Classes
    UnsafeMathOptimizationsOpenCL
  17. lazy val deviceCapabilities: (DeviceId) ⇒ CLCapabilities

    Permalink
    Attributes
    protected
    Definition Classes
    OpenCL
  18. lazy val deviceIds: Seq[DeviceId]

    Permalink
    Attributes
    protected
    Definition Classes
    UseAllDevicesByTypeOpenCL
  19. val deviceType: Status

    Permalink
    Attributes
    protected
    Definition Classes
    UseAllCpuDevicesUseAllDevicesByType
  20. def dispatch(command: (CommandQueue) ⇒ Do[Event]): Do[Event]

    Permalink
    Attributes
    protected
    Definition Classes
    OpenCL
  21. def enqueueReadBuffer[Element, Destination](commandQueue: CommandQueue, deviceBuffer: DeviceBuffer[Element], hostBuffer: Destination, preconditionEvents: Event*)(implicit memory: Aux[Element, Destination]): Do[Event]

    Permalink
    Attributes
    protected
    Definition Classes
    DontReleaseEventTooEarlyOpenCL
  22. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  23. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  24. val executionContext: ExecutionContextExecutor

    Permalink
    Attributes
    protected
    Definition Classes
    GlobalExecutionContext
  25. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  26. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  27. def handleOpenCLNotification(errorInfo: String, privateInfoOption: Option[ByteBuffer]): Unit

    Permalink
    Attributes
    protected
    Definition Classes
    LogContextNotificationOpenCL
  28. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  29. def hashSourceCode: Fastring

    Permalink
    Attributes
    protected
    Definition Classes
    WangHashingRandomNumberGeneratorTensors
  30. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  31. val kernelCache: Cache[(trees)#ValueTerm, CompiledKernel]

    Permalink
    Attributes
    protected[com.thoughtworks.compute]
    Definition Classes
    Tensors
  32. def kernelCacheBuilder: CacheBuilder[(trees)#ValueTerm, CompiledKernel]

    Permalink
    Attributes
    protected
    Definition Classes
    Tensors
  33. val logger: Logger

    Permalink
    Attributes
    protected
    Definition Classes
    StrictLogging
  34. def monadicClose: UnitContinuation[Unit]

    Permalink
    Definition Classes
    TensorsOpenCL → DefaultCloseable → MonadicCloseable
  35. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  36. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  37. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  38. val numberOfCommandQueuesPerDevice: Int

    Permalink
    Attributes
    protected
    Definition Classes
    cpuCommandQueuePool
  39. lazy val platformCapabilities: CLCapabilities

    Permalink
    Attributes
    protected
    Definition Classes
    OpenCL
  40. lazy val platformId: PlatformId

    Permalink
    Attributes
    protected
    Definition Classes
    UseAllDevicesByTypeOpenCL
  41. def platformIds: Seq[PlatformId]

    Permalink
    Attributes
    protected
    Definition Classes
    OpenCL
  42. def releaseContext: UnitContinuation[Unit]

    Permalink
    Attributes
    protected
    Definition Classes
    OpenCL
  43. lazy val shutdownCommandQueues: UnitContinuation[Unit]

    Permalink
    Attributes
    protected
    Definition Classes
    CommandQueuePool
  44. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  45. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  46. val trees: AllTrees with MemoryTrees with StructuralTrees { type Category = com.thoughtworks.compute.Expressions.Tuples with com.thoughtworks.compute.Expressions.Floats with com.thoughtworks.compute.Expressions.Arrays }

    Permalink
    Attributes
    protected
    Definition Classes
    Tensors
  47. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  48. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  49. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  50. def waitForStatus(event: Event, callbackType: Status): UnitContinuation[Status]

    Permalink
    Attributes
    protected
    Definition Classes
    HandleEventInExecutionContextForIntelAndAMDPlatformOpenCL

Inherited from Tensors

Inherited from DontReleaseEventTooEarly

Inherited from UseAllCpuDevices

Inherited from UseAllDevicesByType

Inherited from CommandQueuePool

Inherited from GlobalExecutionContext

Inherited from LogContextNotification

Inherited from UnsafeMathOptimizations

Inherited from OpenCL

Inherited from DefaultCloseable

Inherited from MonadicCloseable[UnitContinuation]

Inherited from StrictLogging

Inherited from AnyRef

Inherited from Any

Ungrouped