Monday 31 May 2021

How to setup a FTP server in Ubuntu?

 Ref: https://www.techrepublic.com/article/how-to-quickly-setup-an-ftp-server-on-ubuntu-18-04/

The VSFTP daemon is found in the standard repositories, so installation can be pulled off with a single command. Open a terminal window and issue the following:

sudo apt-get install vsftpd

Start and enable the service with the commands:

sudo systemctl start vsftpd
sudo systemctl enable vsftpd

Once that installation completes, you're ready to continue.

Creating an FTP user

We're going to make this very easy and create a user for the FTP service that you can then give out to those who need it (and don't have a user account on the server). This could be considered an account for generic FTP usage. You can always create more, and anyone with a user account on the server can log via FTP. Our user will be called ftpuser and is created with the command:

sudo useradd -m ftpuser

Set the user's password with the command:

sudo passwd ftpuser

Your user is ready to go.

Configuring VSFTP

We're going to create a brand new configuration file. Before we do that, let's rename the original with the command:

sudo mv /etc/vsftpd.conf /etc/vsftpd.conf.orig

Create the new file with the command:

sudo nano /etc/vsftpd.conf

In that file, place the following:

listen=NO
listen_ipv6=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES
chroot_local_user=YES
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=NO
pasv_enable=Yes
pasv_min_port=10000
pasv_max_port=10100
allow_writeable_chroot=YES

Logging in

At this point, you should be able to log into your FTP server using the ftpuser created earlier. Login with your favorite FTP GUI client or the command line. You can now upload and download files to your heart's content. Those files will be saved in the home directory of the ftpuser user (so /home/ftpuser). With our configuration file, we've disabled anonymous usage, so the only way to log in will be with a working account on the server.

Done and done

That's it. In about a minute, you've created an FTP server on Ubuntu 18.04. It really is that easy. Remember, however, this is pretty basic. The goal was to get it up and running quickly, so you might find it doesn't perfectly fit your needs. Fortunately, VSFTP is a fairly flexible server. To learn more about what this FTP server can do, issue the command man vsftpd.

Saturday 29 May 2021

How to use Nvidia Triton Inference Server?

ubuntu16/18, driver 440.33.01, nvcr.io/nvidia/tritonserver:20.03-py3, NVIDIA Triton Inference Server 1.12.0
======

step: pull the triton docker
> docker pull nvcr.io/nvidia/tritonserver:20.03-py3

