-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3d21faa
Add wrapper for SYCL queue::memcpy().
PokhodenkoSA 5584588
Fix comment.
PokhodenkoSA dfcf454
Fix comment for DPPLQueue_memcpy
PokhodenkoSA f70c2d0
Rename DPPLQueue_Memcpy
PokhodenkoSA 125e498
Merge remote-tracking branch 'up/master' into feature/memcpy
PokhodenkoSA a83fcc6
Fix cdef void* declaring variables
PokhodenkoSA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean
cdef
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For
c
part ofcpdef
to be efficient,dest
andsrc
need have type declarations. Looks like they can only beMemory
objects.The method does not use
self
at all, so should it be a static method of the class?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method uses
self
in codeDPPLQueue_memcpy(self.queue_ptr, c_dest, c_src, count)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it would be better to not expose
memcpy
as a stand-alone symbol, but rather make it two methodcopyto
andcopyfrom
ofMemory
object. That way it could copy to/from another Memory object, or host memory of any object that supports a buffer protocol.