Skip to content

Commit 3620f35

Browse files
committed
add bootlog
1 parent 18d2ab7 commit 3620f35

7 files changed

+98
-85
lines changed

Diff for: bin/rindow-math-matrix.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,14 @@
1111
}
1212
use Rindow\Math\Matrix\MatrixOperator;
1313

14-
$mo = new MatrixOperator();
14+
$verbose = null;
15+
if($argc>1) {
16+
if($argv[1]=='-v') {
17+
$verbose = 10;
18+
}
19+
}
20+
$mo = new MatrixOperator(verbose:$verbose);
21+
if($verbose!==null) {
22+
echo "\n";
23+
}
1524
echo $mo->service()->info();

Diff for: phpstan-baseline.neon

-40
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: "#^Constructor of class Rindow\\\\Math\\\\Matrix\\\\Drivers\\\\MatlibPHP\\\\MatlibPhp has an unused parameter \\$blasCLFactory\\.$#"
5-
count: 1
6-
path: src/Drivers/MatlibPHP/MatlibPhp.php
7-
8-
-
9-
message: "#^Constructor of class Rindow\\\\Math\\\\Matrix\\\\Drivers\\\\MatlibPHP\\\\MatlibPhp has an unused parameter \\$bufferCLFactory\\.$#"
10-
count: 1
11-
path: src/Drivers/MatlibPHP/MatlibPhp.php
12-
13-
-
14-
message: "#^Constructor of class Rindow\\\\Math\\\\Matrix\\\\Drivers\\\\MatlibPHP\\\\MatlibPhp has an unused parameter \\$bufferFactory\\.$#"
15-
count: 1
16-
path: src/Drivers/MatlibPHP/MatlibPhp.php
17-
18-
-
19-
message: "#^Constructor of class Rindow\\\\Math\\\\Matrix\\\\Drivers\\\\MatlibPHP\\\\MatlibPhp has an unused parameter \\$clblastFactory\\.$#"
20-
count: 1
21-
path: src/Drivers/MatlibPHP/MatlibPhp.php
22-
23-
-
24-
message: "#^Constructor of class Rindow\\\\Math\\\\Matrix\\\\Drivers\\\\MatlibPHP\\\\MatlibPhp has an unused parameter \\$mathCLFactory\\.$#"
25-
count: 1
26-
path: src/Drivers/MatlibPHP/MatlibPhp.php
27-
28-
-
29-
message: "#^Constructor of class Rindow\\\\Math\\\\Matrix\\\\Drivers\\\\MatlibPHP\\\\MatlibPhp has an unused parameter \\$mathFactory\\.$#"
30-
count: 1
31-
path: src/Drivers/MatlibPHP/MatlibPhp.php
32-
33-
-
34-
message: "#^Constructor of class Rindow\\\\Math\\\\Matrix\\\\Drivers\\\\MatlibPHP\\\\MatlibPhp has an unused parameter \\$openblasFactory\\.$#"
35-
count: 1
36-
path: src/Drivers/MatlibPHP/MatlibPhp.php
37-
38-
-
39-
message: "#^Constructor of class Rindow\\\\Math\\\\Matrix\\\\Drivers\\\\MatlibPHP\\\\MatlibPhp has an unused parameter \\$openclFactory\\.$#"
40-
count: 1
41-
path: src/Drivers/MatlibPHP/MatlibPhp.php
42-
433
-
444
message: "#^Constructor of class Rindow\\\\Math\\\\Matrix\\\\Drivers\\\\MatlibPHP\\\\PhpBlas has an unused parameter \\$blas\\.$#"
455
count: 1

Diff for: src/Drivers/AbstractMatlibService.php

