-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[OpenGL] Basic OpenGL backend #492 #495
Conversation
I could't wait to share you more about the work! |
Great! I have one small suggestion (which will make PR/code maintenance much easier): keep each PR small. This will also make your life easier since you have fewer conflicts and get quicker reviews. The PR process of the Metal backend #396 is a great example. I'm super excited to witness the birth of a new backend! At the same time, we should also pay more attention to code maintainability, as we are getting more and more backends :-) Maybe we should consider extracting the common parts of the OpenGL and Metal (and potentially OpenCL in the future) codegen into a base class. |
I can share some experiences when working on the Metal one, or any other big features. I think it’s better to have a working solution in your local repo before opening PRs. The local solution doesn’t have to be clean or anything, just a proof of concept. Then we can start breaking down the solution into smaller PRs, possibly doing some cleanups during this process. This way you can save a lot of the reviewer’s bandwidth :-) We also don’t run into the risk that, in case there is a major design flaw, the main codebase gets polluted by incomplete solutions. |
Yeah, I strongly agree on this two-stage strategy: writing a new backend inevitably has a lot of uncertainty, so it's great to have a minimal working prototype (e.g. one that runs As @k-ye said, doing so allows you to get quick design feedback and thereby minimizes the risk of high-level design errors. It also minimizes the number of hours you spend before you get a working codegen & demos (and everybody gets super excited so you get more helping hands). Last but not least, following this strategy makes the reviewer's job much easier :-) |
Thank for your advises! Managed to use |
How to deal with globals? How can I get raw data from snodes? I can pass in/out data to/from GL now. |
You probably want to tell me here, so I'll see it tomorrow. Good night~~ |
We need to allocate something like a pixel buffer (or something related, my OpenGL knowledge is rusty), which we use as a byte array to store the global data structure :-) |
It will be great if we can do compute shader on WebGL, but my read is that it might take a couple more years for WebGL compute shader to become mature :-) For example, it's still not yet supported by default in my browser. |
I need a deeper understand of snode now. When we say
|
Yes, it will be allocated the first time one kernel is called, or when you access the data structure in Python scope (e.g.
The struct compiler does allocation: taichi/taichi/backends/struct_llvm.cpp Line 292 in 46490e7
The |
I also noticed that
Oh, I almost forget that! taichi/taichi/backends/struct_llvm.cpp Line 300 in 46490e7
Seems you have a memory pool there working for LLVM backend? Maybe GL backend can use it later too, as lone as it doesn't use CUDA API. |
Yeah, you'll have to launch a compute shader task for single element accesses like these. A more efficient way is to use numpy interfaces
The memory pool stuff relies on unified memory (which to my knowledge is not supported by OpenGL), so I would suggest starting with just dense snodes, whose storage can be directly pre-allocated. |
|
Memory allocate done. Next event is to figure out how |
[skip ci] test inout data[3] success [skip ci] try to pass kernel arguments
We're making history! After this and stage 2: |
Ok! Will fix the bug tomorrow. Check |
…GL only supports i32, f32, f64)
TODO: genType atan(genType y, genType x);
genType atan(genType y_over_x); |
I simply skipped OpenGL from |
I saw that you requested a review. If you think this is ready, as suggested before, could you break this down into smaller PRs? Otherwise it's very hard for reviewing.. You may need to create new branches and open new PRs, whereas |
Yes, I will, after everything done. But the actual reason why I requested you for review is, I'm afraid my changes in test_types.py could broke yours. |
ALL TESTS PASSED!!! |
Ha thanks. Don't worry too much until it actually gets merged... And I think it's fine not to worry too much about breaking the metal backend. After all, it's hard to test the code if you don't even have a way to run it.. |
Break down into fragments, closing here. |
Related issue id = #492