|
|
 |
Neural Networks and WebGPU Compute..
Learning from Data..... |
|
|
|
 | Slow Compute |  |
Why are single threaded compute shaders bad?
Single threaded compute shaders are NOT bad. You learn about the shader language, architecture and the algorithm. Most professional developers probably learned to program by starting with small sequential implementations first before ramping things up and distributing the workload. As the old saying goes, you should learn to walk before you try to run.
The reason why single threaded compute shaders are frouned on, gives people the idea that the GPU is akin to the CPU. That you can run lots of programs in parallel on single threads. That the GPU has hundreds or thousands of corese - which means you can have hundreds of thousands of threads - each running a different program! WRONG! These cores and threads are designed to run in parallel - so if you run a single threaded program, it's akin to having all of those cores locked and wasted (they can't be used for other tasks).
However, single threaded tasks are great for learning and testing - without the ability to drop down to a slower single threaded model on the GPU makes the learning ride easier.
Single Threaded Compute
This section is about transitioning to working with the neural network on the GPU (using the compute shader). We want to make sure the compute shader version functions correctly (same as the CPU/JavaScript version).
To accomplish this - we'll have the two version run together - so the computational results can be compared.
This becomes important later on as you start to experiment and tweak the compute implementation to make it run faster; compare results with the client side version.
• The CPU version runs and trains the weights
• Check the XOR output is correct (using activate)
• The GPU version uses the trained weights - check it produces the same result as the CPU version
• Generate random weights and train using the GPU version (single thread)
• Check the XOR output is correct (using activateGPU)
 | CPU and GPU Version (Check Each Other) |  |
The output should look something like the following for the following implementation.
|
|