Skip to content

Commit 766bbf1

Browse files
authored
Merge pull request #944 from SteveBronder/feature/SoA
Adds mem_pattern needed for SoA and AoS types
2 parents 4e907d5 + 1b6537d commit 766bbf1

39 files changed

+3316
-2599
lines changed

Jenkinsfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ pipeline {
196196
cat shotgun_perf_all.tests >> all.tests
197197
cat all.tests
198198
echo "CXXFLAGS+=-march=core2" > cmdstan/make/local
199-
cd cmdstan; make clean-all; git show HEAD --stat; make -j4 build; cd ..
199+
echo "PRECOMPILED_HEADERS=false" >> cmdstan/make/local
200+
cd cmdstan; make clean-all; git show HEAD --stat; cd ..
200201
CXX="${CXX}" ./compare-compilers.sh "--tests-file all.tests --num-samples=10" "\$(readlink -f ../bin/stanc)"
201202
"""
202203

src/analysis_and_optimization/Factor_graph.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let extract_factors_statement stmt =
2323
| Stmt.Fixed.Pattern.TargetPE e ->
2424
List.map (summation_terms e) ~f:(fun x -> TargetTerm x)
2525
| NRFunApp (CompilerInternal FnReject, _) -> [Reject]
26-
| NRFunApp ((UserDefined (s, FnTarget) | StanLib (s, FnTarget)), args) ->
26+
| NRFunApp ((UserDefined (s, FnTarget) | StanLib (s, FnTarget, _)), args) ->
2727
[LPFunction (s, args)]
2828
| Assignment (_, _)
2929
|NRFunApp (_, _)

src/analysis_and_optimization/Mir_utils.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ let rec num_expr_value (v : Expr.Typed.t) : (float * string) option =
3030
| {pattern= Fixed.Pattern.Lit (Real, str); _}
3131
|{pattern= Fixed.Pattern.Lit (Int, str); _} ->
3232
Some (float_of_string str, str)
33-
| {pattern= Fixed.Pattern.FunApp (StanLib ("PMinus__", FnPlain), [v]); _} -> (
33+
| {pattern= Fixed.Pattern.FunApp (StanLib ("PMinus__", FnPlain, _), [v]); _}
34+
-> (
3435
match num_expr_value v with
3536
| Some (v, s) -> Some (-.v, "-" ^ s)
3637
| None -> None )
@@ -295,7 +296,7 @@ let expr_assigned_var Expr.Fixed.({pattern; _}) =
295296
(** See interface file *)
296297
let rec summation_terms (Expr.Fixed.({pattern; _}) as rhs) =
297298
match pattern with
298-
| FunApp (StanLib ("Plus__", FnPlain), [e1; e2]) ->
299+
| FunApp (StanLib ("Plus__", FnPlain, _), [e1; e2]) ->
299300
List.append (summation_terms e1) (summation_terms e2)
300301
| _ -> [rhs]
301302

src/analysis_and_optimization/Monotone_framework.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ let assigned_vars_stmt (s : (Expr.Typed.t, 'a) Stmt.Fixed.Pattern.t) =
442442
match s with
443443
| Assignment ((x, _, _), _) -> Set.Poly.singleton x
444444
| TargetPE _ -> Set.Poly.singleton "target"
445-
| NRFunApp ((UserDefined (_, FnTarget) | StanLib (_, FnTarget)), _) ->
445+
| NRFunApp ((UserDefined (_, FnTarget) | StanLib (_, FnTarget, _)), _) ->
446446
Set.Poly.singleton "target"
447447
| For {loopvar= x; _} -> Set.Poly.singleton x
448448
| Decl {decl_id= _; _}
@@ -485,7 +485,8 @@ let reaching_definitions_transfer
485485
|For {loopvar= x; _} ->
486486
Set.filter p ~f:(fun (y, _) -> y = x)
487487
| TargetPE _ -> Set.filter p ~f:(fun (y, _) -> y = "target")
488-
| NRFunApp ((UserDefined (_, FnTarget) | StanLib (_, FnTarget)), _) ->
488+
| NRFunApp ((UserDefined (_, FnTarget) | StanLib (_, FnTarget, _)), _)
489+
->
489490
Set.filter p ~f:(fun (y, _) -> y = "target")
490491
| NRFunApp (_, _)
491492
|Break | Continue | Return _ | Skip

src/analysis_and_optimization/Optimize.ml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ let rec inline_function_expression propto adt fim
238238
match kind with
239239
| CompilerInternal _ ->
240240
(d_list, s_list, {e with pattern= FunApp (kind, es)})
241-
| UserDefined (fname, suffix) | StanLib (fname, suffix) -> (
241+
| UserDefined (fname, suffix) | StanLib (fname, suffix, _) -> (
242242
let suffix, fname' =
243243
match suffix with
244244
| FnLpdf propto' when propto' && propto ->
@@ -252,7 +252,7 @@ let rec inline_function_expression propto adt fim
252252
let fun_kind =
253253
match kind with
254254
| Fun_kind.UserDefined _ -> Fun_kind.UserDefined (fname, suffix)
255-
| _ -> StanLib (fname, suffix)
255+
| _ -> StanLib (fname, suffix, AoS)
256256
in
257257
(d_list, s_list, {e with pattern= FunApp (fun_kind, es)})
258258
| Some (rt, args, b) ->
@@ -388,7 +388,7 @@ let rec inline_function_statement propto adt fim Stmt.Fixed.({pattern; meta}) =
388388
slist_concat_no_loc (d_list @ s_list)
389389
( match kind with
390390
| CompilerInternal _ -> NRFunApp (kind, es)
391-
| UserDefined (s, _) | StanLib (s, _) -> (
391+
| UserDefined (s, _) | StanLib (s, _, _) -> (
392392
match Map.find fim s with
393393
| None -> NRFunApp (kind, es)
394394
| Some (_, args, b) ->
@@ -593,8 +593,8 @@ let unroll_loop_one_step_statement _ =
593593
IfElse
594594
( Expr.Fixed.
595595
{ lower with
596-
pattern= FunApp (StanLib ("Geq__", FnPlain), [upper; lower])
597-
}
596+
pattern=
597+
FunApp (StanLib ("Geq__", FnPlain, SoA), [upper; lower]) }
598598
, { pattern=
599599
(let body_unrolled =
600600
subst_args_stmt [loopvar] [lower]
@@ -610,7 +610,7 @@ let unroll_loop_one_step_statement _ =
610610
{ lower with
611611
pattern=
612612
FunApp
613-
( StanLib ("Plus__", FnPlain)
613+
( StanLib ("Plus__", FnPlain, SoA)
614614
, [lower; Expr.Helpers.loop_bottom] ) } }
615615
; meta= Location_span.empty }
616616
in
@@ -694,7 +694,7 @@ and accum_any pred b e = b || expr_any pred e
694694

695695
let can_side_effect_top_expr (e : Expr.Typed.t) =
696696
match e.pattern with
697-
| FunApp ((UserDefined (_, FnTarget) | StanLib (_, FnTarget)), _) -> true
697+
| FunApp ((UserDefined (_, FnTarget) | StanLib (_, FnTarget, _)), _) -> true
698698
| FunApp (CompilerInternal internal_fn, _) ->
699699
Internal_fun.can_side_effect internal_fn
700700
| _ -> false
@@ -703,7 +703,7 @@ let cannot_duplicate_expr (e : Expr.Typed.t) =
703703
let pred e =
704704
can_side_effect_top_expr e
705705
|| ( match e.pattern with
706-
| FunApp ((UserDefined (_, FnRng) | StanLib (_, FnRng)), _) -> true
706+
| FunApp ((UserDefined (_, FnRng) | StanLib (_, FnRng, _)), _) -> true
707707
| _ -> false )
708708
|| (preserve_stability && UnsizedType.is_autodiffable e.meta.type_)
709709
in

0 commit comments

Comments
 (0)