Added typed (BLAS-like) API code examples.

Details:
- Added new example code to examples/tapi demonstrating how to use the
  BLIS typed API. These code examples directly mirror the corresponding
  example code files in examples/oapi. This setup provides a convenient
  opportunity for newcomers to BLIS to compare and contrast the typed
  and object APIs when they are used to perform the same tasks.
- Minor cleanups to examples/oapi.
This commit is contained in:
Field G. Van Zee
2018-07-03 18:27:29 -05:00
parent 3f387ca35e
commit b45ea92fc6
19 changed files with 1896 additions and 28 deletions

View File

@@ -43,11 +43,13 @@ int main( int argc, char** argv )
dim_t m, n;
inc_t rs, cs;
//
// This file demonstrates the basics of creating objects in BLIS,
// inspecting their basic properties, and printing matrix objects.
//
//
// Example 1: Create an object containing a 4x3 matrix of double-
// precision real elements stored in column-major order.
@@ -69,6 +71,7 @@ int main( int argc, char** argv )
rs = 1; cs = 6;
bli_obj_create( dt, m, n, rs, cs, &a2 );
//
// Example 2: Create an object containing a 4x3 matrix of double-
// precision real elements stored in row-major order.
@@ -87,6 +90,7 @@ int main( int argc, char** argv )
rs = 8; cs = 1;
bli_obj_create( dt, m, n, rs, cs, &a4 );
//
// Example 3: Create objects using other floating-point datatypes.
//
@@ -98,6 +102,7 @@ int main( int argc, char** argv )
bli_obj_create( BLIS_SCOMPLEX, m, n, rs, cs, &a6 );
bli_obj_create( BLIS_DCOMPLEX, m, n, rs, cs, &a7 );
//
// Example 4: Create objects using default (column) storage so that
// we avoid having to specify rs and cs manually.
@@ -112,6 +117,7 @@ int main( int argc, char** argv )
// in doubt, query the value!
bli_obj_create( BLIS_FLOAT, 3, 5, 0, 0, &a8 );
//
// Example 5: Inspect object fields after creation to expose
// possible alignment/padding.
@@ -128,6 +134,7 @@ int main( int argc, char** argv )
printf( "row stride: %d\n", ( int )bli_obj_row_stride( &a8 ) );
printf( "col stride: %d\n", ( int )bli_obj_col_stride( &a8 ) );
//
// Example 6: Inspect object fields after creation of other floating-
// point datatypes.
@@ -162,6 +169,7 @@ int main( int argc, char** argv )
printf( "row stride: %d\n", ( int )bli_obj_row_stride( &a11 ) );
printf( "col stride: %d\n", ( int )bli_obj_col_stride( &a11 ) );
//
// Example 7: Initialize an object's elements to random values and then
// print the matrix.
@@ -181,6 +189,7 @@ int main( int argc, char** argv )
// elements of type 'float'.
bli_printm( "matrix 'a9' contents:", &a9, "%4.1f", "" );
//
// Example 8: Randomize and then print from an object containing a complex
// matrix.
@@ -193,13 +202,14 @@ int main( int argc, char** argv )
bli_randm( &a11 );
bli_printm( "matrix 'a11' contents (complex):", &a11, "%4.1f", "" );
//
// Example 9: Create, randomize, and print vector objects.
//
printf( "\n#\n# -- Example 9 --\n#\n\n" );
// Now let's create two vector object--a row vector and a column vector.
// Now let's create two vector objects--a row vector and a column vector.
// (A vector object is like a matrix object, except that it has at least
// one unit dimension (equal to one).
bli_obj_create( BLIS_DOUBLE, 4, 1, 0, 0, &v1 );

View File

@@ -46,11 +46,13 @@ int main( int argc, char** argv )
dim_t m, n;
inc_t rs, cs;
//
// This file demonstrates interfacing external or existing buffers
// with BLIS objects.
//
//
// Example 1: Create a bufferless object and then attach an external
// buffer to it, specifying column storage.
@@ -86,6 +88,7 @@ int main( int argc, char** argv )
// assigned.
bli_printm( "matrix 'a1', initialized by columns:", &a1, "%5.1f", "" );
//
// Example 2: Create a bufferless object and then attach an external
// buffer to it, specifying row storage.

View File

@@ -49,11 +49,13 @@ int main( int argc, char** argv )
inc_t rs, cs;
dim_t i, j;
//
// This file demonstrates accessing and updating individual matrix elements
// through the BLIS object API.
//
//
// Example 1: Create an object and then individually access/view some of
// its elements.
@@ -98,6 +100,7 @@ int main( int argc, char** argv )
printf( "\n" );
//
// Example 2: Modify individual elements of an existing matrix.
//
@@ -132,6 +135,7 @@ int main( int argc, char** argv )
// it should contain the same initial state as a1.
bli_printm( "matrix 'a2'", &a2, "%5.1f", "" );
//
// Example 3: Modify individual elements of an existing complex matrix.
//

View File

@@ -51,10 +51,12 @@ int main( int argc, char** argv )
dim_t i, j;
dim_t mv, nv;
//
// This file demonstrates creating and submatrix views into existing matrices.
//
//
// Example 1: Create an object and then create a submatrix view.
//
@@ -85,6 +87,7 @@ int main( int argc, char** argv )
// bli_obj_create(). In the above example, that means only object a1
// would be passed to bli_obj_free().
//
// Example 2: Modify the contents of a submatrix view.
//
@@ -105,6 +108,7 @@ int main( int argc, char** argv )
bli_printm( "submatrix view 'v1' (modified state)", &v1, "%5.1f", "" );
bli_printm( "matrix 'a1' (indirectly modified due to changes to 'v1')", &a1, "%5.1f", "" );
//
// Example 3: Create a submatrix view that is "too big".
//
@@ -125,6 +129,7 @@ int main( int argc, char** argv )
bli_printm( "4x3 submatrix 'v2' at offsets (4,2) -- two rows truncated for safety", &v2, "%5.1f", "" );
//
// Example 4: Create a bufferless object, attach an external buffer, and
// then create a submatrix view.
@@ -145,6 +150,7 @@ int main( int argc, char** argv )
bli_printm( "3x4 submatrix view 'v3' at offsets (2,3)", &v3, "%5.1f", "" );
//
// Example 5: Use a submatrix view to set a region of a larger matrix to
// zero.
@@ -160,6 +166,7 @@ int main( int argc, char** argv )
bli_printm( "matrix 'a2' (modified state)", &a2, "%5.1f", "" );
//
// Example 6: Obtain a submatrix view into a submatrix view.
//

View File

@@ -41,10 +41,12 @@ int main( int argc, char** argv )
num_t dt;
double gamma_d;
//
// This file demonstrates working with scalar objects.
//
//
// Example 1: Create a scalar (1x1) object.
//
@@ -85,6 +87,7 @@ int main( int argc, char** argv )
// update their values, though you can always perform operations *with*
// them--that's the whole point!).
//
// Example 2: Set the value of an existing scalar object.
//
@@ -107,6 +110,7 @@ int main( int argc, char** argv )
bli_printm( "kappa:", &kappa, "%4.1f", "" );
bli_printm( "gamma:", &gamma, "%4.1f", "" );
//
// Example 3: Create and set the value of a complex scalar object.
//
@@ -119,6 +123,7 @@ int main( int argc, char** argv )
bli_setsc( 3.3, -4.4, &zeta );
bli_printm( "zeta (complex):", &zeta, "%4.1f", "" );
//
// Example 4: Copy scalar objects.
//
@@ -133,6 +138,7 @@ int main( int argc, char** argv )
bli_copysc( &BLIS_ONE, &gamma );
bli_printm( "gamma (overwritten with BLIS_ONE):", &gamma, "%4.1f", "" );
//
// Example 5: Perform other operations on scalar objects.
//

View File

@@ -43,11 +43,13 @@ int main( int argc, char** argv )
dim_t m, n;
inc_t rs, cs;
//
// This file demonstrates working with vector objects and the level-1v
// operations.
//
//
// Example 1: Create vector objects and then broadcast (copy) scalar
// values to all elements.
@@ -95,6 +97,7 @@ int main( int argc, char** argv )
bli_printm( "y := alpha", &y, "%4.1f", "" );
bli_printm( "z := 0.0", &z, "%4.1f", "" );
//
// Example 2: Randomize a vector object.
//
@@ -106,6 +109,7 @@ int main( int argc, char** argv )
bli_printm( "w := randv()", &w, "%4.1f", "" );
//
// Example 3: Perform various element-wise operations on vector objects.
//
@@ -147,6 +151,7 @@ int main( int argc, char** argv )
bli_printm( "x (after swapping with y)", &x, "%4.1f", "" );
bli_printm( "y (after swapping with x)", &y, "%4.1f", "" );
//
// Example 4: Perform contraction-like operations on vector objects.
//

View File

@@ -43,11 +43,13 @@ int main( int argc, char** argv )
dim_t m, n;
inc_t rs, cs;
//
// This file demonstrates working with matrix objects and the level-1m
// operations.
//
//
// Example 1: Create matrix objects and then broadcast (copy) scalar
// values to all elements.
@@ -88,6 +90,7 @@ int main( int argc, char** argv )
bli_printm( "b := alpha", &b, "%4.1f", "" );
bli_printm( "c := 0.0", &c, "%4.1f", "" );
//
// Example 2: Randomize a matrix object.
//
@@ -99,6 +102,7 @@ int main( int argc, char** argv )
bli_printm( "e (randomized):", &e, "%4.1f", "" );
//
// Example 3: Perform element-wise operations on matrices.
//
@@ -128,6 +132,7 @@ int main( int argc, char** argv )
bli_axpym( &alpha, &a, &c );
bli_printm( "c := c + alpha * a", &c, "%4.1f", "" );
//
// Example 4: Copy and transpose a matrix.
//
@@ -170,6 +175,7 @@ int main( int argc, char** argv )
bli_printm( "f (copied value):", &f, "%4.1f", "" );
//
// Example 5: Copy and Hermitian-transpose a matrix.
//

View File

@@ -41,10 +41,12 @@ int main( int argc, char** argv )
dim_t m, n;
inc_t rs, cs;
//
// This file demonstrates level-1m operations on structured matrices.
//
//
// Example 1: Initialize the upper triangle of a matrix to random values.
//
@@ -221,6 +223,7 @@ int main( int argc, char** argv )
bli_printm( "d: transpose of lower triangular of bl copied to d", &d, "%4.1f", "" );
//
// Example 5: Create a rectangular matrix (m > n) with a lower trapezoid
// containing random values, then set the strictly upper
@@ -267,6 +270,7 @@ int main( int argc, char** argv )
bli_printm( "e: after upper triangle set to zero", &e, "%4.1f", "" );
//
// Example 6: Create an upper Hessenberg matrix of random values and then
// set the "unstored" values to zero.
@@ -318,6 +322,7 @@ int main( int argc, char** argv )
bli_obj_free( &c );
bli_obj_free( &d );
bli_obj_free( &e );
bli_obj_free( &h );
return 0;
}

View File

@@ -45,10 +45,12 @@ int main( int argc, char** argv )
obj_t* alpha;
obj_t* beta;
//
// This file demonstrates level-2 operations.
//
//
// Example 1: Perform a general rank-1 update (ger) operation.
//
@@ -86,6 +88,7 @@ int main( int argc, char** argv )
bli_obj_free( &x );
bli_obj_free( &y );
//
// Example 2: Perform a general matrix-vector multiply (gemv) operation.
//
@@ -133,6 +136,7 @@ int main( int argc, char** argv )
bli_obj_free( &x );
bli_obj_free( &y );
//
// Example 3: Perform a symmetric rank-1 update (syr) operation.
//
@@ -173,6 +177,7 @@ int main( int argc, char** argv )
bli_obj_free( &a );
bli_obj_free( &x );
//
// Example 4: Perform a symmetric matrix-vector multiply (symv) operation.
//
@@ -218,6 +223,7 @@ int main( int argc, char** argv )
bli_obj_free( &x );
bli_obj_free( &y );
//
// Example 5: Perform a triangular matrix-vector multiply (trmv) operation.
//
@@ -258,6 +264,7 @@ int main( int argc, char** argv )
bli_obj_free( &a );
bli_obj_free( &x );
//
// Example 6: Perform a triangular solve (trsv) operation.
//

View File

@@ -43,14 +43,15 @@ int main( int argc, char** argv )
side_t side;
obj_t a, b, c, d;
obj_t aa, bb, cc;
obj_t* alpha;
obj_t* beta;
//
// This file demonstrates level-3 operations.
//
//
// Example 1: Perform a general matrix-matrix multiply (gemm) operation.
//
@@ -87,6 +88,7 @@ int main( int argc, char** argv )
bli_obj_free( &b );
bli_obj_free( &c );
//
// Example 1b: Perform a general matrix-matrix multiply (gemm) operation
// with the left input operand (matrix A) transposed.
@@ -97,35 +99,36 @@ int main( int argc, char** argv )
// Create some matrix operands to work with.
dt = BLIS_DOUBLE;
m = 4; n = 5; k = 3; rs = 0; cs = 0;
bli_obj_create( dt, m, n, rs, cs, &cc );
bli_obj_create( dt, k, m, rs, cs, &aa );
bli_obj_create( dt, k, n, rs, cs, &bb );
bli_obj_create( dt, m, n, rs, cs, &c );
bli_obj_create( dt, k, m, rs, cs, &a );
bli_obj_create( dt, k, n, rs, cs, &b );
// Set the scalars to use.
alpha = &BLIS_ONE;
beta = &BLIS_ONE;
// Initialize the matrix operands.
bli_randm( &aa );
bli_setm( &BLIS_ONE, &bb );
bli_setm( &BLIS_ZERO, &cc );
bli_randm( &a );
bli_setm( &BLIS_ONE, &b );
bli_setm( &BLIS_ZERO, &c );
// Set the transpose bit in 'aa'.
bli_obj_toggle_trans( &aa );
// Set the transpose bit in 'a'.
bli_obj_toggle_trans( &a );
bli_printm( "a: randomized", &aa, "%4.1f", "" );
bli_printm( "b: set to 1.0", &bb, "%4.1f", "" );
bli_printm( "c: initial value", &cc, "%4.1f", "" );
bli_printm( "a: randomized", &a, "%4.1f", "" );
bli_printm( "b: set to 1.0", &b, "%4.1f", "" );
bli_printm( "c: initial value", &c, "%4.1f", "" );
// c := beta * c + alpha * a^T * b, where 'a', 'b', and 'c' are general.
bli_gemm( alpha, &aa, &bb, beta, &cc );
bli_gemm( alpha, &a, &b, beta, &c );
bli_printm( "c: after gemm", &cc, "%4.1f", "" );
bli_printm( "c: after gemm", &c, "%4.1f", "" );
// Free the objects.
bli_obj_free( &aa );
bli_obj_free( &bb );
bli_obj_free( &cc );
bli_obj_free( &a );
bli_obj_free( &b );
bli_obj_free( &c );
//
// Example 2: Perform a symmetric rank-k update (syrk) operation.
@@ -164,6 +167,7 @@ int main( int argc, char** argv )
bli_obj_free( &c );
bli_obj_free( &a );
//
// Example 3: Perform a symmetric matrix-matrix multiply (symm) operation.
//
@@ -214,6 +218,7 @@ int main( int argc, char** argv )
bli_obj_free( &b );
bli_obj_free( &c );
//
// Example 4: Perform a triangular matrix-matrix multiply (trmm) operation.
//
@@ -251,12 +256,13 @@ int main( int argc, char** argv )
// b := alpha * a * b, where 'a' is triangular and lower-stored.
bli_trmm( side, alpha, &a, &b );
bli_printm( "x: after trmv", &b, "%4.1f", "" );
bli_printm( "x: after trmm", &b, "%4.1f", "" );
// Free the objects.
bli_obj_free( &a );
bli_obj_free( &b );
//
// Example 5: Perform a triangular solve with multiple right-hand sides
// (trsm) operation.

View File

@@ -43,11 +43,13 @@ int main( int argc, char** argv )
dim_t m, n;
inc_t rs, cs;
//
// This file demonstrates working with vector and matrix objects in the
// context of various utility operations.
//
//
// Example 1: Compute various vector norms.
//
@@ -73,7 +75,7 @@ int main( int argc, char** argv )
bli_printm( "x:", &x, "%4.1f", "" );
// Compute the one-norm of 'x'.
// Compute the one, infinity, and frobenius norms of 'x'.
bli_norm1v( &x, &norm1 );
bli_normiv( &x, &normi );
bli_normfv( &x, &normf );
@@ -84,9 +86,9 @@ int main( int argc, char** argv )
bli_printm( "y:", &y, "%4.1f", "" );
// Compute the one-norm of 'y'. Note that we can reuse the same scalars
// from before for computing norms of dcomplex matrices, since the real
// projection of dcomplex is double.
// Compute the one, infinity, and frobenius norms of 'y'. Note that we
// can reuse the same scalars from before for computing norms of
// dcomplex matrices, since the real projection of dcomplex is double.
bli_norm1v( &y, &norm1 );
bli_normiv( &y, &normi );
bli_normfv( &y, &normf );
@@ -95,6 +97,7 @@ int main( int argc, char** argv )
bli_printm( "y: infinity norm:", &normi, "%4.1f", "" );
bli_printm( "y: frobenius norm:", &normf, "%4.1f", "" );
//
// Example 2: Compute various matrix norms.
//
@@ -132,6 +135,7 @@ int main( int argc, char** argv )
bli_printm( "b: infinity norm:", &normi, "%4.1f", "" );
bli_printm( "b: frobenius norm:", &normf, "%4.1f", "" );
//
// Example 3: Make a real matrix explicitly symmetric (or Hermitian).
//
@@ -159,7 +163,7 @@ int main( int argc, char** argv )
// unstored triangle, making the matrix densely symmetric.
bli_mksymm( &c );
bli_printm( "c (after mksymm):", &c, "%4.1f", "" );
bli_printm( "c (after mksymm on lower triangle):", &c, "%4.1f", "" );
// Digression: Most people think only of complex matrices as being able
// to be complex. However, in BLIS, we define Hermitian operations on
@@ -182,11 +186,8 @@ int main( int argc, char** argv )
// imaginary elements to conjugate.
bli_mkherm( &d );
bli_printm( "d (after mkherm):", &d, "%4.1f", "" );
bli_printm( "d (after mkherm on lower triangle):", &d, "%4.1f", "" );
// Set the structure and uplo of 'd'.
bli_obj_set_struc( BLIS_HERMITIAN, &d );
bli_obj_set_uplo( BLIS_LOWER, &d );
//
// Example 4: Make a complex matrix explicitly symmetric or Hermitian.
@@ -235,6 +236,7 @@ int main( int argc, char** argv )
bli_printm( "f (after mkherm):", &f, "%4.1f", "" );
//
// Example 5: Make a real matrix explicitly triangular.
//

