使用Qemu运行Ubuntu文件系统 —— 搭建SVE学习环境(2)


开发环境

PC:ubuntu18.04

Qemu:4.1

Kernel:Linux-5.2

 

概述

  由于要学习ARM的SVE技术,但是目前还没有支持SVE指令的板子,所以只能用Qemu来模拟,但是发现Qemu在用户模式下无法设置SVE的位宽,在浏览ARM官网资料时发现,ARM提供了Arm Instruction Emulator下载链接)可以用来模拟SVE指令,并且可以设置SVE位宽,遗憾的是该模拟器只能运行在AArch64机器上,并且提供了基于ubuntu16.04的安装包。所以,需要先在qemu上运行一个ubuntu系统,然后再在其中安装Arm Instruction Emulator

 

正文

1、参考博客:使用Qemu运行Ubuntu文件系统(1)

2、参考博客:用Qemu搭建aarch64学习环境

3、参考博客:Qemu-4.1 桥接网络设置

4、参考博客:安装docker后,导致qemu的桥接网络出现问题

5、下面是与上面不同的地方

  • 使用的是qemu-aarch64-static

6、在运行时,使用如下命令:(下面用到的制作好的ubuntu16.04镜像可以到这里下载,用户名"pengdl",密码是一个空格)

sudo qemu-system-aarch64 \ -M virt \ -cpu cortex-a57 \ -smp 4 \ -m 2048M \ -kernel ./linux-5.2/arch/arm64/boot/Image \ -nographic \ -append "noinitrd root=/dev/vda rootfstype=ext4 rw" \ -nic tap \ -fsdev local,security_model=passthrough,id=fsdev0,path=/nfsroot \ -device virtio-9p-pci,id=fs1,fsdev=fsdev0,mount_tag=hostshare \ -drive if=none,file=./ubuntu_rootfs/ubuntu.ext4,id=hd0 \ -device virtio-blk-device,drive=hd0

7、系统运行起来后,可以用使用串口或者telnet以普通用户登录虚拟机,然后再用mount -t nfs 或者 mount -t 9p的方式将Host上的目录挂载到虚拟机中,来安装ARMIE。

8、可以参考前一篇交叉编译支持SVE ACLE的gcc,对测试程序稍作修改,来看看修改SVE位宽的运行效果:

#include <stdlib.h> #include <stdio.h> #include <arm_sve.h>

// Scalar version.
void add_arrays(double * restrict dst, double *src, double c, const int N) { for (int i = 0; i < N; i++) dst[i] = src[i] + c; } // Vector version
void vla_add_arrays(double * restrict dst, double *src, double c, const int N) { int64_t i = 0; svbool_t pg = svwhilelt_b64(i, (int64_t)N); while (svptest_any(svptrue_b64(), pg)) { svfloat64_t vsrc = svld1(pg, src + i); svfloat64_t vdst = svadd_x(pg, vsrc, c); svst1(pg, dst + i, vdst); i += svcntd(); pg = svwhilelt_b64(i, (int64_t)N); printf("# %ld\n", i); } } // Vector version
void vla_add_arrays_2(double *dst, double *src, double c, const int N) { for (int i = 0; i < N; i += svcntd()) { svbool_t Pg = svwhilelt_b64(i, N); svfloat64_t vsrc = svld1(Pg, &src[i]); svfloat64_t vdst = svadd_x(Pg, vsrc, c); svst1(Pg, &dst[i], vdst); printf("* %d\n", i); } } int main(void) { double src[100]; double c; double dst_serial[100], dst_vla[100], dst_vla2[100]; for (int i = 0; i < 100; ++i) { src[i] = (double) i / ((double) i + 1); } c = src[rand() % 100]; add_arrays(dst_serial, src, c, 100); vla_add_arrays(dst_vla, src, c, 100); vla_add_arrays_2(dst_vla2, src, c, 100); for (int i = 0; i < 100; ++i) { printf("%f %f %f, %f, %f\n", dst_serial[i], dst_vla[i], dst_vla2[i], src[i], c); } return 0; }

 

运行时,可以设置不同的SVE位宽:

2048:

 

 

1024:

 

 

128:

 

 

完。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM