Running a WebGPU-enabled DCP worker on Google Colab

Published:
5 minute read

If you already know what Distributive Compute Protocol (DCP) is, and how it works, skip to the next section.

DCP is a fast, secure, and powerful parallel computing platform built on the web technology. With a handful of lines of code, one can harness the power of a supercomputer without any orchestration.

With DCP, any idle device can join the compute groups. And by “any” I mean ANY device! The only requirement is that they should be able to run a web browser! DCP supports some other platforms, too. Check out more info from the github repos or from the docs page.

Setting up a DCP worker on Google Colab instances

First, if you want to utilize the GPU, make sure there is a GPU attached to the runtime/instance.

!nvidia-smi

+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.104.05             Driver Version: 535.104.05   CUDA Version: 12.2     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  Tesla T4                       Off | 00000000:00:04.0 Off |                    0 |
| N/A   53C    P8              10W /  70W |      0MiB / 15360MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
                                                                                         
+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|  No running processes found                                                           |
+---------------------------------------------------------------------------------------+

Install the necessary packages and update nodejs:

!sudo apt update
!curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - && sudo apt-get install -y nodejs

Then, install dcp-util and create new ids for the dcp worker.

!mkdir ~/.dcp
!npm i -g dcp-util
!npm install --global dcp-util
!mkad new id
!mkad new default
!ls ~/.dcp

To be able to use the GPU, vulkan is needed, too. More info is here.

# For Ubuntu 22.04
!wget -qO- https://packages.lunarg.com/lunarg-signing-key-pub.asc | sudo tee /etc/apt/trusted.gpg.d/lunarg.asc
!sudo wget -qO /etc/apt/sources.list.d/lunarg-vulkan-jammy.list http://packages.lunarg.com/vulkan/lunarg-vulkan-jammy.list
!sudo apt update
!sudo apt install vulkan-sdk

Install dcp-worker and upload and unzip the dcp-native release zip file to the instance.

!npm i dcp-worker
!unzip ./dcp-native-5.0.1-Linux-x64.zip

Now the directory should look like this:

node_modules artifacts

Now, first run the evaluator in the background:

!nohup ./node_modules/dcp-worker/bin/dcp-evaluator-start --port 9004 --evaluator ./artifacts/Release/dcp-evaluator -- --webgpu &

Notice that:

  1. nohup is needed in google colab to send the process to the background. The little & would not be enough.
  2. The --port option has the evaluator listen on that specific port.
  3. The --evaluator option specifies the dcp-native evaluator path.
  4. If you want to pass any option to the dcp-evaluator, they should be passed after --. For examplae enabling WebGPU would be like -- --webgpu.
  5. The output is redirected to nohup.out. You can open it, by double clicking on the file. If the command runs successfully, you should be able to see something similar to this output:
Starting DCP Evaluator -- 
. Evaluator program at:         /content/artifacts/Release/dcp-evaluator
. Listening on:               9004
. Worker environment type:     native
. Worker environment:      
    /content/node_modules/dcp-client/libexec/sandbox/deny-node.js
    /content/node_modules/kvin/kvin.js
    /content/node_modules/dcp-client/libexec/sandbox/sa-ww-simulation.js
    /content/node_modules/dcp-client/libexec/sandbox/script-load-wrapper.js
    /content/node_modules/dcp-client/libexec/sandbox/native-event-loop.js
    /content/node_modules/dcp-client/libexec/sandbox/wrap-event-listeners.js
    /content/node_modules/dcp-client/libexec/sandbox/timer-classes.js
    /content/node_modules/dcp-client/libexec/sandbox/event-loop-virtualization.js
    /content/node_modules/dcp-client/libexec/sandbox/unique-timing.js
    /content/node_modules/dcp-client/libexec/sandbox/worktimes.js
    /content/node_modules/dcp-client/libexec/sandbox/access-lists.js
    /content/node_modules/dcp-client/libexec/sandbox/bravojs-init.js
    /content/node_modules/bravojs/bravo.js
    /content/node_modules/dcp-client/libexec/sandbox/bravojs-env.js
    /content/node_modules/dcp-client/libexec/sandbox/pyodide-core.js
    /content/node_modules/dcp-client/libexec/sandbox/calculate-capabilities.js
    /content/node_modules/dcp-client/libexec/sandbox/bootstrap.js

Running "dcp-evaluator", version 5.0.1.0+60ebd1d...
Listening for connections (press Ctrl+C to quit)...
Listening on port 9000...
Running "dcp-evaluator", version 5.0.1.0+60ebd1d...
Warning: loader_scanned_icd_add: Driver /usr/lib/x86_64-linux-gnu/libvulkan_lvp.so supports Vulkan 1.1, but only supports loader interface version 4. Interface version 5 or newer required to support this version of Vulkan (Policy #LDP_DRIVER_7)
Warning: loader_scanned_icd_add: Driver /usr/lib/x86_64-linux-gnu/libvulkan_radeon.so supports Vulkan 1.2, but only supports loader interface version 4. Interface version 5 or newer required to support this version of Vulkan (Policy #LDP_DRIVER_7)
Warning: loader_scanned_icd_add: Driver /usr/lib/x86_64-linux-gnu/libvulkan_intel.so supports Vulkan 1.2, but only supports loader interface version 4. Interface version 5 or newer required to support this version of Vulkan (Policy #LDP_DRIVER_7)
Warning: loader_icd_scan: Can not find 'ICD' object in ICD JSON file /usr/share/vulkan/icd.d/nvidia_layers.json.  Skipping ICD JSON
WebGPU: obtained device
Evaluating (press Ctrl+C to quit)...

Now, you should run the worker

!./node_modules/dcp-worker/bin/dcp-worker -o console --port 9004

If you want the worker to join a specific compute group, pass the options: -g computeGroupName,computeGroupPass --leavePublicGroup

The output should be similar to this:

! Public Group fallback has been requested, but the public group is blocked by local configuration
 * Starting DCP Worker KoTlJj1fs6ILYut9nIpilT
 . Configured for scheduler https://scheduler.distributed.computer/
 . Bank is https://bank.distributed.computer/
 . Earned funds will be deposited in account 0xaaaaaaa
 . Identity is 0xbbbbbbb
 . Joining compute group brotwurst
 . Falling back on public group when preferred groups have no work
 . Leaving the public compute group
 . Configured Cores: 1,0.75
 . Worktimes Available:
    -    map-basic@1.0.0
    -    pyodide@0.23.2
 . Supervisor version: 2.0.0 . Output mode: console
 * Ready

Now the worker should be able to pick up new job slices.

To understand how to submit jobs, visit here.