Apache Singa
A General Distributed Deep Learning Library
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
singa::Device Class Referenceabstract

Allocate memory and execute Tensor operations. More...

#include <device.h>

Inheritance diagram for singa::Device:
Inheritance graph
[legend]
Collaboration diagram for singa::Device:
Collaboration graph
[legend]

Public Member Functions

 Device (int id, int num_executors)
 Constructor with device ID, num of executors (e.g., cuda streams), max mem size to use (in MB)
 
virtual void SetRandSeed (unsigned seed)=0
 
BlockNewBlock (int size)
 Called by Tensor.
 
void FreeBlock (Block *block)
 Called by Tensor.
 
virtual size_t GetAllocatedMem ()
 Return the size (bytes) of memory in use TODO(wangwei) override this function for all devices. More...
 
virtual void CopyDataToFrom (Block *dst, Block *src, size_t nBytes, CopyDirection direction, int dst_offset, int src_offset)
 Copy data within or across devices.
 
void CopyDataFromHostPtr (Block *dst, const void *src, size_t nBytes, size_t dst_offset=0)
 
void Exec (function< void(Context *)> &&fn, const vector< Block *> read_blocks, const vector< Block *> write_blocks, bool use_rand_generator=false)
 Submit the operation to the device, which may execute it right now or delay it depending on the scheduler. More...
 
void Sync ()
 wait for all operations submitted to this device.
 
LangType lang () const
 Return the programming language for this device.
 
virtual std::shared_ptr< Devicehost () const
 
Contextcontext (int k)
 
int id () const
 

Protected Member Functions

virtual void DoExec (function< void(Context *)> &&fn, int executor)=0
 Execute one operation on one executor.
 
virtual void CopyToFrom (void *dst, const void *src, size_t nBytes, CopyDirection direction, Context *ctx)=0
 
virtual void * Malloc (int size)=0
 Allocate device memory.
 
virtual void Free (void *ptr)=0
 Free device memory.
 

Protected Attributes

int id_ = 0
 
int num_executors_ = 0
 
unsigned seed_ = 0
 
LangType lang_
 Programming language type, could be kCpp, kCuda, kOpencl.
 
std::shared_ptr< Devicehost_
 The host device.
 
Context ctx_
 

Detailed Description

Allocate memory and execute Tensor operations.

There are three types of devices distinguished by their programming languages, namely cpp, cuda and opencl.

Member Function Documentation

◆ Exec()

void singa::Device::Exec ( function< void(Context *)> &&  fn,
const vector< Block *>  read_blocks,
const vector< Block *>  write_blocks,
bool  use_rand_generator = false 
)

Submit the operation to the device, which may execute it right now or delay it depending on the scheduler.

◆ GetAllocatedMem()

virtual size_t singa::Device::GetAllocatedMem ( )
inlinevirtual

Return the size (bytes) of memory in use TODO(wangwei) override this function for all devices.


The documentation for this class was generated from the following file: