File: GB_AxB_dot2_meta.c

package info (click to toggle)
suitesparse-graphblas 7.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 67,112 kB
  • sloc: ansic: 1,072,243; cpp: 8,081; sh: 512; makefile: 506; asm: 369; python: 125; awk: 10
file content (315 lines) | stat: -rw-r--r-- 11,036 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
//------------------------------------------------------------------------------
// GB_AxB_dot2_meta: C=A'*B, C<M>=A'*B or C<!M>=A'*B via dot products
//------------------------------------------------------------------------------

// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

//------------------------------------------------------------------------------

#define GB_DOT2

#include "GB_unused.h"
#include "GB_AxB_dot_cij.h"

{

    //--------------------------------------------------------------------------
    // get A, B, and C
    //--------------------------------------------------------------------------

    // A and B are never hypersparse.  If they are hypersparse on input, they
    // are converted to hyper_shallow form first, and the C matrix has smaller
    // dimensions.  The C bitmap/full matrix is converted back into a sparse or
    // hypersparse matrix when done.

    int64_t cnvals = 0 ;

    ASSERT (GB_IS_BITMAP (C) || GB_IS_FULL (C)) ;
    int8_t *restrict Cb = C->b ;
    const int64_t cvlen = C->vlen ;
    const bool C_is_full = (Cb == NULL) ;

    const int64_t *restrict Bp = B->p ;
    const int8_t  *restrict Bb = B->b ;
    const int64_t *restrict Bi = B->i ;
    const bool B_is_bitmap = GB_IS_BITMAP (B) ;
    const bool B_is_sparse = GB_IS_SPARSE (B) ;
    const bool B_is_full   = GB_as_if_full (B) ;
    const bool B_iso = B->iso ;
    ASSERT (!GB_IS_HYPERSPARSE (B)) ;
    #define B_is_hyper false

    const int64_t *restrict Ap = A->p ;
    const int8_t  *restrict Ab = A->b ;
    const int64_t *restrict Ai = A->i ;

    const bool A_is_bitmap = GB_IS_BITMAP (A) ;
    const bool A_is_sparse = GB_IS_SPARSE (A) ;
    const bool A_is_full   = GB_as_if_full (A) ;
    const bool A_iso = A->iso ;
    ASSERT (!GB_IS_HYPERSPARSE (A)) ;
    #define A_is_hyper false

    #if !GB_A_IS_PATTERN
    const GB_ATYPE *restrict Ax = (GB_ATYPE *) A->x ;
    #endif
    #if !GB_B_IS_PATTERN
    const GB_BTYPE *restrict Bx = (GB_BTYPE *) B->x ;
    #endif
    #if !GB_IS_ANY_PAIR_SEMIRING
          GB_CTYPE *restrict Cx = (GB_CTYPE *) C->x ;
    #endif

    const int64_t vlen = A->vlen ;

    const int ntasks = naslice * nbslice ;

    //--------------------------------------------------------------------------
    // C=A'*B, C<M>=A'*B, or C<!M>=A'*B via dot products
    //--------------------------------------------------------------------------

    if (M == NULL)
    { 

        //----------------------------------------------------------------------
        // C = A'*B or C=A*B
        //----------------------------------------------------------------------

        #undef GB_MASK_IS_PRESENT

        if (A_not_transposed)
        {
            // C=A*B where A is bitmap or full, and B is sparse
            #define GB_A_NOT_TRANSPOSED
            ASSERT (A_is_bitmap || GB_IS_FULL (A)) ;
            ASSERT (B_is_sparse) ;
            if (C_is_full)
            {
                // C=A*B via dot products, where A is full and B is sparse,
                // and C is full
                ASSERT (GB_as_if_full (A)) ;
                #undef  GB_C_IS_FULL
                #define GB_C_IS_FULL   1
                #define GB_A_IS_SPARSE 0
                #define GB_A_IS_HYPER  0
                #define GB_A_IS_BITMAP 0
                #define GB_A_IS_FULL   1
                #define GB_B_IS_SPARSE 1
                #define GB_B_IS_HYPER  0
                #define GB_B_IS_BITMAP 0
                #define GB_B_IS_FULL   0
                #include "GB_AxB_dot2_template.c"
            }
            else if (A_is_bitmap)
            { 
                // C=A*B via dot products, where A is bitmap and B is sparse,
                // and C is bitmap
                #undef  GB_C_IS_FULL
                #define GB_C_IS_FULL   0
                #define GB_A_IS_SPARSE 0
                #define GB_A_IS_HYPER  0
                #define GB_A_IS_BITMAP 1
                #define GB_A_IS_FULL   0
                #define GB_B_IS_SPARSE 1
                #define GB_B_IS_HYPER  0
                #define GB_B_IS_BITMAP 0
                #define GB_B_IS_FULL   0
                #include "GB_AxB_dot2_template.c"
            }
            else
            { 
                // C=A*B via dot products, where A is full and B is sparse,
                // and C is bitmap
                #undef  GB_C_IS_FULL
                #define GB_C_IS_FULL   0
                #define GB_A_IS_SPARSE 0
                #define GB_A_IS_HYPER  0
                #define GB_A_IS_BITMAP 0
                #define GB_A_IS_FULL   1
                #define GB_B_IS_SPARSE 1
                #define GB_B_IS_HYPER  0
                #define GB_B_IS_BITMAP 0
                #define GB_B_IS_FULL   0
                #include "GB_AxB_dot2_template.c"
            } 
            #undef GB_A_NOT_TRANSPOSED
        }
        else if (C_is_full)
        {
            // C = A'*B, via dot2 method, where A is implicitly transposed,
            // C is full.  3 cases:
            #undef  GB_C_IS_FULL
            #define GB_C_IS_FULL   1
            if (A_is_full && B_is_full)
            {
                // A full, B full
                #define GB_A_IS_SPARSE 0
                #define GB_A_IS_HYPER  0
                #define GB_A_IS_BITMAP 0
                #define GB_A_IS_FULL   1
                #define GB_B_IS_SPARSE 0
                #define GB_B_IS_HYPER  0
                #define GB_B_IS_BITMAP 0
                #define GB_B_IS_FULL   1
                #include "GB_AxB_dot2_template.c"
            }
            else if (A_is_full)
            { 
                // A full, B sparse
                ASSERT (B_is_sparse) ;
                #define GB_A_IS_SPARSE 0
                #define GB_A_IS_HYPER  0
                #define GB_A_IS_BITMAP 0
                #define GB_A_IS_FULL   1
                #define GB_B_IS_SPARSE 1
                #define GB_B_IS_HYPER  0
                #define GB_B_IS_BITMAP 0
                #define GB_B_IS_FULL   0
                #include "GB_AxB_dot2_template.c"
            }
            else
            { 
                // A sparse, B full
                ASSERT (A_is_sparse) ;
                ASSERT (B_is_full) ;
                #define GB_A_IS_SPARSE 1
                #define GB_A_IS_HYPER  0
                #define GB_A_IS_BITMAP 0
                #define GB_A_IS_FULL   0
                #define GB_B_IS_SPARSE 0
                #define GB_B_IS_HYPER  0
                #define GB_B_IS_BITMAP 0
                #define GB_B_IS_FULL   1
                #include "GB_AxB_dot2_template.c"
            }
            #undef  GB_C_IS_FULL
            #define GB_C_IS_FULL   0
        }
        else
        {
            // C = A'*B, via dot2 method, where A is implicitly transposed,
            // C is bitmap
            #include "GB_meta16_factory.c"
        }

    }
    else
    {

        //----------------------------------------------------------------------
        // C<M>=A'*B or C<!M>=A'*B
        //----------------------------------------------------------------------

        // 12 possible cases of the mask are handled:

        // if M is not complemented (Mask_comp is false): 4 cases
        // M can be bitmap or full, not sparse or hyper (dot3 handles that)
        // M can be structural or valued

        // if M is complemented (Mask_comp is true): 8 cases
        // M can be sparse, hyper, bitmap, or full
        // M can be structural or valued

        const int8_t *restrict Mb = M->b ;
        const bool M_is_bitmap = GB_IS_BITMAP (M) ;
        const bool M_is_full = GB_IS_FULL (M) ;

        #if ( GB_IS_ANY_MONOID )
        if (B_is_bitmap && A_is_sparse && M_is_bitmap && Mask_struct
            && Mask_comp)
        { 

            //------------------------------------------------------------------
            // C<#M,struct> = A'*B, special case
            //------------------------------------------------------------------

            // GB_ANY_SPECIALIZED is defined if the following conditions hold:
            // semirings: all built-in semirings with the ANY monoid
            // A: sparse
            // B: bitmap
            // M: bitmap
            // Mask_comp: true
            // Mask_struct: true

            GBURBLE ("(specialized) ") ;
            #define GB_ANY_SPECIALIZED
            #define GB_MASK_IS_PRESENT
            #define GB_A_IS_SPARSE 1
            #define GB_A_IS_HYPER  0
            #define GB_A_IS_BITMAP 0
            #define GB_A_IS_FULL   0
            #define GB_B_IS_SPARSE 0
            #define GB_B_IS_SPARSE 0
            #define GB_B_IS_BITMAP 1
            #define GB_B_IS_FULL   0
            #include "GB_AxB_dot2_template.c"
            #undef  GB_ANY_SPECIALIZED
            #undef GB_MASK_IS_PRESENT

        }
        else
        #endif
        { 

            //------------------------------------------------------------------
            // C<#M>=A'*B or C<#!M>=A*B
            //------------------------------------------------------------------

            const GB_void *restrict Mx = (GB_void *)
                (Mask_struct ? NULL : (M->x)) ;
            const size_t msize = M->type->size ;

            #define GB_MASK_IS_PRESENT

            if (A_not_transposed)
            {
                // C<#M>=A*B where A is bitmap or full, and B is sparse
                #define GB_A_NOT_TRANSPOSED
                ASSERT (A_is_bitmap || GB_IS_FULL (A)) ;
                ASSERT (B_is_sparse) ;
                if (A_is_bitmap)
                { 
                    // C<#M>=A*B via dot products, A is bitmap and B is sparse
                    #define GB_A_IS_SPARSE 0
                    #define GB_A_IS_HYPER  0
                    #define GB_A_IS_BITMAP 1
                    #define GB_A_IS_FULL   0
                    #define GB_B_IS_SPARSE 1
                    #define GB_B_IS_HYPER  0
                    #define GB_B_IS_BITMAP 0
                    #define GB_B_IS_FULL   0
                    #include "GB_AxB_dot2_template.c"
                }
                else
                { 
                    // C<#M>=A*B via dot products, A is full and B is sparse
                    #define GB_A_IS_SPARSE 0
                    #define GB_A_IS_HYPER  0
                    #define GB_A_IS_BITMAP 0
                    #define GB_A_IS_FULL   1
                    #define GB_B_IS_SPARSE 1
                    #define GB_B_IS_HYPER  0
                    #define GB_B_IS_BITMAP 0
                    #define GB_B_IS_FULL   0
                    #include "GB_AxB_dot2_template.c"
                } 
                #undef GB_A_NOT_TRANSPOSED
            }
            else
            {
                // C<#>M = A'*B, via dot2 method, A is implicitly transposed
                #include "GB_meta16_factory.c"
            }

            #undef GB_MASK_IS_PRESENT
        }
    }

    C->nvals = cnvals ;
}

#undef A_is_hyper
#undef B_is_hyper
#undef GB_DOT2