Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization of the reflect Function Using OpenCL #217

Open
Kepler618 opened this issue Dec 24, 2024 · 1 comment
Open

Optimization of the reflect Function Using OpenCL #217

Kepler618 opened this issue Dec 24, 2024 · 1 comment

Comments

@Kepler618
Copy link

Hi. While simulating the beam path using the tracing method, I noticed that the reflect function takes considerably more time to compute compared to the expose and propagate functions. I see that diffraction calculations are already parallelized using OpenCL, which is great for accelerating performance on the GPU.

This made me wonder: Could the reflect function also benefit from OpenCL parallelization? If so, I’d appreciate any thoughts or suggestions on how to implement OpenCL for the reflection calculation. Thank you for your guidance!

@yxrmz
Copy link
Collaborator

yxrmz commented Dec 24, 2024

Reflection/diffraction and intersection search have been implemented in OpenCL, but we intentionally use python-based procedures for most cases (except for computationally heavy diffraction in bent crystals, multi-reflect diffraction and multilayers) for three major reasons: 1) Intersection search requires custom OpenCL code for each optical element/surface shape, 2) OpenCL cannot be used with multithreading/multiprocessing, 3) numpy is usually fast enough.
If you want to play with OpenCL-based intersection search, you can uncomment the condition in _reflect_local
If it's really necessary to accelerate regular flat-crystal diffraction calculation, you can modify the conditions for reflect (option 0), basically changing the implementation from numpy to OpenCL
This might be tricky, so be sure to double-check your results.
If you think the performance gain is worth the effort, let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants