Skip to content

Commit

Permalink
[SYCL][GDB] Fixes for three issues in GDB xmethods. (intel#15250)
Browse files Browse the repository at this point in the history
Three issues are addressed:
  1. Printing non-sycl types may generate a python exception.
2. Accessor subscripts using size_t report an unsupported subscript
type.
  3. Multi-dimensional accessors calculate the wrong array layout.

---------

Co-authored-by: Dmitry Vodopyanov <[email protected]>
  • Loading branch information
2 people authored and AlexeySachkov committed Nov 26, 2024
1 parent 1a9bd30 commit d7b4230
Showing 1 changed file with 11 additions and 28 deletions.
39 changes: 11 additions & 28 deletions sycl/gdb/libsycl.so-gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def dimensions(self):
def access_mode(self):
return self.type().access_mode()

def subscript_int(self, subscript):
def subscript_sizet(self, subscript):
return self.data()[subscript]

def subscript_id(self, subscript):
Expand All @@ -185,25 +185,6 @@ def subscript_id(self, subscript):
def subscript_item(self, subscript):
return self.subscript_id(SYCLItem(subscript).index())

def __getitem__(self, subscript):
code = subscript.type.unqualified().code
if code == gdb.TYPE_CODE_INT:
return self.subscript_int(subscript)
elif (
code == gdb.TYPE_CODE_STRUCT
and subscript.type.name.startswith("sycl::_V1::item<")
and subscript.type.name.endswith(">")
):
return self.subscript_item(subscript)
elif (
code == gdb.TYPE_CODE_STRUCT
and subscript.type.name.startswith("sycl::_V1::id<")
and subscript.type.name.endswith(">")
):
return self.subscript_id(subscript)
else:
raise AttributeError("Unsupported sycl::accessor subscript type.")

def impl(self):
return self.gdb_value()["impl"]

Expand Down Expand Up @@ -511,7 +492,9 @@ def __init__(self, name):
self.name = name

def matches(self, type):
return type.name == self.name or type.name.startswith(self.name + "<")
return type.name != None and (
type.name == self.name or type.name.startswith(self.name + "<")
)

def instantiate(self):
return SYCLTypePrinter.Recognizer(self)
Expand Down Expand Up @@ -682,7 +665,7 @@ def gdb_type(self):
@staticmethod
def data_vector_type(base_type, dimensions, ranges_array):
vector_type = base_type
for index in range(dimensions):
for index in reversed(range(dimensions)):
upperbound = ranges_array[index]
inclusive_upperbound = upperbound - 1
vector_type = vector_type.vector(inclusive_upperbound)
Expand Down Expand Up @@ -1202,8 +1185,8 @@ def get_arg_types(self):
def size_type(self):
return SYCLType.size_type()

def __call__(self, accessor_ptr, subscript):
return SYCLAccessor(accessor_ptr.dereference())[subscript]
def __call__(self, ptr, subscript):
return SYCLAccessor(ptr.dereference()).subscript_sizet(subscript)


class SYCLAccessorSubscriptID(SYCLAccessorSubscript):
Expand All @@ -1217,8 +1200,8 @@ def id_type(self):
dimensions = SYCLAccessorType(self.class_type()).dimensions()
return gdb.lookup_type(f"sycl::_V1::id<{dimensions}>")

def __call__(self, accessor_ptr, subscript):
return SYCLAccessor(accessor_ptr.dereference())[subscript]
def __call__(self, ptr, subscript):
return SYCLAccessor(ptr.dereference()).subscript_id(subscript)


class SYCLAccessorSubscriptItem(SYCLAccessorSubscript):
Expand All @@ -1240,8 +1223,8 @@ def item_type(self):
except:
return None

def __call__(self, accessor_ptr, subscript):
return SYCLAccessor(accessor_ptr.dereference())[subscript]
def __call__(self, ptr, subscript):
return SYCLAccessor(ptr.dereference()).subscript_item(subscript)


class SYCLAccessorSubscriptItemOffset(SYCLAccessorSubscriptItem):
Expand Down

0 comments on commit d7b4230

Please sign in to comment.