{"action":"created","comment":{"url":"https://api.github.com/repos/halide/Halide/pulls/comments/98116428","pull_request_review_id":18749694,"id":98116428,"diff_hunk":"@@ -232,21 +232,64 @@ typedef int (*set_runtime_t)(halide_malloc_t user_malloc,\n                              void *(*)(const char *),\n                              void *(*)(void *, const char *));\n \n-int initialize_kernels(const unsigned char *code, int codeLen,\n-                       handle_t *module_ptr) {\n-    elf_t *lib = obj_dlopen_mem(code, codeLen);\n-    if (!lib) {\n-        halide_print(NULL, \"dlopen_mem failed\\n\");\n-        return -1;\n+// This function should be deleted once the hexagon tools impliment the dlopenbuf api.\n+__attribute__((weak))\n+ void* dlopenbuf(const char*filename, const char* data, int size, int perms) {\n+    FILE *f = fopen(filename, \"w+\");\n+    if (!f) {\n+        log_printf(\"Failed to open shared object file %s\\n\", filename);\n+        return NULL;\n     }\n+    ssize_t written = fwrite(data, 1, size, f);\n+    if (written < (ssize_t)size) {\n+        halide_print(NULL, \"Failed to write shared object file\\n\");\n+        return NULL;\n+    }\n+    fclose(f);\n+    return dlopen(filename, perms);\n+}\n \n+static void dllib_init() {\n+    // The simulator needs this call to enable dlopen to work...\n+    const char *builtin[] = {\"libgcc.so\", \"libc.so\", \"libstdc++.so\"};\n+    dlinit(3, const_cast<char**>(builtin));\n+}\n+\n+int initialize_kernels_v2(const unsigned char *code, int codeLen,\n+                          bool use_dlopenbuf,\n+                          handle_t *module_ptr) {\n+\n+    // Keep this false, even for dlbuf usage, as we do not yet have api for dlopenbuf from standalone.\n+    void *lib = NULL;\n+    elf_t *elib = NULL;\n+    if (use_dlopenbuf) {\n+        dllib_init();\n+        lib = dlopenbuf( \"libhalide_hexagon_host_dlbuf.so\", (const char*)code, codeLen, RTLD_LOCAL | RTLD_LAZY);\n+        if (!lib) {\n+            halide_print(NULL, \"dlopenbuf failed\");\n+            return -1;\n+        }\n+    } else {\n+        elib = obj_dlopen_mem(code, codeLen);\n+        if (!elib) {\n+            halide_print(NULL, \"dlopen_mem failed\\n\");\n+            return -1;\n+        }\n+    }\n     // Initialize the runtime. The Hexagon runtime can't call any\n     // system functions (because we can't link them), so we put all\n     // the implementations that need to do so here, and pass poiners\n     // to them in here.\n-    set_runtime_t set_runtime = (set_runtime_t)obj_dlsym(lib, \"halide_noos_set_runtime\");\n+    set_runtime_t set_runtime;\n+    if (use_dlopenbuf)","path":"src/runtime/hexagon_remote/sim_remote.cpp","position":null,"original_position":60,"commit_id":"7c8b9b40eba6394ea93338ddfc79b1114889f5dc","original_commit_id":"7d211c4139f4cd5c49644442bc3005cd6e637cae","user":{"login":"ronlieb","id":16141415,"avatar_url":"https://avatars.githubusercontent.com/u/16141415?v=3","gravatar_id":"","url":"https://api.github.com/users/ronlieb","html_url":"https://github.com/ronlieb","followers_url":"https://api.github.com/users/ronlieb/followers","following_url":"https://api.github.com/users/ronlieb/following{/other_user}","gists_url":"https://api.github.com/users/ronlieb/gists{/gist_id}","starred_url":"https://api.github.com/users/ronlieb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ronlieb/subscriptions","organizations_url":"https://api.github.com/users/ronlieb/orgs","repos_url":"https://api.github.com/users/ronlieb/repos","events_url":"https://api.github.com/users/ronlieb/events{/privacy}","received_events_url":"https://api.github.com/users/ronlieb/received_events","type":"User","site_admin":false},"body":"done","created_at":"2017-01-26T23:26:02Z","updated_at":"2017-01-26T23:26:02Z","html_url":"https://github.com/halide/Halide/pull/1773#discussion_r98116428","pull_request_url":"https://api.github.com/repos/halide/Halide/pulls/1773","_links":{"self":{"href":"https://api.github.com/repos/halide/Halide/pulls/comments/98116428"},"html":{"href":"https://github.com/halide/Halide/pull/1773#discussion_r98116428"},"pull_request":{"href":"https://api.github.com/repos/halide/Halide/pulls/1773"}}},"pull_request":{"url":"https://api.github.com/repos/halide/Halide/pulls/1773","id":102796408,"html_url":"https://github.com/halide/Halide/pull/1773","diff_url":"https://github.com/halide/Halide/pull/1773.diff","patch_url":"https://github.com/halide/Halide/pull/1773.patch","issue_url":"https://api.github.com/repos/halide/Halide/issues/1773","number":1773,"state":"open","locked":false,"title":"Hexagon 8998 dlopenbuf, dlopen support.","user":{"login":"ronlieb","id":16141415,"avatar_url":"https://avatars.githubusercontent.com/u/16141415?v=3","gravatar_id":"","url":"https://api.github.com/users/ronlieb","html_url":"https://github.com/ronlieb","followers_url":"https://api.github.com/users/ronlieb/followers","following_url":"https://api.github.com/users/ronlieb/following{/other_user}","gists_url":"https://api.github.com/users/ronlieb/gists{/gist_id}","starred_url":"https://api.github.com/users/ronlieb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ronlieb/subscriptions","organizations_url":"https://api.github.com/users/ronlieb/orgs","repos_url":"https://api.github.com/users/ronlieb/repos","events_url":"https://api.github.com/users/ronlieb/events{/privacy}","received_events_url":"https://api.github.com/users/ronlieb/received_events","type":"User","site_admin":false},"body":"Added targets HVX_dlopen HVX_dlbuf\r\nPreserves object relocation mode, and its the default.\r\n\r\nsupports all 3 models.","created_at":"2017-01-23T20:42:25Z","updated_at":"2017-01-26T23:26:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3ed04c36139c4bbad4d66af912f9afd753baff29","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/halide/Halide/pulls/1773/commits","review_comments_url":"https://api.github.com/repos/halide/Halide/pulls/1773/comments","review_comment_url":"https://api.github.com/repos/halide/Halide/pulls/comments{/number}","comments_url":"https://api.github.com/repos/halide/Halide/issues/1773/comments","statuses_url":"https://api.github.com/repos/halide/Halide/statuses/7c8b9b40eba6394ea93338ddfc79b1114889f5dc","head":{"label":"halide:hex_dlopen_buf","ref":"hex_dlopen_buf","sha":"7c8b9b40eba6394ea93338ddfc79b1114889f5dc","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":"2017-01-25T00:08:06Z","pushed_at":"2017-01-26T23:24:48Z","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":263826,"stargazers_count":1534,"watchers_count":1534,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":315,"mirror_url":null,"open_issues_count":247,"forks":315,"open_issues":247,"watchers":1534,"default_branch":"master"}},"base":{"label":"halide:master","ref":"master","sha":"4d9975e29b43c95e7424d0df2d7584019919531d","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":"2017-01-25T00:08:06Z","pushed_at":"2017-01-26T23:24:48Z","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":263826,"stargazers_count":1534,"watchers_count":1534,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":315,"mirror_url":null,"open_issues_count":247,"forks":315,"open_issues":247,"watchers":1534,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/halide/Halide/pulls/1773"},"html":{"href":"https://github.com/halide/Halide/pull/1773"},"issue":{"href":"https://api.github.com/repos/halide/Halide/issues/1773"},"comments":{"href":"https://api.github.com/repos/halide/Halide/issues/1773/comments"},"review_comments":{"href":"https://api.github.com/repos/halide/Halide/pulls/1773/comments"},"review_comment":{"href":"https://api.github.com/repos/halide/Halide/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/halide/Halide/pulls/1773/commits"},"statuses":{"href":"https://api.github.com/repos/halide/Halide/statuses/7c8b9b40eba6394ea93338ddfc79b1114889f5dc"}}}}
{"actor":{"display_login":"ronlieb"}}