Skip to content

Commit

Permalink
set -N from the juvix global options
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira committed May 24, 2024
1 parent f5ab7f8 commit 5e083b7
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 65 deletions.
2 changes: 1 addition & 1 deletion app/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ runPipelineOptions m = do
g <- askGlobalOptions
let opt =
defaultPipelineOptions
{ _pipelineNumJobs = g ^. globalNumJobs,
{ _pipelineNumThreads = g ^. globalNumThreads,
_pipelineUseColors = not (g ^. globalNoColors)
}
runReader opt m
Expand Down
22 changes: 11 additions & 11 deletions app/CommonOptions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,24 @@ parseInputFiles exts' = do
parseInputFile :: FileExt -> Parser (AppPath File)
parseInputFile = parseInputFiles . NonEmpty.singleton

numJobsOpt :: ReadM NumJobs
numJobsOpt = eitherReader aux
numThreadsOpt :: ReadM NumThreads
numThreadsOpt = eitherReader aux
where
aux :: String -> Either String NumJobs
aux :: String -> Either String NumThreads
aux s = do
i :: Int <- readEither s
mkNumJobs (Just i)
mkNumThreads (Just i)

parseNumJobs :: Parser NumJobs
parseNumJobs = do
parseNumThreads :: Parser NumThreads
parseNumThreads = do
option
numJobsOpt
( long "jobs"
<> short 'j'
numThreadsOpt
( long "threads"
<> short 'N'
<> metavar "JOBS"
<> value defaultNumJobs
<> value defaultNumThreads
<> showDefault
<> help "Number of concurrent jobs to run"
<> help "Number of physical threads to run"
<> completer (listCompleter [Juvix.show j | j <- [1 .. numCapabilities]])
)

Expand Down
6 changes: 3 additions & 3 deletions app/GlobalOptions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ data GlobalOptions = GlobalOptions
_globalNoCoverage :: Bool,
_globalNoStdlib :: Bool,
_globalUnrollLimit :: Int,
_globalNumJobs :: NumJobs,
_globalNumThreads :: NumThreads,
_globalFieldSize :: Maybe Natural,
_globalOffline :: Bool
}
Expand Down Expand Up @@ -58,7 +58,7 @@ defaultGlobalOptions :: GlobalOptions
defaultGlobalOptions =
GlobalOptions
{ _globalNoColors = False,
_globalNumJobs = defaultNumJobs,
_globalNumThreads = defaultNumThreads,
_globalShowNameIds = False,
_globalOnlyErrors = False,
_globalNoTermination = False,
Expand Down Expand Up @@ -142,7 +142,7 @@ parseGlobalFlags = do
( long "show-name-ids"
<> help "[DEV] Show the unique number of each identifier when pretty printing"
)
_globalNumJobs <- parseNumJobs
_globalNumThreads <- parseNumThreads
return GlobalOptions {..}

parseBuildDir :: Mod OptionFields (Prepath Dir) -> Parser (AppPath Dir)
Expand Down
2 changes: 2 additions & 0 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Main (main) where
import App
import CommonOptions
import Data.String.Interpolate (i)
import GHC.Conc qualified as GHC
import GlobalOptions
import Juvix.Compiler.Pipeline.Root
import TopCommand
Expand All @@ -13,6 +14,7 @@ main = do
let parserPreferences = prefs showHelpOnEmpty
invokeDir <- getCurrentDir
(_runAppIOArgsGlobalOptions, cli) <- customExecParser parserPreferences descr
GHC.setNumCapabilities (numThreads (_runAppIOArgsGlobalOptions ^. globalNumThreads))
mbuildDir <- mapM (prepathToAbsDir invokeDir) (_runAppIOArgsGlobalOptions ^? globalBuildDir . _Just . pathPath)
mainFile <- topCommandInputPath cli
mapM_ checkMainFile mainFile
Expand Down
3 changes: 2 additions & 1 deletion package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ executables:
- polysemy == 1.9.*
verbatim:
default-language: GHC2021

juvix:
main: Main.hs
source-dirs: app
Expand All @@ -193,6 +192,8 @@ executables:
- string-interpolate == 0.3.*
verbatim:
default-language: GHC2021
ghc-options:
- -threaded
when:
- condition: flag(static)
ld-options:
Expand Down
6 changes: 3 additions & 3 deletions src/Juvix/Compiler/Pipeline/DriverParallel.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ compileInParallel ::
]
r
) =>
NumJobs ->
NumThreads ->
Sem r ()
compileInParallel nj = do
t <- ask
Expand All @@ -95,7 +95,7 @@ compileInParallel nj = do
{ _compileArgsNodesIndex = idx,
_compileArgsNodeName = getNodeName,
_compileArgsDependencies = mkDependencies t,
_compileArgsNumWorkers = numJobs nj,
_compileArgsNumWorkers = numThreads nj,
_compileArgsCompileNode = compileNode
}
void (compile args)
Expand Down Expand Up @@ -137,7 +137,7 @@ evalModuleInfoCache ::
]
r
) =>
NumJobs ->
NumThreads ->
Sem (ModuleInfoCache ': r) a ->
Sem r a
evalModuleInfoCache nj m = do
Expand Down
4 changes: 2 additions & 2 deletions src/Juvix/Compiler/Pipeline/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Juvix.Prelude
data PipelineOptions = PipelineOptions
{ _pipelineImportStrategy :: ImportScanStrategy,
_pipelineDependenciesConfig :: DependenciesConfig,
_pipelineNumJobs :: NumJobs,
_pipelineNumThreads :: NumThreads,
_pipelineUseColors :: Bool
}

Expand All @@ -17,5 +17,5 @@ defaultPipelineOptions =
{ _pipelineImportStrategy = defaultImportScanStrategy,
_pipelineDependenciesConfig = defaultDependenciesConfig,
_pipelineUseColors = True,
_pipelineNumJobs = defaultNumJobs
_pipelineNumThreads = defaultNumThreads
}
6 changes: 3 additions & 3 deletions src/Juvix/Compiler/Pipeline/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ runIOEitherPipeline' entry a = do
. runTopModuleNameChecker
. runReader (opts ^. pipelineImportStrategy)
. withImportTree (entry ^. entryPointModulePath)
. evalModuleInfoCacheHelper (opts ^. pipelineNumJobs)
. evalModuleInfoCacheHelper (opts ^. pipelineNumThreads)
$ a

evalModuleInfoCacheHelper ::
Expand All @@ -153,7 +153,7 @@ evalModuleInfoCacheHelper ::
]
r
) =>
NumJobs ->
NumThreads ->
Sem (ModuleInfoCache ': r) a ->
Sem r a
evalModuleInfoCacheHelper nj m = do
Expand Down Expand Up @@ -235,7 +235,7 @@ runReplPipelineIOEither' lockMode entry = do
. runReader defaultImportScanStrategy
. withImportTree (entry ^. entryPointModulePath)
. ignoreProgressLog
. evalModuleInfoCacheHelper defaultNumJobs
. evalModuleInfoCacheHelper defaultNumThreads
$ processFileToStoredCore entry
return $ case eith of
Left err -> Left err
Expand Down
4 changes: 2 additions & 2 deletions src/Juvix/Data.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Juvix.Data
( module Juvix.Data.Effect,
module Juvix.Data.Error,
module Juvix.Data.NumJobs,
module Juvix.Data.NumThreads,
module Juvix.Data.Fixity,
module Juvix.Data.FileExt,
module Juvix.Data.Hole,
Expand Down Expand Up @@ -34,7 +34,7 @@ import Juvix.Data.Irrelevant
import Juvix.Data.IsImplicit
import Juvix.Data.Loc
import Juvix.Data.NameId qualified
import Juvix.Data.NumJobs
import Juvix.Data.NumThreads
import Juvix.Data.Pragmas
import Juvix.Data.Processed
import Juvix.Data.Uid
Expand Down
39 changes: 0 additions & 39 deletions src/Juvix/Data/NumJobs.hs

This file was deleted.

39 changes: 39 additions & 0 deletions src/Juvix/Data/NumThreads.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module Juvix.Data.NumThreads
( NumThreads,
defaultNumThreads,
numThreadsOne,
numThreads,
mkNumThreads,
mkNumThreads',
)
where

import GHC.Conc
import Juvix.Prelude.Base.Foundation
import Prelude qualified

-- | The number of jobs must be at least 1
newtype NumThreads = NumThreads Int
deriving stock (Eq, Ord, Generic)

instance Show NumThreads where
show (NumThreads i) = show i

numThreadsOne :: NumThreads
numThreadsOne = NumThreads 1

numThreads :: NumThreads -> Int
numThreads (NumThreads i) = i

defaultNumThreads :: NumThreads
defaultNumThreads = NumThreads (max 1 (numCapabilities - 2))

mkNumThreads :: Maybe Int -> Either String NumThreads
mkNumThreads = \case
Nothing -> Right defaultNumThreads
Just n
| n >= 1 -> return (NumThreads n)
| otherwise -> Left "The number of jobs cannot be negative"

mkNumThreads' :: Maybe Int -> NumThreads
mkNumThreads' = either (error . pack) id . mkNumThreads

0 comments on commit 5e083b7

Please sign in to comment.