-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: main
Are you sure you want to change the base?
Add ClashFloPoCo #23
Conversation
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
module Clash.Cores.ClashFloPoCo.GenTemDSL | ||
( getPipeDep, | ||
flopocoPrim, | ||
genFloPoCoInfoEntity, | ||
liftInfoEntity, | ||
genBlackBoxFunction, | ||
genTemplateFunction, | ||
genBlackBoxTemplateFunction, | ||
genBlackBoxTemplateFunctionProd, | ||
genBlackBox, | ||
genBlackBoxProd, | ||
) |
There was a problem hiding this comment.
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:
clash-cores/src/Clash/Cores/Xilinx/Floating.hs
Lines 45 to 76 in 3cc8c71
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 |
There was a problem hiding this comment.
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
-- | 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 |
-- | ||
-- | ||
|
There was a problem hiding this comment.
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
liftInfoEntity :: InfoEntity -> Q Exp | ||
liftInfoEntity (InfoEntity n f p ins outs) = | ||
[|InfoEntity $(lift n) $(lift f) $(lift p) $(lift ins) $(lift outs)|] |
There was a problem hiding this comment.
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?
-- | Function to convert Maybe Int to Int | ||
convertMaybeToInt :: Maybe Int -> Int | ||
convertMaybeToInt = fromMaybe 0 |
There was a problem hiding this comment.
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:
- It only has one use site
- The name
convertMaybeToInt
doesn't really inform the user that happens when the argument isNothing
; the choice for0
is arbitrary.
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 | ||
) | ||
] | ||
) | ||
) | ||
) | ||
) | ||
[] | ||
] |
There was a problem hiding this comment.
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) []]
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.