-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
35 lines (31 loc) · 987 Bytes
/
Copy pathmain.cpp
File metadata and controls
35 lines (31 loc) · 987 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
#include <torch/script.h> // One-stop header.
//#include <torch/torch.h>
//#include <ATen/ATen.h>
//#include <torch/csrc/autograd/variable.h>
//#include <torch/csrc/autograd/function.h>
#include <iostream>
#include <memory>
using namespace std;
int main(){
auto opts =
torch::TensorOptions()
.dtype(torch::kFloat32)
.layout(torch::kStrided)
.device(torch::kCUDA)
.requires_grad(true);
auto nograds =
torch::TensorOptions()
.dtype(torch::kFloat32)
.layout(torch::kStrided)
.device(torch::kCUDA)
.requires_grad(false);
// build a 2-D (3,3) Tensor
// at::Tensor mat = torch::rand({3,3});
at::Tensor mat = torch::rand({3,3},opts);
// at::Tensor mat = torch::rand({3,3},nograds);
// at::Tensor identity = torch::ones({3,3});
at::Tensor identity = torch::ones({3,3},opts);
// at::Tensor identity = torch::ones({3,3},nograds);
std::cout << mat << std::endl;
std::cout << mat * identity << std::endl;
}