Wednesday 2 August 2023

pytorch gdb debug

なんか、やっとできました。要するに、

  libtorch*.so

を LD_LIBRARY_PATH で切り替えることを防ぐ仕組みがあって、install してからでないと gdb できないわけね。

あと、

  apptainer 1.1.7 の --fakeroot --writable がバグってて動かない

ってのもわかりました。singularity でやったら動いた。時間の問題だとは思うけど。 

  cd /opt
  # build pytorh
  git clone --recursive https://github.com/pytorch/pytorch
  cd pytorch
  git submodule sync
  git submodule update --init --recursive
  pip install mkl mkl-include
  # pip install magma-cuda110
  pip install -r requirements.txt
  mkdir -p /opt/pytorch/build
  cd /opt/pytorch/build
  cmake .. -GNinja -DCMAKE_INSTALL_PREFIX=/opt/pytorch/torch -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/include/python3.10 -DCMAKE_BUILD_TYPE=Debug
  ninja
  ninja install
  cd /opt/pytorch
  python3 setup.py develop

できてみれば、どうってことない。なんで、こんな苦労したんだか。

  singularity shell --nv --shell /bin/zsh pytorch.sif
  gdb --args python3 ~kono/src/pytorch-test/ttest.py
  Thread 1 "python3" received signal SIGINT, Interrupt.
  [Switching to Thread 0x7f703d224280 (LWP 2849215)]
  c10::TensorOptions::pinned_memory (this=0x7ffeb2bf44c8, pinned_memory=...) at /opt/pytorch/c10/core/TensorOptions.h:261
  261    }
  (gdb) l
  256    C10_NODISCARD TensorOptions
  257    pinned_memory(c10::optional<bool> pinned_memory) const noexcept {
  258     TensorOptions r = *this;
  259     r.set_pinned_memory(pinned_memory);
  260     return r;
  261    }
  262
  263    /// Sets the `memory_format` property on `TensorOptions`.
  264    C10_NODISCARD TensorOptions
  265    memory_format(c10::optional<MemoryFormat> memory_format) const noexcept {
  (gdb) bt
  #0 c10::TensorOptions::pinned_memory (this=0x7ffeb2bf44c8, pinned_memory=...) at /opt/pytorch/c10/core/TensorOptions.h:261
  #1 0x00007f7033f85bab in torch::autograd::THPVariable_ones_like (self_=0x0, args=0x7f6eae15ee00, kwargs=0x7f703cfaa580)
    at /opt/pytorch/torch/csrc/autograd/generated/python_torch_functions_1.cpp:4836
  #2 0x0000559eece47c9e in ?? ()
  #3 0x0000559eece3e72b in _PyObject_MakeTpCall ()

No comments: