Poplar and PopLibs
FullyConnectedParams.hpp
Go to the documentation of this file.
1// Copyright (c) 2020 Graphcore Ltd. All rights reserved.
6#ifndef popsparse_FullyConnectedParams_hpp
7#define popsparse_FullyConnectedParams_hpp
8
9#include "SparsityParams.hpp"
10
11#include <cassert>
12#include <cmath>
13#include <ostream>
14
15namespace popsparse {
16namespace dynamic {
17
18class FullyConnectedParams {
19
21 SparsityParams sparsityParams;
22
24 double nzRatio;
25
26 std::size_t batchSize;
27 std::size_t numGroups;
28 std::size_t inputChannelsPerGroup;
29 std::size_t outputChannelsPerGroup;
30
31public:
53
54 static FullyConnectedParams
55 createWithNzRatio(const SparsityParams &sparsityParams, double nzRatio,
56 std::size_t batchSize, std::size_t numGroups,
57 std::size_t inputChannels, std::size_t outputChannels);
59 static FullyConnectedParams
60 createWithNumNonZeroValues(const SparsityParams &sparsityParams,
61 std::size_t numNonZeroElems, std::size_t batchSize,
62 std::size_t numGroups, std::size_t inputChannels,
63 std::size_t outputChannels);
65
66 std::size_t getBatchSize() const { return batchSize; }
67 std::size_t getNumGroups() const { return numGroups; }
68 std::size_t getInputChannels() const {
69 return numGroups * inputChannelsPerGroup;
70 }
71 std::size_t getOutputChannels() const {
72 return numGroups * outputChannelsPerGroup;
73 }
74 std::size_t getInputChannelsPerGroup() const { return inputChannelsPerGroup; }
75 std::size_t getOutputChannelsPerGroup() const {
76 return outputChannelsPerGroup;
77 }
78 const SparsityParams &getSparsityParams() const { return sparsityParams; }
79 double getNzRatio() const;
80 std::size_t getNumNonZeroValues() const;
81
82 friend bool operator<(const FullyConnectedParams &a,
83 const FullyConnectedParams &b);
84 friend bool operator==(const FullyConnectedParams &a,
85 const FullyConnectedParams &b);
86 friend bool operator!=(const FullyConnectedParams &a,
87 const FullyConnectedParams &b);
88};
89
90std::ostream &operator<<(std::ostream &os, const FullyConnectedParams &p);
91
92} // namespace dynamic
93} // namespace popsparse
94
95#endif // popsparse_FullyConnectedParams_hpp
Parameters used for sparse tensors.
std::ostream & operator<<(std::ostream &os, const CollectiveOperator &op)
Write op to output stream os.
Support for sparse matrices.
Definition: codelets.hpp:8