# Install KDB-X and the GPU Module

_This page explains how to install KDB-X with a GPU-enabled license, download the GPU module, and run the application on a host or in an NVIDIA container._

## Install KDB-X

Install KDB-X using the [KDB-X install guide](..//../../get_started/kdb-x-install.md).

## Download the GPU module

- Retrieve a KDB-X GPU-enabled license and download the GPU module from the [KX downloads portal](https://portal.dl.kx.com/).
- Save the GPU module in `$HOME/.kx/mod/kx`.

> **Note**
>
> These instructions use the default KDB-X installation location `$HOME/.kx`. If you installed KDB-X elsewhere, adjust the code examples to match your location.
>
The folder structure looks similar to:
```bash
~/.kx/mod/kx/
├── ai
├── gpu.li64.so ← (gpu module)
├── kfk
├── kurl
├── objstor
├── pq
└── rest.q_
```

For more information on modules, refer to [modules](..//../module-index.md).

## Run the application

With KDB-X and the GPU module installed, run the application directly on the host or in an NVIDIA container (requires Docker).

### Non-containerized

If you run [directly on the host](gpu-env.md#running-application-on-the-host-non-containerized), install the CUDA Toolkit on the host and ensure the CUDA runtime and shared libraries are available to the application.

Load the KDB-X GPU module and inspect the available APIs:
```bash
q).gpu:use`kx.gpu
q)key .gpu
``ver`to`xto`from`sync`type`count`attr`meta`group`xgroup`ungroup`take`drop`sublist`cntDev`getDev`setDev`memDev`sele..
```

### Containerized app with CUDA dependencies

We recommend using [NVIDIA containers](gpu-env.md#nvidia-containers). To run the app, use the following `Dockerfile` examples (covering `ubuntu24.04` and `rockylinux10` for CUDA `13.1` built apps):

**Ubuntu example**
```bash
FROM nvidia/cuda:13.1.0-runtime-ubuntu24.04

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        curl \
        unzip \
        zip \
        ca-certificates \
        build-essential

RUN mkdir /opt/kx
WORKDIR /opt/kx/app
ENTRYPOINT ["/opt/kx/bin/q"]
```

**Red Hat example**
```bash
FROM nvidia/cuda:13.1.0-runtime-rockylinux10

RUN dnf install -y \
        curl \
        unzip \
        zip \
        ca-certificates \
        gcc \
        gcc-c++ \
        make \
        libubsan && \
    dnf clean all

RUN mkdir /opt/kx
WORKDIR /opt/kx/app
ENTRYPOINT ["/opt/kx/bin/q"]
```

To build the image:
```bash
docker build -f Dockerfile -t kdbx-gpu .
```

To run the image, mount the KDB-X directory to the container, along with any data sources, dependencies, and ports specific to your application:
```bash
docker run --gpus all -it -p 1234:1234 -v /home/mmcphillips/.kx:/opt/kx kdbx-gpu -p 1234
```

Load the KDB-X GPU module and inspect the available APIs as shown in the [Non-containerized](#non-containerized) section.

> **Warning**
>
> Ensure the `--gpus` flag is passed to `docker run`, otherwise, you will see the following error:
>
> ```bash
> 'no kexport: libcuda.so.1: cannot open shared object file: No such file or directory
> ```
