Poplar and PopLibs
BlockSparseMatMul.hpp
Go to the documentation of this file.
1// Copyright (c) 2020 Graphcore Ltd. All rights reserved.
6#ifndef POPSPARSE_BLOCK_SPARSE_MATMUL_H
7#define POPSPARSE_BLOCK_SPARSE_MATMUL_H
8
9#include "BlockSparse.hpp"
10#include <array>
11#include <poplar/Graph.hpp>
12
13namespace popsparse {
14namespace experimental {
15
16class BSMatMulImpl;
17
31
32public:
75 BSMatMulParams(const std::array<int, 3> &dim,
76 const std::array<int, 3> &blockSize,
77 const std::vector<unsigned char> &rhsSparsity,
78 bool rhsNeedTranspose, poplar::Type inDataType,
79 poplar::Type outDataType, poplar::Type partialDataType,
80 unsigned numGroupsIn = 1);
81
119 BSMatMulParams(const std::array<int, 3> &dim,
120 const std::array<int, 3> &blockSize,
121 const std::vector<unsigned char> &resSparsity,
122 poplar::Type inDataType, poplar::Type outDataType,
123 poplar::Type partialDataType,
124 SubBlockMask subBlockMask = SubBlockMask::None,
125 unsigned numGroupsIn = 1);
126
128
130
131 std::unique_ptr<BSMatMulImpl> impl;
132};
133
158 const BSMatMulParams &bsMatMul,
159 const poplar::DebugContext &debugContext,
160 const poplar::OptionFlags &options = {});
161
186 const BSMatMulParams &bsMatMul,
187 const poplar::DebugContext &debugContext,
188 const poplar::OptionFlags &options = {});
189
238/* [INTERNAL OPTIONS]
239 * * `memoryCycleRatio` Integer [=1]
240 *
241 * This is used to compute the weight of a hypergraph node:
242 * w = memory_cycle_ratio * mem_weight +
243 * (1.0 - memory_cycle_ratio) * cycle_weight
244 * This may be only a temporary option.
245 *
246 * * `partitionMethod` (block, block-naive, strip) [=block]
247 *
248 * * **block:** The matrix multiply computation
249 * graph is created for each non-zero block and Zoltan
250 * is used to partition the graph.
251 *
252 * * **block-naive:** The matrix multiply
253 * computation graph is created for each non-zero block
254 * and a greedy algorithm is used to partition the
255 * graph.
256 *
257 * * **strip:** The graph is created for columns or rows.
258 */
260 const BSMatMulParams &bsMatMulParams,
262 const poplar::Tensor &lhsMatrix,
263 const poplar::Tensor &rhsMatrix,
264 const poplar::OptionFlags &options = {},
265 const poplar::DebugContext &debugContext = {});
266
267} // namespace experimental
268} // namespace popsparse
269
270#endif // POPSPARSE_BLOCK_SPARSE_MATMUL_H
poplar::Tensor createBSMatMulInputLHS(poplar::Graph &graph, const BSMatMulParams &bsMatMul, const poplar::DebugContext &debugContext, const poplar::OptionFlags &options={})
Create a tensor for use as the left operand of block-sparse matrix multiplication.
poplar::Tensor bsMatMul(poplar::Graph &graph, const BSMatMulParams &bsMatMulParams, poplar::program::Sequence &prog, const poplar::Tensor &lhsMatrix, const poplar::Tensor &rhsMatrix, const poplar::OptionFlags &options={}, const poplar::DebugContext &debugContext={})
This function multiplies the left-hand matrix by the right-hand matrix.
poplar::Tensor createBSMatMulInputRHS(poplar::Graph &graph, const BSMatMulParams &bsMatMul, const poplar::DebugContext &debugContext, const poplar::OptionFlags &options={})
Create a tensor for use as the right operand of block-sparse matrix multiplication.
Block sparse operations.
SubBlockMask
Define the sparsity mask inside a block.
Definition: BlockSparse.hpp:26
DebugContext gathers the common external parameters of the context of an operation.
Definition: DebugContext.hpp:221
This class represents a graph program to be executed on the IPU.
Definition: Graph.hpp:52
A set of option/value string flags to be used in various APIs.
Definition: OptionFlags.hpp:24
A reference to a subset of tensor elements.
Definition: Tensor.hpp:38
Class representing device data types.
Definition: Type.hpp:42
Program that executes a sequence of programs.
Definition: Program.hpp:77
This class supports block-sparse matrix multiplication.
Definition: BlockSparseMatMul.hpp:30
BSMatMulParams(const std::array< int, 3 > &dim, const std::array< int, 3 > &blockSize, const std::vector< unsigned char > &resSparsity, poplar::Type inDataType, poplar::Type outDataType, poplar::Type partialDataType, SubBlockMask subBlockMask=SubBlockMask::None, unsigned numGroupsIn=1)
This constructor is for a dense matrix multiplying a dense matrix.
BSMatMulParams(const std::array< int, 3 > &dim, const std::array< int, 3 > &blockSize, const std::vector< unsigned char > &rhsSparsity, bool rhsNeedTranspose, poplar::Type inDataType, poplar::Type outDataType, poplar::Type partialDataType, unsigned numGroupsIn=1)
This constructor is for a dense matrix (left side) multiplying a sparse matrix (right side).
Support for sparse matrices.
Definition: codelets.hpp:8