Monday 28 June 2021

How to setup Nvidia ngc in ubuntu18?

wget -O ngccli_cat_linux.zip https://ngc.nvidia.com/downloads/ngccli_cat_linux.zip && unzip -o ngccli_cat_linux.zip && chmod u+x ngc


echo "export PATH=\"\$PATH:$(pwd)\"" >> ~/.bash_profile && source ~/.bash_profile

 

ngc config set



Sunday 27 June 2021

How to run docker in docker ubuntu?

docker run --gpus all -it -v /var/run/docker.sock:/var/run/docker.sock -p 8888:8888 nvidia/cuda:11.0-base nvidia-smi

Saturday 5 June 2021

How to do vector multiplication using a batch size of 4 in C++?

 https://blog.csdn.net/fuwenyan/article/details/77742766

 

本博记录为卤煮理解,如有疏漏,请指正。转载请注明出处。

卤煮:非文艺小燕儿

本博地址:利用SSE计算向量点乘simd_dot


所谓SSE(Streaming SIMD Extensions),也就是单指令多数据流的扩展。所谓单指令多数据流呢,简单理解就是多个数据流同时处理一条指令。

举个栗子:

一个水箱中的水,底部开1个洞放水,就是单指令单数据流。底部同时开多个相同大小的洞放水,就是单指令多数据流。

多个洞放水当然会比1个洞放得快啦,也就是同样的指令,多数据流速度就快呀。



对于SSE,其实就是处理器中专门开辟了多个128位的寄存器。对于单精度浮点数,占用32bit,那么1个128bit的SSE寄存器,就可以存放4个单精度浮点数。对于单精度浮点数的运算指令,其实就相当于开了4个洞。比如,两个128位的SSE寄存器中存放的数据进行乘法运算,那么一次性就能得到4组运算结果。



大概就是这么个意思。接下来就对采用SSE优化的向量点乘进行详细注释说明。

输入x和y都是长度为len的向量。我们要求x.*y,并将结果返回。
————————————————
版权声明:本文为CSDN博主「非文艺小燕儿_Vivien」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/fuwenyan/article/details/77742766


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

float simd_dot(const float* x, const float* y, const long& len) {
    float inner_prod = 0.0f;
    __m128 X, Y; //声明两个存放在SSE的128位专用寄存器的变量
    __m128 acc = _mm_setzero_ps(); // 声明一个存放在SSE的128位专用寄存器的变量,用来存放X+Y的结果,初始值为0
    float temp[4];//存放中间变量的参数
 
    long i;
    for (i = 0; i + 4 < len; i += 4) {//128位专用寄存器,一次性可以处理4组32位变量的运算
        X = _mm_loadu_ps(x + i); // 将x加载到X(由于128位可以存放四个32位数据,所以默认一次加载连续的4个参数)
        Y = _mm_loadu_ps(y + i);//同上
        acc = _mm_add_ps(acc, _mm_mul_ps(X, Y));//x*y,每轮的x1*y1求和,x2*y2求和,x3*y3求和,x4*y4求和,最终产生的四个和,放在acc的128位寄存器中。
    }
    _mm_storeu_ps(&temp[0], acc); // 将acc中的4个32位的数据加载进内存
    inner_prod = temp[0] + temp[1] + temp[2] + temp[3];//点乘求和
 
    // 刚才只是处理了前4的倍数个元素的点乘,如果len不是4的倍数,那么还有个小尾巴要处理一下
    for (; i < len; ++i) {
        inner_prod += x[i] * y[i];//继续累加小尾巴的乘积
    }
    return inner_prod;//大功告成
}
  

Thursday 3 June 2021

How To Delete A APT Repository And GPG Key In Ubuntu?

Reference: https://ostechnix.com/how-to-delete-a-repository-and-gpg-key-in-ubuntu/

Delete a repository in Ubuntu

