diff options
author | Tom Smeding <t.j.smeding@uu.nl> | 2025-03-03 17:34:16 +0100 |
---|---|---|
committer | Tom Smeding <t.j.smeding@uu.nl> | 2025-03-03 17:34:16 +0100 |
commit | cabd95c691e7bf0bf5adb4609e6df2a10b08856c (patch) | |
tree | 0a9216f89afd28614940dae940a86334b41e5572 /src | |
parent | e34869318cd37fa73c12291141a5fea29248aede (diff) |
Run test primals with Compile (not all succeed yet)
Diffstat (limited to 'src')
-rw-r--r-- | src/Compile.hs | 2 | ||||
-rw-r--r-- | src/Compile/Exec.hs | 14 |
2 files changed, 12 insertions, 4 deletions
diff --git a/src/Compile.hs b/src/Compile.hs index 4c07f3a..d31c531 100644 --- a/src/Compile.hs +++ b/src/Compile.hs @@ -48,7 +48,7 @@ compile :: SList STy env -> Ex env t -> IO (SList Value env -> IO (Rep t)) compile = \env expr -> do let source = compileToString env expr - hPutStrLn stderr $ "Generated C source: <<<\n\x1B[2m" ++ source ++ "\x1B[0m>>>" + -- hPutStrLn stderr $ "Generated C source: <<<\n\x1B[2m" ++ source ++ "\x1B[0m>>>" lib <- buildKernel source ["kernel"] let arg_metrics = reverse (unSList metricsSTy env) diff --git a/src/Compile/Exec.hs b/src/Compile/Exec.hs index 487ed8a..83ce4ff 100644 --- a/src/Compile/Exec.hs +++ b/src/Compile/Exec.hs @@ -6,6 +6,7 @@ module Compile.Exec ( callKernelFun, ) where +import Control.Monad (when) import Data.IORef import qualified Data.Map.Strict as Map import Data.Map.Strict (Map) @@ -20,6 +21,9 @@ import System.Posix.Temp (mkdtemp) import System.Process (readProcess) +debug :: Bool +debug = False + -- The IORef wrapper is required for the finalizer to attach properly (see the 'Weak' docs) data KernelLib = KernelLib !(IORef (Map String (FunPtr (Ptr () -> IO ())))) @@ -29,11 +33,15 @@ buildKernel csource funnames = do path <- mkdtemp template let outso = path ++ "/out.so" - let args = ["-O3", "-march=native", "-shared", "-fPIC", "-std=c99", "-x", "c", "-o", outso, "-", "-Wall", "-Wextra", "-Wno-unused-parameter"] + let args = ["-O3", "-march=native" + ,"-shared", "-fPIC" + ,"-std=c99", "-x", "c" + ,"-o", outso, "-" + ,"-Wall", "-Wextra", "-Wno-unused-variable", "-Wno-unused-parameter"] _ <- readProcess "gcc" args csource numLoaded <- atomicModifyIORef' numLoadedCounter (\n -> (n+1, n+1)) - hPutStrLn stderr $ "[chad] loading kernel " ++ path ++ " (" ++ show numLoaded ++ " total)" + when debug $ hPutStrLn stderr $ "[chad] loading kernel " ++ path ++ " (" ++ show numLoaded ++ " total)" dl <- dlopen outso [RTLD_LAZY, RTLD_LOCAL] removeDirectoryRecursive path -- we keep a reference anyway because we have the file open now @@ -41,7 +49,7 @@ buildKernel csource funnames = do ptrs <- Map.fromList <$> sequence [(name,) <$> dlsym dl name | name <- funnames] ref <- newIORef ptrs _ <- mkWeakIORef ref (do numLeft <- atomicModifyIORef' numLoadedCounter (\n -> (n-1, n-1)) - hPutStrLn stderr $ "[chad] unloading kernel " ++ path ++ " (" ++ show numLeft ++ " left)" + when debug $ hPutStrLn stderr $ "[chad] unloading kernel " ++ path ++ " (" ++ show numLeft ++ " left)" dlclose dl) return (KernelLib ref) |