{"action":"created","comment":{"url":"https://api.github.com/repos/NervanaSystems/ngraph/pulls/comments/194565681","pull_request_review_id":127756663,"id":194565681,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5NDU2NTY4MQ==","diff_hunk":"@@ -937,6 +1073,104 @@ size_t runtime::gpu::CUDAEmitter::build_replace_slice(const GPURuntimeContext* c\n     return primitive_index;\n }\n \n+size_t runtime::gpu::CUDAEmitter::build_broadcast(const GPURuntimeContext* ctx,\n+                                                  const std::array<std::string, 2>& dtypes,\n+                                                  GPUShape result_shape,\n+                                                  const std::set<size_t>& reduce_axes)\n+{\n+    // assumes NC{d1,...,dn} format\n+    std::string kernel_name = \"broadcast_\" + join(dtypes, \"_\");\n+    std::replace(kernel_name.begin(), kernel_name.end(), ' ', '_');\n+\n+    std::stringstream ss;\n+    ss << kernel_name << \"_s\" << join(result_shape, \"_\") << \"_r\" << join(reduce_axes, \"_\");\n+    auto hash = ss.str();\n+\n+    // check if the requested kernel is already an inserted primitive\n+    size_t primitive_index = m_primitive_emitter->lookup(hash);\n+    if (primitive_index != std::numeric_limits<size_t>::max())\n+    {\n+        return primitive_index;\n+    }\n+\n+    // if the kernel has not been compiled, build it\n+    auto compiled_kernel = ctx->compiled_kernel_pool->get(kernel_name);\n+    if (compiled_kernel == nullptr)\n+    {\n+        codegen::CodeWriter writer;\n+        writer << include_helpers();\n+        runtime::gpu::CudaKernelBuilder::get_broadcast_op(\n+            writer, kernel_name, dtypes, result_shape.size());\n+        compiled_kernel = ctx->compiled_kernel_pool->set(kernel_name, writer.get_code());\n+    }\n+\n+    // calculate strides\n+    GPUShape strides = row_major_strides(result_shape);\n+    // precacluate invariants for integer division via multiplication\n+    std::vector<int> stride_magic;\n+    std::vector<int> stride_shift;\n+    for (int i = 0; i < strides.size(); i++)\n+    {\n+        int magic;\n+        int shift;\n+        std::tie(magic, shift) = idiv_magic_u64(strides[i]);\n+        stride_magic.push_back(magic);\n+        stride_shift.push_back(shift);\n+    }\n+    // calculate reduced tensor strides with 0s inserted for reduced axes\n+    GPUShape reduced_shape = result_shape;\n+    for (auto const& axis : reduce_axes)\n+    {\n+        reduced_shape[axis] = 1;\n+    }\n+    GPUShape reduced_strides = row_major_strides(reduced_shape);\n+    for (auto const& axis : reduce_axes)\n+    {\n+        reduced_strides[axis] = 0;\n+    }\n+\n+    GPUAllocator allocator = this->m_primitive_emitter->get_memory_allocator();\n+    size_t idx_strides = allocator.reserve_argspace(strides.data(), strides.size() * sizeof(int));\n+    size_t idx_stride_magic =\n+        allocator.reserve_argspace(stride_magic.data(), stride_magic.size() * sizeof(int));\n+    size_t idx_stride_shift =\n+        allocator.reserve_argspace(stride_shift.data(), stride_shift.size() * sizeof(int));\n+    size_t idx_reduced_strides =\n+        allocator.reserve_argspace(reduced_strides.data(), reduced_strides.size() * sizeof(int));\n+\n+    // TODO: blending factors are not currently implemented\n+    float alpha = 1.0f;\n+    float beta = 0.0f;\n+\n+    int nthreads = static_cast<int>(shape_size(result_shape));\n+\n+    std::unique_ptr<gpu::primitive> softmax(new gpu::primitive{[=](void** inputs,","path":"src/ngraph/runtime/gpu/cuda_emitter.cpp","position":218,"original_position":218,"commit_id":"561b9b6e17b943e902c21db66cf8e2c04c7c50ce","original_commit_id":"561b9b6e17b943e902c21db66cf8e2c04c7c50ce","user":{"login":"fengleitian","id":35274053,"node_id":"MDQ6VXNlcjM1Mjc0MDUz","avatar_url":"https://avatars3.githubusercontent.com/u/35274053?v=4","gravatar_id":"","url":"https://api.github.com/users/fengleitian","html_url":"https://github.com/fengleitian","followers_url":"https://api.github.com/users/fengleitian/followers","following_url":"https://api.github.com/users/fengleitian/following{/other_user}","gists_url":"https://api.github.com/users/fengleitian/gists{/gist_id}","starred_url":"https://api.github.com/users/fengleitian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fengleitian/subscriptions","organizations_url":"https://api.github.com/users/fengleitian/orgs","repos_url":"https://api.github.com/users/fengleitian/repos","events_url":"https://api.github.com/users/fengleitian/events{/privacy}","received_events_url":"https://api.github.com/users/fengleitian/received_events","type":"User","site_admin":false},"body":"It's a little bit confuse when build broadcast with softmax.","created_at":"2018-06-11T22:20:28Z","updated_at":"2018-06-11T22:23:50Z","html_url":"https://github.com/NervanaSystems/ngraph/pull/1070#discussion_r194565681","pull_request_url":"https://api.github.com/repos/NervanaSystems/ngraph/pulls/1070","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/NervanaSystems/ngraph/pulls/comments/194565681"},"html":{"href":"https://github.com/NervanaSystems/ngraph/pull/1070#discussion_r194565681"},"pull_request":{"href":"https://api.github.com/repos/NervanaSystems/ngraph/pulls/1070"}}},"pull_request":{"url":"https://api.github.com/repos/NervanaSystems/ngraph/pulls/1070","id":192172710,"node_id":"MDExOlB1bGxSZXF1ZXN0MTkyMTcyNzEw","html_url":"https://github.com/NervanaSystems/ngraph/pull/1070","diff_url":"https://github.com/NervanaSystems/ngraph/pull/1070.diff","patch_url":"https://github.com/NervanaSystems/ngraph/pull/1070.patch","issue_url":"https://api.github.com/repos/NervanaSystems/ngraph/issues/1070","number":1070,"state":"open","locked":false,"title":"CUDA softmax kernel and broadcast kernel support for multiple non-consecutive axes","user":{"login":"csullivan","id":4804563,"node_id":"MDQ6VXNlcjQ4MDQ1NjM=","avatar_url":"https://avatars1.githubusercontent.com/u/4804563?v=4","gravatar_id":"","url":"https://api.github.com/users/csullivan","html_url":"https://github.com/csullivan","followers_url":"https://api.github.com/users/csullivan/followers","following_url":"https://api.github.com/users/csullivan/following{/other_user}","gists_url":"https://api.github.com/users/csullivan/gists{/gist_id}","starred_url":"https://api.github.com/users/csullivan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/csullivan/subscriptions","organizations_url":"https://api.github.com/users/csullivan/orgs","repos_url":"https://api.github.com/users/csullivan/repos","events_url":"https://api.github.com/users/csullivan/events{/privacy}","received_events_url":"https://api.github.com/users/csullivan/received_events","type":"User","site_admin":false},"body":"This PR introduces fused elementwise+collective kernels. op::Softmax is implemented in the GPU via two of these kernels: \r\n```\r\n1. elementwise exponentiation fused with sum reduce\r\n2. elementwise division fused with broadcast\r\n```\r\n\r\nFeatures:\r\n* Adds softmax cuda kernel to handle activation along arbitrary axes.\r\n* Adds a few new softmax tests\r\n* Adds broadcast to the CUDAEmitter with support for all axis broadcasting (coordinate transformation function is shared in softmax and broadcast)\r\n\r\n\r\nLimitations:\r\n* The softmax kernel relies on atomic updates to global memory which can create contention. I began work on a hierarchical reduction in cs/gpu_softmax_cuda_shfl, but decided to postpone further efforts until later.","created_at":"2018-06-02T01:38:25Z","updated_at":"2018-06-11T22:23:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cadbf37bac619c30195866207ef9de503d5f65db","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":825174556,"node_id":"MDU6TGFiZWw4MjUxNzQ1NTY=","url":"https://api.github.com/repos/NervanaSystems/ngraph/labels/GPU","name":"GPU","color":"3956cc","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/NervanaSystems/ngraph/pulls/1070/commits","review_comments_url":"https://api.github.com/repos/NervanaSystems/ngraph/pulls/1070/comments","review_comment_url":"https://api.github.com/repos/NervanaSystems/ngraph/pulls/comments{/number}","comments_url":"https://api.github.com/repos/NervanaSystems/ngraph/issues/1070/comments","statuses_url":"https://api.github.com/repos/NervanaSystems/ngraph/statuses/561b9b6e17b943e902c21db66cf8e2c04c7c50ce","head":{"label":"NervanaSystems:cs/gpu_softmax_cuda","ref":"cs/gpu_softmax_cuda","sha":"561b9b6e17b943e902c21db66cf8e2c04c7c50ce","user":{"login":"NervanaSystems","id":9260121,"node_id":"MDEyOk9yZ2FuaXphdGlvbjkyNjAxMjE=","avatar_url":"https://avatars2.githubusercontent.com/u/9260121?v=4","gravatar_id":"","url":"https://api.github.com/users/NervanaSystems","html_url":"https://github.com/NervanaSystems","followers_url":"https://api.github.com/users/NervanaSystems/followers","following_url":"https://api.github.com/users/NervanaSystems/following{/other_user}","gists_url":"https://api.github.com/users/NervanaSystems/gists{/gist_id}","starred_url":"https://api.github.com/users/NervanaSystems/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NervanaSystems/subscriptions","organizations_url":"https://api.github.com/users/NervanaSystems/orgs","repos_url":"https://api.github.com/users/NervanaSystems/repos","events_url":"https://api.github.com/users/NervanaSystems/events{/privacy}","received_events_url":"https://api.github.com/users/NervanaSystems/received_events","type":"Organization","site_admin":false},"repo":{"id":98252973,"node_id":"MDEwOlJlcG9zaXRvcnk5ODI1Mjk3Mw==","name":"ngraph","full_name":"NervanaSystems/ngraph","owner":{"login":"NervanaSystems","id":9260121,"node_id":"MDEyOk9yZ2FuaXphdGlvbjkyNjAxMjE=","avatar_url":"https://avatars2.githubusercontent.com/u/9260121?v=4","gravatar_id":"","url":"https://api.github.com/users/NervanaSystems","html_url":"https://github.com/NervanaSystems","followers_url":"https://api.github.com/users/NervanaSystems/followers","following_url":"https://api.github.com/users/NervanaSystems/following{/other_user}","gists_url":"https://api.github.com/users/NervanaSystems/gists{/gist_id}","starred_url":"https://api.github.com/users/NervanaSystems/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NervanaSystems/subscriptions","organizations_url":"https://api.github.com/users/NervanaSystems/orgs","repos_url":"https://api.github.com/users/NervanaSystems/repos","events_url":"https://api.github.com/users/NervanaSystems/events{/privacy}","received_events_url":"https://api.github.com/users/NervanaSystems/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/NervanaSystems/ngraph","description":"nGraph is an open source C++ library, compiler and runtime for Deep Learning frameworks","fork":false,"url":"https://api.github.com/repos/NervanaSystems/ngraph","forks_url":"https://api.github.com/repos/NervanaSystems/ngraph/forks","keys_url":"https://api.github.com/repos/NervanaSystems/ngraph/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NervanaSystems/ngraph/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NervanaSystems/ngraph/teams","hooks_url":"https://api.github.com/repos/NervanaSystems/ngraph/hooks","issue_events_url":"https://api.github.com/repos/NervanaSystems/ngraph/issues/events{/number}","events_url":"https://api.github.com/repos/NervanaSystems/ngraph/events","assignees_url":"https://api.github.com/repos/NervanaSystems/ngraph/assignees{/user}","branches_url":"https://api.github.com/repos/NervanaSystems/ngraph/branches{/branch}","tags_url":"https://api.github.com/repos/NervanaSystems/ngraph/tags","blobs_url":"https://api.github.com/repos/NervanaSystems/ngraph/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NervanaSystems/ngraph/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NervanaSystems/ngraph/git/refs{/sha}","trees_url":"https://api.github.com/repos/NervanaSystems/ngraph/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NervanaSystems/ngraph/statuses/{sha}","languages_url":"https://api.github.com/repos/NervanaSystems/ngraph/languages","stargazers_url":"https://api.github.com/repos/NervanaSystems/ngraph/stargazers","contributors_url":"https://api.github.com/repos/NervanaSystems/ngraph/contributors","subscribers_url":"https://api.github.com/repos/NervanaSystems/ngraph/subscribers","subscription_url":"https://api.github.com/repos/NervanaSystems/ngraph/subscription","commits_url":"https://api.github.com/repos/NervanaSystems/ngraph/commits{/sha}","git_commits_url":"https://api.github.com/repos/NervanaSystems/ngraph/git/commits{/sha}","comments_url":"https://api.github.com/repos/NervanaSystems/ngraph/comments{/number}","issue_comment_url":"https://api.github.com/repos/NervanaSystems/ngraph/issues/comments{/number}","contents_url":"https://api.github.com/repos/NervanaSystems/ngraph/contents/{+path}","compare_url":"https://api.github.com/repos/NervanaSystems/ngraph/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NervanaSystems/ngraph/merges","archive_url":"https://api.github.com/repos/NervanaSystems/ngraph/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NervanaSystems/ngraph/downloads","issues_url":"https://api.github.com/repos/NervanaSystems/ngraph/issues{/number}","pulls_url":"https://api.github.com/repos/NervanaSystems/ngraph/pulls{/number}","milestones_url":"https://api.github.com/repos/NervanaSystems/ngraph/milestones{/number}","notifications_url":"https://api.github.com/repos/NervanaSystems/ngraph/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NervanaSystems/ngraph/labels{/name}","releases_url":"https://api.github.com/repos/NervanaSystems/ngraph/releases{/id}","deployments_url":"https://api.github.com/repos/NervanaSystems/ngraph/deployments","created_at":"2017-07-25T02:02:38Z","updated_at":"2018-06-11T18:23:25Z","pushed_at":"2018-06-11T22:18:39Z","git_url":"git://github.com/NervanaSystems/ngraph.git","ssh_url":"git@github.com:NervanaSystems/ngraph.git","clone_url":"https://github.com/NervanaSystems/ngraph.git","svn_url":"https://github.com/NervanaSystems/ngraph","homepage":"http://ngraph.nervanasys.com/docs/latest","size":31870,"stargazers_count":493,"watchers_count":493,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":47,"mirror_url":null,"archived":false,"open_issues_count":39,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":47,"open_issues":39,"watchers":493,"default_branch":"master"}},"base":{"label":"NervanaSystems:master","ref":"master","sha":"0b95efa6732456e1fda150c20457f462577553a1","user":{"login":"NervanaSystems","id":9260121,"node_id":"MDEyOk9yZ2FuaXphdGlvbjkyNjAxMjE=","avatar_url":"https://avatars2.githubusercontent.com/u/9260121?v=4","gravatar_id":"","url":"https://api.github.com/users/NervanaSystems","html_url":"https://github.com/NervanaSystems","followers_url":"https://api.github.com/users/NervanaSystems/followers","following_url":"https://api.github.com/users/NervanaSystems/following{/other_user}","gists_url":"https://api.github.com/users/NervanaSystems/gists{/gist_id}","starred_url":"https://api.github.com/users/NervanaSystems/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NervanaSystems/subscriptions","organizations_url":"https://api.github.com/users/NervanaSystems/orgs","repos_url":"https://api.github.com/users/NervanaSystems/repos","events_url":"https://api.github.com/users/NervanaSystems/events{/privacy}","received_events_url":"https://api.github.com/users/NervanaSystems/received_events","type":"Organization","site_admin":false},"repo":{"id":98252973,"node_id":"MDEwOlJlcG9zaXRvcnk5ODI1Mjk3Mw==","name":"ngraph","full_name":"NervanaSystems/ngraph","owner":{"login":"NervanaSystems","id":9260121,"node_id":"MDEyOk9yZ2FuaXphdGlvbjkyNjAxMjE=","avatar_url":"https://avatars2.githubusercontent.com/u/9260121?v=4","gravatar_id":"","url":"https://api.github.com/users/NervanaSystems","html_url":"https://github.com/NervanaSystems","followers_url":"https://api.github.com/users/NervanaSystems/followers","following_url":"https://api.github.com/users/NervanaSystems/following{/other_user}","gists_url":"https://api.github.com/users/NervanaSystems/gists{/gist_id}","starred_url":"https://api.github.com/users/NervanaSystems/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NervanaSystems/subscriptions","organizations_url":"https://api.github.com/users/NervanaSystems/orgs","repos_url":"https://api.github.com/users/NervanaSystems/repos","events_url":"https://api.github.com/users/NervanaSystems/events{/privacy}","received_events_url":"https://api.github.com/users/NervanaSystems/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/NervanaSystems/ngraph","description":"nGraph is an open source C++ library, compiler and runtime for Deep Learning frameworks","fork":false,"url":"https://api.github.com/repos/NervanaSystems/ngraph","forks_url":"https://api.github.com/repos/NervanaSystems/ngraph/forks","keys_url":"https://api.github.com/repos/NervanaSystems/ngraph/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NervanaSystems/ngraph/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NervanaSystems/ngraph/teams","hooks_url":"https://api.github.com/repos/NervanaSystems/ngraph/hooks","issue_events_url":"https://api.github.com/repos/NervanaSystems/ngraph/issues/events{/number}","events_url":"https://api.github.com/repos/NervanaSystems/ngraph/events","assignees_url":"https://api.github.com/repos/NervanaSystems/ngraph/assignees{/user}","branches_url":"https://api.github.com/repos/NervanaSystems/ngraph/branches{/branch}","tags_url":"https://api.github.com/repos/NervanaSystems/ngraph/tags","blobs_url":"https://api.github.com/repos/NervanaSystems/ngraph/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NervanaSystems/ngraph/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NervanaSystems/ngraph/git/refs{/sha}","trees_url":"https://api.github.com/repos/NervanaSystems/ngraph/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NervanaSystems/ngraph/statuses/{sha}","languages_url":"https://api.github.com/repos/NervanaSystems/ngraph/languages","stargazers_url":"https://api.github.com/repos/NervanaSystems/ngraph/stargazers","contributors_url":"https://api.github.com/repos/NervanaSystems/ngraph/contributors","subscribers_url":"https://api.github.com/repos/NervanaSystems/ngraph/subscribers","subscription_url":"https://api.github.com/repos/NervanaSystems/ngraph/subscription","commits_url":"https://api.github.com/repos/NervanaSystems/ngraph/commits{/sha}","git_commits_url":"https://api.github.com/repos/NervanaSystems/ngraph/git/commits{/sha}","comments_url":"https://api.github.com/repos/NervanaSystems/ngraph/comments{/number}","issue_comment_url":"https://api.github.com/repos/NervanaSystems/ngraph/issues/comments{/number}","contents_url":"https://api.github.com/repos/NervanaSystems/ngraph/contents/{+path}","compare_url":"https://api.github.com/repos/NervanaSystems/ngraph/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NervanaSystems/ngraph/merges","archive_url":"https://api.github.com/repos/NervanaSystems/ngraph/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NervanaSystems/ngraph/downloads","issues_url":"https://api.github.com/repos/NervanaSystems/ngraph/issues{/number}","pulls_url":"https://api.github.com/repos/NervanaSystems/ngraph/pulls{/number}","milestones_url":"https://api.github.com/repos/NervanaSystems/ngraph/milestones{/number}","notifications_url":"https://api.github.com/repos/NervanaSystems/ngraph/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NervanaSystems/ngraph/labels{/name}","releases_url":"https://api.github.com/repos/NervanaSystems/ngraph/releases{/id}","deployments_url":"https://api.github.com/repos/NervanaSystems/ngraph/deployments","created_at":"2017-07-25T02:02:38Z","updated_at":"2018-06-11T18:23:25Z","pushed_at":"2018-06-11T22:18:39Z","git_url":"git://github.com/NervanaSystems/ngraph.git","ssh_url":"git@github.com:NervanaSystems/ngraph.git","clone_url":"https://github.com/NervanaSystems/ngraph.git","svn_url":"https://github.com/NervanaSystems/ngraph","homepage":"http://ngraph.nervanasys.com/docs/latest","size":31870,"stargazers_count":493,"watchers_count":493,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":47,"mirror_url":null,"archived":false,"open_issues_count":39,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":47,"open_issues":39,"watchers":493,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/NervanaSystems/ngraph/pulls/1070"},"html":{"href":"https://github.com/NervanaSystems/ngraph/pull/1070"},"issue":{"href":"https://api.github.com/repos/NervanaSystems/ngraph/issues/1070"},"comments":{"href":"https://api.github.com/repos/NervanaSystems/ngraph/issues/1070/comments"},"review_comments":{"href":"https://api.github.com/repos/NervanaSystems/ngraph/pulls/1070/comments"},"review_comment":{"href":"https://api.github.com/repos/NervanaSystems/ngraph/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/NervanaSystems/ngraph/pulls/1070/commits"},"statuses":{"href":"https://api.github.com/repos/NervanaSystems/ngraph/statuses/561b9b6e17b943e902c21db66cf8e2c04c7c50ce"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"fengleitian"}}