MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
MyCaffe.common.SyncedMemory< T > Class Template Reference

The SyncedMemory manages the low-level connection between the GPU and host memory. More...

Inheritance diagram for MyCaffe.common.SyncedMemory< T >:

Public Member Functions

 SyncedMemory (CudaDnn< T > cuda, Log log, long lCapacity=0, object tag=null, bool bUseHalfSize=false)
 The SyncedMemory constructor. More...
 
void Dispose ()
 Releases all GPU and host resources used. More...
 
void Allocate (long lCount, bool bUseHalfSize=false)
 Allocate a number of items in GPU memory and save the handle. More...
 
void Allocate (T[] rg, bool bUseHalfSize=false)
 Allocate a number of items and copy the given array into the memory on the GPU. More...
 
void Zero ()
 Set all items in the GPU memory up to the Count, to zero. More...
 
void ZeroAll ()
 Set all items in the GPU memory up to the Capacity, to zero. More...
 
void Set (double dfVal)
 Set all items up to Count to a given value. More...
 
void SetAt (int nIdx, T fVal)
 Set a specific item at a given index to a value. More...
 
GetAt (int nIdx)
 Return a value at a given index. More...
 
long Copy (SyncedMemory< T > src, long hDstHostBuffer=0)
 Copy another SyncedMemory into this one. More...
 
SyncedMemory< T > Clone ()
 Copy this SyncedMemory. More...
 
void set_gpu_data (long hData, long lCount, long lOffset)
 Copies a new Memory Pointer within the low-level CudaDnnDLL where a Memory Pointer uses another already allocated block of GPU memory and just indexes into it. More...
 
void SetData (T[] rgData, int nCount, bool bSetCount=true)
 Sets the array of host data on the GPU and re-allocates the GPU memory if needed. More...
 
T[] update_cpu_data (long lCount=-1)
 Updates the host data by copying the GPU data to the host data. More...
 
void set_cpu_data_locally (T[] rg)
 This does not place the data on the GPU - call async_gpu_push() to move it to the GPU. More...
 
void async_gpu_push (long hStream, T[] rg)
 Pushes the host data, previously set with set_cpu_data_locally(), to the GPU. More...
 

Properties

bool HalfSize [get]
 Returns whether or not the sync memory is half-sized memory. More...
 
object Tag [getset]
 Get/set data associated with the synced memory. More...
 
int DeviceID [get]
 Returns the Device ID on which the GPU memory of this SyncedMemory was allocated. More...
 
long Capacity [get]
 Returns the total amount of GPU memory held by this SyncedMemory. More...
 
long Count [getset]
 Returns the current count of items in this SyncedMemory. Note, the Count may be less than the Capacity. More...
 
long gpu_data [get]
 Returns the handle to the GPU memory. More...
 
long mutable_gpu_data [get]
 Returns the mutable handle to GPU data. More...
 
T[] cpu_data [get]
 Returns the data on the CPU that has already been transferred from GPU to CPU. More...
 
T[] mutable_cpu_data [getset]
 Get/set the mutable host data. More...
 

Detailed Description

The SyncedMemory manages the low-level connection between the GPU and host memory.

The GPU memory is represented by a handle into the memory look-up table managed by the low-level CudaDnn DLL. The host memory is copied and stored in a local array of type 'T'.

Template Parameters
TSpecifies the base type float or double. Using float is recommended to conserve GPU memory.

Definition at line 17 of file SyncedMemory.cs.

Constructor & Destructor Documentation

◆ SyncedMemory()

MyCaffe.common.SyncedMemory< T >.SyncedMemory ( CudaDnn< T >  cuda,
Log  log,
long  lCapacity = 0,
object  tag = null,
bool  bUseHalfSize = false 
)

The SyncedMemory constructor.

Parameters
cudaSpecifies the CudaDnn connection to Cuda.
logSpecifies the Log for output.
lCapacityOptionally, specifies the capacity of the SyncedMemory (in items).
tagOptionally, specifies a tag used for debugging (the default = null).
bUseHalfSizeOptionally, specifies to use half size (FP16) for both data and diff. This option is only available when using the float base type 'T'.

Definition at line 38 of file SyncedMemory.cs.

Member Function Documentation

◆ Allocate() [1/2]

void MyCaffe.common.SyncedMemory< T >.Allocate ( long  lCount,
bool  bUseHalfSize = false 
)

Allocate a number of items in GPU memory and save the handle.

Parameters
lCountSpecifies the number of items.
bUseHalfSizeOptionally, specifis to use half sized memory (default = false). This only applies to the 'float' base type.

Definition at line 92 of file SyncedMemory.cs.

◆ Allocate() [2/2]

void MyCaffe.common.SyncedMemory< T >.Allocate ( T[]  rg,
bool  bUseHalfSize = false 
)

Allocate a number of items and copy the given array into the memory on the GPU.

Parameters
rgSpecifies the array of items to copy.
bUseHalfSizeOptionally, specifis to use half sized memory (default = false). This only applies to the 'float' base type.

Definition at line 117 of file SyncedMemory.cs.

◆ async_gpu_push()

void MyCaffe.common.SyncedMemory< T >.async_gpu_push ( long  hStream,
T[]  rg 
)

Pushes the host data, previously set with set_cpu_data_locally(), to the GPU.

Note, if necessary, this function re-allocates the GPU memory.

Parameters
hStream
rg

Definition at line 446 of file SyncedMemory.cs.

◆ Clone()

Copy this SyncedMemory.

Returns
A new SynedMemory that is a copy of this one, is returned.

Definition at line 252 of file SyncedMemory.cs.

◆ Copy()

long MyCaffe.common.SyncedMemory< T >.Copy ( SyncedMemory< T >  src,
long  hDstHostBuffer = 0 
)

