gpu/kinfu, octree, surface: Missing `__syncwarp()` in `Emulation::warp_reduce` and `warps_buffer` lane-0 broadcasts causes shared-memory RAW races on Volta+ (`sm_70+`)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 55/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- cpp
Hướng nghiên cứu
Start with the six named CUDA files and inspect the reduction and lane-0 broadcast code cited in the issue. Compare these patterns with the octree search kernels already migrated to __shfl_sync, then run the reported kernels under compute-sanitizer --tool racecheck. Done means the shared-memory RAW hazards are gone on Volta+ while the reductions and broadcasts still produce correct results.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
Several PCL GPU utilities still rely on pre-Volta (sm_6x) implicit warp lockstep via volatile __shared__ without __syncwarp(), causing shared-memory RAW data races under Volta+ (sm_70+) Independent Thread Scheduling (confirmed by compute-sanitizer --tool racecheck):
1. Emulation::warp_reduce / pcl::device::warp_reduce (3 files)
gpu/kinfu/src/cuda/utils.hpp#L564-L580gpu/kinfu_large_scale/src/cuda/utils.hpp#L566-L582gpu/octree/src/utils/warp_reduce.hpp#L46-L62
static __device__ __forceinline__ int
warp_reduce ( volatile int *ptr , const unsigned int tid)
{
const unsigned int lane = tid & 31; // index of thread in warp (0..31)
if (lane < 16)
{
int partial = ptr[tid];
ptr[tid] = partial = partial + ptr[tid + 16];
ptr[tid] = partial = partial + ptr[tid + 8];
ptr[tid] = partial = partial + ptr[tid + 4];
ptr[tid] = partial = partial + ptr[tid + 2];
ptr[tid] = partial = partial + ptr[tid + 1];
}
return ptr[tid - lane];
}
Two distinct Volta+ hazards occur here:
- Inside
if (lane < 16), each reduction step writesptr[tid]and the next step immediately readsptr[tid + offset]written by another lane (tid + 8,tid + 4,tid + 2,tid + 1) with no__syncwarp(). - Lanes
16..31skipif (lane < 16)completely and immediately executereturn ptr[tid - lane];concurrently while lane 0 is still performing the 5 reduction writes intoptr[warp_base].
2. Unsynchronized warps_buffer[warp_id] lane-0 broadcast (3 files)
gpu/kinfu/src/cuda/marching_cubes.cu#L149-L172gpu/kinfu_large_scale/src/cuda/marching_cubes.cu#L157-L180gpu/surface/src/cuda/convex_hull.cu#L499-L508(wapr_buffer)
// gpu/kinfu/src/cuda/marching_cubes.cu:167-172 (inside `for (int z = 0; z < VOLUME_Z - 1; z++)`)
if (lane_id == 0)
{
int old = atomicAdd (&global_count, total);
warps_buffer[warp_id] = old;
}
int old_global_voxels_count = warps_buffer[warp_id];
There is no __syncwarp() between lane 0's store (warps_buffer[warp_id] = old) and lanes 1..31's load (warps_buffer[warp_id]), nor before lane 0 overwrites warps_buffer[warp_id] on the next z iteration. (Note that gpu/octree/src/cuda/approx_nsearch.cu and knn_search.cu were already migrated to __shfl_sync, leaving these 3 kernels behind.)
Expected behavior
Intra-warp shared-memory reductions and lane-0 broadcasts should be explicitly synchronized via __syncwarp() or warp shuffle primitives (__shfl_down_sync / __shfl_sync) so they are race-free on sm_70+.
Current Behavior
On Volta+ (sm_70+), compute-sanitizer --tool racecheck --racecheck-report hazard reports shared-memory RAW hazards for both patterns.
To Reproduce
Compiled minimal kernels exercising each pattern with nvcc -O2 -arch=sm_89 -lineinfo and ran compute-sanitizer --tool racecheck --racecheck-report hazard:
Emulation::warp_reduce(<<<4, 128>>>):
========= Warning: (Warp Level Programming) Potential RAW hazard detected at __shared__ 0x36 in block (1,0,0) :
========= Write Thread (13,0,0)
========= Read Thread (5,0,0)
========= RACECHECK SUMMARY: 100 hazards displayed (0 errors, 3168 warnings)
warps_buffer[warp_id]lane-0 broadcast (<<<4, 256>>>,iters = 4):
========= Warning: (Warp Level Programming) Potential RAW hazard detected at __shared__ 0x14 in block (3,0,0) :
========= Write Thread (160,0,0)
========= Read Thread (161,0,0)
========= RACECHECK SUMMARY: 100 hazards displayed (0 errors, 896 warnings)
Your Environment
- OS: Ubuntu 24.04 Linux x86_64
- Compiler: NVCC 12.8 (
sm_89, NVIDIA L40) - PCL Version:
masterHEAD (fd39f32af932d50e033dba17b29e6d5fa4f64255)
Possible Solution
- In
warp_reduce(kinfu/utils.hpp,kinfu_large_scale/utils.hpp,octree/warp_reduce.hpp), replace the pre-Voltavolatileshared-memory ladder with warp shuffle (__shfl_down_sync/__shfl_sync), or insert__syncwarp()between every reduction step and beforereturn ptr[tid - lane];:
static __device__ __forceinline__ int
warp_reduce(volatile int *ptr, const unsigned int tid)
{
const unsigned int mask = __activemask();
int val = ptr[tid];
for (int offset = 16; offset > 0; offset >>= 1)
val += __shfl_down_sync(mask, val, offset);
return __shfl_sync(mask, val, 0);
}
- In
marching_cubes.cu(bothkinfuandkinfu_large_scale) andconvex_hull.cu, replace thewarps_buffer[warp_id]shared-memory broadcast with__shfl_sync:
int old = 0;
if (lane_id == 0)
old = atomicAdd(&global_count, total);
int old_global_voxels_count = __shfl_sync(__activemask(), old, 0);
(Or insert __syncwarp(__activemask()); immediately after the if (lane_id == 0) store and before the next iteration's write.)
- Ngôn ngữ chính
- C++
- Star
- 11.2k
- Fork
- 4.7k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của PointCloudLibrary/pcl
-
kind: bug status: triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
PointCloudLibrary/pcl#6543 ·
-
[io] pcl::io::raw_open opens files in text mode on Windows, so raw_read alters binary dataCó thể đã có người làm @Aditya-stack-droid đã nhận 3 ngày trước. Đang mởkind: bug status: triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
PointCloudLibrary/pcl#6536 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
PointCloudLibrary/pcl#6509 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
PointCloudLibrary/pcl#6542 ·
-
kind: bug status: triage
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
PointCloudLibrary/pcl#6537 ·
Tất cả issue của PointCloudLibrary/pcl
Issue tương tự
-
Invalid-MissingHash/Commit/NotAC
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
azerothcore/azerothcore-wotlk#28636 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
(S1 - Need confirmation)
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
CleverRaven/Cataclysm-DDA#89829 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
comp-documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ClickHouse/ClickHouse#136277 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Flow Needs: Triage :mag:
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
react/react-native#60447 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
RecompLauncher supportĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày