Skip to content

Instantly share code, notes, and snippets.

View tonyyang-svail's full-sized avatar

Yang Yang(Tony) tonyyang-svail

View GitHub Profile

Steps to set up Clion in docker on Linux

Step

  1. Build Paddlepaddle docker images: cd ${PADDLE_SOURCE_DIR} && docker build -t paddle:dev .
  2. Add docker to linux X11 for GUI
    1. xhost + local:docker
    2. xhost + local:nvidia-docker if you are need to use GPU
  3. Go to ${PADDLE_SOURCE_DIR}, start docker and mount paddle's source code to /paddle.
sudo nvidia-docker run -v $PWD:/paddle -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix paddle:dev bash
name: "ResNet-50"
input: "data"
input_dim: 1
input_dim: 3
input_dim: 224
input_dim: 224
layer {
bottom: "data"
top: "conv1"
// https://stackoverflow.com/questions/14038589/what-is-the-canonical-way-to-check-for-errors-using-the-cuda-runtime-api
#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }
inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true)
{
if (code != cudaSuccess)
{
fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
if (abort) exit(code);
}
}
# find backward in all CMakeLists.txt
find paddle/fluid/ -name "CMakeLists.txt" | xargs grep backward
# replace dynamic to tape in all files
ack -l dynamic | xargs sed -i 's/dynamic/tape/g'
#include <iostream>
#include <tuple>
template <size_t I, bool at_end, typename... ARGS>
struct IterOverTypesImpl;
template <size_t I, typename... ARGS>
struct IterOverTypesImpl<I, false, ARGS...> {
void operator()() {
using T = typename std::tuple_element<I, std::tuple<ARGS...>>::type;
Since most of the codes are divided into seperate operators,
and every operator is stored inside a map, how would c++ compiler
take the advantage of the global view to optimize?

Function Default Arguemnt

It seems that we need this fix because the last parameter of TensorCopy has a default value:

https://github.com/PaddlePaddle/Paddle/blob/c816121d11f7aed2939c5b859423883ce8bab050/paddle/fluid/framework/tensor_util.h#L26-L28

The code style does warned the use of default argument: https://google.github.io/styleguide/cppguide.html#Default_Arguments

In short, the existence of this default argument here might make users ignore the fact that TensorCopy has two modes, thus leads to some mis-uses.

Main thread: https://www.cprogramming.com/debugging/segfaults.html

Steps:

  1. Run Docker with priviledged: sudo nvidia-docker run -it --rm --privileged --net=host -v $PWD:/paddle -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY paddle:dev bash
  2. Get rid of read-only file system: mount -o remount,rw /
  3. Make core dump path as the current path bash -c 'echo core.%e.%p > /proc/sys/kernel/core_pattern'
  4. Install gdb: apt-get install gdb
  5. Run core dumped executable: ./op_registry_test
  6. Look for core.dump file, in my case, core.op_registry_tes.72
  7. Use gdb to exam: gdb op_registry_test core.op_registry_tes.72
#include <iostream>
#include <typeinfo> //for 'typeid' to work
#include <typeindex>
using namespace std;
class Base {};
int main() {
cout << typeid(Base).name() << endl; // 4Base