-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
36 lines (28 loc) · 742 Bytes
/
main.cpp
File metadata and controls
36 lines (28 loc) · 742 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
32
33
34
35
36
#include <torch/script.h>
#include <torch/torch.h>
using namespace std;
using namespace torch;
// Prototype declarations
Tensor cpp_matmul(Tensor x, Tensor y);
vector<Tensor> cpp_matsmul(vector<Tensor> x, vector<Tensor> y);
// Register the cpp functions to dll.
static auto registry =
RegisterOperators("sample::matmul", &cpp_matmul)
.op("sample::matsmul", &cpp_matsmul);
// CPP functions
Tensor cpp_matmul(Tensor x, Tensor y)
{
return x.matmul(y);
}
vector<Tensor> cpp_matsmul(vector<Tensor> x, vector<Tensor> y)
{
vector<Tensor> z;
if (x.size() != y.size()) {
cerr << "The numbers of tensors must be the same." << endl;
return z;
}
for (int i = 0; i < x.size(); i++) {
z.push_back(x[i].matmul(y[i]));
}
return z;
}