(git:5a3db73)
Loading...
Searching...
No Matches
dbm_multiply.c File Reference
#include "dbm_multiply.h"
#include "../offload/offload_mempool.h"
#include "../offload/offload_runtime.h"
#include "dbm_hyperparams.h"
#include "dbm_internal.h"
#include "dbm_library.h"
#include "dbm_multiply_comm.h"
#include "dbm_multiply_cpu.h"
#include "dbm_multiply_gpu.h"
#include "dbm_multiply_gpu_kernel.h"
#include "../base/cp_assert.h"
#include <limits.h>
#include <math.h>
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Data Structures

struct  backend_context_t
 Private struct for storing the context of the multiplication backend. More...

Macros

#define BACKEND_NSETS   1

Functions

static float * compute_rows_max_eps (const bool trans, const dbm_matrix_t *matrix, const double filter_eps)
 Private routine for computing the max filter threshold for each row.
static backend_context_t * backend_start (const dbm_matrix_t *matrix_c)
 Private routine for initializing the multiplication backend.
static bool backend_upload_packs (const dbm_pack_t *pack_a, const dbm_pack_t *pack_b, backend_context_t *ctx)
 Private routine for handing newly arrived packs to the backend.
static void backend_end_turn (backend_context_t *ctx)
 Private routine for concluding a turn of the main loop, i.e., before the packs are reused or released and before batches are refilled.
static dbm_task_t * backend_batch_tasks (const int kshard, const backend_context_t *ctx)
 Private routine returning where to write the batch of the given shard.
static void backend_process_batch (dbm_batch_t *batch, const double alpha, const dbm_pack_t *pack_a, const dbm_pack_t *pack_b, const int kshard, dbm_shard_t *shard_c, const bool finish, backend_context_t *ctx)
 Private routine for sending a batch to the multiplication backend. The batch is left empty, i.e., ready to be filled again.
static void backend_stop (backend_context_t *ctx)
 Private routine for shutting down the multiplication backend.
static double phase_lap (double *tick)
 Private routine returning the seconds since tick, which it resets.
static void multiply_packs (const bool transa, const bool transb, const double alpha, const dbm_pack_t *pack_a, const dbm_pack_t *pack_b, const dbm_matrix_t *matrix_a, const dbm_matrix_t *matrix_b, dbm_matrix_t *matrix_c, const float *rows_max_eps, const bool retain_sparsity, int64_t *flop, backend_context_t *ctx)
 Private routine for multiplying two packs (C += alpha * A * B).
void dbm_multiply (const bool transa, const bool transb, const double alpha, const dbm_matrix_t *matrix_a, const dbm_matrix_t *matrix_b, const double beta, dbm_matrix_t *matrix_c, const bool retain_sparsity, const double filter_eps, int64_t *flop)
 Performs a multiplication of two dbm_matrix_t matrices. See dbm_matrix.h for details.

Macro Definition Documentation

◆ BACKEND_NSETS

#define BACKEND_NSETS   1

Definition at line 84 of file dbm_multiply.c.

Function Documentation

◆ compute_rows_max_eps()

float * compute_rows_max_eps ( const bool trans,
const dbm_matrix_t * matrix,
const double filter_eps )
static

Private routine for computing the max filter threshold for each row.

Author
Ole Schuett

Definition at line 30 of file dbm_multiply.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ backend_start()

backend_context_t * backend_start ( const dbm_matrix_t * matrix_c)
static

Private routine for initializing the multiplication backend.

Author
Ole Schuett

Definition at line 91 of file dbm_multiply.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ backend_upload_packs()

bool backend_upload_packs ( const dbm_pack_t * pack_a,
const dbm_pack_t * pack_b,
backend_context_t * ctx )
static

Private routine for handing newly arrived packs to the backend.

Author
Ole Schuett

Definition at line 111 of file dbm_multiply.c.

Here is the caller graph for this function:

◆ backend_end_turn()

void backend_end_turn ( backend_context_t * ctx)
static

Private routine for concluding a turn of the main loop, i.e., before the packs are reused or released and before batches are refilled.

Author
Hans Pabst

Definition at line 129 of file dbm_multiply.c.

Here is the caller graph for this function:

◆ backend_batch_tasks()

dbm_task_t * backend_batch_tasks ( const int kshard,
const backend_context_t * ctx )
static

Private routine returning where to write the batch of the given shard.

Author
Hans Pabst

Definition at line 140 of file dbm_multiply.c.

Here is the caller graph for this function:

◆ backend_process_batch()

void backend_process_batch ( dbm_batch_t * batch,
const double alpha,
const dbm_pack_t * pack_a,
const dbm_pack_t * pack_b,
const int kshard,
dbm_shard_t * shard_c,
const bool finish,
backend_context_t * ctx )
static

Private routine for sending a batch to the multiplication backend. The batch is left empty, i.e., ready to be filled again.

Author
Ole Schuett

Definition at line 176 of file dbm_multiply.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ backend_stop()

void backend_stop ( backend_context_t * ctx)
static

Private routine for shutting down the multiplication backend.

Author
Ole Schuett

Definition at line 205 of file dbm_multiply.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ phase_lap()

double phase_lap ( double * tick)
static

Private routine returning the seconds since tick, which it resets.

Author
Hans Pabst

Definition at line 217 of file dbm_multiply.c.

Here is the caller graph for this function:

◆ multiply_packs()

void multiply_packs ( const bool transa,
const bool transb,
const double alpha,
const dbm_pack_t * pack_a,
const dbm_pack_t * pack_b,
const dbm_matrix_t * matrix_a,
const dbm_matrix_t * matrix_b,
dbm_matrix_t * matrix_c,
const float * rows_max_eps,
const bool retain_sparsity,
int64_t * flop,
backend_context_t * ctx )
static

Private routine for multiplying two packs (C += alpha * A * B).

Blocks in each pack are grouped by shard (free_index % nshards) and sorted by sum_index within each group. The algorithm:

  1. Builds shard-boundary lookup tables for A (rows) and B (cols).
  2. For each (shard_row, shard_col) pair, determines the contiguous A and B block ranges belonging to that shard.
  3. Performs a merge-join over sum_index: advances A and B cursors in lockstep, caching the B sub-range for each sum_index so that multiple A blocks with the same sum_index reuse it without rescanning.
  4. Applies a norm-based filter (alpha^2 * norm_a * norm_b < eps) for early rejection before looking up or allocating the C block.
  5. Accumulates matching pairs into a batched GEMM task list, flushing to the backend (CPU or GPU) every DBM_MAX_BATCH_SIZE tasks.
Author
Ole Schuett and Hans Pabst

Definition at line 242 of file dbm_multiply.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dbm_multiply()

void dbm_multiply ( const bool transa,
const bool transb,
const double alpha,
const dbm_matrix_t * matrix_a,
const dbm_matrix_t * matrix_b,
const double beta,
dbm_matrix_t * matrix_c,
const bool retain_sparsity,
const double filter_eps,
int64_t * flop )

Performs a multiplication of two dbm_matrix_t matrices. See dbm_matrix.h for details.

Performs a multiplication of two dbm_matrix_t matrices, as C := alpha * op( A ) * op( B ) + beta * C.

Author
Ole Schuett

Definition at line 470 of file dbm_multiply.c.

Here is the call graph for this function:
Here is the caller graph for this function: