PHP code example of php-io-extensions / cuda

1. Go to this page and download the library: Download php-io-extensions/cuda library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

php-io-extensions / cuda example snippets



use Cuda\Cuda\Cuda;

$count = Cuda::cudaGetDeviceCount();
Cuda::cudaSetDevice(0);
$props = Cuda::cudaGetDeviceProperties(0);

$dev = Cuda::cudaMalloc(1024);
Cuda::cudaMemcpyHtoD($dev, random_bytes(1024), 1024);
$back = Cuda::cudaMemcpyDtoH($dev, 1024);
Cuda::cudaFree($dev);
bash
php -m | grep cuda
php --ri cuda
php examples/proof_of_work.php
bash
# Headless smoke
php examples/proof_of_work.php

# Windowed GPU-owned framebuffer + Quit (needs sdl3 + display)
DISPLAY=:1 CUDA_PROOF_SECONDS=40 php examples/proof_menu.php