waylonflinn / weblas

GPU Powered BLAS for Browsers :gem:
MIT License
702 stars 43 forks source link

mobile with gpu problem #41

Open borablanca opened 7 years ago

borablanca commented 7 years ago

I tried simple matrix multiplications(1x1 with 1x1, 2x2 with 2x2, 1x2 with 2x1...) with weblas.sgemm on Android 7.0 with:

but it is always producing the same number: 4.000000476837158 no matter what the values of the matrixes are (eg: 2x2 with 2x2 produces a 2x2 matrix where all of the 4 numbers are the same number)

It produces correct results on desktop browsers so I suspect :) that it maybe is related with encode_float. What can be the problem?

waylonflinn commented 7 years ago

Are you using pipeline mode? Pipeline mode requires the platform to support rendering to floating point textures. Sadly, this seems almost entirely lacking on mobile at the moment.

Choose your own adventure:

  1. If you are using pipeline mode, here's a stack overflow answer with code that will help you test whether or not this is the problem: WebGL IOS render to floating point texture
  2. If you are not using pipeline mode: report back here and we'll dig into it.
borablanca commented 7 years ago

I am using standalone sgemm (which is the default) i think. Here is my simple code:

var A = new Float32Array([0.1]);
var B = new Float32Array([0.2]);
alert(weblas.sgemm(
  1,
  1,
  1,
  1.0,
  A,
  B,
  0.0,
  null));

Here is a test page I created. If you open in desktop browser, you will see 0.02 which is the correct result. However try to open with an android phone (chrome in my case), it shows 4.00...

waylonflinn commented 7 years ago

Thanks for the test case. On IOS 10 safari (iPhone) the test page gives "0.01999". This must be an Android specific issue. I'll work on getting a test device for debugging this. It may take a while. If you'd like to investigate further and submit a PR instead of waiting, that's very welcome.

If you would like to help with this, your intuition that the problem lies in the float encode seems reasonable. I'd start there. Additionally, the float encode needs to be tested independently and more thoroughly. If you'd like to help with that testing, I would very much appreciate it. See #11 for a start.

borablanca commented 7 years ago

I will try to look into encode, hope I can find the problem.

waylonflinn commented 7 years ago

Don't hesitate to reach out, here or via email, if you need help. I'm also happy to do a video chat with you, if that would help.