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

Blackbox Error Caused by Simple map #960

Closed
paddytheplaster opened this issue Dec 9, 2019 · 5 comments · Fixed by #963
Closed

Blackbox Error Caused by Simple map #960

paddytheplaster opened this issue Dec 9, 2019 · 5 comments · Fixed by #963
Labels

Comments

@paddytheplaster
Copy link

Hi again,

Clash, version 1.0.1 (using clash-lib, version: 1.0.1) gives me the following error when synthesising (Clash -> vhdl):

Clash.Netlist.BlackBox(233): No blackbox found for: Data.Singletons.TypeLits.Internal.$fSingI->^@#@$_f.
Did you forget to include directories containing primitives? You can use '-i/my/prim/dir' to achieve this.

Compiling the following triggers the error. If I change the RHS of the equation to minBound, the error disappears.

f :: forall (n :: Nat) (d :: Nat)
  .  (KnownNat n,KnownNat d,1 <= n,1 <= d)
  => SNat n
  -> SNat d
  -> BitVector ((d*n)^2)
f _ _ = v2bv $ map (\_ -> low) (repeat False :: Vec ((d*n)^2) Bool)
{- f _ _ = minBound -- is grand -}

Any suggestions?

TIA for your help.

Regards,

Paddy

@paddytheplaster
Copy link
Author

If I pass an 'SNat n' and 'SNat d' as extra parameters and compute the size of the 'Vec' and use 'indices', instaed of 'indicesI', the problem doesn't show any more.

Regards,

Paddy

@rowanG077
Copy link
Member

rowanG077 commented Dec 9, 2019

I don't think it's caused by the map. I think it's triggering due to (d*n)^2 not being normalized.

Adding a constraint that computes the size of the Vec doesn't trigger the error while some other ways to write the same function triggers it.

import Clash.Prelude

triggered1 :: forall (n :: Nat) (d :: Nat)
  .  ( KnownNat n,KnownNat d,1 <= n,1 <= d)
  => SNat n
  -> SNat d
  -> BitVector ((d*n)^2)
triggered1 _ _ = v2bv $ map (\_ -> low) (repeat False :: Vec ((d*n)^2) Bool)

triggered2 :: forall (n :: Nat) (d :: Nat)
  .  ( KnownNat n,KnownNat d,1 <= n,1 <= d)
  => SNat n
  -> SNat d
  -> BitVector ((d*n)^2)
triggered2 _ _ = pack (repeat False :: Vec ((d*n)^2) Bool)

triggered3 :: forall (n :: Nat) (d :: Nat)
  .  ( KnownNat n,KnownNat d,1 <= n,1 <= d)
  => SNat n
  -> SNat d
  -> BitVector ((d*n)^2)
triggered3 _ _ = 0

notTriggered1
  :: forall (n :: Nat) (d :: Nat) (s :: Nat)
  .  ( KnownNat n,KnownNat d, KnownNat s, 1 <= n,1 <= d, s ~ ((d*n)^2))
  => SNat n
  -> SNat d
  -> BitVector s
notTriggered1 _ _ = v2bv $ map (\_ -> low) (repeat False :: Vec s Bool)

notTriggered2 :: forall (n :: Nat) (d :: Nat)
  .  ( KnownNat n,KnownNat d,1 <= n,1 <= d)
  => SNat n
  -> SNat d
  -> BitVector ((d*n)^2)
notTriggered2 _ _ = minBound

topEntity :: Signal System (BitVector 16)
topEntity = pure $ triggered3 (SNat @2) (SNat @2)

Compiling with -fclash-compile-ultra also fixes the issue for triggered1 and triggered2 cases but not for triggered3.

@paddytheplaster
Copy link
Author

Thanks Rowan,

Nice analysis.

Is this '-fclash-compile-ultra' flasg documented anywhere?

Regards,

Paddy

@rowanG077
Copy link
Member

It's not documented anywhere currently. I think #961 will document it. But be aware that this flag can increase the time to compile considerably.

@leonschoorl
Copy link
Member

As @rowanG077 said: this is caused by the ^ in the length of the Vec.

Clash tries to evaluate the ^ with:

-- XXX: Very fragile. /$s^_f/ is a specialized version of ^_f. That means that
-- it is type applied to some specific type.
"Data.Singletons.TypeLits.Internal.$s^_f"
| Just (i,j) <- naturalLiterals args
-> reduce (Literal (NaturalLiteral (i ^ j)))

And as the comment says this is "Very fragile", because we're matching on some generated name for some internal function.
And now it seems this name has changed, with ghc-8.6 it's called: $fSingI->^@#@$_f
And with ghc-8.8 it changed again to: %^_f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants