@@ -17,16 +17,16 @@ export native_code_llvm, native_code_typed, native_llvm_module
1717
1818Statically compile the method of a function `f` specialized to arguments of the type given by `types`.
1919
20- This will create a directory at the specified path with a shared object file (i.e. a `.so` or `.dylib`),
21- and will save a `LazyStaticCompiledFunction` object in the same directory with the extension `.cjl`. This
22- `LazyStaticCompiledFunction` can be deserialized with `load_function( path)`. Once it is instantiated in
23- a julia session, it will be of type `StaticCompiledFunction` and may be called with arguments of type
24- `types` as if it were a function with a single method (the method determined by `types`) .
20+ This will create a directory at the specified path (or in a temporary directory if you exclude that argument)
21+ that contains the files needed for your static compiled function. `compile` will return a
22+ `StaticCompiledFunction` object and `obj_path` which is the absolute path of the directory containing the
23+ compilation artifacts. The `StaticCompiledFunction` can be treated as if it is a function with a single
24+ method corresponding to the types you specified when it was compiled .
2525
26- `compile` will return an already instantiated `StaticCompiledFunction` object and `obj_path` which is the
27- location of the directory containing the compilation artifacts .
26+ To deserialize and instantiate a previously compiled function, simply execute `load_function(path)`, which
27+ returns a callable `StaticCompiledFunction` .
2828
29- ### Examples :
29+ ### Example :
3030
3131Define and compile a `fib` function:
3232```julia
@@ -43,18 +43,39 @@ julia> fib_compiled(10)
4343```
4444Now we can quit this session and load a new one where `fib` is not defined:
4545```julia
46- julia> using StaticCompiler
47-
4846julia> fib
4947ERROR: UndefVarError: fib not defined
5048
49+ julia> using StaticCompiler
50+
5151julia> fib_compiled = load_function("fib.cjl")
5252fib(::Int64) :: Int64
5353
5454julia> fib_compiled(10)
555555
5656```
5757Tada!
58+
59+ ### Details:
60+
61+ Here is the structure of the directory created by `compile` in the above example:
62+ ```julia
63+ shell> tree fib
64+ path
65+ ├── obj.cjl
66+ ├── obj.o
67+ └── obj.so
68+
69+ 0 directories, 3 files
70+ ````
71+ * `obj.so` (or `.dylib` on MacOS) is a shared object file that can be linked to in order to execute your
72+ compiled julia function.
73+ * `obj.cjl` is a serialized `LazyStaticCompiledFunction` object which will be deserialized and instantiated
74+ with `load_function(path)`. `LazyStaticcompiledfunction`s contain the requisite information needed to link to the
75+ `obj.so` inside a julia session. Once it is instantiated in a julia session (i.e. by
76+ `instantiate(::LazyStaticCompiledFunction)`, this happens automatically in `load_function`), it will be of type
77+ `StaticCompiledFunction` and may be called with arguments of type `types` as if it were a function with a
78+ single method (the method determined by `types`).
5879"""
5980function compile (f, _tt, path:: String = tempname (); name = GPUCompiler. safe_name (repr (f)), kwargs... )
6081 tt = Base. to_tuple_type (_tt)
@@ -76,7 +97,6 @@ function compile(f, _tt, path::String = tempname(); name = GPUCompiler.safe_nam
7697 (; f = instantiate (lf), path= abspath (path))
7798end
7899
79-
80100"""
81101 load_function(path) --> compiled_f
82102
@@ -164,8 +184,8 @@ julia> path, name = StaticCompiler.generate_shlib(test, Tuple{Int64}, "./test")
164184
165185shell> tree \$ path
166186./test
167- |-- obj.bc
168- `-- obj.dylib
187+ |-- obj.o
188+ `-- obj.so
169189
1701900 directories, 2 files
171191
0 commit comments