Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scaling issue in the "lift" and "transform" stages #573

Open
quark17 opened this issue Jul 9, 2023 · 0 comments
Open

Scaling issue in the "lift" and "transform" stages #573

quark17 opened this issue Jul 9, 2023 · 0 comments
Labels
evaluator Relates to the elaboration/expanded stage of compilation

Comments

@quark17
Copy link
Collaborator

quark17 commented Jul 9, 2023

The example given in this discussion comment shows a scaling issue as the number of system task calls increases:

package ReadManyBytes where

import Vector

type N = 16

mkReadManyBytes :: Module (Empty)
mkReadManyBytes = module
  rules
    {-# ASSERT no implicit conditions #-}  {-# ASSERT fire when enabled #-}
    "foo": when True ==> do
      opened :: File <- $fopen "my_file" "r"
      x :: Vector N (Int 32) <- mapM (\_ -> $fgetc opened) _
      if (any (\c -> c < 0) x) then do
        $display "Got EOF"
      else do
        mapM_ (\c -> $write "%c" c) x
        $display  -- Newline
      $fclose opened
      $finish

This example replicates $fgetc many times and then replicates $write many times. The scaling issue seems to be most severe with $write in this case. Details are in the replies to the discussion comment, but I'll summarize. At size 128, the first transform is a few seconds, and the later lift and transform stages are 20-30 seconds; at size 512, the first transform is 25 seconds, the lift is 200, and the the second transform runs out of stack (even at 10M, would be worth trying larger). If the replicated $write is removed (or is replaced with a single display of the whole vector), then first transform still takes 25 seconds, but the later lift and transform take no time.

@quark17 quark17 added the evaluator Relates to the elaboration/expanded stage of compilation label Jul 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
evaluator Relates to the elaboration/expanded stage of compilation
Projects
None yet
Development

No branches or pull requests

1 participant