{"action":"created","comment":{"url":"https://api.github.com/repos/halide/Halide/pulls/comments/64498039","id":64498039,"diff_hunk":"@@ -44,15 +95,239 @@ int halide_do_task(void *user_context, halide_task_t f, int idx,\n                    uint8_t *closure) {\n     return f(user_context, idx, closure);\n }\n+void lock_work_queue() {\n+    qurt_mutex_lock(&(work_queue.work_mutex));\n+}\n+void unlock_work_queue() {\n+    qurt_mutex_unlock(&(work_queue.work_mutex));\n+}\n+void goto_work(work *owned_job) {\n+    work myjob;\n+    // You can work only if you get a lock on the work queue.\n+    unsigned int tid = qurt_thread_get_id();\n+    FARF(LOW, \"HVX_TP: %d: goto_work: Trying to get a lock on the work queue\\n\", tid);\n+\n+    // ***********************\n+    // *** Lock work queue ***\n+    // ***********************\n+    lock_work_queue();\n+    FARF(LOW, \"HVX_TP: %d: goto_work: got a lock on the work queue\\n\", tid);\n+\n+    // If I'm a job owner, then I was the thread that called\n+    // do_par_for, and I should only stay in this function while there\n+    // are active workers on the job (i.e. running()) or if the job\n+    // hasn't been claimed entirely (!claimed()). If I'm a lowly worker\n+    // thread, I should stay in this function as long as the work queue is running.\n+    while (owned_job != NULL ? (owned_job->running() || !owned_job->claimed())\n+           : work_queue.running()) {\n+\n+        FARF(LOW, \"HVX_TP: %d: goto_work: In the main goto_work loop \\n\", tid);\n+        int num_jobs = work_queue.num_jobs, job_idx;\n+        work *jobs = work_queue.jobs, *orig_job;\n+        bool job_found = false;\n+        if (!owned_job) {","path":"src/runtime/hexagon_remote/remote.cpp","position":101,"original_position":101,"commit_id":"2195faeb3e3b2456ff93858c3ec35d468ea592ec","original_commit_id":"2195faeb3e3b2456ff93858c3ec35d468ea592ec","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 the control flow here could be simplified if it looked something like this:\r\n\r\n    work *job_to_do = NULL;  // instead of orig_job\r\n    if (!owned_job) {\r\n        // This is a worker thread, try to find a job to to do.\r\n        job_to_do = find_nonempty_job(...);\r\n        if (!job_to_do) {\r\n            // go to sleep\r\n        }\r\n    } else {\r\n        // This is the main thread\r\n        if (owned_job->claimed()) {\r\n            // Go to sleep, wait for the worker thread to wake us up.\r\n        } else {\r\n            // Do some work.\r\n            job_to_do = owned_job;\r\n        }\r\n    }\r\n    // Do some work on job_to_do.\r\n\r\nAfter writing that out, it didn't make as big of a difference as I hoped. I just don't like the redundancy in the \"job exists\" state between job_found and orig_job.\r\n","created_at":"2016-05-25T00:24:08Z","updated_at":"2016-05-25T00:24:08Z","html_url":"https://github.com/halide/Halide/pull/1240#discussion_r64498039","pull_request_url":"https://api.github.com/repos/halide/Halide/pulls/1240","_links":{"self":{"href":"https://api.github.com/repos/halide/Halide/pulls/comments/64498039"},"html":{"href":"https://github.com/halide/Halide/pull/1240#discussion_r64498039"},"pull_request":{"href":"https://api.github.com/repos/halide/Halide/pulls/1240"}}},"pull_request":{"url":"https://api.github.com/repos/halide/Halide/pulls/1240","id":71303092,"html_url":"https://github.com/halide/Halide/pull/1240","diff_url":"https://github.com/halide/Halide/pull/1240.diff","patch_url":"https://github.com/halide/Halide/pull/1240.patch","issue_url":"https://api.github.com/repos/halide/Halide/issues/1240","number":1240,"state":"open","locked":false,"title":"Qurt thread pool hexagon2","user":{"login":"pranavb-ca","id":16598810,"avatar_url":"https://avatars.githubusercontent.com/u/16598810?v=3","gravatar_id":"","url":"https://api.github.com/users/pranavb-ca","html_url":"https://github.com/pranavb-ca","followers_url":"https://api.github.com/users/pranavb-ca/followers","following_url":"https://api.github.com/users/pranavb-ca/following{/other_user}","gists_url":"https://api.github.com/users/pranavb-ca/gists{/gist_id}","starred_url":"https://api.github.com/users/pranavb-ca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pranavb-ca/subscriptions","organizations_url":"https://api.github.com/users/pranavb-ca/orgs","repos_url":"https://api.github.com/users/pranavb-ca/repos","events_url":"https://api.github.com/users/pranavb-ca/events{/privacy}","received_events_url":"https://api.github.com/users/pranavb-ca/received_events","type":"User","site_admin":false},"body":"This is still WIP, but the main body (or more than a major chunk) of the work has been done. Some notes about the implementation\r\n\r\n1. This work has been done entirely in remote.cpp - This implies that the thread pool is currently supported only for the hexagon-offload model on hardware (No simulator).\r\n2. Presently, HVX with parallel fails, i.e to say f.hexagon().vectorize(x, 64).parallel(y, 16) will fail. However, f.hexagon().parallel(y, 16) should result in the creation of a QuRT thread pool of 3 threads (4 including the master thread). I call this the scalar-parallel model and I have tested it on HelloHexagon and it works in both, 64 and 128 byte modes.\r\n3. There are a wide range of FARF log statements, they will be reduced soon.\r\n4. Todo: The work queue has been implemented as a linear array of jobs as opposed to a stack. Therefore the worker threads take linear time to remove work from the queue. I do want to implement this work queue to have an array implementation of a stack so that the top of the stack can be accessed as the job to work on by the worker threads. I'll work on this after I have HVX-parallel pipelines working.\r\n\r\n@dsharletg @ronlieb @dpalermo @abadams : Please take a look\r\n","created_at":"2016-05-24T22:24:27Z","updated_at":"2016-05-25T00:24:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a5b95d7f9dcfbc65de25bd2541bcf4da96b2a537","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/halide/Halide/pulls/1240/commits","review_comments_url":"https://api.github.com/repos/halide/Halide/pulls/1240/comments","review_comment_url":"https://api.github.com/repos/halide/Halide/pulls/comments{/number}","comments_url":"https://api.github.com/repos/halide/Halide/issues/1240/comments","statuses_url":"https://api.github.com/repos/halide/Halide/statuses/2195faeb3e3b2456ff93858c3ec35d468ea592ec","head":{"label":"halide:qurt_thread_pool_hexagon2","ref":"qurt_thread_pool_hexagon2","sha":"2195faeb3e3b2456ff93858c3ec35d468ea592ec","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-05-23T10:25:45Z","pushed_at":"2016-05-25T00:18:35Z","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":264349,"stargazers_count":1292,"watchers_count":1292,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":258,"mirror_url":null,"open_issues_count":185,"forks":258,"open_issues":185,"watchers":1292,"default_branch":"master"}},"base":{"label":"halide:hexagon2","ref":"hexagon2","sha":"4dd1a420cc551dba3475c02d57ef601adddd27be","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-05-23T10:25:45Z","pushed_at":"2016-05-25T00:18:35Z","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":264349,"stargazers_count":1292,"watchers_count":1292,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":258,"mirror_url":null,"open_issues_count":185,"forks":258,"open_issues":185,"watchers":1292,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/halide/Halide/pulls/1240"},"html":{"href":"https://github.com/halide/Halide/pull/1240"},"issue":{"href":"https://api.github.com/repos/halide/Halide/issues/1240"},"comments":{"href":"https://api.github.com/repos/halide/Halide/issues/1240/comments"},"review_comments":{"href":"https://api.github.com/repos/halide/Halide/pulls/1240/comments"},"review_comment":{"href":"https://api.github.com/repos/halide/Halide/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/halide/Halide/pulls/1240/commits"},"statuses":{"href":"https://api.github.com/repos/halide/Halide/statuses/2195faeb3e3b2456ff93858c3ec35d468ea592ec"}}}}
{"actor":{"display_login":"dsharletg"}}