[BUG] Duplicate `ATag` error during sharing recovery with parallel GC

Aperta
#587 8 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
haskell
Ambito
compilers

Direzione di ricerca

The bug is in Data.Array.Accelerate.Trafo.Sharing (Sharing.hs); start at internalError (line 2243) and buildInitialEnvAcc (line 2623). Read sharing recovery near line 3084 and reproduce with given Main.hs via ghc -O1 -threaded -rtsopts -package accelerate then ./repro +RTS -A64k -RTS. Done when 1000 conversions succeed without duplicate ATag errors under parallel GC.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug frontend help wanted

Environment

  • Accelerate 1.4.0.0
  • GHC 9.8.4 / base 4.19.2.0
  • Linux x86_64

Reproducing

Main.hs:

module Main where

import Control.Exception (evaluate)
import Control.Monad (forM_, when)
import qualified Data.Array.Accelerate as A
import qualified Data.Array.Accelerate.Trafo.Sharing as Sharing
import GHC.Conc (setNumCapabilities)

stage :: Int -> A.Acc (A.Vector Double) -> A.Acc (A.Vector Double)
stage n input = foldl1 (A.zipWith (+)) [A.map (\x -> x + A.constant (fromIntegral (n + i))) input | i <- [1 .. 8 :: Int]]

program :: Int -> A.Acc (A.Vector Double) -> A.Acc (A.Vector Double)
program n input = foldl (\x f -> f x) input (replicate 40 (stage n A.>-> stage (n + 1)))

main :: IO ()
main = do
  setNumCapabilities 8
  forM_ [1 .. 1000 :: Int] $ \n -> do
    _ <- evaluate (length (show (Sharing.convertAfun (program n))))
    when (n `mod` 100 == 0) (print n)

With Accelerate installed and available to GHC:

ghc -O1 -threaded -rtsopts -package accelerate Main.hs -o repro
./repro +RTS -A64k -RTS

Expected behavior

All 1000 graph conversions complete successfully.

Actual behavior

Sharing recovery fails with an internal error:

Encountered duplicate 'ATag's
  3116: Atag 1, 3100: Atag 1
CallStack (from HasCallStack):
  internalError: Data.Array.Accelerate.Trafo.Sharing:2243:19
  buildInitialEnvAcc: Data.Array.Accelerate.Trafo.Sharing:2623:48
  scopesAfun1: Data.Array.Accelerate.Trafo.Sharing:2346:62

The failing iteration varies between runs.

Disabling parallel GC for the same executable:

./repro +RTS -A64k -qg -RTS

I tested five runs in each mode using the same executable, alternating between the two modes:

GC mode Runs Duplicate ATag failures Successful runs
Parallel GC 5 3 2
Parallel GC disabled (-qg) 5 0 5

All five runs with -qg completed 1000 conversions each: 5000 conversions with no errors. In the parallel-GC runs, two failures occurred after the progress message 400; another occurred before the first progress message (100).

Suspected cause

Sharing recovery requires physically shared Atag nodes, as described in Sharing.hs.

GHC's parallel copying GC can duplicate immutable constructors through copy_tag_nolock.
This suggests that physical copies of the same tag receive different stable names and
are subsequently rejected as duplicate tags during sharing recovery.

Discussion

Would it be feasible to fix this by identifying bound variables independently of physical sharing,
or by handling duplicated tags during environment construction?

I’d be happy to try working on a fix with some guidance.
I’m not very familiar with de Bruijn indices or the sharing recovery implementation,
and much of the investigation above was carried out with assistance from LLM,
however, I would like to extend my knowledge in this pretty interesting subject,
so I’d appreciate a review of the diagnosis and advice on where to start.

Lingua principale
Haskell
Stelle
1k
Fork
138
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di AccelerateHS/accelerate

Tutte le issue di AccelerateHS/accelerate

Issue simili

Altre issue su Haskell

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.