A near production-ready PHP extension that provides CUDA support for high-performance computing and deep learning tasks. It still needs a lot more testing, anyone who can test or wants to contribute, feel free. I want nothing in return for writing this the goal was merely to level the playing field between PHP and Python and prove that PHP is as capable as it's reptilian counterpart.
That being said, any donations are never refused.
-
Device Management
- Get CUDA device count
- Query device properties
- Set/Get current device
- Device synchronization
- Device reset capabilities
-
Memory Management
- CUDA memory allocation
- Memory copying (host-to-device, device-to-host, device-to-device)
- Automatic resource cleanup
- Unified memory support
- Pinned memory operations
- Memory pool with fragmentation handling
- High-performance matrix operations
- GEMM (General Matrix Multiplication)
- Optimized linear algebra operations
- Automatic handle management
- Batch processing capabilities
- Deep learning primitives
- Convolution operations
- Forward convolution
- Backward convolution (data)
- Backward convolution (filter)
- Pooling operations
- Forward pooling
- Backward pooling
- Activation functions
- Forward activation
- Backward activation
- Tensor creation and manipulation
- Basic operations (add, multiply)
- Activation functions (ReLU, sigmoid, tanh)
- Gradient computation
- Shape manipulation
- Device affinity management
- Load balancing
- Multi-GPU computation
- Device synchronization
- Thread safety
- CUDA event timing
- Memory usage tracking
- Kernel metrics collection
- Device utilization monitoring
- Performance benchmarking
- Comprehensive error checking
- Error status retrieval
- Error message translation
- PHP 7.0 or later
- CUDA Toolkit 8.0 or later
- cuBLAS (included with CUDA Toolkit)
- cuDNN 7.0 or later
- C compiler (gcc/clang)
- PHP development files
- NVTX (optional, for profiling)
- Clone the repository:
git clone https://github.com/yourusername/php-cuda.git
cd php-cuda
- Run the compile script:
./compile.sh
The extension includes a comprehensive test suite covering various aspects of functionality:
To run all tests after installation:
./compile.sh --test
To run individual test files:
cd tests/
php run-test.php test_name.phpt
-
Basic Functionality (
001-basic.phpt
)- Device management
- Basic matrix operations
- Error handling
-
Memory Management (
002-memory.phpt
)- Memory allocation/deallocation
- Memory pool operations
- Leak detection
-
Stress Testing (
003-stress.phpt
)- High-load operations
- Error recovery
- Concurrent operations
-
Neural Network (
004-neural.phpt
)- Layer operations
- Training functions
- Model persistence
-
Tensor Operations (
005-tensor.phpt
)- Tensor creation
- Basic operations
- Activation functions
- Gradient computation
-
Advanced Memory (
006-advanced-memory.phpt
)- Unified memory
- Pinned memory
- Memory pool fragmentation
- Bandwidth measurement
-
Multi-GPU (
007-multi-gpu.phpt
)- Device management
- Multi-GPU computation
- Device synchronization
- Thread safety
-
cuBLAS (
008-cublas.phpt
)- Basic operations
- GEMM operations
- Batch processing
- Performance benchmarks
-
Profiling (
009-profiler.phpt
)- Event timing
- Memory tracking
- Kernel metrics
- Device utilization
- Some tests require multiple GPUs (
007-multi-gpu.phpt
) - Profiling tests require NVTX support (
009-profiler.phpt
) - Memory tests require sufficient GPU memory
- Neural network tests require cuDNN
[Rest of the README content remains unchanged...]
[Previous usage examples remain unchanged...]
[Previous API reference remains unchanged...]
[Previous performance considerations remain unchanged...]
Contributions are welcome! Please feel free to submit pull requests.
MIT License - see LICENSE file for details.
For issues and questions, please use the GitHub issue tracker.