Skip to content

Conversation

@Superjomn
Copy link
Contributor

No description provided.

namespace paddle {
namespace framework {

void OperatorBase::CreateArgumentOffsetMap(const OpProto& proto) {
Copy link
Member

@jacquesqiao jacquesqiao Jul 16, 2017

Choose a reason for hiding this comment

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

Argument in caffe2 has the same meaning with Attribute in Paddle. Should we name it CreateInOutOffsetMap or something else?

Copy link
Contributor Author

@Superjomn Superjomn Jul 17, 2017

Choose a reason for hiding this comment

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

this map stores both the inputs and outputs offests, so maybe CreateArgmentOffsetsMap ?

Copy link
Member

@jacquesqiao jacquesqiao Jul 17, 2017

Choose a reason for hiding this comment

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

InOut instead of Input ~

virtual void Run(const ScopePtr& scope,
const platform::DeviceContext& dev_ctx) const = 0;

// Get a input with argument's name described in `op_desc`
Copy link
Member

Choose a reason for hiding this comment

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

described in op_proto or op_proto_and_checker_maker


const std::string& OperatorBase::Input(const std::string& name) const {
auto it = arg_idxs_.find(name);
PADDLE_ENFORCE(it != arg_idxs_.end(), "no key [%d] in arg_idxs_", name);
Copy link
Member

Choose a reason for hiding this comment

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

[%d] --> [%s]


const std::string& OperatorBase::Output(const std::string& name) const {
auto it = arg_idxs_.find(name);
PADDLE_ENFORCE(it != arg_idxs_.end(), "no key [%d] in arg_idxs_", name);
Copy link
Member

Choose a reason for hiding this comment

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

[%d] --> [%s]

void Run(const std::shared_ptr<Scope>& scope,
const platform::DeviceContext& dev_ctx) const override {
float scale = GetAttr<float>("scale");
ASSERT_NEAR(scale, 3.14, 1e-5);
Copy link
Member

Choose a reason for hiding this comment

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

can remove the unnecessary assert

if (attrs_.count("input_format") == 0) {
return inputs_[it->second];
} else {
const auto& input_format = GetAttr<std::vector<int>>("input_format");
Copy link
Contributor

Choose a reason for hiding this comment

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

What does the input_format mean? If it is the necessary attribute for dynamic-length inputs, should check it in the op_checker ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

OpKernelTestMultiInputsProtoAndCheckerMaker(OpProto* proto,
OpAttrChecker* op_checker)
: OpProtoAndCheckerMaker(proto, op_checker) {
AddInputs("xs", "input of test op");
Copy link
Contributor

Choose a reason for hiding this comment

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

inputs of test op

: OpProtoAndCheckerMaker(proto, op_checker) {
AddInputs("xs", "input of test op");
AddInput("k", "input of test op");
AddOutputs("ys", "output of test op");
Copy link
Contributor

Choose a reason for hiding this comment

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

outputs of test op

attr->set_f(3.14);

auto attr0 = op_desc.mutable_attrs()->Add();
attr0->set_name("input_format");
Copy link
Contributor

Choose a reason for hiding this comment

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

input_starts or input_offsets?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

void CreateInOutOffsetMap(const OpProto& proto);

protected:
std::string Type() const { return type_; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

type_ is better.

void OperatorBase::CreateInOutOffsetMap(const OpProto& proto) {
for (int i = 0; i < proto.inputs_size(); i++) {
const auto& name = proto.inputs()[i].name();
arg_idxs_[name] = i;
Copy link
Member

Choose a reason for hiding this comment

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

in_out_inxs?

Copy link
Collaborator

Choose a reason for hiding this comment

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

actually, index --> indices?

Copy link
Collaborator

Choose a reason for hiding this comment

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

But it doesn't matter, we all understand what arg_idxs_ means.

Copy link
Contributor 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

Choose a reason for hiding this comment

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

为了保持一致,建议还是改成 in_out_idxs 之类的。

ASSERT_EQ((int)context.op_.outputs_.size(), 1);
ASSERT_NEAR(context.op_.GetAttr<float>("scale"), 3.14, 1e-5);
void Compute(const KernelContext& ctx) const {
std::cout << "this is cpu kernel" << std::endl;
Copy link
Member

Choose a reason for hiding this comment

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

cpu_kernel_run_num++ should be added back

}
}

std::vector<std::string> OperatorBase::Inputs(const std::string& name) const {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Possible optimization here. Return a vector_view instead of a vector to prevent memory copy. It is not critical for now. But we can still have a TODO comments here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added in header

done

limitations under the License. */

#pragma once
#include <glog/logging.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why need this include?

Copy link
Member

@jacquesqiao jacquesqiao left a comment

Choose a reason for hiding this comment

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

LGTM! except for a little question: What is the purpose of move CreateInOutOffsetMap from OperatorBase to op registry

@Superjomn Superjomn merged commit a0caf23 into PaddlePaddle:develop Jul 17, 2017
@Superjomn Superjomn deleted the op-varient-inputs branch July 17, 2017 08:03
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.

4 participants