-
Notifications
You must be signed in to change notification settings - Fork 30
Add wrapper for SYCL queue::memcpy(). #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
3d21faa
5584588
dfcf454
f70c2d0
125e498
a83fcc6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
##===--------------- _memory.pxd - dpctl module --------*- Cython -*-------===## | ||
## | ||
## Data Parallel Control (dpCtl) | ||
## | ||
## Copyright 2020 Intel Corporation | ||
## | ||
## Licensed under the Apache License, Version 2.0 (the "License"); | ||
## you may not use this file except in compliance with the License. | ||
## You may obtain a copy of the License at | ||
## | ||
## http://www.apache.org/licenses/LICENSE-2.0 | ||
## | ||
## Unless required by applicable law or agreed to in writing, software | ||
## distributed under the License is distributed on an "AS IS" BASIS, | ||
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
## See the License for the specific language governing permissions and | ||
## limitations under the License. | ||
## | ||
##===----------------------------------------------------------------------===## | ||
|
||
# distutils: language = c++ | ||
# cython: language_level=3 | ||
|
||
from .backend cimport DPPLSyclUSMRef | ||
from ._sycl_core cimport SyclQueue | ||
|
||
|
||
cdef class Memory: | ||
cdef DPPLSyclUSMRef memory_ptr | ||
cdef Py_ssize_t nbytes | ||
cdef SyclQueue queue | ||
|
||
cdef _cinit(self, Py_ssize_t nbytes, ptr_type, SyclQueue queue) | ||
cdef _getbuffer(self, Py_buffer *buffer, int flags) | ||
|
||
|
||
cdef class MemoryUSMShared(Memory): | ||
pass | ||
|
||
|
||
cdef class MemoryUSMHost(Memory): | ||
pass | ||
|
||
|
||
cdef class MemoryUSMDevice(Memory): | ||
pass |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,3 +63,4 @@ cdef class SyclQueue: | |
cpdef SyclContext get_sycl_context (self) | ||
cpdef SyclDevice get_sycl_device (self) | ||
cdef DPPLSyclQueueRef get_queue_ref (self) | ||
cpdef memcpy (self, dest, src, int count) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you mean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For The method does not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps it would be better to not expose |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
##===---------- test_sycl_queue_manager.py - dpctl -------*- Python -*----===## | ||
## | ||
## Data Parallel Control (dpCtl) | ||
## | ||
## Copyright 2020 Intel Corporation | ||
## | ||
## Licensed under the Apache License, Version 2.0 (the "License"); | ||
## you may not use this file except in compliance with the License. | ||
## You may obtain a copy of the License at | ||
## | ||
## http://www.apache.org/licenses/LICENSE-2.0 | ||
## | ||
## Unless required by applicable law or agreed to in writing, software | ||
## distributed under the License is distributed on an "AS IS" BASIS, | ||
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
## See the License for the specific language governing permissions and | ||
## limitations under the License. | ||
## | ||
##===----------------------------------------------------------------------===## | ||
### | ||
### \file | ||
### Defines unit test cases for the SyclQueue.memcpy in sycl_core.pyx. | ||
##===----------------------------------------------------------------------===## | ||
|
||
import dpctl | ||
import unittest | ||
|
||
|
||
|
||
class TestQueueMemcpy (unittest.TestCase): | ||
|
||
def _create_memory (self): | ||
nbytes = 1024 | ||
queue = dpctl.get_current_queue() | ||
mobj = dpctl._memory.MemoryUSMShared(nbytes, queue) | ||
return mobj | ||
|
||
def test_memcpy_copy_usm_to_usm (self): | ||
mobj1 = self._create_memory() | ||
mobj2 = self._create_memory() | ||
q = dpctl.get_current_queue() | ||
|
||
mv1 = memoryview(mobj1) | ||
mv2 = memoryview(mobj2) | ||
|
||
mv1[:3] = b'123' | ||
|
||
q.memcpy(mobj2, mobj1, 3) | ||
|
||
self.assertEqual(mv2[:3], b'123') | ||
|
||
def test_memcpy_type_error (self): | ||
mobj = self._create_memory() | ||
q = dpctl.get_current_queue() | ||
|
||
with self.assertRaises(TypeError) as cm: | ||
q.memcpy(None, mobj, 3) | ||
|
||
self.assertEqual(type(cm.exception), TypeError) | ||
self.assertEqual(str(cm.exception), "Parameter dest should be Memory.") | ||
|
||
with self.assertRaises(TypeError) as cm: | ||
q.memcpy(mobj, None, 3) | ||
|
||
self.assertEqual(type(cm.exception), TypeError) | ||
self.assertEqual(str(cm.exception), "Parameter src should be Memory.") | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Uh oh!
There was an error while loading. Please reload this page.