当前位置: 首页 > news >正文

使用 apt 源安装 ROCm 6.0.x 在Ubuntu 22.04.01

从源码编译 rocSolver

本人只操作过单个rocm版本的情景,20240218 ubuntu 22.04.01


1,卸载原先的rocm


https://docs.amd.com/en/docs-5.1.3/deploy/linux/os-native/uninstall.html
 

# Uninstall single-version ROCm packages
sudo apt autoremove rocm-core# Uninstall Kernel-mode Driver
sudo apt autoremove amdgpu-dkms# remove apt source
sudo rm /etc/apt/sources.list.d/<rocm_repository-name>.list
sudo rm /etc/apt/sources.list.d/<amdgpu_repository-name>.list
sudo rm /etc/apt/sources.list.d/rocm.list
sudo rm /etc/apt/sources.list.d/amdgpu.listsudo rm -rf /var/cache/apt/*
sudo apt-get clean allsudo reboot

2,安装最新的rocm


https://rocm.docs.amd.com/projects/install-on-linux/en/latest/tutorial/quick-start.html#rocm-install-quick

sudo apt install "linux-headers-$(uname -r)" "linux-modules-extra-$(uname -r)"
# See prerequisites. Adding current user to Video and Render groups
sudo usermod -a -G render,video $LOGNAME
wget https://repo.radeon.com/amdgpu-install/6.0.2/ubuntu/jammy/amdgpu-install_6.0.60002-1_all.deb
sudo apt install ./amdgpu-install_6.0.60002-1_all.deb
sudo apt update
sudo apt install amdgpu-dkms
sudo apt install rocm
sudo reboot
sudo amdgpu-install --usecase=graphics,rocm
sudo reboot

3,安装依赖

Clang: ...  'cmath' file not found
找不到 #include_next <cmath>

sudo apt install libstdc++-12-dev

4,示例

4.1 amd官方示例

$ git clone --recursive  https://github.com/amd/rocm-examples.git
$ cd HIP-Basic/device_query
$ make
$ ./hip_device_query

4.2 rocsolver_dgeqrf

ex_rocsolver_dgeqrf.cpp

/
// example.cpp source code //
/#include <algorithm> // for std::min
#include <stddef.h>  // for size_t
#include <stdio.h>
#include <vector>
#include <hip/hip_runtime_api.h> // for hip functions
#include <rocsolver/rocsolver.h> // for all the rocsolver C interfaces and type declarationsvoid init_vector(double* A, int n)
{for(int i=0; i<n; i++)A[i] = (rand()%2000)/1000.0;
}void print_matrix(double* A, int M, int N, int lda)
{for(int i=0; i<M; i++){for(int j=0; j<N; j++){printf("%7.4f, ", A[i + j*lda]);}printf("\n");}}int main() {rocblas_int M = 7;rocblas_int N = 7;rocblas_int lda = M;// here is where you would initialize M, N and lda with desired valuesrocblas_handle handle;rocblas_create_handle(&handle);size_t size_A = size_t(lda) * N;          // the size of the array for the matrixsize_t size_piv = size_t(std::min(M, N)); // the size of array for the Householder scalarsstd::vector<double> hA(size_A);      // creates array for matrix in CPUstd::vector<double> hIpiv(size_piv); // creates array for householder scalars in CPUinit_vector(hA.data(), size_A);memset(hIpiv.data(), 0, size_piv*sizeof(double));print_matrix(hA.data(), M, N, lda);double *dA, *dIpiv;hipMalloc(&dA, sizeof(double)*size_A);      // allocates memory for matrix in GPUhipMalloc(&dIpiv, sizeof(double)*size_piv); // allocates memory for scalars in GPU// here is where you would initialize matrix A (array hA) with input data// note: matrices must be stored in column major format,//       i.e. entry (i,j) should be accessed by hA[i + j*lda]// copy data to GPUhipMemcpy(dA, hA.data(), sizeof(double)*size_A, hipMemcpyHostToDevice);// compute the QR factorization on the GPUrocsolver_dgeqrf(handle, M, N, dA, lda, dIpiv);// copy the results back to CPUhipMemcpy(hA.data(), dA, sizeof(double)*size_A, hipMemcpyDeviceToHost);hipMemcpy(hIpiv.data(), dIpiv, sizeof(double)*size_piv, hipMemcpyDeviceToHost);printf("\nR =\n");print_matrix(hA.data(), M, N, lda);printf("\ntau=\n");print_matrix(hIpiv.data(), 1, N, 1);// the results are now in hA and hIpiv, so you can use them herehipFree(dA);                        // de-allocate GPU memoryhipFree(dIpiv);rocblas_destroy_handle(handle);     // destroy handle
}

Makefile:

EXE := ex_rocsolver_dgeqrfall: $(EXE)INC :=  -I /opt/rocm/include -D__HIP_PLATFORM_AMD__
LD_FLAGS := -L /opt/rocm/lib -lamdhip64 -lrocblas -lrocsolverex_rocsolver_dgeqrf.o: ex_rocsolver_dgeqrf.cppg++ $< $(INC) -c -o $@ex_rocsolver_dgeqrf: ex_rocsolver_dgeqrf.og++ $< $(LD_FLAGS) -o $@.PHONY: clean
clean:${RM} *.o $(EXE)

运行效果:

使用matlab对结果做验证:

http://www.lryc.cn/news/302042.html

相关文章:

  • python函数的定义和调用
  • 【JVM篇】什么是类加载器,有哪些常见的类加载器
  • STM32—DHT11温湿度传感器
  • 相机图像质量研究(31)常见问题总结:图像处理对成像的影响--图像差
  • MySQL之select查询
  • Android MMKV 接入+ 替换原生 SP + 原生 SP 数据迁移
  • C#上位机与三菱PLC的通信07--使用第3方通讯库读写数据
  • LiveGBS流媒体平台GB/T28181常见问题-基础配置流媒体服务配置中本地|内网IP外网IP(可选)外网IP收流如何配置
  • 微服务- 熔断、降级和限流
  • 电路设计(20)——数字电子钟的multism仿真
  • 【论文阅读笔记】Contrastive Learning with Stronger Augmentations
  • 前端win10如何设置固定ip(简单明了)
  • 数据结构1.0(基础)
  • anomalib1.0学习纪实-续2:三个文件夹
  • 【递归】【后续遍历】【迭代】【队列】Leetcode 101 对称二叉树
  • Nginx https反向代理
  • zip解压缩
  • 电动五金工具行业调研:政策促进市场发展
  • 【矩阵】托普利茨矩阵
  • DS:八大排序之归并排序、计数排序
  • 由斐波那契数列探究递推与递归
  • 红队打靶练习:IMF: 1
  • 密码管理局以及什么是密评?为什么要做密评(商用密码应用安全性评估)?
  • 六、Datax通过json字符串运行
  • 关于数据库
  • 洛谷C++简单题小练习day14—闰年推算小程序
  • 房企关注的典型数字化场景之一:数字营销
  • BMS再进阶(新能源汽车电池管理系统)
  • K8s Deployment挂载ConfigMap权限设置
  • 百度智能云分布式数据库 GaiaDB-X 与龙芯平台完成兼容认证