# paras-ecosystem/framework-torch-paras architecture

> Architecture diagram of the GitHub repository paras-ecosystem/framework-torch-paras, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/paras-ecosystem/framework-torch-paras
- Repository: https://github.com/paras-ecosystem/framework-torch-paras

## Overview

Torch-ParaS is a PyTorch PrivateUse1 backend that lets models place tensors on ParaS devices and run native kernels, with unsupported operators falling back to CPU. The principal flow is PyTorch device registration, native extension entry, operator dispatch, then execution on a device queue; memory pooling and device/RNG management support that runtime. The README documents operator categories and fallback behavior; most operator implementations and registration code were not sampled, so those links are documented rather than source-verified.

Main entry points: [`csrc/core/registration.cpp`](https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/core/registration.cpp) (Operator registration), [`python/torch_paras/__init__.py`](https://github.com/paras-ecosystem/framework-torch-paras/blob/main/python/torch_paras/__init__.py) (Python package), [`csrc/core/context.cpp`](https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/core/context.cpp) (Device context), [`csrc/python/module.cpp`](https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/python/module.cpp) (Python extension)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["PyTorch API"]
  node_package["Python package<br/>[__init__.py]"]
  node_nn["NN extensions<br/>[nn.py]"]
end

subgraph group_runtime["Backend Runtime"]
  node_extension["Python extension<br/>[module.cpp]"]
  node_registration["Operator registration<br/>[registration.cpp]"]
  node_context["Device context<br/>[context.cpp]"]
  node_fallback["CPU fallback<br/>[registration.cpp]"]
end

subgraph group_kernels["Native Operators"]
  node_tensor["Tensor lifecycle<br/>[tensor_ops.cpp]"]
  node_creation["Creation ops<br/>[creation_ops.cpp]"]
  node_pointwise["Pointwise ops<br/>[pointwise_ops.cpp]"]
  node_indexing["Indexing ops<br/>[indexing_ops.cpp]"]
  node_scatter["Scatter ops<br/>[scatter_ops.cpp]"]
  node_sort["Sort ops<br/>[sort_ops.cpp]"]
  node_attention["Attention ops<br/>[attention_ops.cpp]"]
  node_fused["Fused ops<br/>[fused_ops.cpp]"]
  node_norm["Normalization ops<br/>[norm_ops.cpp]"]
  node_loss["Loss ops<br/>[loss_ops.cpp]"]
  node_random["Random ops<br/>[random_ops.cpp]"]
  node_vision["Vision ops<br/>[vision_ops.cpp]"]
end

subgraph group_support["Runtime Support"]
  node_compat["Device compatibility<br/>[paras_compat.cpp]"]
  node_allocator[("Memory pool<br/>[allocator.cpp]")]
end

node_user(("PyTorch model"))

node_user -->|"selects device"| node_package
node_package -->|"imports bindings"| node_extension
node_package -->|"loads extensions"| node_nn
node_extension -->|"calls device APIs"| node_context
node_registration -.->|"registers kernels"| node_tensor
node_registration -.->|"registers kernels"| node_creation
node_registration -.->|"registers kernels"| node_pointwise
node_registration -.->|"registers kernels"| node_indexing
node_registration -.->|"registers kernels"| node_scatter
node_registration -.->|"registers kernels"| node_sort
node_registration -.->|"registers kernels"| node_attention
node_registration -.->|"registers kernels"| node_fused
node_registration -.->|"registers kernels"| node_norm
node_registration -.->|"registers kernels"| node_loss
node_registration -.->|"registers kernels"| node_random
node_registration -.->|"registers kernels"| node_vision
node_registration -.->|"routes unsupported"| node_fallback
node_context -->|"owns device queues"| node_compat
node_tensor -.->|"uses pooled memory"| node_allocator
node_context -.->|"manages device pool"| node_allocator

click node_package "https://github.com/paras-ecosystem/framework-torch-paras/blob/main/python/torch_paras/__init__.py"
click node_nn "https://github.com/paras-ecosystem/framework-torch-paras/blob/main/python/torch_paras/nn.py"
click node_extension "https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/python/module.cpp"
click node_registration "https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/core/registration.cpp"
click node_context "https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/core/context.cpp"
click node_tensor "https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/ops/tensor_ops.cpp"
click node_creation "https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/ops/creation_ops.cpp"
click node_pointwise "https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/ops/pointwise_ops.cpp"
click node_indexing "https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/ops/indexing_ops.cpp"
click node_scatter "https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/ops/scatter_ops.cpp"
click node_sort "https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/ops/sort_ops.cpp"
click node_attention "https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/ops/attention_ops.cpp"
click node_fused "https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/ops/fused_ops.cpp"
click node_norm "https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/ops/norm_ops.cpp"
click node_loss "https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/ops/loss_ops.cpp"
click node_random "https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/ops/random_ops.cpp"
click node_vision "https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/ops/vision_ops.cpp"
click node_compat "https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/compat/paras_compat.cpp"
click node_allocator "https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/core/allocator.cpp"
click node_fallback "https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/core/registration.cpp"

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_package,node_nn toneBlue
class node_extension,node_registration,node_context,node_fallback toneAmber
class node_tensor,node_creation,node_pointwise,node_indexing,node_scatter,node_sort,node_attention,node_fused,node_norm,node_loss,node_random,node_vision toneMint
class node_compat,node_allocator toneRose
class node_user toneIndigo
```

## Components

### PyTorch API

- [Python package](https://github.com/paras-ecosystem/framework-torch-paras/blob/main/python/torch_paras/__init__.py): `python/torch_paras/__init__.py`
- [NN extensions](https://github.com/paras-ecosystem/framework-torch-paras/blob/main/python/torch_paras/nn.py): `python/torch_paras/nn.py`

### Backend Runtime

- [Python extension](https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/python/module.cpp): `csrc/python/module.cpp`
- [Operator registration](https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/core/registration.cpp): `csrc/core/registration.cpp`
- [Device context](https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/core/context.cpp): `csrc/core/context.cpp`
- [CPU fallback](https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/core/registration.cpp): `csrc/core/registration.cpp`

### Native Operators

- [Tensor lifecycle](https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/ops/tensor_ops.cpp): `csrc/ops/tensor_ops.cpp`
- [Creation ops](https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/ops/creation_ops.cpp): `csrc/ops/creation_ops.cpp`
- [Pointwise ops](https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/ops/pointwise_ops.cpp): `csrc/ops/pointwise_ops.cpp`
- [Indexing ops](https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/ops/indexing_ops.cpp): `csrc/ops/indexing_ops.cpp`
- [Scatter ops](https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/ops/scatter_ops.cpp): `csrc/ops/scatter_ops.cpp`
- [Sort ops](https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/ops/sort_ops.cpp): `csrc/ops/sort_ops.cpp`
- [Attention ops](https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/ops/attention_ops.cpp): `csrc/ops/attention_ops.cpp`
- [Fused ops](https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/ops/fused_ops.cpp): `csrc/ops/fused_ops.cpp`
- [Normalization ops](https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/ops/norm_ops.cpp): `csrc/ops/norm_ops.cpp`
- [Loss ops](https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/ops/loss_ops.cpp): `csrc/ops/loss_ops.cpp`
- [Random ops](https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/ops/random_ops.cpp): `csrc/ops/random_ops.cpp`
- [Vision ops](https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/ops/vision_ops.cpp): `csrc/ops/vision_ops.cpp`

### Runtime Support

- [Device compatibility](https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/compat/paras_compat.cpp): `csrc/compat/paras_compat.cpp`
- [Memory pool](https://github.com/paras-ecosystem/framework-torch-paras/blob/main/csrc/core/allocator.cpp): `csrc/core/allocator.cpp`

### Other components

- **PyTorch model**

## Connections

- PyTorch model → Python package: selects device (evidence: `README.md`)
- Python package → Python extension: imports bindings (evidence: `python/torch_paras/__init__.py`)
- Python package → NN extensions: loads extensions (evidence: `python/torch_paras/__init__.py`)
- Python extension → Device context: calls device APIs (evidence: `csrc/python/module.cpp`)
- Operator registration → Tensor lifecycle: registers kernels (evidence: `README.md`)
- Operator registration → Creation ops: registers kernels (evidence: `README.md`)
- Operator registration → Pointwise ops: registers kernels (evidence: `README.md`)
- Operator registration → Indexing ops: registers kernels (evidence: `README.md`)
- Operator registration → Scatter ops: registers kernels (evidence: `README.md`)
- Operator registration → Sort ops: registers kernels (evidence: `README.md`)
- Operator registration → Attention ops: registers kernels (evidence: `README.md`)
- Operator registration → Fused ops: registers kernels (evidence: `README.md`)
- Operator registration → Normalization ops: registers kernels (evidence: `README.md`)
- Operator registration → Loss ops: registers kernels (evidence: `README.md`)
- Operator registration → Random ops: registers kernels (evidence: `README.md`)
- Operator registration → Vision ops: registers kernels (evidence: `README.md`)
- Operator registration → CPU fallback: routes unsupported (evidence: `README.md`)
- Device context → Device compatibility: owns device queues
- Tensor lifecycle → Memory pool: uses pooled memory (evidence: `README.md`)
- Device context → Memory pool: manages device pool
