|
| 1 | +##===---------- test_sycl_queue_manager.py - dpctl -------*- Python -*----===## |
| 2 | +## |
| 3 | +## Data Parallel Control (dpCtl) |
| 4 | +## |
| 5 | +## Copyright 2020 Intel Corporation |
| 6 | +## |
| 7 | +## Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +## you may not use this file except in compliance with the License. |
| 9 | +## You may obtain a copy of the License at |
| 10 | +## |
| 11 | +## http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +## |
| 13 | +## Unless required by applicable law or agreed to in writing, software |
| 14 | +## distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +## See the License for the specific language governing permissions and |
| 17 | +## limitations under the License. |
| 18 | +## |
| 19 | +##===----------------------------------------------------------------------===## |
| 20 | +### |
| 21 | +### \file |
| 22 | +### Defines unit test cases for the SyclQueue.memcpy in sycl_core.pyx. |
| 23 | +##===----------------------------------------------------------------------===## |
| 24 | + |
| 25 | +import dpctl |
| 26 | +import unittest |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +class TestQueueMemcpy (unittest.TestCase): |
| 31 | + |
| 32 | + def _create_memory (self): |
| 33 | + nbytes = 1024 |
| 34 | + queue = dpctl.get_current_queue() |
| 35 | + mobj = dpctl._memory.MemoryUSMShared(nbytes, queue) |
| 36 | + return mobj |
| 37 | + |
| 38 | + def test_memcpy_copy_usm_to_usm (self): |
| 39 | + mobj1 = self._create_memory() |
| 40 | + mobj2 = self._create_memory() |
| 41 | + q = dpctl.get_current_queue() |
| 42 | + |
| 43 | + mv1 = memoryview(mobj1) |
| 44 | + mv2 = memoryview(mobj2) |
| 45 | + |
| 46 | + mv1[:3] = b'123' |
| 47 | + |
| 48 | + q.memcpy(mobj2, mobj1, 3) |
| 49 | + |
| 50 | + self.assertEqual(mv2[:3], b'123') |
| 51 | + |
| 52 | + def test_memcpy_type_error (self): |
| 53 | + mobj = self._create_memory() |
| 54 | + q = dpctl.get_current_queue() |
| 55 | + |
| 56 | + with self.assertRaises(TypeError) as cm: |
| 57 | + q.memcpy(None, mobj, 3) |
| 58 | + |
| 59 | + self.assertEqual(type(cm.exception), TypeError) |
| 60 | + self.assertEqual(str(cm.exception), "Parameter dest should be Memory.") |
| 61 | + |
| 62 | + with self.assertRaises(TypeError) as cm: |
| 63 | + q.memcpy(mobj, None, 3) |
| 64 | + |
| 65 | + self.assertEqual(type(cm.exception), TypeError) |
| 66 | + self.assertEqual(str(cm.exception), "Parameter src should be Memory.") |
| 67 | + |
| 68 | + |
| 69 | +if __name__ == '__main__': |
| 70 | + unittest.main() |
0 commit comments