Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cnvCallerGPU
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gad-public
cnvCallerGPU
Commits
f5138a30
Commit
f5138a30
authored
Oct 13, 2023
by
Theo Serralta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update with example gpu
parent
097eb6a5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
0 deletions
+33
-0
test_gpu.py
test_gpu.py
+33
-0
No files found.
test_gpu.py
View file @
f5138a30
import
numpy
as
np
import
pyopencl
as
cl
a_np
=
np
.
random
.
rand
(
50000
)
.
astype
(
np
.
float32
)
b_np
=
np
.
random
.
rand
(
50000
)
.
astype
(
np
.
float32
)
ctx
=
cl
.
create_some_context
()
queue
=
cl
.
CommandQueue
(
ctx
)
mf
=
cl
.
mem_flags
a_g
=
cl
.
Buffer
(
ctx
,
mf
.
READ_ONLY
|
mf
.
COPY_HOST_PTR
,
hostbuf
=
a_np
)
b_g
=
cl
.
Buffer
(
ctx
,
mf
.
READ_ONLY
|
mf
.
COPY_HOST_PTR
,
hostbuf
=
b_np
)
prg
=
cl
.
Program
(
ctx
,
"""
__kernel void sum(
__global const float *a_g, __global const float *b_g, __global float *res_g)
{
int gid = get_global_id(0);
res_g[gid] = a_g[gid] + b_g[gid];
}
"""
)
.
build
()
res_g
=
cl
.
Buffer
(
ctx
,
mf
.
WRITE_ONLY
,
a_np
.
nbytes
)
knl
=
prg
.
sum
# Use this Kernel object for repeated calls
knl
(
queue
,
a_np
.
shape
,
None
,
a_g
,
b_g
,
res_g
)
res_np
=
np
.
empty_like
(
a_np
)
cl
.
enqueue_copy
(
queue
,
res_np
,
res_g
)
# Check on CPU with Numpy:
print
(
res_np
-
(
a_np
+
b_np
))
print
(
np
.
linalg
.
norm
(
res_np
-
(
a_np
+
b_np
)))
assert
np
.
allclose
(
res_np
,
a_np
+
b_np
)
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