1 /*
3 BLIS
4 An object-based framework for developing high-performance BLAS-like
5 libraries.
7 Copyright (C) 2014, The University of Texas at Austin
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are
11 met:
12 - Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
14 - Redistributions in binary form must reproduce the above copyright
15 notice, this list of conditions and the following disclaimer in the
16 documentation and/or other materials provided with the distribution.
17 - Neither the name of The University of Texas at Austin nor the names
18 of its contributors may be used to endorse or promote products
19 derived from this software without specific prior written permission.
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
35 #include "blis.h"
37 void bli_hemm_front( side_t side,
38 obj_t* alpha,
39 obj_t* a,
40 obj_t* b,
41 obj_t* beta,
42 obj_t* c,
43 gemm_t* cntl )
44 {
45 obj_t a_local;
46 obj_t b_local;
47 obj_t c_local;
49 // Check parameters.
50 if ( bli_error_checking_is_enabled() )
51 bli_hemm_check( side, alpha, a, b, beta, c );
53 // If alpha is zero, scale by beta and return.
54 if ( bli_obj_equals( alpha, &BLIS_ZERO ) )
55 {
56 bli_scalm( beta, c );
57 return;
58 }
59 if ( bli_obj_equals( beta, &BLIS_ZERO ) )
60 {
61 bli_setm( beta, c );
62 }
64 // Alias A, B, and C in case we need to apply transformations.
65 bli_obj_alias_to( *a, a_local );
66 bli_obj_alias_to( *b, b_local );
67 bli_obj_alias_to( *c, c_local );
69 // An optimization: If C is stored by rows and the micro-kernel prefers
70 // contiguous columns, or if C is stored by columns and the micro-kernel
71 // prefers contiguous rows, transpose the entire operation to allow the
72 // micro-kernel to access elements of C in its preferred manner.
73 if (
74 ( bli_obj_is_row_stored( c_local ) &&
75 bli_func_prefers_contig_cols( bli_obj_datatype( c_local ),
76 cntl_gemm_ukrs( cntl ) ) ) ||
77 ( bli_obj_is_col_stored( c_local ) &&
78 bli_func_prefers_contig_rows( bli_obj_datatype( c_local ),
79 cntl_gemm_ukrs( cntl ) ) )
80 )
81 {
82 bli_toggle_side( side );
83 bli_obj_toggle_conj( a_local );
84 bli_obj_induce_trans( b_local );
85 bli_obj_induce_trans( c_local );
86 }
88 // Swap A and B if multiplying A from the right so that "B" contains
89 // the Hermitian matrix.
90 if ( bli_is_right( side ) )
91 {
92 bli_obj_swap( a_local, b_local );
93 }
95 gemm_thrinfo_t** infos = bli_create_gemm_thrinfo_paths();
96 dim_t n_threads = thread_num_threads( infos[0] );
98 // Invoke the internal back-end.
99 bli_level3_thread_decorator( n_threads,
100 (level3_int_t) bli_gemm_int,
101 alpha,
102 &a_local,
103 &b_local,
104 beta,
105 &c_local,
106 (void*) cntl,
107 (void**) infos );
109 bli_gemm_thrinfo_free_paths( infos, n_threads );
110 }