{"action":"created","comment":{"url":"https://api.github.com/repos/Theano/Theano/pulls/comments/35502448","id":35502448,"diff_hunk":"@@ -2313,3 +2313,73 @@ def local_gpu_allocempty(node):\n                'scan')\n \n import theano.sandbox.cuda.extra_ops\n+import theano.compile.builders\n+\n+\n+@register_opt()\n+@local_optimizer([theano.compile.builders.OpFromGraph])\n+def local_gpu_op_from_graph(node):\n+    if (isinstance(node.op, theano.compile.builders.OpFromGraph) and\n+        any([(i.owner and isinstance(i.owner.op, HostFromGpu))\n+             for i in node.inputs]) and\n+        # If the output is on the GPU, we already moved it to the GPU.\n+        not any([isinstance(o.type, CudaNdarrayType) for o in node.outputs])):\n+            # Need to implement updates, givens, ...\n+            if node.op.kwargs:\n+                for k in node.op.kwargs.keys():\n+                    if k not in ['mode']:\n+                        return\n+            # We make it simple, we suppose all float32 inputs will be\n+            # on the GPU and that all outputs in float32 will be on\n+            # the GPU.\n+            # We do not want to add the shared inputs. They will be computed again.\n+            new_outer_inp = []  # new outer inputs.\n+            inner_replace = {}\n+            for o_inp, i_inp in zip(node.inputs, node.op.inputs):\n+                if getattr(o_inp, 'dtype', None) == 'float32':\n+                    new_outer_inp.append(as_cuda_ndarray_variable(o_inp))\n+                    inner_replace[i_inp] = tensor.as_tensor_variable(\n+                        CudaNdarrayType(dtype=i_inp.dtype,\n+                                        broadcastable=i_inp.broadcastable)())\n+                else:\n+                    new_outer_inp.append(inp)\n+            new_inner_out = []\n+            for out in node.op.outputs:\n+                if getattr(out, 'dtype', None) == 'float32':\n+                    new = as_cuda_ndarray_variable(out)\n+                    new_inner_out.append(new)\n+                else:\n+                    new_inner_out.append(out)\n+\n+            # SharedVariable was cloned when the FunctionGraph was\n+            # created.  node.op.inputs still make reference to the\n+            # original SharedVariable.  We must swap it to the one\n+            # used in this fgraph\n+            for i in range(len(node.op.shared_inputs)):\n+                # SharedVariable the user used\n+                orig_shr = node.op.shared_inputs[i]\n+                # SharedVariable after cloning orig_shr when\n+                # FunctionGraph cloned the user graph.\n+                fgraph_shr = node.inputs[len(node.op.inputs) + i]\n+                inner_replace[orig_shr] = fgraph_shr\n+            # rebuild the inner graph to introduce the gup_from_host\n+            # at the start.\n+            new = theano.compile.rebuild_collect_shared(\n+                new_inner_out, inputs=node.op.inputs,\n+                replace=inner_replace,\n+                copy_inputs_over=True)\n+            (new_inputs, new_outputs, _) = new\n+            # new_inputs give us the corresponding to the old inputs.\n+            for i in range(len(new_inputs)):\n+                if (new_inputs[i].owner and\n+                        isinstance(new_inputs[i].owner.op, HostFromGpu)):\n+                    new_inputs[i] = new_inputs[i].owner.inputs[0]\n+            op = theano.compile.builders.OpFromGraph(\n+                new_inputs, new_outputs, **node.op.kwargs)\n+            ret = op(*new_outer_inp, **dict(return_list=True))\n+            assert all([inp in node.fgraph.variables for inp in theano.gof.graph.inputs(ret)])\n+\n+            for i in range(len(ret)):\n+                if getattr(node.op.outputs[i], 'dtype', None) == 'float32':\n+                    ret[i] = theano.tensor.as_tensor_variable(ret[i])\n+            return ret","path":"theano/sandbox/cuda/opt.py","position":91,"original_position":91,"commit_id":"c9471c20c324e6c9ac39e7fcd88b8a25841b18b7","original_commit_id":"c9471c20c324e6c9ac39e7fcd88b8a25841b18b7","user":{"login":"nouiz","id":180987,"avatar_url":"https://avatars.githubusercontent.com/u/180987?v=3","gravatar_id":"","url":"https://api.github.com/users/nouiz","html_url":"https://github.com/nouiz","followers_url":"https://api.github.com/users/nouiz/followers","following_url":"https://api.github.com/users/nouiz/following{/other_user}","gists_url":"https://api.github.com/users/nouiz/gists{/gist_id}","starred_url":"https://api.github.com/users/nouiz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nouiz/subscriptions","organizations_url":"https://api.github.com/users/nouiz/orgs","repos_url":"https://api.github.com/users/nouiz/repos","events_url":"https://api.github.com/users/nouiz/events{/privacy}","received_events_url":"https://api.github.com/users/nouiz/received_events","type":"User","site_admin":false},"body":"givens can add extra inputs. But I don't see any code to handle that correctly in OpFromGraph. I just check OpFromGraph init and updates aren't allowed. Can you go in OpFromGraph.__init__ and raise an error for givens to tell not implemented? This isn't a needed feature for OpFromGraph, so no trouble to not implement it for now.","created_at":"2015-07-27T02:32:02Z","updated_at":"2015-07-27T02:32:02Z","html_url":"https://github.com/Theano/Theano/pull/2982#discussion_r35502448","pull_request_url":"https://api.github.com/repos/Theano/Theano/pulls/2982","_links":{"self":{"href":"https://api.github.com/repos/Theano/Theano/pulls/comments/35502448"},"html":{"href":"https://github.com/Theano/Theano/pull/2982#discussion_r35502448"},"pull_request":{"href":"https://api.github.com/repos/Theano/Theano/pulls/2982"}}},"pull_request":{"url":"https://api.github.com/repos/Theano/Theano/pulls/2982","id":36539654,"html_url":"https://github.com/Theano/Theano/pull/2982","diff_url":"https://github.com/Theano/Theano/pull/2982.diff","patch_url":"https://github.com/Theano/Theano/pull/2982.patch","issue_url":"https://api.github.com/repos/Theano/Theano/issues/2982","number":2982,"state":"open","locked":false,"title":"[WIP] First partial working version of OpFromGraph op to GPU","user":{"login":"nouiz","id":180987,"avatar_url":"https://avatars.githubusercontent.com/u/180987?v=3","gravatar_id":"","url":"https://api.github.com/users/nouiz","html_url":"https://github.com/nouiz","followers_url":"https://api.github.com/users/nouiz/followers","following_url":"https://api.github.com/users/nouiz/following{/other_user}","gists_url":"https://api.github.com/users/nouiz/gists{/gist_id}","starred_url":"https://api.github.com/users/nouiz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nouiz/subscriptions","organizations_url":"https://api.github.com/users/nouiz/orgs","repos_url":"https://api.github.com/users/nouiz/repos","events_url":"https://api.github.com/users/nouiz/events{/privacy}","received_events_url":"https://api.github.com/users/nouiz/received_events","type":"User","site_admin":false},"body":"ref: https://github.com/Theano/Theano/issues/1603\r\nTODO:\r\n- [ ] Fix `__eq__` and `__hash__` as this make the new tests fail in DebugMode","created_at":"2015-05-29T19:58:36Z","updated_at":"2015-07-27T02:32:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"23ca5953dc122d796cc391fd3735e1380d0b02d1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Theano/Theano/pulls/2982/commits","review_comments_url":"https://api.github.com/repos/Theano/Theano/pulls/2982/comments","review_comment_url":"https://api.github.com/repos/Theano/Theano/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Theano/Theano/issues/2982/comments","statuses_url":"https://api.github.com/repos/Theano/Theano/statuses/c9471c20c324e6c9ac39e7fcd88b8a25841b18b7","head":{"label":"nouiz:gpu_op_from_graph","ref":"gpu_op_from_graph","sha":"c9471c20c324e6c9ac39e7fcd88b8a25841b18b7","user":{"login":"nouiz","id":180987,"avatar_url":"https://avatars.githubusercontent.com/u/180987?v=3","gravatar_id":"","url":"https://api.github.com/users/nouiz","html_url":"https://github.com/nouiz","followers_url":"https://api.github.com/users/nouiz/followers","following_url":"https://api.github.com/users/nouiz/following{/other_user}","gists_url":"https://api.github.com/users/nouiz/gists{/gist_id}","starred_url":"https://api.github.com/users/nouiz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nouiz/subscriptions","organizations_url":"https://api.github.com/users/nouiz/orgs","repos_url":"https://api.github.com/users/nouiz/repos","events_url":"https://api.github.com/users/nouiz/events{/privacy}","received_events_url":"https://api.github.com/users/nouiz/received_events","type":"User","site_admin":false},"repo":{"id":2255296,"name":"Theano","full_name":"nouiz/Theano","owner":{"login":"nouiz","id":180987,"avatar_url":"https://avatars.githubusercontent.com/u/180987?v=3","gravatar_id":"","url":"https://api.github.com/users/nouiz","html_url":"https://github.com/nouiz","followers_url":"https://api.github.com/users/nouiz/followers","following_url":"https://api.github.com/users/nouiz/following{/other_user}","gists_url":"https://api.github.com/users/nouiz/gists{/gist_id}","starred_url":"https://api.github.com/users/nouiz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nouiz/subscriptions","organizations_url":"https://api.github.com/users/nouiz/orgs","repos_url":"https://api.github.com/users/nouiz/repos","events_url":"https://api.github.com/users/nouiz/events{/privacy}","received_events_url":"https://api.github.com/users/nouiz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nouiz/Theano","description":"Theano is a Python library that allows you to define, optimize, and evaluate mathematical expressions involving multi-dimensional arrays efficiently. It can use GPUs and perform efficient symbolic differentiation. ","fork":true,"url":"https://api.github.com/repos/nouiz/Theano","forks_url":"https://api.github.com/repos/nouiz/Theano/forks","keys_url":"https://api.github.com/repos/nouiz/Theano/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nouiz/Theano/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nouiz/Theano/teams","hooks_url":"https://api.github.com/repos/nouiz/Theano/hooks","issue_events_url":"https://api.github.com/repos/nouiz/Theano/issues/events{/number}","events_url":"https://api.github.com/repos/nouiz/Theano/events","assignees_url":"https://api.github.com/repos/nouiz/Theano/assignees{/user}","branches_url":"https://api.github.com/repos/nouiz/Theano/branches{/branch}","tags_url":"https://api.github.com/repos/nouiz/Theano/tags","blobs_url":"https://api.github.com/repos/nouiz/Theano/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nouiz/Theano/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nouiz/Theano/git/refs{/sha}","trees_url":"https://api.github.com/repos/nouiz/Theano/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nouiz/Theano/statuses/{sha}","languages_url":"https://api.github.com/repos/nouiz/Theano/languages","stargazers_url":"https://api.github.com/repos/nouiz/Theano/stargazers","contributors_url":"https://api.github.com/repos/nouiz/Theano/contributors","subscribers_url":"https://api.github.com/repos/nouiz/Theano/subscribers","subscription_url":"https://api.github.com/repos/nouiz/Theano/subscription","commits_url":"https://api.github.com/repos/nouiz/Theano/commits{/sha}","git_commits_url":"https://api.github.com/repos/nouiz/Theano/git/commits{/sha}","comments_url":"https://api.github.com/repos/nouiz/Theano/comments{/number}","issue_comment_url":"https://api.github.com/repos/nouiz/Theano/issues/comments{/number}","contents_url":"https://api.github.com/repos/nouiz/Theano/contents/{+path}","compare_url":"https://api.github.com/repos/nouiz/Theano/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nouiz/Theano/merges","archive_url":"https://api.github.com/repos/nouiz/Theano/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nouiz/Theano/downloads","issues_url":"https://api.github.com/repos/nouiz/Theano/issues{/number}","pulls_url":"https://api.github.com/repos/nouiz/Theano/pulls{/number}","milestones_url":"https://api.github.com/repos/nouiz/Theano/milestones{/number}","notifications_url":"https://api.github.com/repos/nouiz/Theano/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nouiz/Theano/labels{/name}","releases_url":"https://api.github.com/repos/nouiz/Theano/releases{/id}","created_at":"2011-08-23T13:23:37Z","updated_at":"2015-05-09T01:09:56Z","pushed_at":"2015-07-27T02:18:30Z","git_url":"git://github.com/nouiz/Theano.git","ssh_url":"git@github.com:nouiz/Theano.git","clone_url":"https://github.com/nouiz/Theano.git","svn_url":"https://github.com/nouiz/Theano","homepage":"http://www.deeplearning.net/software/theano","size":41723,"stargazers_count":3,"watchers_count":3,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":0,"forks":4,"open_issues":0,"watchers":3,"default_branch":"master"}},"base":{"label":"Theano:master","ref":"master","sha":"31450d80d5f9c9863f2a92e0ab93076df8454a5d","user":{"login":"Theano","id":970517,"avatar_url":"https://avatars.githubusercontent.com/u/970517?v=3","gravatar_id":"","url":"https://api.github.com/users/Theano","html_url":"https://github.com/Theano","followers_url":"https://api.github.com/users/Theano/followers","following_url":"https://api.github.com/users/Theano/following{/other_user}","gists_url":"https://api.github.com/users/Theano/gists{/gist_id}","starred_url":"https://api.github.com/users/Theano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Theano/subscriptions","organizations_url":"https://api.github.com/users/Theano/orgs","repos_url":"https://api.github.com/users/Theano/repos","events_url":"https://api.github.com/users/Theano/events{/privacy}","received_events_url":"https://api.github.com/users/Theano/received_events","type":"Organization","site_admin":false},"repo":{"id":2183193,"name":"Theano","full_name":"Theano/Theano","owner":{"login":"Theano","id":970517,"avatar_url":"https://avatars.githubusercontent.com/u/970517?v=3","gravatar_id":"","url":"https://api.github.com/users/Theano","html_url":"https://github.com/Theano","followers_url":"https://api.github.com/users/Theano/followers","following_url":"https://api.github.com/users/Theano/following{/other_user}","gists_url":"https://api.github.com/users/Theano/gists{/gist_id}","starred_url":"https://api.github.com/users/Theano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Theano/subscriptions","organizations_url":"https://api.github.com/users/Theano/orgs","repos_url":"https://api.github.com/users/Theano/repos","events_url":"https://api.github.com/users/Theano/events{/privacy}","received_events_url":"https://api.github.com/users/Theano/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Theano/Theano","description":"Theano is a Python library that allows you to define, optimize, and evaluate mathematical expressions involving multi-dimensional arrays efficiently. It can use GPUs and perform efficient symbolic differentiation.","fork":false,"url":"https://api.github.com/repos/Theano/Theano","forks_url":"https://api.github.com/repos/Theano/Theano/forks","keys_url":"https://api.github.com/repos/Theano/Theano/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Theano/Theano/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Theano/Theano/teams","hooks_url":"https://api.github.com/repos/Theano/Theano/hooks","issue_events_url":"https://api.github.com/repos/Theano/Theano/issues/events{/number}","events_url":"https://api.github.com/repos/Theano/Theano/events","assignees_url":"https://api.github.com/repos/Theano/Theano/assignees{/user}","branches_url":"https://api.github.com/repos/Theano/Theano/branches{/branch}","tags_url":"https://api.github.com/repos/Theano/Theano/tags","blobs_url":"https://api.github.com/repos/Theano/Theano/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Theano/Theano/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Theano/Theano/git/refs{/sha}","trees_url":"https://api.github.com/repos/Theano/Theano/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Theano/Theano/statuses/{sha}","languages_url":"https://api.github.com/repos/Theano/Theano/languages","stargazers_url":"https://api.github.com/repos/Theano/Theano/stargazers","contributors_url":"https://api.github.com/repos/Theano/Theano/contributors","subscribers_url":"https://api.github.com/repos/Theano/Theano/subscribers","subscription_url":"https://api.github.com/repos/Theano/Theano/subscription","commits_url":"https://api.github.com/repos/Theano/Theano/commits{/sha}","git_commits_url":"https://api.github.com/repos/Theano/Theano/git/commits{/sha}","comments_url":"https://api.github.com/repos/Theano/Theano/comments{/number}","issue_comment_url":"https://api.github.com/repos/Theano/Theano/issues/comments{/number}","contents_url":"https://api.github.com/repos/Theano/Theano/contents/{+path}","compare_url":"https://api.github.com/repos/Theano/Theano/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Theano/Theano/merges","archive_url":"https://api.github.com/repos/Theano/Theano/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Theano/Theano/downloads","issues_url":"https://api.github.com/repos/Theano/Theano/issues{/number}","pulls_url":"https://api.github.com/repos/Theano/Theano/pulls{/number}","milestones_url":"https://api.github.com/repos/Theano/Theano/milestones{/number}","notifications_url":"https://api.github.com/repos/Theano/Theano/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Theano/Theano/labels{/name}","releases_url":"https://api.github.com/repos/Theano/Theano/releases{/id}","created_at":"2011-08-10T03:48:06Z","updated_at":"2015-07-27T01:46:18Z","pushed_at":"2015-07-27T02:18:30Z","git_url":"git://github.com/Theano/Theano.git","ssh_url":"git@github.com:Theano/Theano.git","clone_url":"https://github.com/Theano/Theano.git","svn_url":"https://github.com/Theano/Theano","homepage":"http://www.deeplearning.net/software/theano","size":57548,"stargazers_count":1755,"watchers_count":1755,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":639,"mirror_url":null,"open_issues_count":420,"forks":639,"open_issues":420,"watchers":1755,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Theano/Theano/pulls/2982"},"html":{"href":"https://github.com/Theano/Theano/pull/2982"},"issue":{"href":"https://api.github.com/repos/Theano/Theano/issues/2982"},"comments":{"href":"https://api.github.com/repos/Theano/Theano/issues/2982/comments"},"review_comments":{"href":"https://api.github.com/repos/Theano/Theano/pulls/2982/comments"},"review_comment":{"href":"https://api.github.com/repos/Theano/Theano/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Theano/Theano/pulls/2982/commits"},"statuses":{"href":"https://api.github.com/repos/Theano/Theano/statuses/c9471c20c324e6c9ac39e7fcd88b8a25841b18b7"}}}}