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

Commit

Permalink
chg
Browse files Browse the repository at this point in the history
  • Loading branch information
antinucleon committed Jun 19, 2015
1 parent 3317180 commit e4e2178
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions src/operator/activation_op-inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,28 @@
#define ACTIVATION_OP_INL_HPP

This comment has been minimized.

Copy link
@tqchen

tqchen Jun 20, 2015

Member

try follow google c style, use -inl.h

#pragma once
#include <mxnet/operator.h>
#include <vector>

namespace mxnet {
template<typename xpu, typename ForwardOp, typename BackOp>
class ActivationOp : public Operator {
public:
public:
virtual void InferShape(const std::vector<TShape> &in_shape,
std::vector<TShape> *out_shape) {
CHECK(in_shape.size() == 1) << "Activation Op: only 1 input is allowed";
out_shape->resize(in_shape.size());
out_shape->at(0) = in_shape[0];
TShape out = in_shape[0];
out_shape->push_back(out);
}
virtual void Forward(Option opt,
RunContext ctx,
const std::vector<TBlob> &in_data,
const std::vector<TBlob> &out_data) {
CHECK(out_data.size() == 1) << "Activation Op: only 1 output data is allowed";
CHECK(in_data.size() == 1) << "Activation Op: only 1 input data is allowed";
mshadow::Stream<xpu> *stream = static_cast<mshadow::Stream<xpu> *>(ctx.stream);
CHECK(out_data.size() == 1) << \
"Activation Op: only 1 output data is allowed";

This comment has been minimized.

Copy link
@tqchen

tqchen Jun 20, 2015

Member

maybe we only need to have error message at infer shape

CHECK(in_data.size() == 1) << \
"Activation Op: only 1 input data is allowed";
mshadow::Stream<xpu> *stream = \
static_cast<mshadow::Stream<xpu> *>(ctx.stream);
mshadow::Tensor<xpu, 2> in = in_data[0].FlatTo2D(stream);
mshadow::Tensor<xpu, 2> out = out_data[0].FlatTo2D(stream);
out = mshadow::expr::F<ForwardOp>(in);
Expand All @@ -35,16 +39,23 @@ class ActivationOp : public Operator {
const std::vector<TBlob> &in_data,
const std::vector<TBlob> &out_grad,
const std::vector<GradReqType> req) {
CHECK(grad_next.size() == 1) << "Activation Op: only 1 input grad is allowed";
CHECK(in_data.size() == 1) << "Activation Op: only 1 input data is allowed";
CHECK(req.size() == 1) << "Activation Op: only 1 req is allowed";
CHECK(req[0] == kWriteInplace) << "Activation Op: only support inplace mode";
mshadow::Stream<xpu> *stream = static_cast<mshadow::Stream<xpu> *>(ctx.stream);
CHECK(grad_next.size() == 1) << \
"Activation Op: only 1 input grad is allowed";
CHECK(in_data.size() == 1) << \
"Activation Op: only 1 input data is allowed";
CHECK(req.size() == 1) << \
"Activation Op: only 1 req is allowed";
CHECK(req[0] == kWriteInplace) << \
"Activation Op: only support inplace mode";
mshadow::Stream<xpu> *stream = \
static_cast<mshadow::Stream<xpu> *>(ctx.stream);
mshadow::Tensor<xpu, 2> grad = grad_next[0].FlatTo2D(stream);
mshadow::Tensor<xpu, 2> data = in_data[0].FlatTo2D(stream);
data = mshadow::expr::F<BackOp>(data) * grad;

This comment has been minimized.

Copy link
@tqchen

tqchen Jun 20, 2015

Member

seems GradientReqType is not checked, this implementation was inplace

}
}; // class ActivationOp
} // namespace cxxnet
}; // class ActivationOp
} // namespace mxnet

#endif // ACTIVATION_OP_INL_HPP


#endif // ACTIVATION_OP_INL_HPP

0 comments on commit e4e2178

Please sign in to comment.