概述
AMD的显卡驱动虽然是开源了,但是对于OPENCL的编译那一套环境一直是自己在搞,貌似没有交给社区,所以要在UOS上配置基于AMD显卡的OPENCL环境,就不能简单的通过apt-get这样的命令直接安装搞定了,需要安装amdgpu-pro这一套,这个里面就包含了他显卡的全套东西(内核驱动,Xorg驱动,OpenGL,OpenCL库)等等.由于官网的amdgpu-pro只针对RHEL/ubuntu的长期维护版本提供支持,其余的Linux发行版就照顾不到了,不过基于debian的发行版还是可以白嫖的,不过就是得手工安装而不能一条命令自动安装了.
具体的可以参考这里:
https://linuxconfig.org/install-opencl-for-the-amdgpu-open-source-drivers-on-debian-and-ubuntu
安装过程
- 下载安装包
安装包我都是bing.com上面搜别人安装的文章给的连接 ,具体的自己去AMD网站用AMDGPU-Pro搜吧.
具体的版本我先后试了好几个版本,总是在内核驱动那里出问题,dkms编译不过去,要么就是我内核太高,5.4了,最后测试出来 https://drivers.amd.com/drivers/linux/amdgpu-pro-20.40-1147287-ubuntu-18.04.tar.xz 这个给18.04.5做的20.40版本可以正常安装. - 做本地源
下载下来的包里面Packages文件都给你生成好了的,直接添加个源就好
actionchen@actionchen-PC:~/M-门罗币/neo$ cat /etc/apt/sources.list.d/demo.list
deb [trusted=yes] file:/home/actionchen/M-门罗币/OPENCL-AMD/amdgpu-pro-20.40-1147287-ubuntu-18.04
我的就是这样,不要介意,我就是为了运行这个门罗币挖矿程序的OPENCL部分才想起来要在UOS上配置OPENCL环境的.
3. 直接开始安装需要的几个包
amdgpu-dkms
opencl-amdgpu-pro-icd
clinfo-amdgpu-pro
opencl-orca-amdgpu-pro-icd
安装这几个,他会自己去把其他依赖的包也给装上
安装完后/opt/amdgpu-pro/bin/clinfo 执行一下就可以看到有platform ,device信息了,Platform 包括支持的Opencl版本信息,device包括显卡的硬件配置信息了.
如果这时候运行程序还是报运行环境不对的话,再安装
ocl-icd-opencl-dev
这个包就对了,其实这个就是个opencl的loader(opencl-icd),前面也装了amd的loader,这里是系统的loader,loader会去/etc/下面扫描各种厂商信息的,如果不装这个,运行程序指定对应的loader也是可以的(反正就是把libopencl.so搞对就行)
- 最后就是直接运行你的opencl程序了,不过我这里有点杯具,这个门罗币的挖矿代码要求显存大于2GB,而我这个联想万年辣鸡笔记本配置的还是跟Intel核显没啥区别的 AMD 625 Mobile,刚好就是2G显存,真不知道这些笔记本厂商是为了啥,为了帮显卡厂商出掉些次品芯片吗 ?
` * ABOUT XMRig/6.8.2 gcc/8.3.0
LIBS libuv/1.40.0 OpenSSL/1.1.1i hwloc/2.4.0
HUGE PAGES supported
1GB PAGES supported
CPU Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz (1) 64-bit AES
L2:1.0 MB L3:6.0 MB 4C/8T NUMA:1
MEMORY 6.0/7.3 GB (83%)
DIMM_A0: 8 GB DDR4 @ 2667 MHz HMAA1GS6CMR6N-VK
ChannelB-DIMM0:
MOTHERBOARD LENOVO - LNVNB161216
DONATE 0%
ASSEMBLY auto:intel
POOL #1 xmr.f2pool.com:13531 algo auto
COMMANDS hashrate, pause, resume, results, connection
ADL press e for health report
OPENCL #0 AMD Accelerated Parallel Processing/OpenCL 2.1 AMD-APP (3180.7)
OPENCL GPU #0 01:00.0 AMD Radeon Graphics (Iceland) 1024 MHz cu:6 mem:1515/2037 MB
CUDA disabled
[2021-02-18 12:33:41.373] net use pool xmr.f2pool.com:13531 127.0.0.1
[2021-02-18 12:33:41.373] net new job from xmr.f2pool.com:13531 diff 32768 algo rx/0 height 2299276
[2021-02-18 12:33:41.373] cpu use argon2 implementation AVX2
[2021-02-18 12:33:41.377] msr register values for "intel" preset have been set successfully (3 ms)
[2021-02-18 12:33:41.377] randomx init dataset algo rx/0 (3 threads) seed b353f283ee2e4460...
[2021-02-18 12:33:41.530] randomx failed to allocate RandomX dataset using 1GB pages
[2021-02-18 12:33:41.550] randomx allocated 2336 MB (2080+256) huge pages 100% 1168/1168 +JIT (174 ms)
[2021-02-18 12:33:51.659] randomx dataset ready (10109 ms)
[2021-02-18 12:33:51.659] cpu use profile rx (3 threads) scratchpad 2048 KB
[2021-02-18 12:33:51.660] opencl use profile rx (2 threads) scratchpad 2048 KB
| # | GPU | BUS ID | INTENSITY | WSIZE | MEMORY | NAME
| 0 | 0 | 01:00.0 | 64 | 8 | 128 | AMD Radeon Graphics (Iceland)
| 1 | 0 | 01:00.0 | 64 | 8 | 128 | AMD Radeon Graphics (Iceland)
[2021-02-18 12:33:51.662] cpu READY threads 3/3 (3) huge pages 100% 3/3 memory 6144 KB (3 ms)
[2021-02-18 12:33:52.454] opencl error CL_MEM_OBJECT_ALLOCATION_FAILURE when calling clCreateBuffer with
[2021-02-18 12:33:52.462] opencl error CL_MEM_OBJECT_ALLOCATION_FAILURE when calling clCreateBuffer with
[2021-02-18 12:33:52.480] opencl thread #0 failed with error RandomX dataset is not available
[2021-02-18 12:33:52.482] opencl thread #1 failed with error RandomX dataset is not available
[2021-02-18 12:33:52.484] opencl thread #0 self-test failed
[2021-02-18 12:33:52.486] opencl thread #1 self-test failed
[2021-02-18 12:33:52.486] opencl disabled (failed to start threads)
- 关于一台机器多个opencl设备以及opencl的平台和设备之间关系的,可以参考下面这篇文章
https://streamhpc.com/blog/2015-08-14/opencl-basics-multiple-opencl-devices-with-the-icd/
综合起来就是:一个platform下面可以对一个多个设备,另外一个设备可以有多个Opnecl实现(例如苹果就比较牛叉,自己给设备实现一套而不是厂商实现) ,还有就是平台和设备的Opencl版本可以不一样.
下一步测试一下在UOS V20 (5.4kerne,非标准4.19内核)桌面上搞一把intel核显的Opencl环境,希望能搞起.
Intel核心新显卡的opencl配置
- 官网
https://github.com/intel/compute-runtime
安装方法参考
https://github.com/intel/compute-runtime/releases/tag/21.06.18993
- 直接下载编译好的包安装就完全完事
cd neo
wget https://github.com/intel/compute-runtime/releases/download/21.06.18993/intel-gmmlib_20.3.2_amd64.deb
wget https://github.com/intel/intel-graphics-compiler/releases/download/igc-1.0.6087/intel-igc-core_1.0.6087_amd64.deb
wget https://github.com/intel/intel-graphics-compiler/releases/download/igc-1.0.6087/intel-igc-opencl_1.0.6087_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/21.06.18993/intel-opencl_21.06.18993_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/21.06.18993/intel-ocloc_21.06.18993_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/21.06.18993/intel-level-zero-gpu_1.0.18993_amd64.deb
- 由于门罗币的挖矿算法就没说支持Intel核心显卡,所以用intel 核心显卡来挖矿就成为了不可能
https://github.com/tevador/RandomX
SChernykh is developing GPU mining code for RandomX. Benchmarks are included in the following repositories:
- CUDA miner - NVIDIA GPUs. OpenCL miner - only for AMD Vega and AMD
- Polaris GPUs (uses GCN machine code).
但是我还是尝试跑了一下,由于装上了intel 的Opencl环境,就有2个platform ,2个device ,运行挖矿程序的时候需要指定一下,门罗币这个挖矿程序还挺好,提供了命令行参数
actionchen@actionchen-PC:/tmp$ clinfo -l
Platform #0: Intel(R) OpenCL HD Graphics
`-- Device #0: Intel(R) Graphics [0x9b41]
Platform #1: AMD Accelerated Parallel Processing
`-- Device #0: Iceland
sudo ./xmrig -x 127.0.0.1:1089 -o xmr.f2pool.com:13531 -u 487oBceUnMnDAM9Fmk8UHu49g7SyKmdaXW3UUYVib7rmj8RbesS812BUQd9p2aJ2p8LYRs3raUsaxBR4NX1rxqRYV9CeSdb.001 -p x -k --randomx-init=3 --opencl --opencl-platform=0 --no-cpu
估计是公司的防火墙做了加固,直接连鱼池是连不上的,直接reset了,所以挂个代理出去.
执行这个后运行到opencl的代码时候会报错退出.我也不知道是我安装的intel opencl二进制包的兼容性问题还是确实是因为挖矿程序生成的Opencl代码绑定了AMD显卡的特定接口.反正核显挖menluo币矿也失败了.
* ABOUT XMRig/6.8.2 gcc/8.3.0
* LIBS libuv/1.40.0 OpenSSL/1.1.1i hwloc/2.4.0
* HUGE PAGES supported
* 1GB PAGES disabled
* CPU Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz (1) 64-bit AES
L2:1.0 MB L3:6.0 MB 4C/8T NUMA:1
* MEMORY 7.2/7.3 GB (98%)
DIMM_A0: 8 GB DDR4 @ 2667 MHz HMAA1GS6CMR6N-VK
ChannelB-DIMM0: <empty>
* MOTHERBOARD LENOVO - LNVNB161216
* DONATE 0%
* ASSEMBLY auto:intel
* POOL #1 xmr.f2pool.com:13531 algo auto
* COMMANDS hashrate, pause, resume, results, connection
* ADL press e for health report
* OPENCL #0 Intel(R) OpenCL HD Graphics/OpenCL 3.0
* OPENCL GPU #0 n/a Intel(R) Graphics [0x9b41] 1100 MHz cu:24 mem:2985/5971 MB
* CUDA disabled
[2021-02-18 16:43:55.498] net use pool xmr.f2pool.com:13531 127.0.0.1
[2021-02-18 16:43:55.498] net new job from xmr.f2pool.com:13531 diff 32768 algo rx/0 height 2299400
[2021-02-18 16:43:55.498] cpu use argon2 implementation AVX2
[2021-02-18 16:43:55.502] msr register values for "intel" preset have been set successfully (5 ms)
[2021-02-18 16:43:55.502] randomx init dataset algo rx/0 (3 threads) seed b353f283ee2e4460...
[2021-02-18 16:43:55.687] randomx allocated 2336 MB (2080+256) huge pages 100% 1168/1168 +JIT (184 ms)
[2021-02-18 16:44:06.028] randomx dataset ready (10341 ms)
[2021-02-18 16:44:06.028] opencl use profile rx (1 thread) scratchpad 2048 KB
| # | GPU | BUS ID | INTENSITY | WSIZE | MEMORY | NAME
| 0 | 0 | n/a | 384 | 8 | 768 | Intel(R) Graphics [0x9b41]
[2021-02-18 16:44:11.827] opencl READY threads 1/1 (4442 ms)
[2021-02-18 16:44:25.621] net new job from xmr.f2pool.com:13531 diff 32768 algo rx/0 height 2299401
Abort was called at 126 line in file:
../neo/opencl/source/os_interface/linux/drm_command_stream.inl
已放弃
小结
笔记本辣鸡显卡和CPU核心显卡都没法挖ML(menluo)币,优化之路到此为止了.
另外,记录下怎么开1GB的大页面,按照挖矿软件官网运行那个脚本没用,开启方法是在系统启动的grub里给内核传参数 hugepagesz=1GB hugepages=3 ,这个1GB页面文件是否能开启成功和CPU还有关系
检查方法如下,如果硬件不支持估计也是开不了的:
cat /proc/cpuinfo | egrep -o pdpe1gb | head -n 1
另外,详细信息可以参考权威文档:
https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt