candle icon indicating copy to clipboard operation
candle copied to clipboard

Add a GDB pretty printer for Tensor objects

Open nickhs opened this issue 1 year ago • 0 comments
trafficstars

Adds a python pretty printer for GDB for Tensor values. Tensor values in GDB now have a "desc" field that contains a formatted view of the tensor similar to the Debug struct.

(gdb) source ./candle-core/scripts/gdb_pretty_printer.py 
Registering global candle-core pretty-printer ...
(gdb) p a
$2 = "Tensor [2, 3]" = {
  raw = Arc(strong=1, weak=0) = {
    value = candle_core::tensor::Tensor_ {
      id: candle_core::tensor::TensorId (
      <snip>
          data: core::cell::UnsafeCell<candle_core::storage::Storage> {
            value: candle_core::storage::Storage::Cpu(candle_core::cpu_backend::CpuStorage::F32(Vec(size=6) = {0, 1, 2, 3, 4, 5}))
          }
       <snip>
  },
  desc = 
[[0, 1, 2],
 [3, 4, 5]]
}

Future work once https://sourceware.org/bugzilla/show_bug.cgi?id=12806 is resolved would be to move the custom pretty printing solution into actually yielding child printers.

nickhs avatar Mar 11 '24 19:03 nickhs