-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Describe problems for functor #3893
Describe problems for functor #3893
Conversation
7a7b90e
to
131d961
Compare
doc/design/functor.md
Outdated
@@ -0,0 +1,17 @@ | |||
# Design Doc: Operator Functor | |||
|
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.
Functions or Functors
#include <algorithm>
#include <iostream>
template <typename T>
T tanh(T x) {
return static_cast<T>(1);
}
template <typename T, typename S>
T sigmoid(T x, S s) {
return (tanh(x) + 1) * s;
}
template <typename Place>
class SigmodOpKernel /*: public framework::OpKernel*/ {
template <typename T, typename S>
class Sigmoid {
public:
Sigmoid(S scale) : scale_(scale) {}
/*__host__ __device__*/ T operator(T x) const { return sigmoid(x, scale_); }
private:
const S scale_;
}
};
template <>
class SigmodOpKernel<CPUPlace> : public framework::OpKernel {};
public:
void Compute(ctx) {
std::transform(
ctx.Input<Tensor>("X")->data(),
ctx.Input<Tensor>("X")->data() + product(ctx.Input<Tensor>("X")->dims()),
ctx.Output<Tensor>("Out")->mutable_data(),
Sigmoid(ctx->Attr<float>("scale")));
}
};
// template <>
// class SigmodOpKernel<GPUPlace> : public framework::OpKernel {};
// public:
// void Compute(ctx) {
// thrust::transform(
// ctx.Input<Tensor>("X")->data(),
// ctx.Input<Tensor>("X")->data() + product(ctx.Input<Tensor>("X")->dims()),
// ctx.Output<Tensor>("Out")->mutable_data(),
// Sigmoid(ctx->Attr<float>("scale")));
// }
// };
doc/design/functor.md
Outdated
@@ -0,0 +1,17 @@ | |||
# Design Doc: Operator Functor |
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.
Design Doc: Functions
Following the overall design, this document is about the functions and how they compose into operators.
Basically, to the ease of definitions, functions operate on scalar values. But most operators operate on Tensors. For example:
Dose this doc only focus on element-wise operators or try to propose a general solution? |
Closed since #3901 |
Part one of
Functor Design Doc
. It describes what problems should be resolved.Related issue #3894