source_file
package_clause
package "package"
package_identifier "ggml"
comment "// #cgo CPPFLAGS: -I${SRCDIR}/ggml/include"
comment "// #include <stdlib.h>"
comment "// #include <stdint.h>"
comment "// #include \"ggml.h\""
comment "// #include \"ggml-cpu.h\""
comment "// #include \"ggml-backend.h\""
import_declaration
import "import"
import_spec
interpreted_string_literal
" "\""
interpreted_string_literal_content "C"
" "\""
import_declaration (+112 nodes collapsed)
function_declaration (+98 nodes collapsed)
type_declaration (+135 nodes collapsed)
function_declaration
func "func"
identifier "New"
parameter_list
( "("
parameter_declaration
identifier "modelPath"
type_identifier "string"
, ","
parameter_declaration
identifier "params"
qualified_type
package_identifier "ml"
. "."
type_identifier "BackendParams"
) ")"
parameter_list
( "("
parameter_declaration
qualified_type
package_identifier "ml"
. "."
type_identifier "Backend"
, ","
parameter_declaration
type_identifier "error"
) ")"
block
{ "{"
statement_list
short_var_declaration
expression_list
identifier "r"
, ","
identifier "err"
:= ":="
expression_list
call_expression
selector_expression
identifier "os"
. "."
field_identifier "Open"
argument_list
( "("
identifier "modelPath"
) ")"
if_statement
if "if"
binary_expression
identifier "err"
!= "!="
nil "nil"
block
{ "{"
statement_list
return_statement
return "return"
expression_list
nil "nil"
, ","
identifier "err"
} "}"
defer_statement
defer "defer"
call_expression
selector_expression
identifier "r"
. "."
field_identifier "Close"
argument_list
( "("
) ")"
short_var_declaration
expression_list
identifier "meta"
, ","
identifier "err"
:= ":="
expression_list
call_expression
selector_expression
identifier "fsggml"
. "."
field_identifier "Decode"
argument_list
( "("
identifier "r"
, ","
unary_expression
- "-"
int_literal "1"
) ")"
if_statement
if "if"
binary_expression
identifier "err"
!= "!="
nil "nil"
block
{ "{"
statement_list
return_statement
return "return"
expression_list
nil "nil"
, ","
identifier "err"
} "}"
expression_statement (+150 nodes collapsed)
var_declaration
var "var"
var_spec
identifier "requiredMemory"
qualified_type
package_identifier "ml"
. "."
type_identifier "BackendMemory"
short_var_declaration (+26 nodes collapsed)
type_declaration (+28 nodes collapsed)
var_declaration
var "var"
var_spec
identifier "cpus"
, ","
identifier "accels"
, ","
identifier "gpus"
slice_type
[ "["
] "]"
pointer_type
* "*"
qualified_type
package_identifier "C"
. "."
type_identifier "struct_ggml_backend_device"
for_statement (+113 nodes collapsed)
short_var_declaration (+25 nodes collapsed)
comment "// create list of buffer types for the cpu"
short_var_declaration (+27 nodes collapsed)
for_statement (+109 nodes collapsed)
assignment_statement (+31 nodes collapsed)
var_declaration
var "var"
var_spec
identifier "props"
qualified_type
package_identifier "C"
. "."
type_identifier "struct_ggml_backend_dev_props"
expression_statement
call_expression
selector_expression
identifier "C"
. "."
field_identifier "ggml_backend_dev_get_props"
argument_list
( "("
selector_expression
identifier "cpuDeviceBufferType"
. "."
field_identifier "d"
, ","
unary_expression
& "&"
identifier "props"
) ")"
assignment_statement all 23:1
expression_list all 23:1
selector_expression all 23:1
selector_expression all 23:1
identifier "requiredMemory" all 23:1
. "." all 23:1
field_identifier "CPU" all 23:1
. "." all 23:1
field_identifier "UUID" all 23:1
= "=" all 23:1
expression_list all 23:1
call_expression all 23:1
selector_expression all 23:1
identifier "C" all 23:1
. "." all 23:1
field_identifier "GoString" all 23:1
argument_list all 23:1
( "(" all 23:1
selector_expression all 23:1
identifier "props" all 23:1
. "." all 23:1
field_identifier "uuid" all 23:1
) ")" all 23:1
assignment_statement (+28 nodes collapsed)
assignment_statement (+28 nodes collapsed)
comment "// create list of buffer types for each gpu"
var_declaration
var "var"
var_spec
identifier "gpuDeviceBufferTypes"
slice_type
[ "["
] "]"
type_identifier "deviceBufferType"
assignment_statement (+27 nodes collapsed)
for_statement
for "for"
range_clause
expression_list
identifier "i"
, ","
identifier "d"
:= ":="
range "range"
identifier "gpus"
block
{ "{"
statement_list
short_var_declaration
expression_list
identifier "bt"
:= ":="
expression_list
call_expression
selector_expression
identifier "C"
. "."
field_identifier "ggml_backend_dev_buffer_type"
argument_list
( "("
identifier "d"
) ")"
assignment_statement (+57 nodes collapsed)
assignment_statement
expression_list
index_expression
identifier "btDeviceMemory"
[ "["
identifier "bt"
] "]"
= "="
expression_list
unary_expression
& "&"
index_expression
selector_expression
identifier "requiredMemory"
. "."
field_identifier "GPUs"
[ "["
identifier "i"
] "]"
assignment_statement (+32 nodes collapsed)
var_declaration
var "var"
var_spec
identifier "props"
qualified_type
package_identifier "C"
. "."
type_identifier "struct_ggml_backend_dev_props"
expression_statement
call_expression
selector_expression
identifier "C"
. "."
field_identifier "ggml_backend_dev_get_props"
argument_list
( "("
identifier "d"
, ","
unary_expression
& "&"
identifier "props"
) ")"
assignment_statement all 27:1
expression_list all 27:1
selector_expression all 27:1
index_expression all 27:1
selector_expression all 27:1
identifier "requiredMemory" all 27:1
. "." all 27:1
field_identifier "GPUs" all 27:1
[ "[" all 27:1
identifier "i" all 27:1
] "]" all 27:1
. "." all 27:1
field_identifier "UUID" all 27:1
= "=" all 27:1
expression_list all 27:1
call_expression all 27:1
selector_expression all 27:1
identifier "C" all 27:1
. "." all 27:1
field_identifier "GoString" all 27:1
argument_list all 27:1
( "(" all 27:1
selector_expression all 27:1
identifier "props" all 27:1
. "." all 27:1
field_identifier "uuid" all 27:1
) ")" all 27:1
assignment_statement (+32 nodes collapsed)
assignment_statement (+32 nodes collapsed)
} "}"
short_var_declaration
expression_list
identifier "useDefaultSplit"
:= ":="
expression_list
true "true"
for_statement (+35 nodes collapsed)
comment "// calculate splits"
short_var_declaration (+21 nodes collapsed)
if_statement (+81 nodes collapsed)
var_declaration
var "var"
var_spec
identifier "sum"
type_identifier "float32"
comment "// cumulative sum of all splits"
for_statement (+32 nodes collapsed)
comment "// normalize splits"
for_statement (+22 nodes collapsed)
comment "// inputs always use cpu"
short_var_declaration
expression_list
identifier "input"
:= ":="
expression_list
identifier "cpuDeviceBufferType"
comment "// define a range of gpu layers. anything outside of this ra"...
short_var_declaration
expression_list
identifier "gpuRangeStart"
:= ":="
expression_list
call_expression
identifier "max"
argument_list
( "("
int_literal "0"
, ","
binary_expression
identifier "blocks"
- "-"
selector_expression
identifier "params"
. "."
field_identifier "NumGPULayers"
) ")"
short_var_declaration (+22 nodes collapsed)
short_var_declaration (+125 nodes collapsed)
comment "// repeating layers are assigned based on their index in rev"...
short_var_declaration
expression_list
identifier "layers"
:= ":="
expression_list
call_expression
identifier "make"
argument_list
( "("
slice_type
[ "["
] "]"
type_identifier "deviceBufferType"
, ","
identifier "blocks"
) ")"
for_statement (+27 nodes collapsed)
comment "// outputs are assigned iff allowed by splits and configured"...
short_var_declaration
expression_list
identifier "output"
:= ":="
expression_list
call_expression
identifier "assignLayer"
argument_list
( "("
identifier "blocks"
) ")"
short_var_declaration (+25 nodes collapsed)
assignment_statement
expression_list
identifier "maxTensors"
+= "+="
expression_list
int_literal "1"
comment "// each layer has at most 2 extra tensors for rope operation"...
assignment_statement
expression_list
identifier "maxTensors"
+= "+="
expression_list
binary_expression
identifier "blocks"
* "*"
int_literal "2"
type_declaration
type "type"
type_spec
type_identifier "tensor"
struct_type
struct "struct"
field_declaration_list
{ "{"
field_declaration
field_identifier "source"
pointer_type
* "*"
qualified_type
package_identifier "fsggml"
. "."
type_identifier "Tensor"
field_declaration
field_identifier "target"
type_identifier "string"
} "}"
comment "// some tensors are mapped to different names so keep a list"
short_var_declaration
expression_list
identifier "targets"
:= ":="
expression_list
call_expression
identifier "make"
argument_list
( "("
map_type
map "map"
[ "["
type_identifier "string"
] "]"
slice_type
[ "["
] "]"
type_identifier "string"
) ")"
comment "// contexts are shared by tensors of the same buffer type"
short_var_declaration (+26 nodes collapsed)
short_var_declaration (+564 nodes collapsed)
short_var_declaration (+81 nodes collapsed)
for_statement (+603 nodes collapsed)
comment "// allocate buffers for each context"
short_var_declaration (+33 nodes collapsed)
for_statement (+209 nodes collapsed)
for_statement (+84 nodes collapsed)
comment "// map tensor names to tensors for easy lookup later"
short_var_declaration (+21 nodes collapsed)
for_statement (+83 nodes collapsed)
comment "// map devices to backend buffer types so new tensors can be"...
short_var_declaration (+26 nodes collapsed)
comment "// create backends and buffer types used for the compute gra"...
var_declaration
var "var"
var_spec
identifier "schedBackends"
slice_type
[ "["
] "]"
pointer_type
* "*"
qualified_type
package_identifier "C"
. "."
type_identifier "struct_ggml_backend"
var_declaration
var "var"
var_spec
identifier "schedBufts"
slice_type
[ "["
] "]"
pointer_type
* "*"
qualified_type
package_identifier "C"
. "."
type_identifier "struct_ggml_backend_buffer_type"
for_statement (+142 nodes collapsed)
short_var_declaration (+35 nodes collapsed)
return_statement (+328 nodes collapsed)
} "}"
function_declaration (+25 nodes collapsed)
method_declaration (+768 nodes collapsed)
method_declaration (+31 nodes collapsed)
method_declaration (+36 nodes collapsed)
method_declaration (+75 nodes collapsed)
method_declaration (+37 nodes collapsed)
method_declaration (+193 nodes collapsed)
method_declaration (+98 nodes collapsed)
type_declaration (+62 nodes collapsed)
method_declaration (+114 nodes collapsed)
method_declaration (+119 nodes collapsed)
method_declaration (+120 nodes collapsed)
method_declaration (+207 nodes collapsed)
method_declaration (+430 nodes collapsed)
method_declaration (+26 nodes collapsed)
function_declaration (+88 nodes collapsed)
function_declaration (+44 nodes collapsed)
method_declaration (+616 nodes collapsed)
method_declaration (+47 nodes collapsed)
method_declaration (+73 nodes collapsed)
function_declaration (+108 nodes collapsed)
method_declaration (+140 nodes collapsed)
method_declaration (+140 nodes collapsed)
method_declaration (+242 nodes collapsed)
method_declaration (+81 nodes collapsed)
type_declaration (+29 nodes collapsed)
method_declaration (+126 nodes collapsed)
method_declaration (+41 nodes collapsed)
method_declaration (+41 nodes collapsed)
method_declaration (+83 nodes collapsed)
method_declaration (+122 nodes collapsed)
method_declaration (+122 nodes collapsed)
method_declaration (+124 nodes collapsed)
method_declaration (+78 nodes collapsed)
method_declaration (+97 nodes collapsed)
method_declaration (+97 nodes collapsed)
method_declaration (+279 nodes collapsed)
method_declaration (+98 nodes collapsed)
method_declaration (+111 nodes collapsed)
method_declaration (+78 nodes collapsed)
method_declaration (+97 nodes collapsed)
method_declaration (+97 nodes collapsed)
method_declaration (+97 nodes collapsed)
method_declaration (+118 nodes collapsed)
method_declaration (+111 nodes collapsed)
method_declaration (+202 nodes collapsed)
method_declaration (+152 nodes collapsed)
method_declaration (+189 nodes collapsed)
method_declaration (+164 nodes collapsed)
method_declaration (+97 nodes collapsed)
method_declaration (+97 nodes collapsed)
method_declaration (+421 nodes collapsed)
method_declaration (+95 nodes collapsed)
method_declaration (+78 nodes collapsed)
method_declaration (+78 nodes collapsed)
method_declaration (+78 nodes collapsed)
method_declaration (+78 nodes collapsed)
method_declaration (+78 nodes collapsed)
method_declaration (+78 nodes collapsed)
method_declaration (+549 nodes collapsed)
method_declaration (+353 nodes collapsed)
method_declaration (+178 nodes collapsed)
method_declaration (+78 nodes collapsed)
method_declaration (+78 nodes collapsed)
method_declaration (+78 nodes collapsed)
method_declaration (+171 nodes collapsed)
method_declaration (+153 nodes collapsed)
method_declaration (+232 nodes collapsed)
method_declaration (+413 nodes collapsed)
method_declaration (+78 nodes collapsed)
method_declaration (+92 nodes collapsed)
method_declaration (+83 nodes collapsed)
method_declaration (+78 nodes collapsed)
method_declaration (+104 nodes collapsed)
method_declaration (+48 nodes collapsed)
method_declaration (+78 nodes collapsed)
method_declaration (+78 nodes collapsed)
method_declaration (+104 nodes collapsed)