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 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
|
//------------------------------------------------------------------------------
// 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-2025, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
#define GB_DOT2
#include "include/GB_unused.h"
#include "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 ;
#ifdef GB_JIT_KERNEL
#define C_is_full GB_C_IS_FULL
#else
const bool C_is_full = (Cb == NULL) ;
#endif
GB_Bp_DECLARE (Bp, const) ; GB_Bp_PTR (Bp, B) ;
GB_Bi_DECLARE (Bi, const) ; GB_Bi_PTR (Bi, B) ;
const int8_t *restrict Bb = B->b ;
#ifdef GB_JIT_KERNEL
#define B_is_bitmap GB_B_IS_BITMAP
#define B_is_sparse GB_B_IS_SPARSE
#define B_is_full GB_B_IS_FULL
#define B_iso GB_B_IS_ISO
#else
const bool B_is_bitmap = GB_IS_BITMAP (B) ;
const bool B_is_sparse = GB_IS_SPARSE (B) ;
const bool B_is_full = GB_IS_FULL (B) ;
const bool B_iso = B->iso ;
const bool Bi_is_32 = B->i_is_32 ;
#define GB_Bi_IS_32 Bi_is_32
#endif
ASSERT (!GB_IS_HYPERSPARSE (B)) ;
#define B_is_hyper false
GB_Ap_DECLARE (Ap, const) ; GB_Ap_PTR (Ap, A) ;
GB_Ai_DECLARE (Ai, const) ; GB_Ai_PTR (Ai, A) ;
const int8_t *restrict Ab = A->b ;
#ifdef GB_JIT_KERNEL
#define A_is_bitmap GB_A_IS_BITMAP
#define A_is_sparse GB_A_IS_SPARSE
#define A_is_full GB_A_IS_FULL
#define A_iso GB_A_IS_ISO
#else
const bool A_is_bitmap = GB_IS_BITMAP (A) ;
const bool A_is_sparse = GB_IS_SPARSE (A) ;
const bool A_is_full = GB_IS_FULL (A) ;
const bool A_iso = A->iso ;
const bool Ai_is_32 = A->i_is_32 ;
#define GB_Ai_IS_32 Ai_is_32
#endif
ASSERT (!GB_IS_HYPERSPARSE (A)) ;
#define A_is_hyper false
#if !GB_A_IS_PATTERN
const GB_A_TYPE *restrict Ax = (GB_A_TYPE *) A->x ;
#endif
#if !GB_B_IS_PATTERN
const GB_B_TYPE *restrict Bx = (GB_B_TYPE *) B->x ;
#endif
#if !GB_IS_ANY_PAIR_SEMIRING
GB_C_TYPE *restrict Cx = (GB_C_TYPE *) C->x ;
#endif
const int64_t vlen = A->vlen ;
const int ntasks = naslice * nbslice ;
//--------------------------------------------------------------------------
// C<#>M=A'*B, C<#M>=A*B via dot products
//--------------------------------------------------------------------------
#ifdef GB_JIT_KERNEL
#define M_is_bitmap GB_M_IS_BITMAP
#define M_is_full GB_M_IS_FULL
#define Mask_struct GB_MASK_STRUCT
#define Mask_comp GB_MASK_COMP
const int8_t *restrict Mb = (M == NULL) ? NULL : M->b ;
const GB_M_TYPE *restrict Mx = (M == NULL) ? NULL :
((GB_M_TYPE *) (Mask_struct ? NULL : (M->x))) ;
GB_DECLARE_TERMINAL_CONST (zterminal) ;
#define GB_META16
#include "include/GB_meta16_definitions.h"
#include "template/GB_AxB_dot2_template.c"
#else
if (M == NULL)
{
//----------------------------------------------------------------------
// C=A'*B or C=A*B, where C is bitmap or full, no mask is present
//----------------------------------------------------------------------
// mask is not present
#undef GB_NO_MASK
#define GB_NO_MASK 1
ASSERT (GB_IS_BITMAP (C) || GB_IS_FULL (C)) ;
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_IS_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 "template/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 "template/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 "template/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 "template/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 "template/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 "template/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 "template/GB_meta16_factory.c"
}
}
else
{
//----------------------------------------------------------------------
// C<#M>=A'*B or C<#M>=A*B, where C is always bitmap
//----------------------------------------------------------------------
// mask is present and C is always bitmap
#undef GB_NO_MASK
#define GB_NO_MASK 0
ASSERT (GB_IS_BITMAP (C)) ;
// 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 (and transposed)
// B: bitmap
// M: bitmap
// Mask_comp: true
// Mask_struct: true
ASSERT (!A_not_transposed) ; // C<#M>=A'*B is being computed
#define GB_ANY_SPECIALIZED
#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 1
#define GB_B_IS_FULL 0
#include "template/GB_AxB_dot2_template.c"
#undef GB_ANY_SPECIALIZED
}
else
#endif
{
//------------------------------------------------------------------
// C<#M>=A'*B or C<#!M>=A*B
//------------------------------------------------------------------
const GB_M_TYPE *restrict Mx = (GB_M_TYPE *)
(Mask_struct ? NULL : (M->x)) ;
const size_t msize = M->type->size ;
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 "template/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 "template/GB_AxB_dot2_template.c"
}
#undef GB_A_NOT_TRANSPOSED
}
else
{
// C<#>M = A'*B, via dot2 method, A is implicitly transposed
#include "template/GB_meta16_factory.c"
}
}
}
#endif
C->nvals = cnvals ;
}
#undef A_is_hyper
#undef B_is_hyper
#undef GB_DOT2
#undef GB_NO_MASK
|