Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
More guards
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrendx committed Jun 26, 2020
1 parent e7ad72b commit d889bdc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/operator/nn/layer_norm-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void LayerNormComputeGeneral(const nnvm::NodeAttrs& attrs,
BinaryBroadcastRTCCompute {"sub"}(attrs, ctx,
{inputs[0], outputs[layernorm::kMean]},
{kWriteTo}, {outputs[0]});
#endif
#endif // MXNET_USE_CUDA
}
// Calculate std
const TBlob centered_out = outputs[0].reshape(red_src_shape);
Expand Down Expand Up @@ -190,7 +190,7 @@ void LayerNormComputeGeneral(const nnvm::NodeAttrs& attrs,
BinaryBroadcastRTCCompute {"add"}(attrs, ctx,
{outputs[0], beta},
{kWriteTo}, {outputs[0]});
#endif
#endif // MXNET_USE_CUDA
}
}

Expand Down Expand Up @@ -289,7 +289,7 @@ void LayerNormGradComputeGeneral(const nnvm::NodeAttrs& attrs,
BinaryBroadcastRTCCompute {"div"}(attrs, ctx,
{normalized_data, std},
{kWriteTo}, {normalized_data});
#endif
#endif // MXNET_USE_CUDA
}
// Calculate grad_beta
bool safe_acc = dmlc::GetEnv("MXNET_SAFE_ACCUMULATION", false);
Expand All @@ -313,8 +313,10 @@ void LayerNormGradComputeGeneral(const nnvm::NodeAttrs& attrs,
ElemwiseBinaryOp::Compute<xpu, op::mshadow_op::mul>(attrs, ctx, {normalized_data, ograd},
{kWriteTo}, {ograd_mult});
} else {
#if MXNET_USE_CUDA
ElemwiseBinaryRTCCompute {"mul"}(attrs, ctx, {normalized_data, ograd},
{kWriteTo}, {ograd_mult});
#endif // MXNET_USE_CUDA
}
if (req[1] != kNullOp) {
MSHADOW_REAL_TYPE_SWITCH(outputs[1].type_flag_, DType, {
Expand Down Expand Up @@ -351,7 +353,7 @@ void LayerNormGradComputeGeneral(const nnvm::NodeAttrs& attrs,
BinaryBroadcastRTCCompute {"div"}(attrs, ctx,
{ograd_mult, std},
{kWriteTo}, {ograd_mult});
#endif
#endif // MXNET_USE_CUDA
}
MSHADOW_REAL_TYPE_SWITCH(outputs[0].type_flag_, DType, {
BROADCAST_NDIM_SWITCH(red_dst_shape.ndim(), NDim, {
Expand All @@ -375,11 +377,13 @@ void LayerNormGradComputeGeneral(const nnvm::NodeAttrs& attrs,
ElemwiseBinaryOp::Compute<xpu, op::mshadow_op::mul>(attrs, ctx, {ograd_mult, normalized_data},
{kWriteTo}, {ograd_mult});
} else {
#if MXNET_USE_CUDA
BinaryBroadcastRTCCompute {"sub"}(attrs, ctx,
{ograd_mult, red_out},
{req[0]}, {outputs[0]});
ElemwiseBinaryRTCCompute {"mul"}(attrs, ctx, {ograd_mult, normalized_data},
{kWriteTo}, {ograd_mult});
#endif // MXNET_USE_CUDA
}
MSHADOW_REAL_TYPE_SWITCH(outputs[0].type_flag_, DType, {
BROADCAST_NDIM_SWITCH(red_dst_shape.ndim(), NDim, {
Expand All @@ -405,7 +409,7 @@ void LayerNormGradComputeGeneral(const nnvm::NodeAttrs& attrs,
BinaryBroadcastRTCCompute {"mul"}(attrs, ctx,
{normalized_data, red_out},
{kAddTo}, {outputs[0]});
#endif
#endif // MXNET_USE_CUDA
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/operator/tensor/elemwise_unary_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void inline CopyBlob(mshadow::Stream<xpu> *s,
* \param dest Destination sparse NDArray
* \param clone_from sparse NDArray from which to clone storage attributes
*/
void AllocateGeometry(const NDArray *dest,
void inline AllocateGeometry(const NDArray *dest,
const OpReqType req,
const NDArray* clone_from = nullptr) {
if (req != kNullOp) {
Expand Down

0 comments on commit d889bdc

Please sign in to comment.