{"action":"created","issue":{"url":"https://api.github.com/repos/mperrin/poppy/issues/250","repository_url":"https://api.github.com/repos/mperrin/poppy","labels_url":"https://api.github.com/repos/mperrin/poppy/issues/250/labels{/name}","comments_url":"https://api.github.com/repos/mperrin/poppy/issues/250/comments","events_url":"https://api.github.com/repos/mperrin/poppy/issues/250/events","html_url":"https://github.com/mperrin/poppy/pull/250","id":323415938,"number":250,"title":"Unified GPU framework using either CUDA or OpenCL","user":{"login":"mperrin","id":1151745,"avatar_url":"https://avatars0.githubusercontent.com/u/1151745?v=4","gravatar_id":"","url":"https://api.github.com/users/mperrin","html_url":"https://github.com/mperrin","followers_url":"https://api.github.com/users/mperrin/followers","following_url":"https://api.github.com/users/mperrin/following{/other_user}","gists_url":"https://api.github.com/users/mperrin/gists{/gist_id}","starred_url":"https://api.github.com/users/mperrin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mperrin/subscriptions","organizations_url":"https://api.github.com/users/mperrin/orgs","repos_url":"https://api.github.com/users/mperrin/repos","events_url":"https://api.github.com/users/mperrin/events{/privacy}","received_events_url":"https://api.github.com/users/mperrin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-05-15T23:14:02Z","updated_at":"2018-05-16T15:57:07Z","closed_at":null,"author_association":"OWNER","pull_request":{"url":"https://api.github.com/repos/mperrin/poppy/pulls/250","html_url":"https://github.com/mperrin/poppy/pull/250","diff_url":"https://github.com/mperrin/poppy/pull/250.diff","patch_url":"https://github.com/mperrin/poppy/pull/250.patch"},"body":"This branch both adds support for OpenCL and refactors the CUDA implementation somewhat. \r\n\r\n- Essentially all GPU and FFTW related functionality is now relocated into `accel_math.py`, inside wrapper functions, in particular one called `fft_2d`. This allows the algorithmic code in the other files to be written without having to concern itself with _how_ a given FFT is implemented. In principle this extends and generales the `_fft` and `_inv_fft` methods on the FresnelWavefront class (which in fact just become stubs that pass through to `accel_math.fft_2d`. This change involved refactoring key algorithmic parts of both `fresnel.py` and `poppy_core.py`. \r\n- OpenCL-based implementation of GPU accelerated FFTs added.  Dependencies are pyopencl, conda, gpyfft. The first two can be installed from conda-forge. The latter is in a user contributed conda package, so use ` conda install -c ljbo3 gpyfft`. A new setting `poppy.conf.use_cuda` allows enabling or disabling this code, on machines with OpenCL-compatible GPUs. \r\n- Work in progress partial implementation of toggling between single and double precision floating point math, controlled by a new setting `poppy.conf.double_precision` which defaults to True. Many things work in single precision mode but currently many test cases fail, presumably since they're not smart enough to adjust tolerances appropriately. Best to ignore this setting for now for most purposes. \r\n\r\nAll tests pass locally for me, using any combo of plain numpy, numexpr+fftw, CUDA, or OpenCL. On the other hand this starts to get very machine-dependent in test setups so further testing is much appreciated.\r\n\r\nSome areas for future work before merging this:\r\n\r\n1. In refactoring the CUDA functionality out of the FresnelWavefront class, that lost the ability to cache CUDA FFT plans as part of FresnelWavefront objects. I tried caching them as a module-level variable in `accel_math.py`, but for unclear reasons doing so led to a memory leak on the GPU (buffers not being freed somehow?), which eventually led to calculations totally failing due to inability to malloc new buffers on the GPU. I couldn't debug where the leak was, but simply _not_ caching the plans avoids it entirely. The time to create a new CUDA FFT plan each time appears < 1 ms, so it's not zero but is relatively negligible. I'm not totally happy with this but reliability comes first. \r\n2. The single precision stuff is all use-at-your-own-risk. Needs more debugging and attention tothe unit test tolerances.\r\n3. Needs docs! \r\n4. Travis doesn't support CI for GPUs, so all the meaningful testing for this will need to be run locally. Need to investigate the available CUDA compute servers at STScI. \r\n5. Benchmark functions would be nice to include. Probably a few relevant cases, perhaps (1) bare FFT (2) coronagraphic multi-plane OpticalSystem calc in Fraunhofer regime (3) Fresnel multi-plane calc.  \r\n"},"comment":{"url":"https://api.github.com/repos/mperrin/poppy/issues/comments/389571634","html_url":"https://github.com/mperrin/poppy/pull/250#issuecomment-389571634","issue_url":"https://api.github.com/repos/mperrin/poppy/issues/250","id":389571634,"user":{"login":"mperrin","id":1151745,"avatar_url":"https://avatars0.githubusercontent.com/u/1151745?v=4","gravatar_id":"","url":"https://api.github.com/users/mperrin","html_url":"https://github.com/mperrin","followers_url":"https://api.github.com/users/mperrin/followers","following_url":"https://api.github.com/users/mperrin/following{/other_user}","gists_url":"https://api.github.com/users/mperrin/gists{/gist_id}","starred_url":"https://api.github.com/users/mperrin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mperrin/subscriptions","organizations_url":"https://api.github.com/users/mperrin/orgs","repos_url":"https://api.github.com/users/mperrin/repos","events_url":"https://api.github.com/users/mperrin/events{/privacy}","received_events_url":"https://api.github.com/users/mperrin/received_events","type":"User","site_admin":false},"created_at":"2018-05-16T15:57:07Z","updated_at":"2018-05-16T15:57:07Z","author_association":"OWNER","body":"Yeah I realized last night after submitting this that I had accidentally left a bunch of debugging print statements in there unintentionally. Those should mostly just come out entirely. \r\n\r\nI suspect the unnecessary IO is part of what's  causing the slowdowns. "}}
{"actor":{"display_login":"mperrin"}}