GPU Quickstart
This page shows how to load the GPU module, move data to and from the GPU, and run queries.
Setup
To use the GPU module, you need:
- A GPU-enabled environment with CUDA 13.1. Refer to GPU Setup.
- KDB-X installed with a GPU-enabled license. Refer to KDB-X Setup.
Basic usage
The following example moves a table to the GPU, runs a VWAP, and retrieves the result.
-
Run the following in your KDB-X session to load the module and move a table to the GPU:
q).gpu:use`kx.gpu / load the module q)N:10000000 q)trade:([]time:.z.d+N?0D;sym:N?`3;price:N?1f;size:1+N?100) q)Trade:.gpu.to trade q)Trade +`time`sym`price`size!(foreign;foreign;foreign;foreign) -
Run a VWAP calculation on CPU vs GPU. The times shown are in milliseconds - the GPU is approximately 4.5x faster in this example:
q)\t:100 r:?[trade;();([sym:`sym]);enlist[`vwap]!enlist (%;(sum;(*;`size;`price));(sum;`size))] 4405 q)\t:100 R:.gpu.select[Trade;();([sym:`sym]);enlist[`vwap]!enlist (%;(sum;(*;`size;`price));(sum;`size))] 981 -
Move a table to the CPU (from device to host):
q)r~1!`sym xasc .gpu.from R 1b
Next steps
- Explore the GPU Examples page for more detailed usage.
- Refer to the GPU Reference page for a full API reference.
- Visit the Troubleshooting Errors page if you encounter issues.