{"action":"created","comment":{"url":"https://api.github.com/repos/Theano/Theano/pulls/comments/66841056","id":66841056,"diff_hunk":"@@ -0,0 +1,368 @@\n+from __future__ import absolute_import, print_function, division\n+\n+import numpy as np\n+import theano\n+from theano import Op\n+import theano.tensor as T\n+from theano.gradient import DisconnectedType\n+\n+from theano.gpuarray import (basic_ops, GpuArrayType)\n+\n+try:\n+    import pygpu\n+    pygpu_available = True\n+except ImportError:\n+    pygpu_available = False\n+\n+try:\n+    import pycuda.driver\n+    pycuda_available = True\n+except ImportError:\n+    pycuda_available = False\n+\n+try:\n+    import scikits.cuda\n+    from scikits.cuda import fft\n+    scikits_cuda_available = True\n+except (ImportError, Exception):\n+    scikits_cuda_available = False\n+\n+\n+class CuRFFTOp(Op):\n+\n+    __props__ = ()\n+\n+    def output_type(self, inp):\n+        # add one extra dim for real/imag\n+        return GpuArrayType(inp.dtype,\n+                            broadcastable=[False] * (inp.type.ndim + 1),\n+                            context_name=inp.type.context_name)\n+\n+    def make_node(self, inp, s=None):\n+        # A shape parameter s can be provided as an input. For now this is used to\n+        # manage odd transform sizes.\n+        # Later this could be extended to handle padding and trunkation,\n+        # following numpy's interface. However, cuFFT expects array that match\n+        # the shape given to the plan, so padding will have to be done in the op.\n+        # The effect of padding on gradients has yet to be investigated.\n+\n+        if not scikits_cuda_available:\n+            raise RuntimeError(\"scikits.cuda is needed for CuFFTOp\")\n+\n+        if not pygpu_available:\n+            raise RuntimeError(\"pygpu is needed for CuFFTOp\")\n+\n+        if not pycuda_available:\n+            raise RuntimeError(\"pycuda is needed for CuFFTOp\")\n+\n+        inp = basic_ops.gpu_contiguous(\n+            basic_ops.as_gpuarray_variable(inp,\n+                                           basic_ops.infer_context_name(inp)))\n+\n+        # If no shape is provided as input, default to input data shape.\n+        if s is None:\n+            s = inp.shape[1:]\n+        s = T.as_tensor_variable(s)\n+\n+        assert inp.dtype == \"float32\"\n+        assert s.ndim == 1\n+        assert 'int' in s.dtype\n+\n+        return theano.Apply(self, [inp, s], [self.output_type(inp)()])\n+\n+    def make_thunk(self, node, storage_map, _, _2):\n+\n+        inputs = [storage_map[v] for v in node.inputs]\n+        outputs = [storage_map[v] for v in node.outputs]\n+\n+        # Initiliaze cuda context to the input's.\n+        with node.inputs[0].type.context:\n+            scikits.cuda.misc.init()\n+\n+        plan_input_shape = [None]\n+        plan = [None]\n+\n+        def thunk():\n+            input_shape = inputs[0][0].shape\n+            s = inputs[1][0]\n+\n+            # Since padding is not supported, assert s matches input shape.\n+            assert (input_shape[1:] == s).all()\n+\n+            # construct output shape\n+            output_shape = [input_shape[0]] + list(s)\n+            # DFT of real input is symmetric, no need to store\n+            # redundant coefficients\n+            output_shape[-1] = output_shape[-1] // 2 + 1\n+            # extra dimension with length 2 for real/imag\n+            output_shape += [2]\n+            output_shape = tuple(output_shape)\n+\n+            z = outputs[0]\n+\n+            # only allocate if there is no previous allocation of the\n+            # right size.\n+            if z[0] is None or z[0].shape != output_shape:\n+                z[0] = pygpu.zeros(output_shape, context=inputs[0][0].context,\n+                                   dtype='float32')\n+\n+            input_pycuda = inputs[0][0]\n+            # I thought we'd need to change the type on output_pycuda\n+            # so it is complex64, but as it turns out scikits.cuda.fft\n+            # doesn't really care either way and treats the array as\n+            # if it is complex64 anyway.\n+            output_pycuda = z[0]\n+\n+            with input_pycuda.context:\n+                # only initialise plan if necessary\n+                if plan[0] is None or plan_input_shape[0] != input_shape:\n+                    plan_input_shape[0] = input_shape\n+                    plan[0] = fft.Plan(s, np.float32, np.complex64,\n+                                       batch=input_shape[0])\n+\n+                # Sync GPU variables before computation\n+                input_pycuda.sync()\n+                output_pycuda.sync()\n+\n+                fft.fft(input_pycuda, output_pycuda, plan[0])\n+\n+                # Sync results to ensure output contains completed computation\n+                pycuda.driver.Context.synchronize()","path":"theano/gpuarray/fft.py","position":133,"original_position":130,"commit_id":"5f0572d8796f4df21b247c5b630b34a3276dc4a1","original_commit_id":"129c21c668cd177dc7a17a736fd5ec00ea18f6fa","user":{"login":"abergeron","id":1002504,"avatar_url":"https://avatars.githubusercontent.com/u/1002504?v=3","gravatar_id":"","url":"https://api.github.com/users/abergeron","html_url":"https://github.com/abergeron","followers_url":"https://api.github.com/users/abergeron/followers","following_url":"https://api.github.com/users/abergeron/following{/other_user}","gists_url":"https://api.github.com/users/abergeron/gists{/gist_id}","starred_url":"https://api.github.com/users/abergeron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abergeron/subscriptions","organizations_url":"https://api.github.com/users/abergeron/orgs","repos_url":"https://api.github.com/users/abergeron/repos","events_url":"https://api.github.com/users/abergeron/events{/privacy}","received_events_url":"https://api.github.com/users/abergeron/received_events","type":"User","site_admin":false},"body":"This might not be required anymore, now that no stream in libgpuarray is async with regards to the null stream.","created_at":"2016-06-13T18:18:33Z","updated_at":"2016-06-13T18:18:33Z","html_url":"https://github.com/Theano/Theano/pull/4535#discussion_r66841056","pull_request_url":"https://api.github.com/repos/Theano/Theano/pulls/4535","_links":{"self":{"href":"https://api.github.com/repos/Theano/Theano/pulls/comments/66841056"},"html":{"href":"https://github.com/Theano/Theano/pull/4535#discussion_r66841056"},"pull_request":{"href":"https://api.github.com/repos/Theano/Theano/pulls/4535"}}},"pull_request":{"url":"https://api.github.com/repos/Theano/Theano/pulls/4535","id":70581680,"html_url":"https://github.com/Theano/Theano/pull/4535","diff_url":"https://github.com/Theano/Theano/pull/4535.diff","patch_url":"https://github.com/Theano/Theano/pull/4535.patch","issue_url":"https://api.github.com/repos/Theano/Theano/issues/4535","number":4535,"state":"open","locked":false,"title":"Port FFTs to gpuarray backend","user":{"login":"slefrancois","id":18192425,"avatar_url":"https://avatars.githubusercontent.com/u/18192425?v=3","gravatar_id":"","url":"https://api.github.com/users/slefrancois","html_url":"https://github.com/slefrancois","followers_url":"https://api.github.com/users/slefrancois/followers","following_url":"https://api.github.com/users/slefrancois/following{/other_user}","gists_url":"https://api.github.com/users/slefrancois/gists{/gist_id}","starred_url":"https://api.github.com/users/slefrancois/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/slefrancois/subscriptions","organizations_url":"https://api.github.com/users/slefrancois/orgs","repos_url":"https://api.github.com/users/slefrancois/repos","events_url":"https://api.github.com/users/slefrancois/events{/privacy}","received_events_url":"https://api.github.com/users/slefrancois/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-05-18T19:03:18Z","updated_at":"2016-06-13T18:18:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b003e710af153f1a270201d3350bb77a712cc5dc","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Theano/Theano/pulls/4535/commits","review_comments_url":"https://api.github.com/repos/Theano/Theano/pulls/4535/comments","review_comment_url":"https://api.github.com/repos/Theano/Theano/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Theano/Theano/issues/4535/comments","statuses_url":"https://api.github.com/repos/Theano/Theano/statuses/5f0572d8796f4df21b247c5b630b34a3276dc4a1","head":{"label":"slefrancois:fft_gpuarray","ref":"fft_gpuarray","sha":"5f0572d8796f4df21b247c5b630b34a3276dc4a1","user":{"login":"slefrancois","id":18192425,"avatar_url":"https://avatars.githubusercontent.com/u/18192425?v=3","gravatar_id":"","url":"https://api.github.com/users/slefrancois","html_url":"https://github.com/slefrancois","followers_url":"https://api.github.com/users/slefrancois/followers","following_url":"https://api.github.com/users/slefrancois/following{/other_user}","gists_url":"https://api.github.com/users/slefrancois/gists{/gist_id}","starred_url":"https://api.github.com/users/slefrancois/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/slefrancois/subscriptions","organizations_url":"https://api.github.com/users/slefrancois/orgs","repos_url":"https://api.github.com/users/slefrancois/repos","events_url":"https://api.github.com/users/slefrancois/events{/privacy}","received_events_url":"https://api.github.com/users/slefrancois/received_events","type":"User","site_admin":false},"repo":{"id":55606547,"name":"Theano","full_name":"slefrancois/Theano","owner":{"login":"slefrancois","id":18192425,"avatar_url":"https://avatars.githubusercontent.com/u/18192425?v=3","gravatar_id":"","url":"https://api.github.com/users/slefrancois","html_url":"https://github.com/slefrancois","followers_url":"https://api.github.com/users/slefrancois/followers","following_url":"https://api.github.com/users/slefrancois/following{/other_user}","gists_url":"https://api.github.com/users/slefrancois/gists{/gist_id}","starred_url":"https://api.github.com/users/slefrancois/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/slefrancois/subscriptions","organizations_url":"https://api.github.com/users/slefrancois/orgs","repos_url":"https://api.github.com/users/slefrancois/repos","events_url":"https://api.github.com/users/slefrancois/events{/privacy}","received_events_url":"https://api.github.com/users/slefrancois/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/slefrancois/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/slefrancois/Theano","forks_url":"https://api.github.com/repos/slefrancois/Theano/forks","keys_url":"https://api.github.com/repos/slefrancois/Theano/keys{/key_id}","collaborators_url":"https://api.github.com/repos/slefrancois/Theano/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/slefrancois/Theano/teams","hooks_url":"https://api.github.com/repos/slefrancois/Theano/hooks","issue_events_url":"https://api.github.com/repos/slefrancois/Theano/issues/events{/number}","events_url":"https://api.github.com/repos/slefrancois/Theano/events","assignees_url":"https://api.github.com/repos/slefrancois/Theano/assignees{/user}","branches_url":"https://api.github.com/repos/slefrancois/Theano/branches{/branch}","tags_url":"https://api.github.com/repos/slefrancois/Theano/tags","blobs_url":"https://api.github.com/repos/slefrancois/Theano/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/slefrancois/Theano/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/slefrancois/Theano/git/refs{/sha}","trees_url":"https://api.github.com/repos/slefrancois/Theano/git/trees{/sha}","statuses_url":"https://api.github.com/repos/slefrancois/Theano/statuses/{sha}","languages_url":"https://api.github.com/repos/slefrancois/Theano/languages","stargazers_url":"https://api.github.com/repos/slefrancois/Theano/stargazers","contributors_url":"https://api.github.com/repos/slefrancois/Theano/contributors","subscribers_url":"https://api.github.com/repos/slefrancois/Theano/subscribers","subscription_url":"https://api.github.com/repos/slefrancois/Theano/subscription","commits_url":"https://api.github.com/repos/slefrancois/Theano/commits{/sha}","git_commits_url":"https://api.github.com/repos/slefrancois/Theano/git/commits{/sha}","comments_url":"https://api.github.com/repos/slefrancois/Theano/comments{/number}","issue_comment_url":"https://api.github.com/repos/slefrancois/Theano/issues/comments{/number}","contents_url":"https://api.github.com/repos/slefrancois/Theano/contents/{+path}","compare_url":"https://api.github.com/repos/slefrancois/Theano/compare/{base}...{head}","merges_url":"https://api.github.com/repos/slefrancois/Theano/merges","archive_url":"https://api.github.com/repos/slefrancois/Theano/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/slefrancois/Theano/downloads","issues_url":"https://api.github.com/repos/slefrancois/Theano/issues{/number}","pulls_url":"https://api.github.com/repos/slefrancois/Theano/pulls{/number}","milestones_url":"https://api.github.com/repos/slefrancois/Theano/milestones{/number}","notifications_url":"https://api.github.com/repos/slefrancois/Theano/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/slefrancois/Theano/labels{/name}","releases_url":"https://api.github.com/repos/slefrancois/Theano/releases{/id}","deployments_url":"https://api.github.com/repos/slefrancois/Theano/deployments","created_at":"2016-04-06T13:06:44Z","updated_at":"2016-04-06T13:06:47Z","pushed_at":"2016-06-13T18:01:42Z","git_url":"git://github.com/slefrancois/Theano.git","ssh_url":"git@github.com:slefrancois/Theano.git","clone_url":"https://github.com/slefrancois/Theano.git","svn_url":"https://github.com/slefrancois/Theano","homepage":"http://www.deeplearning.net/software/theano","size":53408,"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":"ba4aefff59ed8bd8923fe14ad684d1bd1036871c","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}","deployments_url":"https://api.github.com/repos/Theano/Theano/deployments","created_at":"2011-08-10T03:48:06Z","updated_at":"2016-06-13T17:32:05Z","pushed_at":"2016-06-13T18:01:42Z","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":74446,"stargazers_count":3927,"watchers_count":3927,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1425,"mirror_url":null,"open_issues_count":680,"forks":1425,"open_issues":680,"watchers":3927,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Theano/Theano/pulls/4535"},"html":{"href":"https://github.com/Theano/Theano/pull/4535"},"issue":{"href":"https://api.github.com/repos/Theano/Theano/issues/4535"},"comments":{"href":"https://api.github.com/repos/Theano/Theano/issues/4535/comments"},"review_comments":{"href":"https://api.github.com/repos/Theano/Theano/pulls/4535/comments"},"review_comment":{"href":"https://api.github.com/repos/Theano/Theano/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Theano/Theano/pulls/4535/commits"},"statuses":{"href":"https://api.github.com/repos/Theano/Theano/statuses/5f0572d8796f4df21b247c5b630b34a3276dc4a1"}}}}
{"actor":{"display_login":"abergeron"}}