Have you dreamed of running your CUDA algorithms directly in your browser or testing your calculation scripts using your PC's GPU without having to struggle with a complex installation? So hold on to your Freegun pants, because HipScript will transform your Chrome into a real high-performance computing station!

Because until now, to exploit the power of NVIDIA graphics cards with CUDA or AMD with HIP, you had to install a whole bunch of SDKs, drivers and other goodies that gave gray hairs to system administrators and to yours truly as well. But thanks to HipScriptthis era is over, finished, closed, tchao bye bye!

To put it simply, CUDA is the API developed by NVIDIA for GPGPU calculation (general calculation on GPU) and in a CUDA code, we find a C++ base common to the CPU and the GPU, which makes it possible to easily share the same structures and the same functions. Kernels are designed to be launched by thousands (or even millions) of threads, organized in “blocks” and “grids”. AMD was quick to respond, creating HIP : a quasi-twin competitor of CUDA, using its vocabulary and syntax in order to benefit from the already existing ecosystem, even if personally, I still find it much worse than CUDA.

Thanks to HipScripteverything (CUDA or HIP) can now be run directly in the browser! The project exploits both WebAssembly And WebGPU to eliminate the tedious installation of drivers or SDKs. If your browser supports WebGPU (for example Chrome, with a few flags activated), you are therefore equipped to test and execute your codes with a simple click.

ywAAAAAAQABAAACAUwAOw==

For those tinkerers who have managed to read this article so far, here are some possible ideas for use:

  • Lightweight cryptocurrency mining : To test your mining algorithms directly in the browser, eh… And not get rich off the backs of visitors to your site.
  • Real-time 3D rendering : To create impressive visualizations for your projects
  • Machine Learning : To experiment with neural networks without installing PyTorch (because it's annoying to install in particular).
  • Steganography & Encryption : To hide data in images with optimized GPU algorithms or do strong encryption.
  • Hash cracking : Or on the contrary for the robustness of your passwords (legally of course!)
  • Video Compression : To encode your videos with custom algorithms

The HipScript magic happens thanks to an intelligent compilation chain. First, your CUDA/HIP code is converted to OpenCL via the compiler chipStar. Then this OpenCL code is transformed into SPIR-V/Vulkan with clspv. Then tint converts the Vulkan shader into a WebGPU (WGSL) shader and finally, everything is encapsulated in WebAssembly to run in the browser. Isn’t that beautiful anyway?

ywAAAAAAQABAAACAUwAOw==

Here is a small example of a CUDA kernel that runs directly in the browser:

cuda __global__ void addVectors(float* a, float* b, float* c, int n) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < n) { c[i] = a[i] + b[i]; } }

Now go to the online demo to test this code and other more advanced examples! Moreover, support for CUDA/HIP features is constantly evolving. For the moment, HipScript already manages the basic syntax for launching kernels, shared memory (static and dynamic), __syncthreadsor even printf for debugging (although some limitations exist on pointers or number types, such as 64-bit floating point).

And HipScript is not yet perfect since only a subset of CUDA/HIP features are supported at the moment. Performance is not yet at native level. And you need a recent browser with WebGPU enabled.

Despite everything, there is fun to be had! On the optimization side, the team showed ingenuity to reduce the size of the tool and manage LLVM compilation in WebAssembly: compression via Brotli to reduce downloads, integration with Wasmer and to Cloudflare R2 to deploy and run the binary efficiently, although some bugs remain to be resolved. But no matter, the result is already stunning: compiling and launching CUDA/HIP code in a simple Chrome tab is a real tour de force!

The source code is available on GitHub for those who would like to tinker or contribute to the project. And who knows, maybe you'll be the first to create a revolutionary web application that harnesses the raw power of the GPU right in the browser?

For more details, visit the blog lights0123as well as on thePhoronix article.


Source link

Categorized in: