-
Notifications
You must be signed in to change notification settings - Fork 6
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
replace toml to yaml #276
base: master
Are you sure you want to change the base?
replace toml to yaml #276
Changes from 5 commits
bf08551
e34fd57
1ee11fc
48a2a43
dc9c38c
0a4056d
7240f35
627affd
c2e82e1
7238f81
c77c8bd
f63c40e
ebd687b
56e93fc
129f99b
4ffe9bd
a1c4904
9757aa0
8c8f454
f109211
6a61a5a
ae753ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,6 @@ import NITTA.Synthesis (TargetSynthesis (..), mlScoreKeyPrefix, noSynthesis, sta | |
import NITTA.Synthesis.MlBackend.ServerInstance | ||
import NITTA.UIBackend | ||
import NITTA.UIBackend.Types (BackendCtx, mlBackendGetter, nodeScores, outputPath, receivedValues, root) | ||
import NITTA.Utils | ||
import Paths_nitta | ||
import System.Console.CmdArgs hiding (def) | ||
import System.Exit | ||
|
@@ -199,8 +198,6 @@ nittaArgs = | |
getNittaArgs :: IO Nitta | ||
getNittaArgs = cmdArgs nittaArgs | ||
|
||
fromConf toml s = getFromTomlSection s =<< toml | ||
|
||
main = do | ||
( Nitta | ||
filename | ||
|
@@ -229,10 +226,9 @@ main = do | |
-- force line buffering (always, not just when stdout is connected to a tty), | ||
-- it's critical for successful parsing of NITTA's stdout in python scripts | ||
hSetBuffering stdout LineBuffering | ||
|
||
toml <- case uarch of | ||
conf <- case uarch of | ||
Nothing -> return Nothing | ||
Just path -> Just . getToml <$> T.readFile path | ||
Just path -> Just <$> parseConfig path | ||
|
||
let exactFrontendType = identifyFrontendType filename frontend_language | ||
|
||
|
@@ -241,8 +237,8 @@ main = do | |
let frontendResult@FrontendResult{frDataFlow, frTrace, frPrettyLog} = | ||
translate exactFrontendType src | ||
received = [("u#0", map (\i -> read $ show $ sin ((2 :: Double) * 3.14 * 50 * 0.001 * i)) [0 .. toEnum n])] | ||
ioSync = fromJust $ io_sync <|> fromConf toml "ioSync" <|> Just Sync | ||
confMa = toml >>= Just . mkMicroarchitecture ioSync | ||
ioSync = fromJust $ io_sync <|> ioSync' <$> conf <|> Just Sync | ||
confMa = mkMicroarchitecture <$> conf | ||
ma :: BusNetwork T.Text T.Text (Attr (FX m b)) Int | ||
ma | ||
| auto_uarch && isJust confMa = | ||
|
@@ -302,7 +298,7 @@ main = do | |
exitSuccess | ||
) | ||
$ parseFX . fromJust | ||
$ type_ <|> fromConf toml "type" <|> Just "fx32.32" | ||
$ type_ <|> T.unpack . type' <$> conf <|> Just "fx32.32" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
parseFX input = | ||
let typePattern = mkRegex "fx([0-9]+).([0-9]+)" | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
type: fx32.32 | ||
ioSync: Sync | ||
networks: | ||
- name: net1 | ||
pus: | ||
- type: SPI | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can use name as key here? Do you see any disadvantages of this approuch? The same for the network |
||
name: spi | ||
mosi: mosi | ||
miso: miso | ||
sclk: sclk | ||
cs: cs | ||
isSlave: true | ||
bufferSize: 6 | ||
bounceFilter: 0 | ||
protos: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let move it to the top level as puLibrary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is is about all PUs, which nitta can allocate automatically. Current -- in network. Should be -- on the top level & network. |
||
- type: Fram | ||
name: fram{x} # If you want a PU can be allocated only once, remove {x} from the PU name. | ||
size: 32 | ||
- type: Shift | ||
name: shift{x} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you know what this |
||
sRight: true | ||
- type: Multiplier | ||
name: mul{x} | ||
mock: true | ||
- type: Accum | ||
name: accum{x} | ||
isInt: true | ||
- type: Divider | ||
name: div{x} | ||
mock: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will be nice to make possible to set this attr globally. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mock -- attr used for logic simulation via icarus verilog for complex PU, like divider. Usually, we don't need to specify it for PUs independently, so it will be nice to move it on the top level. |
||
pipeline: 4 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,7 @@ dependencies: | |
- data-default | ||
- filepath | ||
- ginger | ||
- htoml | ||
- yaml | ||
- intervals | ||
- mtl | ||
- prettyprinter | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,21 +3,27 @@ | |
{-# LANGUAGE PartialTypeSignatures #-} | ||
|
||
module NITTA.Model.Microarchitecture.Config ( | ||
MicroarchitectureConf (type', ioSync'), | ||
parseConfig, | ||
mkMicroarchitecture, | ||
) where | ||
|
||
import Data.Aeson ( | ||
FromJSON (parseJSON), | ||
Options (sumEncoding), | ||
SumEncoding (TaggedObject, contentsFieldName, tagFieldName), | ||
ToJSON (toJSON), | ||
defaultOptions, | ||
genericParseJSON, | ||
genericToJSON, | ||
) | ||
import Data.Default (Default (def)) | ||
import Data.HashMap.Internal.Strict (HashMap) | ||
import Data.Text qualified as T | ||
import Data.Yaml ( | ||
FromJSON (parseJSON), | ||
ToJSON (toJSON), | ||
Value (Object), | ||
decodeFileThrow, | ||
(.:), | ||
) | ||
import GHC.Generics (Generic) | ||
import NITTA.Intermediate.Value (Val) | ||
import NITTA.Intermediate.Variable (Var) | ||
|
@@ -30,7 +36,6 @@ import NITTA.Model.Networks.Bus ( | |
) | ||
import NITTA.Model.Networks.Types (IOSynchronization) | ||
import NITTA.Model.ProcessorUnits qualified as PU | ||
import NITTA.Utils (getFromToml) | ||
|
||
data PUConf | ||
= Accum | ||
|
@@ -86,16 +91,28 @@ data NetworkConf = NetworkConf | |
instance FromJSON NetworkConf | ||
instance ToJSON NetworkConf | ||
|
||
newtype MicroarchitectureConf = MicroarchitectureConf | ||
{ networks :: [NetworkConf] | ||
data MicroarchitectureConf = MicroarchitectureConf | ||
{ type' :: T.Text | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to name it like In the future, it is possible to make |
||
, ioSync' :: IOSynchronization | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same idea on |
||
, networks :: [NetworkConf] | ||
} | ||
deriving (Generic, Show) | ||
|
||
instance FromJSON MicroarchitectureConf | ||
instance FromJSON MicroarchitectureConf where | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to do it via Generic? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't work out ¯\_(ツ)_/¯ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strange. Maybe because you need to use HashMap instead of Map. |
||
parseJSON (Object v) = do | ||
type' <- v .: "type" | ||
ioSync' <- v .: "ioSync" | ||
networks <- v .: "networks" | ||
return MicroarchitectureConf{type' = type', ioSync' = ioSync', networks = networks} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
parseJSON v = fail $ show v | ||
instance ToJSON MicroarchitectureConf | ||
|
||
mkMicroarchitecture :: (Val v, Var x, ToJSON a, ToJSON x) => IOSynchronization -> HashMap T.Text a -> BusNetwork T.Text x v Int | ||
mkMicroarchitecture ioSync toml = | ||
parseConfig :: FilePath -> IO MicroarchitectureConf | ||
parseConfig path = do | ||
decodeFileThrow path :: IO MicroarchitectureConf | ||
|
||
mkMicroarchitecture :: (Val v, Var x, ToJSON x) => MicroarchitectureConf -> BusNetwork T.Text x v Int | ||
mkMicroarchitecture conf = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use record syntax here |
||
let addPU proto | ||
| proto = addCustomPrototype | ||
| otherwise = addCustom | ||
|
@@ -125,8 +142,8 @@ mkMicroarchitecture ioSync toml = | |
, master_sclk = PU.OutputPortTag sclk | ||
, master_cs = PU.OutputPortTag cs | ||
} | ||
nets = networks (getFromToml toml :: MicroarchitectureConf) | ||
mkNetwork net@NetworkConf{name} = modifyNetwork (busNetwork name ioSync) (build net) | ||
nets = networks conf | ||
mkNetwork net@NetworkConf{name} = modifyNetwork (busNetwork name $ ioSync' conf) (build net) | ||
in case nets of | ||
[n] -> mkNetwork n | ||
_ -> error "multi-networks are not currently supported" |
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.
Something like
parseConfig <$> path
should work?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.
parseConfig
is aFilePath -> IO MicroarchitectureConf
typepath
is aFilePath
type<$>
is a(a -> b) -> f a -> f b
typeThe result must be type of
IO Maybe MicroarchitectureConf
, soJust <$> parseConfig path
doesn't seem to be able to be simplified.