You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@singa.apache.org by "ASF subversion and git services (JIRA)" <ji...@apache.org> on 2016/06/24 05:04:16 UTC

[jira] [Commented] (SINGA-205) Enable slice and concatenate operations for Tensor objects

    [ https://issues.apache.org/jira/browse/SINGA-205?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15347714#comment-15347714 ] 

ASF subversion and git services commented on SINGA-205:
-------------------------------------------------------

Commit 9abd7910d5f4d19202813150339f51cf0500eab1 in incubator-singa's branch refs/heads/dev from [~flytosky]
[ https://git-wip-us.apache.org/repos/asf?p=incubator-singa.git;h=9abd791 ]

SINGA-205 - Enable slice and concatenate operations for Tensor objects

Update the Block class to add the `offset_` field and change the type of
ref_count_ to shared_ptr<atomic<int>>.
Now, we can share the ref_count_ and data_ between different Blocks.
It is useful if Block A is a sub-block of Blokc B, i.e., Block A's data() is Block B's data() + offset.
This feature is not used currently.

Implement CopyRows, CopyColumns, ConcatenateRows and ConcatenateColumns.
SliceRows() is not implmented yet, which may affect the block management
(some blocks sharing internal data).


> Enable slice and concatenate operations for Tensor objects
> ----------------------------------------------------------
>
>                 Key: SINGA-205
>                 URL: https://issues.apache.org/jira/browse/SINGA-205
>             Project: Singa
>          Issue Type: New Feature
>            Reporter: wangwei
>            Assignee: wangwei
>
> Slice and concatenate operations are typical array operations, and are necessary to support some models, e.g., GoogleLeNet.
> For this ticket, we are going to implement the two operations to support 1D and 2D tensors.  The following functions would be implemented,
> 1. SliceRows(Tensor, start, end), the returned tensor shares the memory with the origin tensor.
> 2. CopyRows(Tensor, start, end), CopyColumns(Tensor, start, end) the returned tensor copies values from the original tensor
> 3. ConcatenateRows(vector<Tensor>) and ConcatenateColumns(vector<Tensor>); the returned tensor copies values from the origin tensors.
> To support SliceRows, i.e., memory sharing between two tensors of different sizes, we need to update the Block class as
> {code}
> class Block {
>   Block(void* ptr, size_t size, size_t offset=0);
>   void* mutable_data() const  { return data_+offset_;}
>   const void* data() const  { return data_+offset_;}
>   private:
>     void *data_;
>     size_t offset_ = 0;  // offset in terms of Bytes.
>     shared_ptr<atomic<int>> ref_count_;
> };
> {code}
> The sub-tensors (i.e., generated from SliceRows) would have a different Block instance as the original tensor, but would share the internal `ref_count_` and `data_` fields.
> `offset_` is 0 for the original tensors, but non-zero for sub-tensors . atomic makes the inc and dec operations thread-safe. shared_ptr helps to free `ref_count_` safely.
> SliceColumns is not supported as singa::Tensor uses row major storage which is difficult to support SliceColumns SliceRows(). Users can use CopyColumns().



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)