Copy another SyncedMemory into this one.

Parameters
srcSpecifies the SyncedMemory to copy.
hDstHostBufferOptionally, specifies a host buffer used to copy between kernels (default = 0, not used).
Returns
When used the dst host buffer handle is returned.

Definition at line 205 of file SyncedMemory.cs.

◆ Dispose()

void MyCaffe.common.SyncedMemory< T >.Dispose ( )

Releases all GPU and host resources used.

Definition at line 77 of file SyncedMemory.cs.

◆ GetAt()

T MyCaffe.common.SyncedMemory< T >.GetAt ( int  nIdx)

Return a value at a given index.

Parameters
nIdxSpecifies the index.
Returns
The value at the index is returned.

Definition at line 192 of file SyncedMemory.cs.

◆ Set()

void MyCaffe.common.SyncedMemory< T >.Set ( double  dfVal)

Set all items up to Count to a given value.

Parameters
dfValSpecifies the value.

Definition at line 167 of file SyncedMemory.cs.

◆ set_cpu_data_locally()

void MyCaffe.common.SyncedMemory< T >.set_cpu_data_locally ( T[]  rg)

This does not place the data on the GPU - call async_gpu_push() to move it to the GPU.

Parameters
rgSpecifies an array of host data.

Definition at line 433 of file SyncedMemory.cs.

◆ set_gpu_data()

void MyCaffe.common.SyncedMemory< T >.set_gpu_data ( long  hData,
long  lCount,
long  lOffset 
)

Copies a new Memory Pointer within the low-level CudaDnnDLL where a Memory Pointer uses another already allocated block of GPU memory and just indexes into it.

Parameters
hDataSpecifies a handle to the already allocated GPU memory that the new Memory Pointer will index into.
lCountSpecifies the number of items in this 'virtual memory'
lOffsetSpecifies the offset into the GPU data where the Memory Pointer should start.

Definition at line 319 of file SyncedMemory.cs.

◆ SetAt()

void MyCaffe.common.SyncedMemory< T >.SetAt ( int  nIdx,
fVal 
)

Set a specific item at a given index to a value.

Parameters
nIdxSpecifies the index.
fValSpecifies the value.

Definition at line 181 of file SyncedMemory.cs.

◆ SetData()

void MyCaffe.common.SyncedMemory< T >.SetData ( T[]  rgData,
int  nCount,
bool  bSetCount = true 
)

Sets the array of host data on the GPU and re-allocates the GPU memory if needed.

Parameters
rgDataSpecifies the host data to set.
nCountSpecifies the number of items in the host data to set, which may be less than the host data array length.
bSetCountOptionally, specifies whether or not to set the count. The count is always set when re-allocating the buffer.

Definition at line 359 of file SyncedMemory.cs.

◆ update_cpu_data()

T[] MyCaffe.common.SyncedMemory< T >.update_cpu_data ( long  lCount = -1)

Updates the host data by copying the GPU data to the host data.

Parameters
lCountOptionally, specifies a count (less than Count) to transfer.
Returns
An array of the host data is returned.

Definition at line 409 of file SyncedMemory.cs.

◆ Zero()

void MyCaffe.common.SyncedMemory< T >.Zero ( )

Set all items in the GPU memory up to the Count, to zero.

Definition at line 142 of file SyncedMemory.cs.

◆ ZeroAll()

void MyCaffe.common.SyncedMemory< T >.ZeroAll ( )

Set all items in the GPU memory up to the Capacity, to zero.

Definition at line 154 of file SyncedMemory.cs.

Property Documentation

◆ Capacity

long MyCaffe.common.SyncedMemory< T >.Capacity
get

Returns the total amount of GPU memory held by this SyncedMemory.

Definition at line 290 of file SyncedMemory.cs.

◆ Count

long MyCaffe.common.SyncedMemory< T >.Count
getset

Returns the current count of items in this SyncedMemory. Note, the Count may be less than the Capacity.

Definition at line 298 of file SyncedMemory.cs.

◆ cpu_data

T [] MyCaffe.common.SyncedMemory< T >.cpu_data
get

Returns the data on the CPU that has already been transferred from GPU to CPU.

Definition at line 348 of file SyncedMemory.cs.

◆ DeviceID

int MyCaffe.common.SyncedMemory< T >.DeviceID
get

Returns the Device ID on which the GPU memory of this SyncedMemory was allocated.

Definition at line 282 of file SyncedMemory.cs.

◆ gpu_data

long MyCaffe.common.SyncedMemory< T >.gpu_data
get

Returns the handle to the GPU memory.

Definition at line 307 of file SyncedMemory.cs.

◆ HalfSize

bool MyCaffe.common.SyncedMemory< T >.HalfSize
get

Returns whether or not the sync memory is half-sized memory.

Definition at line 265 of file SyncedMemory.cs.

◆ mutable_cpu_data

T [] MyCaffe.common.SyncedMemory< T >.mutable_cpu_data
getset

Get/set the mutable host data.

When setting the mutable host data, the data is copied to the GPU. When get'ing the host data, the data is transferred from the GPU first and then returned.

Definition at line 385 of file SyncedMemory.cs.

◆ mutable_gpu_data

long MyCaffe.common.SyncedMemory< T >.mutable_gpu_data
get

Returns the mutable handle to GPU data.

Note: This is the same as gpu_data, but is provided for compatibility and readability with the original C++ Caffe code.

Definition at line 335 of file SyncedMemory.cs.

◆ Tag

object MyCaffe.common.SyncedMemory< T >.Tag
getset

Get/set data associated with the synced memory.

Definition at line 273 of file SyncedMemory.cs.


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