矩池云上安装OpenCL教程

本教程租用的是K80,Pytorch1.11 镜像。

images-pytorch1.11

添加nvidia-cuda的阿里源

curl -fsSL https://mirrors.aliyun.com/nvidia-cuda/ubuntu1804/x86_64/3bf863cc.pub | apt-key add -
echo "deb https://mirrors.aliyun.com/nvidia-cuda/ubuntu1804/x86_64/ /" > /etc/apt/sources.list.d/cuda.list
apt update

nvidia-cuda

安装 opencl

apt install ocl-icd-opencl-dev -y

install-opencl

创建链接

mkdir -p /etc/OpenCL/vendors/
cd /etc/OpenCL/vendors
vim nvidia.icd

在 nvidia.icd 里填入以下链接

/usr/lib/x86_64-linux-gnu/libnvidia-opencl.so.1

create-nvidia.icd

验证是否正确链接

cat nvidia.icd
ll /usr/lib/x86_64-linux-gnu/libnvidia-opencl.so.1

check-link

测试opencl

clGetPlatformIDs.c 内容

#include <stdio.h>
#include <CL/opencl.h>

int main(int argc, char **argv)
{
    int status;
    cl_uint n_platform;

    status = clGetPlatformIDs(0, NULL, &n_platform);

     if(status != CL_SUCCESS)
    {
    fprintf(stderr, "no platforms %d\n", status);
    return -1;
    } else
    {
    fprintf(stderr, "number of CL platforms %d\n", n_platform);
    return 0;
    }
}

进入项目目录,我这里是/mnt/testme/opencl_t,新建一个clGetPlatformIDs.c文件,然后写入上面内容。

cd /mnt/testme/opencl_t
vim clGetPlatformIDs.c
gcc clGetPlatformIDs.c -lOpenCL -o main
chmod +x main
./main

check-opencl

出现number of CL platforms 1,安装及测试就完成了

参考文章

客服