Skip to content

[ROCm] add rocm/hip backend and add pic for build of rocm/hip - #121

Merged
cjpais merged 5 commits into
handy-computer:mainfrom
WhatGhost:rocm-backend
Jul 31, 2026
Merged

[ROCm] add rocm/hip backend and add pic for build of rocm/hip#121
cjpais merged 5 commits into
handy-computer:mainfrom
WhatGhost:rocm-backend

Conversation

@WhatGhost

Copy link
Copy Markdown
Contributor

Summary

I want to run transcribe.cpp on my AMD GPU (W9700, gfx1201), but unlike whisper.cpp there is no HIP/ROCm support here.

So I add rocm/hip backend to enable gllm_hip in repo . So the backend classfiation dont select the "OtherGPU" for amd device.

Scope

  • build: CMakeLists.txt, scripts/ci/check_lane_mirror.py
  • backend selection: src/transcribe-backend.{h,cpp}
  • tests: tests/backend_classification_unit.cpp
  • docs: README.md

AI Assistance

AI assisted with the changes of code, the tests, and the documentation in this PR. I reviewed every change manually before submitting.

Validation

Env: Ubuntu 24.04, ROCm 7.2.3, 4x gfx1201, GCC 13.3, CMake 3.28.3.

For Build:

  • I test the whole end-to-end build steps with ROCm backend, it can be built successfully.
  • pass the ctest 33/33

For Runtime:

  • --list-devices reports all four cards as kind=rocm;
  • test Qwen3-ASR-0.6B-Q8_0.gguf on samples/zh.wav , it has the same results with CPU runtime.

No compute kernels are added or changed by this PR — the HIP backend compiles ggml's existing ggml-cuda sources with
hipcc (just like whisper.cpp)

@WhatGhost
WhatGhost requested a review from cjpais as a code owner July 30, 2026 02:11
@cjpais

cjpais commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Thank you! I'm assuming you've tested this on your machine? I will take a review and pull in when I can! I won't be able to run it so easily (though I will try!) and see if it works.

@WhatGhost

Copy link
Copy Markdown
Contributor Author

Thank you! I'm assuming you've tested this on your machine? I will take a review and pull in when I can! I won't be able to run it so easily (though I will try!) and see if it works.

Thanks! Yes, I've testing on my Radeon GPU just like the "Validation" says above. Thanks for your reply and reviews.

@cjpais

cjpais commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Yeah, I saw. I just wanted to double-check just because I'm not always sure to what degree and whether it's just an AI who has submitted the PR or a real person. So sometimes I just follow up to make sure that I'm getting a human response

I pretty much know AI is writing every single PR at this point, and it's totally fine. But I am just looking for making sure that a human basically has touched and validated things themselves because sometimes the AI can validate things, but actually, it's maybe not quite working properly, despite its validation

@WhatGhost

Copy link
Copy Markdown
Contributor Author

Yeah, I saw. I just wanted to double-check just because I'm not always sure to what degree and whether it's just an AI who has submitted the PR or a real person. So sometimes I just follow up to make sure that I'm getting a human response

I pretty much know AI is writing every single PR at this point, and it's totally fine. But I am just looking for making sure that a human basically has touched and validated things themselves because sometimes the AI can validate things, but actually, it's maybe not quite working properly, despite its validation

Yes, your concerns are completely valid. Thank you for your reply. I have personally reviewed and verified all AI-generated code in this PR. Please let me know if anything needs to be changed, and I’ll address it promptly.

@WhatGhost

Copy link
Copy Markdown
Contributor Author

@cjpais Thanks for the commit , it covers several things I had missed, especially the install manifest for non-CMake consumers.
I pull this change to my radeon gpu machine. and run
cmake -B build -DTRANSCRIBE_HIP=ON -DAMDGPU_TARGETS=gfx1201

it fails at configure time:

CMake Error at cmake/transcribe-install.cmake:170 (get_target_property):
      get_target_property() called with non-existent target "hip::host".
Call Stack (most recent call first):
      CMakeLists.txt:459 (include)

I think the cause is CMake target scope,find_package(hip) runs inside ggml/src/ggml-hip/CMakeLists.txt, and the
IMPORTED targets it creates are directory-scoped by default, so hip::host isn't visible from transcribe-install.cmake, which is included at top level (CMakeLists.txt:459). ggml itself can use the target at ggml/src/ggml-hip/CMakeLists.txt:157 because that's the same scope.