+55
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
abstract class AbstractMatlibService implements Service
1313
{
14+
abstract protected function injectDefaultFactories() : void;
15+
1416
// abstract properties
1517
protected string $name = 'unknown';
1618

@@ -36,6 +38,7 @@ abstract class AbstractMatlibService implements Service
3638
protected ?object $clblastMath=null;
3739

3840
protected ?int $serviceLevel=null;
41+
protected int $logLevel = 10;
3942

4043
public function __construct(
4144
protected ?object $bufferFactory=null,
@@ -46,12 +49,16 @@ public function __construct(
4649
protected ?object $blasCLFactory=null,
4750
protected ?object $mathCLFactory=null,
4851
protected ?object $bufferCLFactory=null,
52+
protected ?int $verbose=null,
4953
) {
5054
$this->phpBLASFactory = new PhpBLASFactory();
5155
$this->phpblas = $this->phpBLASFactory->Blas();
5256
$this->phplapack = $this->phpBLASFactory->Lapack();
5357
$this->phpmath = $this->phpBLASFactory->Math();
5458
$this->phpbuffer = $this->phpBLASFactory;
59+
$this->setVerbose($verbose);
60+
61+
$this->injectDefaultFactories();
5562

5663
$level = $this->serviceLevel();
5764
if($level>=Service::LV_ADVANCED) {
@@ -67,6 +74,20 @@ public function __construct(
6774
}
6875
}
6976

77+
protected function setVerbose(int $verbose=null) : void
78+
{
79+
$verbose ??= 0;
80+
$this->logLevel = 10 - $verbose;
81+
}
82+
83+
protected function logging(int $level, string $message) : void
84+
{
85+
if($level < $this->logLevel) {
86+
return;
87+
}
88+
echo $message."\n";
89+
}
90+
7091
protected function bufferFactory() : object
7192
{
7293
if($this->bufferFactory==null) {
@@ -138,32 +159,66 @@ public function serviceLevel() : int
138159
}
139160

140161
$level = Service::LV_BASIC;
162+
$this->logging(0, 'Current level Basic.');
141163
while(true) {
142164
if($this->bufferFactory===null ||
143165
$this->openblasFactory===null ||
144166
$this->mathFactory===null) {
167+
if($this->bufferFactory===null) {
168+
$this->logging(0, 'bufferFactory ** not found **.');
169+
}
170+
if($this->openblasFactory===null) {
171+
$this->logging(0, 'openblasFactory ** not found **.');
172+
}
173+
if($this->mathFactory===null) {
174+
$this->logging(0, 'mathFactory ** not found **.');
175+
}
145176
break;
146177
}
147178
if(!$this->bufferFactory()->isAvailable()||
148179
!$this->openblasFactory()->isAvailable()||
149180
!$this->mathFactory()->isAvailable()) {
181+
if(!$this->bufferFactory()->isAvailable()) {
182+
$this->logging(0, get_class($this->bufferFactory()).' is ** not available **.');
183+
}
184+
if(!$this->openblasFactory()->isAvailable()) {
185+
$this->logging(0, get_class($this->openblasFactory()).' is ** not available **.');
186+
}
187+
if(!$this->mathFactory()->isAvailable()) {
188+
$this->logging(0, get_class($this->mathFactory()).' is ** not available **.');
189+
}
150190
break;
151191
}
152192
$level = Service::LV_ADVANCED;
193+
$this->logging(0, 'Update current level to Advanced.');
153194

154195
if($this->openclFactory==null||
155196
$this->clblastFactory==null) {
197+
if($this->openclFactory===null) {
198+
$this->logging(0, 'openclFactory ** not found **.');
199+
}
200+
if($this->clblastFactory===null) {
201+
$this->logging(0, 'clblastFactory ** not found **.');
202+
}
156203
break;
157204
}
158205
if(!$this->openclFactory()->isAvailable()||
159206
!$this->clblastFactory()->isAvailable()) {
207+
if(!$this->openclFactory()->isAvailable()) {
208+
$this->logging(0, get_class($this->openclFactory()).' is ** not available **.');
209+
}
210+
if(!$this->clblastFactory()->isAvailable()) {
211+
$this->logging(0, get_class($this->clblastFactory()).' is ** not available **.');
212+
}
160213
break;
161214
}
162215
$level = Service::LV_ACCELERATED;
216+
$this->logging(0, 'Update current level to Accelerated.');
163217
break;
164218
}
165219

166220
$this->serviceLevel = $level;
221+
$this->logging(0, 'The service level was diagnosed as '.$this->levelString[$this->serviceLevel].'.');
167222
return $level;
168223
}
169224

Diff for: src/Drivers/MatlibPHP/MatlibPhp.php

+2-35
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,7 @@ class MatlibPhp extends AbstractMatlibService
77
{
88
protected string $name = 'matlib_php';
99

10-
public function __construct(
11-
object $bufferFactory=null,
12-
object $mathFactory=null,
13-
object $openblasFactory=null,
14-
object $openclFactory=null,
15-
object $clblastFactory=null,
16-
object $blasCLFactory=null,
17-
object $mathCLFactory=null,
18-
object $bufferCLFactory=null,
19-
)
10+
protected function injectDefaultFactories() : void
2011
{
21-
//$bufferFactory = $bufferFactory ?? new BufferFactory();
22-
//
23-
//$openblasFactory = $openblasFactory ?? new OpenBLASFactory();
24-
//
25-
//$mathFactory = $mathFactory ?? new MatlibFactory();
26-
//
27-
//$openclFactory = $openclFactory ?? new OpenCLFactory();
28-
//$bufferCLFactory = $bufferCLFactory ?? $openclFactory;
29-
//
30-
//$clblastFactory = $clblastFactory ?? new CLBlastFactory();
31-
//$blasCLFactory = $blasCLFactory ?? $clblastFactory;
32-
//
33-
//$mathCLFactory = $mathCLFactory ?? new MatlibCLFactory();
34-
35-
parent::__construct(
36-
// bufferFactory:$bufferFactory,
37-
// openblasFactory:$openblasFactory,
38-
// mathFactory:$mathFactory,
39-
// openclFactory:$openclFactory,
40-
// clblastFactory:$clblastFactory,
41-
// blasCLFactory:$blasCLFactory,
42-
// mathCLFactory:$mathCLFactory,
43-
// bufferCLFactory:$bufferCLFactory,
44-
);
4512
}
46-
}
13+
}

Diff for: src/Drivers/Selector.php

+19-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Selector
1010
/** @var array<string> $catalog */
1111
protected array $catalog;
1212
protected ?Service $recommended=null;
13+
protected int $logLevel = 10;
1314

1415
/**
1516
* @param array<string> $catalog
@@ -23,24 +24,39 @@ public function __construct(array $catalog = null)
2324
$this->catalog = $catalog;
2425
}
2526

26-
public function select() : Service
27+
protected function logging(int $level, string $message) : void
28+
{
29+
if($level < $this->logLevel) {
30+
return;
31+
}
32+
echo $message."\n";
33+
}
34+
35+
public function select(int $verbose=null) : Service
2736
{
2837
if($this->recommended) {
2938
return $this->recommended;
3039
}
40+
$verbose ??= 0;
41+
$this->logLevel = 10 - $verbose;
3142
$recommended = null;
3243
$highestLevel = 0;
3344
foreach ($this->catalog as $name) {
3445
if(class_exists($name)) {
35-
$service = new $name;
46+
$this->logging(0, 'Loading service: '.$name);
47+
$service = new $name(verbose:$verbose);
3648
if(!($service instanceof Service)) {
3749
throw new LogicException('Not service class: '.$name);
3850
}
3951
$level = $service->serviceLevel();
52+
$this->logging(0, 'Service '.$name.' is level '.$level);
4053
if($level>$highestLevel) {
4154
$highestLevel = $level;
4255
$recommended = $service;
56+
$this->logging(0, 'Update recommend to '.$name);
4357
}
58+
} else {
59+
$this->logging(1, 'Service Not found: '.$name);
4460
}
4561
}
4662
if($highestLevel<=Service::LV_BASIC) {
@@ -50,6 +66,7 @@ public function select() : Service
5066
throw new RuntimeException('Service not found');
5167
}
5268
$this->recommended = $recommended;
69+
$this->logging(1, get_class($recommended).' service has been selected.');
5370
return $recommended;
5471
}
5572
}

Diff for: src/MatrixOperator.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ class MatrixOperator
8181
public function __construct(
8282
Service $service=null,
8383
array $catalog=null,
84+
int $verbose=null,
8485
)
8586
{
8687
if($service===null) {
8788
$selector = new Selector($catalog);
88-
$service = $selector->select();
89+
$service = $selector->select(verbose:$verbose);
8990
}
9091
$this->service = $service;
9192

Diff for: tests/init_autoloader.php

+10-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
throw new \Exception("Loader is not found.");
99
}
1010
$loader->addPsr4('Rindow\\Math\\Matrix\\', __DIR__.'/../src');
11-
$loader->addPsr4('Rindow\\Math\\Matrix\\Drivers\\MatlibFFI\\', __DIR__.'/../../rindow-math-matrix-matlibffi/src');
12-
$loader->addPsr4('Rindow\\Math\\Buffer\\FFI\\', __DIR__.'/../../rindow-math-buffer-ffi/src');
13-
$loader->addPsr4('Rindow\\OpenBLAS\\FFI\\', __DIR__.'/../../rindow-openblas-ffi/src');
14-
$loader->addPsr4('Rindow\\Matlib\\FFI\\', __DIR__.'/../../rindow-matlib-ffi/src');
15-
$loader->addPsr4('Rindow\\OpenCL\\FFI\\', __DIR__.'/../../rindow-opencl-ffi/src');
16-
$loader->addPsr4('Rindow\\CLBlast\\FFI\\', __DIR__.'/../../rindow-clblast-ffi/src');
11+
if(defined('USE_MATLIBEXT') && USE_MATLIBEXT) {
12+
$loader->addPsr4('Rindow\\Math\\Matrix\\Drivers\\MatlibExt\\', __DIR__.'/../../rindow-math-matrix-matlibext/src');
13+
} else {
14+
$loader->addPsr4('Rindow\\Math\\Matrix\\Drivers\\MatlibFFI\\', __DIR__.'/../../rindow-math-matrix-matlibffi/src');
15+
$loader->addPsr4('Rindow\\Math\\Buffer\\FFI\\', __DIR__.'/../../rindow-math-buffer-ffi/src');
16+
$loader->addPsr4('Rindow\\Matlib\\FFI\\', __DIR__.'/../../rindow-matlib-ffi/src');
17+
$loader->addPsr4('Rindow\\OpenBLAS\\FFI\\', __DIR__.'/../../rindow-openblas-ffi/src');
18+
$loader->addPsr4('Rindow\\OpenCL\\FFI\\', __DIR__.'/../../rindow-opencl-ffi/src');
19+
$loader->addPsr4('Rindow\\CLBlast\\FFI\\', __DIR__.'/../../rindow-clblast-ffi/src');
20+
}
1721
$loader->addPsr4('Rindow\\Math\\Plot\\', __DIR__.'/../../rindow-math-plot/src');
1822
$loader->addPsr4('Interop\\Polite\\Math\\', __DIR__.'/../../../interop-phpobjects/polite-math/src');
1923

0 commit comments

Comments
 (0)