Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Eigen Dense and Sparse vari_value types #1952

Merged
merged 224 commits into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from 215 commits
Commits
Show all changes
224 commits
Select commit Hold shift + click to select a range
4727ac7
Fixed typo in release notes
serban-nicusor-toptal Jul 18, 2019
2db4561
Updated 2.21.0 release notes.
serban-nicusor-toptal Oct 18, 2019
a707039
Revert "release/v2.21.0: updating version numbers"
serban-nicusor-toptal Oct 18, 2019
2f037ae
Release v3.0.0
serban-nicusor-toptal Oct 18, 2019
31151b2
Merge branch 'master' of github.com:stan-dev/math
serban-nicusor-toptal Jan 24, 2020
d4e4f15
Fixed conflict in stan/math/prim/fun/log_softmax.hpp
rok-cesnovar Jan 29, 2020
3f8fae4
Updated math version
serban-nicusor-catena Jan 29, 2020
067add1
Reverted release of 3.1.1
serban-nicusor-catena Jan 29, 2020
b96e401
Fixed conflict in stan/math/prim/fun/log_softmax.hpp
rok-cesnovar Jan 29, 2020
ab50cb5
Fixed conflict in stan/math/prim/fun/log_softmax.hpp
rok-cesnovar Jan 29, 2020
ba8e315
Updated math to v3.1.1
serban-nicusor-toptal Jan 29, 2020
ea955b8
Reverted release 3.1.1
serban-nicusor-toptal Jan 29, 2020
f899a98
Fixed conflict in stan/math/prim/fun/log_softmax.hpp
rok-cesnovar Jan 29, 2020
a5d71b2
Fixed conflict in stan/math/prim/fun/log_softmax.hpp
rok-cesnovar Jan 30, 2020
e081b4e
Release v3.1.1
serban-nicusor-toptal Jan 30, 2020
5f28b8f
Fixed merge conflicts
serban-nicusor-toptal Apr 22, 2020
ebbfeb8
Adds templates to vari and var as well as the var operators. Fixes st…
SteveBronder May 28, 2020
d7e1d84
Add a template to grad so that init_dependent can be non-virtual, mak…
SteveBronder May 28, 2020
ba930da
add final to classes inheriting op_varis so flto can more aggressivly…
SteveBronder May 28, 2020
244620a
cleanup templates in var and vari, clang-format, tests for is_var, is…
SteveBronder May 29, 2020
92630dd
add ref to require_convertible check in vari constructors
SteveBronder May 29, 2020
d5139c6
Merge remote-tracking branch 'origin/develop' into feature/vari-base-…
SteveBronder May 30, 2020
2dfa329
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot May 30, 2020
f045272
fix header check
SteveBronder May 30, 2020
4b5fc67
Fix templates for hmm
SteveBronder May 30, 2020
1fe6e2b
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot May 30, 2020
b63acdc
add template to lp value in in positive_constrain
SteveBronder May 30, 2020
df22a0b
Merge branch 'feature/vari-base-templates' of github.com:stan-dev/mat…
SteveBronder May 30, 2020
f20d98a
replace vector func value types in apply_scalar_binary with return ty…
SteveBronder May 30, 2020
16db81b
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot May 30, 2020
4cc404e
var and vari can only be templated with floating point types. Remove …
SteveBronder Jun 1, 2020
57c65b8
update hmm_marginal
SteveBronder Jun 3, 2020
75910a1
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jun 3, 2020
de2b7c5
add flto flag for mac
SteveBronder Jun 3, 2020
81df481
Merge branch 'feature/vari-base-templates' of github.com:stan-dev/mat…
SteveBronder Jun 3, 2020
df7e089
use ? instead of : for flto flags
SteveBronder Jun 3, 2020
b510337
update vari test since integral template types are no longer allowed
SteveBronder Jun 3, 2020
4424dc3
remove whole program vtable clang optimization
SteveBronder Jun 3, 2020
8ce09f4
remove -fstrict-vtable-pointers from clang
SteveBronder Jun 3, 2020
b8de65f
fix is_var test
SteveBronder Jun 4, 2020
8cf3bcc
remove unneeded templating in var_value operators
SteveBronder Jun 4, 2020
a07140c
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jun 4, 2020
7ed5d99
remove flto flag
SteveBronder Jun 4, 2020
52de946
use lambda instead of visitor pattern
SteveBronder Jun 4, 2020
6585a89
fix vari_test
SteveBronder Jun 4, 2020
f42756c
only use fdevirtualize-at-ltrans for linux gcc
SteveBronder Jun 4, 2020
12f9caf
use filter instead of findstring when matching on g++ in makefile
SteveBronder Jun 4, 2020
7a08c41
Merge remote-tracking branch 'origin/develop' into feature/vari-base-…
SteveBronder Jun 6, 2020
d76617a
merge to remote origin
SteveBronder Jun 7, 2020
2c41d98
do not use flto for windows
SteveBronder Jun 7, 2020
77f1059
fix compile_flags missing tab
SteveBronder Jun 7, 2020
e1f6af3
add flto flags to library flags
SteveBronder Jun 8, 2020
fdae56f
remove flto changes
SteveBronder Jun 9, 2020
cc702da
add back flto flag for mac and linux
SteveBronder Jun 9, 2020
c8b5eea
add flto to cppflags
SteveBronder Jun 9, 2020
8726f4c
set ar by clang or gcc cxx_type
SteveBronder Jun 10, 2020
cba8d24
remove vari_base
SteveBronder Jun 10, 2020
4c671e1
use functors instead of lambdas
SteveBronder Jun 10, 2020
a1b2765
update to use variant instead of vari_base
SteveBronder Jun 10, 2020
e4581ca
remove flto from compiler_flags
SteveBronder Jun 10, 2020
04d3a0f
Merge commit '29d3b2df8b6bbba717fb582c0cf2fe90b1eb3aa7' into HEAD
yashikno Jun 10, 2020
52ae3b4
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot Jun 10, 2020
9358df7
remove promote_args_t in var member function templates
SteveBronder Jun 11, 2020
f567182
Merge remote-tracking branch 'bstat/bugfix_matrix_cl_from_map' into f…
SteveBronder Jun 11, 2020
eb18a98
remove TODO comment and fix grammar
SteveBronder Jun 11, 2020
3a71101
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jun 11, 2020
9441346
make visitor classes more generic
SteveBronder Jun 11, 2020
a41f5be
merge to remote
SteveBronder Jun 11, 2020
80c1dea
Merge commit 'a33a9ab8177fa5847c539125760b184ae1a318aa' into HEAD
yashikno Jun 11, 2020
30be7d2
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jun 11, 2020
78b73b9
add const correct stuff for vari value accessors in var
SteveBronder Jun 11, 2020
c27c21a
Merge branch 'feature/vari-base-templates' of github.com:stan-dev/mat…
SteveBronder Jun 11, 2020
5c69ed0
remove constructors for mixed floating point types
SteveBronder Jun 12, 2020
917800a
remove nohup
SteveBronder Jun 12, 2020
94f10c6
Merge remote-tracking branch 'origin/develop' into feature/vari-base-…
SteveBronder Jun 12, 2020
ac7076c
switch order of members in vari_printer for order warning on windows
SteveBronder Jun 12, 2020
1cd05a8
switch order of members in vari_printer for order warning on windows
SteveBronder Jun 12, 2020
2763524
call set_zero_adjoint_nested directly
SteveBronder Jun 13, 2020
ed1d828
call set_zero_adjoint_nested directly
SteveBronder Jun 13, 2020
22f90a1
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jun 13, 2020
d15494d
try variant2
SteveBronder Jun 14, 2020
5c6836b
add noexcept to member functions that will not throw
SteveBronder Jun 14, 2020
d8bb2ac
use lambda for print_stack
SteveBronder Jun 14, 2020
885cdb3
merge to remote
SteveBronder Jun 14, 2020
cd1b3c4
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot Jun 14, 2020
5630a65
use eigen strong inline and static on set_zero_adj()
SteveBronder Jun 14, 2020
5285fdd
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jun 14, 2020
006fbf6
testing if vari long slows us down
SteveBronder Jun 14, 2020
538b011
add back tests for vari long double
SteveBronder Jun 14, 2020
8e76694
Merge branch 'feature/vari-base-templates' of github.com:stan-dev/mat…
SteveBronder Jun 14, 2020
ad2d15f
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jun 14, 2020
3d3efed
Merge remote-tracking branch 'origin/develop' into feature/vari-base-…
SteveBronder Jun 15, 2020
28f3373
remove templates from operators
SteveBronder Jun 15, 2020
0324c82
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jun 15, 2020
e30e111
add dense eigen vari type
SteveBronder Jun 16, 2020
3f88335
try custom visitor
SteveBronder Jun 16, 2020
4104696
switching back to virtual
SteveBronder Jun 16, 2020
ce718a8
Trying multi stack method
SteveBronder Jun 16, 2020
85a44b7
add var_dbl_stack to vari
SteveBronder Jun 16, 2020
ac6e99a
add var_dbl_stack to vari
SteveBronder Jun 16, 2020
f9af055
add var_dbl_stack to vari
SteveBronder Jun 16, 2020
82c0332
remove nochain stack and use dbl stack
SteveBronder Jun 17, 2020
346e6ca
add tuple of stacks to zero out
SteveBronder Jun 17, 2020
2f7d37c
debugs for nested sizes
SteveBronder Jun 17, 2020
e3e2d7e
multi-stack nested
SteveBronder Jun 17, 2020
e742ec0
add size check on start_nested
SteveBronder Jun 17, 2020
5ac9a05
Merge commit 'd5c2cb57c4653b843d41b4a47b1f9c6c242db162' into HEAD
yashikno Jun 17, 2020
5f4278f
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jun 17, 2020
9a8ba4c
add docs to for_each
SteveBronder Jun 17, 2020
fc44eff
update with remote
SteveBronder Jun 17, 2020
5c6faab
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jun 17, 2020
388b075
update docs
SteveBronder Jun 17, 2020
b1435e0
Merge branch 'feature/vari-base-templates' of github.com:stan-dev/mat…
SteveBronder Jun 17, 2020
caa55f4
Use trick from boost::hana on for_each to avoid unused-value warning
SteveBronder Jun 17, 2020
2d3648b
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jun 17, 2020
52ddce4
cpplint
SteveBronder Jun 17, 2020
7810ef6
merge to remote
SteveBronder Jun 17, 2020
b952d58
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot Jun 17, 2020
abf0a5e
update tests to use new zeroing vari stack instead of nochain
SteveBronder Jun 17, 2020
1602f71
merge to remote
SteveBronder Jun 17, 2020
4674b1d
update docs for var and vari
SteveBronder Jun 17, 2020
64de92c
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot Jun 17, 2020
c8cd17a
forgot () in virtual vari_base destructor
SteveBronder Jun 17, 2020
7decf0e
var and vari docs
SteveBronder Jun 17, 2020
9dd3eaf
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jun 17, 2020
1d187bc
fix libstdc++ bug with array
SteveBronder Jun 17, 2020
eccd3cb
cpplint
SteveBronder Jun 17, 2020
6ad6714
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jun 17, 2020
165a883
fix seg fault by not always giving var_zeroing stacks to nested_var_z…
SteveBronder Jun 17, 2020
fa5de84
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jun 17, 2020
efaa936
only push sizes if they are nonzero for the nested zeroing stack
SteveBronder Jun 18, 2020
cd38c4a
Merge commit '461e57f912560b06913de3150dfa939a6f2b78bd' into HEAD
yashikno Jun 18, 2020
908ff3c
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jun 18, 2020
3b85b96
move around the stacks to avoid double push_backs in vari
SteveBronder Jun 19, 2020
8b2a934
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jun 19, 2020
72fefc4
Fix bad stack sizes
SteveBronder Jun 20, 2020
1691985
use make_unique in ad_tape_observer
SteveBronder Jun 20, 2020
c1e3d0e
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jun 20, 2020
46ef24c
update to develop
SteveBronder Jun 22, 2020
66908ec
Merge remote-tracking branch 'origin/develop' into feature/vari-base-…
SteveBronder Jun 23, 2020
4409bfd
update to fix mem bug in mpi tests
SteveBronder Jun 23, 2020
7255554
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot Jun 23, 2020
5e9f707
move back to virtual methods
SteveBronder Jun 24, 2020
645ec49
merge with virtual base branch
SteveBronder Jun 24, 2020
6ed44f6
merge to remote
SteveBronder Jun 24, 2020
330af39
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jun 24, 2020
73e6599
remove references to zero_stack from tests
SteveBronder Jun 24, 2020
5d4deb5
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot Jun 24, 2020
05a3166
small fixes
SteveBronder Jun 24, 2020
40b08cf
Merge branch 'feature/vari-base-templates' of github.com:stan-dev/mat…
SteveBronder Jun 24, 2020
b25944d
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jun 24, 2020
ffd30da
use nested chainable stack class for set zero adjoint
SteveBronder Jun 25, 2020
e5428e9
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jun 25, 2020
13bcbf3
merge to vari-base-templates
SteveBronder Jun 25, 2020
356bb4e
merge to vari-base-templates and add sparse matrix var type
SteveBronder Jun 26, 2020
2130cfe
adds sparse and dense vari_value specializations
SteveBronder Jun 28, 2020
f29623d
Merge commit 'e5428e9d6c50154ed2552cba0809dd1ed93ebb29' into HEAD
yashikno Jun 28, 2020
6f1ce8a
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jun 28, 2020
dd900b2
add docs for x param for eigen_map vari_value constructors
SteveBronder Jun 29, 2020
fdac590
Merge branch 'feature/vari-base-eigen' of github.com:stan-dev/math in…
SteveBronder Jun 29, 2020
5d8c384
use chainable_alloc for sparse matrix vari_value
SteveBronder Jun 29, 2020
1cbd95b
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jun 29, 2020
cea502a
add chainable_alloc() constructor to sparse vari constructor
SteveBronder Jun 29, 2020
02c23a2
merge to remote
SteveBronder Jun 29, 2020
cc2a49d
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jun 29, 2020
41d0e74
using chainable_alloc allows the sparse vari to accept eigen expressions
SteveBronder Jun 30, 2020
9039f7c
Merge branch 'feature/vari-base-eigen' of github.com:stan-dev/math in…
SteveBronder Jun 30, 2020
cdaa2e6
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jun 30, 2020
dc44dcc
add static_assert to make sure var inner type is assignable. Add test…
SteveBronder Jun 30, 2020
fa3a6fc
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot Jun 30, 2020
8d20a67
Add tests for new meta functions, remove forwarding from vari
SteveBronder Jul 1, 2020
b83f5bf
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jul 1, 2020
83d4ce6
remove docs for removed mem param in make_* functions in vari_value
SteveBronder Jul 2, 2020
fba6166
remove private constructor for vari_value
SteveBronder Jul 2, 2020
5788a40
Merge remote-tracking branch 'origin/develop' into feature/vari-base-…
SteveBronder Jul 6, 2020
48801a0
remove make functions from vari_value matrix constructor. Add additio…
SteveBronder Jul 6, 2020
896b267
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jul 6, 2020
950498b
update var templates
SteveBronder Jul 6, 2020
9cfb8a9
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jul 6, 2020
f02d232
kickoff jenkins
SteveBronder Jul 7, 2020
9eea7e7
Merge branch 'feature/vari-base-eigen' of github.com:stan-dev/math in…
SteveBronder Jul 7, 2020
2d1928a
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jul 7, 2020
859d920
update to develop
SteveBronder Jul 8, 2020
7bf1396
update to develop
SteveBronder Jul 8, 2020
e8a386e
Merge branch 'feature/vari-base-templates' into feature/vari-base-eigen
SteveBronder Jul 8, 2020
c8fd050
move Eigen numtraits and read_var to core to help with include order …
SteveBronder Jul 8, 2020
9660a5a
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jul 8, 2020
826d1d5
move Eigen Numtraits and typedefs to core for fwd and rev
SteveBronder Jul 9, 2020
fb317b7
move around fvar Eigen_Numtraits
SteveBronder Jul 9, 2020
eeeb4ee
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2 (tag…
stan-buildbot Jul 9, 2020
58ca7e2
Revert "[Jenkins] auto-formatting by clang-format version 6.0.0-1ubun…
SteveBronder Jul 13, 2020
60f54ab
Revert "move around fvar Eigen_Numtraits"
SteveBronder Jul 13, 2020
d7bd3f5
Revert "move Eigen Numtraits and typedefs to core for fwd and rev"
SteveBronder Jul 13, 2020
370c55b
Revert "[Jenkins] auto-formatting by clang-format version 6.0.0-1ubun…
SteveBronder Jul 13, 2020
0f12bbf
Revert "move Eigen numtraits and read_var to core to help with includ…
SteveBronder Jul 13, 2020
dd1b1f7
Merge remote-tracking branch 'origin/develop' into feature/vari-base-…
SteveBronder Jul 13, 2020
e0c5136
update to develop
SteveBronder Jul 16, 2020
4737ddf
update to develop
SteveBronder Jul 20, 2020
0776132
Merge branch 'feature/vari-base-templates' into feature/vari-base-eigen
SteveBronder Jul 20, 2020
2a14395
adds uint16_t to var test
SteveBronder Jul 22, 2020
31a0d13
update to make vari_value Scalar type an actual scalar type even in t…
SteveBronder Jul 22, 2020
9df61ca
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot Jul 22, 2020
53ee10a
Merge branch 'master' of github.com:stan-dev/math
serban-nicusor-toptal Jul 28, 2020
a7ff367
Merge remote-tracking branch 'origin/develop' into feature/vari-base-…
SteveBronder Jul 29, 2020
1e7a939
Merge remote-tracking branch 'origin/feature/vari-base-templates' int…
SteveBronder Jul 29, 2020
ab3a6ef
Merge remote-tracking branch 'origin/develop' into feature/vari-base-…
SteveBronder Aug 3, 2020
b2900b7
Merge branch 'feature/vari-base-templates' into feature/vari-base-eigen
SteveBronder Aug 3, 2020
6e36185
remove Scalar type trait from vari_value
SteveBronder Aug 3, 2020
5479093
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot Aug 3, 2020
ec592d5
Add vari_base<matrix_cl> (#1967)
t4c1 Aug 3, 2020
783eba8
Merge remote-tracking branch 'origin/develop' into feature/vari-base-…
SteveBronder Aug 4, 2020
33e266d
remove changes to cholesky and vari_pointer type trait in var
SteveBronder Aug 4, 2020
45d7fa2
Merge branch 'feature/vari-base-templates' into feature/vari-base-eigen
SteveBronder Aug 5, 2020
1c3d5ca
Merge remote-tracking branch 'origin/master' into feature/vari-base-e…
SteveBronder Aug 5, 2020
e290f12
merge to develop
SteveBronder Aug 5, 2020
bf096b9
Add grad() method without an input vari and add template paramter to …
SteveBronder Aug 5, 2020
d2edb26
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot Aug 5, 2020
614ae97
fix docs in vari for matrix_cl
SteveBronder Aug 5, 2020
bf38a76
use grad() in grad(Vari*)
SteveBronder Aug 6, 2020
c6af0b0
Move grad() in front of grad(Vari*)
SteveBronder Aug 6, 2020
7945f66
merge to develop and use const S& instead of S&& in var_value and var…
SteveBronder Aug 6, 2020
4e70ba6
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot Aug 6, 2020
8cec8bb
Use pf in var_value for the sparse matrix constructor
SteveBronder Aug 6, 2020
32045cc
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.0…
stan-buildbot Aug 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions stan/math/opencl/copy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stan/math/opencl/matrix_cl.hpp>
#include <stan/math/opencl/matrix_cl_view.hpp>
#include <stan/math/opencl/opencl_context.hpp>
#include <stan/math/opencl/value_type.hpp>
#include <stan/math/opencl/kernels/copy.hpp>
#include <stan/math/opencl/kernels/pack.hpp>
#include <stan/math/opencl/kernels/unpack.hpp>
Expand Down Expand Up @@ -101,6 +102,23 @@ inline Eigen::Matrix<T, R, C> from_matrix_cl(const matrix_cl<T>& src) {
return dst;
}

/** \ingroup opencl
* Copies result of a kernel generator expression to the
* destination Eigen matrix.
*
* @tparam R rows type of the destination
* @tparam C cols type of the destination
* @tparam T type of expression
* @param src source expression
* @return Eigen matrix with a copy of the data in the source matrix
*/
template <int R = Eigen::Dynamic, int C = Eigen::Dynamic, typename T,
require_all_kernel_expressions_t<T>* = nullptr,
require_not_matrix_cl_t<T>* = nullptr>
inline Eigen::Matrix<value_type_t<T>, R, C> from_matrix_cl(const T& src) {
return from_matrix_cl<R, C>(src.eval());
}

/** \ingroup opencl
* Packs the flat triangular matrix on the OpenCL device and
* copies it to the std::vector.
Expand Down
1 change: 1 addition & 0 deletions stan/math/opencl/kernel_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@

#include <stan/math/opencl/kernel_generator/load.hpp>
#include <stan/math/opencl/kernel_generator/scalar.hpp>
#include <stan/math/opencl/kernel_generator/constant.hpp>
#include <stan/math/opencl/kernel_generator/append.hpp>
#include <stan/math/opencl/kernel_generator/binary_operation.hpp>
#include <stan/math/opencl/kernel_generator/unary_function_cl.hpp>
Expand Down
132 changes: 132 additions & 0 deletions stan/math/opencl/kernel_generator/constant.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#ifndef STAN_MATH_OPENCL_KERNEL_GENERATOR_CONSTANT_HPP
#define STAN_MATH_OPENCL_KERNEL_GENERATOR_CONSTANT_HPP
#ifdef STAN_OPENCL

#include <stan/math/opencl/matrix_cl.hpp>
#include <stan/math/opencl/matrix_cl_view.hpp>
#include <stan/math/opencl/kernel_generator/type_str.hpp>
#include <stan/math/opencl/kernel_generator/name_generator.hpp>
#include <stan/math/opencl/kernel_generator/operation_cl.hpp>
#include <limits>
#include <set>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>

namespace stan {
namespace math {

/** \addtogroup opencl_kernel_generator
* @{
*/

/**
* Represents a matrix of single repeated value in kernel generator expressions.
* @tparam T type of the scalar
*/
template <typename T>
class constant_ : public operation_cl<constant_<T>, T> {
T a_;
int rows_;
int cols_;

public:
static_assert(std::is_arithmetic<T>::value,
"class scalar_<T>: std::is_arithmetic<T> must be true!");
using Scalar = T;
using base = operation_cl<constant_<T>, T>;
using base::var_name_;

/**
* Constructor
* @param a scalar value
* @param rows number of rows of the matrix
* @param cols number of columns of the matrix
*/
explicit constant_(const T a, int rows, int cols)
: a_(a), rows_(rows), cols_(cols) {}

/**
* Creates a deep copy of this expression.
* @return copy of \c *this
*/
inline constant_<T> deep_copy() const {
return constant_<T>(a_, rows_, cols_);
}

/**
* Generates kernel code for this expression.
* @param row_index_name row index variable name
* @param col_index_name column index variable name
* @param view_handled whether whether caller already handled matrix view
* @return part of kernel with code for this expression
*/
inline kernel_parts generate(const std::string& row_index_name,
const std::string& col_index_name,
const bool view_handled) const {
kernel_parts res{};
res.args = type_str<Scalar>() + " " + var_name_ + ", ";
return res;
}

/**
* Sets kernel arguments for this and nested expressions.
* @param[in,out] generated set of expressions that already set their kernel
* arguments
* @param kernel kernel to set arguments on
* @param[in,out] arg_num consecutive number of the first argument to set.
* This is incremented for each argument set by this function.
*/
inline void set_args(std::set<const operation_cl_base*>& generated,
cl::Kernel& kernel, int& arg_num) const {
kernel.setArg(arg_num++, a_);
}

/**
* Number of rows of a matrix that would be the result of evaluating this
* expression.
* @return number of rows
*/
inline int rows() const { return rows_; }

/**
* Number of columns of a matrix that would be the result of evaluating this
* expression.
* @return number of columns
*/
inline int cols() const { return cols_; }

/**
* Determine indices of extreme sub- and superdiagonals written.
* @return pair of indices - bottom and top diagonal
*/
inline std::pair<int, int> extreme_diagonals() const {
return {std::numeric_limits<int>::min(), std::numeric_limits<int>::max()};
}
};

/**
* Matrix of repeated values in kernel generator expressions.
*
* In most cases scalars should be directly used instead of this. This is,
* however, useful for initializing some expression to specific value if that
* expresssion could also be plain `matrix_cl`.
*
* @tparam T type of argument
* @param a input argument
* @param rows number of rows
* @param cols number of columns
* @return Block of given expression
*/
template <typename T, typename = require_arithmetic_t<T>>
inline auto constant(const T a, int rows, int cols) {
return constant_<T>(a, rows, cols);
}

/** @}*/
} // namespace math
} // namespace stan

#endif
#endif
27 changes: 22 additions & 5 deletions stan/math/opencl/kernel_generator/is_kernel_expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@
#include <type_traits>

namespace stan {
namespace math {

/** \addtogroup opencl_kernel_generator
* @{
*/

/**
* Non-templated base of \c operation is needed for easy checking if something
* is a subclass of \c operation.
* Non-templated base of `operation_cl` is needed for easy checking if something
* is a subclass of `operation_cl`.
*/
class operation_cl_base {};
/**
* Non-templated base of `operation_cl_lhs` is needed for easy checking if
* something is a subclass of `operation_cl_lhs`.
*/
class operation_cl_lhs_base {};

/**
* Determines whether a type is non-scalar type that is a valid kernel generator
Expand All @@ -26,7 +31,6 @@ template <typename T, typename = void>
struct is_kernel_expression_and_not_scalar
: bool_constant<std::is_base_of<operation_cl_base,
std::remove_reference_t<T>>::value> {};

template <typename T>
struct is_kernel_expression_and_not_scalar<T, require_matrix_cl_t<T>>
: std::true_type {};
Expand Down Expand Up @@ -57,8 +61,21 @@ using require_all_kernel_expressions_and_none_scalar_t
template <typename... Types>
using require_all_kernel_expressions_t
= require_all_t<is_kernel_expression<Types>...>;

/**
* Determines whether a type is an assignable kernel generator
* expression.
*/
template <typename T, typename = void>
struct is_kernel_expression_lhs
: bool_constant<std::is_base_of<operation_cl_lhs_base,
std::remove_reference_t<T>>::value> {};
template <typename T>
struct is_kernel_expression_lhs<T, require_matrix_cl_t<T>> : std::true_type {};

/** @}*/
} // namespace math
STAN_ADD_REQUIRE_UNARY(kernel_expression_lhs, is_kernel_expression_lhs,
opencl_kernel_generator);
} // namespace stan

#endif
Expand Down
7 changes: 7 additions & 0 deletions stan/math/opencl/kernel_generator/operation_cl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ class operation_cl : public operation_cl_base {
* @return number of rows
*/
inline int rows() const {
static_assert(
N > 0, "default rows does not work on expressions with no arguments!");
return index_apply<N>([&](auto... Is) {
// assuming all non-dynamic sizes match
return std::max({this->get_arg<Is>().rows()...});
Expand All @@ -326,6 +328,8 @@ class operation_cl : public operation_cl_base {
* @return number of columns
*/
inline int cols() const {
static_assert(
N > 0, "default cols does not work on expressions with no arguments!");
return index_apply<N>([&](auto... Is) {
// assuming all non-dynamic sizes match
return std::max({this->get_arg<Is>().cols()...});
Expand All @@ -352,6 +356,9 @@ class operation_cl : public operation_cl_base {
* @return pair of indices - bottom and top diagonal
*/
inline std::pair<int, int> extreme_diagonals() const {
static_assert(N > 0,
"default extreme_diagonals does not work on expressions with "
"no arguments!");
return index_apply<N>([&](auto... Is) {
auto arg_diags
= std::make_tuple(this->get_arg<Is>().extreme_diagonals()...);
Expand Down
3 changes: 2 additions & 1 deletion stan/math/opencl/kernel_generator/operation_cl_lhs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ namespace math {
* @tparam Args types of arguments to this operation
*/
template <typename Derived, typename Scalar, typename... Args>
class operation_cl_lhs : public operation_cl<Derived, Scalar, Args...> {
class operation_cl_lhs : public operation_cl<Derived, Scalar, Args...>,
public operation_cl_lhs_base {
protected:
using base = operation_cl<Derived, Scalar, Args...>;
static constexpr int N = sizeof...(Args);
Expand Down
2 changes: 1 addition & 1 deletion stan/math/opencl/kernel_generator/scalar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace math {
*/
template <typename T>
class scalar_ : public operation_cl<scalar_<T>, T> {
private:
protected:
T a_;

public:
Expand Down
94 changes: 81 additions & 13 deletions stan/math/opencl/rev/copy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,76 @@
namespace stan {
namespace math {

namespace internal {
template <typename T_arg_adj, require_eigen_t<T_arg_adj>* = nullptr>
class op_copy_to_cl_vari final
: public vari_value<matrix_cl<value_type_t<T_arg_adj>>> {
T_arg_adj arg_adj_;

public:
template <typename T_arg_val, require_eigen_t<T_arg_val>* = nullptr,
require_vt_same<T_arg_val, T_arg_adj>* = nullptr>
explicit op_copy_to_cl_vari(const T_arg_val& val, T_arg_adj adj)
: vari_value<matrix_cl<value_type_t<T_arg_adj>>>(to_matrix_cl(val)),
arg_adj_(adj) {}

virtual void chain() {
arg_adj_ += from_matrix_cl<std::decay_t<T_arg_adj>::RowsAtCompileTime,
std::decay_t<T_arg_adj>::ColsAtCompileTime>(
this->adj_);
}
};
} // namespace internal

/** \ingroup opencl
* Copies the source var containing Eigen matrices to destination var that has
* data stored on the OpenCL device.
*
* @tparam T type of the Eigen matrix
* @param a source Eigen matrix
* @return var with a copy of the data on the OpenCL device
*/
template <typename T>
inline var_value<matrix_cl<value_type_t<T>>> to_matrix_cl(
const var_value<T>& a) {
return new internal::op_copy_to_cl_vari<decltype(a.vi_->adj_)>(a.val(),
a.vi_->adj_);
}

namespace internal {
template <typename T, int Rows, int Cols,
require_all_kernel_expressions_t<T>* = nullptr>
class op_copy_from_cl_vari final
: public vari_value<Eigen::Matrix<value_type_t<T>, Rows, Cols>> {
vari_value<T>& a_;

public:
explicit op_copy_from_cl_vari(vari_value<T>& a)
: vari_value<Eigen::Matrix<value_type_t<T>, Rows, Cols>>(
from_matrix_cl<Rows, Cols>(a.val_)),
a_(a) {}

virtual void chain() { a_.adj_ = a_.adj_ + to_matrix_cl(this->adj_); }
};
} // namespace internal

/** \ingroup opencl
* Copies the source var that has data stored on the OpenCL device to
* destination var containing Eigen matrices.
*
* @tparam Rows number of compile time rows of the destination matrix
* @tparam Rows number of compile time columns of the destination matrix
* @tparam T type of the matrix or expression on the OpenCL device
* @param a source matrix_cl or expression
* @return var with a copy of the data on the host
*/
template <int Rows = Eigen::Dynamic, int Cols = Eigen::Dynamic, typename T,
require_all_kernel_expressions_t<T>* = nullptr>
inline var_value<Eigen::Matrix<value_type_t<T>, Rows, Cols>> from_matrix_cl(
const var_value<T>& a) {
return new internal::op_copy_from_cl_vari<T, Rows, Cols>(*a.vi_);
}

/** \ingroup opencl
* Copies the source Eigen matrix of vars to
* the destination matrix that is stored
Expand All @@ -26,19 +96,17 @@ namespace math {
* @param src source Eigen matrix
* @return matrix_cl with a copy of the data in the source matrix
*/
template <typename T, int R, int C, require_var_t<T>* = nullptr>
inline matrix_cl<T> to_matrix_cl(const Eigen::Matrix<T, R, C>& src) try {
matrix_cl<T> dst(src.rows(), src.cols());
if (src.size() == 0) {
return dst;
}
dst.val() = to_matrix_cl(src.val().eval());
dst.adj() = to_matrix_cl(src.adj().eval());
return dst;
} catch (const cl::Error& e) {
check_opencl_error("copy var Eigen->(OpenCL)", e);
matrix_cl<T> dst(src.rows(), src.cols());
return dst;
template <typename T, require_eigen_vt<is_var, T>* = nullptr>
inline var_value<matrix_cl<value_type_t<value_type_t<T>>>> to_matrix_cl(
const T& src) {
// the matrix can go out of scope before chain() is called. So we store a map
// to the data
var* src_array
= ChainableStack::instance_->memalloc_.alloc_array<var>(src.size());
Eigen::Map<plain_type_t<T>> src_stacked(src_array, src.rows(), src.cols());
src_stacked = src;
return new internal::op_copy_to_cl_vari<decltype(src_stacked.adj())>(
src_stacked.val(), src_stacked.adj());
}

/** \ingroup opencl
Expand Down
Loading