{"action":"created","issue":{"url":"https://api.github.com/repos/BVLC/caffe/issues/4421","repository_url":"https://api.github.com/repos/BVLC/caffe","labels_url":"https://api.github.com/repos/BVLC/caffe/issues/4421/labels{/name}","comments_url":"https://api.github.com/repos/BVLC/caffe/issues/4421/comments","events_url":"https://api.github.com/repos/BVLC/caffe/issues/4421/events","html_url":"https://github.com/BVLC/caffe/pull/4421","id":163990709,"number":4421,"title":"Introduce a virtual buffer pointer mapping mechanism for OCL memory obj","user":{"login":"gongzg","id":782918,"avatar_url":"https://avatars.githubusercontent.com/u/782918?v=3","gravatar_id":"","url":"https://api.github.com/users/gongzg","html_url":"https://github.com/gongzg","followers_url":"https://api.github.com/users/gongzg/followers","following_url":"https://api.github.com/users/gongzg/following{/other_user}","gists_url":"https://api.github.com/users/gongzg/gists{/gist_id}","starred_url":"https://api.github.com/users/gongzg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gongzg/subscriptions","organizations_url":"https://api.github.com/users/gongzg/orgs","repos_url":"https://api.github.com/users/gongzg/repos","events_url":"https://api.github.com/users/gongzg/events{/privacy}","received_events_url":"https://api.github.com/users/gongzg/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/BVLC/caffe/labels/enhancement","name":"enhancement","color":"c7def8"},{"url":"https://api.github.com/repos/BVLC/caffe/labels/OpenCL","name":"OpenCL","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":16,"created_at":"2016-07-06T03:20:31Z","updated_at":"2016-07-25T11:34:19Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/BVLC/caffe/pulls/4421","html_url":"https://github.com/BVLC/caffe/pull/4421","diff_url":"https://github.com/BVLC/caffe/pull/4421.diff","patch_url":"https://github.com/BVLC/caffe/pull/4421.patch"},"body":"We introduce a virtual buffer pointer mapping mechanism here to unify the\r\nCUDA code path and OCL code path into one style. Thus we can remove a lot\r\nof duplicate code in the layers implementations."},"comment":{"url":"https://api.github.com/repos/BVLC/caffe/issues/comments/234929510","html_url":"https://github.com/BVLC/caffe/pull/4421#issuecomment-234929510","issue_url":"https://api.github.com/repos/BVLC/caffe/issues/4421","id":234929510,"user":{"login":"wujunkai166","id":7006043,"avatar_url":"https://avatars.githubusercontent.com/u/7006043?v=3","gravatar_id":"","url":"https://api.github.com/users/wujunkai166","html_url":"https://github.com/wujunkai166","followers_url":"https://api.github.com/users/wujunkai166/followers","following_url":"https://api.github.com/users/wujunkai166/following{/other_user}","gists_url":"https://api.github.com/users/wujunkai166/gists{/gist_id}","starred_url":"https://api.github.com/users/wujunkai166/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wujunkai166/subscriptions","organizations_url":"https://api.github.com/users/wujunkai166/orgs","repos_url":"https://api.github.com/users/wujunkai166/repos","events_url":"https://api.github.com/users/wujunkai166/events{/privacy}","received_events_url":"https://api.github.com/users/wujunkai166/received_events","type":"User","site_admin":false},"created_at":"2016-07-25T11:34:19Z","updated_at":"2016-07-25T11:34:19Z","body":"@CNugteren @bhack @naibaf7 @gongzg \r\nThe work described in this PR is to utilize an additional data structure (ClState) to map the tuples with types: (cl_mem obj, int obj_buffer_size) to a pointer allocated in a virtual address. The data structure stores all these maps for future usage. Basically, when OpenCL path is chosen in caffe, every time the program calls function A->gpu_data(), it will return a virtual address which is mapped to (cl_mem mem_A, int sizeA). \r\n\r\nThe motivation of this work is that we found a lot of places in caffe need to apply an offset to a base address allocated by calling gpu_data() function and pass it as a parameter to other functions. In CUDA, device memory is allocated and returned in a pointer which points to a basic type (float, double, etc.), so it can easily do the arithmetic operations to get the offset address. However, in OpenCL, calling gpu_data() will return a pointer which points to a memory object, so the arithmetic operations on the pointer will get an incorrect result. That's why we can observe a lot of places with following code patterns:\r\n\r\n#ifdef USE_CUDA\r\n      func(..., A + offset, ...);\r\n#ifdef USE_GREENTEA\r\n      func(..., A, offset, ...);\r\n\r\nThe purpose of the work in this PR is to eliminate this kind of difference to make the code with OpenCL version more clean compared with CUDA version. By utilizing the data structure described above, the two version code path can be merged into only one statement:\r\n     func(..., A + offset, ...);\r\n\r\nHere, in OpenCL version, (A + offset) is a virtual address and it will be decoded into (cl_mem mem_A, int offset) inside func().\r\n\r\nTherfore, this work can make the code more clean and reduce a lot of code differences between Opencl and CUDA version. Moreover, the original CUDA path code won't be changed. It's a little different with some of the work described in above comments. We aim at reducing the difference between CUDA and OpenCL implementation in caffe under the condition that the original CUDA path code won't be changed. "}}
{"actor":{"display_login":"wujunkai166"}}