diku-dk / futhark

:boom::computer::boom: A data-parallel functional programming language
http://futhark-lang.org
ISC License
2.41k stars 165 forks source link

Access hardware accelerated vector types #1922

Open wstevick opened 1 year ago

wstevick commented 1 year ago

I've heard that GPUs are designed to do operations on glsl vec types quickly. So, adding two vec3s takes less then three times as long as adding two floats. I think that OpenCL floatn types are equivalent, so is there a way to write code that uses those in Futhark code? I want to do some ray tracing, and I want my code to be as fast as possible, because of how computationally intensive ray tracing is.

athas commented 1 year ago

There is currently no way to use those in Futhark. We've been reluctant to support them since they don't exist for all our targets. It's definitely something it would be nice to have, though. It's possible we could make them available through an FFI (once we finally get around to adding that as well).

wstevick commented 1 year ago

You could include vector types, and have the implementation be dependent on the target. So, the vectors could be structs for C, and hardware accelerated vectors for OpenCL. If I understand correctly, that's the same sort of thing as what you did with map and reduce.

athas commented 1 year ago

Yes, but while we already have a mechanism for target-dependent code generation of parallel constructs, we don't have a notion of target-dependent primitive types, so the engineering effort is somewhat larger. The current IR wouldn't even be able to express these types, except as small arrays. It's a design question (even more challenging than an engineering question!) whether that is an appropriate representation. It probably is.

wstevick commented 1 year ago

I don't have experience with Futhark internals, but I do have experience coding. Let me know if there's anything I can do to help.

wstevick commented 1 year ago

That being said, I'd have to learn Haskell, so I can't help soon.