-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmatrix-mul-codelets.cpp
More file actions
31 lines (25 loc) · 952 Bytes
/
matrix-mul-codelets.cpp
File metadata and controls
31 lines (25 loc) · 952 Bytes
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
// Copyright (c) 2018 Graphcore Ltd. All rights reserved.
#include <poplar/Vertex.hpp>
using namespace poplar;
// This file contains the definitions of the vertex types used by the
// matrix-vector multiplication example. The vertex type provides a description
// of how individual tasks on the IPU will perform computation.
// A vertex type to perform a dot product calculation.
class DotProductVertex : public Vertex {
public:
// These two inputs read a vector of values (that is, an ordered, contiguous
// set of values in memory) from the graph.
Input<Vector<float>> a;
Input<Vector<float>> b;
// The output is to a single scalar value in the graph.
Output<float> out;
// The compute method performs the dot product between inputs 'a' and
// 'b' and stores the result in 'out'.
bool compute() {
float sum = 0;
for (unsigned i = 0; i < a.size(); ++i)
sum += a[i] * b[i];
*out = sum;
return true;
}
};