{"action":"created","comment":{"url":"https://api.github.com/repos/Theano/Theano/pulls/comments/32168711","id":32168711,"diff_hunk":"@@ -0,0 +1,221 @@\n+import ctypes\n+import theano\n+from theano.sandbox.cuda import (CudaNdarrayType, as_cuda_ndarray_variable,\n+                                 GpuOp, cuda_ndarray, CudaNdarray)\n+from theano.tensor import reshape\n+try:\n+    from scikits.cuda.cusolver import (_libcusolver, cusolverDnCreate,\n+                                       cusolverCheckStatus)\n+    from scikits.cuda.cublas import _CUBLAS_SIDE_MODE, _CUBLAS_OP\n+    cusolver_available = True\n+except (ImportError, OSError):\n+    cusolver_available = False\n+    raise\n+\n+dimshuffle = cuda_ndarray.cuda_ndarray.dimshuffle\n+\n+\n+class CuSolverOp(GpuOp):\n+    \"\"\"cuSOLVER ops lazily raise an error when cuSOLVER is not available.\"\"\"\n+    def make_thunk(self, *args, **kwargs):\n+        if not cusolver_available:\n+            raise RuntimeError('cuSOLVER not available')\n+        return self._make_thunk(*args, **kwargs)\n+\n+\n+class GpuGeqrf(CuSolverOp):\n+    \"\"\"Wrapper of cuSOLVER's implementation of the geqrf LAPACK method.\n+\n+    Notes\n+    -----\n+    Wrapping of the methods is done as in `scikits.cuda.cusolver`. The\n+    interface is intendend to mimick `scipy.linalg.lapack`.\n+\n+    \"\"\"\n+    __props__ = ()\n+\n+    def output_type(self):\n+        return [CudaNdarrayType(broadcastable=[False, False])(),\n+                CudaNdarrayType(broadcastable=[False])(),\n+                CudaNdarrayType(broadcastable=[False])(),\n+                CudaNdarrayType(broadcastable=[])()]\n+\n+    def make_node(self, inp):\n+        inp = as_cuda_ndarray_variable(inp)\n+        assert inp.ndim == 2\n+\n+        return theano.Apply(self, [inp], self.output_type())\n+\n+    def _make_thunk(self, node, storage_map, _, no_recycling=[]):\n+        inputs = [storage_map[v] for v in node.inputs]\n+        outputs = [storage_map[v] for v in node.outputs]\n+\n+        def thunk():\n+            A = inputs[0][0]\n+            m, n = A.shape\n+            # LAPACK routines expect Fortran order\n+            A_T = dimshuffle(A, (1, 0)).reshape((m, n))\n+            A_copy = A_T.copy()\n+\n+            lda = max(1, m)\n+            TAU = CudaNdarray.zeros((min(m, n),))\n+            Lwork = cusolverDnSgeqrf_bufferSize(handle, m, n, A_copy.gpudata,\n+                                                lda)\n+            Work = CudaNdarray.zeros((max(1, Lwork),))","path":"theano/sandbox/cuda/cusolver.py","position":64,"original_position":64,"commit_id":"cc87b066060244dba26e679013bb2b65f1ff1682","original_commit_id":"a0f9969bd23bfa73c219d1bc29f688695896d179","user":{"login":"lamblin","id":178249,"avatar_url":"https://avatars.githubusercontent.com/u/178249?v=3","gravatar_id":"","url":"https://api.github.com/users/lamblin","html_url":"https://github.com/lamblin","followers_url":"https://api.github.com/users/lamblin/followers","following_url":"https://api.github.com/users/lamblin/following{/other_user}","gists_url":"https://api.github.com/users/lamblin/gists{/gist_id}","starred_url":"https://api.github.com/users/lamblin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lamblin/subscriptions","organizations_url":"https://api.github.com/users/lamblin/orgs","repos_url":"https://api.github.com/users/lamblin/repos","events_url":"https://api.github.com/users/lamblin/events{/privacy}","received_events_url":"https://api.github.com/users/lamblin/received_events","type":"User","site_admin":false},"body":"If these allocations become too inefficient, we could add these buffers as additional outputs. That way, if the garbage collector is disabled, the Op could try to re-use them.","created_at":"2015-06-10T21:29:00Z","updated_at":"2015-06-10T21:29:00Z","html_url":"https://github.com/Theano/Theano/pull/3013#discussion_r32168711","pull_request_url":"https://api.github.com/repos/Theano/Theano/pulls/3013","_links":{"self":{"href":"https://api.github.com/repos/Theano/Theano/pulls/comments/32168711"},"html":{"href":"https://github.com/Theano/Theano/pull/3013#discussion_r32168711"},"pull_request":{"href":"https://api.github.com/repos/Theano/Theano/pulls/3013"}}},"pull_request":{"url":"https://api.github.com/repos/Theano/Theano/pulls/3013","id":37324221,"html_url":"https://github.com/Theano/Theano/pull/3013","diff_url":"https://github.com/Theano/Theano/pull/3013.diff","patch_url":"https://github.com/Theano/Theano/pull/3013.patch","issue_url":"https://api.github.com/repos/Theano/Theano/issues/3013","number":3013,"state":"open","locked":false,"title":"Add cuSOLVER QR factorization routine (GEQRF)","user":{"login":"bartvm","id":2299595,"avatar_url":"https://avatars.githubusercontent.com/u/2299595?v=3","gravatar_id":"","url":"https://api.github.com/users/bartvm","html_url":"https://github.com/bartvm","followers_url":"https://api.github.com/users/bartvm/followers","following_url":"https://api.github.com/users/bartvm/following{/other_user}","gists_url":"https://api.github.com/users/bartvm/gists{/gist_id}","starred_url":"https://api.github.com/users/bartvm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bartvm/subscriptions","organizations_url":"https://api.github.com/users/bartvm/orgs","repos_url":"https://api.github.com/users/bartvm/repos","events_url":"https://api.github.com/users/bartvm/events{/privacy}","received_events_url":"https://api.github.com/users/bartvm/received_events","type":"User","site_admin":false},"body":"@lamblin @caglar My first Theano Op, so let me know if I'm doing it wrong\r\n\r\n- [x] Tests\r\n- [ ] Implement `linalg.qr` interface\r\n- [ ] Optimization for CPU -> GPU ops?\r\n\r\nThe next one I'll probably try to implement is `cusolverDnDormqr`.","created_at":"2015-06-10T04:55:53Z","updated_at":"2015-06-10T21:29:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"62297232b0fe3371aae9b6f8a36fd185e8c8bbc1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Theano/Theano/pulls/3013/commits","review_comments_url":"https://api.github.com/repos/Theano/Theano/pulls/3013/comments","review_comment_url":"https://api.github.com/repos/Theano/Theano/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Theano/Theano/issues/3013/comments","statuses_url":"https://api.github.com/repos/Theano/Theano/statuses/cc87b066060244dba26e679013bb2b65f1ff1682","head":{"label":"bartvm:geqrf","ref":"geqrf","sha":"cc87b066060244dba26e679013bb2b65f1ff1682","user":{"login":"bartvm","id":2299595,"avatar_url":"https://avatars.githubusercontent.com/u/2299595?v=3","gravatar_id":"","url":"https://api.github.com/users/bartvm","html_url":"https://github.com/bartvm","followers_url":"https://api.github.com/users/bartvm/followers","following_url":"https://api.github.com/users/bartvm/following{/other_user}","gists_url":"https://api.github.com/users/bartvm/gists{/gist_id}","starred_url":"https://api.github.com/users/bartvm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bartvm/subscriptions","organizations_url":"https://api.github.com/users/bartvm/orgs","repos_url":"https://api.github.com/users/bartvm/repos","events_url":"https://api.github.com/users/bartvm/events{/privacy}","received_events_url":"https://api.github.com/users/bartvm/received_events","type":"User","site_admin":false},"repo":{"id":17371685,"name":"Theano","full_name":"bartvm/Theano","owner":{"login":"bartvm","id":2299595,"avatar_url":"https://avatars.githubusercontent.com/u/2299595?v=3","gravatar_id":"","url":"https://api.github.com/users/bartvm","html_url":"https://github.com/bartvm","followers_url":"https://api.github.com/users/bartvm/followers","following_url":"https://api.github.com/users/bartvm/following{/other_user}","gists_url":"https://api.github.com/users/bartvm/gists{/gist_id}","starred_url":"https://api.github.com/users/bartvm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bartvm/subscriptions","organizations_url":"https://api.github.com/users/bartvm/orgs","repos_url":"https://api.github.com/users/bartvm/repos","events_url":"https://api.github.com/users/bartvm/events{/privacy}","received_events_url":"https://api.github.com/users/bartvm/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bartvm/Theano","description":"Optimizing GPU-meta-programming code generating array oriented optimizing math compiler in Python","fork":true,"url":"https://api.github.com/repos/bartvm/Theano","forks_url":"https://api.github.com/repos/bartvm/Theano/forks","keys_url":"https://api.github.com/repos/bartvm/Theano/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bartvm/Theano/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bartvm/Theano/teams","hooks_url":"https://api.github.com/repos/bartvm/Theano/hooks","issue_events_url":"https://api.github.com/repos/bartvm/Theano/issues/events{/number}","events_url":"https://api.github.com/repos/bartvm/Theano/events","assignees_url":"https://api.github.com/repos/bartvm/Theano/assignees{/user}","branches_url":"https://api.github.com/repos/bartvm/Theano/branches{/branch}","tags_url":"https://api.github.com/repos/bartvm/Theano/tags","blobs_url":"https://api.github.com/repos/bartvm/Theano/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bartvm/Theano/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bartvm/Theano/git/refs{/sha}","trees_url":"https://api.github.com/repos/bartvm/Theano/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bartvm/Theano/statuses/{sha}","languages_url":"https://api.github.com/repos/bartvm/Theano/languages","stargazers_url":"https://api.github.com/repos/bartvm/Theano/stargazers","contributors_url":"https://api.github.com/repos/bartvm/Theano/contributors","subscribers_url":"https://api.github.com/repos/bartvm/Theano/subscribers","subscription_url":"https://api.github.com/repos/bartvm/Theano/subscription","commits_url":"https://api.github.com/repos/bartvm/Theano/commits{/sha}","git_commits_url":"https://api.github.com/repos/bartvm/Theano/git/commits{/sha}","comments_url":"https://api.github.com/repos/bartvm/Theano/comments{/number}","issue_comment_url":"https://api.github.com/repos/bartvm/Theano/issues/comments{/number}","contents_url":"https://api.github.com/repos/bartvm/Theano/contents/{+path}","compare_url":"https://api.github.com/repos/bartvm/Theano/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bartvm/Theano/merges","archive_url":"https://api.github.com/repos/bartvm/Theano/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bartvm/Theano/downloads","issues_url":"https://api.github.com/repos/bartvm/Theano/issues{/number}","pulls_url":"https://api.github.com/repos/bartvm/Theano/pulls{/number}","milestones_url":"https://api.github.com/repos/bartvm/Theano/milestones{/number}","notifications_url":"https://api.github.com/repos/bartvm/Theano/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bartvm/Theano/labels{/name}","releases_url":"https://api.github.com/repos/bartvm/Theano/releases{/id}","created_at":"2014-03-03T16:16:41Z","updated_at":"2015-04-22T20:20:09Z","pushed_at":"2015-06-10T21:24:49Z","git_url":"git://github.com/bartvm/Theano.git","ssh_url":"git@github.com:bartvm/Theano.git","clone_url":"https://github.com/bartvm/Theano.git","svn_url":"https://github.com/bartvm/Theano","homepage":"http://www.deeplearning.net/software/theano","size":33206,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"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":"master"}},"base":{"label":"Theano:master","ref":"master","sha":"e526d59c9c678987f3e21465c71245af05438f85","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-06-10T21:07:40Z","pushed_at":"2015-06-10T21:24:49Z","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":52633,"stargazers_count":1605,"watchers_count":1605,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":587,"mirror_url":null,"open_issues_count":401,"forks":587,"open_issues":401,"watchers":1605,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Theano/Theano/pulls/3013"},"html":{"href":"https://github.com/Theano/Theano/pull/3013"},"issue":{"href":"https://api.github.com/repos/Theano/Theano/issues/3013"},"comments":{"href":"https://api.github.com/repos/Theano/Theano/issues/3013/comments"},"review_comments":{"href":"https://api.github.com/repos/Theano/Theano/pulls/3013/comments"},"review_comment":{"href":"https://api.github.com/repos/Theano/Theano/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Theano/Theano/pulls/3013/commits"},"statuses":{"href":"https://api.github.com/repos/Theano/Theano/statuses/cc87b066060244dba26e679013bb2b65f1ff1682"}}}}