-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cu
More file actions
28 lines (22 loc) · 687 Bytes
/
main.cu
File metadata and controls
28 lines (22 loc) · 687 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
#include <iostream>
#include <torch/torch.h>
#include <cuda_runtime.h>
int main() {
try {
int num_devices;
cudaGetDeviceCount(&num_devices);
if (num_devices > 0) {
std::cout << "CUDA Devices found: " << num_devices << std::endl;
} else {
std::cerr << "No CUDA devices found!" << std::endl;
return 1;
}
torch::Device device(torch::kCUDA, 0); // Use CUDA device 0
auto tensor = torch::randn({2, 3}, device);
std::cout << tensor << std::endl;
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}
return 0;
}