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

Đang mở
#587 11 bình luận 0 reaction 0 người được giao Xem trên GitHub

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
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
haskell
Lĩnh vực
compilers

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Haskell
Star
1k
Fork
138
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
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của AccelerateHS/accelerate

Tất cả issue của AccelerateHS/accelerate

Issue tương tự

Thêm issue về Haskell

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.