sudo pacman -S hip-runtime-amd
pushd /opt/rocm/hip/bin
wget https://raw.githubusercontent.com/ROCm-Developer-Tools/HIPIFY/amd-staging/bin/hipify-perl; sudo chmod +x hipify-perl
popd
echo "export HIP_PATH="/opt/rocm/hip\nexport PATH="$PATH:/opt/rocm/bin:$HIP_PATH/bin" > $HOME/.zshrc
source $HOME/.zshrc
将CUDA代码转换成HIP代码
hipify-perl test.cu > test.cpp
编译HIP代码
hipcc test.cpp -o test
登录colab,需要有google账号
更改runtime选项
Runtime
> change runtime type
>
GPU
%%writefile test.cu
会将该代码块后面的代码写入到test.cu文件中
%%writefile test.cu
#include <cstdio>
#include <cuda_runtime.h>
void Print() {
__device__ ("this is a GPU\n");
printf}
void kernel_host() {
("this is a CPU\n");
printf}
void kernel() {
__global__ ();
Print}
int main() {
<<<1,1>>>();
kernel();
cudaDeviceSynchronize();
kernel_host}
!
会运行shell命令,使用nvcc
编译步骤3中生成的test.cu
文件
!nvcc test.cu -o test
!./test
output:
this is a GPU
this is a CPU