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

Add ClashFloPoCo #23

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Add ClashFloPoCo #23

wants to merge 4 commits into from

Conversation

yourcomrade
Copy link

This will ClashFloPoCo, which is the library for interacting between Clash and FloPoCo. This library provides a custom example of the implementation and binding 3 single precision floating point operations supported by FloPoCo: addition, fuse multiply addition, and exponent. It also provides a markdown doc about how to use it.

@MinhQbaylogic
Copy link

Currently, it has the warning issue for the genBlackBoxProd function used in FloPoCoExample.hs . I will add ghc flag to disable the warning later.

@@ -0,0 +1,121 @@
# Clash library for interacting with FloPoCo
This is the library contains API to interact with FloPoCo to generate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This is the library contains API to interact with FloPoCo to generate
This is library contains an API to interact with [FloPoCo](https://flopoco.org/) to generate

@@ -0,0 +1,121 @@
# Clash library for interacting with FloPoCo
This is the library contains API to interact with FloPoCo to generate
hardware synthesizable floating point arithmetics function.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
hardware synthesizable floating point arithmetics function.
synthesizable floating point arithmetic functions.

# Clash library for interacting with FloPoCo
This is the library contains API to interact with FloPoCo to generate
hardware synthesizable floating point arithmetics function.
It can also be used with Float type in haskell
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
It can also be used with Float type in haskell
It can also be used with Haskell's regular 'Float' type.

It can also be used with Float type in haskell
# How to use it
1. Install FloPoCo library
On Linux, user can run to go to FloPoCo source code follow the instruction.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
On Linux, user can run to go to FloPoCo source code follow the instruction.
On Linux, you can follow the [installation instructions](https://flopoco.org/flopoco_installation.html) to build FloPoCo from source.

# How to use it
1. Install FloPoCo library
On Linux, user can run to go to FloPoCo source code follow the instruction.
For Window, user must enable Window Subsystem Linux to install FloPoCo as
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For Window, user must enable Window Subsystem Linux to install FloPoCo as
For Windows, you must enable Window Subsystem Linux first and then follow the instructions for Linux as

Comment on lines 17 to 28
module Clash.Cores.ClashFloPoCo.GenTemDSL
( getPipeDep,
flopocoPrim,
genFloPoCoInfoEntity,
liftInfoEntity,
genBlackBoxFunction,
genTemplateFunction,
genBlackBoxTemplateFunction,
genBlackBoxTemplateFunctionProd,
genBlackBox,
genBlackBoxProd,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use leading , for the export list, see for example:

module Clash.Cores.Xilinx.Floating
( -- * Instantiating IP
addWith
, add
, E.AddDefDelay
, subWith
, sub
, E.SubDefDelay
, mulWith
, mul
, E.MulDefDelay
, divWith
, div
, E.DivDefDelay
, fromU32With
, fromU32
, E.FromU32DefDelay
, E.Ordering(..)
, E.toMaybeOrdering
, compare
, compareWith
, E.CompareDefDelay
, fromS32With
, fromS32
, E.FromS32DefDelay
-- * Customizing IP
, E.Config(..)
, E.defConfig
, E.ArchOpt(..)
, E.DspUsage(..)
, E.BMemUsage(..)
) where

getPipeDep infoen = do
return (LitT (NumTyLit (fromIntegral (convertMaybeToInt (pipedep infoen)))))

-- | Function to generate the InfoEntity coresponding to the arithmetic entity generated by FloPoCo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have haddock generate a link to InfoEntity

Suggested change
-- | Function to generate the InfoEntity coresponding to the arithmetic entity generated by FloPoCo
-- | Function to generate the 'InfoEntity' coresponding to the arithmetic entity generated by FloPoCo

Comment on lines 100 to 102
--
--

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These line can be removed

Comment on lines 96 to 98
liftInfoEntity :: InfoEntity -> Q Exp
liftInfoEntity (InfoEntity n f p ins outs) =
[|InfoEntity $(lift n) $(lift f) $(lift p) $(lift ins) $(lift outs)|]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not create an instance Lift InfoEntity where you define the InfoEntity type?

Comment on lines +141 to +143
-- | Function to convert Maybe Int to Int
convertMaybeToInt :: Maybe Int -> Int
convertMaybeToInt = fromMaybe 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just inline this definition, because:

  1. It only has one use site
  2. The name convertMaybeToInt doesn't really inform the user that happens when the argument is Nothing; the choice for 0 is arbitrary.

Comment on lines +173 to +199
let funcDec =
FunD
bbfName
[ Clause
[WildP, WildP, WildP, WildP]
( NormalB
( AppE
(VarE 'pure)
( AppE
(ConE 'Right)
( TupE
[ Just (RecUpdE (VarE 'emptyBlackBoxMeta) [('bbKind, ConE 'TDecl)]),
Just
( AppE
( AppE
(AppE (ConE 'BBFunction) (LitE (StringL (entityName <> "TF")))) -- 1st arg
(LitE (IntegerL 0)) -- 2nd arg
)
(AppE (VarE tfName) (LitE (StringL entityName))) -- 3rd arg
)
]
)
)
)
)
[]
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be simplified to:

  -- Create the function declaration
  funExpr <- [|pure (Right (emptyBlackBoxMeta {bbKind = TDecl}, BBFunction (entityName <> "TF") 0 ($(varE tfName) entityName)))|]
  let funcDec = FunD bbfName [Clause [WildP,WildP,WildP, WildP] (NormalB funExpr) []]

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

Successfully merging this pull request may close these issues.

3 participants