@@ -32,10 +32,7 @@ var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
32
32
var isnanf = require ( '@stdlib/math/base/assert/is-nanf' ) ;
33
33
var format = require ( '@stdlib/string/format' ) ;
34
34
var tryRequire = require ( '@stdlib/utils/try-require' ) ;
35
-
36
- // var sgemm = require( '@stdlib/blas/base/sgemm' ).ndarray;
37
- var sgemm = require ( '@stdlib/utils/noop' ) ; // FIXME: remove once `sgemm` merged
38
-
35
+ var dgemm = require ( '@stdlib/blas/base/dgemm' ) . ndarray ;
39
36
var pkg = require ( './../package.json' ) . name ;
40
37
41
38
@@ -46,7 +43,10 @@ var tfnode = tryRequire( resolve( __dirname, '..', 'node_modules', '@tensorflow/
46
43
var opts = {
47
44
'skip' : ( tf instanceof Error )
48
45
} ;
49
- var OPTS = {
46
+ var SOPTS = {
47
+ 'dtype' : 'float64'
48
+ } ;
49
+ var TOPTS = {
50
50
'dtype' : 'float32'
51
51
} ;
52
52
@@ -73,9 +73,9 @@ function createBenchmark1( shapeA, orderA, shapeB, orderB, shapeC, orderC ) {
73
73
var B ;
74
74
var C ;
75
75
76
- A = discreteUniform ( numel ( shapeA ) , 0 , 10 , OPTS ) ;
77
- B = discreteUniform ( numel ( shapeB ) , 0 , 10 , OPTS ) ;
78
- C = discreteUniform ( numel ( shapeC ) , 0 , 10 , OPTS ) ;
76
+ A = discreteUniform ( numel ( shapeA ) , 0 , 10 , SOPTS ) ;
77
+ B = discreteUniform ( numel ( shapeB ) , 0 , 10 , SOPTS ) ;
78
+ C = discreteUniform ( numel ( shapeC ) , 0 , 10 , SOPTS ) ;
79
79
80
80
sa = shape2strides ( shapeA , orderA ) ;
81
81
sb = shape2strides ( shapeB , orderB ) ;
@@ -94,7 +94,7 @@ function createBenchmark1( shapeA, orderA, shapeB, orderB, shapeC, orderC ) {
94
94
95
95
b . tic ( ) ;
96
96
for ( i = 0 ; i < b . iterations ; i ++ ) {
97
- sgemm ( 'no-transpose' , 'no-transpose' , shapeA [ 0 ] , shapeC [ 1 ] , shapeB [ 0 ] , 0.5 , A , sa [ 0 ] , sa [ 1 ] , 0 , B , sb [ 0 ] , sb [ 1 ] , 0 , 2.0 , C , sc [ 0 ] , sc [ 1 ] , 0 ) ;
97
+ dgemm ( 'no-transpose' , 'no-transpose' , shapeA [ 0 ] , shapeC [ 1 ] , shapeB [ 0 ] , 0.5 , A , sa [ 0 ] , sa [ 1 ] , 0 , B , sb [ 0 ] , sb [ 1 ] , 0 , 2.0 , C , sc [ 0 ] , sc [ 1 ] , 0 ) ;
98
98
if ( isnanf ( C [ i % C . length ] ) ) {
99
99
b . fail ( 'should not return NaN' ) ;
100
100
}
@@ -122,9 +122,9 @@ function createBenchmark2( shapeA, shapeB, shapeC ) {
122
122
var bbuf ;
123
123
var cbuf ;
124
124
125
- abuf = discreteUniform ( numel ( shapeA ) , 0 , 10 , OPTS ) ;
126
- bbuf = discreteUniform ( numel ( shapeB ) , 0 , 10 , OPTS ) ;
127
- cbuf = discreteUniform ( numel ( shapeC ) , 0 , 10 , OPTS ) ;
125
+ abuf = discreteUniform ( numel ( shapeA ) , 0 , 10 , TOPTS ) ;
126
+ bbuf = discreteUniform ( numel ( shapeB ) , 0 , 10 , TOPTS ) ;
127
+ cbuf = discreteUniform ( numel ( shapeC ) , 0 , 10 , TOPTS ) ;
128
128
129
129
return benchmark ;
130
130
@@ -144,9 +144,9 @@ function createBenchmark2( shapeA, shapeB, shapeC ) {
144
144
145
145
tf . setBackend ( 'cpu' ) ;
146
146
147
- A = tf . tensor ( abuf , shapeA , OPTS . dtype ) ;
148
- B = tf . tensor ( bbuf , shapeB , OPTS . dtype ) ;
149
- C = tf . tensor ( cbuf , shapeC , OPTS . dtype ) ;
147
+ A = tf . tensor ( abuf , shapeA , TOPTS . dtype ) ;
148
+ B = tf . tensor ( bbuf , shapeB , TOPTS . dtype ) ;
149
+ C = tf . tensor ( cbuf , shapeC , TOPTS . dtype ) ;
150
150
151
151
b . tic ( ) ;
152
152
for ( i = 0 ; i < b . iterations ; i ++ ) {
@@ -184,9 +184,9 @@ function createBenchmark3( shapeA, shapeB, shapeC ) {
184
184
var bbuf ;
185
185
var cbuf ;
186
186
187
- abuf = discreteUniform ( numel ( shapeA ) , 0 , 10 , OPTS ) ;
188
- bbuf = discreteUniform ( numel ( shapeB ) , 0 , 10 , OPTS ) ;
189
- cbuf = discreteUniform ( numel ( shapeC ) , 0 , 10 , OPTS ) ;
187
+ abuf = discreteUniform ( numel ( shapeA ) , 0 , 10 , TOPTS ) ;
188
+ bbuf = discreteUniform ( numel ( shapeB ) , 0 , 10 , TOPTS ) ;
189
+ cbuf = discreteUniform ( numel ( shapeC ) , 0 , 10 , TOPTS ) ;
190
190
191
191
return benchmark ;
192
192
@@ -206,9 +206,9 @@ function createBenchmark3( shapeA, shapeB, shapeC ) {
206
206
207
207
tfnode . setBackend ( 'tensorflow' ) ;
208
208
209
- A = tfnode . tensor ( abuf , shapeA , OPTS . dtype ) ;
210
- B = tfnode . tensor ( bbuf , shapeB , OPTS . dtype ) ;
211
- C = tfnode . tensor ( cbuf , shapeC , OPTS . dtype ) ;
209
+ A = tfnode . tensor ( abuf , shapeA , TOPTS . dtype ) ;
210
+ B = tfnode . tensor ( bbuf , shapeB , TOPTS . dtype ) ;
211
+ C = tfnode . tensor ( cbuf , shapeC , TOPTS . dtype ) ;
212
212
213
213
b . tic ( ) ;
214
214
for ( i = 0 ; i < b . iterations ; i ++ ) {
@@ -250,7 +250,7 @@ function main() {
250
250
var i ;
251
251
252
252
min = 1 ; // 10^min
253
- max = 6 ; // 10^max
253
+ max = 5 ; // 10^max
254
254
255
255
for ( i = min ; i <= max ; i ++ ) {
256
256
N = floor ( pow ( pow ( 10 , i ) , 1.0 / 2.0 ) ) ;
@@ -265,27 +265,27 @@ function main() {
265
265
'row-major'
266
266
] ;
267
267
f = createBenchmark1 ( shapes [ 0 ] , orders [ 0 ] , shapes [ 1 ] , orders [ 1 ] , shapes [ 2 ] , orders [ 2 ] ) ;
268
- bench ( format ( '%s::stdlib:blas/base/sgemm :dtype=%s,orders=(%s),size=%d,shapes={(%s),(%s),(%s)}' , pkg , OPTS . dtype , orders . join ( ',' ) , numel ( shapes [ 2 ] ) , shapes [ 0 ] . join ( ',' ) , shapes [ 1 ] . join ( ',' ) , shapes [ 2 ] . join ( ',' ) ) , f ) ;
268
+ bench ( format ( '%s::stdlib:blas/base/dgemm :dtype=%s,orders=(%s),size=%d,shapes={(%s),(%s),(%s)}' , pkg , SOPTS . dtype , orders . join ( ',' ) , numel ( shapes [ 2 ] ) , shapes [ 0 ] . join ( ',' ) , shapes [ 1 ] . join ( ',' ) , shapes [ 2 ] . join ( ',' ) ) , f ) ;
269
269
270
270
f = createBenchmark2 ( shapes [ 0 ] , shapes [ 1 ] , shapes [ 2 ] ) ;
271
- bench ( format ( '%s::tfjs:matmul:dtype=%s,size=%d,shapes={(%s),(%s),(%s)}' , pkg , OPTS . dtype , numel ( shapes [ 2 ] ) , shapes [ 0 ] . join ( ',' ) , shapes [ 1 ] . join ( ',' ) , shapes [ 2 ] . join ( ',' ) ) , opts , f ) ;
271
+ bench ( format ( '%s::tfjs:matmul:dtype=%s,size=%d,shapes={(%s),(%s),(%s)}' , pkg , TOPTS . dtype , numel ( shapes [ 2 ] ) , shapes [ 0 ] . join ( ',' ) , shapes [ 1 ] . join ( ',' ) , shapes [ 2 ] . join ( ',' ) ) , opts , f ) ;
272
272
273
273
f = createBenchmark3 ( shapes [ 0 ] , shapes [ 1 ] , shapes [ 2 ] ) ;
274
- bench ( format ( '%s::tfjs-node:matmul:dtype=%s,size=%d,shapes={(%s),(%s),(%s)}' , pkg , OPTS . dtype , numel ( shapes [ 2 ] ) , shapes [ 0 ] . join ( ',' ) , shapes [ 1 ] . join ( ',' ) , shapes [ 2 ] . join ( ',' ) ) , opts , f ) ;
274
+ bench ( format ( '%s::tfjs-node:matmul:dtype=%s,size=%d,shapes={(%s),(%s),(%s)}' , pkg , TOPTS . dtype , numel ( shapes [ 2 ] ) , shapes [ 0 ] . join ( ',' ) , shapes [ 1 ] . join ( ',' ) , shapes [ 2 ] . join ( ',' ) ) , opts , f ) ;
275
275
276
276
orders = [
277
277
'row-major' ,
278
278
'column-major' ,
279
279
'row-major'
280
280
] ;
281
281
f = createBenchmark1 ( shapes [ 0 ] , orders [ 0 ] , shapes [ 1 ] , orders [ 1 ] , shapes [ 2 ] , orders [ 2 ] ) ;
282
- bench ( format ( '%s::stdlib:blas/base/sgemm :dtype=%s,orders=(%s),size=%d,shapes={(%s),(%s),(%s)}' , pkg , OPTS . dtype , orders . join ( ',' ) , numel ( shapes [ 2 ] ) , shapes [ 0 ] . join ( ',' ) , shapes [ 1 ] . join ( ',' ) , shapes [ 2 ] . join ( ',' ) ) , f ) ;
282
+ bench ( format ( '%s::stdlib:blas/base/dgemm :dtype=%s,orders=(%s),size=%d,shapes={(%s),(%s),(%s)}' , pkg , SOPTS . dtype , orders . join ( ',' ) , numel ( shapes [ 2 ] ) , shapes [ 0 ] . join ( ',' ) , shapes [ 1 ] . join ( ',' ) , shapes [ 2 ] . join ( ',' ) ) , f ) ;
283
283
284
284
f = createBenchmark2 ( shapes [ 0 ] , shapes [ 1 ] , shapes [ 2 ] ) ;
285
- bench ( format ( '%s::tfjs:matmul:dtype=%s,size=%d,shapes={(%s),(%s),(%s)}' , pkg , OPTS . dtype , numel ( shapes [ 2 ] ) , shapes [ 0 ] . join ( ',' ) , shapes [ 1 ] . join ( ',' ) , shapes [ 2 ] . join ( ',' ) ) , opts , f ) ;
285
+ bench ( format ( '%s::tfjs:matmul:dtype=%s,size=%d,shapes={(%s),(%s),(%s)}' , pkg , TOPTS . dtype , numel ( shapes [ 2 ] ) , shapes [ 0 ] . join ( ',' ) , shapes [ 1 ] . join ( ',' ) , shapes [ 2 ] . join ( ',' ) ) , opts , f ) ;
286
286
287
287
f = createBenchmark3 ( shapes [ 0 ] , shapes [ 1 ] , shapes [ 2 ] ) ;
288
- bench ( format ( '%s::tfjs-node:matmul:dtype=%s,size=%d,shapes={(%s),(%s),(%s)}' , pkg , OPTS . dtype , numel ( shapes [ 2 ] ) , shapes [ 0 ] . join ( ',' ) , shapes [ 1 ] . join ( ',' ) , shapes [ 2 ] . join ( ',' ) ) , opts , f ) ;
288
+ bench ( format ( '%s::tfjs-node:matmul:dtype=%s,size=%d,shapes={(%s),(%s),(%s)}' , pkg , TOPTS . dtype , numel ( shapes [ 2 ] ) , shapes [ 0 ] . join ( ',' ) , shapes [ 1 ] . join ( ',' ) , shapes [ 2 ] . join ( ',' ) ) , opts , f ) ;
289
289
}
290
290
}
291
291
0 commit comments