0Pricing
CUDA Academy · 课时

使用 synccheck 捕获同步错误

发散的 __syncthreads 与相关隐患

使用 synccheck 捕获同步错误 是 CoddyKit 上的免费 CUDA Academy 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 CUDA Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 CUDA Academy 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

The Barrier Contract

A __syncthreads barrier only works if every thread in the block reaches it. Skip it for some threads and behavior turns undefined. ⚠️

Divergent Barriers

Calling a barrier inside a branch some threads skip is a divergent sync, the exact hazard the synccheck tool is built to catch.

Meet synccheck

Run the synccheck tool of compute-sanitizer to detect illegal or divergent uses of __syncthreads and related barriers.

compute-sanitizer --tool synccheck ./tile

A Buggy Conditional Sync

Here only some threads call the barrier, leaving the rest behind. synccheck flags this as a divergent __syncthreads.

if (tid < half) {
    __syncthreads();
}

The Correct Pattern

Pull the barrier out of the branch so all threads reach it together, while only the guarded work stays conditional.

if (tid < half) {
    sum += tile[tid];
}
__syncthreads();

Barriers in Loops

Every thread must run the same number of barriers, so a loop with a thread-dependent trip count plus an inner sync is a trap.

Early Returns Are Risky

A thread that hits an early return before a barrier never arrives, so synccheck reports the remaining threads stuck waiting.

Reading the Report

synccheck names the barrier and the threads that diverged, so you can trace which branch or return broke the contract.

Warp-Level Syncs Too

synccheck also checks __syncwarp masks, flagging when a thread participates with a mask that does not match its lane.

Add Line Info

Compile with -lineinfo so synccheck can point at the exact barrier call instead of just naming the kernel.

nvcc -lineinfo tile.cu -o tile

One Tool per Run

Run synccheck on its own pass, separate from memcheck and racecheck, since each sanitizer tool targets a different class of bug.

Quick Check

What problem does the synccheck tool specifically detect?

Recap

You learned the barrier contract, ran synccheck, and fixed divergent syncs by moving barriers out of branches. Your block stays in step. 🙌

常见问题解答

「使用 synccheck 捕获同步错误」课时是免费的吗?

是的 — 「使用 synccheck 捕获同步错误」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 CUDA Academy 课程的其余内容,请升级到 CoddyKit PRO。 CUDA Academy 课程共包含 4 节课。

「使用 synccheck 捕获同步错误」这节课中我会学到什么?

发散的 __syncthreads 与相关隐患 你通过在浏览器中直接运行的动手代码来练习 CUDA Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 CUDA Academy 需要有经验吗?

无需任何先前经验。CoddyKit 上的 CUDA Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。

「使用 synccheck 捕获同步错误」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 CUDA Academy 课中编写并运行代码吗?

能。每节 CUDA Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 在 cuda-gdb 中单步执行内核
  2. 使用 memcheck 查找内存泄漏
  3. 使用 racecheck 排查竞态
  4. 使用 synccheck 捕获同步错误
← 返回 CUDA Academy