Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] Implement benchmark for cpu and gpu for initializer methods Cl… #68

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ test.php
*.IoT
*.loT
tensor
test_img.jpg
test_img.jpg
composer.lock
vendor
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,23 @@ NumPower aims to manage memory more efficiently than a matrix in PHP arrays
- **Optional (GPU)**: CUBLAS, CUDA Build Toolkit and cuDNN
- **Optional (Image)**: PHP-GD

## Composer Install
## Compiling

```
$ phpize
$ ./configure
$ make install
```

## Compiling with GPU (CUDA) support

```
$ phpize
$ ./configure --with-cuda
$ make install-cuda
```

## Composer install
The composer package provides a stubs file to facilitate autocomplete in the IDE. To install, simply run the command below in your environment with composer installed:

```bash
Expand All @@ -42,7 +58,7 @@ $ composer require numpower/numpower

The composer package will follow the same versioning as the extension.

## GPU Support
## GPU support

If you have an NVIDIA graphics card with CUDA support, you can use your graphics card
to perform operations. To do this, just copy your array to the GPU memory.
Expand Down
35 changes: 35 additions & 0 deletions benchmarks/initializers/ArangeInitializerBench.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* @Groups({"initializers"})
*/
class ArangeInitializerBench
{
/**
* @var size
*/
private $size = 1;

public function setUp(array $params): void
{
$this->size = $params['size'];
}

/**
* @BeforeMethods("setUp")
* @Revs(1000)
* @Iterations(5)
* @ParamProviders({
* "provideSizes",
* })
*/
public function benchARange($params)
{
$ndarray = \NDArray::arange($this->size, 0, 1);
}
public function provideSizes() {
yield ['size' => 100];
yield ['size' => 500];
yield ['size' => 1000];
}
}
?>
39 changes: 39 additions & 0 deletions benchmarks/initializers/ArrayInitializerBench.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* @Groups({"initializers"})
*/
class ArrayInitializerBench
{
/**
* @var matrix
*/
private $matrix = [];

public function setUp(array $params): void
{
$this->matrix = $params['matrix'];
}

/**
* @BeforeMethods("setUp")
* @Revs(1000)
* @Iterations(5)
* @ParamProviders({
* "provideMatrix",
* })
*/
public function benchArray($params)
{
$ndarray = \NDArray::array($this->matrix);
}

public function provideMatrix() {
yield ['matrix' => \NDArray::zeros([1, 100])];
yield ['matrix' => \NDArray::zeros([1, 500])];
yield ['matrix' => \NDArray::zeros([1, 1000])];
yield ['matrix' => \NDArray::zeros([10, 100])];
yield ['matrix' => \NDArray::zeros([1000, 500])];
yield ['matrix' => \NDArray::zeros([10000, 1000])];
}
}
?>
39 changes: 39 additions & 0 deletions benchmarks/initializers/FullInitializerBench.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* @Groups({"initializers"})
*/
class FullInitializerBench
{
/**
* @var shape
*/
private $shape = [];

public function setUp(array $params): void
{
$this->shape = $params['shape'];
}

/**
* @BeforeMethods("setUp")
* @Revs(1000)
* @Iterations(5)
* @ParamProviders({
* "provideShapes"
* })
*/
public function benchFull($params): void
{
\NDArray::full($this->shape, 4);
}

public function provideShapes() {
yield ['shape' => [100, 1]];
yield ['shape' => [500, 1]];
yield ['shape' => [1000, 1]];
yield ['shape' => [10, 100]];
yield ['shape' => [500, 1000]];
yield ['shape' => [1000, 10000]];
}
}
?>
36 changes: 36 additions & 0 deletions benchmarks/initializers/IdentityInitializerBench.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* @Groups({"initializers"})
*/
class IdentityInitializerBench
{
/**
* @var size
*/
private $size = 0;

public function setUp(array $params): void
{
$this->size = $params['size'];
}

/**
* @BeforeMethods("setUp")
* @Revs(1000)
* @Iterations(5)
* @ParamProviders({
* "provideSizes",
* })
*/
public function benchIdentity($params)
{
$ndarray = \NDArray::identity($this->size);
}

public function provideSizes() {
yield ['size' => 100];
yield ['size' => 500];
yield ['size' => 1000];
}
}
?>
39 changes: 39 additions & 0 deletions benchmarks/initializers/OnesInitializerBench.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* @Groups({"initializers"})
*/
class OnesInitializerBench
{
/**
* @var shape
*/
private $shape = [];

public function setUp(array $params): void
{
$this->shape = $params['shape'];
}

/**
* @BeforeMethods("setUp")
* @Revs(1000)
* @Iterations(5)
* @ParamProviders({
* "provideShapes"
* })
*/
public function benchOnes($params): void
{
\NDArray::ones($this->shape);
}

public function provideShapes() {
yield ['shape' => [100, 1]];
yield ['shape' => [500, 1]];
yield ['shape' => [1000, 1]];
yield ['shape' => [10, 100]];
yield ['shape' => [500, 1000]];
yield ['shape' => [1000, 10000]];
}
}
?>
39 changes: 39 additions & 0 deletions benchmarks/initializers/ZerosInitializerBench.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* @Groups({"initializers"})
*/
class ZerosInitializerBench
{
/**
* @var shape
*/
private $shape = [];

public function setUp(array $params): void
{
$this->shape = $params['shape'];
}

/**
* @BeforeMethods("setUp")
* @Revs(1000)
* @Iterations(5)
* @ParamProviders({
* "provideShapes"
* })
*/
public function benchZeros($params): void
{
\NDArray::zeros($this->shape);
}

public function provideShapes() {
yield ['shape' => [100, 1]];
yield ['shape' => [500, 1]];
yield ['shape' => [1000, 1]];
yield ['shape' => [10, 100]];
yield ['shape' => [500, 1000]];
yield ['shape' => [1000, 10000]];
}
}
?>
49 changes: 49 additions & 0 deletions benchmarks/linalg/CholeskyBench.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* @Groups({"linearAlgebra"})
*/
class CholeskyBench
{
/**
* @var testArray
*/
private $testArray = [];

public function setUp(array $params): void
{
$this->testArray = $params['testArray'];
}

/**
* @BeforeMethods("setUp")
* @Revs(1000)
* @Iterations(5)
* @ParamProviders({
* "provideArrays"
* })
*/
public function benchCholesky($params): void
{
\NDArray::cholesky($this->testArray);
}

private function createArray($ndim) {
$symmetric = \NDArray::ones([$ndim, $ndim]);
for ($i=0; $i<$ndim; $i++) {
$symmetric[$i][$i] += $ndim * 10;
}
$L = \NDArray::cholesky($symmetric);
$L_T = \NDArray::transpose($L);
$positive_definite_matrix = \NDArray::matmul($L, $L_T);
return $positive_definite_matrix;
}

public function provideArrays() {
$testSizes = array(10, 100, 1000, 10000);
foreach ($testSizes as &$value) {
$currTestMatrix = $this->createArray($value);
yield ['testArray' => $currTestMatrix];
}
}
}
?>
46 changes: 46 additions & 0 deletions benchmarks/linalg/CondBench.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* @Groups({"linearAlgebra"})
*/
class CondBench
{
/**
* @var testArray
*/
private $testArray = [];

public function setUp(array $params): void
{
$this->testArray = $params['testArray'];
}

/**
* @BeforeMethods("setUp")
* @Revs(1000)
* @Iterations(5)
* @ParamProviders({
* "provideArrays"
* })
*/
public function benchCond($params): void
{
\NDArray::cond($this->testArray);
}

private function createArray($ndim) {
$symmetric = \NDArray::ones([$ndim, $ndim]);
for ($i=0; $i<$ndim; $i++) {
$symmetric[$i][$i] += $ndim * 10;
}
return $symmetric;
}

public function provideArrays() {
$testSizes = array(10, 100, 1000);
foreach ($testSizes as &$value) {
$currTestMatrix = $this->createArray($value);
yield ['testArray' => $currTestMatrix];
}
}
}
?>
Loading