Skip to content

Commit 678cded

Browse files
Shabareesh ShettyShabareesh Shetty
authored andcommitted
feat: add blas/base/zgemm
1 parent 4754d60 commit 678cded

File tree

84 files changed

+8222
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+8222
-0
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var floor = require( '@stdlib/math/base/special/floor' );
28+
var Complex128Array = require( '@stdlib/array/complex128' );
29+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
30+
var pkg = require( './../package.json' ).name;
31+
var zgemm = require( './../lib/ndarray.js' );
32+
33+
34+
// VARIABLES //
35+
36+
var options = {
37+
'dtype': 'float64'
38+
};
39+
40+
41+
// FUNCTIONS //
42+
43+
/**
44+
* Creates a benchmark function.
45+
*
46+
* @private
47+
* @param {PositiveInteger} N - array dimension size
48+
* @returns {Function} benchmark function
49+
*/
50+
function createBenchmark( N ) {
51+
var alpha;
52+
var beta;
53+
var abuf;
54+
var bbuf;
55+
var cbuf;
56+
var A;
57+
var B;
58+
var C;
59+
60+
abuf = uniform( (N*N)*2, -100.0, 100.0, options );
61+
A = new Complex128Array( abuf.buffer );
62+
63+
bbuf = uniform( (N*N)*2, -100.0, 100.0, options );
64+
B = new Complex128Array( bbuf.buffer );
65+
66+
cbuf = uniform( (N*N)*2, -100.0, 100.0, options );
67+
C = new Complex128Array( cbuf.buffer );
68+
69+
alpha = new Complex128( 1.0, 0.0 );
70+
beta = new Complex128( 0.0, 0.0 );
71+
72+
return benchmark;
73+
74+
/**
75+
* Benchmark function.
76+
*
77+
* @private
78+
* @param {Benchmark} b - benchmark instance
79+
*/
80+
function benchmark( b ) {
81+
var z;
82+
var i;
83+
84+
b.tic();
85+
for ( i = 0; i < b.iterations; i++ ) {
86+
z = zgemm( 'no-transpose', 'no-transpose', N, N, N, alpha, A, 1, N, 0, B, 1, N, 0, beta, C, 1, N, 0 );
87+
if ( isnan( z[ i%z.length ] ) ) {
88+
b.fail( 'should not return NaN' );
89+
}
90+
}
91+
b.toc();
92+
if ( isnan( z[ i%z.length ] ) ) {
93+
b.fail( 'should not return NaN' );
94+
}
95+
b.pass( 'benchmark finished' );
96+
b.end();
97+
}
98+
}
99+
100+
101+
// MAIN //
102+
103+
/**
104+
* Main execution sequence.
105+
*
106+
* @private
107+
*/
108+
function main() {
109+
var min;
110+
var max;
111+
var N;
112+
var f;
113+
var i;
114+
115+
min = 1; // 10^min
116+
max = 5; // 10^max
117+
118+
for ( i = min; i <= max; i++ ) {
119+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
120+
f = createBenchmark( N );
121+
bench( pkg+':ndarray:order(A)=column-major,order(B)=column-major,order(C)=column-major,trans(A)=false,trans(B)=false,size='+(N*N), f );
122+
}
123+
}
124+
125+
main();
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var floor = require( '@stdlib/math/base/special/floor' );
28+
var Complex128Array = require( '@stdlib/array/complex128' );
29+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
30+
var pkg = require( './../package.json' ).name;
31+
var zgemm = require( './../lib/ndarray.js' );
32+
33+
34+
// VARIABLES //
35+
36+
var options = {
37+
'dtype': 'float64'
38+
};
39+
40+
41+
// FUNCTIONS //
42+
43+
/**
44+
* Creates a benchmark function.
45+
*
46+
* @private
47+
* @param {PositiveInteger} N - array dimension size
48+
* @returns {Function} benchmark function
49+
*/
50+
function createBenchmark( N ) {
51+
var alpha;
52+
var beta;
53+
var abuf;
54+
var bbuf;
55+
var cbuf;
56+
var A;
57+
var B;
58+
var C;
59+
60+
abuf = uniform( (N*N)*2, -100.0, 100.0, options );
61+
A = new Complex128Array( abuf.buffer );
62+
63+
bbuf = uniform( (N*N)*2, -100.0, 100.0, options );
64+
B = new Complex128Array( bbuf.buffer );
65+
66+
cbuf = uniform( (N*N)*2, -100.0, 100.0, options );
67+
C = new Complex128Array( cbuf.buffer );
68+
69+
alpha = new Complex128( 1.0, 0.0 );
70+
beta = new Complex128( 0.0, 0.0 );
71+
72+
return benchmark;
73+
74+
/**
75+
* Benchmark function.
76+
*
77+
* @private
78+
* @param {Benchmark} b - benchmark instance
79+
*/
80+
function benchmark( b ) {
81+
var z;
82+
var i;
83+
84+
b.tic();
85+
for ( i = 0; i < b.iterations; i++ ) {
86+
z = zgemm( 'no-transpose', 'transpose', N, N, N, alpha, A, 1, N, 0, B, 1, N, 0, beta, C, 1, N, 0 );
87+
if ( isnan( z[ i%z.length ] ) ) {
88+
b.fail( 'should not return NaN' );
89+
}
90+
}
91+
b.toc();
92+
if ( isnan( z[ i%z.length ] ) ) {
93+
b.fail( 'should not return NaN' );
94+
}
95+
b.pass( 'benchmark finished' );
96+
b.end();
97+
}
98+
}
99+
100+
101+
// MAIN //
102+
103+
/**
104+
* Main execution sequence.
105+
*
106+
* @private
107+
*/
108+
function main() {
109+
var min;
110+
var max;
111+
var N;
112+
var f;
113+
var i;
114+
115+
min = 1; // 10^min
116+
max = 5; // 10^max
117+
118+
for ( i = min; i <= max; i++ ) {
119+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
120+
f = createBenchmark( N );
121+
bench( pkg+':ndarray:order(A)=column-major,order(B)=column-major,order(C)=column-major,trans(A)=false,trans(B)=true,size='+(N*N), f );
122+
}
123+
}
124+
125+
main();
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var floor = require( '@stdlib/math/base/special/floor' );
28+
var Complex128Array = require( '@stdlib/array/complex128' );
29+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
30+
var pkg = require( './../package.json' ).name;
31+
var zgemm = require( './../lib/ndarray.js' );
32+
33+
34+
// VARIABLES //
35+
36+
var options = {
37+
'dtype': 'float64'
38+
};
39+
40+
41+
// FUNCTIONS //
42+
43+
/**
44+
* Creates a benchmark function.
45+
*
46+
* @private
47+
* @param {PositiveInteger} N - array dimension size
48+
* @returns {Function} benchmark function
49+
*/
50+
function createBenchmark( N ) {
51+
var alpha;
52+
var beta;
53+
var abuf;
54+
var bbuf;
55+
var cbuf;
56+
var A;
57+
var B;
58+
var C;
59+
60+
abuf = uniform( (N*N)*2, -100.0, 100.0, options );
61+
A = new Complex128Array( abuf.buffer );
62+
63+
bbuf = uniform( (N*N)*2, -100.0, 100.0, options );
64+
B = new Complex128Array( bbuf.buffer );
65+
66+
cbuf = uniform( (N*N)*2, -100.0, 100.0, options );
67+
C = new Complex128Array( cbuf.buffer );
68+
69+
alpha = new Complex128( 1.0, 0.0 );
70+
beta = new Complex128( 0.0, 0.0 );
71+
72+
return benchmark;
73+
74+
/**
75+
* Benchmark function.
76+
*
77+
* @private
78+
* @param {Benchmark} b - benchmark instance
79+
*/
80+
function benchmark( b ) {
81+
var z;
82+
var i;
83+
84+
b.tic();
85+
for ( i = 0; i < b.iterations; i++ ) {
86+
z = zgemm( 'transpose', 'no-transpose', N, N, N, alpha, A, 1, N, 0, B, 1, N, 0, beta, C, 1, N, 0 );
87+
if ( isnan( z[ i%z.length ] ) ) {
88+
b.fail( 'should not return NaN' );
89+
}
90+
}
91+
b.toc();
92+
if ( isnan( z[ i%z.length ] ) ) {
93+
b.fail( 'should not return NaN' );
94+
}
95+
b.pass( 'benchmark finished' );
96+
b.end();
97+
}
98+
}
99+
100+
101+
// MAIN //
102+
103+
/**
104+
* Main execution sequence.
105+
*
106+
* @private
107+
*/
108+
function main() {
109+
var min;
110+
var max;
111+
var N;
112+
var f;
113+
var i;
114+
115+
min = 1; // 10^min
116+
max = 5; // 10^max
117+
118+
for ( i = min; i <= max; i++ ) {
119+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
120+
f = createBenchmark( N );
121+
bench( pkg+':ndarray:order(A)=column-major,order(B)=column-major,order(C)=column-major,trans(A)=true,trans(B)=false,size='+(N*N), f );
122+
}
123+
}
124+
125+
main();

0 commit comments

Comments
 (0)