This repository was archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Operator add_n for row sparse ndarrays #7244
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
85226ca
Add add_n op for row-sparse ndarrays and identity FComputeEx
reminisce acc4bda
Fix bug in square_sum
reminisce 0ef64cf
Remove test_cast_storage_ex from gpu test since it's not implemented yet
reminisce 6fc7ea7
Fix according to the cr
reminisce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,8 @@ void Copy<cpu, cpu>(const TBlob &from, TBlob *to, | |
| } | ||
|
|
||
| template<typename DType, typename IType> | ||
| void ElementwiseSumRspImpl(const std::vector<NDArray>& nds, | ||
| void ElementwiseSumRspImpl(mshadow::Stream<cpu>* s, | ||
| const std::vector<NDArray>& nds, | ||
| const std::vector<IType>& uniq_row_idx, | ||
| NDArray* out, | ||
| const int nthreads = 4) { | ||
|
|
@@ -42,15 +43,18 @@ void ElementwiseSumRspImpl(const std::vector<NDArray>& nds, | |
| if (row_block_start < nnr) { | ||
| const size_t row_block_end = std::min(row_block_start+row_block_len, nnr); | ||
|
|
||
| auto out_values = out->data().FlatTo2D<cpu, DType>(); | ||
| const size_t row_length = out->data().shape_.ProdShape(1, out->data().shape_.ndim()); | ||
| auto out_values = out->data().get_with_shape<cpu, 2, DType>( | ||
| mshadow::Shape2(out->storage_shape()[0], row_length), s); | ||
| auto out_indices = out->aux_data(rowsparse::kIdx).FlatTo1D<cpu, IType>(); | ||
| for (size_t i = row_block_start; i < row_block_end; ++i) { | ||
| out_indices[i] = uniq_row_idx[i]; | ||
| } | ||
| for (const auto& nd : nds) { | ||
| if (nd.storage_initialized()) { | ||
| const auto nd_indices = nd.aux_data(rowsparse::kIdx).FlatTo1D<cpu, IType>(); | ||
| const auto nd_values = nd.data().FlatTo2D<cpu, DType>(); | ||
| const auto nd_values = nd.data().get_with_shape<cpu, 2, DType>( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you discuss the new FlatTo2D method with Eric?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. He suggested not adding a bool argument but calculating the desired shape explicitly. |
||
| mshadow::Shape2(nd.storage_shape()[0], row_length), s); | ||
| const auto nd_num_rows = nd.aux_shape(rowsparse::kIdx).Size(); | ||
| const IType* nd_indices_start = &nd_indices[0]; | ||
| const IType* nd_indices_end = nd_indices_start + nd_num_rows; | ||
|
|
@@ -120,7 +124,7 @@ void GetUniqueRspRowIdx(const std::vector<NDArray>& nds, | |
| uniq_row_idx->resize(it - uniq_row_idx->begin()); | ||
| } | ||
|
|
||
| void ElementwiseSumRsp(const std::vector<NDArray>& nds, NDArray* out) { | ||
| void ElementwiseSumRsp(mshadow::Stream<cpu>* s, const std::vector<NDArray>& nds, NDArray* out) { | ||
| if (nds.empty()) return; | ||
| using namespace rowsparse; | ||
| CHECK_EQ(out->storage_type(), kRowSparseStorage) | ||
|
|
@@ -133,7 +137,7 @@ void ElementwiseSumRsp(const std::vector<NDArray>& nds, NDArray* out) { | |
| GetUniqueRspRowIdx(nds, &uniq_row_idx); | ||
| out->CheckAndAlloc({mshadow::Shape1(uniq_row_idx.size())}); | ||
| out->data().FlatTo2D<cpu, DType>() = static_cast<DType>(0); | ||
| ElementwiseSumRspImpl<DType, IType>(nds, uniq_row_idx, out, omp_get_max_threads()); | ||
| ElementwiseSumRspImpl<DType, IType>(s, nds, uniq_row_idx, out, omp_get_max_threads()); | ||
| }); | ||
| }); | ||
| } | ||
|
|
@@ -149,7 +153,7 @@ void ElementwiseSum<cpu>(mshadow::Stream<cpu>* s, | |
| if (nds.empty()) return; | ||
|
|
||
| if (nds[0].storage_type() == kRowSparseStorage) { | ||
| ElementwiseSumRsp(nds, out); | ||
| ElementwiseSumRsp(s, nds, out); | ||
| } else { | ||
| LOG(FATAL) << "ElementwiseSum<cpu> has not been implemented for storage_type = << " | ||
| << nds[0].storage_type(); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make it inline?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Member functions defined inside classes are automatically inline. There is no need to put the key word
inlinein front of it.