step: download the model example
> git clone https://github.com/triton-inference-server/server.git
(triton server root: /home/ninja/server)
> git checkout r20.03
> cd /home/ninja/server/docs/examples
> ./fetch_models.sh
(to check the model configuration, go to /home/ninja/server/docs/examples/model_repository/*)
> cd /home/ninja/server/docs/examples
> mkdir -p ensemble_model_repository/preprocess_resnet50_ensemble/1

step: up the triton server
> docker run --gpus=1 --rm -p8000:8000 -p8001:8001 -p8002:8002 -v/home/ninja/server/docs/examples/model_repository:/models nvcr.io/nvidia/tritonserver:20.03-py3 trtserver --model-repository=/models

or

> docker run --rm --shm-size=1g --ulimit memlock=-1 --ulimit stack=67108864 -p8000:8000 -p8001:8001 -p8002:8002 -v/home/ninja/server/docs/examples/model_repository:/models nvcr.io/nvidia/tritonserver:20.03-py3 trtserver --model-repository=/models

docker: Error response from daemon: could not select device driver "" with capabilities: [[gpu]].
> sudo apt install nvidia-container-toolkit
> sudo systemctl restart docker

step: check the triton server status
> curl localhost:8000/api/status
(ready_state: SERVER_READY)

step: pull and run the client example
> docker run -it --rm --net=host nvcr.io/nvidia/tritonserver:20.03-py3-clientsdk
(inside docker now)
> root@luke:/workspace#

======

step: run the model inference
> root@luke:/workspace# image_client -m resnet50_netdef -s INCEPTION /workspace/images/mug.jpg

or using python

> cd /workspace/src/clients/python/api_v1/examples
> root@luke:/workspace/src/clients/python/api_v1/examples# python image_client.py -m resnet50_netdef -s INCEPTION /workspace/images/mug.jpg

or using GRPC instead of HTTP as previous two examples

> root@luke:/workspace# image_client -i grpc -u localhost:8001 -m resnet50_netdef -s INCEPTION /workspace/images/mug.jpg

or using -c to see more top n classification results

> root@luke:/workspace# image_client -m resnet50_netdef -s INCEPTION -c 5 /workspace/images/mug.jpg

or the -b flag allows you to send a batch of images for inferencing

> root@luke:/workspace# image_client -m resnet50_netdef -s INCEPTION -c 3 -b 2 /workspace/images/mug.jpg

or provide a directory instead of a single image to perform inferencing on all images in the directory

> root@luke:/workspace# image_client -i grpc -u localhost:8001 -m densenet_onnx -c 5 -s INCEPTION /workspace/images/

or Ensemble Image Classification Example Application ???, need to restart docker ???

> ensemble_image_client /workspace/images/mug.jpg


======

step: to benchmark the model
root@luke:/workspace# perf_client -m resnet50_netdef --concurrency-range 1:4 -f perf.csv
root@luke:/workspace# cp perf.csv /temp (host directory)
(then, make a copy https://docs.google.com/spreadsheets/d/1IsdW78x_F-jLLG4lTV0L-rruk0VEBRL7Mnb-80RGLL4/edit#gid=1572240508)
(and, import the perf.csv into google docs copy)

step: how to use dynamic batching and multiple instances of a single model
https://docs.nvidia.com/deeplearning/triton-inference-server/archives/triton_inference_server_1120/triton-inference-server-guide/docs/optimization.html

example of dynamic batching and multiple instances for config.pbtxt, need to restart triton-client docker
name: "resnet50_netdef"
platform: "caffe2_netdef"
max_batch_size: 128
dynamic_batching { preferred_batch_size: [ 4 ] }
instance_group [ { count: 2 }]
input [
  {
    name: "gpu_0/data"
    data_type: TYPE_FP32
    format: FORMAT_NCHW
    dims: [ 3, 224, 224 ]
  }
]
output [
  {
    name: "gpu_0/softmax"
    data_type: TYPE_FP32
    dims: [ 1000 ]
    label_filename: "resnet50_labels.txt"
  }
]

root@luke:/workspace# perf_client -m resnet50_netdef --concurrency-range 4

reference:
- https://github.com/triton-inference-server/server/blob/main/docs/quickstart.md
- https://docs.nvidia.com/deeplearning/triton-inference-server/archives/triton_inference_server_1120/triton-inference-server-guide/docs/run.html#checking-inference-server-status

Friday 28 May 2021

Python's os and subprocess Popen Commands

 https://stackabuse.com/pythons-os-and-subprocess-popen-commands/

Friday 21 May 2021

Resolve ‘rodata' can not be used when making a PIE object; recompile with -fPIC?

 1. Question
       When I use Ubuntu18.04 desktop operating system to compile "Onenet Video SDK"(https://github.com/cm-heclouds/video_sdk),I encountered an problem as below:

/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(bignum.c.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(ctr_drbg.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(entropy.c.o): relocation R_X86_64_32 against symbol `mbedtls_platform_entropy_poll' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(entropy_poll.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(rsa.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(sha1.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(sha512.c.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(timing.c.o): relocation R_X86_64_32 against `.text' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(aes.c.o): relocation R_X86_64_32S against `.bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(md.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(oid.c.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(ripemd160.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(sha256.c.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(md5.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
onvif/libonvif_s.a(stdsoap2.c.o): In function `soap_ssl_init':
stdsoap2.c:(.text+0x68b5): undefined reference to `SSL_library_init'
stdsoap2.c:(.text+0x68ba): undefined reference to `OPENSSL_add_all_algorithms_noconf'
stdsoap2.c:(.text+0x68bf): undefined reference to `SSL_load_error_strings'
onvif/libonvif_s.a(stdsoap2.c.o): In function `ssl_auth_init':
stdsoap2.c:(.text+0x6b54): undefined reference to `SSLv23_method'
onvif/libonvif_s.a(stdsoap2.c.o): In function `tcp_connect':
stdsoap2.c:(.text+0x9612): undefined reference to `SSL_state'
stdsoap2.c:(.text+0x97e3): undefined reference to `sk_pop_free'
stdsoap2.c:(.text+0x9811): undefined reference to `sk_value'
stdsoap2.c:(.text+0x988f): undefined reference to `sk_num'
stdsoap2.c:(.text+0x98b1): undefined reference to `sk_pop_free'
onvif/libonvif_s.a(mecevp.c.o): In function `soap_mec_init':
mecevp.c:(.text+0x76): undefined reference to `EVP_CIPHER_CTX_init'
onvif/libonvif_s.a(mecevp.c.o): In function `soap_mec_cleanup':
mecevp.c:(.text+0x433): undefined reference to `EVP_CIPHER_CTX_cleanup'
onvif/libonvif_s.a(smdevp.c.o): In function `soap_smd_init':
smdevp.c:(.text+0x33d): undefined reference to `HMAC_CTX_init'
smdevp.c:(.text+0x395): undefined reference to `EVP_MD_CTX_init'
onvif/libonvif_s.a(smdevp.c.o): In function `soap_smd_final':
smdevp.c:(.text+0x76a): undefined reference to `HMAC_CTX_cleanup'
smdevp.c:(.text+0x77c): undefined reference to `EVP_MD_CTX_cleanup'
onvif/libonvif_s.a(smdevp.c.o): In function `soap_smd_check':
smdevp.c:(.text+0x844): undefined reference to `HMAC_CTX_cleanup'
smdevp.c:(.text+0x856): undefined reference to `EVP_MD_CTX_cleanup'
/usr/bin/ld: final link failed: Symbol needs debug section which does not exist
collect2: error: ld returned 1 exit status
sample/CMakeFiles/sample_video_s.dir/build.make:373: recipe for target '../bin/sample_video_s' failed
make[2]: *** [../bin/sample_video_s] Error 1
CMakeFiles/Makefile2:225: recipe for target 'sample/CMakeFiles/sample_video_s.dir/all' failed
make[1]: *** [sample/CMakeFiles/sample_video_s.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

 

2. Analysis:
        It is inferred that the trouble should be positioned in linking procedure. The specialize static library "libmbedcrypto.a" was ever compiled without option "fPIC", but the present system compiler turns on this function definitely. So we can see from log that it recommends recompile with -fPIC.

 

 3. Resolution
        If we use CMake tool to help compile, we can just add an "-no-pie" to linker flags:
SET(CMAKE_EXE_LINKER_FLAGS " -no-pie")
Job done.

 

4.  Summarize knowledge
        PIE full name is "Position Independent Executable", which is used to create an media between common executable and common shared library. This kind of code can relocate space just as common shared library, and it must be linked to Scrt1.o.
Details can be referred to https://blog.csdn.net/ivan240/article/details/5363395.
————————————————
版权声明:本文为CSDN博主「如月灵」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/hanyulongseucas/article/details/87715186

Friday 14 May 2021

CUDA_CUDA_LIBRARY, CUDA_nvcuvid_LIBRARY, cudacodec, CMake Generate step failed?

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CUDA_CUDA_LIBRARY (ADVANCED)
    linked by target "opencv_cudacodec" in directory /home/ccng/workspace/opencv_contrib-4.4.0/modules/cudacodec
CUDA_nvcuvid_LIBRARY (ADVANCED)
    linked by target "opencv_cudacodec" in directory /home/ccng/workspace/opencv_contrib-4.4.0/modules/cudacodec

-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.


============================

 

This bug is due to the nvcuvid and nvidia-encode not set in a correct path.

 

step1: download the correct driver and library into a specific path:-

For nvidia driver 450, cuda10.2 and gpu2080ti:-

download video_codec_sdk from NVIDIA (***very important***)
cd /home/ninja/installer/Video_Codec_SDK_10.0.26/Interface
sudo cp ./* /usr/local/cuda-10.2/include
cd /home/ccng/installer/Video_Codec_SDK_10.0.26/Interface
sudo cp ./* /usr/local/cuda-10.2/targets/x86_64-linux/lib/stubs
(make sure libnvidia-encode.so and libnvcuvid.so are inside the folder)
sudo ln -s /usr/local/cuda-10.2/targets/x86_64-linux/lib/stubs/libnvcuvid.so /usr/local/cuda-10.2/targets/x86_64-linux/lib/stubs/libnvcuvid.so.1
sudo ln -s /usr/local/cuda-10.2/targets/x86_64-linux/lib/stubs/libnvidia-encode.so /usr/local/cuda-10.2/targets/x86_64-linux/lib/stubs/libnvidia-encode.so.1


step2: adding the following configuration in opencv cmake:-

        -DCMAKE_LIBRARY_PATH=/usr/local/cuda-10.2/targets/x86_64-linux/lib/stubs \
        -DCUDA_nvcuvid_LIBRARY=/usr/local/cuda-10.2/targets/x86_64-linux/lib/stubs/libnvcuvid.so.1 \
        -DCUDA_nvcuvenc_LIBRARY=/usr/local/cuda-10.2/targets/x86_64-linux/lib/stubs/libnvidia-encode.so \
        -DCUDA_nvcuvid_LIBRARIES=/usr/local/cuda-10.2/targets/x86_64-linux/lib/stubs/libnvcuvid.so \
        -DCUDA_nvcuvenc_LIBRARIES=/usr/local/cuda-10.2/targets/x86_64-linux/lib/stubs/libnvidia-encode.so \

Tuesday 11 May 2021

How to list videos and concate them into a single video?

for f in ./ch08*.sdv; do echo "file '$PWD/$f'" >> file.txt ; done


concate and convert using nvidia encode and decode:-

ffmpeg -y -vsync 0 -hwaccel cuvid -c:v h264_cuvid -f concat -safe 0 -i ch08.txt -c:v h264_nvenc ch08.mp4

How to use terminal to list the files and save into a text file?

for f in ./*.mp4; do echo "file '$PWD/$f'" >> file.txt ; done