184
examples/tapi/00level1v.c Normal file
View File

@@ -0,0 +1,184 @@
/*
BLIS
An object-based framework for developing high-performance BLAS-like
libraries.
Copyright (C) 2014, The University of Texas
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of The University of Texas nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include "blis.h"
int main( int argc, char** argv )
{
double* x;
double* y;
double* z;
double* w;
double* a;
double alpha, beta, gamma;
dim_t m, n;
inc_t rs, cs;
// Initialize some basic constants.
double zero = 0.0;
double one = 1.0;
double minus_one = -1.0;
//
// This file demonstrates working with vectors and the level-1v
// operations.
//
//
// Example 1: Create vectors and then broadcast (copy) scalar
// values to all elements.
//
printf( "\n#\n# -- Example 1 --\n#\n\n" );
// Create a few vectors to work with. We make them all of the same length
// so that we can perform operations between them.
// NOTE: We've chosen to use row vectors here (1x4) instead of column
// vectors (4x1) to allow for easier reading of standard output (less
// scrolling).
m = 1; n = 4; rs = n; cs = 1;
x = malloc( m * n * sizeof( double ) );
y = malloc( m * n * sizeof( double ) );
z = malloc( m * n * sizeof( double ) );
w = malloc( m * n * sizeof( double ) );
a = malloc( m * n * sizeof( double ) );
// Let's initialize some scalars.
alpha = 2.0;
beta = 0.2;
gamma = 3.0;
printf( "alpha:\n%4.1f\n\n", alpha );
printf( "beta:\n%4.1f\n\n", beta );
printf( "gamma:\n%4.1f\n\n", gamma );
printf( "\n" );
bli_dsetv( BLIS_NO_CONJUGATE, n, &one, x, 1, NULL );
bli_dsetv( BLIS_NO_CONJUGATE, n, &alpha, y, 1, NULL );
bli_dsetv( BLIS_NO_CONJUGATE, n, &zero, z, 1, NULL );
// Note that we can use printv or printm to print vectors since vectors
// are also matrices. We choose to use printm because it honors the
// orientation of the vector (row or column) when printing, whereas
// printv always prints vectors as column vectors regardless of their
// they are 1 x n or n x 1.
bli_dprintm( "x := 1.0", m, n, x, rs, cs, "%4.1f", "" );
bli_dprintm( "y := alpha", m, n, y, rs, cs, "%4.1f", "" );
bli_dprintm( "z := 0.0", m, n, z, rs, cs, "%4.1f", "" );
//
// Example 2: Randomize a vector.
//
printf( "\n#\n# -- Example 2 --\n#\n\n" );
// Set a vector to random values.
bli_drandv( n, w, 1, NULL );
bli_dprintm( "x := randv()", m, n, w, rs, cs, "%4.1f", "" );
//
// Example 3: Perform various element-wise operations on vectors.
//
printf( "\n#\n# -- Example 3 --\n#\n\n" );
// Copy a vector.
bli_dcopyv( BLIS_NO_CONJUGATE, n, w, 1, a, 1, NULL );
bli_dprintm( "a := w", m, n, a, rs, cs, "%4.1f", "" );
// Add and subtract vectors.
bli_daddv( BLIS_NO_CONJUGATE, n, y, 1, a, 1, NULL );
bli_dprintm( "a := a + y", m, n, a, rs, cs, "%4.1f", "" );
bli_dsubv( BLIS_NO_CONJUGATE, n, w, 1, a, 1, NULL );
bli_dprintm( "a := a + w", m, n, a, rs, cs, "%4.1f", "" );
// Scale a vector (destructive).
bli_dscalv( BLIS_NO_CONJUGATE, n, &beta, a, 1, NULL );
bli_dprintm( "a := beta * a", m, n, a, rs, cs, "%4.1f", "" );
// Scale a vector (non-destructive).
bli_dscal2v( BLIS_NO_CONJUGATE, n, &gamma, a, 1, z, 1, NULL );
bli_dprintm( "z := gamma * a", m, n, z, rs, cs, "%4.1f", "" );
// Scale and accumulate between vectors.
bli_daxpyv( BLIS_NO_CONJUGATE, n, &alpha, w, 1, x, 1, NULL );
bli_dprintm( "x := x + alpha * w", m, n, x, rs, cs, "%4.1f", "" );
bli_dxpbyv( BLIS_NO_CONJUGATE, n, w, 1, &minus_one, x, 1, NULL );
bli_dprintm( "x := -1.0 * x + w", m, n, x, rs, cs, "%4.1f", "" );
// Invert a vector element-wise.
bli_dinvertv( n, y, 1, NULL );
bli_dprintm( "y := 1 / y", m, n, y, rs, cs, "%4.1f", "" );
// Swap two vectors.
bli_dswapv( n, x, 1, y, 1, NULL );
bli_dprintm( "x (after swapping with y)", m, n, x, rs, cs, "%4.1f", "" );
bli_dprintm( "y (after swapping with x)", m, n, y, rs, cs, "%4.1f", "" );
//
// Example 4: Perform contraction-like operations on vectors.
//
printf( "\n#\n# -- Example 4 --\n#\n\n" );
// Perform a dot product.
bli_ddotv( BLIS_NO_CONJUGATE, BLIS_NO_CONJUGATE, n, a, 1, z, 1, &gamma, NULL );
printf( "gamma := a * z (dot product):\n%5.2f\n\n", gamma );
// Perform an extended dot product.
bli_ddotxv( BLIS_NO_CONJUGATE, BLIS_NO_CONJUGATE, n, &alpha, a, 1, z, 1, &one, &gamma, NULL );
printf( "gamma := 1.0 * gamma + alpha * a * z (accumulate scaled dot product):\n%5.2f\n\n", gamma );
// Free the memory obtained via malloc().
free( x );
free( y );
free( z );
free( w );
free( z );
return 0;
}
// -----------------------------------------------------------------------------

219
examples/tapi/01level1m.c Normal file
View File

@@ -0,0 +1,219 @@
/*
BLIS
An object-based framework for developing high-performance BLAS-like
libraries.
Copyright (C) 2014, The University of Texas
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of The University of Texas nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include "blis.h"
int main( int argc, char** argv )
{
double* a;
double* b;
double* c;
double* d;
double* e;
double* f;
dcomplex* g;
dcomplex* h;
double alpha, beta, gamma;
dim_t m, n;
inc_t rs, cs;
// Initialize some basic constants.
double zero = 0.0;
double one = 1.0;
double minus_one = -1.0;
dcomplex minus_one_z = {-1.0, 0.0};
//
// This file demonstrates working with matrices and the level-1m
// operations.
//
//
// Example 1: Create matrices and then broadcast (copy) scalar
// values to all elements.
//
printf( "\n#\n# -- Example 1 --\n#\n\n" );
// Create a few matrices to work with. We make them all of the same
// dimensions so that we can perform operations between them.
m = 2; n = 3; rs = 1; cs = m;
a = malloc( m * n * sizeof( double ) );
b = malloc( m * n * sizeof( double ) );
c = malloc( m * n * sizeof( double ) );
d = malloc( m * n * sizeof( double ) );
e = malloc( m * n * sizeof( double ) );
// Let's initialize some scalars.
alpha = 2.0;
beta = 0.2;
gamma = 3.0;
printf( "alpha:\n%4.1f\n\n", alpha );
printf( "beta:\n%4.1f\n\n", beta );
printf( "gamma:\n%4.1f\n\n", gamma );
printf( "\n" );
// Matrices, like vectors, can set by "broadcasting" a constant to every
// element. Note that the second argument (0) is the diagonal offset.
// The diagonal offset is only used when the uplo value is something other
// than BLIS_DENSE (e.g. BLIS_LOWER or BLIS_UPPER).
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, n, &one, a, rs, cs, NULL );
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, n, &alpha, b, rs, cs, NULL );
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, n, &zero, c, rs, cs, NULL );
bli_dprintm( "a := 1.0", m, n, a, rs, cs, "%4.1f", "" );
bli_dprintm( "b := alpha", m, n, b, rs, cs, "%4.1f", "" );
bli_dprintm( "c := 0.0", m, n, c, rs, cs, "%4.1f", "" );
//
// Example 2: Randomize a matrix object.
//
printf( "\n#\n# -- Example 2 --\n#\n\n" );
bli_drandm( 0, BLIS_DENSE, m, n, e, rs, cs, NULL );
bli_dprintm( "e (randomized):", m, n, e, rs, cs, "%4.1f", "" );
//
// Example 3: Perform element-wise operations on matrices.
//
printf( "\n#\n# -- Example 3 --\n#\n\n" );
// Copy a matrix.
bli_dcopym( 0, BLIS_NONUNIT_DIAG, BLIS_DENSE, BLIS_NO_TRANSPOSE,
m, n, e, rs, cs, d, rs, cs, NULL );
bli_dprintm( "d := e", m, n, d, rs, cs, "%4.1f", "" );
// Add and subtract vectors.
bli_daddm( 0, BLIS_NONUNIT_DIAG, BLIS_DENSE, BLIS_NO_TRANSPOSE,
m, n, a, rs, cs, d, rs, cs, NULL );
bli_dprintm( "d := d + a", m, n, d, rs, cs, "%4.1f", "" );
bli_dsubm( 0, BLIS_NONUNIT_DIAG, BLIS_DENSE, BLIS_NO_TRANSPOSE,
m, n, a, rs, cs, e, rs, cs, NULL );
bli_dprintm( "e := e - a", m, n, e, rs, cs, "%4.1f", "" );
// Scale a matrix (destructive).
bli_dscalm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, n, &alpha, e, rs, cs, NULL );
bli_dprintm( "e := alpha * e", m, n, e, rs, cs, "%4.1f", "" );
// Scale a matrix (non-destructive).
bli_dscal2m( 0, BLIS_NONUNIT_DIAG, BLIS_DENSE, BLIS_NO_TRANSPOSE,
m, n, &beta, e, rs, cs, c, rs, cs, NULL );
bli_dprintm( "c := beta * e", m, n, c, rs, cs, "%4.1f", "" );
// Scale and accumulate between matrices.
bli_daxpym( 0, BLIS_NONUNIT_DIAG, BLIS_DENSE, BLIS_NO_TRANSPOSE,
m, n, &alpha, a, rs, cs, c, rs, cs, NULL );
bli_dprintm( "c := alpha * a", m, n, c, rs, cs, "%4.1f", "" );
//
// Example 4: Copy and transpose a matrix.
//
printf( "\n#\n# -- Example 4 --\n#\n\n" );
// Create an n-by-m matrix into which we can copy-transpose an m-by-n
// matrix.
f = malloc( n * m * sizeof( double ) );
dim_t rsf = 1, csf = n;
// Initialize all of 'f' to -1.0 to simulate junk values.
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
n, m, &minus_one, f, rsf, csf, NULL );
bli_dprintm( "e:", m, n, e, rs, cs, "%4.1f", "" );
bli_dprintm( "f (initial value):", n, m, f, rsf, csf, "%4.1f", "" );
// Copy 'e' to 'f', transposing 'e' in the process. Notice that we haven't
// modified any properties of 'd'. It's the source operand that matters
// when marking an operand for transposition, not the destination.
bli_dcopym( 0, BLIS_NONUNIT_DIAG, BLIS_DENSE, BLIS_TRANSPOSE,
n, m, e, rs, cs, f, rsf, csf, NULL );
bli_dprintm( "f (copied value):", n, m, f, rsf, csf, "%4.1f", "" );
//
// Example 5: Copy and Hermitian-transpose a matrix.
//
printf( "\n#\n# -- Example 5 --\n#\n\n" );
g = malloc( m * n * sizeof(dcomplex) );
h = malloc( n * m * sizeof(dcomplex) );
bli_zrandm( 0, BLIS_DENSE, m, n, g, rs, cs, NULL );
bli_zsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
n, m, &minus_one_z, h, rsf, csf, NULL );
bli_zprintm( "g:", m, n, g, rs, cs, "%4.1f", "" );
bli_zprintm( "h (initial value):", n, m, h, rsf, csf, "%4.1f", "" );
bli_zcopym( 0, BLIS_NONUNIT_DIAG, BLIS_DENSE, BLIS_CONJ_TRANSPOSE,
n, m, g, rs, cs, h, rsf, csf, NULL );
bli_zprintm( "h (copied value):", n, m, h, rsf, csf, "%4.1f", "" );
// Free the memory obtained via malloc().
free( a );
free( b );
free( c );
free( d );
free( e );
free( f );
free( g );
free( h );
return 0;
}
// -----------------------------------------------------------------------------

View File

@@ -0,0 +1,247 @@
/*
BLIS
An object-based framework for developing high-performance BLAS-like
libraries.
Copyright (C) 2014, The University of Texas
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of The University of Texas nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include "blis.h"
int main( int argc, char** argv )
{
double* a;
double* b;
double* c;
double* d;
double* e;
double* h;
dim_t m, n;
inc_t rs, cs;
// Initialize some basic constants.
double zero = 0.0;
double one = 1.0;
double minus_one = -1.0;
//
// This file demonstrates level-1m operations on structured matrices.
//
//
// Example 1: Initialize the upper triangle of a matrix to random values.
//
printf( "\n#\n# -- Example 1 --\n#\n\n" );
// Create a matrix to work with.
m = 5; n = 5; rs = 1; cs = m;
a = malloc( m * n * sizeof( double ) );
// Set the upper triangle to random values.
bli_drandm( 0, BLIS_UPPER, m, n, a, rs, cs, NULL );
bli_dprintm( "a: randomize upper part (lower part may contain garbage)",
m, n, a, rs, cs, "%4.1f", "" );
//
// Example 2: Initialize the upper triangle of a matrix to random values
// but also explicitly set the strictly lower triangle to zero.
//
printf( "\n#\n# -- Example 2 --\n#\n\n" );
// Create a matrix to work with.
m = 5; n = 5; rs = 1; cs = m;
b = malloc( m * n * sizeof( double ) );
// Set the upper triangle to random values.
bli_drandm( 0, BLIS_UPPER, m, n, b, rs, cs, NULL );
// Set the strictly lower triangle of 'b' to zero (by setting the lower
// triangle of 'bl' to zero).
bli_dsetm( BLIS_NO_CONJUGATE, -1, BLIS_NONUNIT_DIAG, BLIS_LOWER,
m, n, &zero, b, rs, cs, NULL );
bli_dprintm( "b: randomize upper part; set strictly lower part to 0.0)",
m, n, b, rs, cs, "%4.1f", "" );
// You may not see the effect of setting the strictly lower part to zero,
// since those values may already be zero (instead of random junk). So
// let's set it to something you'll notice, like -1.0.
bli_dsetm( BLIS_NO_CONJUGATE, -1, BLIS_NONUNIT_DIAG, BLIS_LOWER,
m, n, &minus_one, b, rs, cs, NULL );
bli_dprintm( "b: randomize upper part; set strictly lower part to -1.0)",
m, n, b, rs, cs, "%4.1f", "" );
//
// Example 3: Copy the lower triangle of an existing matrix to a newly
// created (but otherwise uninitialized) matrix.
//
printf( "\n#\n# -- Example 3 --\n#\n\n" );
// Create a matrix to work with.
m = 5; n = 5; rs = 1; cs = m;
c = malloc( m * n * sizeof( double ) );
bli_dcopym( 0, BLIS_NONUNIT_DIAG, BLIS_LOWER, BLIS_NO_TRANSPOSE,
m, n, b, rs, cs, c, rs, cs, NULL );
bli_dprintm( "c: copy lower part of b (upper part may contain garbage)",
m, n, c, rs, cs, "%4.1f", "" );
bli_dcopym( 0, BLIS_NONUNIT_DIAG, BLIS_LOWER, BLIS_NO_TRANSPOSE,
m, n, b, rs, cs, a, rs, cs, NULL );
bli_dprintm( "a: copy lower triangle of b to upper triangular a",
m, n, a, rs, cs, "%4.1f", "" );
//
// Example 4: Copy the lower triangle of an existing object into the
// upper triangle of an existing object.
//
printf( "\n#\n# -- Example 4 --\n#\n\n" );
// Create a matrix to work with.
m = 5; n = 5; rs = 1; cs = m;
d = malloc( m * n * sizeof( double ) );
// Let's start by setting entire destination matrix to zero.
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, n, &zero, d, rs, cs, NULL );
bli_dprintm( "d: initial value (all zeros)",
m, n, d, rs, cs, "%4.1f", "" );
// Let's change a few values of b manually so we can later see the full
// effect of the transposition.
bli_dsetijm( 2.0, 0.0, 2, 0, b, rs, cs );
bli_dsetijm( 3.0, 0.0, 3, 0, b, rs, cs );
bli_dsetijm( 4.0, 0.0, 4, 0, b, rs, cs );
bli_dsetijm( 3.1, 0.0, 2, 1, b, rs, cs );
bli_dsetijm( 3.2, 0.0, 3, 2, b, rs, cs );
bli_dprintm( "b:",
m, n, b, rs, cs, "%4.1f", "" );
bli_dcopym( 0, BLIS_NONUNIT_DIAG, BLIS_LOWER, BLIS_TRANSPOSE,
m, n, b, rs, cs, d, rs, cs, NULL );
bli_dprintm( "d: transpose of lower triangle of b copied to d",
m, n, d, rs, cs, "%4.1f", "" );
//
// Example 5: Create a rectangular matrix (m > n) with a lower trapezoid
// containing random values, then set the strictly upper
// triangle to zeros.
//
printf( "\n#\n# -- Example 5 --\n#\n\n" );
// Create a matrix to work with.
m = 6; n = 4; rs = 1; cs = m;
e = malloc( m * n * sizeof( double ) );
// Initialize the entire matrix to -1.0 to simulate junk values.
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, n, &minus_one, e, rs, cs, NULL );
bli_dprintm( "e: initial value (all -1.0)",
m, n, e, rs, cs, "%4.1f", "" );
// Randomize the lower trapezoid.
bli_drandm( 0, BLIS_LOWER, m, n, e, rs, cs, NULL );
bli_dprintm( "e: after lower trapezoid randomized",
m, n, e, rs, cs, "%4.1f", "" );
// Set the upper triangle to zero.
bli_dsetm( BLIS_NO_CONJUGATE, 1, BLIS_NONUNIT_DIAG, BLIS_UPPER,
m, n, &zero, e, rs, cs, NULL );
bli_dprintm( "e: after upper triangle set to zero",
m, n, e, rs, cs, "%4.1f", "" );
//
// Example 6: Create an upper Hessenberg matrix of random values and then
// set the "unstored" values to zero.
//
printf( "\n#\n# -- Example 6 --\n#\n\n" );
// Create a matrix to work with.
m = 5; n = 5; rs = 1; cs = m;
h = malloc( m * n * sizeof( double ) );
// Initialize the entire matrix to -1.0 to simulate junk values.
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, n, &minus_one, h, rs, cs, NULL );
bli_dprintm( "h: initial value (all -1.0)",
m, n, h, rs, cs, "%4.1f", "" );
// Randomize the elements on and above the first subdiagonal.
bli_drandm( -1, BLIS_UPPER, m, n, h, rs, cs, NULL );
bli_dprintm( "h: after randomizing above first subdiagonal",
m, n, h, rs, cs, "%4.1f", "" );
// Set the region strictly below the first subdiagonal (on or below
// the second subdiagonal) to zero.
bli_dsetm( BLIS_NO_CONJUGATE, -2, BLIS_NONUNIT_DIAG, BLIS_LOWER,
m, n, &zero, h, rs, cs, NULL );
bli_dprintm( "h: after setting elements below first subdiagonal to zero",
m, n, h, rs, cs, "%4.1f", "" );
// Free the memory obtained via malloc().
free( a );
free( b );
free( c );
free( d );
free( e );
free( h );
return 0;
}
// -----------------------------------------------------------------------------

319
examples/tapi/03level2.c Normal file
View File

@@ -0,0 +1,319 @@
/*
BLIS
An object-based framework for developing high-performance BLAS-like
libraries.
Copyright (C) 2014, The University of Texas
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of The University of Texas nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include "blis.h"
int main( int argc, char** argv )
{
double* a;
double* x;
double* y;
double* b;
double* d;
double alpha, beta;
dim_t m, n;
inc_t rs, cs;
// Initialize some basic constants.
double zero = 0.0;
double one = 1.0;
double two = 2.0;
double minus_one = -1.0;
//
// This file demonstrates level-2 operations.
//
//
// Example 1: Perform a general rank-1 update (ger) operation.
//
printf( "\n#\n# -- Example 1 --\n#\n\n" );
// Create some matrix and vector operands to work with.
m = 4; n = 5; rs = 1; cs = m;
a = malloc( m * n * sizeof( double ) );
x = malloc( m * 1 * sizeof( double ) );
y = malloc( 1 * n * sizeof( double ) );
// Let's initialize some scalars.
alpha = 1.0;
// Initialize vectors 'x' and 'y'.
bli_drandv( m, x, 1, NULL );
bli_dsetv( BLIS_NO_CONJUGATE, n, &minus_one, y, 1, NULL );
// Initialize 'a' to 1.0.
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, n, &one, a, rs, cs, NULL );
bli_dprintm( "x: set to random values", m, 1, x, 1, m, "%4.1f", "" );
bli_dprintm( "y: set to -1.0", 1, n, y, n, 1, "%4.1f", "" );
bli_dprintm( "a: intial value", m, n, a, rs, cs, "%4.1f", "" );
// a := a + alpha * x * y, where 'a' is general.
bli_dger( BLIS_NO_CONJUGATE, BLIS_NO_CONJUGATE,
m, n, &alpha, x, 1, y, 1, a, rs, cs, NULL );
bli_dprintm( "a: after ger", m, n, a, rs, cs, "%4.1f", "" );
// Free the memory obtained via malloc().
free( a );
free( x );
free( y );
//
// Example 2: Perform a general matrix-vector multiply (gemv) operation.
//
printf( "\n#\n# -- Example 2 --\n#\n\n" );
// Create some matrix and vector operands to work with.
m = 4; n = 5; rs = 1; cs = m;
a = malloc( m * n * sizeof( double ) );
x = malloc( 1 * n * sizeof( double ) );
y = malloc( 1 * m * sizeof( double ) );
// Set the scalars to use.
alpha = 1.0;
beta = 1.0;
// Initialize vectors 'x' and 'y'.
bli_dsetv( BLIS_NO_CONJUGATE, n, &one, x, 1, NULL );
bli_dsetv( BLIS_NO_CONJUGATE, m, &zero, y, 1, NULL );
// Randomize 'a'.
bli_drandm( 0, BLIS_DENSE, m, n, a, rs, cs, NULL );
bli_dprintm( "a: randomized", m, n, a, rs, cs, "%4.1f", "" );
bli_dprintm( "x: set to 1.0", 1, n, x, n, 1, "%4.1f", "" );
bli_dprintm( "y: intial value", 1, m, y, m, 1, "%4.1f", "" );
// y := beta * y + alpha * a * x, where 'a' is general.
bli_dgemv( BLIS_NO_TRANSPOSE, BLIS_NO_CONJUGATE,
m, n, &alpha, a, rs, cs, x, 1, &beta, y, 1, NULL );
bli_dprintm( "y: after gemv", 1, m, y, m, 1, "%4.1f", "" );
// Free the memory obtained via malloc().
free( a );
free( x );
free( y );
//
// Example 3: Perform a symmetric rank-1 update (syr) operation.
//
printf( "\n#\n# -- Example 3 --\n#\n\n" );
// Create some matrix and vector operands to work with.
m = 5; rs = 1; cs = 5;
a = malloc( m * m * sizeof( double ) );
x = malloc( 1 * m * sizeof( double ) );
// Set alpha.
alpha = 1.0;
// Initialize vector 'x'.
bli_drandv( m, x, 1, NULL );
// Zero out all of matrix 'a'. This is optional, but will avoid possibly
// displaying junk values in the unstored triangle.
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, m, &zero, a, rs, cs, NULL );
// Randomize the lower triangle of 'a'.
bli_drandm( 0, BLIS_LOWER, m, m, a, rs, cs, NULL );
bli_dprintm( "x: set to random values", 1, m, x, m, 1, "%4.1f", "" );
bli_dprintm( "a: initial value (zeros in upper triangle)", m, m, a, 1, m, "%4.1f", "" );
// a := a + alpha * x * x^T, where 'a' is symmetric and lower-stored.
bli_dsyr( BLIS_LOWER, BLIS_NO_CONJUGATE, m, &alpha, x, 1, a, rs, cs, NULL );
bli_dprintm( "a: after syr", m, m, a, 1, m, "%4.1f", "" );
// Free the memory obtained via malloc().
free( a );
free( x );
//
// Example 4: Perform a symmetric matrix-vector multiply (symv) operation.
//
printf( "\n#\n# -- Example 4 --\n#\n\n" );
// Create some matrix and vector operands to work with.
m = 5;; rs = 1; cs = m;
a = malloc( m * m * sizeof( double ) );
x = malloc( 1 * m * sizeof( double ) );
y = malloc( 1 * m * sizeof( double ) );
// Set the scalars to use.
alpha = 1.0;
beta = 1.0;
// Initialize vectors 'x' and 'y'.
bli_dsetv( BLIS_NO_CONJUGATE, m, &one, x, 1, NULL );
bli_dsetv( BLIS_NO_CONJUGATE, m, &zero, y, 1, NULL );
// Zero out all of matrix 'a'. This is optional, but will avoid possibly
// displaying junk values in the unstored triangle.
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, m, &zero, a, rs, cs, NULL );
// Randomize 'a'.
bli_drandm( 0, BLIS_UPPER, m, m, a, rs, cs, NULL );
bli_dprintm( "a: randomized (zeros in lower triangle)", m, m, a, rs, cs, "%4.1f", "" );
bli_dprintm( "x: set to 1.0", 1, m, x, m, 1, "%4.1f", "" );
bli_dprintm( "y: intial value", 1, m, y, m, 1, "%4.1f", "" );
// y := beta * y + alpha * a * x, where 'a' is symmetric and upper-stored.
bli_dsymv( BLIS_UPPER, BLIS_NO_TRANSPOSE, BLIS_NO_CONJUGATE,
m, &alpha, a, rs, cs, x, 1, &beta, y, 1, NULL );
bli_dprintm( "y: after symv", 1, m, y, m, 1, "%4.1f", "" );
// Free the memory obtained via malloc().
free( a );
free( x );
free( y );
//
// Example 5: Perform a triangular matrix-vector multiply (trmv) operation.
//
printf( "\n#\n# -- Example 5 --\n#\n\n" );
// Create some matrix and vector operands to work with.
m = 5;; rs = 1; cs = m;
a = malloc( m * m * sizeof( double ) );
x = malloc( 1 * m * sizeof( double ) );
// Set the scalars to use.
alpha = 1.0;
// Initialize vector 'x'.
bli_dsetv( BLIS_NO_CONJUGATE, m, &one, x, 1, NULL );
// Zero out all of matrix 'a'. This is optional, but will avoid possibly
// displaying junk values in the unstored triangle.
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, m, &zero, a, rs, cs, NULL );
// Randomize 'a'.
bli_drandm( 0, BLIS_LOWER, m, m, a, rs, cs, NULL );
bli_dprintm( "a: randomized (zeros in upper triangle)", m, m, a, rs, cs, "%4.1f", "" );
bli_dprintm( "x: intial value", 1, m, x, m, 1, "%4.1f", "" );
// x := alpha * a * x, where 'a' is triangular and lower-stored.
bli_dtrmv( BLIS_LOWER, BLIS_NO_TRANSPOSE, BLIS_NONUNIT_DIAG,
m, &alpha, a, rs, cs, x, 1, NULL );
bli_dprintm( "x: after trmv", 1, m, x, m, 1, "%4.1f", "" );
// Free the memory obtained via malloc().
free( a );
free( x );
//
// Example 6: Perform a triangular solve (trsv) operation.
//
printf( "\n#\n# -- Example 6 --\n#\n\n" );
// Create some matrix and vector operands to work with.
m = 5;; rs = 1; cs = m;
a = malloc( m * m * sizeof( double ) );
b = malloc( 1 * m * sizeof( double ) );
y = malloc( 1 * m * sizeof( double ) );
// Set the scalars to use.
alpha = 1.0;
// Initialize vector 'x'.
bli_dsetv( BLIS_NO_CONJUGATE, m, &one, b, 1, NULL );
// Zero out all of matrix 'a'. This is optional, but will avoid possibly
// displaying junk values in the unstored triangle.
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, m, &zero, a, rs, cs, NULL );
// Randomize 'a'.
bli_drandm( 0, BLIS_LOWER, m, m, a, rs, cs, NULL );
// Load the diagonal. By setting the diagonal to something of greater
// absolute value than the off-diagonal elements, we increase the odds
// that the matrix is not singular (singular matrices have no inverse).
d = malloc( m * m * sizeof( double ) );
bli_dsetd( BLIS_NO_CONJUGATE, 0, m, m, &two, d, 1, m, NULL );
bli_daddd( 0, BLIS_NONUNIT_DIAG, BLIS_NO_TRANSPOSE,
m, m, d, 1, m, a, rs, cs, NULL );
bli_dprintm( "a: randomized (zeros in upper triangle)", m, m, a, rs, cs, "%4.1f", "" );
bli_dprintm( "b: intial value", 1, m, b, m, 1, "%4.1f", "" );
// x := alpha * a * x, where 'a' is triangular and lower-stored.
bli_dtrsv( BLIS_LOWER, BLIS_NO_TRANSPOSE, BLIS_NONUNIT_DIAG,
m, &alpha, a, rs, cs, x, 1, NULL );
bli_dprintm( "b: after trsv", 1, m, b, m, 1, "%4.1f", "" );
// We can confirm the solution by comparing the product of a and x to the
// original value of b.
bli_dcopyv( BLIS_NO_TRANSPOSE, m, b, 1, y, 1, NULL );
bli_dtrmv( BLIS_LOWER, BLIS_NO_TRANSPOSE, BLIS_NONUNIT_DIAG,
m, &alpha, a, rs, cs, y, 1, NULL );
bli_dprintm( "y: should equal initial value of b", 1, m, y, m, 1, "%4.1f", "" );
// Free the memory obtained via malloc().
free( a );
free( b );
free( y );
return 0;
}

349
examples/tapi/04level3.c Normal file
View File

@@ -0,0 +1,349 @@
/*
BLIS
An object-based framework for developing high-performance BLAS-like
libraries.
Copyright (C) 2014, The University of Texas
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of The University of Texas nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include "blis.h"
int main( int argc, char** argv )
{
dim_t m, n, k;
inc_t rsa, csa;
inc_t rsb, csb;
inc_t rsc, csc;
double* a;
double* b;
double* c;
double* d;
double alpha, beta;
// Initialize some basic constants.
double zero = 0.0;
double one = 1.0;
double two = 2.0;
//
// This file demonstrates level-3 operations.
//
//
// Example 1: Perform a general matrix-matrix multiply (gemm) operation.
//
printf( "\n#\n# -- Example 1 --\n#\n\n" );
// Create some matrix and vector operands to work with.
m = 4; n = 5; k = 3;
rsc = 1; csc = m;
rsa = 1; csa = m;
rsb = 1; csb = k;
c = malloc( m * n * sizeof( double ) );
a = malloc( m * k * sizeof( double ) );
b = malloc( k * n * sizeof( double ) );
// Set the scalars to use.
alpha = 1.0;
beta = 1.0;
// Initialize the matrix operands.
bli_drandm( 0, BLIS_DENSE, m, k, a, rsa, csa, NULL );
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
k, n, &one, b, rsb, csb, NULL );
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, n, &zero, c, rsc, csc, NULL );
bli_dprintm( "a: randomized", m, k, a, rsa, csa, "%4.1f", "" );
bli_dprintm( "b: set to 1.0", k, n, b, rsb, csb, "%4.1f", "" );
bli_dprintm( "c: initial value", m, n, c, rsc, csc, "%4.1f", "" );
// c := beta * c + alpha * a * b, where 'a', 'b', and 'c' are general.
bli_dgemm( BLIS_NO_TRANSPOSE, BLIS_NO_TRANSPOSE,
m, n, k, &alpha, a, rsa, csa, b, rsb, csb,
&beta, c, rsc, csc, NULL );
bli_dprintm( "c: after gemm", m, n, c, rsc, csc, "%4.1f", "" );
// Free the memory obtained via malloc().
free( a );
free( b );
free( c );
//
// Example 1b: Perform a general matrix-matrix multiply (gemm) operation
// with the left input operand (matrix A) transposed.
//
printf( "\n#\n# -- Example 1b --\n#\n\n" );
// Create some matrix and vector operands to work with.
m = 4; n = 5; k = 3;
rsc = 1; csc = m;
rsa = 1; csa = k;
rsb = 1; csb = k;
c = malloc( m * n * sizeof( double ) );
a = malloc( k * m * sizeof( double ) );
b = malloc( k * n * sizeof( double ) );
// Set the scalars to use.
alpha = 1.0;
beta = 1.0;
// Initialize the matrix operands.
bli_drandm( 0, BLIS_DENSE, k, m, a, rsa, csa, NULL );
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
k, n, &one, b, rsb, csb, NULL );
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, n, &zero, c, rsc, csc, NULL );
bli_dprintm( "a: randomized", k, m, a, rsa, csa, "%4.1f", "" );
bli_dprintm( "b: set to 1.0", k, n, b, rsb, csb, "%4.1f", "" );
bli_dprintm( "c: initial value", m, n, c, rsc, csc, "%4.1f", "" );
// c := beta * c + alpha * a^T * b, where 'a', 'b', and 'c' are general.
bli_dgemm( BLIS_TRANSPOSE, BLIS_NO_TRANSPOSE,
m, n, k, &alpha, a, rsa, csa, b, rsb, csb,
&beta, c, rsc, csc, NULL );
bli_dprintm( "c: after gemm", m, n, c, rsc, csc, "%4.1f", "" );
// Free the memory obtained via malloc().
free( a );
free( b );
free( c );
//
// Example 2: Perform a symmetric rank-k update (syrk) operation.
//
printf( "\n#\n# -- Example 2 --\n#\n\n" );
// Create some matrix and vector operands to work with.
m = 5; k = 3;
rsc = 1; csc = m;
rsa = 1; csa = m;
c = malloc( m * m * sizeof( double ) );
a = malloc( m * k * sizeof( double ) );
// Set the scalars to use.
alpha = 1.0;
// Initialize the matrix operands.
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, m, &zero, c, rsc, csc, NULL );
bli_drandm( 0, BLIS_DENSE, m, k, a, rsa, csa, NULL );
// Randomize the lower triangle of 'c'.
bli_drandm( 0, BLIS_LOWER, m, n, c, rsc, csc, NULL );
bli_dprintm( "a: set to random values", m, k, a, rsa, csa, "%4.1f", "" );
bli_dprintm( "c: initial value (zeros in upper triangle)", m, m, c, rsc, csc, "%4.1f", "" );
// c := c + alpha * a * a^T, where 'c' is symmetric and lower-stored.
bli_dsyrk( BLIS_LOWER, BLIS_NO_TRANSPOSE,
m, k, &alpha, a, rsa, csa,
&beta, c, rsc, csc, NULL );
bli_dprintm( "c: after syrk", m, m, c, rsc, csc, "%4.1f", "" );
// Free the memory obtained via malloc().
free( a );
free( c );
//
// Example 3: Perform a symmetric matrix-matrix multiply (symm) operation.
//
printf( "\n#\n# -- Example 3 --\n#\n\n" );
// Create some matrix and vector operands to work with.
m = 5; n = 6;
rsc = 1; csc = m;
rsa = 1; csa = m;
rsb = 1; csb = m;
c = malloc( m * n * sizeof( double ) );
a = malloc( m * m * sizeof( double ) );
b = malloc( m * n * sizeof( double ) );
// Set the scalars to use.
alpha = 1.0;
beta = 1.0;
// Initialize matrices 'b' and 'c'.
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, n, &one, b, rsb, csb, NULL );
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, n, &zero, c, rsc, csc, NULL );
// Zero out all of matrix 'a'. This is optional, but will avoid possibly
// displaying junk values in the unstored triangle.
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, m, &zero, a, rsa, csa, NULL );
// Randomize the upper triangle of 'a'.
bli_drandm( 0, BLIS_UPPER, m, m, a, rsa, csa, NULL );
bli_dprintm( "a: randomized (zeros in lower triangle)", m, m, a, rsa, csa, "%4.1f", "" );
bli_dprintm( "b: set to 1.0", m, n, b, rsb, csb, "%4.1f", "" );
bli_dprintm( "c: initial value", m, n, c, rsc, csc, "%4.1f", "" );
// c := beta * c + alpha * a * b, where 'a' is symmetric and upper-stored.
bli_dsymm( BLIS_LEFT, BLIS_UPPER, BLIS_NO_CONJUGATE, BLIS_NO_TRANSPOSE,
m, n, &alpha, a, rsa, csa, b, rsb, csb,
&beta, c, rsc, csc, NULL );
bli_dprintm( "c: after symm", m, n, c, rsc, csc, "%4.1f", "" );
// Free the memory obtained via malloc().
free( a );
free( b );
free( c );
//
// Example 4: Perform a triangular matrix-matrix multiply (trmm) operation.
//
printf( "\n#\n# -- Example 4 --\n#\n\n" );
// Create some matrix and vector operands to work with.
m = 5; n = 4;
rsa = 1; csa = m;
rsb = 1; csb = m;
a = malloc( m * m * sizeof( double ) );
b = malloc( m * n * sizeof( double ) );
// Set the scalars to use.
alpha = 1.0;
// Initialize matrix 'b'.
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, n, &one, b, rsb, csb, NULL );
// Zero out all of matrix 'a'. This is optional, but will avoid possibly
// displaying junk values in the unstored triangle.
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, m, &zero, a, rsa, csa, NULL );
// Randomize the lower triangle of 'a'.
bli_drandm( 0, BLIS_LOWER, m, m, a, rsa, csa, NULL );
bli_dprintm( "a: randomized (zeros in upper triangle)", m, m, a, rsa, csa, "%4.1f", "" );
bli_dprintm( "b: initial value", m, n, b, rsb, csb, "%4.1f", "" );
// b := alpha * a * b, where 'a' is triangular and lower-stored.
bli_dtrmm( BLIS_LEFT, BLIS_LOWER, BLIS_NONUNIT_DIAG, BLIS_NO_TRANSPOSE,
m, n, &alpha, a, rsa, csa, b, rsb, csb, NULL );
bli_dprintm( "b: after trmm", m, n, b, rsb, csb, "%4.1f", "" );
// Free the memory obtained via malloc().
free( a );
free( b );
//
// Example 5: Perform a triangular solve with multiple right-hand sides
// (trsm) operation.
//
printf( "\n#\n# -- Example 5 --\n#\n\n" );
// Create some matrix and vector operands to work with.
m = 5; n = 4;
rsa = 1; csa = m;
rsb = 1; csb = m;
rsc = 1; csc = m;
a = malloc( m * m * sizeof( double ) );
b = malloc( m * n * sizeof( double ) );
c = malloc( m * n * sizeof( double ) );
// Set the scalars to use.
alpha = 1.0;
// Initialize matrix 'b'.
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, n, &one, b, rsb, csb, NULL );
// Zero out all of matrix 'a'. This is optional, but will avoid possibly
// displaying junk values in the unstored triangle.
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, m, &zero, a, rsa, csa, NULL );
// Randomize the lower triangle of 'a'.
bli_drandm( 0, BLIS_LOWER, m, m, a, rsa, csa, NULL );
// Load the diagonal. By setting the diagonal to something of greater
// absolute value than the off-diagonal elements, we increase the odds
// that the matrix is not singular (singular matrices have no inverse).
d = malloc( m * m * sizeof( double ) );
bli_dsetd( BLIS_NO_CONJUGATE, 0, m, m, &two, d, 1, m, NULL );
bli_daddd( 0, BLIS_NONUNIT_DIAG, BLIS_NO_TRANSPOSE,
m, m, d, 1, m, a, rsa, csa, NULL );
bli_dprintm( "a: randomized (zeros in upper triangle)", m, m, a, rsa, csa, "%4.1f", "" );
bli_dprintm( "b: initial value", m, n, b, rsb, csb, "%4.1f", "" );
// solve a * x = alpha * b, where 'a' is triangular and lower-stored, and
// overwrite b with the solution matrix x.
bli_dtrsm( BLIS_LEFT, BLIS_LOWER, BLIS_NONUNIT_DIAG, BLIS_NO_TRANSPOSE,
m, n, &alpha, a, rsa, csa, b, rsb, csb, NULL );
bli_dprintm( "b: after trmm", m, n, b, rsb, csb, "%4.1f", "" );
// We can confirm the solution by comparing the product of a and x to the
// original value of b.
bli_dcopym( 0, BLIS_NONUNIT_DIAG, BLIS_DENSE, BLIS_NO_TRANSPOSE,
m, n, b, rsb, csb, c, rsc, csc, NULL );
bli_dtrmm( BLIS_LEFT, BLIS_LOWER, BLIS_NONUNIT_DIAG, BLIS_NO_TRANSPOSE,
m, n, &alpha, a, rsa, csa, c, rsc, csc, NULL );
bli_dprintm( "c: should equal initial value of b", m, n, c, rsc, csc, "%4.1f", "" );
// Free the memory obtained via malloc().
free( a );
free( b );
free( c );
free( d );
return 0;
}
// -----------------------------------------------------------------------------

282
examples/tapi/05util.c Normal file
View File

@@ -0,0 +1,282 @@
/*
BLIS
An object-based framework for developing high-performance BLAS-like
libraries.
Copyright (C) 2014, The University of Texas
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of The University of Texas nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include "blis.h"
int main( int argc, char** argv )
{
double* x;
dcomplex* y;
double* a;
dcomplex* b;
double* c;
double* d;
dcomplex* e;
dcomplex* f;
double* g;
double norm1, normi, normf;
dim_t m, n;
inc_t rs, cs;
// Initialize some basic constants.
double minus_one = -1.0;
dcomplex minus_one_z = { -1.0, 0.0 };
//
// This file demonstrates working with vector and matrices in the
// context of various utility operations.
//
//
// Example 1: Compute various vector norms.
//
printf( "\n#\n# -- Example 1 --\n#\n\n" );
// Create a few matrices to work with.
m = 1; n = 5; rs = 5; cs = 1;
x = malloc( m * n * sizeof( double ) );
y = malloc( m * n * sizeof( dcomplex ) );
// Initialize the vectors to random values.
bli_drandv( n, x, 1, NULL );
bli_zrandv( n, y, 1, NULL );
bli_dprintm( "x", m, n, x, rs, cs, "%4.1f", "" );
// Compute the one, infinity, and frobenius norms of 'x'. Note that when
// computing the norm alpha of a vector 'x', the datatype of alpha must be
// equal to the real projection of the datatype of 'x'.
bli_dnorm1v( n, x, 1, &norm1, NULL );
bli_dnormiv( n, x, 1, &normi, NULL );
bli_dnormfv( n, x, 1, &normf, NULL );
bli_dprintm( "x: 1-norm:", 1, 1, &norm1, rs, cs, "%4.1f", "" );
bli_dprintm( "x: infinity norm:", 1, 1, &normi, rs, cs, "%4.1f", "" );
bli_dprintm( "x: frobenius norm:", 1, 1, &normf, rs, cs, "%4.1f", "" );
bli_zprintm( "y", m, n, y, rs, cs, "%4.1f", "" );
// Compute the one, infinity, and frobenius norms of 'y'. Note that we
// can reuse the same scalars from before for computing norms of
// dcomplex matrices, since the real projection of dcomplex is double.
bli_znorm1v( n, y, 1, &norm1, NULL );
bli_znormiv( n, y, 1, &normi, NULL );
bli_znormfv( n, y, 1, &normf, NULL );
bli_dprintm( "y: 1-norm:", 1, 1, &norm1, 1, 1, "%4.1f", "" );
bli_dprintm( "y: infinity norm:", 1, 1, &normi, 1, 1, "%4.1f", "" );
bli_dprintm( "y: frobenius norm:", 1, 1, &normf, 1, 1, "%4.1f", "" );
//
// Example 2: Compute various matrix norms.
//
printf( "\n#\n# -- Example 2 --\n#\n\n" );
// Create a few matrices to work with.
m = 5; n = 6; rs = 1; cs = m;
a = malloc( m * n * sizeof( double ) );
b = malloc( m * n * sizeof( dcomplex ) );
// Initialize the matrices to random values.
bli_drandm( 0, BLIS_DENSE, m, n, a, rs, cs, NULL );
bli_zrandm( 0, BLIS_DENSE, m, n, b, rs, cs, NULL );
bli_dprintm( "a:", m, n, a, rs, cs, "%4.1f", "" );
// Compute the one-norm of 'a'.
bli_dnorm1m( 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, n, a, rs, cs, &norm1, NULL );
bli_dnormim( 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, n, a, rs, cs, &normi, NULL );
bli_dnormfm( 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, n, a, rs, cs, &normf, NULL );
bli_dprintm( "a: 1-norm:", 1, 1, &norm1, 1, 1, "%4.1f", "" );
bli_dprintm( "a: infinity norm:", 1, 1, &normi, 1, 1, "%4.1f", "" );
bli_dprintm( "a: frobenius norm:", 1, 1, &normf, 1, 1, "%4.1f", "" );
bli_zprintm( "b:", m, n, b, rs, cs, "%4.1f", "" );
// Compute the one-norm of 'b'.
bli_znorm1m( 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, n, b, rs, cs, &norm1, NULL );
bli_znormim( 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, n, b, rs, cs, &normi, NULL );
bli_znormfm( 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, n, b, rs, cs, &normf, NULL );
bli_dprintm( "a: 1-norm:", 1, 1, &norm1, 1, 1, "%4.1f", "" );
bli_dprintm( "a: infinity norm:", 1, 1, &normi, 1, 1, "%4.1f", "" );
bli_dprintm( "a: frobenius norm:", 1, 1, &normf, 1, 1, "%4.1f", "" );
//
// Example 3: Make a real matrix explicitly symmetric (or Hermitian).
//
printf( "\n#\n# -- Example 3 --\n#\n\n" );
// Create a few matrices to work with.
m = 4; n = 4; rs = 1; cs = m;
c = malloc( m * m * sizeof( double ) );
d = malloc( m * m * sizeof( double ) );
// Initialize all of 'c' to -1.0 to simulate junk values.
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, m, &minus_one, c, rs, cs, NULL );
// Randomize the lower triangle of 'c'.
bli_drandm( 0, BLIS_LOWER, m, m, c, rs, cs, NULL );
bli_dprintm( "c (initial state):", m, m, c, rs, cs, "%4.1f", "" );
// mksymm on a real matrix transposes the stored triangle into the
// unstored triangle, making the matrix densely symmetric.
bli_dmksymm( BLIS_LOWER, m, c, rs, cs, NULL );
bli_dprintm( "c (after mksymm on lower triangle):", m, m, c, rs, cs, "%4.1f", "" );
// Digression: Most people think only of complex matrices as being able
// to be complex. However, in BLIS, we define Hermitian operations on
// real matrices, too--they are simply equivalent to the corresponding
// symmetric operation. For example, when we make a real matrix explicitly
// Hermitian, the result is indistinguishable from making it symmetric.
// Initialize all of 'd' to -1.0 to simulate junk values.
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, m, &minus_one, d, rs, cs, NULL );
// Randomize the lower triangle of 'd'.
bli_drandm( 0, BLIS_LOWER, m, m, d, rs, cs, NULL );
bli_dprintm( "d (initial state):", m, m, d, rs, cs, "%4.1f", "" );
// mkherm on a real matrix behaves the same as mksymm, as there are no
// imaginary elements to conjugate.
bli_dmkherm( BLIS_LOWER, m, d, rs, cs, NULL );
bli_dprintm( "c (after mkherm on lower triangle):", m, m, d, rs, cs, "%4.1f", "" );
//
// Example 4: Make a complex matrix explicitly symmetric or Hermitian.
//
printf( "\n#\n# -- Example 4 --\n#\n\n" );
// Create a few matrices to work with.
m = 4; n = 4; rs = 1; cs = m;
e = malloc( m * m * sizeof( dcomplex ) );
f = malloc( m * m * sizeof( dcomplex ) );
// Initialize all of 'e' to -1.0 to simulate junk values.
bli_zsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, m, &minus_one_z, e, rs, cs, NULL );
// Randomize the upper triangle of 'e'.
bli_zrandm( 0, BLIS_UPPER, m, m, e, rs, cs, NULL );
bli_zprintm( "e (initial state):", m, m, e, rs, cs, "%4.1f", "" );
// mksymm on a complex matrix transposes the stored triangle into the
// unstored triangle.
bli_zmksymm( BLIS_UPPER, m, e, rs, cs, NULL );
bli_zprintm( "e (after mksymm on lower triangle):", m, m, e, rs, cs, "%4.1f", "" );
// Initialize all of 'f' to -1.0 to simulate junk values.
bli_zsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, m, &minus_one_z, f, rs, cs, NULL );
// Randomize the upper triangle of 'd'.
bli_zrandm( 0, BLIS_UPPER, m, m, f, rs, cs, NULL );
bli_zprintm( "f (initial state):", m, m, f, rs, cs, "%4.1f", "" );
// mkherm on a real matrix behaves the same as mksymm, as there are no
// imaginary elements to conjugate.
bli_zmkherm( BLIS_UPPER, m, f, rs, cs, NULL );
bli_zprintm( "f (after mkherm on lower triangle):", m, m, f, rs, cs, "%4.1f", "" );
//
// Example 5: Make a real matrix explicitly triangular.
//
printf( "\n#\n# -- Example 5 --\n#\n\n" );
// Create a few matrices to work with.
m = 5; n = 5; rs = 1; cs = m;
g = malloc( m * m * sizeof( double ) );
// Initialize all of 'g' to -1.0 to simulate junk values.
bli_dsetm( BLIS_NO_CONJUGATE, 0, BLIS_NONUNIT_DIAG, BLIS_DENSE,
m, m, &minus_one, g, rs, cs, NULL );
// Randomize the lower triangle of 'g'.
bli_drandm( 0, BLIS_LOWER, m, m, g, rs, cs, NULL );
bli_dprintm( "g (initial state):", m, m, g, rs, cs, "%4.1f", "" );
// mktrim does not explicitly copy any data, since presumably the stored
// triangle already contains the data of interest. However, mktrim does
// explicitly writes zeros to the unstored region.
bli_dmktrim( BLIS_LOWER, m, g, rs, cs, NULL );
bli_dprintm( "g (after mktrim):", m, m, g, rs, cs, "%4.1f", "" );
// Free the memory obtained via malloc().
free( x );
free( y );
free( a );
free( b );
free( c );
free( d );
free( e );
free( f );
free( g );
return 0;
}
// -----------------------------------------------------------------------------

178
examples/tapi/Makefile Normal file
View File

@@ -0,0 +1,178 @@
#
#
# BLIS
# An object-based framework for developing high-performance BLAS-like
# libraries.
#
# Copyright (C) 2014, The University of Texas at Austin
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# - Neither the name of The University of Texas at Austin nor the names
# of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
#
# Makefile
#
# Field G. Van Zee
#
# Makefile for BLIS testsuite.
#
#
# --- Makefile PHONY target definitions ----------------------------------------
#
.PHONY: all bin clean run
#
# --- Distribution path override -----------------------------------------------
#
# Override the default DIST_PATH and BUILD_PATH values so that make can find
# the source distribution and build location.
DIST_PATH := ../..
BUILD_PATH := ../..
#
# --- Include common makefile definitions --------------------------------------
#
# Define the name of the common makefile fragment.
COMMON_MK_FILE := common.mk
# Construct the path to the makefile configuration file that was generated by
# the configure script.
COMMON_MK_PATH := $(DIST_PATH)/$(COMMON_MK_FILE)
# Include the common makefile fragment.
-include $(COMMON_MK_PATH)
# Detect whether we actually got the common makefile fragment. If we didn't,
# then it is likely that the user has not yet generated it (via configure).
#ifeq ($(strip $(COMMON_MK_INCLUDED)),yes)
#COMMON_MK_PRESENT := yes
#else
#COMMON_MK_PRESENT := no
#endif
#
# --- General build definitions ------------------------------------------------
#
TEST_SRC_PATH := .
TEST_OBJ_PATH := .
# Gather all local object files.
TEST_OBJS := $(sort $(patsubst $(TEST_SRC_PATH)/%.c, \
$(TEST_OBJ_PATH)/%.o, \
$(wildcard $(TEST_SRC_PATH)/*.c)))
# Use the "framework" CFLAGS for the configuration family.
CFLAGS := $(call get-frame-cflags-for,$(CONFIG_NAME))
# Add local header paths to CFLAGS
CFLAGS += -I$(TEST_SRC_PATH)
# Locate the libblis library to which we will link.
LIBBLIS_LINK := $(BUILD_PATH)/$(LIBBLIS_LINK)
# Binary executable name.
TEST_BINS := 00level1v.x \
01level1m.x \
02level1m_diag.x \
03level2.x \
04level3.x \
05util.x
#
# --- Targets/rules ------------------------------------------------------------
#
# --- Primary targets ---
all: bin
bin: $(TEST_BINS)
# --- Environment check rules ---
#
#check-env: check-env-make-defs check-env-fragments check-env-mk
#
#check-env-mk:
#ifeq ($(CONFIG_MK_PRESENT),no)
# $(error Cannot proceed: config.mk not detected! Run configure first)
#endif
#
#check-env-fragments: check-env-mk
#ifeq ($(MAKEFILE_FRAGMENTS_PRESENT),no)
# $(error Cannot proceed: makefile fragments not detected! Run configure first)
#endif
#
#check-env-make-defs: check-env-fragments
#ifeq ($(MAKE_DEFS_MK_PRESENT),no)
# $(error Cannot proceed: make_defs.mk not detected! Invalid configuration)
#endif
# --Object file rules --
$(TEST_OBJ_PATH)/%.o: $(TEST_SRC_PATH)/%.c $(LIBBLIS_LINK)
ifeq ($(ENABLE_VERBOSE),yes)
$(CC) $(CFLAGS) -c $< -o $@
else
@echo "Compiling $@"
@$(CC) $(CFLAGS) -c $< -o $@
endif
# -- Executable file rules --
%.x: %.o $(LIBBLIS_LINK)
ifeq ($(ENABLE_VERBOSE),yes)
$(LINKER) $< $(LIBBLIS_LINK) $(LDFLAGS) -o $@
else
@echo "Linking $@ against '$(LIBBLIS_LINK) $(LDFLAGS)'"
@$(LINKER) $< $(LIBBLIS_LINK) $(LDFLAGS) -o $@
endif
# -- Test run rules --
#run: $(TEST_BIN)
# ./$(TEST_BIN)
# -- Clean rules --
clean:
- $(RM_F) $(TEST_OBJS) $(TEST_BINS)

29
examples/tapi/README Normal file
View File

@@ -0,0 +1,29 @@
BLIS typed API examples
-----------------------
This directory contains several files, each containing various pieces of
example code that demonstrate core functionality of the typed API in BLIS.
These example files should be thought of collectively like a tutorial, and
therefore it is recommended to start from the beginning (the file that
starts in '00').
You can build all of the examples by simply running 'make' from this
directory. (You can also run 'make clean'.) The makefile assumes that
you've already configured and built (but not necessarily installed) BLIS
two directories up, in "../..". Once the executable files have been built,
we recommend reading the code in one terminal window alongside the
executable output in another. This will help you see the effects of each
section of code.
This tutorial is not exhaustive or complete; many typed API functions
were omitted (mostly for brevity's sake) and thus more examples could be
written. If you've found typed functionality in BLIS and are unsure how to
use it, or if you are unsure of what additional functionality is present in
BLIS, please feel free to join and then start a discussion on the blis-devel
mailing list [1].
Thanks for your interest in BLIS!
[1] https://groups.google.com/d/forum/blis-devel