Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pyopencl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alexandru Fikl
pyopencl
Commits
4a603cfb
Commit
4a603cfb
authored
15 years ago
by
Andreas Klöckner
Browse files
Options
Downloads
Patches
Plain Diff
Add (fixed) narray example by Roger Pau Monn'e.
parent
bdb37787
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/narray.py
+37
-0
37 additions, 0 deletions
examples/narray.py
with
37 additions
and
0 deletions
examples/narray.py
0 → 100644
+
37
−
0
View file @
4a603cfb
# example by Roger Pau Monn'e
import
pyopencl
as
cl
import
numpy
as
np
demo_r
=
np
.
empty
(
(
500
,
5
),
dtype
=
np
.
uint32
)
ctx
=
cl
.
create_context_from_type
(
cl
.
device_type
.
GPU
)
queue
=
cl
.
CommandQueue
(
ctx
)
mf
=
cl
.
mem_flags
demo_buf
=
cl
.
create_buffer
(
ctx
,
mf
.
WRITE_ONLY
,
demo_r
.
nbytes
)
prg
=
cl
.
create_program_with_source
(
ctx
,
"""
__kernel void demo(__global uint *demo)
{
int i;
int gid = get_global_id(0);
for(i=0; i<5;i++)
{
demo[gid*5+i] = (uint) 1;
}
}
"""
)
try
:
prg
.
build
()
except
:
print
"
Error:
"
print
prg
.
get_build_info
(
ctx
.
devices
[
0
],
cl
.
program_build_info
.
LOG
)
raise
prg
.
demo
(
queue
,
(
500
,),
demo_buf
)
cl
.
enqueue_read_buffer
(
queue
,
demo_buf
,
demo_r
).
wait
()
for
res
in
demo_r
:
print
res
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment