-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello.py
58 lines (41 loc) · 1.9 KB
/
hello.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import torch
# Define a function which creates a file (YYYY-MM-DD_HH-MM-SS.txt) in the directory "./data" and writes a message to it
def write_message(message=None):
import os
import datetime
# Create a directory if it does not exist
os.makedirs("data", exist_ok=True)
if not message:
# print whether cuda is available, device name, total memory and multiprocessor count
message = "EndoReg DB DevEnv (with cuda support)!\n"
message += f"Cuda is available: {torch.cuda.is_available()}\n"
message += f"Number of usable devices: {torch.cuda.device_count()}\n"
message += "\n"
for i in range(torch.cuda.device_count()):
properties = torch.cuda.get_device_properties(i)
message += f"Device {i}: {properties.name}\n"
message += f" Total Memory: {properties.total_memory / (1024**2):.2f} MB\n"
message += f" Multiprocessor Count: {properties.multi_processor_count}\n"
message += "\n"
# # Get the current date and time
# now = datetime.datetime.now()
# date_time = now.strftime("%Y-%m-%d_%H-%M-%S")
# Create a file with the current date and time
# file_name = f"data/{date_time}.txt"
# with open(file_name, "w") as file:
# file.write(message)
# return file_name
def main():
print("Hello from EndoReg-DB DevEnv (with cuda support)!")
print("Cuda is available:", torch.cuda.is_available())
num_of_gpus = torch.cuda.device_count()
print("Number of usable devices:", num_of_gpus)
for i in range(num_of_gpus):
properties = torch.cuda.get_device_properties(i)
print(f"Device {i}: {properties.name}")
print(f" Total Memory: {properties.total_memory / (1024**2):.2f} MB")
print(f" Multiprocessor Count: {properties.multi_processor_count}")
write_message()
# write_message()
if __name__ == "__main__":
main()