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
57923244
Commit
57923244
authored
10 years ago
by
Yichao Yu
Browse files
Options
Downloads
Patches
Plain Diff
MemoryObjectHolder.get_host_array
parent
19974a27
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pyopencl/c_wrapper/wrap_cl_core.h
+1
-0
1 addition, 0 deletions
pyopencl/c_wrapper/wrap_cl_core.h
pyopencl/cffi_cl.py
+50
-15
50 additions, 15 deletions
pyopencl/cffi_cl.py
src/c_wrapper/memory_object.cpp
+12
-0
12 additions, 0 deletions
src/c_wrapper/memory_object.cpp
with
63 additions
and
15 deletions
pyopencl/c_wrapper/wrap_cl_core.h
+
1
−
0
View file @
57923244
...
...
@@ -91,6 +91,7 @@ error *buffer__get_sub_region(clobj_t *_sub_buf, clobj_t _buf, size_t orig,
error
*
buffer__getitem
(
clobj_t
*
_ret
,
clobj_t
_buf
,
ssize_t
start
,
ssize_t
end
);
// Memory Object
error
*
memory_object__release
(
clobj_t
obj
);
error
*
memory_object__get_host_array
(
clobj_t
,
void
**
hostptr
,
size_t
*
size
);
// Memory Map
error
*
memory_map__release
(
clobj_t
_map
,
clobj_t
_queue
,
const
clobj_t
*
_wait_for
,
uint32_t
num_wait_for
,
...
...
This diff is collapsed.
Click to expand it.
pyopencl/cffi_cl.py
+
50
−
15
View file @
57923244
...
...
@@ -620,8 +620,53 @@ class CommandQueue(_Common):
_handle_error
(
_lib
.
command_queue__flush
(
self
.
ptr
))
# TODO set_property
def
_norm_shape_dtype
(
shape
,
dtype
,
order
=
"
C
"
,
strides
=
None
,
name
=
""
):
dtype
=
np
.
dtype
(
dtype
)
if
not
isinstance
(
shape
,
tuple
):
try
:
shape
=
tuple
(
shape
)
except
:
shape
=
(
shape
,)
if
strides
is
None
:
if
order
==
"
cC
"
:
strides
=
c_contigous_strides
(
byte_size
,
shape
)
elif
order
==
"
cF
"
:
strides
=
f_contigous_strides
(
byte_size
,
shape
)
else
:
raise
RuntimeError
(
"
unrecognized order specifier %s
"
%
order
,
status_code
.
INVALID_VALUE
,
name
)
return
dtype
,
shape
,
strides
class
cffi_array
(
np
.
ndarray
):
__array_priority__
=
-
100.0
def
__new__
(
cls
,
ptr
,
shape
,
dtype
,
strides
,
base
=
None
):
self
=
np
.
ndarray
.
__new__
(
cls
,
shape
,
dtype
=
dtype
,
buffer
=
ffi
.
buffer
(
ptr
),
strides
=
strides
)
if
base
is
None
:
base
=
ptr
self
.
__base
=
base
return
self
@property
def
base
(
self
):
return
self
.
__base
class
MemoryObjectHolder
(
_Common
):
pass
def
get_host_array
(
self
,
shape
,
dtype
,
order
=
"
C
"
):
dtype
,
shape
,
strides
=
_norm_shape_dtype
(
shape
,
dtype
,
order
,
None
,
'
MemoryObjectHolder.get_host_array
'
)
_hostptr
=
_ffi
.
new
(
'
void**
'
)
_size
=
_ffi
.
new
(
'
size_t*
'
)
_handle_error
(
memory_object__get_host_array
(
self
.
ptr
,
_hostptr
,
_size
))
ary
=
cffi_array
(
_hostptr
[
0
],
shape
,
dtype
,
strides
,
self
)
if
ary
.
nbytes
>
_size
[
0
]:
raise
LogicError
(
"
Resulting array is larger than memory object.
"
,
status_code
.
INVALID_VALUE
,
"
MemoryObjectHolder.get_host_array
"
)
return
ary
class
MemoryObject
(
MemoryObjectHolder
):
...
...
@@ -1176,21 +1221,9 @@ def _enqueue_copy_buffer_rect(queue, src, dst, src_origin, dst_origin, region,
def
enqueue_map_buffer
(
queue
,
buf
,
flags
,
offset
,
shape
,
dtype
,
order
=
"
C
"
,
strides
=
None
,
wait_for
=
None
,
is_blocking
=
True
):
dtype
=
np
.
dtype
(
dtype
)
if
not
isinstance
(
shape
,
tuple
):
try
:
shape
=
tuple
(
shape
)
except
:
shape
=
(
shape
,)
dtype
,
shape
,
strides
=
_norm_shape_dtype
(
shape
,
dtype
,
order
,
strides
,
'
enqueue_map_buffer
'
)
byte_size
=
dtype
.
itemsize
if
strides
is
None
:
if
order
==
"
cC
"
:
strides
=
c_contigous_strides
(
byte_size
,
shape
)
elif
order
==
"
cF
"
:
strides
=
f_contigous_strides
(
byte_size
,
shape
)
else
:
raise
RuntimeError
(
"
unrecognized order specifier %s
"
%
order
,
status_code
.
INVALID_VALUE
,
'
enqueue_map_buffer
'
)
for
s
in
shape
:
byte_size
*=
s
c_wait_for
,
num_wait_for
=
_clobj_list
(
wait_for
)
...
...
@@ -1281,6 +1314,8 @@ def enqueue_map_image(queue, img, flags, origin, region, shape, dtype,
if
origin_l
>
3
or
region_l
>
3
:
raise
RuntimeError
(
"
origin or region has too many components
"
,
status_code
.
INVALID_VALUE
,
"
enqueue_map_image
"
)
dtype
,
shape
,
strides
=
_norm_shape_dtype
(
shape
,
dtype
,
order
,
strides
,
'
enqueue_map_image
'
)
_event
=
_ffi
.
new
(
'
clobj_t*
'
)
_map
=
_ffi
.
new
(
'
clobj_t*
'
)
_row_pitch
=
_ffi
.
new
(
'
size_t*
'
)
...
...
This diff is collapsed.
Click to expand it.
src/c_wrapper/memory_object.cpp
+
12
−
0
View file @
57923244
...
...
@@ -76,3 +76,15 @@ memory_object__release(clobj_t obj)
static_cast
<
memory_object
*>
(
obj
)
->
release
();
});
}
error
*
memory_object__get_host_array
(
clobj_t
_obj
,
void
**
hostptr
,
size_t
*
size
)
{
auto
obj
=
static_cast
<
memory_object
*>
(
_obj
);
return
c_handle_error
([
&
]
{
pyopencl_call_guarded
(
clGetMemObjectInfo
,
obj
,
CL_MEM_HOST_PTR
,
size_arg
(
*
hostptr
),
nullptr
);
pyopencl_call_guarded
(
clGetMemObjectInfo
,
obj
,
CL_MEM_SIZE
,
size_arg
(
*
size
),
nullptr
);
});
}
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