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
Multiple
Tensor
s of the sameshape
can be merged into a largerTensor
via theTensor.join
function. Given aSeq
of three 2x2Tensor
s,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
join
ing 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))
, A
Tensor
can besplit
into smallTensor
s on the direction of a specific dimension. Given a 3D tensor whoseshape
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)) }
, 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]]")
- Alphabetic
- By Inheritance
- cpu
- WangHashingRandomNumberGenerator
- HandleEventInExecutionContextForIntelAndAMDPlatform
- SynchronizedCreatingKernel
- DontReleaseEventTooEarly
- UseAllCpuDevices
- UseAllDevicesByType
- CommandQueuePool
- GlobalExecutionContext
- LogContextNotification
- UnsafeMathOptimizations
- Tensors
- OpenCL
- DefaultCloseable
- MonadicCloseable
- StrictLogging
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
trait
CompiledKernel extends MonadicCloseable[UnitContinuation]
- Attributes
- protected
- Definition Classes
- Tensors
-
final
case class
EventBuffer[JvmType](buffer: Tensors.DeviceBuffer[JvmType], event: Tensors.Event) extends PendingBuffer[JvmType] with Product with Serializable
- Attributes
- protected
- Definition Classes
- Tensors
- Annotations
- @silent()
-
trait
InlineTensor extends Tensor
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
-
trait
MonoidPrograms extends AnyRef
- Attributes
- protected
- Definition Classes
- Tensors
-
trait
NonInlineTensor extends Tensor
- Definition Classes
- Tensors
-
sealed
trait
PendingBuffer[JvmType] extends AnyRef
- Attributes
- protected
- Definition Classes
- Tensors
-
final
case class
ReadyBuffer[JvmType](buffer: Tensors.DeviceBuffer[JvmType]) extends PendingBuffer[JvmType] with Product with Serializable
- Attributes
- protected
- Definition Classes
- Tensors
- Annotations
- @silent()
-
sealed
trait
Tensor extends AnyRef
- Definition Classes
- Tensors
-
trait
TransformedTensor extends InlineTensor
- Definition Classes
- Tensors
-
type
CommandQueue = OpenCL.CommandQueue[cpu.this.type]
- Attributes
- protected
- Definition Classes
- OpenCL
-
type
DeviceBuffer[Element] = OpenCL.DeviceBuffer[cpu.this.type, Element]
- Attributes
- protected
- Definition Classes
- OpenCL
-
type
DeviceId = OpenCL.DeviceId[cpu.this.type]
- Attributes
- protected
- Definition Classes
- OpenCL
-
type
Event = OpenCL.Event[cpu.this.type]
- Attributes
- protected
- Definition Classes
- OpenCL
-
type
Kernel = OpenCL.Kernel[cpu.this.type]
- Attributes
- protected
- Definition Classes
- OpenCL
-
type
PlatformId = OpenCL.PlatformId[cpu.this.type]
- Attributes
- protected
- Definition Classes
- OpenCL
-
type
Program = OpenCL.Program[cpu.this.type]
- Attributes
- protected
- Definition Classes
- OpenCL
Value Members
-
object
PlusPrograms extends MonoidPrograms
- Attributes
- protected
- Definition Classes
- Tensors
-
object
Tensor
- Definition Classes
- Tensors
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
lazy val
acquireCommandQueue: Do[CommandQueue]
- Attributes
- protected
- Definition Classes
- CommandQueuePool → OpenCL
- Annotations
- @transient()
-
def
allocateBuffer[Element](size: Long)(implicit memory: Memory[Element]): Do[DeviceBuffer[Element]]
Returns an uninitialized buffer of
Element
on device.Returns an uninitialized buffer of
Element
on device.- Attributes
- protected
- Definition Classes
- OpenCL
-
def
allocateBufferFrom[Element, HostBuffer](hostBuffer: HostBuffer)(implicit memory: Aux[Element, HostBuffer]): Do[DeviceBuffer[Element]]
Returns a buffer of
Element
on device whose content is copied fromhostBuffer
.Returns a buffer of
Element
on device whose content is copied fromhostBuffer
.- Attributes
- protected
- Definition Classes
- OpenCL
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
lazy val
context: Long
- Attributes
- protected
- Definition Classes
- OpenCL
- Annotations
- @transient()
-
def
createCommandQueue(deviceId: DeviceId, properties: Map[Int, Long]): CommandQueue
- Attributes
- protected
- Definition Classes
- OpenCL
-
def
createKernel(program: Program): Kernel
Creates single kernel from this Program.
Creates single kernel from this Program.
- Attributes
- protected
- Definition Classes
- SynchronizedCreatingKernel → OpenCL
- Exceptions thrown
com.thoughtworks.compute.OpenCL.Exceptions.InvalidValue
if the this Program has more than one kernel.
-
def
createKernels(program: Program): Seq[Kernel]
- Attributes
- protected
- Definition Classes
- SynchronizedCreatingKernel → OpenCL
-
def
createProgramWithSource(sourceCode: TraversableOnce[CharSequence]): Program
- Attributes
- protected
- Definition Classes
- OpenCL
-
lazy val
deviceCapabilities: (DeviceId) ⇒ CLCapabilities
- Attributes
- protected
- Definition Classes
- OpenCL
- Annotations
- @transient()
-
lazy val
deviceIds: Seq[DeviceId]
- Attributes
- protected
- Definition Classes
- UseAllDevicesByType → OpenCL
- Annotations
- @transient()
-
val
deviceType: Status
- Attributes
- protected
- Definition Classes
- UseAllCpuDevices → UseAllDevicesByType
-
def
dispatch(command: (CommandQueue) ⇒ Do[Event]): Do[Event]
- Attributes
- protected
- Definition Classes
- OpenCL
-
def
enqueueReadBuffer[Element, Destination](commandQueue: CommandQueue, deviceBuffer: DeviceBuffer[Element], hostBuffer: Destination, preconditionEvents: Event*)(implicit memory: Aux[Element, Destination]): Do[Event]
- Attributes
- protected
- Definition Classes
- DontReleaseEventTooEarly → OpenCL
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
val
executionContext: ExecutionContextExecutor
- Attributes
- protected
- Definition Classes
- GlobalExecutionContext
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
handleOpenCLNotification(errorInfo: String, privateInfoOption: Option[ByteBuffer]): Unit
- Attributes
- protected
- Definition Classes
- LogContextNotification → OpenCL
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashSourceCode: Fastring
- Attributes
- protected
- Definition Classes
- WangHashingRandomNumberGenerator → Tensors
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
val
kernelCache: Cache[(trees)#ValueTerm, CompiledKernel]
- Attributes
- protected[com.thoughtworks.compute]
- Definition Classes
- Tensors
-
def
kernelCacheBuilder: CacheBuilder[(trees)#ValueTerm, CompiledKernel]
- Attributes
- protected
- Definition Classes
- Tensors
-
val
logger: Logger
- Attributes
- protected
- Definition Classes
- StrictLogging
-
def
monadicClose: UnitContinuation[Unit]
- Definition Classes
- DontReleaseEventTooEarly → OpenCL → DefaultCloseable → MonadicCloseable
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
val
numberOfCommandQueuesPerDevice: Int
- Attributes
- protected
- Definition Classes
- cpu → CommandQueuePool
-
def
openclCompilerFlags: String
- Attributes
- protected
- Definition Classes
- UnsafeMathOptimizations → Tensors
-
lazy val
platformCapabilities: CLCapabilities
- Attributes
- protected
- Definition Classes
- OpenCL
- Annotations
- @transient()
-
lazy val
platformId: PlatformId
- Attributes
- protected
- Definition Classes
- UseAllDevicesByType → OpenCL
- Annotations
- @transient()
-
def
platformIds: Seq[PlatformId]
- Attributes
- protected
- Definition Classes
- OpenCL
-
def
releaseContext: UnitContinuation[Unit]
- Attributes
- protected
- Definition Classes
- OpenCL
-
lazy val
shutdownCommandQueues: UnitContinuation[Unit]
- Attributes
- protected
- Definition Classes
- CommandQueuePool
- Annotations
- @transient()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
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 }
- Attributes
- protected
- Definition Classes
- Tensors
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
waitForStatus(event: Event, callbackType: Status): UnitContinuation[Status]
- Attributes
- protected
- Definition Classes
- HandleEventInExecutionContextForIntelAndAMDPlatform → OpenCL