-
Notifications
You must be signed in to change notification settings - Fork 7
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
any example showing how to use the wrapper? #2
Comments
This wrapper attempts to mimic the Embree C API closely. So, if you want to figure out how to do something, my goal is for a user to be able to consult the Embree API first. That said, this wrapper is in a prototype stage and hasn't been used or tested thoroughly yet. Here's some code that I'm using currently for raytracing, somewhat out of context:
In this example, I'm shooting some rays from perturbed triangle centroids to other triangles and seeing which rays actually hit their target triangles. In this case, I've loaded an OBJ using another Python library (doesn't really matter which), and then used Embree's API to tell it about the mesh's vertices and faces. If you aren't familiar with Embree, if you consult the Embree API, you'll find that the code above matches what is done in Embree's provided examples. Please let me know if you run into any trouble, and feel free to post code and mesh files here. Please note: the entire API isn't wrapped yet, but should be very easy to wrap more functions. If a function from the Embree API that you need is missing, please say so. You can check embree.pyx to see if a function has been wrapped. |
@sampotter thanks for the prompt response and the example. However, just before we go to code examples I would like to clarify the installation procedure. How someone should install the wrapper? I tried to run |
No problem. Can you tell me a little more about your setup? I see that you're using Windows, which should work in principle, but is less familiar to me. Are you using Anaconda? At this point, I haven't tested this wrapper on Windows, so we'll need to figure out an appropriate workflow for getting it installed. And yes, please post the build output. |
Yes, currently I am on a windows machine. I know that usually with this kind of things in linux is more straight forward. However, in principle someone should be able to install the wrapper on both systems. Anyways back to the point, in my project I am using Pycharm where I have set both a As you correctly figured out I am on a windows 10 machine, with Python 3.8, and I have installed Embree v3 by using the windows installer. This is the output from the build:
|
How did you install Embree? |
Do you think that it might have to do with the Embree installation which is linked against the Visual Studio 2013 (VC12) and Visual Studio 2015/2017 (VC14) runtime? I installed it by using the |
No, your installation doesn't appear to be a problem. It can't find If you want to try debugging this yourself, look for instances of |
Actually it seems that it is not a direct replacement, since the set of input parameters are different. I found this stackoverflow thread https://stackoverflow.com/questions/33696092/whats-the-correct-replacement-for-posix-memalign-in-windows where they discussing the same issue and the provided solution seems to do the trick. |
That's what I was looking at, as well. :-) To provide some context, when using Embree, things that are allocated on the heap need to be aligned appropriately for SIMD. This is explained pretty clearly in the Embree API, which I linked to in my first reply. Regardless of the exact API of the function, what's needed is a malloc that can align allocated memory to the right byte boundary for use with SIMD. |
@sampotter do you think that you could use the C's Based on this https://tianrunhe.wordpress.com/2012/04/23/aligned-malloc-in-c/ it seems that Here are some other reference links: https://cython.readthedocs.io/en/latest/src/tutorial/memory_allocation.html https://github.com/linux-rdma/rdma-core/blob/master/pyverbs/mem_alloc.pyx I couldn't find any way to use calls to I also found the following link which could be usefull: |
Hey @ttsesm, I just pushed a commit that should fix this. I switched from posix_memalign to aligned_alloc on POSIX, and _aligned_malloc on Windows, which has the same API. I was able to compile without any trouble on Windows but haven't tested this. Let me know how this works. |
Hmm, thought I had fixed this, but my changed cause some problems on macOS, which I wasn't able to figure out (in the small amount of time I budgeted for it). I created a new branch off of develop (aligned_allocation) where we can try to figure this out. The latest commit there is working on Mac, but haven't had a chance to try it on Windows or Linux yet. |
Thanks @sampotter, I've managed to make it compile in Windows (I do not have access to a linux machine currently). I had to make the following change though:
in line Line 19 in 802b5f4
Line 803 in 802b5f4
EINVAL was not declared.
|
Thanks for catching that, and glad you were able to get it to compile. If you put together a pull request I'll be happy to accept it. |
@sampotter I had some time to play a bit with the provided code in one of your first responses. However, while embree module is compiled and installed it doesn't seem that I can import it. Any idea what could be the issue? I've compiled and installed it running the following command from the
As you can see, I can find it in my site packages in pycharm: but if I try to import it so that to be able to use it, it doesn't find it. |
@ttsesm Sorry about the delay. Could you be a little more explicit about what's going wrong? It's hard for me to help with so little info. |
@ttsesm Closing this due to lack of activity. |
I also had trouble importhing this package. I've isolated the issue to |
@sampotter I actually get the error:
Any suggestions on how to fix this? |
Very hard to say without more information. Could you provide more information about your setup, what version of Python you have, whether you're using vanilla Python or Anaconda, what version of Embree itself, how you installed it, etc etc |
Hi @sampotter, Setup: Steps to Reproduce:
py setup.py build_ext -I/c/Program\ Files/Intel/Embree3/include -L /c/Program\ Files/Intel/Embree3/lib
py setup.py install
ImportError: DLL load failed while importing embree: The specified module could not be found.
C:\project\.venv\Lib\site-packages\embree-0.0.0-py3.8-win-amd64.egg
│ embree.cp38-win_amd64.pyd
│ embree.py
│
├───EGG-INFO
│ dependency_links.txt
│ native_libs.txt
│ not-zip-safe
│ PKG-INFO
│ SOURCES.txt
│ top_level.txt
│
└───__pycache__
embree.cpython-38.pyc So I open an In [1]: cd C:\project\.venv\Lib\site-packages\embree-0.0.0-py3.8-win-amd64.egg
In [2]: import sys, pkg_resources, importlib.util
In [3]: # In this instance, `__name__` is `__main__`, not `embree`, just fyi
In [4]: __file__ = pkg_resources.resource_filename(__name__, 'embree.cp38-win_amd64.pyd')
In [5]: __file__
Out [5]: 'embree.cp38-win_amd64.pyd'
In [6]: spec = importlib.util.spec_from_file_location(__name__,__file__)
In [7]: spec
Out [7]: ModuleSpec(name='__main__', loader=<_frozen_importlib_external.ExtensionFileLoader object at 0x000002176D5FC7C0>, origin='C:\\project\\.venv\\Lib\\site-packages\\embree-0.0.0-py3.8-win-amd64.egg\\embree.cp38-win_amd64.pyd')
In [8]: mod = importlib.util.module_from_spec(spec)
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
C:\project\.venv\Lib\site-packages\embree-0.0.0-py3.8-win-amd64.egg\embree.cp38-win_amd64.pyd in <module>
C:\Program Files\Python38\lib\importlib\_bootstrap.py in module_from_spec(spec)
C:\Program Files\Python38\lib\importlib\_bootstrap_external.py in create_module(self, spec)
C:\Program Files\Python38\lib\importlib\_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)
ImportError: DLL load failed while importing __main__: The specified module could not be found. |
Hmm, I looked through what you sent, but nothing jumps out at me. Unfortunately, I don't have a Windows machine to test with at the moment, and I don't use Python on Windows very often (if at all). Of course, I would be very happy to get this issue resolved, but I'm going to need to punt and ask you to try to figure this out yourself... If you can determine what the problem is and put it together in a pull request, I'll trust your judgment and happily merge it. Sorry I can't be more help at the moment. |
@sampotter Not to put you on the spot, but you provided Windows install instructions. How did you verify the install works properly on a Windows machine if you don't use Windows? |
I had access to a Windows machine for work over a year ago, but no longer do. At the time, another person who was using this library (probably the OP for this thread) wanted some help, and I happened to have the time to give it a shot. Of course, this is an open source project. If these instructions don't work for you and you find a way to improve them so that they handle a broader set of cases, it would be very helpful to include them. |
@sampotter I see now, that is completely understandable. Thank you for venturing into Windows for us! I think |
Sure, please give it a shot if you have time and I'll be happy to merge any PRs if they seem reasonable. Make sure to @ me when you post so I don't miss anything. |
@adam-grant-hendry Any luck with this? |
@sampotter Not yet. Been busy with the day job. I got Embree2 to compile though. See pyvista #468 |
No problem, and nice job---that's good to know... it will be helpful to let people know there's another option on Windows in case they run into trouble. |
@sampotter I would like to use the embree lib for raycasting since it provides a nice accelerated solution. However, I am not quite sure how to use your wrapper. Would be possible to write a small example showing some use case. For example considering that someone has the indices and faces of a mesh object in numpy arrays how to create the corresponding mesh in embree by using this wrapper?
The text was updated successfully, but these errors were encountered: