Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,13 @@ class FutharkLexer(RegexLexer):
[],
1,
),
(
"man/futhark-eval",
"futhark-eval",
"execute Futhark expression",
[],
1,
),
(
"man/futhark-script",
"futhark-script",
Expand Down
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ the `development blog <https://futhark-lang.org/blog.html>`_.
man/futhark-cuda.rst
man/futhark-dataset.rst
man/futhark-doc.rst
man/futhark-eval.rst
man/futhark-fmt.rst
man/futhark-hip.rst
man/futhark-ispc.rst
man/futhark-literate.rst
man/futhark-lsp.rst
man/futhark-script.rst
man/futhark-multicore.rst
man/futhark-opencl.rst
man/futhark-pkg.rst
Expand All @@ -65,6 +65,7 @@ the `development blog <https://futhark-lang.org/blog.html>`_.
man/futhark-python.rst
man/futhark-repl.rst
man/futhark-run.rst
man/futhark-script.rst
man/futhark-test.rst
man/futhark-wasm-multicore.rst
man/futhark-wasm.rst
Expand Down
69 changes: 69 additions & 0 deletions docs/man/futhark-eval.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
.. role:: ref(emphasis)

.. _futhark-eval(1):

================
futhark-eval
================

SYNOPSIS
========

futhark eval [options...] expression

DESCRIPTION
===========

This command executes Futhark expressions through the interpreter and prints
their results to stdout. You can provide a ``.fut`` file with definitions that
are then accessible in the expression.

Further, if you pass ``--backend``, the file will be compiled with the given
compiler backend, and any references to entry points in the evaluation
expression will be handled by compiled code. This is the main purpose of
``futhark eval``: it allows convenient invocation of Futhark entry points
without having to recompile.

The expression itself is not compiled, so it is best to put as much of the heavy
work as possible into the entry points provided in the ``.fut`` file. Also,
beware: while the expression can access any definition in the file, only the
ones explicitly declared as entry points will be compiled and run fast. All
other definitions will be executed in interpreted mode.

OPTIONS
=======

--backend=name

The backend used when compiling Futhark programs (without leading ``futhark``,
e.g. just ``opencl``). Defaults to no backend, meaning purely interpreted.

-f, --file=FILE

Evaluate expressions in the context of this file.

--futhark=program

The program used to perform operations (eg. compilation). Defaults
to the binary running ``futhark eval`` itself.

--pass-option=opt

Pass an option to benchmark programs that are being run. For
example, we might want to run OpenCL programs on a specific device::

futhark eval prog.fut --backend=opencl --pass-option=-dHawaii

--pass-compiler-option=opt

Pass an extra option to the compiler when compiling the programs.

--skip-compilation

Do not run the compiler, and instead assume that the program has
already been compiled. Use with caution.

SEE ALSO
========

:ref:`futhark-literate(1)`, :ref:`futhark-test(1)`, :ref:`futhark-bench(1)`
6 changes: 0 additions & 6 deletions docs/man/futhark.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ A Futhark compiler development command, intentionally undocumented and
intended for use in developing the Futhark compiler, not for
programmers writing in Futhark.

futhark eval [-f FILE] [-w] <exprs...>
--------------------------------------

Evaluates expressions given as command-line arguments. Optionally
allows a file import using ``-f``.

futhark hash PROGRAM
--------------------

Expand Down
13 changes: 12 additions & 1 deletion futhark.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,17 @@ library
Language.Futhark.Core
Language.Futhark.Interpreter
Language.Futhark.Interpreter.AD
Language.Futhark.Interpreter.FFI
Language.Futhark.Interpreter.FFI.Server
Language.Futhark.Interpreter.FFI.Server.Explorer
Language.Futhark.Interpreter.FFI.Server.Interface
Language.Futhark.Interpreter.FFI.Server.Packer
Language.Futhark.Interpreter.FFI.Server.TypeLayout
Language.Futhark.Interpreter.FFI.UIDs
Language.Futhark.Interpreter.FFI.Util.BiMap
Language.Futhark.Interpreter.FFI.Util.NDArray
Language.Futhark.Interpreter.FFI.Util.UID
Language.Futhark.Interpreter.FFI.Values
Language.Futhark.Interpreter.Values
Language.Futhark.FreeVars
Language.Futhark.Parser
Expand Down Expand Up @@ -477,7 +488,7 @@ library
, file-embed >=0.0.14.0
, filepath >=1.4.1.1
, free >=5.1.10
, futhark-data >= 1.1.3.0
, futhark-data >= 1.1.4.0
, futhark-server >= 1.3.3.0
, futhark-manifest == 1.7.0.0
, githash >=0.1.6.1
Expand Down
4 changes: 2 additions & 2 deletions nix/futhark-data.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
}:
mkDerivation {
pname = "futhark-data";
version = "1.1.3.0";
sha256 = "a3a274bfa9f2bf9df30e8f5a23a9243726c1c82502bcaee53e2a347e0697c9be";
version = "1.1.4.0";
sha256 = "137733709a6e360e6f8f5b376b68bc13d026c4c9737b4efc56ed77a50e18f0fa";
libraryHaskellDepends = [
base binary bytestring bytestring-to-vector containers half
megaparsec mtl scientific text vector vector-binary-instances
Expand Down
56 changes: 44 additions & 12 deletions src/Futhark/CLI/Eval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import Control.Monad
import Data.Map qualified as M
import Data.Text qualified as T
import Futhark.Eval
( InterpreterConfig (..),
interpreterConfig,
( EvalConfig (..),
evalConfig,
newFutharkiState,
runExpr,
)
Expand All @@ -27,37 +27,69 @@ import System.IO (stderr)

-- | Run @futhark eval@.
main :: String -> [String] -> IO ()
main = mainWithOptions interpreterConfig options "options... <exprs...>" run
main = mainWithOptions evalConfig options "options... <exprs...>" run
where
run [] _ = Nothing
run exprs config = Just $ runExprs exprs config

runExprs :: [String] -> InterpreterConfig -> IO ()
runExprs :: [String] -> EvalConfig -> IO ()
runExprs exprs cfg = do
let InterpreterConfig _ file = cfg
maybe_new_state <- newFutharkiState cfg file M.empty
maybe_new_state <- newFutharkiState cfg M.empty
interpreter_state <- case maybe_new_state of
Left reason -> do
hPutDocLn stderr reason
exitWith $ ExitFailure 2
Right s -> pure s
forM_ exprs $ \expr -> putDocLn =<< runExpr interpreter_state (T.pack expr)

options :: [FunOptDescr InterpreterConfig]
options :: [FunOptDescr EvalConfig]
options =
[ Option
"f"
["file"]
( ReqArg
( \entry -> Right $ \config ->
config {interpreterFile = Just entry}
)
(\entry -> Right $ \config -> config {evalFile = Just entry})
"NAME"
)
"The file to load before evaluating expressions.",
Option
"w"
["no-warnings"]
(NoArg $ Right $ \config -> config {interpreterPrintWarnings = False})
"Do not print warnings."
(NoArg $ Right $ \config -> config {evalPrintWarnings = False})
"Do not print warnings.",
Option
"p"
["pass-option"]
( ReqArg
( \opt ->
Right $ \config ->
config {evalExtraOptions = opt : evalExtraOptions config}
)
"OPT"
)
"Pass this option to programs being run.",
Option
[]
["pass-compiler-option"]
( ReqArg
( \opt ->
Right $ \config ->
config {evalCompilerOptions = opt : evalCompilerOptions config}
)
"OPT"
)
"Pass this option to the compiler.",
Option
""
["skip-compilation"]
(NoArg $ Right $ \config -> config {evalSkipCompilation = True})
"Use already compiled server-mode program.",
Option
[]
["backend"]
( ReqArg
(\backend -> Right $ \config -> config {evalBackend = Just backend})
"BACKEND"
)
"The compiler backend used (defaults to interpreted)."
]
4 changes: 4 additions & 0 deletions src/Futhark/CLI/REPL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ breakForReason s top _ =
runInterpreter :: F I.ExtOp a -> FutharkiM (Either I.InterpreterError a)
runInterpreter m = runF m (pure . Right) intOp
where
intOp (I.ExtOpCall {}) = error "Unexpected ExtOpCall"
intOp (I.ExtOpRealize {}) = error "Unexpected ExtOpRealize"
intOp (I.ExtOpError err) =
pure $ Left err
intOp (I.ExtOpTrace w v c) = do
Expand Down Expand Up @@ -365,6 +367,8 @@ runInterpreter m = runF m (pure . Right) intOp
runInterpreterNoBreak :: (MonadIO m) => F I.ExtOp a -> m (Either I.InterpreterError a)
runInterpreterNoBreak m = runF m (pure . Right) intOp
where
intOp (I.ExtOpCall {}) = error "Unexpected ExtOpCall"
intOp (I.ExtOpRealize {}) = error "Unexpected ExtOpRealize"
intOp (I.ExtOpError err) = pure $ Left err
intOp (I.ExtOpTrace w v c) = do
liftIO $ putDocLn $ pretty w <> ":" <+> align (unAnnotate v)
Expand Down
2 changes: 2 additions & 0 deletions src/Futhark/CLI/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ newFutharkiState cfg file = runExceptT $ do
runInterpreter' :: (MonadIO m) => F I.ExtOp a -> m (Either I.InterpreterError a)
runInterpreter' m = runF m (pure . Right) intOp
where
intOp (I.ExtOpCall {}) = error "Unexpected ExtOpCall"
intOp (I.ExtOpRealize {}) = error "Unexpected ExtOpRealize"
intOp (I.ExtOpError err) = pure $ Left err
intOp (I.ExtOpTrace w v c) = do
liftIO $ hPutDocLn stderr $ pretty w <> ":" <+> align (unAnnotate v)
Expand Down
Loading
Loading