Skip to content

Commit

Permalink
Fix #2024.
Browse files Browse the repository at this point in the history
  • Loading branch information
athas committed Oct 6, 2023
1 parent 481c176 commit 5282ee4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed

* Inefficient locking for certain segmented histograms (#2024).

## [0.25.5]

### Added
Expand Down
12 changes: 8 additions & 4 deletions src/Futhark/CodeGen/ImpGen/GPU/SegHist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,14 @@ computeHistoUsage space op = do

prepareAtomicUpdateGlobal ::
Maybe Locking ->
Shape ->
[VName] ->
SegHistSlug ->
CallKernelGen
( Maybe Locking,
[Imp.TExp Int64] -> InKernelGen ()
)
prepareAtomicUpdateGlobal l dests slug =
prepareAtomicUpdateGlobal l segments dests slug =
-- We need a separate lock array if the operators are not all of a
-- particularly simple form that permits pure atomic operations.
case (l, slugAtomicUpdate slug) of
Expand All @@ -181,7 +182,8 @@ prepareAtomicUpdateGlobal l dests slug =
let num_locks = 100151
dims =
map pe64 $
shapeDims (histOpShape (slugOp slug))
shapeDims segments
++ shapeDims (histOpShape (slugOp slug))
++ [tvSize (slugNumSubhistos slug)]
++ shapeDims (histShape (slugOp slug))

Expand All @@ -202,14 +204,15 @@ bodyPassage kbody

prepareIntermediateArraysGlobal ::
Passage ->
Shape ->
Imp.TExp Int32 ->
Imp.TExp Int64 ->
[SegHistSlug] ->
CallKernelGen
( Imp.TExp Int32,
[[Imp.TExp Int64] -> InKernelGen ()]
)
prepareIntermediateArraysGlobal passage hist_T hist_N slugs = do
prepareIntermediateArraysGlobal passage segments hist_T hist_N slugs = do
-- The paper formulae assume there is only one histogram, but in our
-- implementation there can be multiple that have been horisontally
-- fused. We do a bit of trickery with summings and averages to
Expand Down Expand Up @@ -379,7 +382,7 @@ prepareIntermediateArraysGlobal passage hist_T hist_N slugs = do

pure $ subhistosArray info

(l', do_op') <- prepareAtomicUpdateGlobal l dests slug
(l', do_op') <- prepareAtomicUpdateGlobal l segments dests slug

pure (l', do_op')

Expand Down Expand Up @@ -492,6 +495,7 @@ histKernelGlobal map_pes num_groups group_size space slugs kbody = do
(hist_S, histograms) <-
prepareIntermediateArraysGlobal
(bodyPassage kbody)
(Shape (init space_sizes))
num_threads
(pe64 $ last space_sizes)
slugs
Expand Down
5 changes: 3 additions & 2 deletions src/Futhark/IR/Prop/Reshape.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ flattenIndex ::
[num] ->
[num] ->
num
flattenIndex dims is =
sum $ zipWith (*) is slicesizes
flattenIndex dims is
| length is /= length slicesizes = error "flattenIndex: length mismatch"
| otherwise = sum $ zipWith (*) is slicesizes
where
slicesizes = drop 1 $ sliceSizes dims

Expand Down

0 comments on commit 5282ee4

Please sign in to comment.