maybe it can add some 'if' guard such as

if(TARGET hip::host)
        get_target_property(_hip_host_links hip::host INTERFACE_LINK_LIBRARIES)
        ...
endif()

could you take another look at this part? Do you met the same issue, or maybe some env issue in my machine.

@cjpais

cjpais commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Thanks. I'll take a look and fix it. I'm also thinking we probably need to update all of the bindings to make sure it works properly and out of the box. I'm taking a look at this now as well

@WhatGhost

WhatGhost commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

And by the way. I forget to add a "rocm" comment to 'include/transcribe.h' . I add it via a new commit. And by my check, it don't afftect 'transcribe.abihash'

@cjpais

cjpais commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

no worries I will be committing a bunch in a second, 等一下

@cjpais

cjpais commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

@WhatGhost can you check the following, and also any additional testing you want on your side?! And after this gets merged, can I ping you for helping out in regards to rocm?

  1. Run the static build and tests
  rm -rf build-hip
  cmake -S . -B build-hip \
    -DCMAKE_BUILD_TYPE=Release \
    -DTRANSCRIBE_HIP=ON \
    -DAMDGPU_TARGETS=gfx1201 \
    -DTRANSCRIBE_BUILD_SHARED=OFF \
    -DTRANSCRIBE_INSTALL=ON

  cmake --build build-hip -j
  ctest --test-dir build-hip --output-on-failure
  1. Check that ROCm works after the library is installed
  cmake --install build-hip --prefix "$PWD/build-hip/install"

  uv run --no-project scripts/ci/link_smoke.py \
    --prefix "$PWD/build-hip/install"

you should see something like

  link-smoke ok
  kind=rocm
  1. Rerun the Qwen3-ASR test and explicitly select ROCm with --backend rocm. Please confirm it selects the AMD GPU and produces the expected transcription. If possible, compare it with --backend auto.

  2. Check the Rust ROCm feature

   TRANSCRIBE_CMAKE_ARGS="-DAMDGPU_TARGETS=gfx1201" \
     cargo run -p transcribe-cpp \
     --no-default-features --features rocm \
     --example backend-select

@WhatGhost

Copy link
Copy Markdown
Contributor Author

@

@WhatGhost can you check the following, and also any additional testing you want on your side?! And after this gets merged, can I ping you for helping out in regards to rocm?

  1. Run the static build and tests
  rm -rf build-hip
  cmake -S . -B build-hip \
    -DCMAKE_BUILD_TYPE=Release \
    -DTRANSCRIBE_HIP=ON \
    -DAMDGPU_TARGETS=gfx1201 \
    -DTRANSCRIBE_BUILD_SHARED=OFF \
    -DTRANSCRIBE_INSTALL=ON

  cmake --build build-hip -j
  ctest --test-dir build-hip --output-on-failure
  1. Check that ROCm works after the library is installed
  cmake --install build-hip --prefix "$PWD/build-hip/install"

  uv run --no-project scripts/ci/link_smoke.py \
    --prefix "$PWD/build-hip/install"

you should see something like

  link-smoke ok
  kind=rocm
  1. Rerun the Qwen3-ASR test and explicitly select ROCm with --backend rocm. Please confirm it selects the AMD GPU and produces the expected transcription. If possible, compare it with --backend auto.
  2. Check the Rust ROCm feature
   TRANSCRIBE_CMAKE_ARGS="-DAMDGPU_TARGETS=gfx1201" \
     cargo run -p transcribe-cpp \
     --no-default-features --features rocm \
     --example backend-select

Ok, Thanks very much. I'll run these test and response the results here as soon as the test finished. And no problem, you can ping me about ROCm-related issues .And I’ll take a look if it’s something I can help with. However, I don’t check GitHub notifications very often, so my response may be delayed.

@WhatGhost

Copy link
Copy Markdown
Contributor Author

no worries I will be committing a bunch in a second, 等一下

@cjpais Hi, I dont see any commit after this comment, Is there someting i missed ?

@cjpais

cjpais commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

sorry forgot to push haha

@WhatGhost

