Skip to content

Commit

Permalink
fix typo; fix ci bug;
Browse files Browse the repository at this point in the history
  • Loading branch information
clearhanhui committed Aug 30, 2023
1 parent 4bc4ba9 commit 4903987
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions chap2/include/TensorCuda.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ void tensor_cuda() {
if (torch::cuda::is_available()) {
device = torch::Device(torch::kCUDA);
}
torch::Tensor b = torch::randn({3, 3}).cuda();
torch::Tensor a = torch::randn({3, 3}).to(device);
// torch::Tensor a = torch::randn({3, 3}).cuda();
torch::Tensor b = torch::randn({3, 3}).to(device);
torch::Tensor c = torch::randn({3, 3}, device); // 似乎是发生了 Device -> TensorOptions 的隐式转换

std::cout << a << std::endl;
// std::cout << a << std::endl;
std::cout << b << std::endl;
std::cout << c << std::endl;
}
4 changes: 2 additions & 2 deletions chap2/python/TensorBasics.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ def tensor_calculate():
# CUDA
def tensor_cuda():
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
a = torch.randn((3,3)).cuda()
# a = torch.randn((3,3)).cuda()
b = torch.randn((3,3)).to(device)
c = torch.randn((3,3), device=device) # more efficient
print(a)
# print(a)
print(b)
print(c)

Expand Down
4 changes: 2 additions & 2 deletions chap2/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ torch::Device device = torch::Device(torch::kCPU);
if (torch::cuda::is_available()) {
device = torch::Device(torch::kCUDA);
}
torch::Tensor b = torch::randn({3, 3}).cuda();
torch::Tensor a = torch::randn({3, 3}).to(device);
torch::Tensor a = torch::randn({3, 3}).cuda();
torch::Tensor b = torch::randn({3, 3}).to(device);
torch::Tensor c = torch::randn({3, 3}, device);
```

Expand Down

0 comments on commit 4903987

Please sign in to comment.