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_trmm3_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_trmm3_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 }
60 // Alias A, B, and C so we can tweak the objects if necessary.
61 bli_obj_alias_to( *a, a_local );
62 bli_obj_alias_to( *b, b_local );
63 bli_obj_alias_to( *c, c_local );
65 // We do not explicitly implement the cases where A is transposed.
66 // However, we can still handle them. Specifically, if A is marked as
67 // needing a transposition, we simply induce a transposition. This
68 // allows us to only explicitly implement the no-transpose cases. Once
69 // the transposition is induced, the correct algorithm will be called,
70 // since, for example, an algorithm over a transposed lower triangular
71 // matrix A moves in the same direction (forwards) as a non-transposed
72 // upper triangular matrix. And with the transposition induced, the
73 // matrix now appears to be upper triangular, so the upper triangular
74 // algorithm will grab the correct partitions, as if it were upper
75 // triangular (with no transpose) all along.
76 if ( bli_obj_has_trans( a_local ) )
77 {
78 bli_obj_induce_trans( a_local );
79 bli_obj_set_onlytrans( BLIS_NO_TRANSPOSE, a_local );
80 }
82 #if 0
84 // If A is being multiplied from the right, transpose all operands
85 // so that we can perform the computation as if A were being multiplied
86 // from the left.
87 if ( bli_is_right( side ) )
88 {
89 bli_toggle_side( side );
90 bli_obj_induce_trans( a_local );
91 bli_obj_induce_trans( b_local );
92 bli_obj_induce_trans( c_local );
93 }
95 #else
97 // An optimization: If C is stored by rows and the micro-kernel prefers
98 // contiguous columns, or if C is stored by columns and the micro-kernel
99 // prefers contiguous rows, transpose the entire operation to allow the
100 // micro-kernel to access elements of C in its preferred manner.
101 if (
102 ( bli_obj_is_row_stored( c_local ) &&
103 bli_func_prefers_contig_cols( bli_obj_datatype( c_local ),
104 cntl_gemm_ukrs( cntl ) ) ) ||
105 ( bli_obj_is_col_stored( c_local ) &&
106 bli_func_prefers_contig_rows( bli_obj_datatype( c_local ),
107 cntl_gemm_ukrs( cntl ) ) )
108 )
109 {
110 bli_toggle_side( side );
111 bli_obj_induce_trans( a_local );
112 bli_obj_induce_trans( b_local );
113 bli_obj_induce_trans( c_local );
114 }
116 // If A is being multiplied from the right, swap A and B so that
117 // the matrix will actually be on the right.
118 if ( bli_is_right( side ) )
119 {
120 bli_obj_swap( a_local, b_local );
121 }
123 #endif
125 // Set each alias as the root object.
126 // NOTE: We MUST wait until we are done potentially swapping the objects
127 // before setting the root fields!
128 bli_obj_set_as_root( a_local );
129 bli_obj_set_as_root( b_local );
130 bli_obj_set_as_root( c_local );
133 trmm_thrinfo_t** infos = bli_create_trmm_thrinfo_paths( FALSE );
134 dim_t n_threads = thread_num_threads( infos[0] );
136 // Invoke the internal back-end.
137 bli_level3_thread_decorator( n_threads,
138 (level3_int_t) bli_trmm_int,
139 alpha,
140 &a_local,
141 &b_local,
142 beta,
143 &c_local,
144 (void*) cntl,
145 (void**) infos );
147 bli_trmm_thrinfo_free_paths( infos, n_threads );
148 }