Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mozheng-homework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mozheng
mozheng-homework
Commits
3f5d20df
Commit
3f5d20df
authored
Oct 25, 2020
by
mozheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
不符合题意,更改
parent
98c4f409
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
28 deletions
+32
-28
1/main.py
+28
-26
1/readme.md
+2
-2
1/res1.jpg
+0
-0
1/res1.png
+0
-0
Readme.md
+2
-0
No files found.
1/main.py
View file @
3f5d20df
from
numba
import
jit
from
numpy
import
arange
import
cupy
as
cp
import
numpy
as
np
import
time
import
time
@jit
def
numba_sum
(
arr
):
def
matrix_add
(
matrix
,
a
,
b
,
times
):
M
,
N
=
arr
.
shape
#矩阵的相加
result
=
0.0
for
_
in
range
(
times
):
for
i
in
range
(
M
):
c
=
matrix
.
add
(
a
,
b
)
for
j
in
range
(
N
):
return
c
result
+=
arr
[
i
,
j
]
return
result
def
sum
(
arr
):
M
,
N
=
arr
.
shape
result
=
0.0
for
i
in
range
(
M
):
for
j
in
range
(
N
):
result
+=
arr
[
i
,
j
]
return
result
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
a
=
arange
(
9
)
.
reshape
(
3
,
3
)
h
,
w
=
10000
,
10000
a
=
np
.
random
.
normal
(
size
=
h
*
w
)
a
=
a
.
reshape
((
h
,
w
))
b
=
np
.
random
.
normal
(
size
=
h
*
w
)
b
=
b
.
reshape
((
h
,
w
))
start_time
=
time
.
time
()
start_time
=
time
.
time
()
for
i
in
range
(
10000000
):
matrix_add
(
np
,
a
,
b
,
100
)
numba_sum
(
a
)
end_time
=
time
.
time
()
end_time
=
time
.
time
()
print
(
"使用numba:"
,
end_time
-
start_time
)
print
(
"使用numpy(cpu): {0} sec"
.
format
(
end_time
-
start_time
)
)
a
=
cp
.
random
.
normal
(
size
=
h
*
w
)
a
=
a
.
reshape
((
h
,
w
))
b
=
cp
.
random
.
normal
(
size
=
h
*
w
)
b
=
b
.
reshape
((
h
,
w
))
start_time
=
time
.
time
()
start_time
=
time
.
time
()
for
i
in
range
(
10000000
):
matrix_add
(
cp
,
a
,
b
,
100
)
sum
(
a
)
end_time
=
time
.
time
()
end_time
=
time
.
time
()
print
(
"使用cpu:"
,
end_time
-
start_time
)
print
(
"使用cupy(gpu): {0} sec"
.
format
(
end_time
-
start_time
))
\ No newline at end of file
1/readme.md
View file @
3f5d20df
...
@@ -6,4 +6,4 @@ Cupy是使用NVIDIA CUDA核心进行加速运算,因为GPU上有好多CUDA核
...
@@ -6,4 +6,4 @@ Cupy是使用NVIDIA CUDA核心进行加速运算,因为GPU上有好多CUDA核
代码:
[
main.py
](
main.py
)
代码:
[
main.py
](
main.py
)
结果:
结果:
!
[
](res1.png)
!
[
](res1.jpg)
\ No newline at end of file
\ No newline at end of file
1/res1.jpg
0 → 100644
View file @
3f5d20df
7.2 KB
1/res1.png
deleted
100644 → 0
View file @
98c4f409
3.14 KB
Readme.md
View file @
3f5d20df
http://47.94.6.102/113/mozheng-homework
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment