This repository has been 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.8k
[MXNET-323] Improve performance of broadcast ops backward pass #11252
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c86c618
Fix cached broadcast
anirudh2290 3e77798
Fix
anirudh2290 e09810c
Use seq_reduce_compute logic for stable sum
anirudh2290 cd29174
Fix lint
anirudh2290 4142b92
Add declarations
anirudh2290 27bb730
Merge branch 'master' of https://github.com/dmlc/mxnet into cached_br…
anirudh2290 8e2b4a8
Add elemwise binary broadcast op cuh file
anirudh2290 cf481f6
Add license for elemwise_binary_broadcast_op-inl.cuh
anirudh2290 1cd2470
Fix broadcast
anirudh2290 c0926f6
Fix indentation
anirudh2290 76850d9
Use cpu and gpu instead of xpu
anirudh2290 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 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 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 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#ifndef MXNET_OPERATOR_TENSOR_ELEMWISE_BINARY_BROADCAST_OP_CUH_ | ||
#define MXNET_OPERATOR_TENSOR_ELEMWISE_BINARY_BROADCAST_OP_CUH_ | ||
#include <mxnet/operator_util.h> | ||
#include <mxnet/op_attr_types.h> | ||
#include <algorithm> | ||
#include <vector> | ||
#include <string> | ||
#include <utility> | ||
#include "broadcast_reduce-inl.h" | ||
namespace mxnet { | ||
namespace op { | ||
template<typename xpu, typename LOP, typename ROP> | ||
inline typename std::enable_if<std::is_same<xpu, gpu>::value, void>::type | ||
BinaryBroadcastBackwardUseNone(const nnvm::NodeAttrs& attrs, | ||
const OpContext& ctx, | ||
const std::vector<TBlob>& inputs, | ||
const std::vector<OpReqType>& req, | ||
const std::vector<TBlob>& outputs) { | ||
using namespace broadcast; | ||
TShape new_lshape, new_rshape, new_oshape; | ||
int ndim = BinaryBroadcastShapeCompact(outputs[0].shape_, outputs[1].shape_, inputs[0].shape_, | ||
&new_lshape, &new_rshape, &new_oshape); | ||
if (!ndim) { | ||
ElemwiseBinaryOp::BackwardUseNone<gpu, LOP, ROP>(attrs, ctx, inputs, req, outputs); | ||
} else { | ||
MSHADOW_TYPE_SWITCH(outputs[0].type_flag_, DType, { | ||
Stream<gpu> *s = ctx.get_stream<gpu>(); | ||
const TBlob lhs = outputs[0].reshape(new_lshape); | ||
const TBlob rhs = outputs[1].reshape(new_rshape); | ||
const TBlob out = inputs[0].reshape(new_oshape); | ||
BROADCAST_NDIM_SWITCH(ndim, NDim, { | ||
// Request temporary storage | ||
size_t workspace_size = new_oshape.Size(); | ||
Tensor<gpu, 1, char> workspace = | ||
ctx.requested[0].get_space_typed<gpu, 1, char>( | ||
Shape1(workspace_size * sizeof(index_t)), s); | ||
Reduce<red::sum, NDim, DType, LOP>(s, lhs, req[0], workspace, out); | ||
Reduce<red::sum, NDim, DType, ROP>(s, rhs, req[1], workspace, out); | ||
}); | ||
}); | ||
} | ||
} | ||
} // namespace op | ||
} // namespace mxnet | ||
#endif |
This file contains 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.
since this implementation is only for cpu, is it better to replace xpu with cpu inside?