Send Feedback
Skip to content

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:

  1. A GPU-enabled environment with CUDA 13.1. Refer to GPU Setup.
  2. 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.

  1. 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)
    
  2. 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
    
  3. Move a table to the CPU (from device to host):

    q)r~1!`sym xasc .gpu.from R
    1b
    

Next steps