Fix intra-workgroup counts/scan_sum race in spla_mxm_merge_simple_kernel

Open
#314 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
70/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp
Domain
backend, testing

Research direction

Read src/opencl/kernels/mxm_merge_simple.cl and inspect spla_mxm_merge_simple_kernel around the counts read and wd_initialize call. Add the local memory barrier at the specified point, regenerate src/opencl/generated/auto_mxm_merge_simple.hpp, and add a regression test that exercises multiple subgroups and checks for deterministic mxm results.

Written by the indexing model from the issue text.

Description

task

Non-deterministic mxm checksum starting at c2e3187c (313-S2) because spla_mxm_merge_simple_kernel in src/opencl/kernels/mxm_merge_simple.cl reads scratch.load.counts[...] and immediately calls wd_initialize(scratch.work.work_sum, scratch.work.scan_sum, ...) without a barrier(CLK_LOCAL_MEM_FENCE).

After c2e3187c unpadded work_sum (MS_THREADS * 2u + 1u < LM_SIZE(MS_THREADS * 2u)), scratch.work.scan_sum overlaps the tail of scratch.load.counts inside union MxMMergeSimpleScratch, so with WD_BLOCKIN == 1u faster subgroups overwrite counts before other subgroups read it.

Fix: add barrier(CLK_LOCAL_MEM_FENCE); after reading scratch.load.counts[...] and before wd_initialize(...) in src/opencl/kernels/mxm_merge_simple.cl, regenerate src/opencl/generated/auto_mxm_merge_simple.hpp, and add a multi-subgroup regression test.

Dominant language
C++
Stars
37
Forks
21
Avg merge
11h 3m
Merged PRs (30d)
13

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from SparseLinearAlgebra/spla

All issues in SparseLinearAlgebra/spla

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.