# dmlc/dlpack architecture

> Architecture diagram of the GitHub repository dmlc/dlpack, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dmlc/dlpack
- Repository: https://github.com/dmlc/dlpack

## Overview

DLPack is an in-memory tensor interchange format, not a tensor or operator implementation. Its principal workflow is to describe tensor memory in a managed DLPack structure and let another framework consume that memory; the included NumPy adapter demonstrates this with a PyCapsule. The C header defines the shared ABI, while the NumPy code implements export and import. The README also describes broader framework sharing and operator reuse, but the sampled code does not show framework-to-framework dispatch. The graph therefore focuses on the evidenced NumPy path and marks the broader integration boundary as unverified.

Main entry points: [`apps/numpy_dlpack/dlpack/from_numpy.py`](https://github.com/dmlc/dlpack/blob/main/apps/numpy_dlpack/dlpack/from_numpy.py) (NumPy exporter), [`include/dlpack/dlpack.h`](https://github.com/dmlc/dlpack/blob/main/include/dlpack/dlpack.h) (Managed tensor), [`apps/numpy_dlpack/dlpack/to_numpy.py`](https://github.com/dmlc/dlpack/blob/main/apps/numpy_dlpack/dlpack/to_numpy.py) (NumPy importer), [`contrib/dlpack/dlpackcpp.h`](https://github.com/dmlc/dlpack/blob/main/contrib/dlpack/dlpackcpp.h) (C++ tensor wrapper)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_abi["Shared tensor ABI"]
  node_managed["Managed tensor<br/>[dlpack.h]"]
end

subgraph group_numpy["NumPy adapter"]
  node_export["NumPy exporter<br/>[from_numpy.py]"]
  node_capsule["DLPack capsule<br/>[from_numpy.py]"]
  node_import["NumPy importer<br/>[to_numpy.py]"]
  node_pytypes["Python ABI types<br/>[dlpack.py]"]
end

subgraph group_cpp["C++ example"]
  node_cppwrap["C++ tensor wrapper<br/>[dlpackcpp.h]"]
end

node_framework(("NumPy user"))
node_numpyresult["NumPy array"]
node_frameworks(("Other frameworks"))

node_framework -->|"provides array"| node_export
node_export -->|"describes tensor"| node_managed
node_export -->|"wraps tensor"| node_capsule
node_capsule -->|"provides tensor"| node_import
node_import -->|"creates array view"| node_numpyresult
node_cppwrap -->|"uses ABI"| node_managed
node_frameworks -.->|"shares tensors"| node_managed

click node_export "https://github.com/dmlc/dlpack/blob/main/apps/numpy_dlpack/dlpack/from_numpy.py"
click node_managed "https://github.com/dmlc/dlpack/blob/main/include/dlpack/dlpack.h"
click node_capsule "https://github.com/dmlc/dlpack/blob/main/apps/numpy_dlpack/dlpack/from_numpy.py"
click node_import "https://github.com/dmlc/dlpack/blob/main/apps/numpy_dlpack/dlpack/to_numpy.py"
click node_pytypes "https://github.com/dmlc/dlpack/blob/main/apps/numpy_dlpack/dlpack/dlpack.py"
click node_cppwrap "https://github.com/dmlc/dlpack/blob/main/contrib/dlpack/dlpackcpp.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_managed,node_framework toneBlue
class node_export,node_capsule,node_import,node_pytypes toneAmber
class node_cppwrap toneMint
class node_numpyresult,node_frameworks toneIndigo
```

## Components

### Shared tensor ABI

- [Managed tensor](https://github.com/dmlc/dlpack/blob/main/include/dlpack/dlpack.h): `include/dlpack/dlpack.h`

### NumPy adapter

- [NumPy exporter](https://github.com/dmlc/dlpack/blob/main/apps/numpy_dlpack/dlpack/from_numpy.py): `apps/numpy_dlpack/dlpack/from_numpy.py`
- [DLPack capsule](https://github.com/dmlc/dlpack/blob/main/apps/numpy_dlpack/dlpack/from_numpy.py): `apps/numpy_dlpack/dlpack/from_numpy.py`
- [NumPy importer](https://github.com/dmlc/dlpack/blob/main/apps/numpy_dlpack/dlpack/to_numpy.py): `apps/numpy_dlpack/dlpack/to_numpy.py`
- [Python ABI types](https://github.com/dmlc/dlpack/blob/main/apps/numpy_dlpack/dlpack/dlpack.py): `apps/numpy_dlpack/dlpack/dlpack.py`

### C++ example

- [C++ tensor wrapper](https://github.com/dmlc/dlpack/blob/main/contrib/dlpack/dlpackcpp.h): `contrib/dlpack/dlpackcpp.h`

### Other components

- **NumPy user**
- **NumPy array**
- **Other frameworks**

## Connections

- NumPy user → NumPy exporter: provides array (evidence: `apps/numpy_dlpack/dlpack/from_numpy.py`)
- NumPy exporter → Managed tensor: describes tensor (evidence: `apps/numpy_dlpack/dlpack/from_numpy.py`)
- NumPy exporter → DLPack capsule: wraps tensor (evidence: `apps/numpy_dlpack/dlpack/from_numpy.py`)
- DLPack capsule → NumPy importer: provides tensor (evidence: `apps/numpy_dlpack/dlpack/to_numpy.py`)
- NumPy importer → NumPy array: creates array view (evidence: `apps/numpy_dlpack/dlpack/to_numpy.py`)
- C++ tensor wrapper → Managed tensor: uses ABI (evidence: `contrib/dlpack/dlpackcpp.h`)
- Other frameworks → Managed tensor: shares tensors (evidence: `README.md`)
