{"action":"created","comment":{"url":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls/comments/126057070","pull_request_review_id":48507347,"id":126057070,"diff_hunk":"@@ -0,0 +1,75 @@\n+/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.\n+\n+Licensed under the Apache License, Version 2.0 (the \"License\");\n+you may not use this file except in compliance with the License.\n+You may obtain a copy of the License at\n+\n+    http://www.apache.org/licenses/LICENSE-2.0\n+\n+Unless required by applicable law or agreed to in writing, software\n+distributed under the License is distributed on an \"AS IS\" BASIS,\n+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+See the License for the specific language governing permissions and\n+limitations under the License. */\n+\n+#pragma once\n+\n+#include <boost/variant.hpp>\n+#include <string>\n+#include <unordered_map>\n+#include <vector>\n+#include \"paddle/framework/op_desc.pb.h\"\n+#include \"paddle/framework/scope.h\"\n+#include \"paddle/utils/Error.h\"\n+\n+namespace paddle {\n+namespace framework {\n+\n+class DeviceContext {};\n+class CpuContext : public DeviceContext {};\n+class GpuContext : public DeviceContext {};\n+\n+/**\n+ * OpRunContext is the only parameter of Operator's Run function.\n+ * Run will get input/output variables, state such as momentum and\n+ * device resource such as CUDA stream, cublas handle, etc. from\n+ * OpRunContext. User should construct it before run the Operator.\n+ */\n+class OpRunContext {\n+ public:\n+  Scope* scope;\n+  DeviceContext* device_context;\n+};\n+\n+using Attribute =\n+    boost::variant<boost::blank, int, float, std::string, std::vector<int>,\n+                   std::vector<float>, std::vector<std::string>>;\n+using AttributeMap = std::unordered_map<std::string, Attribute>;\n+\n+/**\n+ * OperatorBase has the basic element that Net will call to do compute.\n+ * It have no construct function because CreateOperator(const& op_desc)\n+ * will parse op_desc and set the input/output/attr properly.\n+ */\n+class OperatorBase {\n+ public:\n+  virtual ~OperatorBase() {}\n+  /// when implement an Op, your should implement this function.\n+  virtual void Run(OpRunContext* context) const = 0;\n+\n+  /// InferShape infer the size of Variables used by this Operator with\n+  /// information\n+  /// inside scope\n+  virtual void InferShape(const Scope* scope) const = 0;\n+\n+  std::string DebugString() const;\n+\n+ public:","path":"paddle/framework/operator.h","position":67,"original_position":67,"commit_id":"57d1fbd6bebc675eb842d4541d8b53d29f0f2731","original_commit_id":"57d1fbd6bebc675eb842d4541d8b53d29f0f2731","user":{"login":"jacquesqiao","id":3048612,"avatar_url":"https://avatars3.githubusercontent.com/u/3048612?v=3","gravatar_id":"","url":"https://api.github.com/users/jacquesqiao","html_url":"https://github.com/jacquesqiao","followers_url":"https://api.github.com/users/jacquesqiao/followers","following_url":"https://api.github.com/users/jacquesqiao/following{/other_user}","gists_url":"https://api.github.com/users/jacquesqiao/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquesqiao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquesqiao/subscriptions","organizations_url":"https://api.github.com/users/jacquesqiao/orgs","repos_url":"https://api.github.com/users/jacquesqiao/repos","events_url":"https://api.github.com/users/jacquesqiao/events{/privacy}","received_events_url":"https://api.github.com/users/jacquesqiao/received_events","type":"User","site_admin":false},"body":"caffe里面是把这几个函数放在了OpBase中，因为caffe的op在new的时候把workspace和context都创建好放在了op里边，所以caffe op的run不需要加什么参数。\r\n\r\n我们目前scope和devicecontext都是运行时才能确定，通过组装成一个 OpRunContext 给 Run(OpRunContext* context) ，所以目前的想法是这几个函数都有OpRunContext提供：\r\n这样的话，很自然的，我们就会有OpKernel这个概念了，Operator存储一些非运行时的配置，运行之前组装OpRunContext传给OpKernel的run。\r\n```cpp\r\nclass OpKernel {\r\n  void Run(OpRunContext* context) {\r\n    auto input0 =  context.Input(0);\r\n    auto cuda_stream = contex.cuda_stream();\r\n  }\r\n}","created_at":"2017-07-07T02:18:05Z","updated_at":"2017-07-07T02:18:05Z","html_url":"https://github.com/PaddlePaddle/Paddle/pull/2725#discussion_r126057070","pull_request_url":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls/2725","_links":{"self":{"href":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls/comments/126057070"},"html":{"href":"https://github.com/PaddlePaddle/Paddle/pull/2725#discussion_r126057070"},"pull_request":{"href":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls/2725"}}},"pull_request":{"url":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls/2725","id":128720499,"html_url":"https://github.com/PaddlePaddle/Paddle/pull/2725","diff_url":"https://github.com/PaddlePaddle/Paddle/pull/2725.diff","patch_url":"https://github.com/PaddlePaddle/Paddle/pull/2725.patch","issue_url":"https://api.github.com/repos/PaddlePaddle/Paddle/issues/2725","number":2725,"state":"open","locked":false,"title":"add operator base","user":{"login":"jacquesqiao","id":3048612,"avatar_url":"https://avatars3.githubusercontent.com/u/3048612?v=3","gravatar_id":"","url":"https://api.github.com/users/jacquesqiao","html_url":"https://github.com/jacquesqiao","followers_url":"https://api.github.com/users/jacquesqiao/followers","following_url":"https://api.github.com/users/jacquesqiao/following{/other_user}","gists_url":"https://api.github.com/users/jacquesqiao/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquesqiao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquesqiao/subscriptions","organizations_url":"https://api.github.com/users/jacquesqiao/orgs","repos_url":"https://api.github.com/users/jacquesqiao/repos","events_url":"https://api.github.com/users/jacquesqiao/events{/privacy}","received_events_url":"https://api.github.com/users/jacquesqiao/received_events","type":"User","site_admin":false},"body":"","created_at":"2017-07-04T03:42:26Z","updated_at":"2017-07-07T02:18:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"80b9232d8eae6711eabb29d7fd7f8f128ca25bf6","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls/2725/commits","review_comments_url":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls/2725/comments","review_comment_url":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls/comments{/number}","comments_url":"https://api.github.com/repos/PaddlePaddle/Paddle/issues/2725/comments","statuses_url":"https://api.github.com/repos/PaddlePaddle/Paddle/statuses/57d1fbd6bebc675eb842d4541d8b53d29f0f2731","head":{"label":"jacquesqiao:opbase","ref":"opbase","sha":"57d1fbd6bebc675eb842d4541d8b53d29f0f2731","user":{"login":"jacquesqiao","id":3048612,"avatar_url":"https://avatars3.githubusercontent.com/u/3048612?v=3","gravatar_id":"","url":"https://api.github.com/users/jacquesqiao","html_url":"https://github.com/jacquesqiao","followers_url":"https://api.github.com/users/jacquesqiao/followers","following_url":"https://api.github.com/users/jacquesqiao/following{/other_user}","gists_url":"https://api.github.com/users/jacquesqiao/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquesqiao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquesqiao/subscriptions","organizations_url":"https://api.github.com/users/jacquesqiao/orgs","repos_url":"https://api.github.com/users/jacquesqiao/repos","events_url":"https://api.github.com/users/jacquesqiao/events{/privacy}","received_events_url":"https://api.github.com/users/jacquesqiao/received_events","type":"User","site_admin":false},"repo":{"id":75146336,"name":"Paddle","full_name":"jacquesqiao/Paddle","owner":{"login":"jacquesqiao","id":3048612,"avatar_url":"https://avatars3.githubusercontent.com/u/3048612?v=3","gravatar_id":"","url":"https://api.github.com/users/jacquesqiao","html_url":"https://github.com/jacquesqiao","followers_url":"https://api.github.com/users/jacquesqiao/followers","following_url":"https://api.github.com/users/jacquesqiao/following{/other_user}","gists_url":"https://api.github.com/users/jacquesqiao/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquesqiao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquesqiao/subscriptions","organizations_url":"https://api.github.com/users/jacquesqiao/orgs","repos_url":"https://api.github.com/users/jacquesqiao/repos","events_url":"https://api.github.com/users/jacquesqiao/events{/privacy}","received_events_url":"https://api.github.com/users/jacquesqiao/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jacquesqiao/Paddle","description":"PArallel Distributed Deep LEarning","fork":true,"url":"https://api.github.com/repos/jacquesqiao/Paddle","forks_url":"https://api.github.com/repos/jacquesqiao/Paddle/forks","keys_url":"https://api.github.com/repos/jacquesqiao/Paddle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jacquesqiao/Paddle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jacquesqiao/Paddle/teams","hooks_url":"https://api.github.com/repos/jacquesqiao/Paddle/hooks","issue_events_url":"https://api.github.com/repos/jacquesqiao/Paddle/issues/events{/number}","events_url":"https://api.github.com/repos/jacquesqiao/Paddle/events","assignees_url":"https://api.github.com/repos/jacquesqiao/Paddle/assignees{/user}","branches_url":"https://api.github.com/repos/jacquesqiao/Paddle/branches{/branch}","tags_url":"https://api.github.com/repos/jacquesqiao/Paddle/tags","blobs_url":"https://api.github.com/repos/jacquesqiao/Paddle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jacquesqiao/Paddle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jacquesqiao/Paddle/git/refs{/sha}","trees_url":"https://api.github.com/repos/jacquesqiao/Paddle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jacquesqiao/Paddle/statuses/{sha}","languages_url":"https://api.github.com/repos/jacquesqiao/Paddle/languages","stargazers_url":"https://api.github.com/repos/jacquesqiao/Paddle/stargazers","contributors_url":"https://api.github.com/repos/jacquesqiao/Paddle/contributors","subscribers_url":"https://api.github.com/repos/jacquesqiao/Paddle/subscribers","subscription_url":"https://api.github.com/repos/jacquesqiao/Paddle/subscription","commits_url":"https://api.github.com/repos/jacquesqiao/Paddle/commits{/sha}","git_commits_url":"https://api.github.com/repos/jacquesqiao/Paddle/git/commits{/sha}","comments_url":"https://api.github.com/repos/jacquesqiao/Paddle/comments{/number}","issue_comment_url":"https://api.github.com/repos/jacquesqiao/Paddle/issues/comments{/number}","contents_url":"https://api.github.com/repos/jacquesqiao/Paddle/contents/{+path}","compare_url":"https://api.github.com/repos/jacquesqiao/Paddle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jacquesqiao/Paddle/merges","archive_url":"https://api.github.com/repos/jacquesqiao/Paddle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jacquesqiao/Paddle/downloads","issues_url":"https://api.github.com/repos/jacquesqiao/Paddle/issues{/number}","pulls_url":"https://api.github.com/repos/jacquesqiao/Paddle/pulls{/number}","milestones_url":"https://api.github.com/repos/jacquesqiao/Paddle/milestones{/number}","notifications_url":"https://api.github.com/repos/jacquesqiao/Paddle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jacquesqiao/Paddle/labels{/name}","releases_url":"https://api.github.com/repos/jacquesqiao/Paddle/releases{/id}","deployments_url":"https://api.github.com/repos/jacquesqiao/Paddle/deployments","created_at":"2016-11-30T03:13:08Z","updated_at":"2016-11-30T03:13:12Z","pushed_at":"2017-07-06T15:46:56Z","git_url":"git://github.com/jacquesqiao/Paddle.git","ssh_url":"git@github.com:jacquesqiao/Paddle.git","clone_url":"https://github.com/jacquesqiao/Paddle.git","svn_url":"https://github.com/jacquesqiao/Paddle","homepage":"http://www.paddlepaddle.org/","size":28080,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"PaddlePaddle:develop","ref":"develop","sha":"e4828b7eded5ae0f623aab241a77b29220f032c1","user":{"login":"PaddlePaddle","id":23534030,"avatar_url":"https://avatars0.githubusercontent.com/u/23534030?v=3","gravatar_id":"","url":"https://api.github.com/users/PaddlePaddle","html_url":"https://github.com/PaddlePaddle","followers_url":"https://api.github.com/users/PaddlePaddle/followers","following_url":"https://api.github.com/users/PaddlePaddle/following{/other_user}","gists_url":"https://api.github.com/users/PaddlePaddle/gists{/gist_id}","starred_url":"https://api.github.com/users/PaddlePaddle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PaddlePaddle/subscriptions","organizations_url":"https://api.github.com/users/PaddlePaddle/orgs","repos_url":"https://api.github.com/users/PaddlePaddle/repos","events_url":"https://api.github.com/users/PaddlePaddle/events{/privacy}","received_events_url":"https://api.github.com/users/PaddlePaddle/received_events","type":"Organization","site_admin":false},"repo":{"id":65711522,"name":"Paddle","full_name":"PaddlePaddle/Paddle","owner":{"login":"PaddlePaddle","id":23534030,"avatar_url":"https://avatars0.githubusercontent.com/u/23534030?v=3","gravatar_id":"","url":"https://api.github.com/users/PaddlePaddle","html_url":"https://github.com/PaddlePaddle","followers_url":"https://api.github.com/users/PaddlePaddle/followers","following_url":"https://api.github.com/users/PaddlePaddle/following{/other_user}","gists_url":"https://api.github.com/users/PaddlePaddle/gists{/gist_id}","starred_url":"https://api.github.com/users/PaddlePaddle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PaddlePaddle/subscriptions","organizations_url":"https://api.github.com/users/PaddlePaddle/orgs","repos_url":"https://api.github.com/users/PaddlePaddle/repos","events_url":"https://api.github.com/users/PaddlePaddle/events{/privacy}","received_events_url":"https://api.github.com/users/PaddlePaddle/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/PaddlePaddle/Paddle","description":"PArallel Distributed Deep LEarning","fork":false,"url":"https://api.github.com/repos/PaddlePaddle/Paddle","forks_url":"https://api.github.com/repos/PaddlePaddle/Paddle/forks","keys_url":"https://api.github.com/repos/PaddlePaddle/Paddle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PaddlePaddle/Paddle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PaddlePaddle/Paddle/teams","hooks_url":"https://api.github.com/repos/PaddlePaddle/Paddle/hooks","issue_events_url":"https://api.github.com/repos/PaddlePaddle/Paddle/issues/events{/number}","events_url":"https://api.github.com/repos/PaddlePaddle/Paddle/events","assignees_url":"https://api.github.com/repos/PaddlePaddle/Paddle/assignees{/user}","branches_url":"https://api.github.com/repos/PaddlePaddle/Paddle/branches{/branch}","tags_url":"https://api.github.com/repos/PaddlePaddle/Paddle/tags","blobs_url":"https://api.github.com/repos/PaddlePaddle/Paddle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PaddlePaddle/Paddle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PaddlePaddle/Paddle/git/refs{/sha}","trees_url":"https://api.github.com/repos/PaddlePaddle/Paddle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PaddlePaddle/Paddle/statuses/{sha}","languages_url":"https://api.github.com/repos/PaddlePaddle/Paddle/languages","stargazers_url":"https://api.github.com/repos/PaddlePaddle/Paddle/stargazers","contributors_url":"https://api.github.com/repos/PaddlePaddle/Paddle/contributors","subscribers_url":"https://api.github.com/repos/PaddlePaddle/Paddle/subscribers","subscription_url":"https://api.github.com/repos/PaddlePaddle/Paddle/subscription","commits_url":"https://api.github.com/repos/PaddlePaddle/Paddle/commits{/sha}","git_commits_url":"https://api.github.com/repos/PaddlePaddle/Paddle/git/commits{/sha}","comments_url":"https://api.github.com/repos/PaddlePaddle/Paddle/comments{/number}","issue_comment_url":"https://api.github.com/repos/PaddlePaddle/Paddle/issues/comments{/number}","contents_url":"https://api.github.com/repos/PaddlePaddle/Paddle/contents/{+path}","compare_url":"https://api.github.com/repos/PaddlePaddle/Paddle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PaddlePaddle/Paddle/merges","archive_url":"https://api.github.com/repos/PaddlePaddle/Paddle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PaddlePaddle/Paddle/downloads","issues_url":"https://api.github.com/repos/PaddlePaddle/Paddle/issues{/number}","pulls_url":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls{/number}","milestones_url":"https://api.github.com/repos/PaddlePaddle/Paddle/milestones{/number}","notifications_url":"https://api.github.com/repos/PaddlePaddle/Paddle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PaddlePaddle/Paddle/labels{/name}","releases_url":"https://api.github.com/repos/PaddlePaddle/Paddle/releases{/id}","deployments_url":"https://api.github.com/repos/PaddlePaddle/Paddle/deployments","created_at":"2016-08-15T06:59:08Z","updated_at":"2017-07-07T00:46:27Z","pushed_at":"2017-07-07T02:05:50Z","git_url":"git://github.com/PaddlePaddle/Paddle.git","ssh_url":"git@github.com:PaddlePaddle/Paddle.git","clone_url":"https://github.com/PaddlePaddle/Paddle.git","svn_url":"https://github.com/PaddlePaddle/Paddle","homepage":"http://www.paddlepaddle.org/","size":40728,"stargazers_count":5061,"watchers_count":5061,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1340,"mirror_url":null,"open_issues_count":586,"forks":1340,"open_issues":586,"watchers":5061,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls/2725"},"html":{"href":"https://github.com/PaddlePaddle/Paddle/pull/2725"},"issue":{"href":"https://api.github.com/repos/PaddlePaddle/Paddle/issues/2725"},"comments":{"href":"https://api.github.com/repos/PaddlePaddle/Paddle/issues/2725/comments"},"review_comments":{"href":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls/2725/comments"},"review_comment":{"href":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls/2725/commits"},"statuses":{"href":"https://api.github.com/repos/PaddlePaddle/Paddle/statuses/57d1fbd6bebc675eb842d4541d8b53d29f0f2731"}}}}
{"actor":{"display_login":"jacquesqiao"}}