2

Suppose I have the task of summing 1048576 numbers. Suppose I can also ignore the time involved sending those numbers to the GPU (they don't need to - they can be derived from a simple mathematical formula). Is it possible to sum all those numbers in parallel there?

My attempt: I was going to go with an usual parallel reduction, making the texture 1/4 of its size on each pass, so I'd need log(N) passes. The problem I am having is that a texture holds Vec4<byte> values. I am interested in float values! There is an extension to write Vec4<float> values, but it doesn't allow reading them back, and they are still Vec4s!

Does anyone have a solution for that problem? Considering the tricky nature of WebGL, a minimal code demo would be very helpful.

MaiaVictor
  • 51,090
  • 44
  • 144
  • 286

2 Answers2

0

You may use Web Worker for doing your calculation in another thread in parallel.

Please see this for more details:

https://developer.mozilla.org/en-US/docs/Web/Guide/Performance/Using_web_workers

advncd
  • 3,787
  • 1
  • 25
  • 31
0

Are you looking at using WebGL because you need a mobile solution ? There are many limitations in having compute with WebGL. Have you looked at WebCL instead.

If you still want to pursue WebGL, you can take a look at encoding threads like below:

How do I convert a vec4 rgba value to a float?

Community
  • 1
  • 1
Prabindh
  • 3,356
  • 2
  • 23
  • 25
  • WebCL doesn't exist other than as a mostly abandoned spec. Both Firefox and Chrome have shown not just no interest but negative interest in WebCL. – gman Apr 30 '14 at 16:46
  • Well, there are definitely some forums where there is very positive interest :) – Prabindh Apr 30 '14 at 23:13
  • There's lots of interest is making high performance computing available to JavaScript. The issue is providing an API that is safe, performant (async by design), and will run everywhere without having to query a bunch of device specific things to set up the computations. WebCL provides none of this. Hopefully someone will suggest a better API. Maybe CUDA or River Trail or something along those lines. – gman May 01 '14 at 04:10