PHPackages                             rindow/rindow-math-matrix-matlibffi - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. rindow/rindow-math-matrix-matlibffi

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

rindow/rindow-math-matrix-matlibffi
===================================

Rindow Math Matrix's Drivers for Matlib with FFI

1.0.5(1y ago)1133BSD-3-ClausePHPPHP ^8.1CI passing

Since Mar 20Pushed 1y ago1 watchersCompare

[ Source](https://github.com/rindow/rindow-math-matrix-matlibffi)[ Packagist](https://packagist.org/packages/rindow/rindow-math-matrix-matlibffi)[ RSS](/packages/rindow-rindow-math-matrix-matlibffi/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (7)Versions (7)Used By (0)

Rindow Math Matrix's Drivers for Matlib with PHP FFI
====================================================

[](#rindow-math-matrixs-drivers-for-matlib-with-php-ffi)

Status: [![Build Status](https://github.com/rindow/rindow-math-matrix-matlibffi/workflows/tests/badge.svg)](https://github.com/rindow/rindow-math-matrix-matlibffi/actions)[![Downloads](https://camo.githubusercontent.com/8538909ee99da90db6370e6cb16e079116757e3b484b5f7efc1079524ce818c9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72696e646f772f72696e646f772d6d6174682d6d61747269782d6d61746c6962666669)](https://packagist.org/packages/rindow/rindow-math-matrix-matlibffi)[![Latest Stable Version](https://camo.githubusercontent.com/a4e8958df76945ce71bd755c9fdbbd7df26ec6a24caf15e9a6f78b486cd2107e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72696e646f772f72696e646f772d6d6174682d6d61747269782d6d61746c6962666669)](https://packagist.org/packages/rindow/rindow-math-matrix-matlibffi)[![License](https://camo.githubusercontent.com/e84644151d0f9ee8a5ac078ab65cc8e5d665771c2f7875d294f972f833a5531a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f72696e646f772f72696e646f772d6d6174682d6d61747269782d6d61746c6962666669)](https://packagist.org/packages/rindow/rindow-math-matrix-matlibffi)

This package is matlib drivers for Rindow-math-matrix. These drivers act as adapters to drive PHP FFI. Each PHP C Libraries requires a separate download and installation of a binary file appropriate for your environment's PHP version and OS version.

Rindow Math Matrix is the fundamental package for scientific matrix operation

- A powerful N-dimensional array object
- Sophisticated (broadcasting) functions
- Tools for integrating C/C++ through the FFI
- Useful linear algebra and random number capabilities

Please see the documents on [Rindow mathematics projects](https://rindow.github.io/mathematics/) web pages.

Rindow Math Matrix's repository is [here](https://github.com/rindow/rindow-math-matrix/).

Requirements
============

[](#requirements)

- PHP 8.1 or PHP8.2 or PHP8.3 or PHP8.4
- Rindow Math Matrix v2.0 or later
- Rindow Matlib 1.0.0 or later
- OpenBLAS 0.3.20 or later(Linux/Windows), vecLib(macOS)
- OpenCL 1.1 or later
- CLBlast 1.5.2 or later

### Download pre-build binaries from each projects

[](#download-pre-build-binaries-from-each-projects)

You can perform very fast N-dimensional array operations in conjunction. Download the pre-build binary files from each project's release page.

- Pre-build binaries
    - [Rindow Matlib](https://github.com/rindow/rindow-matlib/releases)
    - [OpenBLAS](https://github.com/OpenMathLib/OpenBLAS/releases)
    - [CLBlast](https://github.com/CNugteren/CLBlast/releases)

Setup for Windows
=================

[](#setup-for-windows)

Download the binary file, unzip it, and copy it to the execution directory.

- rindow-matlib-X.X.X-win64.zip
- OpenBLAS-X.X.X-x64.zip
- CLBlast-X.X.X-windows-x64.zip

Add FFI extension to php.ini

```
C:\TMP> cd \path\to\php\directory
C:\PHP> notepad php.ini

extension=ffi
```

```
C:\TMP> PATH %PATH%;\path\to\binary\directories\bin
C:\TMP> cd \your\progject\directory
C:\PRJ> composer require rindow/rindow-math-matrix
C:\PRJ> composer require rindow/rindow-math-matrix-matlibffi
C:\PRJ> vendor/bin/rindow-math-matrix
Service Level   : Accelerated
Buffer Factory  : Rindow\Math\Buffer\FFI\BufferFactory
BLAS Driver     : Rindow\OpenBLAS\FFI\Blas(THREAD)
LAPACK Driver   : Rindow\OpenBLAS\FFI\Lapack
Math Driver     : Rindow\Matlib\FFI\Matlib(THREAD)
OpenCL Factory  : Rindow\OpenCL\FFI\OpenCLFactory
CLBlast Factory : Rindow\CLBlast\FFI\CLBlastFactory
```

The OpenCL 1.2 environment is already set up if you are using the Windows standard driver.

If you add the -v option as shown below, the driver loading status at boot time will be displayed. It will help with troubleshooting.

```
C:\PRJ> vendor/bin/rindow-math-matrix -v
```

Setup for Linux
===============

[](#setup-for-linux)

Install each library using the apt command.

Make sure FFI extension is enabled.

```
$ php -m | grep FFI
FFI
```

Download the pre-build binary file.

-

Please install using the apt command.

```
$ sudo apt install ./rindow-matlib_X.X.X_amd64.deb
```

Since rindow-matlib currently uses ptheads, so you should choose the pthread version for OpenBLAS as well. In version 1.0 of Rindow-matlib we recommended the OpenMP version, but now we have changed our policy and are recommending the pthread version. This issue does not occur on Windows.

```
$ sudo apt install libopenblas0 liblapacke
```

If you want to use GPU, install the OpenCL environment. In addition, there are the following drivers.

- mesa-opencl-icd
- beignet-opencl-icd
- intel-opencl-icd
- nvidia-opencl-icd-xxx
- pocl-opencl-icd

```
$ sudo apt install clinfo
$ sudo apt install mesa-opencl-icd
$ sudo mkdir -p /usr/local/usr/lib
$ sudo ln -s /usr/lib/clc /usr/local/usr/lib/clc
```

And then, Install the fast matrix calculation library for OpenCL. If you use Ubuntu22.04 or Debian 12 or later, You can install it from distribution packages.

```
$ sudo apt install libclblast1
```

If You use Ubuntu20.04 or Debian 11, You need to download clblast from Github and make deb file. Please download the CLBlast installation script from the rindow-clblast-ffi release page.

```
$ wget https://github.com/rindow/rindow-clblast-ffi/releases/download/X.X.X/clblast-packdeb.zip
$ unzip clblast-packdeb.zip
$ sh clblast-packdeb.sh
$ sudo apt install ./clblast_X.X.X_amd64.deb
```

> *CAUTION*: However, The rindow-matlib v1.1 do not support Ubuntu 20.04/Debian 11. If you want to use Ubuntu 20.04, please build it from source code or use rindow-matlib v1.0.

And then, Install the rindow-math-matrix on your project directory.

```
$ composer require rindow/rindow-math-matrix
$ composer require rindow/rindow-math-matrix-matlibffi
$ vendor/bin/rindow-math-matrix
Service Level   : Accelerated
Buffer Factory  : Rindow\Math\Buffer\FFI\BufferFactory
BLAS Driver     : Rindow\OpenBLAS\FFI\Blas(THREAD)
LAPACK Driver   : Rindow\OpenBLAS\FFI\Lapack
Math Driver     : Rindow\Matlib\FFI\Matlib(THREAD)
OpenCL Factory  : Rindow\OpenCL\FFI\OpenCLFactory
CLBlast Factory : Rindow\CLBlast\FFI\CLBlastFactory
```

If you add the -v option as shown below, the driver loading status at boot time will be displayed. It will help with troubleshooting.

```
$ vendor/bin/rindow-math-matrix -v
```

Setup for macOS
===============

[](#setup-for-macos)

Install each library using the apt command.

Make sure FFI extension is enabled.

```
$ php -m | grep FFI
FFI
```

Download the pre-build binary file.

-

Please install using the apt command.

```
$ curl https://github.com/rindow/rindow-matlib/releases/download/X.X.X/rindow-matlib-X.X.X-Darwin-XXXX.tar.gz -O -L
$ tar -xzf rindow-matlib-XXX-Darwin-XXX.tar.gz
$ sudo cp -r usr/include /usr/local/
$ sudo cp -r usr/lib /usr/local/
```

If you want to use OpenMP mode instead of native thread mode, instantiate OpenMP. In most cases OpenMP mode is not needed.

```
$ brew install libomp
```

And then, Install the rindow-math-matrix on your project directory.

```
$ composer require rindow/rindow-math-matrix
$ composer require rindow/rindow-math-matrix-matlibffi
$ vendor/bin/rindow-math-matrix
Service Level   : Advanced
Buffer Factory  : Rindow\Math\Buffer\FFI\BufferFactory
BLAS Driver     : Rindow\OpenBLAS\FFI\Blas(THREAD)
LAPACK Driver   : Rindow\OpenBLAS\FFI\Lapack
Math Driver     : Rindow\Matlib\FFI\Matlib(THREAD)
```

OpenCL is not supported on macOS.

### Check driver status

[](#check-driver-status)

You can check the driver settings by running the sample below.

```
