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

Add Texture, Sampling Hardware Accerlation and Mutability hints #2380

Open
ifsheldon opened this issue May 29, 2021 · 5 comments
Open

Add Texture, Sampling Hardware Accerlation and Mutability hints #2380

ifsheldon opened this issue May 29, 2021 · 5 comments
Labels
feature request Suggest an idea on this project

Comments

@ifsheldon
Copy link

ifsheldon commented May 29, 2021

Concisely describe the proposed feature
Please consider design APIs for accessing texture memories and utilizing hardware-accelerated samplers.

Describe the solution you'd like (if any)
As far as I know, backends like CUDA and OpenGL have dedicated texture memory handling functions and hardware acceleration for texture fetch and sampling. But now, samplings in taichi_glsl is only soft implementations, I think. So, it will be great if you can add APIs that directly interact with the underlying hardware accelerated backend APIs.

Another related feature request will be hints for immutable data. I remember that in CUDA, there're some nuanced ways to hint cuda compiler that a block of data will not be modified in runtime and thus it can safely put the data in higher read cache hierarchy to speed up. I think you, very likely, have implemented some inferences on what data are mutated and what are not and based on that you have done some read optimizations, but it will be also great if you can give us a way to mark data's mutability to hint for optimizations.

@ifsheldon ifsheldon added the feature request Suggest an idea on this project label May 29, 2021
@ifsheldon ifsheldon changed the title Add Texture and Sampling Hardware Support Add Texture, Sampling Hardware Accerlation and Mutability hints May 29, 2021
@maajor
Copy link
Contributor

maajor commented Jun 2, 2021

+1

Please see this perftest for different type of buffer comparison.

Seems most buffer differ not much, but bilinear interpolation on Texture2D do make a difference. See the benchmark that nearest sample, bilinear sample and load on Texture2D take similar time.

As for mutability, DirectX is the same, you can declare with RW or read-only for example, but I think it need more profiling to tell if there is any difference.

@k-ye
Copy link
Member

k-ye commented Jun 8, 2022

FYI, we are tracking this work in #5109

@ifsheldon
Copy link
Author

Thanks for the update!

How about mutability hints? Do you have any plans of adding them? Mutability hints may be beneficial for both performance and debugging.

@k-ye
Copy link
Member

k-ye commented Jun 8, 2022

I think mutability hints and texture support are two different things, and #5109 is talking about the later :-) But yeah, we could leverage constant memory to pass read-only data. From the mutability perspective, we only intend to support texture sampling (read-only operations) as a start, if that's what you are asking...

@ifsheldon
Copy link
Author

From the mutability perspective, we only intend to support texture sampling (read-only operations) as a start, if that's what you are asking...

Yeah, but not only texture sampling. I mean, generally, if data is asserted to be read-only, some helpful performance optimization and checks can be (more easily) implemented. For example, I remember there're __ldg intrinsics and simple constant pointer hints for CUDA users to hint the NVCC that some data are read-only and accessed with only read operations. Probably you can let Taichi users to hint or assert that a field that is passed to a kernel is read-only so then any write operations to the read-only field is forbidden. This can help users to prevent some read-write bugs and help you Taichi developers to optimize the performance (say, loading read-only data from a field using __ldg when CUDA backend is used, or use constant memory if applicable).

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

No branches or pull requests

3 participants