PHPackages                             krakjoe/ort - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. krakjoe/ort

ActivePhp-ext-zend

krakjoe/ort
===========

High performance tensor mathematics for PHP.

136139[1 issues](https://github.com/krakjoe/ort/issues)[1 PRs](https://github.com/krakjoe/ort/pulls)C

Since Feb 3Pushed 3mo ago5 watchersCompare

[ Source](https://github.com/krakjoe/ort)[ Packagist](https://packagist.org/packages/krakjoe/ort)[ RSS](/packages/krakjoe-ort/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP-ORT
=======

[](#php-ort)

[![Testing](https://github.com/krakjoe/ort/actions/workflows/testing.yml/badge.svg)](https://github.com/krakjoe/ort/actions/workflows/testing.yml)[![Coverage](https://camo.githubusercontent.com/cfce2ef6d89f7b2b2361143ed0fd1a161345906ee3ae23004f44cef03de5cfba/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6b72616b6a6f652f6f72742f62616467652e7376673f6272616e63683d646576656c6f70)](https://coveralls.io/github/krakjoe/ort?branch=develop)

*PHP - Oh Really, Tensors?*

This extension provides high performance tensor mathematics. It supports a wide range of mathematical operations on tensors, including element-wise computations, reductions, linear algebra functions, and more.

This extension also includes optional integration with Microsoft's ONNX Runtime for efficient model execution.

Features
--------

[](#features)

- **High-Performance Mathematics**: Hardware Acceleration
    - CPU (SIMD): WASM, NEON, RISCV64, AVX512, AVX2, SSE4.1, SSE2
    - GPU: CUDA
- **Hybrid Parallelism**: Automatic work distribution across CPU/GPU
- **Comprehensive Type Support**: 10 data types with automatic promotion
- **Memory Efficient**: Reference-counted tensors with zero-copy slicing
- **ONNX Integration**: Optional and Direct ONNX model loading and inference

Quick Start
-----------

[](#quick-start)

### Installation

[](#installation)

```
# Build extension
phpize
./configure --enable-ort
make
sudo make install
```

### Installation with ONNX Runtime

[](#installation-with-onnx-runtime)

```
# Fetch onnxruntime from github
wget https://github.com/microsoft/onnxruntime/releases/download/v1.22.0/onnxruntime-linux-x64-1.22.0.tgz

# Install onnxruntime
tar -C /usr/local -xvf onnxruntime-linux-x64-1.22.0.tgz --strip-components 1

# Build and install extension
phpize
./configure --with-ort-onnx=/usr/local --enable-ort
make -j$(nproc)
sudo make install
```

*Note: Use microsoft provided releases of ONNX, not brew or ppa or apt provided releases.*

### Installation with CUDA

[](#installation-with-cuda)

See [docs/gpu.md](docs/gpu.md) for more information about GPU acceleration.

#### Post Installation

[](#post-installation)

Add to your `php.ini`:

```
extension=ort.so
```

### Basic Usage

[](#basic-usage)

```
use ORT\Tensor\Transient;
use ORT\Math;

// Create tensors
$a = new Transient([1000, 1000], $matrix_data, ORT\Tensor::FLOAT);
$b = new Transient([1000, 1000], $matrix_data, ORT\Tensor::FLOAT);

// High-performance matrix multiplication
$result = Math\matmul($a, $b);

// Element-wise operations
$sum = Math\add($a, $b);
$scaled = Math\multiply($a, 2.5);  // Scalar operations

// Reductions
$total = Math\reduce\tensor\sum($a);
$row_sums = Math\reduce\axis\sum($a, 1);
```

Performance
-----------

[](#performance)

- **SIMD Acceleration**: Up to 8x faster with AVX2 vectorization
- **Multi-Core Scaling**: Automatic scaling to available CPU cores
- **Memory Optimization**: Aligned memory allocation for optimal performance

Check your system configuration:

```
echo "Backend: " . (ORT\Math\backend() ?: "scalar") . "\n";
echo "Cores: " . ORT\Math\cores() . "\n";
```

API Reference (not exhaustive)
------------------------------

[](#api-reference-not-exhaustive)

### Tensor Types

[](#tensor-types)

- `ORT\Tensor\Transient` - Temporary tensors
- `ORT\Tensor\Persistent` - Named, persistent tensors

### Mathematical Operations

[](#mathematical-operations)

- **Binary**: `add`, `subtract`, `multiply`, `divide`, `pow`, `mod`
- **Unary**: `sin`, `cos`, `exp`, `log`, `sqrt`, `abs`, `neg`
- **Matrix**: `matmul`, `dot`, `transpose`
- **Reduction**: `sum`, `mean`, `min`, `max`, `argmax`, `argmin`
- **Transformation**: `softmax`

### ONNX Integration

[](#onnx-integration)

- `ORT\Model` - Load and manage ONNX models
- `ORT\Runtime` - Execute ONNX model inference

See [docs/api.md](docs/api.md) for more extensive API reference.

Configuration
-------------

[](#configuration)

### Environment Variables

[](#environment-variables)

- `ORT_SCALE_CORES` - Set thread pool size (default: CPU cores)

### Build Options

[](#build-options)

- `--enable-ort-backend=type` - Enable SIMD optimizations (default: auto)
- `--with-ort-onnx` - Link against ONNX Runtime (default: no)

### Backend Types

[](#backend-types)

- `auto` - detect backend type for platform
- `wasm` - use wasm backend
- `neon` - use neon backend
- `riscv64` - use riscv64 backend
- `avx2` - use avx2 backend
- `sse41` - use sse41 backend
- `sse2` - use sse2 backend
- `cuda` - use cuda backend
- `none` - disable backend

Technical Details
-----------------

[](#technical-details)

See [docs](docs) for detailed technical documentation.

Requirements
------------

[](#requirements)

- **PHP**: 7.4+ or 8.0+
- **ONNX Runtime**: 1.16+ (optional)
- **Compiler**: GCC 4.8+ or Clang 3.8+
- **CPU**: x86\_64, aarch64, riscv64, wasm

License
-------

[](#license)

This project is licensed under the PHP License 3.01.

Contributing
------------

[](#contributing)

Contributions are welcome! Please ensure:

- Code follows existing style conventions
- SIMD implementations include proper fallbacks
- Thread safety is maintained
- Tests pass across supported PHP versions

Support
-------

[](#support)

For issues and feature requests, please use the project's issue tracker.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance54

Moderate activity, may be stable

Popularity22

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 Bus Factor1

Top contributor holds 99.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a53e08d9e444763eaca5611e49ff1403e8e0803a648b6cbd0e3a0d33430a2ff4?d=identicon)[krakjoe](/maintainers/krakjoe)

---

Top Contributors

[![krakjoe](https://avatars.githubusercontent.com/u/2236138?v=4)](https://github.com/krakjoe "krakjoe (393 commits)")[![pronskiy](https://avatars.githubusercontent.com/u/1196825?v=4)](https://github.com/pronskiy "pronskiy (2 commits)")[![ndossche](https://avatars.githubusercontent.com/u/7771979?v=4)](https://github.com/ndossche "ndossche (1 commits)")

### Embed Badge

![Health badge](/badges/krakjoe-ort/health.svg)

```
[![Health](https://phpackages.com/badges/krakjoe-ort/health.svg)](https://phpackages.com/packages/krakjoe-ort)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
