{-# LANGUAGE FlexibleContexts #-}
module Futhark.CLI.PyOpenCL (main) where
import Control.Monad.IO.Class
import qualified Futhark.CodeGen.Backends.PyOpenCL as PyOpenCL
import Futhark.Compiler.CLI
import Futhark.Passes
import System.Directory
import System.FilePath
main :: String -> [String] -> IO ()
main :: String -> [String] -> IO ()
main = ()
-> [CompilerOption ()]
-> String
-> String
-> Pipeline SOACS KernelsMem
-> (FutharkConfig
-> () -> CompilerMode -> String -> Prog KernelsMem -> FutharkM ())
-> String
-> [String]
-> IO ()
forall cfg lore.
cfg
-> [CompilerOption cfg]
-> String
-> String
-> Pipeline SOACS lore
-> (FutharkConfig
-> cfg -> CompilerMode -> String -> Prog lore -> FutharkM ())
-> String
-> [String]
-> IO ()
compilerMain
()
[]
String
"Compile PyOpenCL"
String
"Generate Python + OpenCL code from optimised Futhark program."
Pipeline SOACS KernelsMem
gpuPipeline
((FutharkConfig
-> () -> CompilerMode -> String -> Prog KernelsMem -> FutharkM ())
-> String -> [String] -> IO ())
-> (FutharkConfig
-> () -> CompilerMode -> String -> Prog KernelsMem -> FutharkM ())
-> String
-> [String]
-> IO ()
forall a b. (a -> b) -> a -> b
$ \FutharkConfig
fcfg () CompilerMode
mode String
outpath Prog KernelsMem
prog -> do
let class_name :: String
class_name =
case CompilerMode
mode of
CompilerMode
ToLibrary -> String -> String
takeBaseName String
outpath
CompilerMode
_ -> String
"internal"
String
pyprog <- FutharkConfig -> FutharkM (Warnings, String) -> FutharkM String
forall a. FutharkConfig -> FutharkM (Warnings, a) -> FutharkM a
handleWarnings FutharkConfig
fcfg (FutharkM (Warnings, String) -> FutharkM String)
-> FutharkM (Warnings, String) -> FutharkM String
forall a b. (a -> b) -> a -> b
$ CompilerMode
-> String -> Prog KernelsMem -> FutharkM (Warnings, String)
forall (m :: * -> *).
MonadFreshNames m =>
CompilerMode -> String -> Prog KernelsMem -> m (Warnings, String)
PyOpenCL.compileProg CompilerMode
mode String
class_name Prog KernelsMem
prog
case CompilerMode
mode of
CompilerMode
ToLibrary ->
IO () -> FutharkM ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> FutharkM ()) -> IO () -> FutharkM ()
forall a b. (a -> b) -> a -> b
$ String -> String -> IO ()
writeFile (String
outpath String -> String -> String
`addExtension` String
"py") String
pyprog
CompilerMode
_ -> IO () -> FutharkM ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> FutharkM ()) -> IO () -> FutharkM ()
forall a b. (a -> b) -> a -> b
$ do
String -> String -> IO ()
writeFile String
outpath String
pyprog
Permissions
perms <- IO Permissions -> IO Permissions
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Permissions -> IO Permissions)
-> IO Permissions -> IO Permissions
forall a b. (a -> b) -> a -> b
$ String -> IO Permissions
getPermissions String
outpath
String -> Permissions -> IO ()
setPermissions String
outpath (Permissions -> IO ()) -> Permissions -> IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> Permissions -> Permissions
setOwnerExecutable Bool
True Permissions
perms