FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-sandbox/src/cuda_code.py at master · akafael/python-sandbox · GitHub
akafael
/
python-sandbox
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
2
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-sandbox
/
src
/
cuda_code.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
23 lines (18 loc) · 657 Bytes
Breadcrumbs
python-sandbox
/
src
/
cuda_code.py
Copy path
File metadata and controls
23 lines (18 loc) · 657 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import
torch
import
time
# Example: Matrix multiplication
matrix_size
=
1000
a_cpu
=
torch
.
randn
(
matrix_size
,
matrix_size
)
b_cpu
=
torch
.
randn
(
matrix_size
,
matrix_size
)
start_time
=
time
.
time
()
result_cpu
=
torch
.
matmul
(
a_cpu
,
b_cpu
)
end_time
=
time
.
time
()
print
(
f"CPU computation time:
{
end_time
-
start_time
:.4f
}
seconds"
)
if
torch
.
cuda
.
is_available
():
a_gpu
=
a_cpu
.
to
(
"cuda"
)
b_gpu
=
b_cpu
.
to
(
"cuda"
)
start_time
=
time
.
time
()
result_gpu
=
torch
.
matmul
(
a_gpu
,
b_gpu
)
torch
.
cuda
.
synchronize
()
# Wait for GPU operations to complete
end_time
=
time
.
time
()
print
(
f"GPU computation time:
{
end_time
-
start_time
:.4f
}
seconds"
)
Back
|
FazBrowse Home
|
New Git URL