-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] Implement benchmark for cpu and gpu for initializer methods Cl…
…oses #57 (#65) * CPU Benchmark files for initializers Added benchmark files for CPU initializers using phpBench * New methods and features for 0.6.0 (#64) * feat: squeeze manipulation routine with axis support * feat: NDArray::full implementation * feat: NDArray::fill release * feat: argmin and argmax with axis support * feat: NDArray::positive implementation * feat: NDArray::reciprocal implementation * feat: NDArray::reciprocal stubs * feat: NDArray::reciprocal stubs * feat: NDArray::swapaxes implementation feat: NDArray::transpose permutation * feat: NDArray::swapaxes and new transpose stubs * feat: NDArray::argmin and argmax keepdims option * feat: NDArray::rollaxis implementation * feat: NDArray::moveaxis implementation * fix: improvements to the slicing mechanism * feat: ndarray slicing stubs * fix: fixed slicing shape when arrays contain values * feat: hstack, vstack and dstack implementation * feat: column_stack implementation * feat: column_stack PHP stubs * feat: NDArray::concatenate implementation * feat: NDArray::append implementation * feat: NDArray::append stubs * docs: update README.md * fix: NDArray::append memory leak when using PHP arrays as arguments. * fix: new routines GPU implementation * Added Param Providers + Added parameter providers for readability and coding best practices - removed repetitive code * Added default phpbench file + Added default PHPBench configuration file * Update composer.json * Update initializers.c Fixed comment for NDArray ones * Fixed setUp for benchmarking Refactored function names for clarity, and fixed phpBench setup method * Added benchmarks for the linear algebra methods Added benchmarks for Linear Algebra methods with the exception of functions Cond, Inv, and Qr * Added benchmarks for sum and products methods Added benchmarks for sum and products methods * Added benchmarks for the arithmetic methods Added benchmarks for the arithmetic methods - removed initial testArray values * Added default values for aggregate benchmarking Added default Revs and iteration values for more accurate runtime time estimates. * Added Benchmarks for QR decomp, Condi, and Inverse - remove extra comments on Cholesky benchmark file - removed extra param comment in linalg file + Benchmark for QR decomposition function + Benchmark for Inverse function + Benchmark for Cond function * Added annotations and ignore configure~ file + Updated .gitignore to ignore generated configure file + Added MIT license under composer file * Added Group annotations Added Group annotations to all benchmarks. * Update readability of ArrayInitializerBench Updated Array Initializer Benchmark to utilize zeros Initializer for setup instead of hard coded arrays * Temp files in .gitignore Removed temp files from .gitignore --------- Co-authored-by: Henrique Borba <[email protected]>
- Loading branch information
1 parent
0e20c24
commit d6ed83b
Showing
56 changed files
with
3,001 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,4 +45,6 @@ test.php | |
*.IoT | ||
*.loT | ||
tensor | ||
test_img.jpg | ||
test_img.jpg | ||
composer.lock | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])]; | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]]; | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]]; | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]]; | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} | ||
} | ||
?> |
Oops, something went wrong.