WhatGhost commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

And no problem, you can ping me about ROCm-related issues

@cjpais And by the way ,you can also reach out to other members @zihaomu @LZ-QWQ @zhangnju of our team for helping out in regards to rocm

@cjpais

cjpais commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Thanks @WhatGhost, noted them down! Appreciate it

@WhatGhost

Copy link
Copy Markdown
Contributor Author

@cjpais I have test these 4 steps.
For 1: It can succesfully build and the test is all passed with 33/33
For 2: It works and i see the output just as you say

For 3: ok, i run qwen3_asr with samples/zh.wav ,identical across backends.
--backend rocm -> qwen3_asr: using rocm backend: ROCm0
--backend auto -> qwen3_asr: using rocm backend: ROCm0
--backend cpu -> qwen3_asr: using cpu backend (strict)
All three produce 開放時間:早上九點至下午五點。

for 4. I met some undefined symbol issue.

rust-lld: error: undefined symbol: hipblasSgemm
 rust-lld: error: undefined symbol: hipLaunchCooperativeKernel
 rust-lld: error: undefined symbol: hipblasStrsmBatched
 rust-lld: error: undefined symbol: hipblasSgemmStridedBatched

I look like the rust dont find the hip so. I'm not familiar with Rust. I ask the AI.and here is the AI said.

What I think is happening: the ROCm libraries reach the manifest as absolute
library_paths, and sys/build.rs emits those as cargo:rustc-link-arg, which
per your own note at build.rs:399 doesn't propagate past the immediate
dependent. libggml-hip.a arrives through libraries -> rustc-link-lib and
does propagate — so the archive that references these symbols gets linked
while the libraries that define them don't. Vulkan avoids this by going
through _system_libs -> rustc-link-lib instead.
Two observations that fit that reading:

  • cargo test -p transcribe-cpp-sys --no-default-features --features rocm
    passes unmodified — rustc-link-arg does reach sys's own artifacts.
  • Re-injecting the exact same manifest paths by hand is enough to make the
    example link and run:
    RUSTFLAGS="-C link-arg=/opt/rocm/lib/libamdhip64.so -C link-arg=..."
    cargo run -p transcribe-cpp --no-default-features --features rocm
    --example backend-select -- model.gguf
    ROCm0 [rocm] — AMD Radeon Graphics
    Rocm = true
    loaded with Backend::Auto -> bound backend: ROCm0
    requesting Cuda failed cleanly: backend error (status 8)
    So the Rust-side ROCm logic itself looks right — Backend::Rocm, the feature
    mapping and the availability probe all behave — it's only the link line that
    doesn't survive the hop. Worth flagging that the same gap would reach any
    downstream crate depending on transcribe-cpp, not just this example.

could you please take another look at this Rust's issue, Thanks!

@cjpais

cjpais commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

@WhatGhost thanks for the quick testing, I am flying a bit blind without hardware. Could you test the rust build again? I've updated the build script

@WhatGhost

Copy link
Copy Markdown
Contributor Author

@WhatGhost thanks for the quick testing, I am flying a bit blind without hardware. Could you test the rust build again? I've updated the build script

@cjpais I've re-test the 4 steps and they are all passed. Thanks for your kindly support!!

@cjpais

cjpais commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Thank you!

@cjpais
cjpais merged commit 223c9b0 into handy-computer:main Jul 31, 2026
25 checks passed
cunba-ai added a commit to cunba-ai/transcribe.cpp that referenced this pull request Aug 2, 2026
Upstream PR handy-computer#121 (223c9b0) added a TRANSCRIBE_HIP option that wraps
GGML_HIP via FORCE, plus a PIC fix guarded by TRANSCRIBE_HIP for the
hipcc/ROCm static-archive link problem. Passing -DGGML_HIP=ON directly
left that PIC fix disabled — the ROCm jobs only worked because
BUILD_SHARED_LIBS=ON happened to turn PIC on via ggml.

Switch the Linux and Windows ROCm-CPU configure steps to
-DTRANSCRIBE_HIP=ON so the build goes through the upstream wrapper:
GGML_HIP is set correctly and the HIP PIC codegen fix applies.

Co-authored-by: Edward Chen <qinghua.chen@miaosoft.cn>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants