15
15
# limitations under the License.
16
16
import dpctl
17
17
18
+ __doc__ = "Implementation of array API mandated Device class"
19
+
18
20
19
21
class Device :
20
22
"""
@@ -29,7 +31,8 @@ class Device:
29
31
or ``sycl_device``.
30
32
"""
31
33
32
- __device_queue_map__ = dict ()
34
+ __device_queue_map__ = {}
35
+ sycl_queue_ = None
33
36
34
37
def __new__ (cls , * args , ** kwargs ):
35
38
raise TypeError ("No public constructor" )
@@ -62,9 +65,9 @@ def create_device(cls, dev):
62
65
obj .sycl_queue_ = cls .__device_queue_map__ [dev ]
63
66
else :
64
67
raise ValueError (
65
- "Using non-root device {} to specify offloading "
68
+ f "Using non-root device { dev } to specify offloading "
66
69
"target is ambiguous. Please use dpctl.SyclQueue "
67
- "targeting this device" . format ( dev )
70
+ "targeting this device"
68
71
)
69
72
else :
70
73
if dev is None :
@@ -100,13 +103,13 @@ def sycl_device(self):
100
103
def __repr__ (self ):
101
104
try :
102
105
sd = self .sycl_device
103
- except AttributeError :
106
+ except AttributeError as exc :
104
107
raise ValueError (
105
- "Instance of {} is not initialized" . format ( self . __class__ )
106
- )
108
+ f "Instance of { self . __class__ } is not initialized"
109
+ ) from exc
107
110
try :
108
111
fs = sd .filter_string
109
- return "Device({})" . format ( fs )
112
+ return f "Device({ fs } )"
110
113
except TypeError :
111
114
# This is a sub-device
112
115
return repr (self .sycl_queue )
@@ -150,20 +153,19 @@ def normalize_queue_device(sycl_queue=None, device=None):
150
153
if q is None :
151
154
d = Device .create_device (d )
152
155
return d .sycl_queue
153
- else :
154
- if not isinstance (q , dpctl .SyclQueue ):
155
- raise TypeError (f"Expected dpctl.SyclQueue, got { type (q )} " )
156
- if d is None :
157
- return q
158
- d = Device .create_device (d )
159
- qq = dpctl .utils .get_execution_queue (
160
- (
161
- q ,
162
- d .sycl_queue ,
163
- )
156
+ if not isinstance (q , dpctl .SyclQueue ):
157
+ raise TypeError (f"Expected dpctl.SyclQueue, got { type (q )} " )
158
+ if d is None :
159
+ return q
160
+ d = Device .create_device (d )
161
+ qq = dpctl .utils .get_execution_queue (
162
+ (
163
+ q ,
164
+ d .sycl_queue ,
165
+ )
166
+ )
167
+ if qq is None :
168
+ raise TypeError (
169
+ "sycl_queue and device keywords can not be both specified"
164
170
)
165
- if qq is None :
166
- raise TypeError (
167
- "sycl_queue and device keywords can not be both specified"
168
- )
169
- return qq
171
+ return qq
0 commit comments