MyCaffe
1.12.2.41
Deep learning software for Windows C# programmers.
|
The SyncedMemory manages the low-level connection between the GPU and host memory. More...
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... | |
T | 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... | |
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'.
T | Specifies the base type float or double. Using float is recommended to conserve GPU memory. |
Definition at line 17 of file SyncedMemory.cs.
MyCaffe.common.SyncedMemory< T >.SyncedMemory | ( | CudaDnn< T > | cuda, |
Log | log, | ||
long | lCapacity = 0 , |
||
object | tag = null , |
||
bool | bUseHalfSize = false |
||
) |
The SyncedMemory constructor.
cuda | Specifies the CudaDnn connection to Cuda. |
log | Specifies the Log for output. |
lCapacity | Optionally, specifies the capacity of the SyncedMemory (in items). |
tag | Optionally, specifies a tag used for debugging (the default = null). |
bUseHalfSize | Optionally, 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.
void MyCaffe.common.SyncedMemory< T >.Allocate | ( | long | lCount, |
bool | bUseHalfSize = false |
||
) |
Allocate a number of items in GPU memory and save the handle.
lCount | Specifies the number of items. |
bUseHalfSize | Optionally, specifis to use half sized memory (default = false). This only applies to the 'float' base type. |
Definition at line 92 of file SyncedMemory.cs.
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.
rg | Specifies the array of items to copy. |
bUseHalfSize | Optionally, specifis to use half sized memory (default = false). This only applies to the 'float' base type. |
Definition at line 117 of file SyncedMemory.cs.
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.
hStream | |
rg |
Definition at line 446 of file SyncedMemory.cs.
SyncedMemory< T > MyCaffe.common.SyncedMemory< T >.Clone | ( | ) |
Copy this SyncedMemory.
Definition at line 252 of file SyncedMemory.cs.
long MyCaffe.common.SyncedMemory< T >.Copy | ( | SyncedMemory< T > | src, |
long | hDstHostBuffer = 0 |
||
) |
Copy another SyncedMemory into this one.
src | Specifies the SyncedMemory to copy. |
hDstHostBuffer | Optionally, specifies a host buffer used to copy between kernels (default = 0, not used). |
Definition at line 205 of file SyncedMemory.cs.
void MyCaffe.common.SyncedMemory< T >.Dispose | ( | ) |
Releases all GPU and host resources used.
Definition at line 77 of file SyncedMemory.cs.
T MyCaffe.common.SyncedMemory< T >.GetAt | ( | int | nIdx | ) |
Return a value at a given index.
nIdx | Specifies the index. |
Definition at line 192 of file SyncedMemory.cs.
void MyCaffe.common.SyncedMemory< T >.Set | ( | double | dfVal | ) |
Set all items up to Count to a given value.
dfVal | Specifies the value. |
Definition at line 167 of file SyncedMemory.cs.
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.
rg | Specifies an array of host data. |
Definition at line 433 of file SyncedMemory.cs.
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.
hData | Specifies a handle to the already allocated GPU memory that the new Memory Pointer will index into. |
lCount | Specifies the number of items in this 'virtual memory' |
lOffset | Specifies the offset into the GPU data where the Memory Pointer should start. |
Definition at line 319 of file SyncedMemory.cs.
void MyCaffe.common.SyncedMemory< T >.SetAt | ( | int | nIdx, |
T | fVal | ||
) |
Set a specific item at a given index to a value.
nIdx | Specifies the index. |
fVal | Specifies the value. |
Definition at line 181 of file SyncedMemory.cs.
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.
rgData | Specifies the host data to set. |
nCount | Specifies the number of items in the host data to set, which may be less than the host data array length. |
bSetCount | Optionally, 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.
T[] MyCaffe.common.SyncedMemory< T >.update_cpu_data | ( | long | lCount = -1 | ) |
Updates the host data by copying the GPU data to the host data.
lCount | Optionally, specifies a count (less than Count) to transfer. |
Definition at line 409 of file SyncedMemory.cs.
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.
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.
|
get |
Returns the total amount of GPU memory held by this SyncedMemory.
Definition at line 290 of file SyncedMemory.cs.
|
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.
|
get |
Returns the data on the CPU that has already been transferred from GPU to CPU.
Definition at line 348 of file SyncedMemory.cs.
|
get |
Returns the Device ID on which the GPU memory of this SyncedMemory was allocated.
Definition at line 282 of file SyncedMemory.cs.
|
get |
Returns the handle to the GPU memory.
Definition at line 307 of file SyncedMemory.cs.
|
get |
Returns whether or not the sync memory is half-sized memory.
Definition at line 265 of file SyncedMemory.cs.
|
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.
|
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.
|
getset |
Get/set data associated with the synced memory.
Definition at line 273 of file SyncedMemory.cs.