Skip to content

Commit 9cd6bd8

Browse files
Moved _memory.pyx, _memory.pxd to dpctl.memory submodule
Now to access memory objects one does import dpctl import dpctl.memory
1 parent 3b06ba8 commit 9cd6bd8

File tree

10 files changed

+87
-21
lines changed

10 files changed

+87
-21
lines changed

dpctl/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
__author__ = "Intel Corp."
4848

4949
from ._sycl_core import *
50-
from ._memory import MemoryUSMShared, MemoryUSMDevice, MemoryUSMHost
5150
from ._version import get_versions
5251

5352

dpctl/_sycl_core.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ from __future__ import print_function
3030
from enum import Enum, auto
3131
import logging
3232
from ._backend cimport *
33-
from ._memory cimport _Memory
33+
from .memory._memory cimport _Memory
3434
from libc.stdlib cimport malloc, free
3535

3636

dpctl/memory/__init__.pxd

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
##===------------- __init__.pxd - dpctl module --------*- Cython -*-------===##
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+
## This file declares the extension types and functions for the Cython API
23+
## implemented in sycl_core.pyx.
24+
##
25+
##===----------------------------------------------------------------------===##
26+
27+
# distutils: language = c++
28+
# cython: language_level=3
29+
30+
from ._memory cimport *

dpctl/memory/__init__.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
##===---------- memory/__init__.py - dpctl module -------*- 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+
## This top-level dpctl module.
23+
##
24+
##===----------------------------------------------------------------------===##
25+
"""
26+
Data Parallel Control Memory
27+
28+
`dpctl.memory` provides Python objects for untyped USM memory
29+
container of bytes for each kind of USM pointers: shared pointers,
30+
device pointers and host pointers.
31+
32+
Shared and host pointers are accessible from both host and a device,
33+
while device pointers are only accessible from device.
34+
35+
Python objects corresponding to shared and host pointers implement
36+
Python simple buffer protocol. It is therefore possible to use these
37+
objects to maniputalate USM memory using NumPy or `bytearray`,
38+
`memoryview`, or `array.array` classes.
39+
40+
"""
41+
from ._memory import MemoryUSMShared, MemoryUSMDevice, MemoryUSMHost

dpctl/_memory.pxd renamed to dpctl/memory/_memory.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
# distutils: language = c++
2222
# cython: language_level=3
2323

24-
from ._backend cimport DPPLSyclUSMRef
25-
from ._sycl_core cimport SyclQueue, SyclDevice, SyclContext
24+
from .._backend cimport DPPLSyclUSMRef
25+
from .._sycl_core cimport SyclQueue, SyclDevice, SyclContext
2626

2727

2828
cdef class _Memory:

dpctl/_memory.pyx renamed to dpctl/memory/_memory.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030

3131
import dpctl
3232
from dpctl._backend cimport *
33-
from ._sycl_core cimport SyclContext, SyclQueue, SyclDevice
34-
from ._sycl_core cimport get_current_queue
33+
from .._sycl_core cimport SyclContext, SyclQueue, SyclDevice
34+
from .._sycl_core cimport get_current_queue
3535

3636
from cpython cimport Py_buffer
3737
from cpython.bytes cimport PyBytes_AS_STRING, PyBytes_FromStringAndSize

dpctl/tests/test_sycl_kernel_submit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import ctypes
2626
import dpctl
2727
import unittest
28-
import dpctl._memory as dpctl_mem
28+
import dpctl.memory as dpctl_mem
2929
import numpy as np
3030

3131

dpctl/tests/test_sycl_queue_memcpy.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
##===----------------------------------------------------------------------===##
2424

2525
import dpctl
26+
import dpctl.memory
2627
import unittest
2728

2829

2930
class TestQueueMemcpy(unittest.TestCase):
3031
def _create_memory(self):
3132
nbytes = 1024
32-
mobj = dpctl.MemoryUSMShared(nbytes)
33+
mobj = dpctl.memory.MemoryUSMShared(nbytes)
3334
return mobj
3435

3536
@unittest.skipUnless(
@@ -60,7 +61,9 @@ def test_memcpy_type_error(self):
6061
q.memcpy(None, mobj, 3)
6162

6263
self.assertEqual(type(cm.exception), TypeError)
63-
self.assertEqual(str(cm.exception), "Parameter `dest` should have type _Memory.")
64+
self.assertEqual(
65+
str(cm.exception), "Parameter `dest` should have type _Memory."
66+
)
6467

6568
with self.assertRaises(TypeError) as cm:
6669
q.memcpy(mobj, None, 3)

dpctl/tests/test_sycl_usm.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424

2525
import unittest
2626
import dpctl
27-
from dpctl import MemoryUSMShared, MemoryUSMHost, MemoryUSMDevice
28-
import dpctl._memory
27+
from dpctl.memory import MemoryUSMShared, MemoryUSMHost, MemoryUSMDevice
2928
import numpy as np
3029

3130

setup.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ def extensions():
115115
runtime_library_dirs = []
116116

117117
extension_args = {
118-
"depends": [
119-
dppl_sycl_interface_include,
120-
],
118+
"depends": [dppl_sycl_interface_include,],
121119
"include_dirs": [np.get_include(), dppl_sycl_interface_include],
122120
"extra_compile_args": eca + get_other_cxxflags(),
123121
"extra_link_args": ela,
@@ -130,16 +128,12 @@ def extensions():
130128
extensions = [
131129
Extension(
132130
"dpctl._sycl_core",
133-
[
134-
os.path.join("dpctl", "_sycl_core.pyx"),
135-
],
131+
[os.path.join("dpctl", "_sycl_core.pyx"),],
136132
**extension_args
137133
),
138134
Extension(
139-
"dpctl._memory",
140-
[
141-
os.path.join("dpctl", "_memory.pyx"),
142-
],
135+
"dpctl.memory._memory",
136+
[os.path.join("dpctl", "memory", "_memory.pyx"),],
143137
**extension_args
144138
),
145139
]

0 commit comments

Comments
 (0)