ding.data.shm_buffer¶
ding.data.shm_buffer
¶
ShmBuffer
¶
Overview
Shared memory buffer to store numpy array.
__init__(dtype, shape, copy_on_get=True, ctype=None)
¶
Overview
Initialize the buffer.
Arguments:
- dtype (:obj:Union[type, np.dtype]): The dtype of the data to limit the size of the buffer.
- shape (:obj:Tuple[int]): The shape of the data to limit the size of the buffer.
- copy_on_get (:obj:bool): Whether to copy data when calling get method.
- ctype (:obj:Optional[type]): Origin class type, e.g. np.ndarray, torch.Tensor.
fill(src_arr)
¶
Overview
Fill the shared memory buffer with a numpy array. (Replace the original one.)
Arguments:
- src_arr (:obj:np.ndarray): array to fill the buffer.
get()
¶
Overview
Get the array stored in the buffer.
Return:
- data (:obj:np.ndarray): A copy of the data stored in the buffer.
ShmBufferContainer
¶
Bases: object
Overview
Support multiple shared memory buffers. Each key-value is name-buffer.
__init__(dtype, shape, copy_on_get=True)
¶
Overview
Initialize the buffer container.
Arguments:
- dtype (:obj:Union[type, np.dtype]): The dtype of the data to limit the size of the buffer.
- shape (:obj:Union[Dict[Any, tuple], tuple]): If Dict[Any, tuple], use a dict to manage multiple buffers; If tuple, use single buffer.
- copy_on_get (:obj:bool): Whether to copy data when calling get method.
fill(src_arr)
¶
Overview
Fill the one or many shared memory buffer.
Arguments:
- src_arr (:obj:Union[Dict[Any, np.ndarray], np.ndarray]): array to fill the buffer.
get()
¶
Overview
Get the one or many arrays stored in the buffer.
Return:
- data (:obj:np.ndarray): The array(s) stored in the buffer.
Full Source Code
../ding/data/shm_buffer.py