Skip to content
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

Add skeletons of mul, rowwise_add, sigmoid, softmax ops #2914

Merged

Conversation

reyoung
Copy link
Collaborator

@reyoung reyoung commented Jul 17, 2017

  • Implement InferShape and register them, give a stub Kernel method
    by LOG(INFO)

* Implement InferShape and register them, give a stub Kernel method
  by LOG(INFO)
@reyoung reyoung requested review from JiayiFeng and QiJune July 17, 2017 07:58
@@ -278,5 +278,11 @@ std::ostream& operator<<(std::ostream& os, const DDim& ddim) {
return os;
}

ssize_t DDim::size() const { return product(*this); }

DDim::DDim(std::initializer_list<int> init_list) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constructor could be significantly easier for Op developer to invoke Tensor::set_dims.

Just by

tensor.set_dims({100, 784})

@@ -278,5 +278,11 @@ std::ostream& operator<<(std::ostream& os, const DDim& ddim) {
return os;
}

ssize_t DDim::size() const { return product(*this); }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, size() should be a member function for DDim. Invoke product is pretty strange to get the size.

auto dim0 = inputs[0]->dims();
auto dim1 = inputs[1]->dims();

PADDLE_ENFORCE(dim0.size() == 2, "Input 0 must be matrix");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, a matrix is a tensor with rank=2. It should be

PADDLE_ENFORCE(paddle::framework::arity(dim0)==2, "input 0 must be matrix");

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Change size() to arity

PADDLE_ENFORCE(inputs.size() == 2, "The mul op must take two inputs");
auto dim0 = inputs[0]->dims();
auto dim1 = inputs[1]->dims();
PADDLE_ENFORCE(dim0.size() == 2 && dim1.size() == 2,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the size of dim, but rank of dim.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@QiJune QiJune left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

op_library(mul_op SRCS mul_op.cc mul_op.cu)
op_library(rowwise_add_op SRCS rowwise_add_op.cu rowwise_add_op.cc)
op_library(sigmoid_op SRCS sigmoid_op.cu sigmoid_op.cc)
op_library(softmax_op SRCS softmax_op.cc softmax_op.cu)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to maintain a consistent sequence. .cc first and .cu follows.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a unit-test here to test op_library is not caring about source sequence.


#include <paddle/framework/op_registry.h>
#include <paddle/framework/tensor.h>
#include <paddle/operators/mul_op.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow the code style, using

#include "paddle/framework/op_registry.h"
#include "paddle/framework/tensor.h"
#include "paddle/operators/mul_op.h"

@reyoung reyoung merged commit 861b66d into PaddlePaddle:develop Jul 18, 2017
reyoung added a commit to reyoung/Paddle that referenced this pull request Jul 18, 2017
* There is a merge conflict when merge PR PaddlePaddle#2914
* Develop and PR PaddlePaddle#2914 both add `DDim::size` method, but did not
  triger git merge conflict while merge.
@reyoung reyoung mentioned this pull request Jul 18, 2017
@reyoung reyoung deleted the feature/add_some_skeletons_of_ops branch October 28, 2017 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants