In this post we keep records for setting up procedure on Tensorflow custom-op development environment.
Conda
At first, we recommend using Conda to seperate the Python version and dependency.
Conda configuration file ~/.condarc
Conda init script inside like bashrc
Use like conda init zsh
to setup Conda automatically. Or place following snippet in common shell rc file to support multiple shell:
Get faimilar with Conda command
Conda with TF2.3 under CUDA 10
TF2.3 is the last version support CUDA 10, or upgrade Nvidia driver for >=TF2.4. But Conda do not provide TF2.3 out of box because of some issues.
Thought it is not recommended way, we use pip to install TF2.3 while conda to install the must have cudnn
and cudatoolkit
package.
The envrionment configuration for TF2.3 and furthur data science were exported.
Tensorflow Custom-op
tfopgen is a scaffold project to generate custom-op start-up codebase.
The Tensorflow package root path can be found with TF_ROOT=$(python -c 'import pkgutil as p; from pathlib import Path; print(Path(p.get_loader("tensorflow").get_filename()).parent)')
.
Be careful with some inconsistence issues:
-
Missing header file under
third_party
. Do a link likeln -s "$(dirname $(command -v nvcc))/../targets/x86_64-linux/include" ${TF_ROOT}/include/third_party/gpus/cuda/include
-
cuda toolkit (e.g. nvcc) better be a fixed path or a lot of changes needed. Do a link with
ln -s "$(dirname $(command -v nvcc))/.." /usr/local/cuda
-
Be careful with your GPU’s capcbility while spectifying
nvcc
options--gpu-architecture
. Or weird things can happen in runtime, like triggeringno kernel image is available for execution on the device
hence a segment fault to crash the process. One can placeGPU_ARCH := $(shell python3 -c "from tensorflow.python.client import device_lib; print(next(d.physical_device_desc for d in device_lib.list_local_devices() if d.device_type=='GPU'))" 2> /dev/null | awk -F: -v RS=, '/compute capability/{print "sm_"int($2*10)}')
inside the Makefile and then use--gpu-architecture=$(GPU_ARCH)
inside theNVCCFLAGS
.