Analysis_and_optimization.Memory_patternstype demotion = int * Middle.Mem_pattern.t * stringval demotion_reasons : demotion list Core.refval user_warning_op : Middle.Mem_pattern.t -> int -> string -> string -> unitval matrix_set :
Middle.Expr.Typed.Meta.t Middle.Expr.t ->
(Dataflow_types.vexpr * Middle.Expr.Typed.Meta.t) Core.Set.Poly.tReturn a Var expression of the name for each type containing an eigen matrix
val query_var_eigen_names : Middle.Expr.Typed.t -> string Core.Set.Poly.tReturn a set of all types containing autodiffable Eigen matrices in an expression.
Check whether one set is a nonzero subset of another set.
val count_single_idx : int -> Middle.Expr.Typed.t Middle.Index.t -> intCheck an Index to count how many times we see a single index.
val is_uni_eigen_loop_indexing :
bool ->
Middle.UnsizedType.t ->
Middle.Expr.Typed.t Middle.Index.t list ->
boolFind indices on Matrix and Vector types that perform single cell access. Returns true if it finds a vector, row vector, matrix, or matrix with single cell access as well as an array of any of the above that is accessing the inner matrix types cell.
val query_stan_math_mem_pattern_support :
string ->
Middle.UnsizedType.argumentlist ->
boolval is_fun_soa_supported : string -> Middle.Expr.Typed.t list -> boolValidate whether a function can support SoA matrices
val query_initial_demotable_expr :
bool ->
int ->
acc:string Core.Set.Poly.t ->
Middle.Expr.Typed.t ->
string Core.Set.Poly.tQuery to find the initial set of objects that cannot be SoA. This is mostly recursing over expressions, with the exceptions being functions and indexing expressions. For the logic on functions see the docs for query_initial_demotable_funs.
val query_initial_demotable_funs :
bool ->
int ->
string Core.Set.Poly.t ->
Middle.Expr.Typed.Meta.t Middle.Expr.t Middle.Fun_kind.t ->
Middle.Expr.Typed.t list ->
string Core.Set.Poly.tQuery a function to detect if it or any of its used expression's objects or expressions should be demoted to AoS.
The logic here demotes the expressions in a function to AoS if the function's inner expression returns has a meta type containing a matrix and either of :
val extract_nonderived_admatrix_types :
Middle.Expr.Typed.t ->
(Middle.UnsizedType.autodifftype * Middle.UnsizedType.t) listRecurse through subexpressions and return a list of Unsized types. Recursion continues until
val extract_nonderived_admatrix_types_fun :
Middle.Expr.Typed.Meta.t Middle.Expr.t Middle.Fun_kind.t ->
Middle.Expr.Typed.t list ->
(Middle.UnsizedType.autodifftype * Middle.UnsizedType.t) listRecurse through functions to find nonderived ad matrix types. Special cases for StanLib functions are for
val contains_at_least_one_ad_matrix_or_all_data :
Middle.UnsizedType.argumentlist ->
boolChecks if a list of types contains at least on ad matrix or if everything is derived from data
val query_initial_demotable_stmt :
bool ->
string Core.Set.Poly.t ->
(Middle.Expr.Typed.Meta.t, Middle.Stmt.Located.Meta.t) Middle.Stmt.t ->
string Core.Set.Poly.tQuery to find the initial set of objects in statements that cannot be SoA. This is mostly recursive over expressions and statements, with the exception of functions and Assignments. For assignments: We demote the LHS variable if any of the following are true:
We demote RHS variables if any of the following are true:
For functions see the documentation for query_initial_demotable_funs for the logic on demotion rules.
val query_demotable_stmt :
string Core.Set.Poly.t ->
Middle.Stmt.Located.Non_recursive.t ->
string Core.Set.Poly.tLook through a statement to see whether the objects used in it need to be modified from SoA to AoS. Returns the set of object names that need demoted in a statement, if any. This function looks at Assignment statements, and returns back the set of top level object names given:
aos_exits, all the names of the expressions with a type containing a matrix are returned.val modify_kind :
?force_demotion:bool ->
string Core.Set.Poly.t ->
Middle.Expr.Typed.t Middle.Fun_kind.t ->
Middle.Expr.Typed.t list ->
Middle.Expr.Typed.t Middle.Fun_kind.t * Middle.Expr.Typed.t listModify a function and it's subexpressions from SoA <-> AoS and vice versa. This performs demotion for sub expressions recursively. The top level expression and it's sub expressions are demoted to SoA if
force argument is trueval modify_expr_pattern :
?force_demotion:bool ->
string Core.Set.Poly.t ->
Middle.Expr.Typed.t Middle.Expr.Pattern.t ->
Middle.Expr.Typed.t Middle.Expr.Pattern.tModify an expression and it's subexpressions from SoA <-> AoS and vice versa. The only real paths in the below is on the functions and ternary expressions. The logic for functions is defined in modify_kind. TernaryIf is forcefully demoted to AoS if the type of the expression contains a matrix.
val modify_expr :
?force_demotion:bool ->
string Core.Set.Poly.t ->
Middle.Expr.Typed.t ->
Middle.Expr.Typed.tGiven a Set of strings containing the names of objects that can be modified from AoS <-> SoA and vice versa, modify them within the expression.
val modify_stmt_pattern :
(Middle.Expr.Typed.t, Middle.Stmt.Located.t) Middle.Stmt.Pattern.t ->
string Core.Set.Poly.t ->
(Middle.Expr.Typed.t, Middle.Stmt.Located.t) Middle.Stmt.Pattern.tModify statement patterns in the MIR from AoS <-> SoA and vice versa For Decl and Assignment's reading in parameters, we demote to AoS if the decl_id (or assign name) is in the modifiable set and otherwise promote the statement to SoA. For general Assignment statements, we check if the assignee is in the demotable set. If so, we force demotion of all of the rhs expressions. All other statements recurse over their statements and expressions. *
val modify_stmt :
Middle.Stmt.Located.t ->
string Core.Set.Poly.t ->
Middle.Stmt.Located.tModify statement patterns in the MIR from AoS <-> SoA and vice versa
val collect_mem_pattern_variables :
Middle.Stmt.Located.t Core.List.t ->
(string * Middle.Expr.Typed.Meta.t Middle.Expr.t Middle.SizedType.t) listval pp_mem_patterns : Stdlib.Format.formatter -> Middle.Program.Typed.t -> unit