1 /*
3 BLIS
4 An object-based framework for developing high-performance BLAS-like
5 libraries.
7 Copyright (C) 2014, The University of Texas
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 nor the names of its
18 contributors may be used to endorse or promote products derived
19 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 #ifndef BLIS_DMA_H
36 #define BLIS_DMA_H
38 /*
39 * EDMA Pool
40 */
41 struct dma_s
42 {
43 bool_t edma_status;
44 void** edma_handle;
45 dim_t num_channels;
46 dim_t top_index;
47 };
48 typedef struct dma_s dma_t;
50 /*
51 * Control Leaf for DMA
52 */
53 struct dmam_s
54 {
55 impl_t impl_type;
56 varnum_t var_num;
57 blksz_t* mc;
58 blksz_t* nc;
59 membuf_t dma_buf_type; //target level buffer
60 };
61 typedef struct dmam_s dmam_t;
63 /*
64 * Thread info for DMA
65 */
66 struct dmam_thrinfo_s //implements thrinfo_t
67 {
68 thread_comm_t* ocomm; //The thread communicator for the other threads sharing the same work at this level
69 dim_t ocomm_id; //Our thread id within that thread comm
70 thread_comm_t* icomm; //The thread communicator for the other threads sharing the same work at this level
71 dim_t icomm_id; //Our thread id within that thread comm
73 dim_t n_way; //Number of distinct caucuses used to parallelize the loop
74 dim_t work_id; //What we're working on
75 };
76 typedef struct dmam_thrinfo_s dmam_thrinfo_t;
78 dmam_t* bli_dmam_cntl_obj_create( impl_t impl_type,
79 varnum_t var_num,
80 blksz_t* mc,
81 blksz_t* nc,
82 membuf_t pack_buf_type );
84 #define bli_obj_alias_for_dma( a, b ) \
85 { \
86 bli_obj_init_basic_shallow_copy_of( a, b ); \
87 \
88 /*(b).pack_mem = (a).pack_mem; \
89 (b).m_padded = (a).m_padded; \
90 (b).n_padded = (a).n_padded; \
91 (b).ps = (a).ps; \
92 (b).pd = (a).pd; */\
93 }
95 #define bli_obj_dma_mem( obj ) \
96 \
97 ( &((obj).dma_mem) )
99 #define bli_obj_edma_handle( obj ) \
100 \
101 ( &((obj).edma_handle) )
103 #define bli_edma_handle_set_NULL(obj) \
104 { \
105 (obj).edma_handle = NULL; \
106 }
108 #define bli_obj_alias_with_dma(a, b) \
109 { \
110 bli_obj_alias_to( a, b ); \
111 &((b).edma_handle) = &((a).edma_handle); \
112 }
114 #define bli_obj_init_dma( obj_p ) \
115 { \
116 mem_t* pack_mem = bli_obj_pack_mem( *obj_p ); \
117 mem_t* dma_mem = bli_obj_dma_mem( *obj_p ); \
118 \
119 bli_mem_set_buffer( NULL, pack_mem ); \
120 bli_mem_set_buffer( NULL, dma_mem ); \
121 bli_edma_handle_set_NULL( *obj_p ); \
122 }
123 //#define bli_obj_init_dma( obj_p ) \
124 //{ \
125 // mem_t* dma_mem = bli_obj_dma_mem( *obj_p ); \
126 //\
127 // bli_mem_set_buffer( NULL, dma_mem ); \
128 //}
132 #define cntl_sub_dmam_b( cntl ) cntl->sub_dmam_b
133 #define cntl_sub_dmam_a( cntl ) cntl->sub_dmam_a
134 #define cntl_sub_dmam_c( cntl ) cntl->sub_dmam_c
136 #define bli_obj_release_dma( obj_p , cntl ) \
137 { \
138 mem_t* dma_mem = bli_obj_dma_mem( *(obj_p) ); \
139 if ( bli_mem_is_alloc( dma_mem ) && cntl != NULL ) \
140 bli_mem_release( dma_mem ); \
141 }
143 // Functions to initialize the EDMA and EDMA channels
144 void bli_dma_init (void);
145 void bli_dma_init_pool(gint_t edma_status,
146 gint_t num_channels,
147 EdmaMgr_Handle* pool_edma_handles,
148 dma_t * dma_pool);
150 void bli_dma_channel_acquire(EdmaMgr_Handle* edma_handle, dim_t core_id);
151 void bli_dma_channel_release(EdmaMgr_Handle edma_handle, dim_t core_id);
153 void bli_dmam_wait(obj_t* p, dmam_t* cntl, dmam_thrinfo_t* thread);
154 void bli_obj_release_edma_handle(obj_t* p);
156 void bli_dma_finalize(void);
158 /*
159 * Checks the parameters, and initializes the destination obj_t with parameters from the source, and allocate
160 * memory for the destination buffer.
161 */
162 void bli_dmam_init( obj_t* a,
163 obj_t* p,
164 dmam_t* cntl);
166 void bli_dmam_init_check(obj_t* a,
167 obj_t* p,
168 dmam_t* cntl);
170 void bli_dmam_int( obj_t* a,
171 obj_t* p,
172 dmam_t* cntl,
173 dmam_thrinfo_t* thread );
175 void bli_dma_var1( obj_t* a,
176 obj_t* p,
177 dmam_thrinfo_t* thread );
181 #endif //BLIS_DMA_H