0 | {--
 1 | Copyright (C) 2024  Joel Berkeley
 2 |
 3 | This program is free software: you can redistribute it and/or modify
 4 | it under the terms of the GNU Affero General Public License as published
 5 | by the Free Software Foundation, either version 3 of the License, or
 6 | (at your option) any later version.
 7 |
 8 | This program is distributed in the hope that it will be useful,
 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 | GNU Affero General Public License for more details.
12 |
13 | You should have received a copy of the GNU Affero General Public License
14 | along with this program.  If not, see <https://www.gnu.org/licenses/>.
15 | --}
16 | ||| For internal spidr use only.
17 | module Compiler.Xla.PJRT.PjrtExecutable
18 |
19 | import Compiler.Xla.Client.ExecutableBuildOptions
20 |
21 | import Compiler.FFI
22 |
23 | ffi : String -> String
24 | ffi = libxla "c/xla/pjrt/pjrt_executable.h"
25 |
26 | export
27 | data CompileOptions = MkCompileOptions GCAnyPtr
28 |
29 | %foreign (ffi "CompileOptions_delete")
30 | prim__deleteCompileOptions : AnyPtr -> PrimIO ()
31 |
32 | %foreign (ffi "CompileOptions_new")
33 | prim__mkCompileOptions : AnyPtr -> PrimIO AnyPtr
34 |
35 | export
36 | mkCompileOptions : HasIO io => ExecutableBuildOptions -> io CompileOptions
37 | mkCompileOptions (MkExecutableBuildOptions executableBuildOptions) = do
38 |   options <- primIO $ prim__mkCompileOptions executableBuildOptions
39 |   options <- onCollectAny' options (primIO . prim__deleteCompileOptions)
40 |   pure (MkCompileOptions options)
41 |
42 | %foreign (ffi "CompileOptions_SerializeAsString")
43 | prim__compileOptionsSerializeAsString : GCAnyPtr -> PrimIO AnyPtr
44 |
45 | ||| It is up to the caller to `delete` the `CppString`.
46 | export
47 | serializeAsString : HasIO io => CompileOptions -> io CppString
48 | serializeAsString (MkCompileOptions options) = MkCppString <$> (
49 |     primIO $ prim__compileOptionsSerializeAsString options
50 |   )
51 |