High-performance GPU computing and tensor operations with PHP.
Project details
PHP GPU Tensors is a native extension that harnesses the power of NVIDIA GPUs for high-performance tensor operations and machine-learning workloads. It enables runtime-compiled CUDA kernels and optimized data movement, making it an efficient choice for developers seeking to integrate GPU computing directly into their PHP applications.
PHP GPU Tensors is a native PHP extension designed specifically for GPU computing. This extension provides efficient handling of tensor operations and machine-learning tasks leveraging NVIDIA GPU acceleration. It enables developers to create tensor operations and data pipelines directly in PHP, without the need for a Python runtime. The core features include:
CudaArray class to perform a range of operations including arithmetic, broadcasting, comparisons, and matrix multiplications. The library supports batch processing and reductions, as well as slicing similar to Python’s style..npy file imports to optimize execution.Here is a quick example demonstrating basic tensor operations:
use Cuda\CudaArray;
$a = CudaArray::ones([4]);
$b = CudaArray::full([4], 2.0);
$c = CudaArray::full([4], 3.0);
// Eager execution (default): one GPU operation per call.
$eager = $a + $b * $c;
// Fusion (opt-in): capture once, replay as fused GPU kernels.
$plan = Fusion::compile(fn($a, $b, $c) => $a + $b * $c, inputs: [$a, $b, $c]);
$fused = $plan->run($a, $b, $c);
print_r($fused->toArray()); // [7, 7, 7, 7]
This code snippet highlights how to perform tensor arithmetic operations seamlessly using PHP.
The efficiency of Fusion compared to eager execution has shown notable improvements:
| Mode | Time per Step | Patches per Second | Training Time (1,280 Steps) |
|---|---|---|---|
| Eager Execution | 4.08 ms | 125,444 | 5.22 s |
| Fused Execution | 0.66 ms | 776,251 | 0.84 s |
This performance data illustrates the potential benefits of adopting kernel fusion in training routines.
The extension is available via Packagist and can be easily installed by running:
pie install lcmialichi/php-gpu-tensors:0.1.0-beta.4
PHP GPU Tensors opens new possibilities for conducting high-performance tensor operations directly within PHP environments. By utilizing CUDA for acceleration, it empowers developers to harness the speed and efficiency of GPU computing for machine learning and numerical workloads.
Comments
0Start the conversation
Share the first comment.