Whenever you add a repository using "add-apt-repository" command, it will be stored in /etc/apt/sources.list file.

To delete a software repository from Ubuntu and its derivatives, just open the /etc/apt/sources.list file and look for the repository entry and delete it.

$ sudo nano /etc/apt/sources.list

As you can see in the below screenshot, I have added Oracle Virtualbox repository in my Ubuntu system.

virtualbox repository

The contents of /etc/apt/sources.list file

To delete this repository, simply remove the entry. Save and close the file.

If you have added PPA repositories, look into /etc/apt/sources.list.d/ directory and delete the respective entry.

Alternatively, you can delete the repository using "add-apt-repository" command. For example, I am deleting the Systemback repository like below.

$ sudo add-apt-repository -r ppa:nemh/systemback

Finally, update the software sources list using command:

$ sudo apt update
 
===========================================================
 

Delete repository keys in Ubuntu

We use "apt-key" command to add the repository keys. First, let us list the added keys using command:

$ sudo apt-key list

This command will list all added repository keys.

/etc/apt/trusted.gpg -------------------- pub rsa1024 2010-10-31 [SC] 3820 03C2 C8B7 B4AB 813E 915B 14E4 9429 73C6 2A1B uid [ unknown] Launchpad PPA for Kendek pub rsa4096 2016-04-22 [SC] B9F8 D658 297A F3EF C18D 5CDF A2F6 83C5 2980 AECF uid [ unknown] Oracle Corporation (VirtualBox archive signing key) <info@virtualbox.org> sub rsa4096 2016-04-22 [E] /etc/apt/trusted.gpg.d/ubuntu-keyring-2012-archive.gpg ------------------------------------------------------ pub rsa4096 2012-05-11 [SC] 790B C727 7767 219C 42C8 6F93 3B4F E6AC C0B2 1F32 uid [ unknown] Ubuntu Archive Automatic Signing Key (2012) <ftpmaster@ubuntu.com> /etc/apt/trusted.gpg.d/ubuntu-keyring-2012-cdimage.gpg ------------------------------------------------------ pub rsa4096 2012-05-11 [SC] 8439 38DF 228D 22F7 B374 2BC0 D94A A3F0 EFE2 1092 uid [ unknown] Ubuntu CD Image Automatic Signing Key (2012) <cdimage@ubuntu.com> /etc/apt/trusted.gpg.d/ubuntu-keyring-2018-archive.gpg ------------------------------------------------------ pub rsa4096 2018-09-17 [SC] F6EC B376 2474 EDA9 D21B 7022 8719 20D1 991B C93C uid [ unknown] Ubuntu Archive Automatic Signing Key (2018) <ftpmaster@ubuntu.com>

As you can see in the above output, the long (40 characters) hex value is the repository key. If you want APT package manager to stop trusting the key, simply delete it using command:

$ sudo apt-key del "3820 03C2 C8B7 B4AB 813E 915B 14E4 9429 73C6 2A1B"

Or, specify the last 8 characters only:

$ sudo apt-key del 73C62A1B

Done! The repository key has been deleted. Run the following command to update the repository lists:

$ sudo apt update
 

Tuesday 1 June 2021

How to find, copy and paste files from all subfolders into another folder

  find . -name "*_body.jpg" -exec cp "{}" /home/ninja/temp  \;

Install the pip3 using apt

sudo apt install python3-pip

sudo apt install python3-venv

Using Virtual Environments

To get started, if you’re not using Python 3, you’ll want to install the virtualenv tool with pip:

$ pip3 install pip --upgrade 
$ pip3 install virtualenv

If you are using Python 3, then you should already have the venv module from the standard library installed.


Create a new virtual environment inside the directory:

# Python 2:
$ virtualenv env

# Python 3
$ python3 -m venv env 

In order to use this environment’s packages/resources in isolation, you need to “activate” it. To do this, just run the following:

$ source env/bin/activate
(env) $