{"action":"created","comment":{"url":"https://api.github.com/repos/cupy/cupy/pulls/comments/231761973","pull_request_review_id":172311942,"id":231761973,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzMTc2MTk3Mw==","diff_hunk":"@@ -437,6 +440,328 @@ def get_rnn_lin_layer_bias_params(\n     return bias\n \n \n+cdef class DescriptorArray(object):\n+\n+    cdef:\n+        vector.vector[size_t] _value\n+        object _destroy\n+\n+    def __init__(self, destroyer):\n+        self._destroy = destroyer\n+\n+    def __del__(self):\n+        for desc in self._value:\n+            self._destroy(desc)\n+\n+    def append(self, desc):\n+        self._value.push_back(desc)\n+\n+    @property\n+    def data(self):\n+        return <size_t>&self._value[0]\n+    \n+\n+cpdef DescriptorArray _make_tensor_descriptor_array(xs, lengths):\n+    \"\"\"Make an array of pointers denoting pointers of tensor descriptors.\n+\n+    \"\"\"\n+    cdef DescriptorArray descs = DescriptorArray(\n+        py_cudnn.destroyTensorDescriptor)\n+    cdef size_t desc\n+    cdef int data_type = get_data_type(xs.dtype)\n+    cdef vector.vector[int] c_shape, c_strides\n+    cdef Py_ssize_t itemsize = xs.itemsize\n+    cdef Py_ssize_t s\n+    cdef int length\n+\n+    for s in xs._strides:\n+        c_strides.push_back(s // itemsize)\n+    c_strides.push_back(1)\n+    for s in xs._shape:\n+        c_shape.push_back(s)\n+    c_shape.push_back(1)\n+\n+    for length in lengths:\n+        c_shape[0] = length\n+        desc = cudnn.createTensorDescriptor()\n+        descs.append(desc)\n+        cudnn.setTensorNdDescriptor(\n+            desc, data_type, 3, <size_t>&c_shape[0], <size_t>&c_strides[0])\n+\n+    return descs\n+\n+\n+cdef core.ndarray _make_rnn_workspace(\n+    Descriptor rnn_desc, int length, DescriptorArray descs):\n+    cdef size_t handle = get_handle()\n+    cdef size_t work_size = py_cudnn.getRNNWorkspaceSize(\n+        handle, rnn_desc.value, length, descs.data)\n+    return core.ndarray((work_size,), dtype='b')\n+\n+\n+def rnn_forward_inference(\n+        DropoutStates states, int direction_mode, int rnn_mode,\n+        core.ndarray hx, core.ndarray cx, core.ndarray w, core.ndarray xs,\n+        lengths):\n+    hx = core.ascontiguousarray(hx)\n+    cx = core.ascontiguousarray(cx)\n+    w = core.ascontiguousarray(w)\n+    xs = core.ascontiguousarray(xs)\n+\n+    cdef int length = len(lengths)\n+    cdef int n_layers\n+    cdef int n_units = hx.shape[2]\n+    cdef int input_units\n+    if direction_mode == py_cudnn.CUDNN_BIDIRECTIONAL:\n+        input_units = n_units * 2\n+        n_layers = hx.shape[0] // 2\n+    else:  # py_cudnn.CUDNN_UNIDIRECTIONAL\n+        input_units = n_units\n+        n_layers = hx.shape[0]\n+\n+    cdef core.ndarray ys = core.ndarray((len(xs), input_units), dtype=xs.dtype)\n+    cdef size_t handle = get_handle()\n+\n+    cdef Descriptor rnn_desc = create_rnn_descriptor(\n+        n_units, n_layers, states._desc,\n+        py_cudnn.CUDNN_LINEAR_INPUT, direction_mode,\n+        rnn_mode, get_data_type(xs.dtype))\n+\n+    c_x_descs = _make_tensor_descriptor_array(xs, lengths)\n+    cdef Descriptor hx_desc = create_tensor_nd_descriptor(hx)\n+    cdef Descriptor w_desc = create_filter_descriptor(w)\n+\n+    c_y_descs = _make_tensor_descriptor_array(ys, lengths)\n+    cdef core.ndarray hy = core.ndarray(hx.shape, hx.dtype)\n+    cdef Descriptor hy_desc = create_tensor_nd_descriptor(hy)\n+\n+    cdef Descriptor cx_desc, cy_desc\n+    cdef core.ndarray cy\n+    if cx is not None:\n+        cx_ptr = cx.data.ptr\n+        cx_desc = create_tensor_nd_descriptor(cx)\n+        cx_desc_value = cx_desc.value\n+        cy = core.ndarray(cx.shape, cx.dtype)\n+        cy_ptr = cy.data.ptr\n+        cy_desc = create_tensor_nd_descriptor(cy)\n+        cy_desc_value = cy_desc.value\n+    else:\n+        cx_ptr = 0\n+        cx_desc_value = 0\n+        cy = None\n+        cy_ptr = 0\n+        cy_desc_value = 0\n+\n+    cdef core.ndarray workspace = _make_rnn_workspace(\n+        rnn_desc, length, c_x_descs)\n+    \n+    py_cudnn.RNNForwardInference(\n+        handle, rnn_desc.value, length,\n+        c_x_descs.data, xs.data.ptr, hx_desc.value, hx.data.ptr,\n+        cx_desc_value, cx_ptr, w_desc.value, w.data.ptr,\n+        c_y_descs.data, ys.data.ptr, hy_desc.value, hy.data.ptr,\n+        cy_desc_value, cy_ptr, workspace.data.ptr, workspace.size)\n+\n+    return hy, cy, ys\n+\n+\n+def rnn_forward_training(\n+        DropoutStates states, int direction_mode, int rnn_mode,\n+        core.ndarray hx, core.ndarray cx, core.ndarray w, core.ndarray xs,\n+        lengths):\n+    hx = core.ascontiguousarray(hx)\n+    cx = core.ascontiguousarray(cx)\n+    w = core.ascontiguousarray(w)\n+    xs = core.ascontiguousarray(xs)\n+\n+    cdef int length = len(lengths)\n+    cdef int n_layers\n+    cdef int n_units = hx.shape[2]\n+    cdef int input_units\n+\n+    if direction_mode == py_cudnn.CUDNN_BIDIRECTIONAL:\n+        input_units = n_units * 2\n+        n_layers = hx.shape[0] // 2\n+    else:  # py_cudnn.CUDNN_UNIDIRECTIONAL","path":"cupy/cudnn.pyx","position":167,"original_position":167,"commit_id":"574d553eb3af8e886fe41d87ddebd98dc7e307c3","original_commit_id":"574d553eb3af8e886fe41d87ddebd98dc7e307c3","user":{"login":"okuta","id":7133388,"node_id":"MDQ6VXNlcjcxMzMzODg=","avatar_url":"https://avatars1.githubusercontent.com/u/7133388?v=4","gravatar_id":"","url":"https://api.github.com/users/okuta","html_url":"https://github.com/okuta","followers_url":"https://api.github.com/users/okuta/followers","following_url":"https://api.github.com/users/okuta/following{/other_user}","gists_url":"https://api.github.com/users/okuta/gists{/gist_id}","starred_url":"https://api.github.com/users/okuta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/okuta/subscriptions","organizations_url":"https://api.github.com/users/okuta/orgs","repos_url":"https://api.github.com/users/okuta/repos","events_url":"https://api.github.com/users/okuta/events{/privacy}","received_events_url":"https://api.github.com/users/okuta/received_events","type":"User","site_admin":false},"body":"```suggestion\r\n    else:  # cudnn.CUDNN_UNIDIRECTIONAL\r\n```","created_at":"2018-11-08T04:23:39Z","updated_at":"2018-11-08T04:32:45Z","html_url":"https://github.com/cupy/cupy/pull/1659#discussion_r231761973","pull_request_url":"https://api.github.com/repos/cupy/cupy/pulls/1659","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/cupy/cupy/pulls/comments/231761973"},"html":{"href":"https://github.com/cupy/cupy/pull/1659#discussion_r231761973"},"pull_request":{"href":"https://api.github.com/repos/cupy/cupy/pulls/1659"}}},"pull_request":{"url":"https://api.github.com/repos/cupy/cupy/pulls/1659","id":217558469,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE3NTU4NDY5","html_url":"https://github.com/cupy/cupy/pull/1659","diff_url":"https://github.com/cupy/cupy/pull/1659.diff","patch_url":"https://github.com/cupy/cupy/pull/1659.patch","issue_url":"https://api.github.com/repos/cupy/cupy/issues/1659","number":1659,"state":"open","locked":false,"title":"[WIP] RNN high level API","user":{"login":"unnonouno","id":740680,"node_id":"MDQ6VXNlcjc0MDY4MA==","avatar_url":"https://avatars1.githubusercontent.com/u/740680?v=4","gravatar_id":"","url":"https://api.github.com/users/unnonouno","html_url":"https://github.com/unnonouno","followers_url":"https://api.github.com/users/unnonouno/followers","following_url":"https://api.github.com/users/unnonouno/following{/other_user}","gists_url":"https://api.github.com/users/unnonouno/gists{/gist_id}","starred_url":"https://api.github.com/users/unnonouno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/unnonouno/subscriptions","organizations_url":"https://api.github.com/users/unnonouno/orgs","repos_url":"https://api.github.com/users/unnonouno/repos","events_url":"https://api.github.com/users/unnonouno/events{/privacy}","received_events_url":"https://api.github.com/users/unnonouno/received_events","type":"User","site_admin":false},"body":"I extracted high-level API from Chainer. It provides high-level API for cudnn's RNN.","created_at":"2018-09-24T05:18:30Z","updated_at":"2018-11-08T04:32:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0f42d7eb1f3fced21eccde8e293e2c76a9e6188e","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/cupy/cupy/pulls/1659/commits","review_comments_url":"https://api.github.com/repos/cupy/cupy/pulls/1659/comments","review_comment_url":"https://api.github.com/repos/cupy/cupy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cupy/cupy/issues/1659/comments","statuses_url":"https://api.github.com/repos/cupy/cupy/statuses/574d553eb3af8e886fe41d87ddebd98dc7e307c3","head":{"label":"unnonouno:rnn-high-level-api","ref":"rnn-high-level-api","sha":"574d553eb3af8e886fe41d87ddebd98dc7e307c3","user":{"login":"unnonouno","id":740680,"node_id":"MDQ6VXNlcjc0MDY4MA==","avatar_url":"https://avatars1.githubusercontent.com/u/740680?v=4","gravatar_id":"","url":"https://api.github.com/users/unnonouno","html_url":"https://github.com/unnonouno","followers_url":"https://api.github.com/users/unnonouno/followers","following_url":"https://api.github.com/users/unnonouno/following{/other_user}","gists_url":"https://api.github.com/users/unnonouno/gists{/gist_id}","starred_url":"https://api.github.com/users/unnonouno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/unnonouno/subscriptions","organizations_url":"https://api.github.com/users/unnonouno/orgs","repos_url":"https://api.github.com/users/unnonouno/repos","events_url":"https://api.github.com/users/unnonouno/events{/privacy}","received_events_url":"https://api.github.com/users/unnonouno/received_events","type":"User","site_admin":false},"repo":{"id":95103764,"node_id":"MDEwOlJlcG9zaXRvcnk5NTEwMzc2NA==","name":"cupy","full_name":"unnonouno/cupy","private":false,"owner":{"login":"unnonouno","id":740680,"node_id":"MDQ6VXNlcjc0MDY4MA==","avatar_url":"https://avatars1.githubusercontent.com/u/740680?v=4","gravatar_id":"","url":"https://api.github.com/users/unnonouno","html_url":"https://github.com/unnonouno","followers_url":"https://api.github.com/users/unnonouno/followers","following_url":"https://api.github.com/users/unnonouno/following{/other_user}","gists_url":"https://api.github.com/users/unnonouno/gists{/gist_id}","starred_url":"https://api.github.com/users/unnonouno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/unnonouno/subscriptions","organizations_url":"https://api.github.com/users/unnonouno/orgs","repos_url":"https://api.github.com/users/unnonouno/repos","events_url":"https://api.github.com/users/unnonouno/events{/privacy}","received_events_url":"https://api.github.com/users/unnonouno/received_events","type":"User","site_admin":false},"html_url":"https://github.com/unnonouno/cupy","description":"NumPy-like API accelerated with CUDA","fork":true,"url":"https://api.github.com/repos/unnonouno/cupy","forks_url":"https://api.github.com/repos/unnonouno/cupy/forks","keys_url":"https://api.github.com/repos/unnonouno/cupy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/unnonouno/cupy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/unnonouno/cupy/teams","hooks_url":"https://api.github.com/repos/unnonouno/cupy/hooks","issue_events_url":"https://api.github.com/repos/unnonouno/cupy/issues/events{/number}","events_url":"https://api.github.com/repos/unnonouno/cupy/events","assignees_url":"https://api.github.com/repos/unnonouno/cupy/assignees{/user}","branches_url":"https://api.github.com/repos/unnonouno/cupy/branches{/branch}","tags_url":"https://api.github.com/repos/unnonouno/cupy/tags","blobs_url":"https://api.github.com/repos/unnonouno/cupy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/unnonouno/cupy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/unnonouno/cupy/git/refs{/sha}","trees_url":"https://api.github.com/repos/unnonouno/cupy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/unnonouno/cupy/statuses/{sha}","languages_url":"https://api.github.com/repos/unnonouno/cupy/languages","stargazers_url":"https://api.github.com/repos/unnonouno/cupy/stargazers","contributors_url":"https://api.github.com/repos/unnonouno/cupy/contributors","subscribers_url":"https://api.github.com/repos/unnonouno/cupy/subscribers","subscription_url":"https://api.github.com/repos/unnonouno/cupy/subscription","commits_url":"https://api.github.com/repos/unnonouno/cupy/commits{/sha}","git_commits_url":"https://api.github.com/repos/unnonouno/cupy/git/commits{/sha}","comments_url":"https://api.github.com/repos/unnonouno/cupy/comments{/number}","issue_comment_url":"https://api.github.com/repos/unnonouno/cupy/issues/comments{/number}","contents_url":"https://api.github.com/repos/unnonouno/cupy/contents/{+path}","compare_url":"https://api.github.com/repos/unnonouno/cupy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/unnonouno/cupy/merges","archive_url":"https://api.github.com/repos/unnonouno/cupy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/unnonouno/cupy/downloads","issues_url":"https://api.github.com/repos/unnonouno/cupy/issues{/number}","pulls_url":"https://api.github.com/repos/unnonouno/cupy/pulls{/number}","milestones_url":"https://api.github.com/repos/unnonouno/cupy/milestones{/number}","notifications_url":"https://api.github.com/repos/unnonouno/cupy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/unnonouno/cupy/labels{/name}","releases_url":"https://api.github.com/repos/unnonouno/cupy/releases{/id}","deployments_url":"https://api.github.com/repos/unnonouno/cupy/deployments","created_at":"2017-06-22T10:26:18Z","updated_at":"2017-06-22T10:26:20Z","pushed_at":"2018-10-23T00:15:30Z","git_url":"git://github.com/unnonouno/cupy.git","ssh_url":"git@github.com:unnonouno/cupy.git","clone_url":"https://github.com/unnonouno/cupy.git","svn_url":"https://github.com/unnonouno/cupy","homepage":"https://cupy.chainer.org","size":15043,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"cupy:master","ref":"master","sha":"262ef46b999cdaf84aa6987193e1bc9c2ee5a1bf","user":{"login":"cupy","id":23187665,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIzMTg3NjY1","avatar_url":"https://avatars2.githubusercontent.com/u/23187665?v=4","gravatar_id":"","url":"https://api.github.com/users/cupy","html_url":"https://github.com/cupy","followers_url":"https://api.github.com/users/cupy/followers","following_url":"https://api.github.com/users/cupy/following{/other_user}","gists_url":"https://api.github.com/users/cupy/gists{/gist_id}","starred_url":"https://api.github.com/users/cupy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cupy/subscriptions","organizations_url":"https://api.github.com/users/cupy/orgs","repos_url":"https://api.github.com/users/cupy/repos","events_url":"https://api.github.com/users/cupy/events{/privacy}","received_events_url":"https://api.github.com/users/cupy/received_events","type":"Organization","site_admin":false},"repo":{"id":72523920,"node_id":"MDEwOlJlcG9zaXRvcnk3MjUyMzkyMA==","name":"cupy","full_name":"cupy/cupy","private":false,"owner":{"login":"cupy","id":23187665,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIzMTg3NjY1","avatar_url":"https://avatars2.githubusercontent.com/u/23187665?v=4","gravatar_id":"","url":"https://api.github.com/users/cupy","html_url":"https://github.com/cupy","followers_url":"https://api.github.com/users/cupy/followers","following_url":"https://api.github.com/users/cupy/following{/other_user}","gists_url":"https://api.github.com/users/cupy/gists{/gist_id}","starred_url":"https://api.github.com/users/cupy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cupy/subscriptions","organizations_url":"https://api.github.com/users/cupy/orgs","repos_url":"https://api.github.com/users/cupy/repos","events_url":"https://api.github.com/users/cupy/events{/privacy}","received_events_url":"https://api.github.com/users/cupy/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/cupy/cupy","description":"NumPy-like API accelerated with CUDA","fork":false,"url":"https://api.github.com/repos/cupy/cupy","forks_url":"https://api.github.com/repos/cupy/cupy/forks","keys_url":"https://api.github.com/repos/cupy/cupy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cupy/cupy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cupy/cupy/teams","hooks_url":"https://api.github.com/repos/cupy/cupy/hooks","issue_events_url":"https://api.github.com/repos/cupy/cupy/issues/events{/number}","events_url":"https://api.github.com/repos/cupy/cupy/events","assignees_url":"https://api.github.com/repos/cupy/cupy/assignees{/user}","branches_url":"https://api.github.com/repos/cupy/cupy/branches{/branch}","tags_url":"https://api.github.com/repos/cupy/cupy/tags","blobs_url":"https://api.github.com/repos/cupy/cupy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cupy/cupy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cupy/cupy/git/refs{/sha}","trees_url":"https://api.github.com/repos/cupy/cupy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cupy/cupy/statuses/{sha}","languages_url":"https://api.github.com/repos/cupy/cupy/languages","stargazers_url":"https://api.github.com/repos/cupy/cupy/stargazers","contributors_url":"https://api.github.com/repos/cupy/cupy/contributors","subscribers_url":"https://api.github.com/repos/cupy/cupy/subscribers","subscription_url":"https://api.github.com/repos/cupy/cupy/subscription","commits_url":"https://api.github.com/repos/cupy/cupy/commits{/sha}","git_commits_url":"https://api.github.com/repos/cupy/cupy/git/commits{/sha}","comments_url":"https://api.github.com/repos/cupy/cupy/comments{/number}","issue_comment_url":"https://api.github.com/repos/cupy/cupy/issues/comments{/number}","contents_url":"https://api.github.com/repos/cupy/cupy/contents/{+path}","compare_url":"https://api.github.com/repos/cupy/cupy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cupy/cupy/merges","archive_url":"https://api.github.com/repos/cupy/cupy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cupy/cupy/downloads","issues_url":"https://api.github.com/repos/cupy/cupy/issues{/number}","pulls_url":"https://api.github.com/repos/cupy/cupy/pulls{/number}","milestones_url":"https://api.github.com/repos/cupy/cupy/milestones{/number}","notifications_url":"https://api.github.com/repos/cupy/cupy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cupy/cupy/labels{/name}","releases_url":"https://api.github.com/repos/cupy/cupy/releases{/id}","deployments_url":"https://api.github.com/repos/cupy/cupy/deployments","created_at":"2016-11-01T09:54:45Z","updated_at":"2018-11-08T04:24:22Z","pushed_at":"2018-11-08T04:24:17Z","git_url":"git://github.com/cupy/cupy.git","ssh_url":"git@github.com:cupy/cupy.git","clone_url":"https://github.com/cupy/cupy.git","svn_url":"https://github.com/cupy/cupy","homepage":"https://cupy.chainer.org","size":16101,"stargazers_count":2394,"watchers_count":2394,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":195,"mirror_url":null,"archived":false,"open_issues_count":191,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":195,"open_issues":191,"watchers":2394,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cupy/cupy/pulls/1659"},"html":{"href":"https://github.com/cupy/cupy/pull/1659"},"issue":{"href":"https://api.github.com/repos/cupy/cupy/issues/1659"},"comments":{"href":"https://api.github.com/repos/cupy/cupy/issues/1659/comments"},"review_comments":{"href":"https://api.github.com/repos/cupy/cupy/pulls/1659/comments"},"review_comment":{"href":"https://api.github.com/repos/cupy/cupy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cupy/cupy/pulls/1659/commits"},"statuses":{"href":"https://api.github.com/repos/cupy/cupy/statuses/574d553eb3af8e886fe41d87ddebd98dc7e307c3"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"okuta"}}