ssh to dev-container

  1. Check SSH Service Status [in dev-container]

    • Verified if SSH service was already running in the container
    • Found no SSH daemon running initially
  2. Install OpenSSH Server [in dev-container]

    • Used sudo apt install -y openssh-server to install SSH server package
    • System automatically generated SSH host keys during installation
  3. Start SSH Service [in dev-container]

    • Executed sudo service ssh start to launch SSH daemon
    • Confirmed SSH was listening on port 22 using netstat -tlnp
  4. Configure SSH Security Settings [in dev-container]

    • Modified /etc/ssh/sshd_config to enable root login: PermitRootLogin yes
    • Enabled password authentication: PasswordAuthentication yes
  5. Set Root Password [in dev-container]

    • Set root user password to “123456” using echo "root:123456" | sudo chpasswd
    • Cleared and reset password when authentication issues occurred
  6. Restart SSH Service [in dev-container]

    • Applied configuration changes with sudo service ssh restart
    • Ensured all settings took effect
  7. Regenerate Host Keys [in dev-container]

    • Removed old host keys with sudo rm -f /etc/ssh/ssh_host_*
    • Generated new keys using sudo ssh-keygen -A
    • Resolved host key verification conflicts
  8. Test SSH Connectivity [in dev-container]

    • Tested internal SSH connection using sshpass -p "123456" ssh -o StrictHostKeyChecking=no root@localhost
    • Verified successful authentication and command execution
    • Confirmed external SSH connection works through port forwarding
  9. Setup Port Forwarding and Provide Connection Instructions [in dev-container + on local machine]

    • Map the current dev container’s port 22 to the host’s port 65345(or other), enabling external applications to connect to the SSH service inside the container
    • Configured port forwarding: localhost:65345(or other) → container:22 in VS Code/Cursor
    • Created ~/.ssh/config file on the host machine and added connection settings
    • Guided user through VS Code Remote SSH extension setup or terminal connection

SSH Configuration (~/.ssh/config):
After completing the above process, you need to manually add this content to your SSH config file, then connect through kirocode

1
2
3
4
5
6
Host dev-container
HostName localhost
User root
Port 65345
PasswordAuthentication yes
StrictHostKeyChecking no

Hello World from HIP and LLVM

引言

这是一篇用来测试博客是否渲染成功的硬核技术文章。

核心代码测试

1
2
3
4
#include <hip/hip_runtime.h>
__global__ void hello() {
printf("Hello from GPU!\n");
}

Compile rocm runtime library

引言

AMD开源了runtime library, 如果你有一张AMD的卡, 完全可以自己尝试编译一下他们的仓库,debug一下

步骤

克隆仓库: https://github.com/ROCm/rocm-systems.git和https://github.com/ROCm/llvm-project.git, 我自己编译的版本是rocm-7.2, 注意分支的一致性

编译LLVM

下面的路径可以按需替换

1
2
3
4
5
6
7
8
9
10

cmake -S llvm -B build -DCMAKE_BUILD_TYPE=Release -G Ninja \
-DLLVM_ENABLE_PROJECTS="clang;lld" \
-DLLVM_EXTERNAL_PROJECTS="device-libs;comgr" \
-DLLVM_EXTERNAL_DEVICE_LIBS_SOURCE_DIR=/home/jing.zhou/rocm-llvm/amd/device-libs \
-DLLVM_EXTERNAL_COMGR_SOURCE_DIR=/home/jing.zhou/rocm-llvm/amd/comgr \
-DCMAKE_INSTALL_PREFIX=/home/jing.zhou/rocm-systems/projects/install \
-DLLVM_TARGETS_TO_BUILD="X86;AMDGPU" \
-DCMAKE_LINKER=/home/jing.zhou/tools/bin/mold

编译clr

cd到rocm-systems目录,

1
2
3
4
5
6
7
8
9
10
11
export CLR_DIR="$(readlink -f projects/clr)"
export HIP_DIR="$(readlink -f projects/hip)"

export PATH=/home/jing.zhou/rocm-systems/projects/install/bin:$PATH

cd "$CLR_DIR"
mkdir -p build; cd build
cmake -DHIP_COMMON_DIR=$HIP_DIR -DCMAKE_PREFIX_PATH="/home/jing.zhou/rocm-systems/projects" -DROCM_INSTALL_PATH="/home/jing.zhou/rocm-systems/projects/install" -DCMAKE_INSTALL_PREFIX=/home/jing.zhou/rocm-systems/projects/install -DCLR_BUILD_HIP=ON -DCLR_BUILD_OCL=OFF -DHIP_PLATFORM=amd ..
make -j$(nproc)
make install

demo

1
2
3
4
export LD_LIBRARY_PATH=/home/jing.zhou/rocm-systems/projects/install/lib:$LD_LIBRARY_PATH
export HIP_CLANG_PATH="/home/jing.zhou/rocm-systems/projects/install/bin"
export HIP_PATH="/home/jing.zhou/rocm-systems/projects/install"
export HIP_PLATFORM=amd

写一份简单的hello-world代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
// 引入 HIP 运行时头文件
#include <hip/hip_runtime.h>

// 1. 定义 GPU 核函数 (Kernel)
// __global__ 告诉编译器这个函数是在 GPU 上执行的,但由 CPU 发起调用
__global__ void gpu_hello_world() {
// blockIdx, blockDim, threadIdx 是 HIP 的内置变量
// 这里计算出当前线程的全局唯一 ID
int gtid = blockIdx.x * blockDim.x + threadIdx.x;

// printf 在 GPU 核函数中是受支持的(适合调试)
printf("Hello World from GPU thread %d!\n", gtid);
}

int main() {
// 2. 在 CPU (Host) 上打印
std::cout << "Hello World from CPU!" << std::endl;

// 3. 配置 GPU 的执行网格 (Grid) 和线程块 (Block)
// 这里我们启动 1 个线程块,里面包含 4 个线程
dim3 grid(1);
dim3 block(4);

// 4. 启动 GPU 核函数
// 使用 <<<...>>> 语法来指定网格和线程块大小
hipLaunchKernelGGL(gpu_hello_world, grid, block, 0, 0);

// 5. 同步 CPU 和 GPU
// 因为 GPU 的执行是异步的,CPU 需要等待 GPU 打印完毕后再退出程序
hipDeviceSynchronize();

return 0;
}

输出

1
2
3
4
5
6
Hello World from CPU!
Hello World from GPU thread 0!
Hello World from GPU thread 1!
Hello World from GPU thread 2!
Hello World from GPU thread 3!