{"action":"created","comment":{"url":"https://api.github.com/repos/halide/Halide/pulls/comments/70159228","id":70159228,"diff_hunk":"@@ -1,23 +1,264 @@\n-#include <rpcmem.h>\n+#include <pthread.h>\n+#include <assert.h>\n+#include <stdint.h>\n+#include <stdlib.h>\n+#include <sys/types.h>\n+#include <unistd.h>\n+#include <sys/ioctl.h>\n+#include <sys/types.h>\n+#include <sys/stat.h>\n+#include <fcntl.h>\n+#include <sys/mman.h>\n+#include <linux/types.h>\n+#include <android/log.h>\n+\n+#include \"bin/src/halide_hexagon_remote.h\"\n+\n+#include \"stdio.h\"\n+\n+namespace {\n+\n+typedef halide_hexagon_remote_handle_t handle_t;\n+typedef halide_hexagon_remote_buffer buffer;\n+\n+// Allocations that are intended to be shared with Hexagon can be\n+// shared without copying if they are contiguous in physical\n+// memory. Android's ION allocator gives us a mechanism with which we\n+// can allocate contiguous physical memory.\n+enum ion_heap_id {\n+    system_heap_id = 25,\n+};\n+\n+enum ion_flags {\n+    ion_flag_cached = 1,\n+};\n+\n+typedef int ion_user_handle_t;\n+\n+struct ion_allocation_data {\n+    size_t len;\n+    size_t align;\n+    unsigned int heap_id_mask;\n+    unsigned int flags;\n+    ion_user_handle_t handle;\n+};\n+\n+struct ion_fd_data {\n+    ion_user_handle_t handle;\n+    int fd;\n+};\n+\n+struct ion_handle_data {\n+    ion_user_handle_t handle;\n+};\n+\n+#define ION_IOC_ALLOC _IOWR('I', 0, ion_allocation_data)\n+#define ION_IOC_FREE _IOWR('I', 1, ion_handle_data)\n+#define ION_IOC_MAP _IOWR('I', 2, ion_fd_data)\n+\n+ion_user_handle_t ion_alloc(int ion_fd, size_t len, size_t align, unsigned int heap_id_mask, unsigned int flags) {\n+    ion_allocation_data alloc = {\n+        len,\n+        align,\n+        heap_id_mask,\n+        flags,\n+        0\n+    };\n+    if (ioctl(ion_fd, ION_IOC_ALLOC, &alloc) < 0) {\n+        return -1;\n+    }\n+    return alloc.handle;\n+}\n+\n+int ion_map(int ion_fd, ion_user_handle_t handle) {\n+    ion_fd_data data = {\n+        handle,\n+        0\n+    };\n+    if (ioctl(ion_fd, ION_IOC_MAP, &data) < 0) {\n+        return -1;\n+    }\n+    return data.fd;\n+}\n+\n+int ion_free(int ion_fd, ion_user_handle_t ion_handle) {\n+    if(ioctl(ion_fd, ION_IOC_FREE, &ion_handle) < 0) {\n+        return -1;\n+    }\n+    return 0;\n+}\n+\n+// We need to be able to keep track of the size and some other\n+// information about ION allocations, so define a simple linked list\n+// of allocations we can traverse later.\n+struct allocation_record {\n+    allocation_record *next;\n+    int ion_fd;\n+    ion_user_handle_t handle;\n+    int buf_fd;\n+    void *buf;\n+    size_t size;\n+};\n+\n+// Make a dummy allocation so we don't need a special case for the\n+// head list node.\n+allocation_record allocations = { NULL, };\n+pthread_mutex_t allocations_mutex = PTHREAD_MUTEX_INITIALIZER;\n+\n+}  // namespace\n \n extern \"C\" {\n \n+// If this symbol is defined in the stub library we are going to link\n+// to, we need to call this in order to actually get zero copy\n+// behavior from our buffers.\n+__attribute__((weak)) void remote_register_buf(void* buf, int size, int fd);\n+\n void halide_hexagon_host_malloc_init() {\n-    rpcmem_init();\n+    pthread_mutex_init(&allocations_mutex, NULL);\n }\n \n void halide_hexagon_host_malloc_deinit() {\n-    rpcmem_deinit();\n+    pthread_mutex_destroy(&allocations_mutex);\n }\n \n void *halide_hexagon_host_malloc(size_t size) {\n-    // This heap is much faster than RPCMEM_DEFAULT_HEAP.\n-    const int system_heap = 25;\n-    return rpcmem_alloc(system_heap, RPCMEM_DEFAULT_FLAGS, size);\n+    int ion_fd = open(\"/dev/ion\", O_RDONLY, 0);","path":"src/runtime/hexagon_remote/halide_host.cpp","position":132,"original_position":132,"commit_id":"c7574e0a88b97be4ef95434e9178237201a6e6c1","original_commit_id":"c7574e0a88b97be4ef95434e9178237201a6e6c1","user":{"login":"dsharletg","id":7494796,"avatar_url":"https://avatars.githubusercontent.com/u/7494796?v=3","gravatar_id":"","url":"https://api.github.com/users/dsharletg","html_url":"https://github.com/dsharletg","followers_url":"https://api.github.com/users/dsharletg/followers","following_url":"https://api.github.com/users/dsharletg/following{/other_user}","gists_url":"https://api.github.com/users/dsharletg/gists{/gist_id}","starred_url":"https://api.github.com/users/dsharletg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dsharletg/subscriptions","organizations_url":"https://api.github.com/users/dsharletg/orgs","repos_url":"https://api.github.com/users/dsharletg/repos","events_url":"https://api.github.com/users/dsharletg/events{/privacy}","received_events_url":"https://api.github.com/users/dsharletg/received_events","type":"User","site_admin":false},"body":"I think it's a bit easier to keep it where it is. While it's a syscall, so are the ioctl calls, of which are there are several, so it doesn't reduce overhead much (even ignoring non-syscall overhead).\r\n\r\nI'm also a bit worried about thread safety and such by lifting this out of the malloc call. I think this implementation is simplest and safest.","created_at":"2016-07-09T01:04:54Z","updated_at":"2016-07-09T01:04:54Z","html_url":"https://github.com/halide/Halide/pull/1369#discussion_r70159228","pull_request_url":"https://api.github.com/repos/halide/Halide/pulls/1369","_links":{"self":{"href":"https://api.github.com/repos/halide/Halide/pulls/comments/70159228"},"html":{"href":"https://github.com/halide/Halide/pull/1369#discussion_r70159228"},"pull_request":{"href":"https://api.github.com/repos/halide/Halide/pulls/1369"}}},"pull_request":{"url":"https://api.github.com/repos/halide/Halide/pulls/1369","id":76827946,"html_url":"https://github.com/halide/Halide/pull/1369","diff_url":"https://github.com/halide/Halide/pull/1369.diff","patch_url":"https://github.com/halide/Halide/pull/1369.patch","issue_url":"https://api.github.com/repos/halide/Halide/issues/1369","number":1369,"state":"open","locked":false,"title":"Fastrpc fixes","user":{"login":"dsharletg","id":7494796,"avatar_url":"https://avatars.githubusercontent.com/u/7494796?v=3","gravatar_id":"","url":"https://api.github.com/users/dsharletg","html_url":"https://github.com/dsharletg","followers_url":"https://api.github.com/users/dsharletg/followers","following_url":"https://api.github.com/users/dsharletg/following{/other_user}","gists_url":"https://api.github.com/users/dsharletg/gists{/gist_id}","starred_url":"https://api.github.com/users/dsharletg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dsharletg/subscriptions","organizations_url":"https://api.github.com/users/dsharletg/orgs","repos_url":"https://api.github.com/users/dsharletg/repos","events_url":"https://api.github.com/users/dsharletg/events{/privacy}","received_events_url":"https://api.github.com/users/dsharletg/received_events","type":"User","site_admin":false},"body":"This PR is ready again... it changes the following:\r\n\r\n- Remove the dependency on rpcmem_android.c in the Hexagon SDK\r\n- Remove non-zero returning function get_symbol from the RPC interface\r\n- Try to link statically with the C++/GCC runtimes, to avoid versioning issues\r\n- Remove some unused libraries from the Makefile\r\n\r\n","created_at":"2016-07-08T23:25:21Z","updated_at":"2016-07-09T01:04:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d2133ebf2f8795a1e27c7c988c53e787e1c9837b","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/halide/Halide/pulls/1369/commits","review_comments_url":"https://api.github.com/repos/halide/Halide/pulls/1369/comments","review_comment_url":"https://api.github.com/repos/halide/Halide/pulls/comments{/number}","comments_url":"https://api.github.com/repos/halide/Halide/issues/1369/comments","statuses_url":"https://api.github.com/repos/halide/Halide/statuses/c7574e0a88b97be4ef95434e9178237201a6e6c1","head":{"label":"halide:fastrpc-fixes","ref":"fastrpc-fixes","sha":"c7574e0a88b97be4ef95434e9178237201a6e6c1","user":{"login":"halide","id":1548551,"avatar_url":"https://avatars.githubusercontent.com/u/1548551?v=3","gravatar_id":"","url":"https://api.github.com/users/halide","html_url":"https://github.com/halide","followers_url":"https://api.github.com/users/halide/followers","following_url":"https://api.github.com/users/halide/following{/other_user}","gists_url":"https://api.github.com/users/halide/gists{/gist_id}","starred_url":"https://api.github.com/users/halide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/halide/subscriptions","organizations_url":"https://api.github.com/users/halide/orgs","repos_url":"https://api.github.com/users/halide/repos","events_url":"https://api.github.com/users/halide/events{/privacy}","received_events_url":"https://api.github.com/users/halide/received_events","type":"Organization","site_admin":false},"repo":{"id":5241312,"name":"Halide","full_name":"halide/Halide","owner":{"login":"halide","id":1548551,"avatar_url":"https://avatars.githubusercontent.com/u/1548551?v=3","gravatar_id":"","url":"https://api.github.com/users/halide","html_url":"https://github.com/halide","followers_url":"https://api.github.com/users/halide/followers","following_url":"https://api.github.com/users/halide/following{/other_user}","gists_url":"https://api.github.com/users/halide/gists{/gist_id}","starred_url":"https://api.github.com/users/halide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/halide/subscriptions","organizations_url":"https://api.github.com/users/halide/orgs","repos_url":"https://api.github.com/users/halide/repos","events_url":"https://api.github.com/users/halide/events{/privacy}","received_events_url":"https://api.github.com/users/halide/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/halide/Halide","description":"a language for image processing and computational photography","fork":false,"url":"https://api.github.com/repos/halide/Halide","forks_url":"https://api.github.com/repos/halide/Halide/forks","keys_url":"https://api.github.com/repos/halide/Halide/keys{/key_id}","collaborators_url":"https://api.github.com/repos/halide/Halide/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/halide/Halide/teams","hooks_url":"https://api.github.com/repos/halide/Halide/hooks","issue_events_url":"https://api.github.com/repos/halide/Halide/issues/events{/number}","events_url":"https://api.github.com/repos/halide/Halide/events","assignees_url":"https://api.github.com/repos/halide/Halide/assignees{/user}","branches_url":"https://api.github.com/repos/halide/Halide/branches{/branch}","tags_url":"https://api.github.com/repos/halide/Halide/tags","blobs_url":"https://api.github.com/repos/halide/Halide/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/halide/Halide/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/halide/Halide/git/refs{/sha}","trees_url":"https://api.github.com/repos/halide/Halide/git/trees{/sha}","statuses_url":"https://api.github.com/repos/halide/Halide/statuses/{sha}","languages_url":"https://api.github.com/repos/halide/Halide/languages","stargazers_url":"https://api.github.com/repos/halide/Halide/stargazers","contributors_url":"https://api.github.com/repos/halide/Halide/contributors","subscribers_url":"https://api.github.com/repos/halide/Halide/subscribers","subscription_url":"https://api.github.com/repos/halide/Halide/subscription","commits_url":"https://api.github.com/repos/halide/Halide/commits{/sha}","git_commits_url":"https://api.github.com/repos/halide/Halide/git/commits{/sha}","comments_url":"https://api.github.com/repos/halide/Halide/comments{/number}","issue_comment_url":"https://api.github.com/repos/halide/Halide/issues/comments{/number}","contents_url":"https://api.github.com/repos/halide/Halide/contents/{+path}","compare_url":"https://api.github.com/repos/halide/Halide/compare/{base}...{head}","merges_url":"https://api.github.com/repos/halide/Halide/merges","archive_url":"https://api.github.com/repos/halide/Halide/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/halide/Halide/downloads","issues_url":"https://api.github.com/repos/halide/Halide/issues{/number}","pulls_url":"https://api.github.com/repos/halide/Halide/pulls{/number}","milestones_url":"https://api.github.com/repos/halide/Halide/milestones{/number}","notifications_url":"https://api.github.com/repos/halide/Halide/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/halide/Halide/labels{/name}","releases_url":"https://api.github.com/repos/halide/Halide/releases{/id}","deployments_url":"https://api.github.com/repos/halide/Halide/deployments","created_at":"2012-07-31T04:05:25Z","updated_at":"2016-07-08T08:52:41Z","pushed_at":"2016-07-09T00:52:29Z","git_url":"git://github.com/halide/Halide.git","ssh_url":"git@github.com:halide/Halide.git","clone_url":"https://github.com/halide/Halide.git","svn_url":"https://github.com/halide/Halide","homepage":"http://halide-lang.org","size":270444,"stargazers_count":1335,"watchers_count":1335,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":270,"mirror_url":null,"open_issues_count":200,"forks":270,"open_issues":200,"watchers":1335,"default_branch":"master"}},"base":{"label":"halide:master","ref":"master","sha":"357b95b2a30736e7c20286cee03189fd03e50bf6","user":{"login":"halide","id":1548551,"avatar_url":"https://avatars.githubusercontent.com/u/1548551?v=3","gravatar_id":"","url":"https://api.github.com/users/halide","html_url":"https://github.com/halide","followers_url":"https://api.github.com/users/halide/followers","following_url":"https://api.github.com/users/halide/following{/other_user}","gists_url":"https://api.github.com/users/halide/gists{/gist_id}","starred_url":"https://api.github.com/users/halide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/halide/subscriptions","organizations_url":"https://api.github.com/users/halide/orgs","repos_url":"https://api.github.com/users/halide/repos","events_url":"https://api.github.com/users/halide/events{/privacy}","received_events_url":"https://api.github.com/users/halide/received_events","type":"Organization","site_admin":false},"repo":{"id":5241312,"name":"Halide","full_name":"halide/Halide","owner":{"login":"halide","id":1548551,"avatar_url":"https://avatars.githubusercontent.com/u/1548551?v=3","gravatar_id":"","url":"https://api.github.com/users/halide","html_url":"https://github.com/halide","followers_url":"https://api.github.com/users/halide/followers","following_url":"https://api.github.com/users/halide/following{/other_user}","gists_url":"https://api.github.com/users/halide/gists{/gist_id}","starred_url":"https://api.github.com/users/halide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/halide/subscriptions","organizations_url":"https://api.github.com/users/halide/orgs","repos_url":"https://api.github.com/users/halide/repos","events_url":"https://api.github.com/users/halide/events{/privacy}","received_events_url":"https://api.github.com/users/halide/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/halide/Halide","description":"a language for image processing and computational photography","fork":false,"url":"https://api.github.com/repos/halide/Halide","forks_url":"https://api.github.com/repos/halide/Halide/forks","keys_url":"https://api.github.com/repos/halide/Halide/keys{/key_id}","collaborators_url":"https://api.github.com/repos/halide/Halide/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/halide/Halide/teams","hooks_url":"https://api.github.com/repos/halide/Halide/hooks","issue_events_url":"https://api.github.com/repos/halide/Halide/issues/events{/number}","events_url":"https://api.github.com/repos/halide/Halide/events","assignees_url":"https://api.github.com/repos/halide/Halide/assignees{/user}","branches_url":"https://api.github.com/repos/halide/Halide/branches{/branch}","tags_url":"https://api.github.com/repos/halide/Halide/tags","blobs_url":"https://api.github.com/repos/halide/Halide/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/halide/Halide/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/halide/Halide/git/refs{/sha}","trees_url":"https://api.github.com/repos/halide/Halide/git/trees{/sha}","statuses_url":"https://api.github.com/repos/halide/Halide/statuses/{sha}","languages_url":"https://api.github.com/repos/halide/Halide/languages","stargazers_url":"https://api.github.com/repos/halide/Halide/stargazers","contributors_url":"https://api.github.com/repos/halide/Halide/contributors","subscribers_url":"https://api.github.com/repos/halide/Halide/subscribers","subscription_url":"https://api.github.com/repos/halide/Halide/subscription","commits_url":"https://api.github.com/repos/halide/Halide/commits{/sha}","git_commits_url":"https://api.github.com/repos/halide/Halide/git/commits{/sha}","comments_url":"https://api.github.com/repos/halide/Halide/comments{/number}","issue_comment_url":"https://api.github.com/repos/halide/Halide/issues/comments{/number}","contents_url":"https://api.github.com/repos/halide/Halide/contents/{+path}","compare_url":"https://api.github.com/repos/halide/Halide/compare/{base}...{head}","merges_url":"https://api.github.com/repos/halide/Halide/merges","archive_url":"https://api.github.com/repos/halide/Halide/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/halide/Halide/downloads","issues_url":"https://api.github.com/repos/halide/Halide/issues{/number}","pulls_url":"https://api.github.com/repos/halide/Halide/pulls{/number}","milestones_url":"https://api.github.com/repos/halide/Halide/milestones{/number}","notifications_url":"https://api.github.com/repos/halide/Halide/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/halide/Halide/labels{/name}","releases_url":"https://api.github.com/repos/halide/Halide/releases{/id}","deployments_url":"https://api.github.com/repos/halide/Halide/deployments","created_at":"2012-07-31T04:05:25Z","updated_at":"2016-07-08T08:52:41Z","pushed_at":"2016-07-09T00:52:29Z","git_url":"git://github.com/halide/Halide.git","ssh_url":"git@github.com:halide/Halide.git","clone_url":"https://github.com/halide/Halide.git","svn_url":"https://github.com/halide/Halide","homepage":"http://halide-lang.org","size":270444,"stargazers_count":1335,"watchers_count":1335,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":270,"mirror_url":null,"open_issues_count":200,"forks":270,"open_issues":200,"watchers":1335,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/halide/Halide/pulls/1369"},"html":{"href":"https://github.com/halide/Halide/pull/1369"},"issue":{"href":"https://api.github.com/repos/halide/Halide/issues/1369"},"comments":{"href":"https://api.github.com/repos/halide/Halide/issues/1369/comments"},"review_comments":{"href":"https://api.github.com/repos/halide/Halide/pulls/1369/comments"},"review_comment":{"href":"https://api.github.com/repos/halide/Halide/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/halide/Halide/pulls/1369/commits"},"statuses":{"href":"https://api.github.com/repos/halide/Halide/statuses/c7574e0a88b97be4ef95434e9178237201a6e6c1"}}}}
{"actor":{"display_login":"dsharletg"}}