Skip to content

Commit e1fdd13

Browse files
siboehmmiscco
authored andcommitted
[skip-tests] gdb pretty printer: handle non-cuda device vectors
1 parent 812ba98 commit e1fdd13

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

thrust/scripts/gdb-pretty-printers.py

+28-9
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __next__(self):
3131
self.count = self.count + 1
3232
return ('[%d]' % count, elt)
3333

34-
class _device_iterator(Iterator):
34+
class _cuda_iterator(Iterator):
3535
def __init__(self, start, size):
3636
self.exec = exec
3737
self.item = start
@@ -88,14 +88,14 @@ def __init__(self, val):
8888
self.pointer = val['m_storage']['m_begin']['m_iterator']
8989
self.size = int(val['m_size'])
9090
self.capacity = int(val['m_storage']['m_size'])
91-
self.is_device = False
92-
if str(self.pointer.type).startswith("thrust::device_ptr"):
91+
self.is_device_vector = str(self.pointer.type).startswith("thrust::device_ptr")
92+
if self.is_device_vector:
9393
self.pointer = self.pointer['m_iterator']
94-
self.is_device = True
94+
self.is_cuda_vector = "cuda" in str(val['m_storage']['m_allocator'])
9595

9696
def children(self):
97-
if self.is_device:
98-
return self._device_iterator(self.pointer, self.size)
97+
if self.is_cuda_vector:
98+
return self._cuda_iterator(self.pointer, self.size)
9999
else:
100100
return self._host_accessible_iterator(self.pointer, self.size)
101101

@@ -107,8 +107,8 @@ def display_hint(self):
107107
return 'array'
108108

109109

110-
class ThrustReferencePrinter(gdb.printing.PrettyPrinter):
111-
"Print a thrust::device_reference"
110+
class ThrustCUDAReferencePrinter(gdb.printing.PrettyPrinter):
111+
"Print a thrust::device_reference that resides in CUDA memory space"
112112

113113
def __init__(self, val):
114114
self.val = val
@@ -138,6 +138,22 @@ def to_string(self):
138138
def display_hint(self):
139139
return None
140140

141+
class ThrustHostAccessibleReferencePrinter(gdb.printing.PrettyPrinter):
142+
def __init__(self, val):
143+
self.val = val
144+
self.pointer = val['ptr']['m_iterator']
145+
146+
def children(self):
147+
return []
148+
149+
def to_string(self):
150+
typename = str(self.val.type)
151+
return ('(%s) @%s: %s' % (typename, self.pointer, self.pointer.dereference()))
152+
153+
def display_hint(self):
154+
return None
155+
156+
141157

142158
def lookup_thrust_type(val):
143159
if not str(val.type.unqualified()).startswith('thrust::'):
@@ -146,7 +162,10 @@ def lookup_thrust_type(val):
146162
if suffix.startswith('host_vector') or suffix.startswith('device_vector'):
147163
return ThrustVectorPrinter(val)
148164
elif int(gdb.VERSION.split(".")[0]) >= 10 and suffix.startswith('device_reference'):
149-
return ThrustReferencePrinter(val)
165+
# look for tag in type name
166+
if "cuda" in "".join(str(field.type) for field in val["ptr"].type.fields()):
167+
return ThrustCUDAReferencePrinter(val)
168+
return ThrustHostAccessibleReferencePrinter(val)
150169
return None
151170

152171

0 commit comments

Comments
 (0)