Skip to content

Commit 527931b

Browse files
committed
bench: update to use dgemm
1 parent 6c76e49 commit 527931b

File tree

3 files changed

+39
-45
lines changed

3 files changed

+39
-45
lines changed

docs/migration-guides/mathjs/benchmark/benchmark.gemm.square_matrices.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
3434
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
3535
var format = require( '@stdlib/string/format' );
3636
var tryRequire = require( '@stdlib/utils/try-require' );
37-
38-
// var sgemm = require( '@stdlib/blas/base/sgemm' ).ndarray;
39-
var sgemm = require( '@stdlib/utils/noop' ); // FIXME: remove once `sgemm` merged
40-
37+
var dgemm = require( '@stdlib/blas/base/dgemm' ).ndarray;
4138
var pkg = require( './../package.json' ).name;
4239

4340

@@ -48,7 +45,7 @@ var opts = {
4845
'skip': ( mathjs instanceof Error )
4946
};
5047
var OPTS = {
51-
'dtype': 'float32'
48+
'dtype': 'float64'
5249
};
5350

5451

@@ -95,7 +92,7 @@ function createBenchmark1( shapeA, orderA, shapeB, orderB, shapeC, orderC ) {
9592

9693
b.tic();
9794
for ( i = 0; i < b.iterations; i++ ) {
98-
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 );
95+
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 );
9996
if ( isnanf( C[ i%C.length ] ) ) {
10097
b.fail( 'should not return NaN' );
10198
}
@@ -195,7 +192,7 @@ function main() {
195192
'row-major'
196193
];
197194
f = createBenchmark1( shapes[0], orders[0], shapes[1], orders[1], shapes[2], orders[2] );
198-
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 );
195+
bench( format( '%s::stdlib:blas/base/dgemm: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 );
199196

200197
f = createBenchmark2( shapes[0], shapes[1], shapes[2] );
201198
bench( format( '%s::mathjs:multiply: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 );
@@ -206,7 +203,7 @@ function main() {
206203
'row-major'
207204
];
208205
f = createBenchmark1( shapes[0], orders[0], shapes[1], orders[1], shapes[2], orders[2] );
209-
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 );
206+
bench( format( '%s::stdlib:blas/base/dgemm: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 );
210207

211208
f = createBenchmark2( shapes[0], shapes[1], shapes[2] );
212209
bench( format( '%s::mathjs:multiply: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 );

docs/migration-guides/scijs/benchmark/benchmark.gemm.square_matrices.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
3232
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
3333
var format = require( '@stdlib/string/format' );
3434
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;
3936
var pkg = require( './../package.json' ).name;
4037

4138

@@ -47,7 +44,7 @@ var opts = {
4744
'skip': ( ndarray instanceof Error || ndgemm instanceof Error )
4845
};
4946
var OPTS = {
50-
'dtype': 'float32'
47+
'dtype': 'float64'
5148
};
5249

5350

@@ -94,7 +91,7 @@ function createBenchmark1( shapeA, orderA, shapeB, orderB, shapeC, orderC ) {
9491

9592
b.tic();
9693
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 );
94+
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 );
9895
if ( isnanf( C[ i%C.length ] ) ) {
9996
b.fail( 'should not return NaN' );
10097
}
@@ -188,7 +185,7 @@ function main() {
188185
var i;
189186

190187
min = 1; // 10^min
191-
max = 6; // 10^max
188+
max = 5; // 10^max
192189

193190
for ( i = min; i <= max; i++ ) {
194191
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
@@ -203,7 +200,7 @@ function main() {
203200
'row-major'
204201
];
205202
f = createBenchmark1( shapes[0], orders[0], shapes[1], orders[1], shapes[2], orders[2] );
206-
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 );
203+
bench( format( '%s::stdlib:blas/base/dgemm: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 );
207204

208205
f = createBenchmark2( shapes[0], orders[0], shapes[1], orders[1], shapes[2], orders[2] );
209206
bench( format( '%s::scijs:ndarray-gemm: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( ',' ) ), opts, f );
@@ -214,7 +211,7 @@ function main() {
214211
'row-major'
215212
];
216213
f = createBenchmark1( shapes[0], orders[0], shapes[1], orders[1], shapes[2], orders[2] );
217-
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 );
214+
bench( format( '%s::stdlib:blas/base/dgemm: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 );
218215

219216
f = createBenchmark2( shapes[0], orders[0], shapes[1], orders[1], shapes[2], orders[2] );
220217
bench( format( '%s::scijs:ndarray-gemm: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( ',' ) ), opts, f );

docs/migration-guides/tfjs/benchmark/benchmark.gemm.square_matrices.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
3232
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
3333
var format = require( '@stdlib/string/format' );
3434
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;
3936
var pkg = require( './../package.json' ).name;
4037

4138

@@ -46,7 +43,10 @@ var tfnode = tryRequire( resolve( __dirname, '..', 'node_modules', '@tensorflow/
4643
var opts = {
4744
'skip': ( tf instanceof Error )
4845
};
49-
var OPTS = {
46+
var SOPTS = {
47+
'dtype': 'float64'
48+
};
49+
var TOPTS = {
5050
'dtype': 'float32'
5151
};
5252

@@ -73,9 +73,9 @@ function createBenchmark1( shapeA, orderA, shapeB, orderB, shapeC, orderC ) {
7373
var B;
7474
var C;
7575

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 );
7979

8080
sa = shape2strides( shapeA, orderA );
8181
sb = shape2strides( shapeB, orderB );
@@ -94,7 +94,7 @@ function createBenchmark1( shapeA, orderA, shapeB, orderB, shapeC, orderC ) {
9494

9595
b.tic();
9696
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 );
9898
if ( isnanf( C[ i%C.length ] ) ) {
9999
b.fail( 'should not return NaN' );
100100
}
@@ -122,9 +122,9 @@ function createBenchmark2( shapeA, shapeB, shapeC ) {
122122
var bbuf;
123123
var cbuf;
124124

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 );
128128

129129
return benchmark;
130130

@@ -144,9 +144,9 @@ function createBenchmark2( shapeA, shapeB, shapeC ) {
144144

145145
tf.setBackend( 'cpu' );
146146

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 );
150150

151151
b.tic();
152152
for ( i = 0; i < b.iterations; i++ ) {
@@ -184,9 +184,9 @@ function createBenchmark3( shapeA, shapeB, shapeC ) {
184184
var bbuf;
185185
var cbuf;
186186

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 );
190190

191191
return benchmark;
192192

@@ -206,9 +206,9 @@ function createBenchmark3( shapeA, shapeB, shapeC ) {
206206

207207
tfnode.setBackend( 'tensorflow' );
208208

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 );
212212

213213
b.tic();
214214
for ( i = 0; i < b.iterations; i++ ) {
@@ -250,7 +250,7 @@ function main() {
250250
var i;
251251

252252
min = 1; // 10^min
253-
max = 6; // 10^max
253+
max = 5; // 10^max
254254

255255
for ( i = min; i <= max; i++ ) {
256256
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
@@ -265,27 +265,27 @@ function main() {
265265
'row-major'
266266
];
267267
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 );
269269

270270
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 );
272272

273273
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 );
275275

276276
orders = [
277277
'row-major',
278278
'column-major',
279279
'row-major'
280280
];
281281
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 );
283283

284284
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 );
286286

287287
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 );
289289
}
290290
}
291291

0 commit comments

Comments
 (0)