[GH-ISSUE #3524] [Engine] SM70/Volta build fails: q36_engine.cu calls __device__ __half_as_ushort from host function verify_q8 #1444

Closed
opened 2026-11-04 01:51:20 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @li-y-w on GitHub (Oct 21, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/3524

Summary

Building the 0.1.45+ engine with -DSTRATA_EXPERIMENTAL_SM60=ON (Volta / SM70, e.g. Tesla V100) fails: src/qwen35/q36_engine.cu calls the device-only intrinsic __half_as_ushort() from a host function.

Environment

Strata main @ 9de04cd4 (Control 0.1.46.3, engine 0.1.46.3)
OS Linux (Ubuntu 24.04) x86_64
GPU Tesla V100-SXM2-16GB (SM70, driver 580.178.04)
CUDA 12.0.140 (build-cuda12, CMAKE_CUDA_ARCHITECTURES=70)
Host compiler g++-12 (12.4.0)
CMake option STRATA_EXPERIMENTAL_SM60=ON

Error

src/qwen35/q36_engine.cu(1659): error: calling a __device__ function("__half_as_ushort(    ::__half)") from a __host__ function("verify_q8") is not allowed

1 error detected in the compilation of "src/qwen35/q36_engine.cu".
ninja: build stopped: subcommand failed.

setup.sh --update retries the build once, hits the same error, then falls back to the previously installed engine (could not compile the updated engine: starting the installed one), so the update silently no-ops while claiming success.

Cause

verify_q8() is a host function (it only runs under STRATA_Q36_VDEBUG for debug output). Line 1659 casts the fp16 value of the CPU butterfly sum to its bit pattern:

std::fprintf(stderr, "VDEBUG block %zu: ds new %08x old %08x, qs bytes %s, cpu butterfly sum %.9g (half %04x)\n",
             blk, ds_a, ds_b, std::memcmp(&a[o + 4], &b[o + 4], 32) == 0 ? "equal" : "DIFFER", (double) t[0],
             (unsigned) __half_as_ushort(__float2half(t[0])));

__half_as_ushort is declared __device__ in cuda_fp16.h; on this arch/header combination nvcc does not accept the host call. It is not guarded by #ifdef __CUDA_ARCH__, so the SM60/SM70 path cannot build at all.

Fix

Read the bit pattern on the host directly — same value, no device intrinsic:

unsigned short t0_bits;
{ const __half t0h = __float2half(t[0]); std::memcpy(&t0_bits, &t0h, 2); }
std::fprintf(stderr, "... (half %04x)\n", ..., (unsigned) t0_bits);

(or __half2ushort_rn / union pun; anything host-side). I verified this builds and runs:

  • cmake --build build-cuda12 --target strata strata_qwen35 → OK
  • ./update.sh → engine compiled: .../engine-cuda12/strata, Strata is updated (engine 0.1.46.3)
  • Model starts, /health 200, 262144 ctx, chat completions work

Suggestion

Guard the debug cast with #if defined(__CUDA_ARCH__) or use the host-safe conversion above, so the SM60 experimental path keeps compiling. Secondarily: when the engine build fails, update.sh exiting 0 with "Strata is updated" is misleading — a non-zero exit code (or a clear "engine NOT updated" banner) would save users from thinking they upgraded when they did not.

Originally created by @li-y-w on GitHub (Oct 21, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/3524 ## Summary Building the 0.1.45+ engine with `-DSTRATA_EXPERIMENTAL_SM60=ON` (Volta / SM70, e.g. Tesla V100) fails: `src/qwen35/q36_engine.cu` calls the device-only intrinsic `__half_as_ushort()` from a host function. ## Environment | | | |---|---| | Strata | `main` @ `9de04cd4` (Control 0.1.46.3, engine 0.1.46.3) | | OS | Linux (Ubuntu 24.04) x86_64 | | GPU | Tesla V100-SXM2-16GB (SM70, driver 580.178.04) | | CUDA | 12.0.140 (build-cuda12, `CMAKE_CUDA_ARCHITECTURES=70`) | | Host compiler | g++-12 (12.4.0) | | CMake option | `STRATA_EXPERIMENTAL_SM60=ON` | ## Error ``` src/qwen35/q36_engine.cu(1659): error: calling a __device__ function("__half_as_ushort( ::__half)") from a __host__ function("verify_q8") is not allowed 1 error detected in the compilation of "src/qwen35/q36_engine.cu". ninja: build stopped: subcommand failed. ``` `setup.sh --update` retries the build once, hits the same error, then falls back to the previously installed engine (`could not compile the updated engine: starting the installed one`), so the update silently no-ops while claiming success. ## Cause `verify_q8()` is a host function (it only runs under `STRATA_Q36_VDEBUG` for debug output). Line 1659 casts the fp16 value of the CPU butterfly sum to its bit pattern: ```cpp std::fprintf(stderr, "VDEBUG block %zu: ds new %08x old %08x, qs bytes %s, cpu butterfly sum %.9g (half %04x)\n", blk, ds_a, ds_b, std::memcmp(&a[o + 4], &b[o + 4], 32) == 0 ? "equal" : "DIFFER", (double) t[0], (unsigned) __half_as_ushort(__float2half(t[0]))); ``` `__half_as_ushort` is declared `__device__` in `cuda_fp16.h`; on this arch/header combination nvcc does not accept the host call. It is not guarded by `#ifdef __CUDA_ARCH__`, so the SM60/SM70 path cannot build at all. ## Fix Read the bit pattern on the host directly — same value, no device intrinsic: ```cpp unsigned short t0_bits; { const __half t0h = __float2half(t[0]); std::memcpy(&t0_bits, &t0h, 2); } std::fprintf(stderr, "... (half %04x)\n", ..., (unsigned) t0_bits); ``` (or `__half2ushort_rn` / union pun; anything host-side). I verified this builds and runs: - `cmake --build build-cuda12 --target strata strata_qwen35` → OK - `./update.sh` → `engine compiled: .../engine-cuda12/strata`, `Strata is updated (engine 0.1.46.3)` - Model starts, `/health` 200, 262144 ctx, chat completions work ## Suggestion Guard the debug cast with `#if defined(__CUDA_ARCH__)` or use the host-safe conversion above, so the SM60 experimental path keeps compiling. Secondarily: when the engine build fails, `update.sh` exiting 0 with "Strata is updated" is misleading — a non-zero exit code (or a clear "engine NOT updated" banner) would save users from thinking they upgraded when they did not.
Author
Owner

@github-actions[bot] commented on GitHub (Oct 21, 2026):

Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing:

  • Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other], then a short description. Example: "[Engine] decode stops after 2 minutes".

Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment /reopen.

Details: CONTRIBUTING.md

<!-- gh-comment-id:6304715322 --> @github-actions[bot] commented on GitHub (Oct 21, 2026): Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing: - [ ] Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other], then a short description. Example: "[Engine] decode stops after 2 minutes". Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment `/reopen`. Details: [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md)
Author
Owner

@github-actions[bot] commented on GitHub (Oct 21, 2026):

Thanks, this follows the format now.

<!-- gh-comment-id:6304725593 --> @github-actions[bot] commented on GitHub (Oct 21, 2026): Thanks, this follows the format now.
Author
Owner

@Niko1221 commented on GitHub (Oct 29, 2026):

Thank you. Fixed in 0.2.2: verify_q8 no longer calls the device-only __half_as_ushort from host code, so the Volta build gets past that line with CUDA 12.0 and 12.1. If the build stops at another line, send the new error.

Release: https://github.com/Niko1221/Strata/releases/tag/v0.2.2

<!-- gh-comment-id:6491907251 --> @Niko1221 commented on GitHub (Oct 29, 2026): Thank you. Fixed in 0.2.2: `verify_q8` no longer calls the device-only `__half_as_ushort` from host code, so the Volta build gets past that line with CUDA 12.0 and 12.1. If the build stops at another line, send the new error. Release: https://github.com/Niko1221/Strata/releases/tag/v0.2.2
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#1444
No description provided.