99
1010### XMethod implementations ###
1111
12+
1213class Accessor :
1314 """Generalized base class for buffer index calculation"""
1415
@@ -31,15 +32,17 @@ def index(self, arg):
3132 return int (arg )
3233 # unwrap if inside item
3334 try :
34- arg = arg [' MImpl' ][ ' MIndex' ]
35+ arg = arg [" MImpl" ][ " MIndex" ]
3536 except :
3637 pass
3738 # https://github.com/intel/llvm/blob/97272b7ebd569bfa13811913a31e30f926559217/sycl/include/CL/sycl/accessor.hpp#L678-L690
3839 result = 0
3940 for dim in range (self .depth ):
40- result = result * self .memory_range (dim ) + \
41- self .offset (dim ) + \
42- arg ['common_array' ][dim ]
41+ result = (
42+ result * self .memory_range (dim )
43+ + self .offset (dim )
44+ + arg ["common_array" ][dim ]
45+ )
4346 return result
4447
4548 def value (self , arg ):
@@ -50,16 +53,17 @@ class HostAccessor(Accessor):
5053 """For Host device memory layout"""
5154
5255 def payload (self ):
53- return self .obj [' impl' ][ ' _M_ptr' ].dereference ()
56+ return self .obj [" impl" ][ " _M_ptr" ].dereference ()
5457
5558 def memory_range (self , dim ):
56- return self .payload ()[' MMemoryRange' ][ ' common_array' ][dim ]
59+ return self .payload ()[" MMemoryRange" ][ " common_array" ][dim ]
5760
5861 def offset (self , dim ):
59- return self .payload ()[' MOffset' ][ ' common_array' ][dim ]
62+ return self .payload ()[" MOffset" ][ " common_array" ][dim ]
6063
6164 def data (self ):
62- return self .payload ()['MData' ]
65+ return self .payload ()["MData" ]
66+
6367
6468class HostAccessorLocal (HostAccessor ):
6569 """For Host device memory layout"""
@@ -68,27 +72,29 @@ def index(self, arg):
6872 if arg .type .code == gdb .TYPE_CODE_INT :
6973 return int (arg )
7074 # https://github.com/intel/llvm/blob/97272b7ebd569bfa13811913a31e30f926559217/sycl/include/CL/sycl/accessor.hpp#L1049-L1053
71- result = 0 ;
75+ result = 0
7276 for dim in range (self .depth ):
73- result = result * \
74- self .payload ()['MSize' ]['common_array' ][dim ] + \
75- arg ['common_array' ][dim ];
76- return result ;
77+ result = (
78+ result * self .payload ()["MSize" ]["common_array" ][dim ]
79+ + arg ["common_array" ][dim ]
80+ )
81+ return result
7782
7883 def data (self ):
79- return self .payload ()['MMem' ]
84+ return self .payload ()["MMem" ]
85+
8086
8187class DeviceAccessor (Accessor ):
8288 """For CPU/GPU memory layout"""
8389
8490 def memory_range (self , dim ):
85- return self .obj [' impl' ][ ' MemRange' ][ ' common_array' ][dim ]
91+ return self .obj [" impl" ][ " MemRange" ][ " common_array" ][dim ]
8692
8793 def offset (self , dim ):
88- return self .obj [' impl' ][ ' Offset' ][ ' common_array' ][dim ]
94+ return self .obj [" impl" ][ " Offset" ][ " common_array" ][dim ]
8995
9096 def data (self ):
91- return self .obj [' MData' ]
97+ return self .obj [" MData" ]
9298
9399
94100class AccessorOpIndex (gdb .xmethod .XMethodWorker ):
@@ -106,12 +112,12 @@ def get_result_type(self, *args):
106112 return self .result_type
107113
108114 def __call__ (self , obj , arg ):
109- # No way to wasily figure out which devices is currently being used,
115+ # No way to easily figure out which devices is currently being used,
110116 # try all accessor implementations until one of them works:
111117 accessors = [
112118 DeviceAccessor (obj , self .result_type , self .depth ),
113119 HostAccessor (obj , self .result_type , self .depth ),
114- HostAccessorLocal (obj , self .result_type , self .depth )
120+ HostAccessorLocal (obj , self .result_type , self .depth ),
115121 ]
116122 for accessor in accessors :
117123 try :
@@ -129,39 +135,41 @@ class AccessorOpIndex1D(AccessorOpIndex):
129135
130136 def get_arg_types (self ):
131137 assert self .depth == 1
132- return gdb .lookup_type ('size_t' )
138+ return gdb .lookup_type ("size_t" )
139+
133140
134141class AccessorOpIndexItemTrue (AccessorOpIndex ):
135142 """Introduces an extra overload for item wrapper"""
136143
137144 def get_arg_types (self ):
138145 return gdb .lookup_type ("cl::sycl::item<%s, true>" % self .depth )
139146
147+
140148class AccessorOpIndexItemFalse (AccessorOpIndex ):
141149 """Introduces an extra overload for item wrapper"""
142150
143151 def get_arg_types (self ):
144152 return gdb .lookup_type ("cl::sycl::item<%s, false>" % self .depth )
145153
154+
146155class AccessorMatcher (gdb .xmethod .XMethodMatcher ):
147156 """Entry point for cl::sycl::accessor"""
157+
148158 def __init__ (self ):
149- gdb .xmethod .XMethodMatcher .__init__ (self , ' AccessorMatcher' )
159+ gdb .xmethod .XMethodMatcher .__init__ (self , " AccessorMatcher" )
150160
151161 def match (self , class_type , method_name ):
152- if method_name != ' operator[]' :
162+ if method_name != " operator[]" :
153163 return None
154164
155- result = re .match (' ^cl::sycl::accessor<.+>$' , class_type .tag )
165+ result = re .match (" ^cl::sycl::accessor<.+>$" , class_type .tag )
156166 if result is None :
157167 return None
158168
159169 depth = int (class_type .template_argument (1 ))
160170 result_type = class_type .template_argument (0 )
161171
162- methods = [
163- AccessorOpIndex (class_type , result_type , depth )
164- ]
172+ methods = [AccessorOpIndex (class_type , result_type , depth )]
165173 try :
166174 method = AccessorOpIndexItemTrue (class_type , result_type , depth )
167175 method .get_arg_types ()
@@ -178,38 +186,49 @@ def match(self, class_type, method_name):
178186 methods .append (AccessorOpIndex1D (class_type , result_type , depth ))
179187 return methods
180188
189+
181190class PrivateMemoryOpCall (gdb .xmethod .XMethodWorker ):
182191 """Provides operator() overload for h_item argument"""
183192
184193 class ItemBase :
185194 """Wrapper for cl::sycl::detail::ItemBase which reimplements index calculation"""
186195
187- def __init__ (self , obj , ):
188- result = re .match ('^cl::sycl::detail::ItemBase<(.+), (.+)>$' , str (obj .type ))
196+ def __init__ (
197+ self ,
198+ obj ,
199+ ):
200+ result = re .match ("^cl::sycl::detail::ItemBase<(.+), (.+)>$" , str (obj .type ))
189201 self .dim = int (result [1 ])
190- self .with_offset = ( result [2 ] == ' true' )
202+ self .with_offset = result [2 ] == " true"
191203 self .obj = obj
192204
193205 def get_linear_id (self ):
194- index = self .obj [' MIndex' ][ ' common_array' ]
195- extent = self .obj [' MExtent' ][ ' common_array' ]
206+ index = self .obj [" MIndex" ][ " common_array" ]
207+ extent = self .obj [" MExtent" ][ " common_array" ]
196208
197209 if self .with_offset :
198- offset = self .obj [' MOffset' ][ ' common_array' ]
210+ offset = self .obj [" MOffset" ][ " common_array" ]
199211 if self .dim == 1 :
200212 return index [0 ] - offset [0 ]
201213 elif self .dim == 2 :
202214 return (index [0 ] - offset [0 ]) * extent [1 ] + (index [1 ] - offset [1 ])
203215 else :
204- return ((index [0 ] - offset [0 ]) * extent [1 ] * extent [2 ]) + \
205- ((index [1 ] - offset [1 ]) * extent [2 ]) + (index [2 ] - offset [2 ])
216+ return (
217+ ((index [0 ] - offset [0 ]) * extent [1 ] * extent [2 ])
218+ + ((index [1 ] - offset [1 ]) * extent [2 ])
219+ + (index [2 ] - offset [2 ])
220+ )
206221 else :
207222 if self .dim == 1 :
208223 return index [0 ]
209224 elif self .dim == 2 :
210225 return index [0 ] * extent [1 ] + index [1 ]
211226 else :
212- return (index [0 ] * extent [1 ] * extent [2 ]) + (index [1 ] * extent [2 ]) + index [2 ]
227+ return (
228+ (index [0 ] * extent [1 ] * extent [2 ])
229+ + (index [1 ] * extent [2 ])
230+ + index [2 ]
231+ )
213232
214233 def __init__ (self , result_type , dim ):
215234 self .result_type = result_type
@@ -222,38 +241,41 @@ def get_result_type(self, *args):
222241 return self .result_type
223242
224243 def __call__ (self , obj , * args ):
225- if obj [' Val' ].type .tag .endswith (self .result_type ):
244+ if obj [" Val" ].type .tag .endswith (self .result_type ):
226245 # On device private_memory is a simple wrapper over actual value
227- return obj [' Val' ]
246+ return obj [" Val" ]
228247 else :
229248 # On host it wraps a unique_ptr to an array of items
230- item_base = args [0 ][' localItem' ][ ' MImpl' ]
249+ item_base = args [0 ][" localItem" ][ " MImpl" ]
231250 item_base = self .ItemBase (item_base )
232251 index = item_base .get_linear_id ()
233- return obj ['Val' ]['_M_t' ]['_M_t' ]['_M_head_impl' ][index ]
252+ return obj ["Val" ]["_M_t" ]["_M_t" ]["_M_head_impl" ][index ]
253+
234254
235255class PrivateMemoryMatcher (gdb .xmethod .XMethodMatcher ):
236256 """Entry point for cl::sycl::private_memory"""
237257
238258 def __init__ (self ):
239- gdb .xmethod .XMethodMatcher .__init__ (self , ' PrivateMemoryMatcher' )
259+ gdb .xmethod .XMethodMatcher .__init__ (self , " PrivateMemoryMatcher" )
240260
241261 def match (self , class_type , method_name ):
242- if method_name != ' operator()' :
262+ if method_name != " operator()" :
243263 return None
244264
245- result = re .match ('^cl::sycl::private_memory<((cl::)?(sycl::)?id<.+>), (.+)>$' , class_type .tag )
265+ result = re .match (
266+ "^cl::sycl::private_memory<((cl::)?(sycl::)?id<.+>), (.+)>$" , class_type .tag
267+ )
246268 if result is None :
247269 return None
248270 return PrivateMemoryOpCall (result [1 ], result [4 ])
249271
250272
251-
252273gdb .xmethod .register_xmethod_matcher (None , AccessorMatcher (), replace = True )
253274gdb .xmethod .register_xmethod_matcher (None , PrivateMemoryMatcher (), replace = True )
254275
255276### Pretty-printer implementations ###
256277
278+
257279class SyclArrayPrinter :
258280 """Print an object deriving from cl::sycl::detail::array"""
259281
@@ -275,7 +297,7 @@ def __next__(self):
275297 elt = self .data [count ]
276298 except :
277299 elt = "<error reading variable>"
278- return (' [%d]' % count , elt )
300+ return (" [%d]" % count , elt )
279301
280302 def __init__ (self , value ):
281303 if value .type .code == gdb .TYPE_CODE_REF :
@@ -288,7 +310,7 @@ def __init__(self, value):
288310
289311 def children (self ):
290312 try :
291- return self .ElementIterator (self .value [' common_array' ], self .dimensions )
313+ return self .ElementIterator (self .value [" common_array" ], self .dimensions )
292314 except :
293315 # There is no way to return an error from this method. Return an
294316 # empty iterable to make GDB happy and rely on to_string method
@@ -300,13 +322,14 @@ def to_string(self):
300322 # Check if accessing array value will succeed and resort to
301323 # error message otherwise. Individual array element access failures
302324 # will be caught by iterator itself.
303- _ = self .value [' common_array' ]
325+ _ = self .value [" common_array" ]
304326 return self .type .tag
305327 except :
306328 return "<error reading variable>"
307329
308330 def display_hint (self ):
309- return 'array'
331+ return "array"
332+
310333
311334class SyclBufferPrinter :
312335 """Print a cl::sycl::buffer"""
@@ -316,18 +339,22 @@ def __init__(self, value):
316339 self .type = value .type .unqualified ().strip_typedefs ()
317340 self .elt_type = value .type .template_argument (0 )
318341 self .dimensions = value .type .template_argument (1 )
319- self .typeregex = re .compile (' ^([a-zA-Z0-9_:]+)(<.*>)?$' )
342+ self .typeregex = re .compile (" ^([a-zA-Z0-9_:]+)(<.*>)?$" )
320343
321344 def to_string (self ):
322345 match = self .typeregex .match (self .type .tag )
323346 if not match :
324347 return "<error parsing type>"
325- return ('%s<%s, %s> = {impl=%s}'
326- % (match .group (1 ), self .elt_type , self .dimensions ,
327- self .value ['impl' ].address ))
348+ return "%s<%s, %s> = {impl=%s}" % (
349+ match .group (1 ),
350+ self .elt_type ,
351+ self .dimensions ,
352+ self .value ["impl" ].address ,
353+ )
354+
328355
329356sycl_printer = gdb .printing .RegexpCollectionPrettyPrinter ("SYCL" )
330- sycl_printer .add_printer ("cl::sycl::id" , ' ^cl::sycl::id<.*$' , SyclArrayPrinter )
331- sycl_printer .add_printer ("cl::sycl::range" , ' ^cl::sycl::range<.*$' , SyclArrayPrinter )
332- sycl_printer .add_printer ("cl::sycl::buffer" , ' ^cl::sycl::buffer<.*$' , SyclBufferPrinter )
357+ sycl_printer .add_printer ("cl::sycl::id" , " ^cl::sycl::id<.*$" , SyclArrayPrinter )
358+ sycl_printer .add_printer ("cl::sycl::range" , " ^cl::sycl::range<.*$" , SyclArrayPrinter )
359+ sycl_printer .add_printer ("cl::sycl::buffer" , " ^cl::sycl::buffer<.*$" , SyclBufferPrinter )
333360gdb .printing .register_pretty_printer (None , sycl_printer , True )
0 commit comments