0%

Run and exec

  • docker run --ipc=host --gpus all --entrypoint=/bin/bash -it -d -v /home/name:/home/name -e TZ=Asia/Beijing --name ouyang tensorflow/tensorflow:2.4.1-gpu
  • run flags:
    • --pid=host: Use it if you want your container to share the host’s process namespace, basically allowing processes within the container to see all of the processes on the system.
    • --ipc=private|shareable|host|container:name-or-id: IPC namespace provides separation of named shared memory segments, semaphores and message queues. Shared memory segments is commenly used by databases and C/OpenMPI, C++/using boost libraries and etc.
  • docker exec -it ${container_name} /bin/bash
  • docker exec -it -w /home/name ouyang sh -c “tmux a” /bin/bash

System

  • docker system df
  • docker system df -v
  • sudo service docker start/stop
Read more »

Structure of TensorFlow HashTable source code

core/kernels/lookup_table_op.h

  • class LookupTableOp:

    • This class inherits from the OpKernel class and supports different table implementations specified by the Container template.
    • It has a member PersistentTensor table_handle_. This member is stored in the OpKernelContext by ctx->allocate_persistent.
  • Container must be inherited from LookupInterface. Container example: MutableDenseHashTable, MutableHashTableOfTensors and etc.

  • class HashTable: This class inherits from InitializableLookupTable class and wraps an flat_hash_map, where the key and value data type is specified. Once the table is marked as initialized it becomes read-only.

core/kernels/lookup_table_op.cc

  • LookupTableOpKernel: This class inherits from the OpKernel.

  • It will make sure the table_handle_ will be the first input for ops such as LookupTableFind, LookupTableInsert, etc.

  • This class will be inherited by operations like Remove, Insert, Find, Size, Export, Import and etc. For example:

    1
    2
    3
    class LookupTableOpKernel : public OpKernel;
    class LookupTableFindOp : public LookupTableOpKernel;
    REGISTER_KERNEL_BUILDER(Name("LookupTableFindV2").LookupTableFindOp);
  • Here are some examples of hashtable kernel builder:

    1
    2
    3
    REGISTER_KERNEL_BUILDER(Name("HashTableV2"), LookupTableOp<lookup::HashTable<key_dtype, value_dtype>, key_dtype, value_dtype>);
    REGISTER_KERNEL_BUILDER(Name("MutableHashTableV2"), LookupTableOp<lookup::MutableHashTableOfScalars<key_dtype, value_dtype>, key_dtype, value_dtype>);
    REGISTER_KERNEL_BUILDER(Name("MutableHashTableOfTensorsV2"), LookupTableOp<lookup::MutableHashTableOfTensors<key_dtype, value_dtype>, key_dtype, value_dtype>);
Read more »

Why “file(GLOB xxx)” is evil

About find_package

  • Check local modules: cmake –help-module-list

  • Manual for a specific module: cmake –help-module FindCUDA

    Read more »

Good git resources

Git Move files from one repository to another while preserving git history

  1. mkdir merge_repo && cd merge_repo
  2. git clone --branch master --origin origin --progress -v git@github:xxx/projectA.git
  3. cd projectA
  4. git remote rm origin
  5. git filter-branch --subdirectory-filter subfolder/FOLDER_TO_KEEP -- --all
  6. git reset --hard && git gc --aggressive && git prune && git clean -fd
  7. (optional) mkdir anotherfolder && mv * anotherfolder && git add . && git commit
  8. cd ..
  9. git clone <git repository B url> projectB
  10. cd projectB
  11. git remote add repoA ../projectA
  12. git pull repoA master --allow-unrelated-histories
  13. git remote rm repoA
  14. git push
Read more »

CI: clang and yapf

  • clang-format -style=file -i tensorflow/core/kernels/ResourceSparseApplyAdagradV2.*
  • yapf -i --style pep8 tensorflow/python/test_abs.py
  • cpplint --linelength=80 --counting=detailed --filter=-build/namespaces --root=src $(find src/pytorch_ops -name “.h” -or -name “.cc”)
  • cpplint --linelength=80 --counting=detailed --root=src $(find src -path “src/pytorch_ops” -prune -name “.h” -or -name “.cc”)

GDB and nm

  • nm -D BINARY // Only show BINARY (object file, static/dynamic library, executable) dynamic section’s symbol: T/t means golbal/local symbol. U means undefined symbol.
  • nm -Du BINARY // Only show undefined symbol
  • c++filt // Transform symbols in so to human readable form

Performance Monitoring Tools

  • Program Optimization: Gprof, Perf, VTune
  • Program Debugging: Valgrind, Sanitizers
  • Advanced Analysis: Pin, Contech
    Read more »