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
Model registry
Operate
Environments
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
Andreas Klöckner
pyopencl
Commits
cacc9f0e
Commit
cacc9f0e
authored
12 years ago
by
Andreas Klöckner
Browse files
Options
Downloads
Patches
Plain Diff
Be tolerant of bogus offsetof() data from the device.
parent
e1d70395
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
pyopencl/tools.py
+19
-3
19 additions, 3 deletions
pyopencl/tools.py
with
19 additions
and
3 deletions
pyopencl/tools.py
+
19
−
3
View file @
cacc9f0e
...
...
@@ -401,7 +401,7 @@ def match_dtype_to_c_struct(device, name, dtype, context=None):
src
=
r
"""
#define pycl_offsetof(st, m) \
((size_t) (
(char *)&(
(st *)0)->m - (
char *)
0
))
((size_t) ((
__local
char *)
&(
dummy.m) - (__local
char *)
&dummy
))
%(pre_decls)s
...
...
@@ -410,6 +410,7 @@ def match_dtype_to_c_struct(device, name, dtype, context=None):
__kernel void get_size_and_offsets(__global size_t *result)
{
result[0] = sizeof(%(my_type)s);
__local %(my_type)s dummy;
%(offset_code)s
}
"""
%
dict
(
...
...
@@ -428,9 +429,24 @@ def match_dtype_to_c_struct(device, name, dtype, context=None):
import
pyopencl.array
result_buf
=
cl
.
array
.
empty
(
queue
,
1
+
len
(
fields
),
np
.
uintp
)
knl
(
queue
,
(
1
,),
None
,
result_buf
.
data
)
knl
(
queue
,
(
1
,),
(
1
,),
result_buf
.
data
)
queue
.
finish
()
size_and_offsets
=
result_buf
.
get
()
size
=
int
(
size_and_offsets
[
0
])
from
pytools
import
any
offsets
=
size_and_offsets
[
1
:]
if
any
(
ofs
>=
size
for
ofs
in
offsets
):
# offsets not plausible
if
dtype
.
itemsize
==
size
:
# If sizes match, use numpy's idea of the offsets.
offsets
=
[
offset
for
field_name
,
(
field_dtype
,
offset
)
in
fields
]
else
:
raise
RuntimeError
(
"
cannot discover struct layout on
'
%s
'"
%
device
)
result_buf
.
data
.
release
()
del
knl
del
prg
...
...
@@ -440,7 +456,7 @@ def match_dtype_to_c_struct(device, name, dtype, context=None):
dtype_arg_dict
=
dict
(
names
=
[
field_name
for
field_name
,
(
field_dtype
,
offset
)
in
fields
],
formats
=
[
field_dtype
for
field_name
,
(
field_dtype
,
offset
)
in
fields
],
offsets
=
[
int
(
x
)
for
x
in
size_and_
offsets
[
1
:]
],
offsets
=
[
int
(
x
)
for
x
in
offsets
],
itemsize
=
int
(
size_and_offsets
[
0
]),
)
dtype
=
np
.
dtype
(
dtype_arg_dict
)
...
...
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