├── share ├── src │ └── bi │ │ ├── bugs.hpp │ │ ├── cuda │ │ ├── math │ │ │ ├── multi_operation.hpp │ │ │ ├── magma.cu │ │ │ ├── cublas.cu │ │ │ ├── sim_temp_vector.hpp │ │ │ ├── magma.hpp │ │ │ ├── temp_vector.hpp │ │ │ ├── sim_temp_matrix.hpp │ │ │ └── temp_matrix.hpp │ │ ├── random │ │ │ ├── RandomKernel.cu │ │ │ └── RandomGPU.cu │ │ ├── resampler │ │ │ ├── misc.hpp │ │ │ ├── StratifiedResamplerGPU.cuh │ │ │ ├── MultinomialResamplerGPU.hpp │ │ │ └── StratifiedResamplerKernel.cuh │ │ ├── thread.cuh │ │ ├── updater │ │ │ ├── StaticUpdaterGPU.cuh │ │ │ ├── SparseStaticUpdaterGPU.cuh │ │ │ ├── DynamicUpdaterGPU.cuh │ │ │ ├── SparseStaticSamplerGPU.cuh │ │ │ ├── StaticSamplerGPU.cuh │ │ │ ├── StaticLogDensityGPU.cuh │ │ │ ├── StaticMaxLogDensityGPU.cuh │ │ │ ├── StaticUpdaterKernel.cuh │ │ │ ├── SparseStaticLogDensityGPU.cuh │ │ │ ├── DynamicSamplerGPU.cuh │ │ │ ├── DynamicLogDensityGPU.cuh │ │ │ ├── SparseStaticMaxLogDensityGPU.cuh │ │ │ ├── DynamicMaxLogDensityGPU.cuh │ │ │ └── SparseStaticUpdaterKernel.cuh │ │ ├── cache │ │ │ └── AncestryCacheKernel.cuh │ │ └── ode │ │ │ └── RK4IntegratorGPU.cuh │ │ ├── bi.cpp │ │ ├── math │ │ ├── matrix.hpp │ │ ├── vector.hpp │ │ ├── temp_matrix.hpp │ │ ├── temp_vector.hpp │ │ ├── io.hpp │ │ ├── scalar.hpp │ │ ├── pi.hpp │ │ ├── gsl.hpp │ │ ├── loc_vector.hpp │ │ ├── loc_temp_vector.hpp │ │ ├── loc_matrix.hpp │ │ ├── loc_temp_matrix.hpp │ │ └── sim_temp_vector.hpp │ │ ├── kd │ │ └── partition.hpp │ │ ├── resampler │ │ ├── RejectionResampler.cpp │ │ ├── MultinomialResampler.cpp │ │ ├── StratifiedResampler.cpp │ │ ├── SystematicResampler.cpp │ │ ├── MetropolisResampler.cpp │ │ └── Resampler.cpp │ │ ├── misc │ │ ├── macro.hpp │ │ ├── location.hpp │ │ ├── exception.hpp │ │ ├── compile.hpp │ │ ├── TicToc.hpp │ │ └── omp.hpp │ │ ├── null │ │ ├── SMCNullBuffer.cpp │ │ ├── MCMCNullBuffer.cpp │ │ ├── KalmanFilterNullBuffer.cpp │ │ ├── ParticleFilterNullBuffer.cpp │ │ ├── InputNullBuffer.cpp │ │ ├── OptimiserNullBuffer.cpp │ │ ├── SimulatorNullBuffer.cpp │ │ ├── OptimiserNullBuffer.hpp │ │ ├── SMCNullBuffer.hpp │ │ └── MCMCNullBuffer.hpp │ │ ├── host │ │ ├── math │ │ │ ├── qrupdate.cpp │ │ │ ├── lapack.cpp │ │ │ ├── cblas.cpp │ │ │ ├── sim_temp_vector.hpp │ │ │ ├── qrupdate.hpp │ │ │ └── sim_temp_matrix.hpp │ │ ├── random │ │ │ └── RandomHost.cpp │ │ ├── resampler │ │ │ └── MetropolisResamplerHost.hpp │ │ └── updater │ │ │ ├── StaticSamplerMatrixVisitorHost.hpp │ │ │ ├── StaticLogDensityMatrixVisitorHost.hpp │ │ │ └── StaticMaxLogDensityMatrixVisitorHost.hpp │ │ ├── mpi │ │ ├── mpi.cpp │ │ └── mpi.hpp │ │ ├── state │ │ └── ScheduleIterator.hpp │ │ ├── typelist │ │ ├── empty.hpp │ │ ├── equals.hpp │ │ ├── pop_front_spec.hpp │ │ ├── front_spec.hpp │ │ ├── push_back_spec.hpp │ │ ├── append.hpp │ │ ├── front.hpp │ │ ├── index.hpp │ │ ├── contains.hpp │ │ ├── typelist.hpp │ │ ├── back.hpp │ │ ├── push_front.hpp │ │ ├── push_front_list.hpp │ │ └── runtime.hpp │ │ ├── concept │ │ ├── Norm.hpp │ │ ├── Kernel.hpp │ │ ├── ConditionalPdf.hpp │ │ └── Partitioner.hpp │ │ ├── traits │ │ ├── resampler_traits.hpp │ │ └── dim_traits.hpp │ │ ├── method │ │ └── misc.hpp │ │ ├── random │ │ └── Random.cpp │ │ ├── sse │ │ └── math │ │ │ └── scalar.hpp │ │ ├── buffer │ │ └── buffer.hpp │ │ ├── netcdf │ │ ├── NetCDFBuffer.cpp │ │ └── NetCDFBuffer.hpp │ │ ├── init.hpp │ │ ├── primitive │ │ ├── cross_range.hpp │ │ ├── repeated_sequence.hpp │ │ ├── stuttered_sequence.hpp │ │ ├── pitched_range.hpp │ │ ├── strided_range.hpp │ │ └── strided_pitched_range.hpp │ │ └── ode │ │ └── IntegratorConstants.hpp ├── tt │ ├── package │ │ ├── config.conf.tt │ │ ├── VERSION.md.tt │ │ ├── run.sh.tt │ │ ├── init.sh.tt │ │ ├── MANIFEST.tt │ │ ├── META.yml.tt │ │ ├── README.md.tt │ │ └── Model.bi.tt │ ├── bi │ │ ├── var_group.bi.tt │ │ ├── const.bi.tt │ │ ├── inline.bi.tt │ │ ├── dim.bi.tt │ │ ├── var.bi.tt │ │ ├── macro │ │ │ ├── dim_list.bi.tt │ │ │ └── arg_list.bi.tt │ │ ├── action.bi.tt │ │ ├── block.bi.tt │ │ └── model.bi.tt │ ├── cpp │ │ ├── test │ │ │ ├── test_filter_gpu.cu.tt │ │ │ ├── test_gpu.cu.tt │ │ │ └── test_resampler_gpu.cu.tt │ │ ├── action │ │ │ ├── misc │ │ │ │ ├── footer.hpp.tt │ │ │ │ └── header.hpp.tt │ │ │ ├── cholesky.hpp.tt │ │ │ ├── std_.hpp.tt │ │ │ ├── transpose.hpp.tt │ │ │ ├── exclusive_scan.hpp.tt │ │ │ ├── inclusive_scan.hpp.tt │ │ │ ├── eval_.hpp.tt │ │ │ ├── gemm_.hpp.tt │ │ │ ├── gemv_.hpp.tt │ │ │ └── ode_.hpp.tt │ │ ├── block │ │ │ ├── misc │ │ │ │ ├── footer.hpp.tt │ │ │ │ └── header.hpp.tt │ │ │ ├── initial.hpp.tt │ │ │ ├── bridge.hpp.tt │ │ │ ├── proposal_initial.hpp.tt │ │ │ ├── lookahead_transition.hpp.tt │ │ │ ├── proposal_parameter.hpp.tt │ │ │ ├── lookahead_observation.hpp.tt │ │ │ ├── matrix_.hpp.tt │ │ │ ├── parameter.hpp.tt │ │ │ ├── wiener_.hpp.tt │ │ │ ├── std_.hpp.tt │ │ │ └── const_std_.hpp.tt │ │ ├── client │ │ │ ├── filter_gpu.cu.tt │ │ │ ├── sample_gpu.cu.tt │ │ │ ├── optimise_gpu.cu.tt │ │ │ └── misc │ │ │ │ └── header.cpp.tt │ │ ├── macro │ │ │ ├── put_output.hpp.tt │ │ │ ├── create_action_typedef.hpp.tt │ │ │ ├── create_block_typedef.hpp.tt │ │ │ ├── create_action_typetree.hpp.tt │ │ │ ├── create_action_typelist.hpp.tt │ │ │ ├── create_block_typelist.hpp.tt │ │ │ ├── alias_dims.hpp.tt │ │ │ ├── std_action.hpp.tt │ │ │ └── offset_coord.hpp.tt │ │ ├── model.cpp.tt │ │ ├── macro.hpp.tt │ │ └── dim.hpp.tt │ └── dot │ │ ├── action.dot.tt │ │ ├── model.dot.tt │ │ ├── block.dot.tt │ │ └── var.dot.tt ├── autogen.sh ├── nvcc_wrapper.pl └── bi.lex ├── docs ├── .gitignore └── pdf │ └── manual.pdf ├── t ├── 001_load.t ├── 010_cpu.t ├── 002_help.t ├── 003_gen.t └── 004_build_tools.t ├── MakeManifest.PL ├── test.conf ├── MakeParser.PL ├── .includepath ├── .gitignore ├── Test.bi ├── lib └── Bi │ ├── Action │ ├── normal.pm │ ├── log_normal.pm │ ├── truncated_normal.pm │ ├── log_gaussian.pm │ ├── wiener.pm │ ├── exclusive_scan.pm │ ├── inclusive_scan.pm │ └── transpose.pm │ ├── Client │ ├── optimize.pm │ ├── rewrite.pm │ └── draw.pm │ ├── Block │ ├── eval_.pm │ ├── matrix_.pm │ ├── pdf_.pm │ ├── cholesky_.pm │ ├── bridge.pm │ ├── wiener_.pm │ ├── proposal_parameter.pm │ ├── lookahead_observation.pm │ ├── lookahead_transition.pm │ ├── std_.pm │ ├── proposal_initial.pm │ ├── const_std_.pm │ ├── common_std_.pm │ ├── observation.pm │ └── orthogonal_std_.pm │ ├── Test │ └── test.pm │ ├── Visitor │ ├── EvalConst.pm │ └── TargetReplacer.pm │ └── Visitor.pm ├── MANIFEST.SKIP ├── inc └── Module │ └── Install │ ├── Scripts.pm │ ├── Base.pm │ └── WriteAll.pm ├── script ├── libbi └── bi ├── README.md ├── .project ├── Makefile.PL └── INSTALL_LINUX.md /share/src/bi/bugs.hpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | /tex 2 | /dev 3 | -------------------------------------------------------------------------------- /share/tt/package/config.conf.tt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /share/tt/package/VERSION.md.tt: -------------------------------------------------------------------------------- 1 | v1.0.0 2 | ------ 3 | 4 | * First version. 5 | -------------------------------------------------------------------------------- /t/001_load.t: -------------------------------------------------------------------------------- 1 | use Test::More tests => 1; 2 | 3 | BEGIN { use_ok('Bi'); } 4 | -------------------------------------------------------------------------------- /share/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | #libtoolize 4 | autoreconf --install 5 | 6 | -------------------------------------------------------------------------------- /docs/pdf/manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohannesBuchner/LibBi/master/docs/pdf/manual.pdf -------------------------------------------------------------------------------- /MakeManifest.PL: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use ExtUtils::Manifest qw(mkmanifest); 4 | 5 | mkmanifest; 6 | -------------------------------------------------------------------------------- /t/010_cpu.t: -------------------------------------------------------------------------------- 1 | use Test::More tests => 1; 2 | 3 | is(system('script/libbi sample @test.conf') >> 8, 0, 'CPU'); 4 | -------------------------------------------------------------------------------- /share/tt/package/run.sh.tt: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | libbi sample @config.conf --target prior --model-file [% name %].bi 4 | -------------------------------------------------------------------------------- /test.conf: -------------------------------------------------------------------------------- 1 | --target prior 2 | --model-file Test.bi 3 | --end-time 1 4 | --nsamples 32 5 | --output-file test.nc 6 | -------------------------------------------------------------------------------- /t/002_help.t: -------------------------------------------------------------------------------- 1 | use Test::More tests => 1; 2 | 3 | is(system('script/libbi help >/dev/null') >> 8, 0, 'help system'); 4 | -------------------------------------------------------------------------------- /MakeParser.PL: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | `mkdir -p lib/Parse`; 4 | `yapp -m Parse::Bi -o lib/Parse/Bi.pm share/bi.yp`; 5 | -------------------------------------------------------------------------------- /.includepath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /share/tt/bi/var_group.bi.tt: -------------------------------------------------------------------------------- 1 | 2 | // Variable group [% var_group.get_name %] 3 | [% INCLUDE var.bi.tt FOREACH var IN var_group.get_vars-%] 4 | -------------------------------------------------------------------------------- /share/tt/package/init.sh.tt: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | libbi sample @config.conf --target joint --model-file [% name %].bi --output-file data/obs.nc 4 | -------------------------------------------------------------------------------- /t/003_gen.t: -------------------------------------------------------------------------------- 1 | use Test::More tests => 1; 2 | 3 | is(system('script/libbi sample @test.conf --dry-build --dry-run') >> 8, 0, 'code generation'); 4 | -------------------------------------------------------------------------------- /share/tt/cpp/test/test_filter_gpu.cu.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | %] 6 | 7 | #include "test_filter_cpu.cpp" 8 | -------------------------------------------------------------------------------- /share/tt/package/MANIFEST.tt: -------------------------------------------------------------------------------- 1 | MANIFEST 2 | LICENSE 3 | META.yml 4 | README.md 5 | VERSION.md 6 | init.sh 7 | run.sh 8 | [% name %].bi 9 | config.conf 10 | data 11 | -------------------------------------------------------------------------------- /share/tt/package/META.yml.tt: -------------------------------------------------------------------------------- 1 | name: [% name %] 2 | version: 1.0.0 3 | author: 4 | email: 5 | website-url: 6 | download-url: 7 | github-url: 8 | description: 9 | 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /Makefile 2 | /MANIFEST.bak 3 | /META.yml 4 | /MYMETA.json 5 | /MYMETA.yml 6 | /Makefile.old 7 | /.LibBi 8 | /.Test 9 | /blib 10 | /pm_to_blib 11 | /test.nc 12 | -------------------------------------------------------------------------------- /share/tt/cpp/action/misc/footer.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /share/tt/cpp/block/misc/footer.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /share/tt/cpp/test/test_gpu.cu.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | #include "test_cpu.cpp" 10 | -------------------------------------------------------------------------------- /share/tt/bi/const.bi.tt: -------------------------------------------------------------------------------- 1 | [%- 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | -%] 8 | const [% const.get_name %] = [% const.get_expr.to_bi %] 9 | -------------------------------------------------------------------------------- /share/tt/bi/inline.bi.tt: -------------------------------------------------------------------------------- 1 | [%- 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | -%] 8 | inline [% inline.get_name %] = [% inline.get_expr.to_bi %] 9 | -------------------------------------------------------------------------------- /share/tt/cpp/block/initial.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | [%-PROCESS block/parameter.hpp.tt-%] 10 | -------------------------------------------------------------------------------- /share/tt/cpp/block/bridge.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | [% PROCESS block/observation.hpp.tt %] 10 | -------------------------------------------------------------------------------- /share/tt/cpp/block/proposal_initial.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | [% PROCESS block/initial.hpp.tt %] 10 | -------------------------------------------------------------------------------- /share/tt/cpp/test/test_resampler_gpu.cu.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | #include "test_resampler_cpu.cpp" 10 | -------------------------------------------------------------------------------- /share/tt/cpp/block/lookahead_transition.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | [% PROCESS block/transition.hpp.tt %] 10 | -------------------------------------------------------------------------------- /share/tt/cpp/block/proposal_parameter.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | [% PROCESS block/parameter.hpp.tt %] 10 | -------------------------------------------------------------------------------- /share/tt/cpp/block/lookahead_observation.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | [% PROCESS block/observation.hpp.tt %] 10 | -------------------------------------------------------------------------------- /share/tt/bi/dim.bi.tt: -------------------------------------------------------------------------------- 1 | [%- 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | PROCESS macro/arg_list.bi.tt 8 | -%] 9 | dim [% dim.get_name %][% arg_list(dim) %] 10 | -------------------------------------------------------------------------------- /share/tt/package/README.md.tt: -------------------------------------------------------------------------------- 1 | LibBi package: [% name %] 2 | ========================= 3 | 4 | Synopsis 5 | -------- 6 | 7 | ./run.sh 8 | 9 | Description 10 | ----------- 11 | 12 | 13 | References 14 | ---------- 15 | -------------------------------------------------------------------------------- /share/tt/cpp/client/filter_gpu.cu.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | [%-PROCESS client/misc/header.cpp.tt-%] 10 | 11 | #include "filter_cpu.cpp" 12 | -------------------------------------------------------------------------------- /share/tt/cpp/client/sample_gpu.cu.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | [%-PROCESS client/misc/header.cpp.tt-%] 10 | 11 | #include "sample_cpu.cpp" 12 | -------------------------------------------------------------------------------- /share/tt/cpp/block/matrix_.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev: 3232 $ 6 | ## $Date: 2012-10-16 14:09:21 +0800 (Tue, 16 Oct 2012) $ 7 | %] 8 | 9 | [%-PROCESS block/eval_.hpp.tt %] 10 | -------------------------------------------------------------------------------- /share/tt/cpp/client/optimise_gpu.cu.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | [%-PROCESS client/misc/header.cpp.tt-%] 10 | 11 | #include "optimise_cpu.cpp" 12 | -------------------------------------------------------------------------------- /share/tt/bi/var.bi.tt: -------------------------------------------------------------------------------- 1 | [%- 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | PROCESS macro/dim_list.bi.tt 8 | -%] 9 | [% var.get_type %] [% var.get_name %][% dim_list(var) %][% arg_list(var) %] 10 | -------------------------------------------------------------------------------- /t/004_build_tools.t: -------------------------------------------------------------------------------- 1 | use Test::More tests => 3; 2 | 3 | is(system('make --version >/dev/null') >> 8, 0, 'make presence'); 4 | is(system('automake --version >/dev/null') >> 8, 0, 'automake presence'); 5 | is(system('autoconf --version >/dev/null') >> 8, 0, 'autoconf presence'); 6 | -------------------------------------------------------------------------------- /share/src/bi/cuda/math/multi_operation.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_MATH_MULTIOPERATION_HPP 9 | #define BI_CUDA_MATH_MULTIOPERATION_HPP 10 | 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /share/tt/dot/action.dot.tt: -------------------------------------------------------------------------------- 1 | [%- 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | -%] 8 | [%-FOREACH ref IN action.get_all_right_var_refs %] 9 | [% ref.get_var.get_name %] -> [% action.get_left.get_var.get_name %]; 10 | [%-END-%] 11 | -------------------------------------------------------------------------------- /share/tt/cpp/macro/put_output.hpp.tt: -------------------------------------------------------------------------------- 1 | [%- 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | -%] 8 | [%-MACRO put_output(action, expr) BLOCK-%] 9 | x.template fetch(s, p, cox_.index()) = [% expr.to_cpp %]; 10 | [%-END-%] 11 | -------------------------------------------------------------------------------- /share/src/bi/bi.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * This file exists only to readily facilitate autoconf checks for the 5 | * presence of libbi. 6 | * 7 | * @author Lawrence Murray 8 | * $Rev$ 9 | * $Date$ 10 | */ 11 | int main(int argc, char** argv) { 12 | // 13 | } 14 | -------------------------------------------------------------------------------- /share/src/bi/math/matrix.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_MATH_MATRIX_HPP 9 | #define BI_MATH_MATRIX_HPP 10 | 11 | #include "../host/math/matrix.hpp" 12 | #ifdef ENABLE_CUDA 13 | #include "../cuda/math/matrix.hpp" 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /share/src/bi/math/vector.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_MATH_VECTOR_HPP 9 | #define BI_MATH_VECTOR_HPP 10 | 11 | #include "../host/math/vector.hpp" 12 | #ifdef ENABLE_CUDA 13 | #include "../cuda/math/vector.hpp" 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /Test.bi: -------------------------------------------------------------------------------- 1 | model Test { 2 | param theta, sigma2; 3 | noise w; 4 | state x; 5 | 6 | sub parameter { 7 | theta ~ gaussian(); 8 | sigma2 ~ inverse_gamma(); 9 | } 10 | 11 | sub initial { 12 | x ~ gaussian(); 13 | } 14 | 15 | sub transition { 16 | w ~ gaussian(0.0, sqrt(sigma2)); 17 | x <- theta*x + w; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /share/src/bi/kd/partition.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_KD_PARTITION_HPP 9 | #define BI_KD_PARTITION_HPP 10 | 11 | namespace bi { 12 | /** 13 | * Partitions. 14 | */ 15 | enum Partition { 16 | LEFT, 17 | RIGHT 18 | }; 19 | } 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /share/src/bi/resampler/RejectionResampler.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #include "RejectionResampler.hpp" 9 | 10 | bi::RejectionResampler::RejectionResampler() : 11 | Resampler(1.0, 1.0) { 12 | // ^ the arguments (0.0, 0.0) force resampling at all times. 13 | } 14 | -------------------------------------------------------------------------------- /share/tt/cpp/action/cholesky.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | %] 6 | 7 | [%-PROCESS action/misc/header.hpp.tt-%] 8 | 9 | /** 10 | * Action: [% action.get_name %]. 11 | */ 12 | class [% class_name %] { 13 | public: 14 | [% std_action %] 15 | 16 | }; 17 | 18 | [%-PROCESS action/misc/footer.hpp.tt-%] 19 | -------------------------------------------------------------------------------- /share/tt/cpp/macro/create_action_typedef.hpp.tt: -------------------------------------------------------------------------------- 1 | [%- 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | -%] 8 | [%-MACRO create_action_typedef(block) BLOCK %] 9 | /** 10 | * Type list for actions. 11 | */ 12 | typedef GET_TYPETREE(Block[% block.get_id %]ActionTypeList) action_typelist; 13 | [% END-%] 14 | -------------------------------------------------------------------------------- /share/tt/cpp/macro/create_block_typedef.hpp.tt: -------------------------------------------------------------------------------- 1 | [%- 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | -%] 8 | [%-MACRO create_block_typedef(block) BLOCK %] 9 | /** 10 | * Type list of sub-blocks. 11 | */ 12 | typedef GET_TYPETREE(Block[% block.get_id %]BlockTypeList) block_typelist; 13 | [% END-%] 14 | -------------------------------------------------------------------------------- /share/src/bi/math/temp_matrix.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_MATH_TEMPMATRIX_HPP 9 | #define BI_MATH_TEMPMATRIX_HPP 10 | 11 | #include "../host/math/temp_matrix.hpp" 12 | #ifdef ENABLE_CUDA 13 | #include "../cuda/math/temp_matrix.hpp" 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /share/src/bi/math/temp_vector.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_MATH_TEMPVECTOR_HPP 9 | #define BI_MATH_TEMPVECTOR_HPP 10 | 11 | #include "../host/math/temp_vector.hpp" 12 | #ifdef ENABLE_CUDA 13 | #include "../cuda/math/temp_vector.hpp" 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /lib/Bi/Action/normal.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | normal - normal distribution, synonym of L. 4 | 5 | =head1 SEE ALSO 6 | 7 | L 8 | 9 | =cut 10 | 11 | package Bi::Action::normal; 12 | 13 | use parent 'Bi::Action::gaussian'; 14 | 15 | 1; 16 | 17 | =head1 AUTHOR 18 | 19 | Lawrence Murray 20 | 21 | =head1 VERSION 22 | 23 | $Rev$ $Date$ 24 | -------------------------------------------------------------------------------- /share/src/bi/math/io.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * IO functions for matrix and vector types. 5 | * 6 | * @author Lawrence Murray 7 | * $Rev$ 8 | * $Date$ 9 | */ 10 | #ifndef BI_MATH_IO_HPP 11 | #define BI_MATH_IO_HPP 12 | 13 | #include "../host/math/io.hpp" 14 | #ifdef ENABLE_CUDA 15 | #include "../cuda/math/io.hpp" 16 | #endif 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /share/tt/bi/macro/dim_list.bi.tt: -------------------------------------------------------------------------------- 1 | [%- 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | -%] 8 | 9 | [%-MACRO dim_list(var) BLOCK-%] 10 | [%-'[' IF var.get_dims.size-%] 11 | [%-FOREACH dim IN var.get_dims-%] 12 | [%-dim.get_name-%] 13 | [%-IF !loop.last %],[% END-%] 14 | [%-END-%] 15 | [%-']' IF var.get_dims.size-%] 16 | [%-END-%] 17 | -------------------------------------------------------------------------------- /share/tt/cpp/macro/create_action_typetree.hpp.tt: -------------------------------------------------------------------------------- 1 | [%- 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | -%] 8 | [%-MACRO create_action_typetree(block) BLOCK-%] 9 | /** 10 | * Type tree for actions. 11 | */ 12 | BEGIN_TYPETREE(Block[% block.get_id %]ActionTypeList) 13 | [% block.get_actions.to_typetree %] 14 | END_TYPETREE() 15 | [% END %] 16 | -------------------------------------------------------------------------------- /share/src/bi/resampler/MultinomialResampler.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #include "MultinomialResampler.hpp" 9 | 10 | bi::MultinomialResampler::MultinomialResampler(const bool sort, 11 | const double essRel, const double bridgeEssRel) : 12 | Resampler(essRel, bridgeEssRel), sort(sort) { 13 | // 14 | } 15 | -------------------------------------------------------------------------------- /share/src/bi/resampler/StratifiedResampler.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #include "StratifiedResampler.hpp" 9 | 10 | bi::StratifiedResampler::StratifiedResampler(const bool sort, 11 | const double essRel, const double bridgeEssRel) : 12 | Resampler(essRel, bridgeEssRel), sort(sort) { 13 | // 14 | } 15 | -------------------------------------------------------------------------------- /share/src/bi/resampler/SystematicResampler.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #include "SystematicResampler.hpp" 9 | 10 | bi::SystematicResampler::SystematicResampler(const bool sort, 11 | const double essRel, const double bridgeEssRel) : 12 | Resampler(essRel, bridgeEssRel), sort(sort) { 13 | // 14 | } 15 | -------------------------------------------------------------------------------- /lib/Bi/Action/log_normal.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | log_normal - log-normal distribution, synonym of L. 4 | 5 | =head1 SEE ALSO 6 | 7 | L 8 | 9 | =cut 10 | 11 | package Bi::Action::log_normal; 12 | 13 | use parent 'Bi::Action::gaussian'; 14 | 15 | 1; 16 | 17 | =head1 AUTHOR 18 | 19 | Lawrence Murray 20 | 21 | =head1 VERSION 22 | 23 | $Rev$ $Date$ 24 | -------------------------------------------------------------------------------- /MANIFEST.SKIP: -------------------------------------------------------------------------------- 1 | ~$ 2 | \.svn 3 | \.git 4 | \.Bi 5 | \.LibBi 6 | \.Test 7 | \.#MANIFEST.SKIP 8 | \.includepath 9 | \.project 10 | ^MANIFEST\.bak$ 11 | ^docs/dev 12 | ^docs/html 13 | ^docs/tex 14 | ^eclipse 15 | ^LibBi.* 16 | ^libbi.* 17 | ^Makefile$ 18 | ^Makefile\.old$ 19 | ^MakeManifest.PL$ 20 | ^MANIFEST$ 21 | ^MANIFEST.SKIP$ 22 | ^META.yml$ 23 | ^MYMETA.json$ 24 | ^MYMETA.yml$ 25 | ^_site 26 | ^blib 27 | ^pm_to_blib 28 | -------------------------------------------------------------------------------- /share/tt/cpp/action/std_.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev: 3273 $ 6 | ## $Date: 2012-11-05 13:26:38 +0800 (Mon, 05 Nov 2012) $ 7 | %] 8 | 9 | [%-PROCESS action/misc/header.hpp.tt-%] 10 | 11 | /** 12 | * Action: [% action.get_name %]. 13 | */ 14 | struct [% class_name %] { 15 | [% std_action %] 16 | }; 17 | 18 | [%-PROCESS action/misc/footer.hpp.tt-%] 19 | -------------------------------------------------------------------------------- /share/src/bi/misc/macro.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | * 8 | * Useful macros for defining other macros... 9 | */ 10 | #ifndef BI_MISC_MACRO_HPP 11 | #define BI_MISC_MACRO_HPP 12 | 13 | /** 14 | * @def MACRO_QUOTE 15 | * 16 | * @arg x 17 | * 18 | * Quotes macro argument as string 19 | */ 20 | #define MACRO_QUOTE(x) #x 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /share/src/bi/null/SMCNullBuffer.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Pierre Jacob 5 | * $Rev $ 6 | * $Date$ 7 | */ 8 | #include "SMCNullBuffer.hpp" 9 | 10 | bi::SMCNullBuffer::SMCNullBuffer(const Model& m, const size_t P, 11 | const size_t T, const std::string& file, const FileMode mode, 12 | const SchemaMode schema) : 13 | MCMCNullBuffer(m, P, T, file, mode, schema) { 14 | // 15 | } 16 | -------------------------------------------------------------------------------- /share/src/bi/cuda/random/RandomKernel.cu: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #include "RandomKernel.cuh" 9 | 10 | CUDA_FUNC_GLOBAL void bi::kernelSeeds(curandStateSA rng, const unsigned seed) { 11 | const int p = blockIdx.x*blockDim.x + threadIdx.x; 12 | RngGPU rng1; 13 | rng.load(p, rng1.r); 14 | rng1.seed(seed); 15 | rng.store(p, rng1.r); 16 | } 17 | -------------------------------------------------------------------------------- /share/src/bi/null/MCMCNullBuffer.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #include "MCMCNullBuffer.hpp" 9 | 10 | bi::MCMCNullBuffer::MCMCNullBuffer(const Model& m, const size_t P, 11 | const size_t T, const std::string& file, const FileMode mode, 12 | const SchemaMode schema) : 13 | SimulatorNullBuffer(m, P, T, file, mode, schema) { 14 | // 15 | } 16 | -------------------------------------------------------------------------------- /lib/Bi/Client/optimize.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | optimize - optimization of the parameters of a model. 4 | 5 | =head1 SEE ALSO 6 | 7 | L 8 | 9 | =cut 10 | 11 | package Bi::Client::optimize; 12 | 13 | use parent 'Bi::Client::optimise'; 14 | 15 | 1; 16 | 17 | =head1 AUTHOR 18 | 19 | Lawrence Murray 20 | 21 | =head1 VERSION 22 | 23 | $Rev: 3483 $ $Date: 2013-02-13 12:08:35 +0800 (Wed, 13 Feb 2013) $ 24 | 25 | -------------------------------------------------------------------------------- /lib/Bi/Action/truncated_normal.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | truncated_normal - truncated normal distribution, synonym of 4 | L. 5 | 6 | =head1 SEE ALSO 7 | 8 | L 9 | 10 | =cut 11 | 12 | package Bi::Action::truncated_normal; 13 | 14 | use parent 'Bi::Action::truncated_gaussian'; 15 | 16 | 1; 17 | 18 | =head1 AUTHOR 19 | 20 | Lawrence Murray 21 | 22 | =head1 VERSION 23 | 24 | $Rev$ $Date$ 25 | -------------------------------------------------------------------------------- /share/tt/cpp/macro/create_action_typelist.hpp.tt: -------------------------------------------------------------------------------- 1 | [%- 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | -%] 8 | [%-MACRO create_action_typelist(block) BLOCK-%] 9 | /** 10 | * Type list for actions. 11 | */ 12 | BEGIN_TYPELIST(Block[% block.get_id %]ActionTypeList) 13 | [% FOREACH action IN block.get_actions-%] 14 | SINGLE_TYPE(1, Action[% action.get_id %]) 15 | [% END-%] 16 | END_TYPELIST() 17 | [% END %] 18 | -------------------------------------------------------------------------------- /share/tt/cpp/macro/create_block_typelist.hpp.tt: -------------------------------------------------------------------------------- 1 | [%- 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | -%] 8 | [%-MACRO create_block_typelist(block) BLOCK %] 9 | /** 10 | * Type list of sub-blocks. 11 | */ 12 | BEGIN_TYPELIST(Block[% block.get_id %]BlockTypeList) 13 | [% FOREACH subblock IN block.get_blocks-%] 14 | SINGLE_TYPE(1, Block[% subblock.get_id %]) 15 | [% END-%] 16 | END_TYPELIST() 17 | [% END-%] 18 | -------------------------------------------------------------------------------- /lib/Bi/Block/eval_.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | eval- - scalar expression block. 4 | 5 | =cut 6 | 7 | package Bi::Block::eval_; 8 | 9 | use parent 'Bi::Block'; 10 | use warnings; 11 | use strict; 12 | 13 | our $BLOCK_ARGS = []; 14 | 15 | sub validate { 16 | my $self = shift; 17 | 18 | $self->process_args($BLOCK_ARGS); 19 | } 20 | 21 | 1; 22 | 23 | =head1 AUTHOR 24 | 25 | Lawrence Murray 26 | 27 | =head1 VERSION 28 | 29 | $Rev$ $Date$ 30 | -------------------------------------------------------------------------------- /share/src/bi/resampler/MetropolisResampler.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #include "MetropolisResampler.hpp" 9 | 10 | bi::MetropolisResampler::MetropolisResampler(const int B, const double essRel, 11 | const double bridgeEssRel) : 12 | Resampler(essRel, bridgeEssRel), B(B) { 13 | // 14 | } 15 | 16 | void bi::MetropolisResampler::setSteps(const int B) { 17 | this->B = B; 18 | } 19 | -------------------------------------------------------------------------------- /share/src/bi/host/math/qrupdate.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #include "qrupdate.hpp" 9 | 10 | #define QRUPDATE_FUNC_DEF(name, dname, sname) \ 11 | BOOST_TYPEOF(sname##_) *bi::qrupdate_##name::func = sname##_; \ 12 | BOOST_TYPEOF(dname##_) *bi::qrupdate_##name::func = dname##_; 13 | 14 | QRUPDATE_FUNC_DEF(ch1up, dch1up, sch1up) 15 | QRUPDATE_FUNC_DEF(ch1dn, dch1dn, sch1dn) 16 | -------------------------------------------------------------------------------- /share/tt/dot/model.dot.tt: -------------------------------------------------------------------------------- 1 | [%- 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | -%] 8 | digraph model { 9 | compound=true; 10 | overlap=scale; 11 | splines=true; 12 | sep=.2; 13 | d2tgraphstyle="scale=0.6" 14 | nslimit=4.0; 15 | mclimit=4.0; 16 | 17 | [% FOREACH name IN ['parameter', 'transition', 'observation'] %] 18 | [%-INCLUDE block.dot.tt block = model.get_block(name) FILTER indent(2) %] 19 | [%-END-%] 20 | } 21 | -------------------------------------------------------------------------------- /share/src/bi/mpi/mpi.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #include "mpi.hpp" 9 | 10 | #include 11 | 12 | std::string bi::append_rank(const std::string& name) { 13 | #ifdef ENABLE_MPI 14 | boost::mpi::communicator world; 15 | std::stringstream stream; 16 | 17 | stream << name << '.' << world.rank(); 18 | 19 | return stream.str(); 20 | #else 21 | return name; 22 | #endif 23 | } 24 | -------------------------------------------------------------------------------- /share/tt/package/Model.bi.tt: -------------------------------------------------------------------------------- 1 | /** 2 | * [% name %] model. 3 | */ 4 | model [% name %] { 5 | // declare constants... 6 | // declare dimensions... 7 | // declare variables... 8 | 9 | sub parameter { 10 | // specify the parameter model 11 | } 12 | 13 | sub initial { 14 | // specify the initial condition model 15 | } 16 | 17 | sub transition { 18 | // specify the transition model 19 | } 20 | 21 | sub observation { 22 | // specify the observation model 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /share/tt/cpp/macro/alias_dims.hpp.tt: -------------------------------------------------------------------------------- 1 | [%- 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | -%] 8 | [%-MACRO alias_dims(action) BLOCK %] 9 | [%-un = 0-%] 10 | [%-FOREACH alias IN action.get_aliases %] 11 | [%-IF alias.has_name -%] 12 | BI_UNUSED const int [% alias.get_name %]_ = cox.i[% loop.index %]; 13 | [%-ELSE-%] 14 | BI_UNUSED const int un[% un; un = un + 1 %] = cox.i[% loop.index %]; 15 | [%-END-%] 16 | [%-END %] 17 | [%-END-%] 18 | -------------------------------------------------------------------------------- /share/src/bi/state/ScheduleIterator.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_STATE_SCHEDULEITERATOR_HPP 9 | #define BI_STATE_SCHEDULEITERATOR_HPP 10 | 11 | #include "ScheduleElement.hpp" 12 | 13 | #include 14 | 15 | namespace bi { 16 | /** 17 | * Iterator over Schedule. 18 | * 19 | * @ingroup state 20 | */ 21 | typedef std::vector::const_iterator ScheduleIterator; 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /share/src/bi/host/math/lapack.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #include "lapack.hpp" 9 | 10 | #define LAPACK_FUNC_DEF(name, dname, sname) \ 11 | BOOST_TYPEOF(sname##_) *bi::lapack_##name::func = sname##_; \ 12 | BOOST_TYPEOF(dname##_) *bi::lapack_##name::func = dname##_; 13 | 14 | LAPACK_FUNC_DEF(potrf, dpotrf, spotrf) 15 | LAPACK_FUNC_DEF(potrs, dpotrs, spotrs) 16 | LAPACK_FUNC_DEF(syevx, dsyevx, ssyevx) 17 | -------------------------------------------------------------------------------- /share/src/bi/misc/location.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_MISC_LOCATION_HPP 9 | #define BI_MISC_LOCATION_HPP 10 | 11 | namespace bi { 12 | /** 13 | * Tags for location-specific data types and operations. 14 | */ 15 | enum Location { 16 | /** 17 | * Locate object on host. 18 | */ 19 | ON_HOST = 0, 20 | 21 | /** 22 | * Locate object on device. 23 | */ 24 | ON_DEVICE = 1 25 | }; 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /share/tt/cpp/client/misc/header.cpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | [%- 10 | IF have_model; 11 | class_name = "Model" _ model.get_name; 12 | ELSE; 13 | class_name = "Model"; 14 | END; 15 | -%] 16 | 17 | /** 18 | * @file 19 | * 20 | * @author Generated by LibBi 21 | * $Rev$ 22 | * $Date$ 23 | */ 24 | #ifdef ENABLE_GPERFTOOLS 25 | #include "google/profiler.h" 26 | #endif 27 | #include "bi/init.hpp" 28 | #include "bi/cuda/cuda.hpp" 29 | #include "bi/mpi/mpi.hpp" 30 | -------------------------------------------------------------------------------- /share/src/bi/mpi/mpi.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_MPI_MPI_HPP 9 | #define BI_MPI_MPI_HPP 10 | 11 | #ifdef ENABLE_MPI 12 | #include 13 | #include "boost/mpi/environment.hpp" 14 | #include "boost/mpi/communicator.hpp" 15 | #endif 16 | 17 | #include 18 | 19 | namespace bi { 20 | /** 21 | * Append rank to file name. 22 | * 23 | * @param name File name. 24 | */ 25 | std::string append_rank(const std::string& name); 26 | 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /share/src/bi/null/KalmanFilterNullBuffer.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #include "KalmanFilterNullBuffer.hpp" 9 | 10 | bi::KalmanFilterNullBuffer::KalmanFilterNullBuffer(const Model& m, 11 | const size_t P, const size_t T, const std::string& file, 12 | const FileMode mode, const SchemaMode schema) : 13 | SimulatorNullBuffer(m, P, T, file, mode, schema) { 14 | // 15 | } 16 | 17 | void bi::KalmanFilterNullBuffer::writeLogLikelihood(const real ll) { 18 | // 19 | } 20 | -------------------------------------------------------------------------------- /share/src/bi/null/ParticleFilterNullBuffer.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #include "ParticleFilterNullBuffer.hpp" 9 | 10 | bi::ParticleFilterNullBuffer::ParticleFilterNullBuffer(const Model& m, 11 | const size_t P, const size_t T, const std::string& file, 12 | const FileMode mode, const SchemaMode schema) : 13 | SimulatorNullBuffer(m, P, T, file, mode, schema) { 14 | // 15 | } 16 | 17 | void bi::ParticleFilterNullBuffer::writeLogLikelihood(const real ll) { 18 | // 19 | } 20 | -------------------------------------------------------------------------------- /share/tt/bi/action.bi.tt: -------------------------------------------------------------------------------- 1 | [%- 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | PROCESS macro/arg_list.bi.tt 8 | -%] 9 | 10 | [%-action.get_left.get_var.get_name-%] 11 | [%-IF action.get_aliases.size-%] 12 | [[% FOREACH alias IN action.get_aliases %][% IF alias.has_name %][% alias.get_name %][% IF alias.has_range %]=[% END %][% END %][% IF alias.has_range %][% alias.get_range.to_bi %][% END %][% IF !loop.last %],[% END %][% END %]] 13 | [%-END-%] [% action.get_op %] [% action.get_name %][% arg_list(action) %] // Action[% action.get_id %] 14 | -------------------------------------------------------------------------------- /lib/Bi/Block/matrix_.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | matrix_ - matrix expression block. 4 | 5 | =head1 DESCRIPTION 6 | 7 | This block behaves the same as L, but is required to group matrix 8 | actions into separate blocks from scalar actions. 9 | 10 | =cut 11 | 12 | package Bi::Block::matrix_; 13 | 14 | use parent 'Bi::Block'; 15 | use warnings; 16 | use strict; 17 | 18 | our $BLOCK_ARGS = []; 19 | 20 | sub validate { 21 | my $self = shift; 22 | 23 | $self->process_args($BLOCK_ARGS); 24 | } 25 | 26 | 1; 27 | 28 | =head1 AUTHOR 29 | 30 | Lawrence Murray 31 | -------------------------------------------------------------------------------- /share/tt/bi/macro/arg_list.bi.tt: -------------------------------------------------------------------------------- 1 | [%- 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | -%] 8 | 9 | [%-MACRO arg_list(item) BLOCK-%] 10 | [%-'(' IF (item.num_args || item.num_named_args)-%] 11 | [%-FOREACH arg IN item.get_args-%] 12 | [%-arg.to_bi %][% IF !(loop.last && item.num_named_args == 0) %], [% END-%] 13 | [%-END-%] 14 | [%-FOREACH name IN item.get_named_args.keys.sort-%] 15 | [%-name %] = [% item.get_named_args.$name.to_bi %][% IF !loop.last %], [% END-%] 16 | [%-END-%] 17 | [%-')' IF (item.num_args || item.num_named_args)-%] 18 | [%-END-%] 19 | -------------------------------------------------------------------------------- /share/src/bi/cuda/resampler/misc.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_RESAMPLER_MISC_HPP 9 | #define BI_CUDA_RESAMPLER_MISC_HPP 10 | 11 | namespace bi { 12 | /** 13 | * Placeholder for passing as argument to kernels to enable pre-permute. 14 | */ 15 | enum EnablePrePermute { 16 | ENABLE_PRE_PERMUTE = 1 17 | }; 18 | 19 | /** 20 | * Placeholder for passing as argument to kernels to disable pre-permute. 21 | */ 22 | enum DisablePrePermute { 23 | DISABLE_PRE_PERMUTE = 0 24 | }; 25 | 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /share/src/bi/resampler/Resampler.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #include "Resampler.hpp" 9 | 10 | bi::Resampler::Resampler(const double essRel, const double bridgeEssRel) : 11 | essRel(essRel), bridgeEssRel(bridgeEssRel), maxLogWeight(0.0) { 12 | /* pre-condition */ 13 | BI_ASSERT(essRel >= 0.0 && essRel <= 1.0); 14 | BI_ASSERT(bridgeEssRel >= 0.0 && bridgeEssRel <= 1.0); 15 | 16 | // 17 | } 18 | 19 | void bi::Resampler::setMaxLogWeight(const double maxLogWeight) { 20 | this->maxLogWeight = maxLogWeight; 21 | } 22 | -------------------------------------------------------------------------------- /share/src/bi/null/InputNullBuffer.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #include "InputNullBuffer.hpp" 9 | 10 | bi::InputNullBuffer::InputNullBuffer(const Model& m, 11 | const std::string& file, const long ns, const long np) { 12 | // 13 | } 14 | 15 | void bi::InputNullBuffer::readMask(const size_t k, const VarType type, 16 | Mask& mask) { 17 | BI_ERROR_MSG(false, "time index outside valid range"); 18 | } 19 | 20 | void bi::InputNullBuffer::readMask0(const VarType type, 21 | Mask& mask) { 22 | mask.clear(); 23 | } 24 | -------------------------------------------------------------------------------- /share/src/bi/null/OptimiserNullBuffer.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #include "OptimiserNullBuffer.hpp" 9 | 10 | bi::OptimiserNullBuffer::OptimiserNullBuffer(const Model& m, const size_t T, 11 | const std::string& file, const FileMode mode, const SchemaMode schema) : 12 | SimulatorNullBuffer(m, 0, T, file, mode, schema) { 13 | // 14 | } 15 | 16 | void bi::OptimiserNullBuffer::writeValue(const size_t k, const real& x) { 17 | // 18 | } 19 | 20 | void bi::OptimiserNullBuffer::writeSize(const size_t k, const real& x) { 21 | // 22 | } 23 | -------------------------------------------------------------------------------- /share/src/bi/cuda/math/magma.cu: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #include "magma.hpp" 9 | 10 | #define MAGMA_FUNC_DEF(name, dname, sname) \ 11 | BOOST_TYPEOF(magma_##sname) *bi::magma_##name::func = magma_##sname; \ 12 | BOOST_TYPEOF(magma_##dname) *bi::magma_##name::func = magma_##dname; 13 | 14 | #ifdef HAVE_MAGMA_H 15 | MAGMA_FUNC_DEF(potrf, dpotrf_gpu, spotrf_gpu) 16 | MAGMA_FUNC_DEF(potrs, dpotrs_gpu, spotrs_gpu) 17 | MAGMA_FUNC_DEF(get_potrf_nb, get_dpotrf_nb, get_spotrf_nb) 18 | //MAGMA_FUNC_DEF(syevx, dsyevx_gpu, ssyevx_gpu) 19 | #endif 20 | -------------------------------------------------------------------------------- /share/src/bi/typelist/empty.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_TYPELIST_EMPTY_HPP 9 | #define BI_TYPELIST_EMPTY_HPP 10 | 11 | #include "typelist.hpp" 12 | 13 | namespace bi { 14 | /** 15 | * Is type list empty? 16 | * 17 | * @ingroup typelist 18 | * 19 | * @tparam T A type list. 20 | */ 21 | template 22 | struct empty { 23 | static const bool value = false; 24 | }; 25 | 26 | /** 27 | * @internal 28 | */ 29 | template<> 30 | struct empty { 31 | static const bool value = true; 32 | }; 33 | 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /share/src/bi/typelist/equals.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_TYPELIST_EQUALS_HPP 9 | #define BI_TYPELIST_EQUALS_HPP 10 | 11 | namespace bi { 12 | /** 13 | * Type equality check. 14 | * 15 | * @ingroup typelist 16 | * 17 | * @tparam X A type. 18 | * @ptaram Y A type. 19 | */ 20 | template 21 | struct equals { 22 | static const bool value = false; 23 | }; 24 | 25 | /** 26 | * @internal 27 | */ 28 | template 29 | struct equals { 30 | static const bool value = true; 31 | }; 32 | 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /share/nvcc_wrapper.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | ## 4 | ## Wrapper around nvcc for compatibility with libtool. 5 | ## 6 | ## @author Lawrence Murray 7 | ## $Rev$ 8 | ## $Date$ 9 | ## 10 | 11 | my @host_args; 12 | my @dev_args; 13 | my $arg; 14 | my $cmd; 15 | 16 | foreach $arg (@ARGV) { 17 | $arg =~ s/(-pthread)/-Xcompiler="$1"/g; 18 | $arg =~ s/-g\d+/-g/g; 19 | $arg =~ s/(-f(?:instrument-functions|unroll-loops|no-inline|PIC))/-Xcompiler="$1"/g; 20 | $arg =~ s/(-D(?:PIC))/-Xcompiler="$1"/g; 21 | 22 | push(@dev_args, $arg); 23 | } 24 | 25 | $cmd = join(' ', @dev_args) . "\n"; 26 | 27 | exec($cmd) || die; 28 | -------------------------------------------------------------------------------- /share/tt/cpp/macro/std_action.hpp.tt: -------------------------------------------------------------------------------- 1 | [%- 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | -%] 8 | [%-MACRO std_action BLOCK %] 9 | /** 10 | * Target type. 11 | */ 12 | typedef Var[% action.get_left.get_var.get_id %] target_type; 13 | 14 | /** 15 | * Coordinate type. 16 | */ 17 | typedef ActionCoord[% action.get_id %] coord_type; 18 | 19 | /** 20 | * Size of the action. 21 | */ 22 | static const int SIZE = [% action.get_size %]; 23 | 24 | /** 25 | * Is this a matrix action? 26 | */ 27 | static const bool IS_MATRIX = [% action.is_matrix %]; 28 | [%-END-%] 29 | -------------------------------------------------------------------------------- /share/src/bi/typelist/pop_front_spec.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_TYPELIST_POP_FRONT_SPEC_HPP 9 | #define BI_TYPELIST_POP_FRONT_SPEC_HPP 10 | 11 | #include "empty.hpp" 12 | 13 | //#include "boost/static_assert.hpp" 14 | 15 | namespace bi { 16 | /** 17 | * Pop first spec of a type list. Used by append. 18 | * 19 | * @ingroup typelist 20 | * 21 | * @tparam T A type list. 22 | */ 23 | template 24 | struct pop_front_spec { 25 | //BOOST_STATIC_ASSERT(!empty::value); 26 | typedef typename T::tail type; 27 | }; 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /lib/Bi/Block/pdf_.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | pdf_ - block for univariate pdf actions. 4 | 5 | =cut 6 | 7 | package Bi::Block::pdf_; 8 | 9 | use parent 'Bi::Block'; 10 | use warnings; 11 | use strict; 12 | 13 | our $BLOCK_ARGS = []; 14 | 15 | sub validate { 16 | my $self = shift; 17 | 18 | $self->process_args($BLOCK_ARGS); 19 | 20 | if (@{$self->get_blocks} > 0) { 21 | die("a 'pdf_' block may not contain nested blocks\n"); 22 | } 23 | } 24 | 25 | 1; 26 | 27 | =head1 AUTHOR 28 | 29 | Lawrence Murray 30 | 31 | =head1 VERSION 32 | 33 | $Rev: 2925 $ $Date: 2012-08-12 17:49:28 +0800 (Sun, 12 Aug 2012) $ 34 | -------------------------------------------------------------------------------- /inc/Module/Install/Scripts.pm: -------------------------------------------------------------------------------- 1 | #line 1 2 | package Module::Install::Scripts; 3 | 4 | use strict 'vars'; 5 | use Module::Install::Base (); 6 | 7 | use vars qw{$VERSION @ISA $ISCORE}; 8 | BEGIN { 9 | $VERSION = '1.06'; 10 | @ISA = 'Module::Install::Base'; 11 | $ISCORE = 1; 12 | } 13 | 14 | sub install_script { 15 | my $self = shift; 16 | my $args = $self->makemaker_args; 17 | my $exe = $args->{EXE_FILES} ||= []; 18 | foreach ( @_ ) { 19 | if ( -f $_ ) { 20 | push @$exe, $_; 21 | } elsif ( -d 'script' and -f "script/$_" ) { 22 | push @$exe, "script/$_"; 23 | } else { 24 | die("Cannot find script '$_'"); 25 | } 26 | } 27 | } 28 | 29 | 1; 30 | -------------------------------------------------------------------------------- /share/src/bi/math/scalar.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_MATH_SCALAR_HPP 9 | #define BI_MATH_SCALAR_HPP 10 | 11 | /** 12 | * Value type for calculations, float or double. We use this rather 13 | * than templates because of limited function template support on the GPU 14 | * and necessary use of global variables. 15 | */ 16 | #ifdef ENABLE_SINGLE 17 | typedef float real; 18 | #else 19 | typedef double real; 20 | #endif 21 | 22 | /** 23 | * @def BI_REAL 24 | * 25 | * Cast alias. 26 | */ 27 | #define BI_REAL(x, ...) static_cast(x,##__VA_ARGS__) 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /share/tt/cpp/macro/offset_coord.hpp.tt: -------------------------------------------------------------------------------- 1 | [%- 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | -%] 8 | [%-MACRO offset_coord(action) BLOCK-%] 9 | [%-dynamic = 0-%] 10 | [%-FOREACH alias IN action.get_aliases-%] 11 | [%-IF !alias.get_range.get_start.is_const-%] 12 | [%-dynamic = 1-%] 13 | [%-END-%] 14 | [%-END-%] 15 | 16 | [%-IF !dynamic-%] 17 | const CX& cox_ = cox; 18 | [%-ELSE-%] 19 | CX cox_ = cox; 20 | [% FOREACH alias IN action.get_aliases %] 21 | [% IF !alias.get_range.get_start.is_const %] 22 | cox_.i[% loop.index %] = [% alias.get_range.get_start.to_cpp %]; 23 | [% END %] 24 | [%-END %] 25 | [%-END-%] 26 | [%-END-%] 27 | -------------------------------------------------------------------------------- /lib/Bi/Test/test.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | test - frontend to test client programs. 4 | 5 | =head1 SYNOPSIS 6 | 7 | libbi test ... 8 | 9 | =head1 INHERITS 10 | 11 | L 12 | 13 | =cut 14 | our @CLIENT_OPTIONS = (); 15 | 16 | =head1 METHODS 17 | 18 | =over 4 19 | 20 | =cut 21 | 22 | package Bi::Client::test; 23 | 24 | use parent 'Bi::Client'; 25 | use warnings; 26 | use strict; 27 | 28 | sub init { 29 | my $self = shift; 30 | 31 | $self->{_binary} = 'test'; 32 | push(@{$self->{_params}}, @CLIENT_OPTIONS); 33 | } 34 | 35 | 1; 36 | 37 | =back 38 | 39 | =head1 AUTHOR 40 | 41 | Lawrence Murray 42 | 43 | =head1 VERSION 44 | 45 | $Rev$ $Date$ 46 | -------------------------------------------------------------------------------- /share/src/bi/null/SimulatorNullBuffer.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #include "SimulatorNullBuffer.hpp" 9 | 10 | bi::SimulatorNullBuffer::SimulatorNullBuffer(const Model& m, const size_t P, 11 | const size_t T, const std::string& file, const FileMode mode, 12 | const SchemaMode schema) { 13 | // 14 | } 15 | 16 | void bi::SimulatorNullBuffer::writeTime(const size_t k, const real& t) { 17 | // 18 | } 19 | 20 | void bi::SimulatorNullBuffer::writeStart(const size_t k, const long& start) { 21 | // 22 | } 23 | 24 | void bi::SimulatorNullBuffer::writeLen(const size_t k, const long& len) { 25 | // 26 | } 27 | -------------------------------------------------------------------------------- /share/src/bi/typelist/front_spec.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_TYPELIST_FRONT_SPEC_HPP 9 | #define BI_TYPELIST_FRONT_SPEC_HPP 10 | 11 | #include "typelist.hpp" 12 | #include "empty.hpp" 13 | 14 | //#include "boost/static_assert.hpp" 15 | 16 | namespace bi { 17 | /** 18 | * Get front spec of a type list. Used by append. 19 | * 20 | * @ingroup typelist 21 | * 22 | * @tparam T A type list. 23 | */ 24 | template 25 | struct front_spec { 26 | //BOOST_STATIC_ASSERT(!empty::value); 27 | typedef typelist type; 28 | }; 29 | 30 | } 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /share/tt/cpp/model.cpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | [%-class_name = "Model" _ model.get_name-%] 10 | /** 11 | * @file 12 | * 13 | * @author Generated by LibBi 14 | * $Rev$ 15 | * $Date$ 16 | */ 17 | #include "[% class_name %].hpp" 18 | 19 | using namespace bi; 20 | 21 | [% class_name %]::[% class_name %]() : Model(*this) { 22 | /* add dimensions */ 23 | [%-FOREACH dim IN model.get_all_dims %] 24 | addDim(dim[% dim.get_id %]); 25 | [%-END %] 26 | 27 | /* add variables */ 28 | [%-FOREACH var IN model.get_all_vars %] 29 | addVar<[% class_name %],Var[% var.get_id %]>(var[% var.get_id %]); 30 | [%-END %] 31 | } 32 | -------------------------------------------------------------------------------- /lib/Bi/Block/cholesky_.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | cholesky_ - special block for cholesky action. 4 | 5 | =cut 6 | 7 | package Bi::Block::cholesky_; 8 | 9 | use parent 'Bi::Block'; 10 | use warnings; 11 | use strict; 12 | 13 | our $BLOCK_ARGS = []; 14 | 15 | sub validate { 16 | my $self = shift; 17 | 18 | $self->process_args($BLOCK_ARGS); 19 | 20 | my $name = $self->get_name; 21 | if (@{$self->get_blocks} > 0) { 22 | die("a '$name' block may not contain nested blocks\n"); 23 | } 24 | if (@{$self->get_actions} != 1) { 25 | die("a '$name' block may only contain one action\n"); 26 | } 27 | } 28 | 29 | 1; 30 | 31 | =head1 AUTHOR 32 | 33 | Lawrence Murray 34 | -------------------------------------------------------------------------------- /lib/Bi/Block/bridge.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | bridge - the bridge potential. 4 | 5 | =head1 SYNOPSIS 6 | 7 | sub bridge { 8 | ... 9 | } 10 | 11 | =head1 DESCRIPTION 12 | 13 | Actions in the C block may reference variables of any type, but may 14 | only target variables of type C and C. References to C 15 | variables provide their next value. Use of the built-in variables C 16 | and C will be useful. 17 | 18 | =cut 19 | 20 | package Bi::Block::bridge; 21 | 22 | use parent 'Bi::Block::observation'; 23 | use warnings; 24 | use strict; 25 | 26 | 1; 27 | 28 | =head1 AUTHOR 29 | 30 | Lawrence Murray 31 | 32 | =head1 VERSION 33 | 34 | $Rev$ $Date$ 35 | -------------------------------------------------------------------------------- /share/src/bi/host/random/RandomHost.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #include "RandomHost.hpp" 9 | 10 | #ifdef ENABLE_MPI 11 | #include "boost/mpi/communicator.hpp" 12 | #endif 13 | 14 | void bi::RandomHost::seeds(Random& rng, const unsigned seed) { 15 | #pragma omp parallel 16 | { 17 | #ifdef ENABLE_MPI 18 | boost::mpi::communicator world; 19 | const int rank = world.rank(); 20 | const int size = world.size(); 21 | 22 | int s = seed*size*bi_omp_max_threads + rank*bi_omp_max_threads + bi_omp_tid; 23 | #else 24 | int s = seed*bi_omp_max_threads + bi_omp_tid; 25 | #endif 26 | 27 | rng.getHostRng().seed(s); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /share/src/bi/concept/Norm.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #error "Concept documentation only, should not be #included" 9 | 10 | namespace concept { 11 | /** 12 | * Vector norm concept. 13 | * 14 | * @ingroup concept 15 | * 16 | * @note This is a phony class, representing a concept, for documentation 17 | * purposes only. 18 | */ 19 | struct Norm { 20 | /** 21 | * Evaluate the norm. 22 | * 23 | * @tparam V1 Vector type. 24 | * 25 | * @param x \f$\mathbf{x}\f$; a vector. 26 | * 27 | * @return \f$\|\mathbf{x}\|\f$; the norm of the vector. 28 | */ 29 | template 30 | typename V1::value_type operator()(const V1& x) const = 0; 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /script/libbi: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | =head1 NAME 4 | 5 | libbi - frontend to LibBi functionality. 6 | 7 | =head1 SYNOPSIS 8 | 9 | libbi I I 10 | 11 | libbi @I 12 | libbi I @I 13 | 14 | =head1 METHODS 15 | 16 | =over 4 17 | 18 | =cut 19 | 20 | BEGIN { 21 | use FindBin qw($Bin); 22 | use File::Spec; 23 | 24 | unshift(@INC, File::Spec->catfile($Bin, '..', 'lib')); 25 | } 26 | 27 | use warnings; 28 | use strict; 29 | 30 | use Getopt::ArgvFile; 31 | 32 | use Bi::FrontEnd; 33 | 34 | 35 | my $frontend = new Bi::FrontEnd; 36 | $frontend->do; 37 | 38 | =back 39 | 40 | =head1 AUTHOR 41 | 42 | Lawrence Murray 43 | 44 | =head1 VERSION 45 | 46 | $Rev$ $Date$ 47 | -------------------------------------------------------------------------------- /share/src/bi/traits/resampler_traits.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_TRAITS_RESAMPLER_TRAITS_HPP 9 | #define BI_TRAITS_RESAMPLER_TRAITS_HPP 10 | 11 | namespace bi { 12 | /** 13 | * Precompute type for given resampler. 14 | * 15 | * @ingroup method_resampler 16 | * 17 | * @tparam R Resampler type. 18 | * @tparam L Location. 19 | */ 20 | template 21 | struct precompute_type { 22 | typedef int type; 23 | }; 24 | 25 | /** 26 | * Does resampler need a maximum log-weight? 27 | * 28 | * @ingroup method_resampler 29 | */ 30 | template 31 | struct resampler_needs_max { 32 | static const bool value = false; 33 | }; 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | LibBi README.md 2 | =============== 3 | 4 | [LibBi](http://www.libbi.org) is used for state-space modelling and Bayesian 5 | inference on modern computer hardware, including multi-core CPUs, many-core 6 | GPUs (graphics processing units) and distributed-memory clusters. 7 | 8 | The staple methods used in LibBi are those based on sequential Monte Carlo 9 | (SMC). This includes particle Markov chain Monte Carlo (PMCMC) and SMC^2 10 | methods. Extra methods include the extended Kalman filter and some parameter 11 | optimisation routines. 12 | 13 | LibBi consists of a C++ template library, as well as a parser and compiler, 14 | written in Perl, for its own domain-specific language that is used to specify 15 | models. 16 | 17 | See the `INSTALL.md` file for installation instructions. 18 | -------------------------------------------------------------------------------- /share/src/bi/cuda/random/RandomGPU.cu: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #include "RandomGPU.cuh" 9 | 10 | #include "../../cuda/device.hpp" 11 | 12 | #ifdef ENABLE_MPI 13 | #include "boost/mpi/communicator.hpp" 14 | #endif 15 | 16 | void bi::RandomGPU::seeds(Random& rng, const unsigned seed) { 17 | #ifdef ENABLE_MPI 18 | boost::mpi::communicator world; 19 | const int rank = world.rank(); 20 | const int size = world.size(); 21 | 22 | int s = seed*size + rank; 23 | #else 24 | int s = seed; 25 | #endif 26 | 27 | dim3 Db, Dg; 28 | Db.x = deviceIdealThreadsPerBlock(); 29 | Dg.x = deviceIdealThreads()/Db.x; 30 | 31 | kernelSeeds<<>>(rng.devRngs, s); 32 | CUDA_CHECK; 33 | } 34 | -------------------------------------------------------------------------------- /lib/Bi/Block/wiener_.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | wiener_ - block for L actions. 4 | 5 | =cut 6 | 7 | package Bi::Block::wiener_; 8 | 9 | use parent 'Bi::Block'; 10 | use warnings; 11 | use strict; 12 | 13 | our $BLOCK_ARGS = []; 14 | 15 | sub validate { 16 | my $self = shift; 17 | 18 | $self->process_args($BLOCK_ARGS); 19 | 20 | if (@{$self->get_blocks} > 0) { 21 | die("a 'wiener_' block may not contain nested blocks\n"); 22 | } 23 | 24 | foreach my $action (@{$self->get_actions}) { 25 | if ($action->get_name ne 'wiener') { 26 | die("a 'wiener_' block may only contain 'wiener' actions\n"); 27 | } 28 | } 29 | } 30 | 31 | 1; 32 | 33 | =head1 AUTHOR 34 | 35 | Lawrence Murray 36 | 37 | =head1 VERSION 38 | 39 | $Rev$ $Date$ 40 | -------------------------------------------------------------------------------- /share/src/bi/method/misc.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_METHOD_MISC_HPP 9 | #define BI_METHOD_MISC_HPP 10 | 11 | namespace bi { 12 | /** 13 | * Optimisation modes. 14 | */ 15 | enum OptimiserMode { 16 | /** 17 | * Maximum likelihood estimation. 18 | */ 19 | MAXIMUM_LIKELIHOOD, 20 | 21 | /** 22 | * Maximum a posteriori. 23 | */ 24 | MAXIMUM_A_POSTERIORI 25 | }; 26 | 27 | /** 28 | * MarginalSIR adaptation strategies. 29 | */ 30 | enum MarginalSIRAdapter { 31 | /** 32 | * No adaptation. 33 | */ 34 | NO_ADAPTER, 35 | 36 | /** 37 | * Local proposals. 38 | */ 39 | LOCAL_ADAPTER, 40 | 41 | /** 42 | * Global proposals. 43 | */ 44 | GLOBAL_ADAPTER 45 | }; 46 | 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /share/tt/cpp/block/misc/header.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | [%-PROCESS macro.hpp.tt-%] 10 | 11 | [%-class_name = "Block" _ block.get_id-%] 12 | [%-model_class_name = "Model" _ model.get_name-%] 13 | /** 14 | * @file 15 | * 16 | * @author Generated by LibBi 17 | * $Rev$ 18 | * $Date$ 19 | */ 20 | #ifndef LIBBI_[% class_name | upper %]_HPP 21 | #define LIBBI_[% class_name | upper %]_HPP 22 | 23 | [%-FOREACH subblock IN block.get_blocks %] 24 | #include "Block[% subblock.get_id %].hpp" 25 | [%-END %] 26 | [%-FOREACH action IN block.get_actions %] 27 | #include "../action/Action[% action.get_id %].hpp" 28 | [%-END %] 29 | 30 | #include "bi/typelist/macro_typelist.hpp" 31 | #include "bi/traits/block_traits.hpp" 32 | 33 | #include "boost/typeof/typeof.hpp" 34 | -------------------------------------------------------------------------------- /share/src/bi/cuda/thread.cuh: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_THREAD_CUH 9 | #define BI_CUDA_THREAD_CUH 10 | 11 | #include "cuda.hpp" 12 | 13 | /** 14 | * @internal 15 | * 16 | * Return id of the current thread, a unique number across all threads in all 17 | * blocks. 18 | * 19 | * @return Id of the thread. 20 | */ 21 | CUDA_FUNC_DEVICE int get_tid(); 22 | 23 | inline int get_tid() { 24 | int blockSize, blockId, threadId, tid; 25 | 26 | blockSize = blockDim.y*blockDim.x*blockDim.z; 27 | blockId = blockIdx.y + blockIdx.x*gridDim.x + blockIdx.z*gridDim.x*gridDim.y; 28 | threadId = threadIdx.y + threadIdx.x*blockDim.y + threadIdx.z*blockDim.y*blockDim.x; 29 | tid = blockId*blockSize + threadId; 30 | 31 | return tid; 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /share/src/bi/traits/dim_traits.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_TRAITS_DIM_TRAITS_HPP 9 | #define BI_TRAITS_DIM_TRAITS_HPP 10 | 11 | #include "../typelist/index.hpp" 12 | #include "../typelist/front.hpp" 13 | #include "../typelist/pop_front.hpp" 14 | #include "../typelist/size.hpp" 15 | 16 | namespace bi { 17 | /** 18 | * Id of dimension. 19 | * 20 | * @ingroup model_low 21 | * 22 | * @tparam D Dimension type. 23 | */ 24 | template 25 | struct dim_id { 26 | static const int value = D::ID; 27 | }; 28 | 29 | /** 30 | * Size of dimension. 31 | * 32 | * @ingroup model_low 33 | * 34 | * @tparam D Dimension type. 35 | */ 36 | template 37 | struct dim_size { 38 | static const int value = D::SIZE; 39 | }; 40 | 41 | } 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /share/tt/cpp/action/misc/header.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | [%-PROCESS macro.hpp.tt-%] 10 | 11 | [%-class_name = 'Action' _ action.get_id-%] 12 | [%-model_class_name = "Model" _ model.get_name-%] 13 | /** 14 | * @file 15 | * 16 | * Automatically generated by LibBi, do not edit. 17 | */ 18 | #ifndef LIBBI_ACTION[% action.get_id %]_HPP 19 | #define LIBBI_ACTION[% action.get_id %]_HPP 20 | 21 | #include "ActionCoord[% action.get_id %].hpp" 22 | 23 | #include "bi/state/State.hpp" 24 | #include "bi/state/Mask.hpp" 25 | #include "bi/cuda/cuda.hpp" 26 | #include "bi/math/scalar.hpp" 27 | #include "bi/math/pi.hpp" 28 | #include "bi/math/function.hpp" 29 | #ifdef ENABLE_SSE 30 | #include "bi/sse/math/scalar.hpp" 31 | #endif 32 | 33 | class Model[% model.get_name %]; 34 | -------------------------------------------------------------------------------- /script/bi: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | =head1 NAME 4 | 5 | bi - frontend to LibBi functionality. 6 | 7 | =head1 SYNOPSIS 8 | 9 | bi I I 10 | 11 | bi @I 12 | bi I @I 13 | 14 | =head1 METHODS 15 | 16 | =over 4 17 | 18 | =cut 19 | 20 | BEGIN { 21 | use FindBin qw($Bin); 22 | use File::Spec; 23 | 24 | unshift(@INC, File::Spec->catfile($Bin, '..', 'lib')); 25 | } 26 | 27 | use warnings; 28 | use strict; 29 | 30 | use Getopt::ArgvFile; 31 | 32 | use Bi::FrontEnd; 33 | 34 | warn("the 'bi' command is deprecated, use 'libbi' instead.\n"); 35 | 36 | my $frontend = new Bi::FrontEnd; 37 | $frontend->do; 38 | 39 | =back 40 | 41 | =head1 AUTHOR 42 | 43 | Lawrence Murray 44 | 45 | =head1 VERSION 46 | 47 | $Rev: 3864 $ $Date: 2013-05-22 17:48:18 +0800 (Wed, 22 May 2013) $ 48 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | LibBi 4 | 5 | 6 | 7 | 8 | 9 | net.sourceforge.texlipse.builder.TexlipseBuilder 10 | 11 | 12 | 13 | 14 | org.epic.perleditor.perlbuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.linuxtools.rpm.rpmlint.rpmlintBuilder 20 | 21 | 22 | 23 | 24 | 25 | net.sourceforge.texlipse.builder.TexlipseNature 26 | org.epic.perleditor.perlnature 27 | org.eclipse.linuxtools.rpm.rpmlint.rpmlintNature 28 | 29 | 30 | -------------------------------------------------------------------------------- /lib/Bi/Block/proposal_parameter.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | parameter - a proposal distribution over parameters. 4 | 5 | =head1 SYNOPSIS 6 | 7 | sub proposal_parameter { 8 | theta ~ gaussian(theta, 1.0) // local proposal 9 | theta ~ gaussian(0.0, 1.0) // independent proposal 10 | } 11 | 12 | =head1 DESCRIPTION 13 | 14 | This may be a local or independent proposal distribution, used by the 15 | C command. 16 | 17 | Actions in the C block may only refer to variables of 18 | type C and C. They may only target variables of type C. 19 | 20 | =cut 21 | 22 | package Bi::Block::proposal_parameter; 23 | 24 | use parent 'Bi::Block::parameter'; 25 | use warnings; 26 | use strict; 27 | 28 | 1; 29 | 30 | =head1 AUTHOR 31 | 32 | Lawrence Murray 33 | 34 | =head1 VERSION 35 | 36 | $Rev$ $Date$ 37 | -------------------------------------------------------------------------------- /lib/Bi/Block/lookahead_observation.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | lookahead_observation - a likelihood function for lookahead operations. 4 | 5 | =head1 SYNOPSIS 6 | 7 | sub lookahead_observation { 8 | ... 9 | } 10 | 11 | =head1 DESCRIPTION 12 | 13 | This may be a deterministic, computationally cheaper or perhaps inflated 14 | version of the likelihood function. It is used by the auxiliary particle 15 | filter. 16 | 17 | Actions in the C block may only refer to variables 18 | of type C, C and C. They may only target variables of 19 | type C. 20 | 21 | =cut 22 | 23 | package Bi::Block::lookahead_observation; 24 | 25 | use parent 'Bi::Block::observation'; 26 | use warnings; 27 | use strict; 28 | 29 | 1; 30 | 31 | =head1 AUTHOR 32 | 33 | Lawrence Murray 34 | 35 | =head1 VERSION 36 | 37 | $Rev$ $Date$ 38 | -------------------------------------------------------------------------------- /lib/Bi/Block/lookahead_transition.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | lookahead_transition - a transition distribution for lookahead operations. 4 | 5 | =head1 SYNOPSIS 6 | 7 | sub lookahead_transition { 8 | ... 9 | } 10 | 11 | =head1 DESCRIPTION 12 | 13 | This may be a deterministic, computationally cheaper or perhaps inflated 14 | version of the transition distribution. It is used by the auxiliary particle 15 | filter. 16 | 17 | Actions in the C block may reference variables of any 18 | type except C, but may only target variables of type C and 19 | C. 20 | 21 | =cut 22 | 23 | package Bi::Block::lookahead_transition; 24 | 25 | use parent 'Bi::Block::transition'; 26 | use warnings; 27 | use strict; 28 | 29 | 1; 30 | 31 | =head1 AUTHOR 32 | 33 | Lawrence Murray 34 | 35 | =head1 VERSION 36 | 37 | $Rev$ $Date$ 38 | -------------------------------------------------------------------------------- /share/tt/bi/block.bi.tt: -------------------------------------------------------------------------------- 1 | [%- 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | PROCESS macro/arg_list.bi.tt 8 | -%] 9 | [% IF block.get_top_level %]sub [% END %][% IF block.is_named %][% block.get_name %][% END %][% arg_list(block) %] { // Block[% block.get_id %] 10 | [% INCLUDE const.bi.tt FILTER indent(2) FOREACH const IN block.get_consts-%] 11 | [% INCLUDE inline.bi.tt FILTER indent(2) FOREACH inline IN block.get_inlines-%] 12 | [% INCLUDE dim.bi.tt FILTER indent(2) FOREACH dim IN block.get_dims-%] 13 | [% INCLUDE var.bi.tt FILTER indent(2) FOREACH var IN block.get_vars-%] 14 | 15 | [%-FOREACH child IN block.get_children-%] 16 | [%-IF child.get_type == 'action'-%] 17 | [%-INCLUDE action.bi.tt action = child FILTER indent(2)-%] 18 | [%-ELSE-%] 19 | [%-INCLUDE block.bi.tt block = child FILTER indent(2)-%] 20 | [%-END-%] 21 | [%-END-%] 22 | } 23 | -------------------------------------------------------------------------------- /lib/Bi/Block/std_.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | std_ - optimisation block for L actions. 4 | 5 | =cut 6 | 7 | package Bi::Block::std_; 8 | 9 | use parent 'Bi::Block'; 10 | use warnings; 11 | use strict; 12 | 13 | our $BLOCK_ARGS = []; 14 | 15 | sub validate { 16 | my $self = shift; 17 | 18 | $self->process_args($BLOCK_ARGS); 19 | 20 | if (@{$self->get_blocks} > 0) { 21 | die("a 'std_' block may not contain nested blocks\n"); 22 | } 23 | if (@{$self->get_actions} != 1) { 24 | die("a 'std_' block may only contain one action\n"); 25 | } 26 | 27 | my $action = $self->get_action; 28 | if ($action->get_name ne 'std_') { 29 | die("a 'std_' block may only contain 'std_' actions\n"); 30 | } 31 | } 32 | 33 | 1; 34 | 35 | =head1 AUTHOR 36 | 37 | Lawrence Murray 38 | 39 | =head1 VERSION 40 | 41 | $Rev$ $Date$ 42 | -------------------------------------------------------------------------------- /share/tt/bi/model.bi.tt: -------------------------------------------------------------------------------- 1 | [%- 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | -%] 8 | [%-PROCESS macro/arg_list.bi.tt-%] 9 | model [% model.get_name %][% arg_list(model) %] { 10 | [% INCLUDE const.bi.tt FILTER indent(2) FOREACH const IN model.get_consts-%] 11 | [% INCLUDE inline.bi.tt FILTER indent(2) FOREACH inline IN model.get_inlines-%] 12 | [% INCLUDE dim.bi.tt FILTER indent(2) FOREACH dim IN model.get_dims-%] 13 | [% INCLUDE var.bi.tt FILTER indent(2) FOREACH var IN model.get_vars-%] 14 | [% INCLUDE var_group.bi.tt FILTER indent(2) FOREACH var_group IN model.get_var_groups-%] 15 | 16 | [% FOREACH child IN model.get_children-%] 17 | [%-IF child.get_type == 'action'-%] 18 | [% INCLUDE action.bi.tt action = child FILTER indent(2)-%] 19 | [%-ELSE-%] 20 | [% INCLUDE block.bi.tt block = child FILTER indent(2) %] 21 | 22 | [%-END-%] 23 | [% END-%] 24 | } 25 | -------------------------------------------------------------------------------- /share/src/bi/typelist/push_back_spec.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_TYPELIST_PUSH_BACK_SPEC_HPP 9 | #define BI_TYPELIST_PUSH_BACK_SPEC_HPP 10 | 11 | #include "typelist.hpp" 12 | 13 | namespace bi { 14 | /** 15 | * Push spec onto back of a type list. Used by append. 16 | * 17 | * @ingroup typelist 18 | * 19 | * @tparam T1 A type list. 20 | * @tparam T2 A type list. 21 | */ 22 | template 23 | struct push_back_spec { 24 | typedef typelist::type> type; 25 | }; 26 | 27 | /** 28 | * @internal 29 | * 30 | * Base case. 31 | */ 32 | template 33 | struct push_back_spec { 34 | typedef typelist type; 35 | }; 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /share/tt/dot/block.dot.tt: -------------------------------------------------------------------------------- 1 | [%- 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | -%] 8 | [%-FOREACH ref IN block.get_vars(['input', 'param', 'noise', 'state', 'obs']) %] 9 | [%-INCLUDE ref.dot.tt FILTER indent(2) %] 10 | [%-END-%] 11 | 12 | [% IF block.get_name != 'eval_' %] 13 | subgraph cluster_block[% block.get_id %] { 14 | label="[% block.get_name %]"; 15 | color="#000000"; 16 | [% END %] 17 | 18 | [%-FOREACH action IN block.get_actions-%] 19 | [%-INCLUDE var.dot.tt var = action.get_left.get_var FILTER indent(2) %] 20 | [%-END-%] 21 | 22 | [%-FOREACH subblock IN block.get_blocks %] 23 | [%-INCLUDE block.dot.tt block = subblock FILTER indent(2) %] 24 | [%-END-%] 25 | 26 | [%-FOREACH action IN block.get_actions %] 27 | [%-INCLUDE action.dot.tt action = action FILTER indent(2) %] 28 | [%-END-%] 29 | 30 | [% IF block.get_name != 'eval_' %] 31 | } 32 | [% END %] 33 | -------------------------------------------------------------------------------- /share/src/bi/math/pi.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * Common \f$\pi\f$ pre-calculations using big-decimal. We should note that, 5 | * actually, these are no more accurate than using double precision, but they 6 | * do at least ensure decent accuracy before casting to single precision. 7 | * 8 | * @author Lawrence Murray 9 | * $Rev$ 10 | * $Date$ 11 | */ 12 | #ifndef BI_MATH_PI_HPP 13 | #define BI_MATH_PI_HPP 14 | 15 | /** 16 | * Value of \f$\pi\f$ 17 | */ 18 | #define BI_PI 3.1415926535897932384626433832795 19 | 20 | /** 21 | * Value of \f$2\pi\f$ 22 | */ 23 | #define BI_TWO_PI 6.2831853071795864769252867665590 24 | 25 | /** 26 | * Value of \f$\sqrt{2\pi}\f$ 27 | */ 28 | #define BI_SQRT_TWO_PI 2.5066282746310005024157652848110 29 | 30 | /** 31 | * Value of \f$\frac{1}{2}\ln 2\pi = \ln \sqrt{2\pi}\f$ 32 | */ 33 | #define BI_HALF_LOG_TWO_PI 0.91893853320467274178032973640562 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /share/src/bi/random/Random.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #include "Random.hpp" 9 | 10 | #ifdef ENABLE_CUDA 11 | #include "../cuda/device.hpp" 12 | #endif 13 | 14 | bi::Random::Random() : own(true) { 15 | hostRngs = new RngHost[bi_omp_max_threads]; 16 | } 17 | 18 | bi::Random::Random(const unsigned seed) : own(true) { 19 | hostRngs = new RngHost[bi_omp_max_threads]; 20 | this->seeds(seed); 21 | } 22 | 23 | bi::Random::Random(const Random& o) { 24 | hostRngs = o.hostRngs; 25 | #ifdef ENABLE_CUDA 26 | devRngs = o.devRngs; 27 | #endif 28 | own = false; 29 | } 30 | 31 | bi::Random::~Random() { 32 | if (own) { 33 | delete[] hostRngs; 34 | } 35 | } 36 | 37 | void bi::Random::seeds(const unsigned seed) { 38 | RandomHost::seeds(*this, seed); 39 | #ifdef ENABLE_CUDA 40 | RandomGPU::seeds(*this, seed); 41 | #endif 42 | } 43 | -------------------------------------------------------------------------------- /lib/Bi/Action/log_gaussian.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | log_gaussian - log-Gaussian distribution. 4 | 5 | =head1 SYNOPSIS 6 | 7 | x ~ log_gaussian() 8 | x ~ log_gaussian(0.0, 1.0) 9 | x ~ log_gaussian(mean = 0.0, std = 1.0) 10 | 11 | =head1 DESCRIPTION 12 | 13 | A C action specifies that the logarithm of a variable is 14 | Gaussian distributed according to the given C and C parameters. 15 | 16 | =cut 17 | 18 | package Bi::Action::log_gaussian; 19 | 20 | use parent 'Bi::Action::gaussian'; 21 | 22 | =head1 PARAMETERS 23 | 24 | =over 4 25 | 26 | =item C (position 0, default 0.0) 27 | 28 | Mean of the log-transformed variable. 29 | 30 | =item C (position 1, default 1.0) 31 | 32 | Standard deviation of the log-transformed variable. 33 | 34 | =back 35 | 36 | =cut 37 | 38 | 1; 39 | 40 | =head1 AUTHOR 41 | 42 | Lawrence Murray 43 | 44 | =head1 VERSION 45 | 46 | $Rev$ $Date$ 47 | -------------------------------------------------------------------------------- /share/tt/cpp/action/transpose.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | %] 6 | 7 | [%- 8 | A = action.get_named_arg('A'); 9 | %] 10 | 11 | [%-PROCESS action/misc/header.hpp.tt-%] 12 | 13 | /** 14 | * Action: [% action.get_name %]. 15 | */ 16 | class [% class_name %] { 17 | public: 18 | [% std_action %] 19 | 20 | [% declare_action_static_matrix_function('simulate') %] 21 | [% declare_action_dynamic_matrix_function('simulate') %] 22 | }; 23 | 24 | #include "bi/math/view.hpp" 25 | #include "bi/math/operation.hpp" 26 | 27 | [% sig_action_static_matrix_function('simulate') %] { 28 | [% fetch_parents(action) %] 29 | 30 | BOOST_AUTO(A, [% get_var(A) %]); 31 | BOOST_AUTO(B, [% get_output_var(B) %]); 32 | 33 | bi::trans(A, B); 34 | } 35 | 36 | [% sig_action_dynamic_matrix_function('simulate') %] { 37 | simulates(s, p, pax, x); 38 | } 39 | 40 | [%-PROCESS action/misc/footer.hpp.tt-%] 41 | -------------------------------------------------------------------------------- /share/tt/cpp/action/exclusive_scan.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | [%- 10 | a = action.get_named_arg('x'); 11 | %] 12 | 13 | [%-PROCESS action/misc/header.hpp.tt-%] 14 | 15 | /** 16 | * Action: [% action.get_name %]. 17 | */ 18 | class [% class_name %] { 19 | public: 20 | [% std_action %] 21 | 22 | [% declare_action_static_matrix_function('simulate') %] 23 | [% declare_action_dynamic_matrix_function('simulate') %] 24 | }; 25 | 26 | #include "bi/math/view.hpp" 27 | 28 | [% sig_action_static_matrix_function('simulate') %] { 29 | [% fetch_parents(action) %] 30 | 31 | BOOST_AUTO(a, [% get_var(a) %]); 32 | BOOST_AUTO(b, [% get_output_var(b) %]); 33 | 34 | bi::exclusive_scan(a, b); 35 | } 36 | 37 | [% sig_action_dynamic_matrix_function('simulate') %] { 38 | simulates(s, p, pax, x); 39 | } 40 | 41 | [%-PROCESS action/misc/footer.hpp.tt-%] 42 | -------------------------------------------------------------------------------- /share/tt/cpp/action/inclusive_scan.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | [%- 10 | a = action.get_named_arg('x'); 11 | %] 12 | 13 | [%-PROCESS action/misc/header.hpp.tt-%] 14 | 15 | /** 16 | * Action: [% action.get_name %]. 17 | */ 18 | class [% class_name %] { 19 | public: 20 | [% std_action %] 21 | 22 | [% declare_action_static_matrix_function('simulate') %] 23 | [% declare_action_dynamic_matrix_function('simulate') %] 24 | }; 25 | 26 | #include "bi/math/view.hpp" 27 | 28 | [% sig_action_static_matrix_function('simulate') %] { 29 | [% fetch_parents(action) %] 30 | 31 | BOOST_AUTO(a, [% get_var(a) %]); 32 | BOOST_AUTO(b, [% get_output_var(b) %]); 33 | 34 | bi::inclusive_scan(a, b); 35 | } 36 | 37 | [% sig_action_dynamic_matrix_function('simulate') %] { 38 | simulates(s, p, pax, x); 39 | } 40 | 41 | [%-PROCESS action/misc/footer.hpp.tt-%] 42 | -------------------------------------------------------------------------------- /share/tt/cpp/action/eval_.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | [%-PROCESS action/misc/header.hpp.tt-%] 10 | 11 | [%- 12 | expr = action.get_named_arg('expr') 13 | -%] 14 | 15 | /** 16 | * Action: [% action.get_name %]. 17 | */ 18 | struct [% class_name %] { 19 | [% std_action %] 20 | 21 | [% declare_action_static_function('simulate') %] 22 | [% declare_action_dynamic_function('simulate') %] 23 | }; 24 | 25 | 26 | [% sig_action_static_function('simulate') %] { 27 | [% alias_dims(action) %] 28 | [% fetch_parents(action) %] 29 | [% offset_coord(action) %] 30 | [% put_output(action, expr) %] 31 | } 32 | 33 | [% sig_action_dynamic_function('simulate') %] { 34 | [% alias_dims(action) %] 35 | [% fetch_parents(action) %] 36 | [% offset_coord(action) %] 37 | [% put_output(action, expr) %] 38 | } 39 | 40 | [%-PROCESS action/misc/footer.hpp.tt-%] 41 | -------------------------------------------------------------------------------- /lib/Bi/Block/proposal_initial.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | proposal_initial - a proposal distribution over the initial values of state 4 | variables. 5 | 6 | =head1 SYNOPSIS 7 | 8 | sub proposal_initial { 9 | x ~ gaussian(x, 1.0) // local proposal 10 | x ~ gaussian(0.0, 1.0) // independent proposal 11 | } 12 | 13 | =head1 DESCRIPTION 14 | 15 | This may be a local or independent proposal distribution, used by the 16 | C command when the C<--with-transform-initial-to-param> option is 17 | used. 18 | 19 | Actions in the C block may only refer to variables of 20 | type C, C and C. They may only target variables of type 21 | C. 22 | 23 | =cut 24 | 25 | package Bi::Block::proposal_initial; 26 | 27 | use parent 'Bi::Block::initial'; 28 | use warnings; 29 | use strict; 30 | 31 | 1; 32 | 33 | =head1 AUTHOR 34 | 35 | Lawrence Murray 36 | 37 | =head1 VERSION 38 | 39 | $Rev$ $Date$ 40 | -------------------------------------------------------------------------------- /share/tt/dot/var.dot.tt: -------------------------------------------------------------------------------- 1 | [%- 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | -%] 8 | [%- 9 | shapes.param = 'circle'; 10 | shapes.noise = 'circle'; 11 | shapes.input = 'circle'; 12 | shapes.obs = 'circle'; 13 | shapes.state = 'circle'; 14 | 15 | styles.param = 'filled'; 16 | styles.noise = 'filled'; 17 | styles.input = 'filled'; 18 | styles.obs = 'filled'; 19 | styles.state = 'filled'; 20 | 21 | colors.param = '#000000'; 22 | colors.noise = '#000000'; 23 | colors.input = '#000000'; 24 | colors.obs = '#000000'; 25 | colors.state = '#000000'; 26 | 27 | fillcolors.param = '#FFFFFF'; 28 | fillcolors.noise = '#FFFFFF'; 29 | fillcolors.input = '#CCCCCC'; 30 | fillcolors.obs = '#CCCCCC'; 31 | fillcolors.state = '#FFFFFF'; 32 | -%] 33 | [% var.get_name %] [label="[% var.get_name %]",shape="[% shapes.${var.get_type} %]",style="[% styles.${var.get_type} %]",color="[% colors.${var.get_type} %]",fillcolor="[% fillcolors.${var.get_type} %]"] 34 | -------------------------------------------------------------------------------- /Makefile.PL: -------------------------------------------------------------------------------- 1 | use inc::Module::Install; 2 | 3 | # metadata 4 | name 'LibBi'; 5 | abstract 'LibBi is used for state-space modelling and Bayesian inference on 6 | modern computer hardware, including multi-core CPUs, many-core GPUs (graphics 7 | processing units) and distributed-memory clusters.'; 8 | author 'Lawrence Murray '; 9 | version '1.2.0'; 10 | license 'gpl'; 11 | 12 | # dependencies 13 | requires 'Template' => 2.24; 14 | requires 'Graph' => 0.94; 15 | requires 'Math::Symbolic' => 0.606; 16 | requires 'Carp::Assert' => 0.20; 17 | requires 'Parse::Yapp' => 0.0; 18 | requires 'Parse::Lex' => 2.21; 19 | requires 'File::Slurp' => 0.0; 20 | requires 'File::ShareDir' => 1.03; 21 | requires 'Getopt::ArgvFile' => 1.11; 22 | 23 | # installs 24 | install_script 'script/libbi'; 25 | install_script 'script/bi'; 26 | install_share 'share'; 27 | 28 | # ignores 29 | makemaker_args(PL_FILES => { 'MakeParser.PL' => 'lib/Parse/Bi.pm' }); 30 | no_index 'docs'; 31 | 32 | WriteAll; 33 | -------------------------------------------------------------------------------- /share/src/bi/math/gsl.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_MATH_GSL_HPP 9 | #define BI_MATH_GSL_HPP 10 | 11 | #include "vector.hpp" 12 | 13 | #include 14 | 15 | namespace bi { 16 | /** 17 | * View of GSL vector. 18 | * 19 | * @param x The GSL vector. 20 | */ 21 | host_vector_reference gsl_vector_reference(gsl_vector* x); 22 | 23 | /** 24 | * View of GSL vector. 25 | * 26 | * @param x The GSL vector. 27 | */ 28 | const host_vector_reference gsl_vector_reference(const gsl_vector* x); 29 | 30 | } 31 | 32 | bi::host_vector_reference bi::gsl_vector_reference(gsl_vector* x) { 33 | return host_vector_reference(x->data, x->size, x->stride); 34 | } 35 | 36 | const bi::host_vector_reference bi::gsl_vector_reference( 37 | const gsl_vector* x) { 38 | return host_vector_reference(x->data, x->size, x->stride); 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /share/src/bi/sse/math/scalar.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * Types and operators for Streaming SIMD Extensions (SSE). 5 | * 6 | * @author Lawrence Murray 7 | * $Rev$ 8 | * $Date$ 9 | */ 10 | #ifndef BI_SSE_MATH_SCALAR_HPP 11 | #define BI_SSE_MATH_SCALAR_HPP 12 | 13 | #include "../../math/scalar.hpp" 14 | 15 | #ifdef ENABLE_SSE 16 | #include "sse_float.hpp" 17 | #include "sse_double.hpp" 18 | #endif 19 | 20 | #ifdef ENABLE_AVX 21 | #include "avx_float.hpp" 22 | #include "avx_double.hpp" 23 | #endif 24 | 25 | namespace bi { 26 | #if defined(ENABLE_SINGLE) && defined(ENABLE_AVX) 27 | typedef avx_float simd_real; 28 | #elif defined(ENABLE_SINGLE) && defined(ENABLE_SSE) 29 | typedef sse_float simd_real; 30 | #elif defined(ENABLE_AVX) 31 | typedef avx_double simd_real; 32 | #elif defined(ENABLE_SSE) 33 | typedef sse_double simd_real; 34 | #else 35 | typedef real simd_real; 36 | #endif 37 | } 38 | 39 | #define BI_SIMD_SIZE (sizeof(simd_real)/sizeof(real)) 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /share/tt/cpp/action/gemm_.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | %] 6 | 7 | [%- 8 | A = action.get_named_arg('A'); 9 | X = action.get_named_arg('X'); 10 | Y = action.get_left; 11 | %] 12 | 13 | [%-PROCESS action/misc/header.hpp.tt-%] 14 | 15 | /** 16 | * Action: [% action.get_name %]. 17 | */ 18 | class [% class_name %] { 19 | public: 20 | [% std_action %] 21 | 22 | [% declare_action_static_matrix_function('simulate') %] 23 | [% declare_action_dynamic_matrix_function('simulate') %] 24 | }; 25 | 26 | #include "bi/math/view.hpp" 27 | 28 | [% sig_action_static_matrix_function('simulate') %] { 29 | [% fetch_parents(action) %] 30 | 31 | BOOST_AUTO(A, [% get_var(A) %]); 32 | BOOST_AUTO(X, [% get_var(X) %]); 33 | BOOST_AUTO(Y, [% get_output_var(Y) %]); 34 | 35 | bi::gemm(A, X, Y); 36 | } 37 | 38 | [% sig_action_dynamic_matrix_function('simulate') %] { 39 | simulates(s, p, pax, x); 40 | } 41 | 42 | [%-PROCESS action/misc/footer.hpp.tt-%] 43 | -------------------------------------------------------------------------------- /share/tt/cpp/action/gemv_.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | %] 6 | 7 | [%- 8 | A = action.get_named_arg('A'); 9 | b = action.get_named_arg('x'); 10 | c = action.get_left; 11 | %] 12 | 13 | [%-PROCESS action/misc/header.hpp.tt-%] 14 | 15 | /** 16 | * Action: [% action.get_name %]. 17 | */ 18 | class [% class_name %] { 19 | public: 20 | [% std_action %] 21 | 22 | [% declare_action_static_matrix_function('simulate') %] 23 | [% declare_action_dynamic_matrix_function('simulate') %] 24 | }; 25 | 26 | #include "bi/math/view.hpp" 27 | 28 | [% sig_action_static_matrix_function('simulate') %] { 29 | [% fetch_parents(action) %] 30 | 31 | BOOST_AUTO(A, [% get_var(A) %]); 32 | BOOST_AUTO(b, [% get_var(b) %]); 33 | BOOST_AUTO(c, [% get_output_var(c) %]); 34 | 35 | bi::gemv(A, b, c); 36 | } 37 | 38 | [% sig_action_dynamic_matrix_function('simulate') %] { 39 | simulates(s, p, pax, x); 40 | } 41 | 42 | [%-PROCESS action/misc/footer.hpp.tt-%] 43 | -------------------------------------------------------------------------------- /share/src/bi/cuda/resampler/StratifiedResamplerGPU.cuh: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_RESAMPLER_STRATIFIEDRESAMPLERGPU_CUH 9 | #define BI_CUDA_RESAMPLER_STRATIFIEDRESAMPLERGPU_CUH 10 | 11 | #include "StratifiedResamplerKernel.cuh" 12 | #include "../device.hpp" 13 | 14 | template 15 | void bi::StratifiedResamplerGPU::op(Random& rng, const V1 Ws, V2 Os, 16 | const int n) { 17 | /* pre-condition */ 18 | BI_ASSERT(Ws.size() == Os.size()); 19 | 20 | typedef typename V1::value_type T1; 21 | typename sim_temp_vector::type alphas(n); 22 | 23 | const int P = Ws.size(); 24 | 25 | rng.uniforms(alphas); 26 | 27 | dim3 Db, Dg; 28 | Db.x = bi::min(P, deviceIdealThreadsPerBlock()); 29 | Dg.x = (bi::min(P, deviceIdealThreads()) + Db.x - 1)/Db.x; 30 | //deviceBalance1d(Db, Dg); 31 | 32 | kernelStratifiedResamplerOp<<>>(alphas, Ws, Os, n); 33 | CUDA_CHECK; 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /share/src/bi/typelist/append.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_TYPELIST_APPEND_HPP 9 | #define BI_TYPELIST_APPEND_HPP 10 | 11 | #include "typelist.hpp" 12 | #include "front_spec.hpp" 13 | #include "push_back_spec.hpp" 14 | #include "pop_front_spec.hpp" 15 | 16 | namespace bi { 17 | /** 18 | * Append two type lists. 19 | * 20 | * @ingroup typelist 21 | * 22 | * @tparam T1 A type list. 23 | * @tparam T2 A type list. 24 | */ 25 | template 26 | struct append { 27 | typedef typename append::type>::type,typename pop_front_spec::type>::type type; 28 | }; 29 | 30 | /** 31 | * @internal 32 | */ 33 | template 34 | struct append { 35 | typedef T1 type; 36 | }; 37 | 38 | /** 39 | * @internal 40 | */ 41 | template 42 | struct append { 43 | typedef T2 type; 44 | }; 45 | 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /share/src/bi/null/OptimiserNullBuffer.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_NULL_OPTIMISERNULLBUFFER_HPP 9 | #define BI_NULL_OPTIMISERNULLBUFFER_HPP 10 | 11 | #include "SimulatorNullBuffer.hpp" 12 | 13 | namespace bi { 14 | /** 15 | * Null output buffer for optimisers. 16 | * 17 | * @ingroup io_null 18 | */ 19 | class OptimiserNullBuffer: public SimulatorNullBuffer { 20 | public: 21 | /** 22 | * @copydoc OptimiserNetCDFBuffer::OptimiserNetCDFBuffer() 23 | */ 24 | OptimiserNullBuffer(const Model& m, const size_t T = 0, 25 | const std::string& file = "", const FileMode mode = READ_ONLY, 26 | const SchemaMode schema = PARAM_ONLY); 27 | 28 | /** 29 | * @copydoc OptimiserNetCDFBuffer::writeValue() 30 | */ 31 | void writeValue(const size_t k, const real& x); 32 | 33 | /** 34 | * @copydoc OptimiserNetCDFBuffer::writeSize() 35 | */ 36 | void writeSize(const size_t k, const real& x); 37 | }; 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /share/src/bi/misc/exception.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_MISC_EXCEPTION_HPP 9 | #define BI_MISC_EXCEPTION_HPP 10 | 11 | namespace bi { 12 | /** 13 | * Cholesky decomposition failed (matrix not positive definite). 14 | */ 15 | struct CholeskyException { 16 | /** 17 | * Constructor. 18 | */ 19 | CholeskyException(const int info) : info(info) { 20 | // 21 | } 22 | 23 | /** 24 | * Info return by potrf(). 25 | */ 26 | int info; 27 | }; 28 | 29 | /** 30 | * Eigendecomposition failed. 31 | */ 32 | struct EigenException { 33 | /** 34 | * Constructor. 35 | */ 36 | EigenException(const int info) : info(info) { 37 | // 38 | } 39 | 40 | /** 41 | * Info return by potrf(). 42 | */ 43 | int info; 44 | }; 45 | 46 | /** 47 | * Particle filter degenerated. 48 | */ 49 | struct ParticleFilterDegeneratedException { 50 | // 51 | }; 52 | } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /share/src/bi/host/math/cblas.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #include "cblas.hpp" 9 | 10 | #define CBLAS_FUNC_DEF(name, dname, sname) \ 11 | BOOST_TYPEOF(cblas_##sname) *bi::cblas_##name::func = cblas_##sname; \ 12 | BOOST_TYPEOF(cblas_##dname) *bi::cblas_##name::func = cblas_##dname; 13 | 14 | CBLAS_FUNC_DEF(copy, dcopy, scopy) 15 | CBLAS_FUNC_DEF(scal, dscal, sscal) 16 | CBLAS_FUNC_DEF(dot, ddot, sdot) 17 | CBLAS_FUNC_DEF(iamax, idamax, isamax) 18 | CBLAS_FUNC_DEF(axpy, daxpy, saxpy) 19 | CBLAS_FUNC_DEF(gemv, dgemv, sgemv) 20 | CBLAS_FUNC_DEF(symv, dsymv, ssymv) 21 | CBLAS_FUNC_DEF(trmv, dtrmv, strmv) 22 | CBLAS_FUNC_DEF(gbmv, dgbmv, sgbmv) 23 | CBLAS_FUNC_DEF(gemm, dgemm, sgemm) 24 | CBLAS_FUNC_DEF(symm, dsymm, ssymm) 25 | CBLAS_FUNC_DEF(trmm, dtrmm, strmm) 26 | CBLAS_FUNC_DEF(ger, dger, sger) 27 | CBLAS_FUNC_DEF(syr, dsyr, ssyr) 28 | CBLAS_FUNC_DEF(syr2, dsyr2, ssyr2) 29 | CBLAS_FUNC_DEF(syrk, dsyrk, ssyrk) 30 | CBLAS_FUNC_DEF(trsv, dtrsv, strsv) 31 | CBLAS_FUNC_DEF(trsm, dtrsm, strsm) 32 | -------------------------------------------------------------------------------- /share/src/bi/cuda/math/cublas.cu: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #include "cublas.hpp" 9 | 10 | #define CUBLAS_FUNC_DEF(name, dname, sname) \ 11 | BOOST_TYPEOF(cublas##sname) *bi::cublas_##name::func = cublas##sname; \ 12 | BOOST_TYPEOF(cublas##dname) *bi::cublas_##name::func = cublas##dname; 13 | 14 | CUBLAS_FUNC_DEF(copy, Dcopy, Scopy) 15 | CUBLAS_FUNC_DEF(scal, Dscal, Sscal) 16 | CUBLAS_FUNC_DEF(dot, Ddot, Sdot) 17 | CUBLAS_FUNC_DEF(iamax, Idamax, Isamax) 18 | CUBLAS_FUNC_DEF(axpy, Daxpy, Saxpy) 19 | CUBLAS_FUNC_DEF(gemv, Dgemv, Sgemv) 20 | CUBLAS_FUNC_DEF(symv, Dsymv, Ssymv) 21 | CUBLAS_FUNC_DEF(trmv, Dtrmv, Strmv) 22 | CUBLAS_FUNC_DEF(gbmv, Dgbmv, Sgbmv) 23 | CUBLAS_FUNC_DEF(gemm, Dgemm, Sgemm) 24 | CUBLAS_FUNC_DEF(symm, Dsymm, Ssymm) 25 | CUBLAS_FUNC_DEF(trmm, Dtrmm, Strmm) 26 | CUBLAS_FUNC_DEF(ger, Dger, Sger) 27 | CUBLAS_FUNC_DEF(syr, Dsyr, Ssyr) 28 | CUBLAS_FUNC_DEF(syr2, Dsyr2, Ssyr2) 29 | CUBLAS_FUNC_DEF(syrk, Dsyrk, Ssyrk) 30 | CUBLAS_FUNC_DEF(trsv, Dtrsv, Strsv) 31 | CUBLAS_FUNC_DEF(trsm, Dtrsm, Strsm) 32 | -------------------------------------------------------------------------------- /share/tt/cpp/macro.hpp.tt: -------------------------------------------------------------------------------- 1 | [%- 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | -%] 8 | [%-PROCESS macro/alias_dims.hpp.tt-%] 9 | [%-PROCESS macro/create_action_typedef.hpp.tt-%] 10 | [%-PROCESS macro/create_action_typelist.hpp.tt-%] 11 | [%-PROCESS macro/create_action_typetree.hpp.tt-%] 12 | [%-PROCESS macro/create_block_typedef.hpp.tt-%] 13 | [%-PROCESS macro/create_block_typelist.hpp.tt-%] 14 | [%-PROCESS macro/declare_action_function.hpp.tt-%] 15 | [%-PROCESS macro/declare_action_matrix_function.hpp.tt-%] 16 | [%-PROCESS macro/declare_block_function.hpp.tt-%] 17 | [%-PROCESS macro/fetch_parents.hpp.tt-%] 18 | [%-PROCESS macro/get_var.hpp.tt-%] 19 | [%-PROCESS macro/offset_coord.hpp.tt-%] 20 | [%-PROCESS macro/put_output.hpp.tt-%] 21 | [%-PROCESS macro/read_argv.cpp.tt-%] 22 | [%-PROCESS macro/sig_action_function.hpp.tt-%] 23 | [%-PROCESS macro/sig_action_matrix_function.hpp.tt-%] 24 | [%-PROCESS macro/sig_block_function.hpp.tt-%] 25 | [%-PROCESS macro/std_action.hpp.tt-%] 26 | [%-PROCESS macro/std_action_function.hpp.tt-%] 27 | [%-PROCESS macro/std_block_function.hpp.tt-%] 28 | -------------------------------------------------------------------------------- /share/tt/cpp/action/ode_.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | [%-PROCESS action/misc/header.hpp.tt-%] 10 | 11 | [%- 12 | dfdt = action.get_named_arg('dfdt') 13 | -%] 14 | 15 | /** 16 | * Action: [% action.get_name %]. 17 | */ 18 | class [% class_name %] { 19 | public: 20 | [% std_action %] 21 | 22 | /** 23 | * Compute time derivative of variable. 24 | */ 25 | template 26 | static CUDA_FUNC_BOTH void dfdt(const T1 t, 27 | const bi::State<[% model_class_name %],L>& s, const int p, 28 | const CX& cox, const PX& pax, T2& dfdt); 29 | }; 30 | 31 | template 32 | inline void [% class_name %]::dfdt(const T1 t, 33 | const bi::State<[% model_class_name %],L>& s, const int p, 34 | const CX& cox, const PX& pax, T2& dfdt) { 35 | [% alias_dims(action) %] 36 | [% fetch_parents(action) %] 37 | [% offset_coord(action) %] 38 | dfdt = [% dfdt.to_cpp %]; 39 | } 40 | 41 | [%-PROCESS action/misc/footer.hpp.tt-%] 42 | -------------------------------------------------------------------------------- /share/src/bi/buffer/buffer.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_BUFFER_BUFFER_HPP 9 | #define BI_BUFFER_BUFFER_HPP 10 | 11 | namespace bi { 12 | /** 13 | * Schema flags. 14 | */ 15 | enum SchemaMode { 16 | /** 17 | * Default schema. 18 | */ 19 | DEFAULT, 20 | 21 | /** 22 | * Have multiple parameter samples. 23 | */ 24 | MULTI, 25 | 26 | /** 27 | * Multiple parameter samples, but parameters only. 28 | */ 29 | PARAM_ONLY, 30 | 31 | /** 32 | * Use flexi schema. 33 | */ 34 | FLEXI 35 | }; 36 | 37 | /** 38 | * File open flags. 39 | */ 40 | enum FileMode { 41 | /** 42 | * Open file read-only. 43 | */ 44 | READ_ONLY, 45 | 46 | /** 47 | * Open file for reading and writing, 48 | */ 49 | WRITE, 50 | 51 | /** 52 | * Open file for reading and writing, replacing any existing file of the 53 | * same name. 54 | */ 55 | REPLACE, 56 | 57 | /** 58 | * Open file for reading and writing, fails if any existing file of the 59 | * same name 60 | */ 61 | NEW 62 | }; 63 | } 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /share/src/bi/netcdf/NetCDFBuffer.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #include "NetCDFBuffer.hpp" 9 | 10 | #include "../misc/assert.hpp" 11 | 12 | bi::NetCDFBuffer::NetCDFBuffer(const std::string& file, const FileMode mode) : 13 | file(file), ncid(-1) { 14 | BI_ERROR_MSG(!file.empty(), "No file specified"); 15 | switch (mode) { 16 | case WRITE: 17 | ncid = nc_open(file, NC_WRITE); 18 | break; 19 | case NEW: 20 | ncid = nc_create(file, NC_NETCDF4 | NC_NOCLOBBER); 21 | nc_set_fill(ncid, NC_NOFILL); 22 | break; 23 | case REPLACE: 24 | ncid = nc_create(file, NC_NETCDF4); 25 | nc_set_fill(ncid, NC_NOFILL); 26 | break; 27 | default: 28 | ncid = nc_open(file, NC_NOWRITE); 29 | } 30 | } 31 | 32 | bi::NetCDFBuffer::NetCDFBuffer(const NetCDFBuffer& o) : 33 | file(o.file), ncid(-1) { 34 | if (!file.empty()) { 35 | ncid = nc_open(file, NC_NOWRITE); 36 | } 37 | } 38 | 39 | bi::NetCDFBuffer::~NetCDFBuffer() { 40 | nc_sync(ncid); 41 | nc_close(ncid); 42 | } 43 | 44 | void bi::NetCDFBuffer::clear() { 45 | // 46 | } 47 | -------------------------------------------------------------------------------- /share/src/bi/math/loc_vector.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_MATH_LOC_VECTOR_HPP 9 | #define BI_MATH_LOC_VECTOR_HPP 10 | 11 | #include "vector.hpp" 12 | #include "../misc/location.hpp" 13 | 14 | #include "boost/mpl/if.hpp" 15 | 16 | namespace bi { 17 | /** 18 | * Vector with location designated by template parameter. 19 | * 20 | * @ingroup math_matvec 21 | * 22 | * @tparam L Location. 23 | * @tparam T Scalar type. 24 | * @tparam size_value Static size, -1 for dynamic. 25 | * @tparam inc_value Static increment, -1 for dynamic. 26 | * 27 | * loc_vector is a convenience class for creating a vector on host or device 28 | * according to a template argument. 29 | */ 30 | template 31 | struct loc_vector { 32 | #ifdef ENABLE_CUDA 33 | typedef typename boost::mpl::if_c, 35 | host_vector >::type type; 36 | #else 37 | typedef host_vector type; 38 | #endif 39 | }; 40 | } 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /lib/Bi/Visitor/EvalConst.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | Bi::Visitor::EvalConst - visitor for evaluating a constant expression. 4 | 5 | =head1 SYNOPSIS 6 | 7 | use Bi::Visitor::EvalConst; 8 | $val = Bi::Visitor::EvalConst->evaluate($expr); 9 | 10 | =head1 INHERITS 11 | 12 | L 13 | 14 | =head1 METHODS 15 | 16 | =over 4 17 | 18 | =cut 19 | 20 | package Bi::Visitor::EvalConst; 21 | 22 | use parent 'Bi::Visitor'; 23 | use warnings; 24 | use strict; 25 | 26 | use Carp::Assert; 27 | use Bi::Visitor::ToPerl; 28 | 29 | =item B(I) 30 | 31 | Evaluate. 32 | 33 | =over 4 34 | 35 | =item I 36 | 37 | L object. 38 | 39 | =back 40 | 41 | Returns the result of evaluating the expression. 42 | 43 | =cut 44 | sub evaluate { 45 | my $class = shift; 46 | my $expr = shift; 47 | 48 | assert ($expr->isa('Bi::Expression') && $expr->is_const) if DEBUG; 49 | 50 | my $perl = Bi::Visitor::ToPerl->evaluate($expr); 51 | 52 | return eval($perl); 53 | } 54 | 55 | 1; 56 | 57 | =back 58 | 59 | =head1 AUTHOR 60 | 61 | Lawrence Murray 62 | 63 | =head1 VERSION 64 | 65 | $Rev$ $Date$ 66 | -------------------------------------------------------------------------------- /share/src/bi/host/math/sim_temp_vector.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_HOST_MATH_SIM_TEMP_VECTOR_HPP 9 | #define BI_HOST_MATH_SIM_TEMP_VECTOR_HPP 10 | 11 | #include "temp_vector.hpp" 12 | 13 | #include "boost/mpl/if.hpp" 14 | 15 | namespace bi { 16 | /** 17 | * Temporary host vector type that is similar to some other given stencil 18 | * type. 19 | * 20 | * @ingroup math_matvec 21 | * 22 | * @tparam VM1 Vector or matrix type. 23 | * @tparam size_value Static size, -1 for dynamic. 24 | * @tparam inc_value Static increment, -1 for dynamic. 25 | * 26 | * sim_temp_host_vector is a convenience class for creating a temporary vector 27 | * on host that is similar to the given vector or matrix type @p VM1 in the 28 | * sense that it has the same scalar type. 29 | */ 30 | template 31 | struct sim_temp_host_vector { 32 | /** 33 | * @internal 34 | */ 35 | typedef typename VM1::value_type T; 36 | 37 | typedef typename temp_host_vector::type type; 38 | }; 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /share/src/bi/concept/Kernel.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #error "Concept documentation only, should not be #included" 9 | 10 | namespace concept { 11 | /** 12 | * %Kernel. 13 | * 14 | * @ingroup concept 15 | * 16 | * @note This is a phony class, representing a concept, for documentation 17 | * purposes only. 18 | */ 19 | struct Kernel { 20 | /** 21 | * Evaluate the kernel. 22 | * 23 | * @param x \f$x\f$; point at which to evaluate the kernel. 24 | * 25 | * @return \f$\log \mathcal{K}(x)\f$; log-density of the kernel at the 26 | * given point. 27 | */ 28 | template 29 | T1 logDensity(const T1 x) const = 0; 30 | 31 | /** 32 | * Evaluate the kernel. 33 | * 34 | * @param x \f$x\f$; point at which to evaluate the kernel. 35 | * 36 | * @return \f$\mathcal{K}(x)\f$; density of the kernel at the given point. 37 | */ 38 | template 39 | T1 density(const T1 x) const = 0; 40 | 41 | /** 42 | * @copydoc density() 43 | */ 44 | template 45 | T1 operator()(const T1 x) const = 0; 46 | }; 47 | } 48 | -------------------------------------------------------------------------------- /share/src/bi/cuda/math/sim_temp_vector.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_MATH_SIM_TEMP_VECTOR_HPP 9 | #define BI_CUDA_MATH_SIM_TEMP_VECTOR_HPP 10 | 11 | #include "temp_vector.hpp" 12 | 13 | #include "boost/mpl/if.hpp" 14 | 15 | namespace bi { 16 | /** 17 | * Temporary device vector type that is similar to some other given stencil 18 | * type. 19 | * 20 | * @ingroup math_matvec 21 | * 22 | * @tparam VM1 Vector or matrix type. 23 | * @tparam size_value Static size, -1 for dynamic. 24 | * @tparam inc_value Static increment, -1 for dynamic. 25 | * 26 | * sim_temp_gpu_vector is a convenience class for creating a temporary vector 27 | * on device that is similar to the given vector or matrix type @p VM1 in the 28 | * sense that it has the same scalar type. 29 | */ 30 | template 31 | struct sim_temp_gpu_vector { 32 | /** 33 | * @internal 34 | */ 35 | typedef typename VM1::value_type T; 36 | 37 | typedef typename temp_gpu_vector::type type; 38 | }; 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /share/src/bi/cuda/math/magma.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * Macros for MAGMA usage. 5 | * 6 | * @author Lawrence Murray 7 | * $Rev$ 8 | * $Date$ 9 | */ 10 | #ifndef BI_CUDA_MATH_MAGMA_HPP 11 | #define BI_CUDA_MATH_MAGMA_HPP 12 | 13 | #include "cublas.hpp" 14 | #ifdef HAVE_MAGMA_H 15 | #include "magma.h" 16 | #endif 17 | 18 | #include "boost/typeof/typeof.hpp" 19 | 20 | /** 21 | * @def MAGMA_FUNC(name, sname, dname) 22 | * 23 | * Macro for constructing template facades for magma functions. 24 | */ 25 | #define MAGMA_FUNC(name, dname, sname) \ 26 | namespace bi { \ 27 | template \ 28 | struct magma_##name {}; \ 29 | \ 30 | template<> \ 31 | struct magma_##name { \ 32 | static BOOST_TYPEOF(magma_##sname) *func; \ 33 | }; \ 34 | \ 35 | template<> \ 36 | struct magma_##name { \ 37 | static BOOST_TYPEOF(magma_##dname) *func; \ 38 | }; \ 39 | } 40 | 41 | #ifdef HAVE_MAGMA_H 42 | MAGMA_FUNC(potrf, dpotrf_gpu, spotrf_gpu) 43 | MAGMA_FUNC(potrs, dpotrs_gpu, spotrs_gpu) 44 | MAGMA_FUNC(get_potrf_nb, get_dpotrf_nb, get_spotrf_nb) 45 | //MAGMA_FUNC(syevx, dsyevx_gpu, ssyevx_gpu) 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /lib/Bi/Client/rewrite.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | rewrite - output internal model representation after applying transformations 4 | and optimisations. 5 | 6 | =head1 SYNOPSIS 7 | 8 | libbi rewrite --model-file I.bi 9 | 10 | =head1 DESCRIPTION 11 | 12 | The C command takes a model specification and outputs a new 13 | specification that shows the internal transformations and 14 | optimisations applied by LibBi. It is useful for validation and debugging 15 | purposes. The new specification is written to C. 16 | 17 | =cut 18 | 19 | package Bi::Client::rewrite; 20 | 21 | use parent 'Bi::Client'; 22 | use warnings; 23 | use strict; 24 | 25 | use Bi::Gen::Bi; 26 | 27 | =head1 METHODS 28 | 29 | =over 4 30 | 31 | =cut 32 | 33 | sub init { 34 | my $self = shift; 35 | 36 | $self->{_binary} = undef; 37 | } 38 | 39 | sub is_cpp { 40 | return 0; 41 | } 42 | 43 | sub exec { 44 | my $self = shift; 45 | my $model = shift; 46 | 47 | my $bi = new Bi::Gen::Bi(); 48 | $bi->gen($model); 49 | } 50 | 51 | 1; 52 | 53 | =back 54 | 55 | =head1 AUTHOR 56 | 57 | Lawrence Murray 58 | 59 | =head1 VERSION 60 | 61 | $Rev$ $Date$ 62 | -------------------------------------------------------------------------------- /share/tt/cpp/dim.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | [%-class_name = 'Dim' _ dim.get_id-%] 10 | /** 11 | * @file 12 | * 13 | * @author Generated by LibBi 14 | * $Rev$ 15 | * $Date$ 16 | */ 17 | #ifndef LIBBI_[% class_name | upper %]_HPP 18 | #define LIBBI_[% class_name | upper %]_HPP 19 | 20 | #include "bi/model/Dim.hpp" 21 | #include "bi/math/scalar.hpp" 22 | 23 | /** 24 | * Dimension: [% dim.get_id %]. 25 | */ 26 | class [% class_name %] : public bi::Dim { 27 | public: 28 | /** 29 | * Constructor. 30 | */ 31 | [% class_name %](); 32 | 33 | /** 34 | * Get name of the dimension. 35 | * 36 | * @return Name of the dimension. 37 | */ 38 | static const char* getName(); 39 | 40 | /** 41 | * Id. 42 | */ 43 | static const int ID = [% dim.get_id %]; 44 | 45 | /** 46 | * Size. 47 | */ 48 | static const int SIZE = [% dim.get_size %]; 49 | }; 50 | 51 | inline [% class_name %]::[% class_name %]() : bi::Dim(*this) { 52 | // 53 | } 54 | 55 | inline const char* [% class_name %]::getName() { 56 | return "[% dim.get_name %]"; 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /share/src/bi/math/loc_temp_vector.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_MATH_LOC_TEMP_VECTOR_HPP 9 | #define BI_MATH_LOC_TEMP_VECTOR_HPP 10 | 11 | #include "temp_vector.hpp" 12 | #include "../misc/location.hpp" 13 | 14 | #include "boost/mpl/if.hpp" 15 | 16 | namespace bi { 17 | /** 18 | * Vector with location designated by template parameter. 19 | * 20 | * @ingroup math_matvec 21 | * 22 | * @tparam L Location. 23 | * @tparam T Scalar type. 24 | * @tparam size_value Static size, -1 for dynamic. 25 | * @tparam inc_value Static increment, -1 for dynamic. 26 | * 27 | * loc_temp_vector is a convenience class for creating a temporary vector on 28 | * host or device according to a template argument. 29 | */ 30 | template 31 | struct loc_temp_vector { 32 | #ifdef ENABLE_CUDA 33 | typedef typename boost::mpl::if_c, 35 | temp_host_vector >::type::type type; 36 | #else 37 | typedef typename temp_host_vector::type type; 38 | #endif 39 | }; 40 | } 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /lib/Bi/Client/draw.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | draw - draw a model as a directed graph. 4 | 5 | =head1 SYNOPSIS 6 | 7 | libbi draw --model-file I.bi > I.dot 8 | dot -Tpdf -o I.pdf I.dot 9 | 10 | =head1 DESCRIPTION 11 | 12 | The C command takes a model specification and outputs a directed graph 13 | to visualise the model. It is useful for validation and debugging 14 | purposes. The output is a C script that can be processed by the C 15 | program to create a figure. 16 | 17 | =cut 18 | 19 | package Bi::Client::draw; 20 | 21 | use parent 'Bi::Client'; 22 | use warnings; 23 | use strict; 24 | 25 | use Bi::Gen::Dot; 26 | 27 | =head1 METHODS 28 | 29 | =over 4 30 | 31 | =cut 32 | 33 | sub init { 34 | my $self = shift; 35 | 36 | $self->{_binary} = undef; 37 | } 38 | 39 | sub is_cpp { 40 | return 0; 41 | } 42 | 43 | sub needs_transform { 44 | return 0; 45 | } 46 | 47 | sub exec { 48 | my $self = shift; 49 | my $model = shift; 50 | 51 | my $dot = new Bi::Gen::Dot(); 52 | $dot->gen($model); 53 | } 54 | 55 | 1; 56 | 57 | =back 58 | 59 | =head1 AUTHOR 60 | 61 | Lawrence Murray 62 | 63 | =head1 VERSION 64 | 65 | $Rev$ $Date$ 66 | -------------------------------------------------------------------------------- /share/src/bi/cuda/updater/StaticUpdaterGPU.cuh: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_UPDATER_STATICUPDATERGPU_CUH 9 | #define BI_CUDA_UPDATER_STATICUPDATERGPU_CUH 10 | 11 | #include "../../state/State.hpp" 12 | #include "../../method/misc.hpp" 13 | 14 | namespace bi { 15 | /** 16 | * Static updater, on device. 17 | * 18 | * @ingroup method_updater 19 | * 20 | * @tparam B Model type. 21 | * @tparam S Action type list. 22 | */ 23 | template 24 | class StaticUpdaterGPU { 25 | public: 26 | static void update(State& s); 27 | }; 28 | } 29 | 30 | #include "StaticUpdaterKernel.cuh" 31 | #include "../device.hpp" 32 | 33 | template 34 | void bi::StaticUpdaterGPU::update(State& s) { 35 | const int N = (block_is_matrix::value) ? block_count::value : block_size::value; 36 | const int P = s.size(); 37 | dim3 Db, Dg; 38 | 39 | Db.x = bi::min(deviceIdealThreadsPerBlock(), P); 40 | Dg.x = (P + Db.x - 1)/Db.x; 41 | Db.y = 1; 42 | Dg.y = N; 43 | 44 | if (N > 0) { 45 | kernelStaticUpdater<<>>(s); 46 | CUDA_CHECK; 47 | } 48 | } 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /lib/Bi/Block/const_std_.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | const_std_ - optimisation block for L actions with arguments 4 | that are constant expressions. 5 | 6 | =cut 7 | 8 | package Bi::Block::const_std_; 9 | 10 | use parent 'Bi::Block'; 11 | use warnings; 12 | use strict; 13 | 14 | our $BLOCK_ARGS = []; 15 | 16 | sub validate { 17 | my $self = shift; 18 | 19 | $self->process_args($BLOCK_ARGS); 20 | 21 | if (@{$self->get_blocks} > 0) { 22 | die("a 'const_std_' block may not contain nested blocks\n"); 23 | } 24 | if (@{$self->get_actions} != 1) { 25 | die("a 'const_std_' block may only contain one action\n"); 26 | } 27 | 28 | my $action = $self->get_action; 29 | if ($action->get_name ne 'std_') { 30 | die("a 'const_std_' block may only contain 'std_' actions\n"); 31 | } else { 32 | foreach my $arg ('std') { 33 | if ($action->is_named_arg($arg) && !$action->get_named_arg($arg)->is_const) { 34 | die("a 'const_std_' block may only contain actions with constant '$arg' argument\n"); 35 | } 36 | } 37 | } 38 | } 39 | 40 | 1; 41 | 42 | =head1 AUTHOR 43 | 44 | Lawrence Murray 45 | 46 | =head1 VERSION 47 | 48 | $Rev$ $Date$ 49 | -------------------------------------------------------------------------------- /lib/Bi/Action/wiener.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | wiener - wiener process. 4 | 5 | =head1 SYNOPSIS 6 | 7 | dW ~ wiener() 8 | 9 | =head1 DESCRIPTION 10 | 11 | A C action specifies that a variable is an increment of a Wiener 12 | process: Gaussian distributed with mean zero and variance C, 13 | where C is the starting time, and C the ending time, of the current 14 | time interval 15 | 16 | =cut 17 | 18 | package Bi::Action::wiener; 19 | 20 | use parent 'Bi::Action'; 21 | use warnings; 22 | use strict; 23 | 24 | our $ACTION_ARGS = []; 25 | 26 | sub validate { 27 | my $self = shift; 28 | 29 | Bi::Action::validate($self); 30 | $self->process_args($ACTION_ARGS); 31 | $self->ensure_op('~'); 32 | 33 | unless ($self->get_left->get_shape->compat($self->get_shape)) { 34 | die("incompatible sizes on left and right sides of action.\n"); 35 | } 36 | 37 | $self->set_parent('wiener_'); 38 | } 39 | 40 | sub mean { 41 | # mean is always zero 42 | return new Bi::Expression::Literal(0.0); 43 | } 44 | 45 | sub jacobian { 46 | # always zero 47 | return ([], []); 48 | } 49 | 50 | 1; 51 | 52 | =head1 AUTHOR 53 | 54 | Lawrence Murray 55 | 56 | =head1 VERSION 57 | 58 | $Rev$ $Date$ 59 | -------------------------------------------------------------------------------- /lib/Bi/Block/common_std_.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | common_std_ - optimisation block for L actions with arguments 4 | that are common expressions. 5 | 6 | =cut 7 | 8 | package Bi::Block::common_std_; 9 | 10 | use parent 'Bi::Block'; 11 | use warnings; 12 | use strict; 13 | 14 | our $BLOCK_ARGS = []; 15 | 16 | sub validate { 17 | my $self = shift; 18 | 19 | $self->process_args($BLOCK_ARGS); 20 | 21 | if (@{$self->get_blocks} > 0) { 22 | die("a 'common_std_' block may not contain nested blocks\n"); 23 | } 24 | if (@{$self->get_actions} != 1) { 25 | die("a 'common_std_' block may only contain one action\n"); 26 | } 27 | 28 | my $action = $self->get_action; 29 | if ($action->get_name ne 'std_') { 30 | die("a 'common_std_' block may only contain 'std_' actions\n"); 31 | } else { 32 | foreach my $arg ('std') { 33 | if ($action->is_named_arg($arg) && !$action->get_named_arg($arg)->is_common) { 34 | die("a 'common_std_' block may only contain actions with common '$arg' argument\n"); 35 | } 36 | } 37 | } 38 | } 39 | 40 | 1; 41 | 42 | =head1 AUTHOR 43 | 44 | Lawrence Murray 45 | 46 | =head1 VERSION 47 | 48 | $Rev$ $Date$ 49 | -------------------------------------------------------------------------------- /share/src/bi/typelist/front.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_TYPELIST_FRONT_HPP 9 | #define BI_TYPELIST_FRONT_HPP 10 | 11 | #include "typelist.hpp" 12 | #include "empty.hpp" 13 | 14 | //#include "boost/static_assert.hpp" 15 | 16 | namespace bi { 17 | /** 18 | * @internal 19 | * 20 | * Implementation. 21 | */ 22 | template 23 | struct front_impl { 24 | 25 | }; 26 | 27 | /** 28 | * Get the first item of a type list. 29 | * 30 | * @ingroup typelist 31 | * 32 | * @tparam T A type list. 33 | */ 34 | template 35 | struct front { 36 | //BOOST_STATIC_ASSERT(!empty::value); 37 | typedef typename front_impl::type type; 38 | }; 39 | 40 | /** 41 | * @internal 42 | * 43 | * Implementation, scalar type at front. 44 | */ 45 | template 46 | struct front_impl { 47 | typedef item type; 48 | }; 49 | 50 | /** 51 | * @internal 52 | * 53 | * Implementation, list type at front. 54 | */ 55 | template 56 | struct front_impl { 57 | typedef typename front_impl::type type; 58 | }; 59 | 60 | } 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /share/src/bi/init.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * Documentation elements. 5 | * 6 | * @author Lawrence Murray 7 | * $Rev$ 8 | * $Date$ 9 | */ 10 | #ifndef BI_INIT_HPP 11 | #define BI_INIT_HPP 12 | 13 | namespace bi { 14 | /** 15 | * Initialise LibBi. 16 | * 17 | * @param threads Number of threads. 18 | */ 19 | void bi_init(const int threads = 0); 20 | } 21 | 22 | #include "misc/omp.hpp" 23 | #include "ode/IntegratorConstants.hpp" 24 | 25 | #ifdef ENABLE_CUDA 26 | #include "cuda/math/magma.hpp" 27 | #include "cuda/cuda.hpp" 28 | #include "cuda/device.hpp" 29 | #endif 30 | 31 | #ifdef ENABLE_MPI 32 | #include "boost/mpi.hpp" 33 | #endif 34 | 35 | // need to keep in same compilation unit as caller for bi_ode_init() 36 | inline void bi::bi_init(const int threads) { 37 | bi_omp_init(threads); 38 | bi_ode_init(); 39 | 40 | #ifdef ENABLE_CUDA 41 | cudaThreadSetCacheConfig(cudaFuncCachePreferL1); 42 | #ifdef HAVE_MAGMA_H 43 | magma_init(); 44 | #endif 45 | #ifdef ENABLE_MPI 46 | boost::mpi::communicator world; 47 | int rank = world.rank(); 48 | #else 49 | int rank = 0; 50 | #endif 51 | int dev = chooseDevice(rank); 52 | //std::cerr << "Rank " << rank << " using device " << dev << std::endl; 53 | #endif 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /share/src/bi/cuda/updater/SparseStaticUpdaterGPU.cuh: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_UPDATER_SPARSESTATICUPDATERGPU_CUH 9 | #define BI_CUDA_UPDATER_SPARSESTATICUPDATERGPU_CUH 10 | 11 | #include "../../state/State.hpp" 12 | #include "../../state/Mask.hpp" 13 | #include "../../method/misc.hpp" 14 | 15 | namespace bi { 16 | /** 17 | * Sparse static updater, on device. 18 | * 19 | * @ingroup method_updater 20 | * 21 | * @tparam B Model type. 22 | * @tparam S Action type list. 23 | */ 24 | template 25 | class SparseStaticUpdaterGPU { 26 | public: 27 | static void update(State& s, Mask& mask); 28 | }; 29 | } 30 | 31 | #include "SparseStaticUpdaterKernel.cuh" 32 | #include "../device.hpp" 33 | 34 | template 35 | void bi::SparseStaticUpdaterGPU::update(State& s, 36 | Mask& mask) { 37 | const int P = s.size(); 38 | 39 | if (mask.size() > 0) { 40 | dim3 Dg, Db; 41 | 42 | Db.x = bi::min(deviceIdealThreadsPerBlock(), P); // over trajectories 43 | Dg.x = (P + Db.x - 1)/Db.x; 44 | 45 | kernelSparseStaticUpdater<<>>(s, mask); 46 | CUDA_CHECK; 47 | } 48 | } 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /share/src/bi/misc/compile.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * Macros for compiler specific language elements. 5 | * 6 | * @author Lawrence Murray 7 | * $Rev$ 8 | * $Date$ 9 | */ 10 | #ifndef BI_MISC_COMPILE_HPP 11 | #define BI_MISC_COMPILE_HPP 12 | 13 | /** 14 | * @def BI_FORCE_INLINE 15 | * 16 | * Force inlining of particular function with gcc or Intel compiler. 17 | */ 18 | #if defined(__GNUC__) 19 | #define BI_FORCE_INLINE __attribute((always_inline)) 20 | #elif defined(__ICC) 21 | #define BI_FORCE_INLINE __forceinline 22 | #else 23 | #define BI_FORCE_INLINE 24 | #endif 25 | 26 | /** 27 | * @def BI_ALIGN 28 | * 29 | * Align variable in memory. 30 | * 31 | * @arg n Number of bytes to which to align. 32 | */ 33 | #define BI_ALIGN(n) __attribute((aligned (n))) 34 | 35 | /** 36 | * @def BI_UNUSED 37 | * 38 | * Declare variable as possibly unused, to eliminate warnings. 39 | */ 40 | #if defined(__GNUC__) 41 | #define BI_UNUSED __attribute((unused)) 42 | #else 43 | #define BI_UNUSED 44 | #endif 45 | 46 | /** 47 | * @def BI_THREAD 48 | * 49 | * Declare variable as thread local storage. 50 | */ 51 | #if defined(__GNUC__) and defined(ENABLE_OPENMP) and defined(HAVE_OMP_H) 52 | #define BI_THREAD __thread 53 | #else 54 | #define BI_THREAD 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /share/src/bi/cuda/cache/AncestryCacheKernel.cuh: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_CACHE_ANCESTRYCACHEKERNEL_CUH 9 | #define BI_CUDA_CACHE_ANCESTRYCACHEKERNEL_CUH 10 | 11 | #include "../cuda.hpp" 12 | 13 | namespace bi { 14 | /** 15 | * Kernel function for ancestry tree pruning. 16 | * 17 | * @tparam V1 Integer vector type. 18 | * @tparam V2 Integer vector type. 19 | * 20 | * @param as Ancestors. 21 | * @param os Offspring. 22 | * @param ls Leaves. 23 | * @param[out] numRemoved Number of nodes removed by each thread. 24 | */ 25 | template 26 | CUDA_FUNC_GLOBAL void kernelAncestryCachePrune(V1 as, V1 os, V1 ls, V2 numRemoved); 27 | 28 | } 29 | 30 | template 31 | CUDA_FUNC_GLOBAL void bi::kernelAncestryCachePrune(V1 as, V1 os, V1 ls, V2 numRemoved) { 32 | const int N = ls.size(); 33 | const int i = blockIdx.x*blockDim.x + threadIdx.x; 34 | int j, o, m = 0; 35 | 36 | if (i < N) { 37 | j = ls(i); 38 | o = os(j); 39 | while (o == 0) { 40 | ++m; 41 | j = as(j); 42 | if (j >= 0) { 43 | o = atomicSub(&os(j), 1) - 1; 44 | } else { 45 | break; 46 | } 47 | } 48 | numRemoved(i) = m; 49 | } 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /share/src/bi/null/SMCNullBuffer.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Pierre Jacob 5 | * @author Lawrence Murray 6 | * $Rev$ 7 | * $Date$ 8 | */ 9 | #ifndef BI_NULL_SMCNULLBUFFER_HPP 10 | #define BI_NULL_SMCNULLBUFFER_HPP 11 | 12 | #include "MCMCNullBuffer.hpp" 13 | 14 | namespace bi { 15 | /** 16 | * Null output buffer for SMC. 17 | * 18 | * @ingroup io_null 19 | */ 20 | class SMCNullBuffer: public MCMCNullBuffer { 21 | public: 22 | /** 23 | * @copydoc SMCNetCDFBuffer::SMCNetCDFBuffer() 24 | */ 25 | SMCNullBuffer(const Model& m, const size_t P = 0, const size_t T = 0, 26 | const std::string& file = "", const FileMode mode = READ_ONLY, 27 | const SchemaMode schema = MULTI); 28 | 29 | /** 30 | * @copydoc SMCNetCDFBuffer::writeLogWeights() 31 | */ 32 | template 33 | void writeLogWeights(const size_t p, const V1 lws); 34 | 35 | /** 36 | * @copydoc SMCNetCDFBuffer::writeLogEvidences() 37 | */ 38 | template 39 | void writeLogEvidences(const V1 les); 40 | }; 41 | } 42 | 43 | template 44 | void bi::SMCNullBuffer::writeLogWeights(const size_t p, const V1 lws) { 45 | // 46 | } 47 | 48 | template 49 | void bi::SMCNullBuffer::writeLogEvidences(const V1 les) { 50 | // 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /share/src/bi/null/MCMCNullBuffer.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_NULL_MCMCNULLBUFFER_HPP 9 | #define BI_NULL_MCMCNULLBUFFER_HPP 10 | 11 | #include "SimulatorNullBuffer.hpp" 12 | 13 | namespace bi { 14 | /** 15 | * Null output buffer for marginal MH. 16 | * 17 | * @ingroup io_null 18 | */ 19 | class MCMCNullBuffer: public SimulatorNullBuffer { 20 | public: 21 | /** 22 | * @copydoc MCMCNetCDFBuffer::MCMCNetCDFBuffer() 23 | */ 24 | MCMCNullBuffer(const Model& m, const size_t P = 0, const size_t T = 0, 25 | const std::string& file = "", const FileMode mode = READ_ONLY, 26 | const SchemaMode schema = MULTI); 27 | 28 | /** 29 | * @copydoc MCMCNetCDFBuffer::writeLogLikelihoods() 30 | */ 31 | template 32 | void writeLogLikelihoods(const size_t p, const V1 ll); 33 | 34 | /** 35 | * @copydoc MCMCNetCDFBuffer::writeLogPriors() 36 | */ 37 | template 38 | void writeLogPriors(const size_t p, const V1 lp); 39 | }; 40 | } 41 | 42 | template 43 | void bi::MCMCNullBuffer::writeLogLikelihoods(const size_t p, const V1 ll) { 44 | // 45 | } 46 | 47 | template 48 | void bi::MCMCNullBuffer::writeLogPriors(const size_t p, const V1 lp) { 49 | // 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /share/src/bi/primitive/cross_range.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_MISC_CROSSRANGE_HPP 9 | #define BI_MISC_CROSSRANGE_HPP 10 | 11 | #include "cross_sequence.hpp" 12 | 13 | #include "thrust/iterator/permutation_iterator.h" 14 | #include "thrust/distance.h" 15 | 16 | namespace bi { 17 | /** 18 | * Cross range. 19 | * 20 | * @ingroup primitive_iterators 21 | */ 22 | template 23 | struct cross_range { 24 | typedef typename thrust::iterator_difference::type difference_type; 25 | typedef typename cross_sequence::iterator CrossIterator; 26 | typedef thrust::permutation_iterator PermutationIterator; 27 | typedef PermutationIterator iterator; 28 | 29 | cross_range(Iterator first, Iterator last, const difference_type rows, const difference_type cols) : 30 | first(first), last(last), rows(rows), cols(cols) { 31 | // 32 | } 33 | 34 | iterator begin() const { 35 | return iterator(first, cross_sequence(0, rows, cols).begin()); 36 | } 37 | 38 | iterator end() const { 39 | return begin() + rows*cols; 40 | } 41 | 42 | private: 43 | Iterator first, last; 44 | difference_type rows, cols; 45 | }; 46 | 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /INSTALL_LINUX.md: -------------------------------------------------------------------------------- 1 | # Installation on Linux 2 | 3 | On Linux, dependencies are readily available from package 4 | managers. See the list of requirements in `INSTALL_GENERIC.md` for 5 | what to install, or the specific instructions for Ubuntu and openSUSE 6 | below. 7 | 8 | ## Step 1: Install required packages 9 | 10 | On Ubuntu: 11 | 12 | sudo apt-get install libblas-dev liblapack-dev libqrupdate-dev \ 13 | libboost-all-dev libgsl0-dev libnetcdf-dev autoconf automake 14 | 15 | On openSUSE: 16 | 17 | sudo zypper install blas lapack qrupdate boost-devel gsl-devel \ 18 | netcdf-devel autoconf automake 19 | 20 | ## Step 2 (optional): Install CUDA 21 | 22 | If you have a CUDA-enabled GPU and would like LibBi to be able to use 23 | it, you must also download and install the CUDA Toolkit 24 | . 25 | 26 | ## Step 3: Install Thrust 27 | 28 | If CUDA *is not* installed, it is necessary to install Thrust. If CUDA 29 | *is* installed, Thrust is included with it, and need not be installed 30 | separately. 31 | 32 | To install Thrust: 33 | 34 | wget https://github.com/thrust/thrust/releases/download/v1.7.0/thrust-1.7.0.zip 35 | unzip thrust-1.7.0.zip 36 | sudo mv thrust /usr/local/include 37 | 38 | ## Step 4: Install LibBi 39 | 40 | Install LibBi as per the instructions in `INSTALL.md`. 41 | -------------------------------------------------------------------------------- /share/src/bi/host/resampler/MetropolisResamplerHost.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_HOST_RESAMPLER_METROPOLISRESAMPLERHOST_HPP 9 | #define BI_HOST_RESAMPLER_METROPOLISRESAMPLERHOST_HPP 10 | 11 | template 12 | void bi::MetropolisResamplerHost::ancestors(Random& rng, const V1 lws, 13 | V2 as, int B) { 14 | const int P1 = lws.size(); // number of particles 15 | const int P2 = as.size(); // number of ancestors to draw 16 | 17 | #pragma omp parallel 18 | { 19 | real alpha, lw1, lw2; 20 | int k, p1, p2, p; 21 | 22 | #pragma omp for 23 | for (p = 0; p < P2; ++p) { 24 | p1 = p; 25 | lw1 = lws(p); 26 | for (k = 0; k < B; ++k) { 27 | p2 = rng.uniformInt(0, P1 - 1); 28 | lw2 = lws(p2); 29 | alpha = rng.uniform(); 30 | 31 | if (bi::log(alpha) < lw2 - lw1) { 32 | /* accept */ 33 | p1 = p2; 34 | lw1 = lw2; 35 | } 36 | } 37 | 38 | /* write result */ 39 | as(p) = p1; 40 | } 41 | } 42 | } 43 | 44 | template 45 | void bi::MetropolisResamplerHost::ancestorsPermute(Random& rng, const V1 lws, 46 | V2 as, int B) { 47 | ancestors(rng, lws, as, B); 48 | permute(as); 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /share/src/bi/cuda/math/temp_vector.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_MATH_TEMP_VECTOR_HPP 9 | #define BI_CUDA_MATH_TEMP_VECTOR_HPP 10 | 11 | #include "vector.hpp" 12 | #include "../../primitive/device_allocator.hpp" 13 | #include "../../primitive/pooled_allocator.hpp" 14 | #include "../../primitive/pipelined_allocator.hpp" 15 | 16 | namespace bi { 17 | /** 18 | * Temporary vector on device. 19 | * 20 | * @ingroup math_matvec 21 | * 22 | * @tparam T Scalar type. 23 | * @tparam size_value Static size, -1 for dynamic. 24 | * @tparam inc_value Static increment, -1 for dynamic. 25 | * 26 | * temp_gpu_vector is a convenience class for producing vectors in device 27 | * memory that are suitable for short-term use before destruction. It uses 28 | * pooled_allocator to reuse allocated buffers, as device memory allocations 29 | * can be slow. 30 | */ 31 | template 32 | struct temp_gpu_vector { 33 | /** 34 | * @internal 35 | * 36 | * Allocator type. 37 | */ 38 | typedef pipelined_allocator > > allocator_type; 39 | 40 | /** 41 | * Vector type. 42 | */ 43 | typedef gpu_vector type; 44 | }; 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /share/src/bi/typelist/index.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_TYPELIST_INDEX_HPP 9 | #define BI_TYPELIST_INDEX_HPP 10 | 11 | #include "front.hpp" 12 | #include "pop_front.hpp" 13 | 14 | namespace bi { 15 | /** 16 | * @internal 17 | * 18 | * Implementation. 19 | */ 20 | template 21 | struct index_impl { 22 | static const int value = index_impl::type,typename front::type,X,reps+1>::value; 23 | }; 24 | 25 | /** 26 | * Index of first occurrence of type in type list. 27 | * 28 | * @ingroup typelist 29 | * 30 | * @tparam T A type list. 31 | * @ptaram X A type. 32 | */ 33 | template 34 | struct index { 35 | static const int value = index_impl::type,typename front::type,X,0>::value; 36 | }; 37 | 38 | /** 39 | * @internal 40 | * 41 | * Implementation, base case. 42 | */ 43 | template 44 | struct index_impl { 45 | static const int value = reps; 46 | }; 47 | 48 | /** 49 | * @internal 50 | * 51 | * Implementation, error case. 52 | */ 53 | template 54 | struct index_impl { 55 | // 56 | }; 57 | 58 | } 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /share/src/bi/cuda/updater/DynamicUpdaterGPU.cuh: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_UPDATER_DYNAMICUPDATERGPU_CUH 9 | #define BI_CUDA_UPDATER_DYNAMICUPDATERGPU_CUH 10 | 11 | #include "../../state/State.hpp" 12 | #include "../../method/misc.hpp" 13 | 14 | namespace bi { 15 | /** 16 | * Dynamic updater, on device. 17 | * 18 | * @ingroup method_updater 19 | * 20 | * @tparam B Model type. 21 | * @tparam S Action type list. 22 | */ 23 | template 24 | class DynamicUpdaterGPU { 25 | public: 26 | template 27 | static void update(const T1 t1, const T1 t2, State& s); 28 | }; 29 | } 30 | 31 | #include "DynamicUpdaterKernel.cuh" 32 | #include "../device.hpp" 33 | 34 | template 35 | template 36 | void bi::DynamicUpdaterGPU::update(const T1 t1, const T1 t2, 37 | State& s) { 38 | const int N = (block_is_matrix::value) ? block_count::value : block_size::value; 39 | const int P = s.size(); 40 | dim3 Db, Dg; 41 | 42 | Db.x = bi::min(deviceIdealThreadsPerBlock(), P); 43 | Db.y = 1; 44 | Dg.x = (P + Db.x - 1)/Db.x; 45 | Dg.y = N; 46 | 47 | if (N > 0) { 48 | kernelDynamicUpdater<<>>(t1, t2, s); 49 | CUDA_CHECK; 50 | } 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /share/bi.lex: -------------------------------------------------------------------------------- 1 | MODEL \bmodel\b 2 | SUB \bsub\b 3 | DIM \bdim\b 4 | CONST \bconst\b 5 | INLINE \binline\b 6 | STATE \bstate\b 7 | STATE_AUX \bstate_aux_\b 8 | NOISE \bnoise\b 9 | INPUT \binput\b 10 | OBS \bobs\b 11 | PARAM \bparam\b 12 | PARAM_AUX \bparam_aux_\b 13 | DO \bdo\b 14 | THEN \bthen\b 15 | DT \bdt\b 16 | IDENTIFIER [a-zA-Z_][a-zA-Z_0-9]* 17 | COMMENT_INLINE \/\*(.|\n)*?\*\/ 18 | COMMENT_EOL \/\/.* 19 | COMMENT_BEGIN \/\* 20 | COMMENT_END \*\/ 21 | STRING_LITERAL '(\\.|[^\\'])*' 22 | STRING_LITERAL "(\\.|[^\\"])*" 23 | LITERAL [0-9]+\.[0-9]*([Ee][+-]?[0-9]+)? 24 | LITERAL [0-9]*\.[0-9]+([Ee][+-]?[0-9]+)? 25 | INTEGER_LITERAL [0-9]+[Ee][+-]?[0-9]+ 26 | INTEGER_LITERAL [0-9]+ 27 | SET_TO <\- 28 | RIGHT_OP >> 29 | LEFT_OP << 30 | AND_OP \&\& 31 | OR_OP \|\| 32 | LE_OP <= 33 | GE_OP >= 34 | EQ_OP == 35 | NE_OP \!= 36 | POW_OP \*\* 37 | ELEM_MUL_OP \.\* 38 | ELEM_DIV_OP \.\/ 39 | ELEM_ADD_OP \.\+ 40 | ELEM_SUB_OP \.\- 41 | ELEM_POW_OP \.\*\* 42 | OP [;,:=()\[\]\{\}&!~\-+*\/%<>\^|?] 43 | NEW_LINE \n 44 | OTHER . 45 | -------------------------------------------------------------------------------- /share/src/bi/primitive/repeated_sequence.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_MISC_REPEATED_SEQUENCE_HPP 9 | #define BI_MISC_REPEATED_SEQUENCE_HPP 10 | 11 | #include "../primitive/functor.hpp" 12 | 13 | #include "thrust/iterator/counting_iterator.h" 14 | #include "thrust/iterator/transform_iterator.h" 15 | 16 | namespace bi { 17 | /** 18 | * Repeated sequence, repeating an entire counting sequence multiple times. 19 | * 20 | * @ingroup primitive_iterators 21 | */ 22 | template 23 | struct repeated_sequence { 24 | typedef modulus_constant_functor ModulusFunc; 25 | typedef thrust::counting_iterator CountingIterator; 26 | typedef thrust::transform_iterator TransformIterator; 27 | typedef TransformIterator iterator; 28 | 29 | /** 30 | * Constructor. 31 | * 32 | * @param first First element of the counting sequence. 33 | * @param reps Number of times to repeat the counting sequence. 34 | */ 35 | repeated_sequence(const T first, const T reps) : 36 | first(first), reps(reps) { 37 | // 38 | } 39 | 40 | iterator begin() const { 41 | return TransformIterator(CountingIterator(first), ModulusFunc(reps)); 42 | } 43 | 44 | private: 45 | const T first, reps; 46 | }; 47 | 48 | } 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /share/src/bi/host/math/qrupdate.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * Function declarations and macros for qrupdate usage. See Fortran source 5 | * of qrupdate for function documentation. 6 | * 7 | * @author Lawrence Murray 8 | * $Rev$ 9 | * $Date$ 10 | */ 11 | #ifndef BI_HOST_MATH_QRUPDATE_HPP 12 | #define BI_HOST_MATH_QRUPDATE_HPP 13 | 14 | extern "C" { 15 | void sch1up_(int* n, float* R, int& ldr, float* u, float* w); 16 | void dch1up_(int* n, double* R, int& ldr, double* u, double* w); 17 | void sch1dn_(int* n, float* R, int* ldr, float* u, float* w, int* info); 18 | void dch1dn_(int* n, double* R, int* ldr, double* u, double* w, int* info); 19 | } 20 | 21 | #include "boost/typeof/typeof.hpp" 22 | 23 | /** 24 | * @def QRUPDATE_FUNC(name, sname, dname) 25 | * 26 | * Macro for constructing template facades for qrupdate functions. 27 | */ 28 | #define QRUPDATE_FUNC(name, dname, sname) \ 29 | namespace bi { \ 30 | template \ 31 | struct qrupdate_##name {}; \ 32 | \ 33 | template<> \ 34 | struct qrupdate_##name { \ 35 | static BOOST_TYPEOF(sname##_) *func; \ 36 | }; \ 37 | \ 38 | template<> \ 39 | struct qrupdate_##name { \ 40 | static BOOST_TYPEOF(dname##_) *func; \ 41 | }; \ 42 | } 43 | 44 | QRUPDATE_FUNC(ch1up, dch1up, sch1up) 45 | QRUPDATE_FUNC(ch1dn, dch1dn, sch1dn) 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /share/src/bi/cuda/math/sim_temp_matrix.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_MATH_SIM_TEMP_MATRIX_HPP 9 | #define BI_CUDA_MATH_SIM_TEMP_MATRIX_HPP 10 | 11 | #include "temp_matrix.hpp" 12 | 13 | #include "boost/mpl/if.hpp" 14 | 15 | namespace bi { 16 | /** 17 | * Temporary device matrix type that is similar to some other given stencil 18 | * type. 19 | * 20 | * @ingroup math_matvec 21 | * 22 | * @tparam VM1 Vector or matrix type. 23 | * @tparam size1_value Static number of rows, -1 for dynamic. 24 | * @tparam size2_value Static number of columns, -1 for dynamic. 25 | * @tparam lead_value Static lead, -1 for dynamic. 26 | * @tparam inc_value Static column increment, -1 for dynamic. 27 | * 28 | * sim_temp_gpu_matrix is a convenience class for creating a temporary matrix 29 | * on device that is similar to the given vector or matrix type @p VM1 in the 30 | * sense that it has the same scalar type. 31 | */ 32 | template 34 | struct sim_temp_gpu_matrix { 35 | /** 36 | * @internal 37 | */ 38 | typedef typename VM1::value_type T; 39 | 40 | typedef typename temp_gpu_matrix::type type; 41 | }; 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /share/src/bi/host/math/sim_temp_matrix.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_HOST_MATH_SIM_TEMP_MATRIX_HPP 9 | #define BI_HOST_MATH_SIM_TEMP_MATRIX_HPP 10 | 11 | #include "temp_matrix.hpp" 12 | 13 | #include "boost/mpl/if.hpp" 14 | 15 | namespace bi { 16 | /** 17 | * Temporary host matrix type that is similar to some other given stencil 18 | * type. 19 | * 20 | * @ingroup math_matvec 21 | * 22 | * @tparam VM1 vector or matrix type. 23 | * @tparam size1_value Static number of rows, -1 for dynamic. 24 | * @tparam size2_value Static number of columns, -1 for dynamic. 25 | * @tparam lead_value Static lead, -1 for dynamic. 26 | * @tparam inc_value Static column increment, -1 for dynamic. 27 | * 28 | * sim_temp_host_matrix is a convenience class for creating a temporary matrix 29 | * on host that is similar to the given vector or matrix type @p VM1 in the 30 | * sense that it has the same scalar type. 31 | */ 32 | template 34 | struct sim_temp_host_matrix { 35 | /** 36 | * @internal 37 | */ 38 | typedef typename VM1::value_type T; 39 | 40 | typedef typename temp_host_matrix::type type; 41 | }; 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /share/src/bi/cuda/resampler/MultinomialResamplerGPU.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_RESAMPLER_MULTINOMIALRESAMPLERGPU_HPP 9 | #define BI_CUDA_RESAMPLER_MULTINOMIALRESAMPLERGPU_HPP 10 | 11 | template 12 | void bi::MultinomialResamplerGPU::ancestors(Random& rng, const V1 lws, V2 as, 13 | MultinomialPrecompute& pre) 14 | throw (ParticleFilterDegeneratedException) { 15 | typedef typename V1::value_type T1; 16 | 17 | const int P = as.size(); 18 | const int lwsSize = lws.size(); 19 | 20 | typename sim_temp_vector::type alphas(P); 21 | typename sim_temp_vector::type as1(P); 22 | 23 | if (pre.W > 0) { 24 | /* random numbers */ 25 | rng.uniforms(alphas, 0.0, pre.W); 26 | 27 | /* sample */ 28 | if (pre.sort) { 29 | bi::lower_bound(pre.Ws, alphas, as1); 30 | bi::gather(as1, pre.ps, as); 31 | } else { 32 | bi::lower_bound(pre.Ws, alphas, as); 33 | } 34 | } else { 35 | throw ParticleFilterDegeneratedException(); 36 | } 37 | 38 | /* post-condition */ 39 | //BI_ASSERT(max_reduce(as) < lws.size()); 40 | // ^ CUDA craziness, doesn't like the above at runtime 41 | #ifndef NDEBUG 42 | bool cond = max_reduce(as) < lws.size(); 43 | BI_ASSERT(cond); 44 | #endif 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /share/src/bi/cuda/updater/SparseStaticSamplerGPU.cuh: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_UPDATER_SPARSESTATICSAMPLERGPU_CUH 9 | #define BI_CUDA_UPDATER_SPARSESTATICSAMPLERGPU_CUH 10 | 11 | #include "../../random/Random.hpp" 12 | #include "../../state/State.hpp" 13 | #include "../../state/Mask.hpp" 14 | #include "../../method/misc.hpp" 15 | 16 | namespace bi { 17 | /** 18 | * Sparse static sampling, on device. 19 | * 20 | * @ingroup method_updater 21 | * 22 | * @tparam B Model type. 23 | * @tparam S Action type list. 24 | */ 25 | template 26 | class SparseStaticSamplerGPU { 27 | public: 28 | static void update(Random& rng, State& s, 29 | Mask& mask); 30 | }; 31 | } 32 | 33 | #include "SparseStaticSamplerKernel.cuh" 34 | #include "../device.hpp" 35 | 36 | template 37 | void bi::SparseStaticSamplerGPU::update(Random& rng, 38 | State& s, Mask& mask) { 39 | const int P = s.size(); 40 | 41 | if (mask.size() > 0) { 42 | dim3 Dg, Db; 43 | 44 | Db.x = bi::min(P, deviceIdealThreadsPerBlock()); 45 | Dg.x = (bi::min(P, deviceIdealThreads()) + Db.x - 1)/Db.x; 46 | 47 | kernelSparseStaticSampler<<>>(rng.devRngs, s, mask); 48 | CUDA_CHECK; 49 | } 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /share/tt/cpp/block/parameter.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | [%-PROCESS block/misc/header.hpp.tt-%] 10 | 11 | [%-create_block_typelist(block)-%] 12 | 13 | /** 14 | * Block: [% block.get_name %]. 15 | */ 16 | class [% class_name %] { 17 | public: 18 | [%-create_block_typedef(block)-%] 19 | 20 | [% declare_block_static_function('simulate') %] 21 | [% declare_block_static_function('sample') %] 22 | [% declare_block_static_function('logdensity') %] 23 | [% declare_block_static_function('maxlogdensity') %] 24 | }; 25 | 26 | [% sig_block_static_function('simulate') %] { 27 | [%-FOREACH subblock IN block.get_blocks %] 28 | Block[% subblock.get_id %]::simulates(s); 29 | [%-END %] 30 | } 31 | 32 | [% sig_block_static_function('sample') %] { 33 | [%-FOREACH subblock IN block.get_blocks %] 34 | Block[% subblock.get_id %]::samples(rng, s); 35 | [%-END %] 36 | } 37 | 38 | [% sig_block_static_function('logdensity') %] { 39 | [%-FOREACH subblock IN block.get_blocks %] 40 | Block[% subblock.get_id %]::logDensities(s, lp); 41 | [%-END %] 42 | } 43 | 44 | [% sig_block_static_function('maxlogdensity') %] { 45 | [%-FOREACH subblock IN block.get_blocks %] 46 | Block[% subblock.get_id %]::maxLogDensities(s, lp); 47 | [%-END %] 48 | } 49 | 50 | [%-PROCESS block/misc/footer.hpp.tt-%] 51 | -------------------------------------------------------------------------------- /share/src/bi/typelist/contains.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_TYPELIST_CONTAINS_HPP 9 | #define BI_TYPELIST_CONTAINS_HPP 10 | 11 | #include "front.hpp" 12 | #include "pop_front.hpp" 13 | 14 | namespace bi { 15 | /** 16 | * @internal 17 | * 18 | * Implementation. 19 | */ 20 | template 21 | struct contains_impl { 22 | static const int value = contains_impl::type,typename front::type,X,reps+1>::value; 23 | }; 24 | 25 | /** 26 | * Does type list contain type? 27 | * 28 | * @ingroup typelist 29 | * 30 | * @tparam T A type list. 31 | * @ptaram X A type. 32 | */ 33 | template 34 | struct contains { 35 | static const int value = contains_impl::type,typename front::type,X,0>::value; 36 | }; 37 | 38 | /** 39 | * @internal 40 | * 41 | * Implementation, base case. 42 | */ 43 | template 44 | struct contains_impl { 45 | static const bool value = true; 46 | }; 47 | 48 | /** 49 | * @internal 50 | * 51 | * Implementation, base case. 52 | */ 53 | template 54 | struct contains_impl { 55 | static const bool value = false; 56 | }; 57 | 58 | } 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /share/src/bi/cuda/updater/StaticSamplerGPU.cuh: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_UPDATER_STATICSAMPLERGPU_CUH 9 | #define BI_CUDA_UPDATER_STATICSAMPLERGPU_CUH 10 | 11 | #include "../../random/Random.hpp" 12 | #include "../../state/State.hpp" 13 | #include "../../method/misc.hpp" 14 | 15 | namespace bi { 16 | /** 17 | * Static sampler, on device. 18 | * 19 | * @ingroup method_updater 20 | * 21 | * @tparam B Model type. 22 | * @tparam S Action type list. 23 | */ 24 | template 25 | class StaticSamplerGPU { 26 | public: 27 | /** 28 | * @copydoc StaticSampler::samples(Random&, State&) 29 | */ 30 | static void samples(Random& rng, State& s); 31 | }; 32 | } 33 | 34 | #include "StaticSamplerKernel.cuh" 35 | #include "../device.hpp" 36 | 37 | template 38 | void bi::StaticSamplerGPU::samples(Random& rng, State& s) { 39 | const int N = (block_is_matrix::value) ? block_count::value : block_size::value; 40 | const int P = s.size(); 41 | dim3 Db, Dg; 42 | 43 | Db.x = bi::min(P, deviceIdealThreadsPerBlock()); 44 | Dg.x = (bi::min(P, deviceIdealThreads()) + Db.x - 1)/Db.x; 45 | 46 | if (N > 0) { 47 | kernelStaticSampler<<>>(rng.devRngs, s); 48 | CUDA_CHECK; 49 | } 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /share/src/bi/primitive/stuttered_sequence.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_MISC_STUTTERED_SEQUENCE_HPP 9 | #define BI_MISC_STUTTERED_SEQUENCE_HPP 10 | 11 | #include "../primitive/functor.hpp" 12 | 13 | #include "thrust/iterator/counting_iterator.h" 14 | #include "thrust/iterator/transform_iterator.h" 15 | 16 | namespace bi { 17 | /** 18 | * Stuttered sequence, repeating each element of a counting sequence several 19 | * times. 20 | * 21 | * @ingroup primitive_iterators 22 | */ 23 | template 24 | struct stuttered_sequence { 25 | typedef div_constant_functor DivideFunc; 26 | typedef thrust::counting_iterator CountingIterator; 27 | typedef thrust::transform_iterator TransformIterator; 28 | typedef TransformIterator iterator; 29 | 30 | /** 31 | * Constructor. 32 | * 33 | * @param first First element of the counting sequence. 34 | * @param reps Number of times to repeat each element in the counting 35 | * sequence. 36 | */ 37 | stuttered_sequence(const T first, const T reps) : 38 | first(first), reps(reps) { 39 | // 40 | } 41 | 42 | iterator begin() const { 43 | return TransformIterator(CountingIterator(first), DivideFunc(reps)); 44 | } 45 | 46 | private: 47 | const T first, reps; 48 | }; 49 | 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /share/src/bi/math/loc_matrix.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_MATH_LOC_MATRIX_HPP 9 | #define BI_MATH_LOC_MATRIX_HPP 10 | 11 | #include "matrix.hpp" 12 | #include "../misc/location.hpp" 13 | 14 | #include "boost/mpl/if.hpp" 15 | 16 | namespace bi { 17 | /** 18 | * Matrix with location designated by template parameter. 19 | * 20 | * @ingroup math_matvec 21 | * 22 | * @tparam L Location. 23 | * @tparam T Scalar type. 24 | * @tparam size1_value Static number of rows, -1 for dynamic. 25 | * @tparam size2_value Static number of columns, -1 for dynamic. 26 | * @tparam lead_value Static lead, -1 for dynamic. 27 | * @tparam inc_value Static column increment, -1 for dynamic. 28 | * 29 | * loc_matrix is a convenience class for creating a matrix on host or device 30 | * according to a template argument. 31 | */ 32 | template 34 | struct loc_matrix { 35 | #ifdef ENABLE_CUDA 36 | typedef typename boost::mpl::if_c, 38 | host_matrix >::type type; 39 | #else 40 | typedef host_matrix type; 41 | #endif 42 | }; 43 | } 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /share/src/bi/ode/IntegratorConstants.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * Easy interface for setting ODE parameters. 5 | * 6 | * @author Lawrence Murray 7 | * $Rev$ 8 | * $Date$ 9 | * 10 | */ 11 | #ifndef BI_MATH_ODE_HPP 12 | #define BI_MATH_ODE_HPP 13 | 14 | #include "../host/ode/IntegratorConstants.hpp" 15 | #ifdef __CUDACC__ 16 | #include "../cuda/ode/IntegratorConstants.cuh" 17 | #endif 18 | 19 | /** 20 | * Initialise ODE parameters. 21 | */ 22 | void bi_ode_init(); 23 | 24 | /** 25 | * Set ODE parameters. 26 | * 27 | * @param h0 Initial step size. 28 | * @param atoler Absolute error tolerance. 29 | * @param rtoler Relative error tolerance. 30 | */ 31 | void bi_ode_set(const real h0, const real atoler, const real rtoler); 32 | 33 | inline void bi_ode_init() { 34 | #ifdef __CUDACC__ 35 | ode_init(); 36 | #endif 37 | h_ode_init(); 38 | } 39 | 40 | inline void bi_ode_set(const real h0, const real atoler, const real rtoler) { 41 | if (h_h0 != h0) { 42 | h_ode_set_h0(h0); 43 | #ifdef __CUDACC__ 44 | ode_set_h0(h0); 45 | #endif 46 | } 47 | if (h_atoler != atoler) { 48 | h_ode_set_atoler(atoler); 49 | #ifdef __CUDACC__ 50 | ode_set_atoler(atoler); 51 | #endif 52 | } 53 | if (h_rtoler != rtoler) { 54 | h_ode_set_rtoler(rtoler); 55 | #ifdef __CUDACC__ 56 | ode_set_rtoler(rtoler); 57 | #endif 58 | } 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /lib/Bi/Block/observation.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | observation - the likelihood function. 4 | 5 | =head1 SYNOPSIS 6 | 7 | sub observation { 8 | ... 9 | } 10 | 11 | =head1 DESCRIPTION 12 | 13 | Actions in the C block may only refer to variables of type 14 | C, C and C. They may only target variables of type 15 | C. 16 | 17 | =cut 18 | 19 | package Bi::Block::observation; 20 | 21 | use parent 'Bi::Block'; 22 | use warnings; 23 | use strict; 24 | 25 | our $BLOCK_ARGS = []; 26 | 27 | sub validate { 28 | my $self = shift; 29 | 30 | $self->process_args($BLOCK_ARGS); 31 | 32 | my $name = $self->get_name; 33 | my $actions = $self->get_all_actions; 34 | foreach my $action (@$actions) { 35 | my $op = $action->get_op; 36 | my $var_name = $action->get_left->get_var->get_name; 37 | my $type = $action->get_left->get_var->get_type; 38 | 39 | if ($op ne '~') { 40 | warn("only '~' actions should appear in the '$name' block.\n"); 41 | } elsif ($type ne 'obs') { 42 | warn("variable '$var_name' is of type '$type'; only variables of type 'obs' should appear on the left side of actions in the '$name' block.\n"); 43 | } 44 | } 45 | 46 | } 47 | 48 | 1; 49 | 50 | =head1 AUTHOR 51 | 52 | Lawrence Murray 53 | 54 | =head1 VERSION 55 | 56 | $Rev$ $Date$ 57 | -------------------------------------------------------------------------------- /share/src/bi/primitive/pitched_range.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_MISC_PITCHED_RANGE_HPP 9 | #define BI_MISC_PITCHED_RANGE_HPP 10 | 11 | #include "pitched_sequence.hpp" 12 | 13 | #include "thrust/iterator/permutation_iterator.h" 14 | #include "thrust/distance.h" 15 | 16 | namespace bi { 17 | /** 18 | * Pitched range. 19 | * 20 | * @ingroup primitive_iterators 21 | */ 22 | template 23 | struct pitched_range { 24 | typedef typename thrust::iterator_difference::type difference_type; 25 | typedef typename pitched_sequence::iterator PitchedIterator; 26 | typedef thrust::permutation_iterator PermutationIterator; 27 | typedef PermutationIterator iterator; 28 | 29 | pitched_range(Iterator first, Iterator last, const difference_type rows, const difference_type lead) : 30 | first(first), last(last), rows(rows), lead(lead) { 31 | // 32 | } 33 | 34 | iterator begin() const { 35 | return iterator(first, pitched_sequence(0, rows, lead).begin()); 36 | } 37 | 38 | iterator end() const { 39 | difference_type d = thrust::distance(first, last); 40 | return begin() + (d/lead*rows) + (d % lead); 41 | } 42 | 43 | private: 44 | Iterator first, last; 45 | difference_type rows, lead; 46 | }; 47 | 48 | } 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /share/src/bi/cuda/updater/StaticLogDensityGPU.cuh: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_UPDATER_STATICLOGDENSITYGPU_CUH 9 | #define BI_CUDA_UPDATER_STATICLOGDENSITYGPU_CUH 10 | 11 | #include "../../state/State.hpp" 12 | #include "../../method/misc.hpp" 13 | 14 | namespace bi { 15 | /** 16 | * Static log-density updater, on device. 17 | * 18 | * @ingroup method_updater 19 | * 20 | * @tparam B Model type. 21 | * @tparam S Action type list. 22 | */ 23 | template 24 | class StaticLogDensityGPU { 25 | public: 26 | template 27 | static void logDensities(State& s, V1 lp); 28 | }; 29 | } 30 | 31 | #include "StaticLogDensityKernel.cuh" 32 | #include "../device.hpp" 33 | 34 | template 35 | template 36 | void bi::StaticLogDensityGPU::logDensities(State& s, 37 | V1 lp) { 38 | /* pre-condition */ 39 | BI_ASSERT(V1::on_device); 40 | 41 | const int N = (block_is_matrix::value) ? block_count::value : block_size::value; 42 | const int P = s.size(); 43 | dim3 Db, Dg; 44 | 45 | Db.y = N; 46 | Dg.y = 1; 47 | Db.x = bi::max(1, bi::min(deviceIdealThreadsPerBlock()/N, P)); 48 | Dg.x = (P + Db.x - 1)/Db.x; 49 | 50 | if (N > 0) { 51 | kernelStaticLogDensity<<>>(s, lp); 52 | CUDA_CHECK; 53 | } 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /share/src/bi/primitive/strided_range.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | * 8 | * Implementation based on discussion at 9 | * http://groups.google.com/group/thrust-users/browse_thread/thread/a506470f5c634813 10 | */ 11 | #ifndef BI_MISC_STRIDEDRANGE_HPP 12 | #define BI_MISC_STRIDEDRANGE_HPP 13 | 14 | #include "strided_sequence.hpp" 15 | 16 | #include "thrust/iterator/permutation_iterator.h" 17 | #include "thrust/distance.h" 18 | 19 | namespace bi { 20 | /** 21 | * Strided range. 22 | * 23 | * @ingroup primitive_iterators 24 | */ 25 | template 26 | struct strided_range { 27 | typedef typename thrust::iterator_difference::type difference_type; 28 | typedef typename strided_sequence::iterator StridedIterator; 29 | typedef thrust::permutation_iterator PermutationIterator; 30 | typedef PermutationIterator iterator; 31 | 32 | strided_range(Iterator first, Iterator last, const difference_type inc) : 33 | first(first), last(last), inc(inc) { 34 | // 35 | } 36 | 37 | iterator begin() const { 38 | return iterator(first, strided_sequence(0, inc).begin()); 39 | } 40 | 41 | iterator end() const { 42 | return begin() + thrust::distance(first, last)/inc; 43 | } 44 | 45 | private: 46 | Iterator first, last; 47 | difference_type inc; 48 | }; 49 | 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /share/src/bi/cuda/updater/StaticMaxLogDensityGPU.cuh: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_UPDATER_STATICMAXLOGDENSITYGPU_CUH 9 | #define BI_CUDA_UPDATER_STATICMAXLOGDENSITYGPU_CUH 10 | 11 | #include "../../state/State.hpp" 12 | #include "../../method/misc.hpp" 13 | 14 | namespace bi { 15 | /** 16 | * Static maximum log-density updater, on device. 17 | * 18 | * @ingroup method_updater 19 | * 20 | * @tparam B Model type. 21 | * @tparam S Action type list. 22 | */ 23 | template 24 | class StaticMaxLogDensityGPU { 25 | public: 26 | template 27 | static void maxLogDensities(State& s, V1 lp); 28 | }; 29 | } 30 | 31 | #include "StaticMaxLogDensityKernel.cuh" 32 | #include "../device.hpp" 33 | 34 | template 35 | template 36 | void bi::StaticMaxLogDensityGPU::maxLogDensities(State& s, 37 | V1 lp) { 38 | /* pre-condition */ 39 | BI_ASSERT(V1::on_device); 40 | 41 | const int N = (block_is_matrix::value) ? block_count::value : block_size::value; 42 | const int P = s.size(); 43 | dim3 Db, Dg; 44 | 45 | Db.y = N; 46 | Dg.y = 1; 47 | Db.x = bi::max(1, bi::min(deviceIdealThreadsPerBlock()/N, P)); 48 | Dg.x = (P + Db.x - 1)/Db.x; 49 | 50 | if (N > 0) { 51 | kernelStaticMaxLogDensity<<>>(s, lp); 52 | CUDA_CHECK; 53 | } 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /share/src/bi/typelist/typelist.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_TYPELIST_TYPELIST_HPP 9 | #define BI_TYPELIST_TYPELIST_HPP 10 | 11 | namespace bi { 12 | /** 13 | * Categories of types in type list. 14 | * 15 | * @ingroup typelist 16 | */ 17 | enum typelist_marker { 18 | /** 19 | * Scalar type. 20 | */ 21 | TYPELIST_SCALAR, 22 | 23 | /** 24 | * List type. 25 | */ 26 | TYPELIST_COMPOUND 27 | }; 28 | 29 | /** 30 | * Empty type list. 31 | * 32 | * @ingroup typelist 33 | */ 34 | struct empty_typelist { 35 | // 36 | }; 37 | 38 | /** 39 | * Type list. 40 | * 41 | * @ingroup typelist 42 | * 43 | * @tparam M Marker. 44 | * @tparam N Repetitions. 45 | * @tparam X Item type. 46 | * @tparam T Tail type. 47 | */ 48 | template 49 | struct typelist { 50 | /** 51 | * @internal 52 | * 53 | * Category of first type in type list. 54 | */ 55 | static const typelist_marker marker = M; 56 | 57 | /** 58 | * @internal 59 | * 60 | * Number of times first type in type list is repeated. 61 | */ 62 | static const int reps = N; 63 | 64 | /** 65 | * @internal 66 | * 67 | * First type in type list. 68 | */ 69 | typedef X item; 70 | 71 | /** 72 | * @internal 73 | * 74 | * Remainder of type list. 75 | */ 76 | typedef T tail; 77 | 78 | }; 79 | } 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /lib/Bi/Action/exclusive_scan.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | exclusive_scan - exclusive scan primitive (also called prefix sum or 4 | cumulative sum). 5 | 6 | =head1 SYNOPSIS 7 | 8 | X <- exclusive_scan(x) 9 | 10 | =head1 DESCRIPTION 11 | 12 | An C action computes into each element C of C, the sum 13 | of the first C elements of C. 14 | 15 | =cut 16 | 17 | package Bi::Action::exclusive_scan; 18 | 19 | use parent 'Bi::Action'; 20 | use warnings; 21 | use strict; 22 | 23 | =head1 PARAMETERS 24 | 25 | =over 4 26 | 27 | =item C (position 0, mandatory) 28 | 29 | The vector over which to scan. 30 | 31 | =back 32 | 33 | =cut 34 | our $ACTION_ARGS = [ 35 | { 36 | name => 'x', 37 | positional => 1, 38 | mandatory => 1 39 | } 40 | ]; 41 | 42 | sub validate { 43 | my $self = shift; 44 | 45 | Bi::Action::validate($self); 46 | $self->process_args($ACTION_ARGS); 47 | $self->ensure_op('<-'); 48 | $self->ensure_vector('x'); 49 | 50 | my $x = $self->get_named_arg('x'); 51 | $self->set_shape($x->get_shape); 52 | unless ($self->get_left->get_shape->compat($self->get_shape)) { 53 | die("incompatible sizes on left and right sides of action.\n"); 54 | } 55 | $self->set_parent('matrix_'); 56 | $self->set_is_matrix(1); 57 | $self->set_can_nest(1); 58 | } 59 | 60 | 1; 61 | 62 | =head1 AUTHOR 63 | 64 | Lawrence Murray 65 | 66 | =head1 VERSION 67 | 68 | $Rev$ $Date$ 69 | -------------------------------------------------------------------------------- /lib/Bi/Action/inclusive_scan.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | inclusive_scan - inclusive scan primitive (also called prefix sum or 4 | cumulative sum). 5 | 6 | =head1 SYNOPSIS 7 | 8 | X <- inclusive_scan(x) 9 | 10 | =head1 DESCRIPTION 11 | 12 | An C action computes into each element C of C, the sum 13 | of the first C elements of C. 14 | 15 | =cut 16 | 17 | package Bi::Action::inclusive_scan; 18 | 19 | use parent 'Bi::Action'; 20 | use warnings; 21 | use strict; 22 | 23 | =head1 PARAMETERS 24 | 25 | =over 4 26 | 27 | =item C (position 0, mandatory) 28 | 29 | The vector over which to scan. 30 | 31 | =back 32 | 33 | =cut 34 | our $ACTION_ARGS = [ 35 | { 36 | name => 'x', 37 | positional => 1, 38 | mandatory => 1 39 | } 40 | ]; 41 | 42 | sub validate { 43 | my $self = shift; 44 | 45 | Bi::Action::validate($self); 46 | $self->process_args($ACTION_ARGS); 47 | $self->ensure_op('<-'); 48 | $self->ensure_vector('x'); 49 | 50 | my $x = $self->get_named_arg('x'); 51 | $self->set_shape($x->get_shape); 52 | 53 | unless ($self->get_left->get_shape->compat($self->get_shape)) { 54 | die("incompatible sizes on left and right sides of action.\n"); 55 | } 56 | 57 | $self->set_parent('matrix_'); 58 | $self->set_is_matrix(1); 59 | $self->set_can_nest(1); 60 | } 61 | 62 | 1; 63 | 64 | =head1 AUTHOR 65 | 66 | Lawrence Murray 67 | 68 | =head1 VERSION 69 | 70 | $Rev$ $Date$ 71 | -------------------------------------------------------------------------------- /share/src/bi/typelist/back.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_TYPELIST_BACK_HPP 9 | #define BI_TYPELIST_BACK_HPP 10 | 11 | #include "typelist.hpp" 12 | #include "empty.hpp" 13 | 14 | //#include "boost/static_assert.hpp" 15 | 16 | namespace bi { 17 | /** 18 | * @internal 19 | * 20 | * Implementation, recursive. 21 | */ 22 | template 23 | struct back_impl { 24 | typedef typename back_impl::type type; 26 | }; 27 | 28 | /** 29 | * Get the last item of a type list. 30 | * 31 | * @ingroup typelist 32 | * 33 | * @tparam T A type list. 34 | */ 35 | template 36 | struct back { 37 | //BOOST_STATIC_ASSERT(!empty::value); 38 | typedef typename back_impl::type type; 40 | }; 41 | 42 | /** 43 | * @internal 44 | * 45 | * Implementation, back item is value. 46 | */ 47 | template 48 | struct back_impl { 49 | typedef item type; 50 | }; 51 | 52 | /** 53 | * @internal 54 | * 55 | * Implementation, back item is list. 56 | */ 57 | template 58 | struct back_impl { 59 | typedef typename back_impl::type type; 61 | }; 62 | 63 | } 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /share/src/bi/math/loc_temp_matrix.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_MATH_LOC_TEMP_MATRIX_HPP 9 | #define BI_MATH_LOC_TEMP_MATRIX_HPP 10 | 11 | #include "temp_matrix.hpp" 12 | #include "../misc/location.hpp" 13 | 14 | #include "boost/mpl/if.hpp" 15 | 16 | namespace bi { 17 | /** 18 | * Matrix with location designated by template parameter. 19 | * 20 | * @ingroup math_matvec 21 | * 22 | * @tparam L Location. 23 | * @tparam T Scalar type. 24 | * @tparam size1_value Static number of rows, -1 for dynamic. 25 | * @tparam size2_value Static number of columns, -1 for dynamic. 26 | * @tparam lead_value Static lead, -1 for dynamic. 27 | * @tparam inc_value Static column increment, -1 for dynamic. 28 | * 29 | * loc_temp_matrix is a convenience class for creating a temporary matrix on 30 | * host or device according to a template argument. 31 | */ 32 | template 34 | struct loc_temp_matrix { 35 | #ifdef ENABLE_CUDA 36 | typedef typename boost::mpl::if_c, 38 | temp_host_matrix >::type::type type; 39 | #else 40 | typedef typename temp_host_matrix::type type; 41 | #endif 42 | }; 43 | } 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /share/tt/cpp/block/wiener_.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | [%-PROCESS block/misc/header.hpp.tt-%] 10 | 11 | [% create_action_typetree(block) %] 12 | 13 | /** 14 | * Block: [% block.get_name %]. 15 | */ 16 | class [% class_name %] { 17 | public: 18 | [% create_action_typedef(block) %] 19 | 20 | [% declare_block_dynamic_function('simulate') %] 21 | [% declare_block_dynamic_function('sample') %] 22 | [% declare_block_dynamic_function('logdensity') %] 23 | [% declare_block_dynamic_function('maxlogdensity') %] 24 | }; 25 | 26 | #include "bi/updater/DynamicUpdater.hpp" 27 | #include "bi/updater/DynamicSampler.hpp" 28 | #include "bi/updater/DynamicLogDensity.hpp" 29 | #include "bi/updater/DynamicMaxLogDensity.hpp" 30 | 31 | [% sig_block_dynamic_function('simulate') %] { 32 | bi::DynamicUpdater<[% model_class_name %],action_typelist>::update(t1, t2, s); 33 | } 34 | 35 | [% sig_block_dynamic_function('sample') %] { 36 | bi::DynamicSampler<[% model_class_name %],action_typelist>::samples(rng, t1, t2, s); 37 | } 38 | 39 | [% sig_block_dynamic_function('logdensity') %] { 40 | bi::DynamicLogDensity<[% model_class_name %],action_typelist>::logDensities(t1, t2, s, lp); 41 | } 42 | 43 | [% sig_block_dynamic_function('maxlogdensity') %] { 44 | bi::DynamicMaxLogDensity<[% model_class_name %],action_typelist>::maxLogDensities(t1, t2, s, lp); 45 | } 46 | 47 | [%-PROCESS block/misc/footer.hpp.tt-%] 48 | -------------------------------------------------------------------------------- /share/src/bi/concept/ConditionalPdf.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #error "Concept documentation only, should not be #included" 9 | 10 | #include "../random/Random.hpp" 11 | 12 | namespace concept { 13 | /** 14 | * Conditional pdf concept. 15 | * 16 | * @ingroup concept 17 | * 18 | * @note This is a phony class, representing a concept, for documentation 19 | * purposes only. 20 | */ 21 | struct ConditionalPdf { 22 | /** 23 | * Sample from conditional distribution. 24 | * 25 | * @tparam V1 Vector type. 26 | * @tparam V2 Vector type. 27 | * 28 | * @param[in,out] rng Random number generator. 29 | * @param x1 \f$\mathbf{x}_1\f$. 30 | * @param[out] x2 \f$\mathbf{x}_2 \sim p(X_2\,|\,\mathbf{x}_1)\f$. 31 | */ 32 | template 33 | void sample(Random& rng, const V1& x1, V2& x2); 34 | 35 | /** 36 | * Evaluate conditional probability density. 37 | * 38 | * @tparam V1 Vector type. 39 | * @tparam V2 Vector type. 40 | * 41 | * @param x1 \f$\mathbf{x}_1\f$. 42 | * @param x2 \f$\mathbf{x}_2\f$. 43 | * 44 | * @return \f$p(\mathbf{x}_2\,|\,\mathbf{x}_1)\f$. 45 | */ 46 | template 47 | typename V2::value_type density(const V1& x1, const V2& x2); 48 | 49 | /** 50 | * @copydoc density 51 | */ 52 | template 53 | typename V2::value_type operator()(const V1& x1, const V2& x2); 54 | 55 | }; 56 | } 57 | -------------------------------------------------------------------------------- /share/src/bi/cuda/updater/StaticUpdaterKernel.cuh: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_UPDATER_STATICUPDATERKERNEL_CUH 9 | #define BI_CUDA_UPDATER_STATICUPDATERKERNEL_CUH 10 | 11 | #include "../cuda.hpp" 12 | 13 | namespace bi { 14 | /** 15 | * Kernel function for static update. 16 | * 17 | * @tparam B Model type. 18 | * @tparam S Action type list. 19 | */ 20 | template 21 | CUDA_FUNC_GLOBAL void kernelStaticUpdater(State s); 22 | 23 | } 24 | 25 | #include "StaticUpdaterMatrixVisitorGPU.cuh" 26 | #include "StaticUpdaterVisitorGPU.cuh" 27 | #include "../constant.cuh" 28 | #include "../global.cuh" 29 | #include "../../state/Pa.hpp" 30 | 31 | template 32 | CUDA_FUNC_GLOBAL void bi::kernelStaticUpdater(State s) { 33 | typedef Pa PX; 34 | typedef Ou OX; 35 | typedef StaticUpdaterMatrixVisitorGPU MatrixVisitor; 36 | typedef StaticUpdaterVisitorGPU ElementVisitor; 37 | typedef typename boost::mpl::if_c::value,MatrixVisitor, 38 | ElementVisitor>::type Visitor; 39 | 40 | const int p = blockIdx.x*blockDim.x + threadIdx.x; 41 | const int id = blockIdx.y*blockDim.y + threadIdx.y; 42 | PX pax; 43 | OX x; 44 | 45 | /* update */ 46 | if (p < s.size()) { 47 | Visitor::accept(s, p, id, pax, x); 48 | } 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /share/src/bi/misc/TicToc.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_MISC_TICTOC_HPP 9 | #define BI_MISC_TICTOC_HPP 10 | 11 | #include 12 | 13 | namespace bi { 14 | /** 15 | * Timing class. 16 | * 17 | * @ingroup misc 18 | */ 19 | class TicToc { 20 | public: 21 | /** 22 | * Constructor. Starts timer. 23 | */ 24 | TicToc(); 25 | 26 | /** 27 | * Start or restart timer. 28 | */ 29 | void tic(); 30 | 31 | /** 32 | * Read timer. 33 | * 34 | * @return Number of microseconds since last call to tic(). 35 | */ 36 | long toc(); 37 | 38 | /** 39 | * Synchronize host and device if CUDA is enabled, and across all processes 40 | * if MPI is enabled. 41 | */ 42 | void sync(); 43 | 44 | private: 45 | /** 46 | * Time of last call to tic(). 47 | */ 48 | timeval start; 49 | 50 | }; 51 | 52 | } 53 | 54 | inline bi::TicToc::TicToc() { 55 | tic(); 56 | } 57 | 58 | inline void bi::TicToc::tic() { 59 | gettimeofday(&start, NULL); 60 | } 61 | 62 | inline long bi::TicToc::toc() { 63 | timeval end; 64 | gettimeofday(&end, NULL); 65 | 66 | return (end.tv_sec - start.tv_sec)*1e6 + (end.tv_usec - start.tv_usec); 67 | } 68 | 69 | inline void bi::TicToc::sync() { 70 | #ifdef ENABLE_CUDA 71 | synchronize(); 72 | #endif 73 | 74 | #ifdef ENABLE_MPI 75 | boost::mpi::communicator world; 76 | world.barrier(); 77 | #endif 78 | } 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /share/src/bi/netcdf/NetCDFBuffer.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_NETCDF_NETCDFBUFFER_HPP 9 | #define BI_NETCDF_NETCDFBUFFER_HPP 10 | 11 | #include "../buffer/buffer.hpp" 12 | #include "../model/Model.hpp" 13 | #include "../method/misc.hpp" 14 | #include "../math/scalar.hpp" 15 | 16 | #include "netcdf.hpp" 17 | 18 | namespace bi { 19 | /** 20 | * NetCDF input or output file. 21 | * 22 | * @ingroup io_netcdf 23 | */ 24 | class NetCDFBuffer { 25 | public: 26 | /** 27 | * Constructor. 28 | * 29 | * @param file NetCDF file name. 30 | * @param mode File open mode. 31 | */ 32 | NetCDFBuffer(const std::string& file = "", const FileMode mode = READ_ONLY); 33 | 34 | /** 35 | * Copy constructor. 36 | * 37 | * Reopens the file of the argument with a new file handle, in read only 38 | * mode. 39 | */ 40 | NetCDFBuffer(const NetCDFBuffer& o); 41 | 42 | /** 43 | * Destructor. 44 | */ 45 | ~NetCDFBuffer(); 46 | 47 | /** 48 | * Does nothing but maintain interface with caches. 49 | */ 50 | void clear(); 51 | 52 | protected: 53 | /** 54 | * NetCDF file name recorded by constructor. Using this is preferred to the 55 | * nc_inq_path() function, as the latter requires fiddling with buffer 56 | * sizes to retrieve. 57 | */ 58 | std::string file; 59 | 60 | /** 61 | * NetCDF file id. 62 | */ 63 | int ncid; 64 | }; 65 | } 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /share/src/bi/typelist/push_front.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_TYPELIST_PUSH_FRONT_HPP 9 | #define BI_TYPELIST_PUSH_FRONT_HPP 10 | 11 | #include "typelist.hpp" 12 | 13 | namespace bi { 14 | /** 15 | * @internal 16 | * 17 | * Implementation, front item is different. 18 | */ 19 | template 20 | struct push_front_impl { 21 | typedef typelist > type; 22 | }; 23 | 24 | /** 25 | * Push value onto front of a type list. 26 | * 27 | * @ingroup typelist 28 | * 29 | * @tparam T A type list. 30 | * @tparam X A scalar type. 31 | * @tparam N Repetitions. 32 | */ 33 | template 34 | struct push_front { 35 | typedef typename push_front_impl::type type; 36 | }; 37 | 38 | /** 39 | * @internal 40 | * 41 | * Implementation, front item is same. 42 | */ 43 | template 44 | struct push_front_impl { 45 | typedef typelist type; 46 | }; 47 | 48 | /** 49 | * @internal 50 | * 51 | * Special case for empty_typelist. 52 | */ 53 | template 54 | struct push_front { 55 | typedef typelist type; 56 | }; 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /inc/Module/Install/Base.pm: -------------------------------------------------------------------------------- 1 | #line 1 2 | package Module::Install::Base; 3 | 4 | use strict 'vars'; 5 | use vars qw{$VERSION}; 6 | BEGIN { 7 | $VERSION = '1.06'; 8 | } 9 | 10 | # Suspend handler for "redefined" warnings 11 | BEGIN { 12 | my $w = $SIG{__WARN__}; 13 | $SIG{__WARN__} = sub { $w }; 14 | } 15 | 16 | #line 42 17 | 18 | sub new { 19 | my $class = shift; 20 | unless ( defined &{"${class}::call"} ) { 21 | *{"${class}::call"} = sub { shift->_top->call(@_) }; 22 | } 23 | unless ( defined &{"${class}::load"} ) { 24 | *{"${class}::load"} = sub { shift->_top->load(@_) }; 25 | } 26 | bless { @_ }, $class; 27 | } 28 | 29 | #line 61 30 | 31 | sub AUTOLOAD { 32 | local $@; 33 | my $func = eval { shift->_top->autoload } or return; 34 | goto &$func; 35 | } 36 | 37 | #line 75 38 | 39 | sub _top { 40 | $_[0]->{_top}; 41 | } 42 | 43 | #line 90 44 | 45 | sub admin { 46 | $_[0]->_top->{admin} 47 | or 48 | Module::Install::Base::FakeAdmin->new; 49 | } 50 | 51 | #line 106 52 | 53 | sub is_admin { 54 | ! $_[0]->admin->isa('Module::Install::Base::FakeAdmin'); 55 | } 56 | 57 | sub DESTROY {} 58 | 59 | package Module::Install::Base::FakeAdmin; 60 | 61 | use vars qw{$VERSION}; 62 | BEGIN { 63 | $VERSION = $Module::Install::Base::VERSION; 64 | } 65 | 66 | my $fake; 67 | 68 | sub new { 69 | $fake ||= bless(\@_, $_[0]); 70 | } 71 | 72 | sub AUTOLOAD {} 73 | 74 | sub DESTROY {} 75 | 76 | # Restore warning handler 77 | BEGIN { 78 | $SIG{__WARN__} = $SIG{__WARN__}->(); 79 | } 80 | 81 | 1; 82 | 83 | #line 159 84 | -------------------------------------------------------------------------------- /share/tt/cpp/block/std_.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | [%- 10 | std = block.get_actions.0.get_named_arg('std'); 11 | target = block.get_actions.0.get_left; 12 | -%] 13 | 14 | [%-PROCESS block/misc/header.hpp.tt-%] 15 | 16 | /** 17 | * Block: [% block.get_name %]. 18 | */ 19 | class [% class_name %] { 20 | public: 21 | [% declare_block_static_function('simulate') %] 22 | [% declare_block_static_function('sample') %] 23 | [% declare_block_static_function('logdensity') %] 24 | [% declare_block_static_function('maxlogdensity') %] 25 | 26 | [% declare_block_dynamic_function('simulate') %] 27 | [% declare_block_dynamic_function('sample') %] 28 | [% declare_block_dynamic_function('logdensity') %] 29 | [% declare_block_dynamic_function('maxlogdensity') %] 30 | }; 31 | 32 | #include "bi/primitive/matrix_primitive.hpp" 33 | 34 | [% sig_block_static_function('simulate') %] { 35 | BOOST_AUTO(std, [% block_gets_var(std) %]); 36 | BOOST_AUTO(target, [% block_gets_var(target) %]); 37 | 38 | target = std; 39 | } 40 | 41 | [% std_block_static_function('sample') %] 42 | [% std_block_static_function('logdensity') %] 43 | [% std_block_static_function('maxlogdensity') %] 44 | 45 | [% std_block_dynamic_function('simulate') %] 46 | [% std_block_dynamic_function('sample') %] 47 | [% std_block_dynamic_function('logdensity') %] 48 | [% std_block_dynamic_function('maxlogdensity') %] 49 | 50 | [% PROCESS 'block/misc/footer.hpp.tt' %] 51 | -------------------------------------------------------------------------------- /lib/Bi/Visitor.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | Bi::Visitor - abstract class for functors which operate as visitors over 4 | L trees. 5 | 6 | =head1 DESCRIPTION 7 | 8 | C objects are functors that operate as visitors over 9 | L trees. These classes have no constructors as such, and are 10 | not intended to be instantiated persistently. To use, simply call the B 11 | method; this will construct a temporary (local) object of the class, visit 12 | the L object passed as an argument, and return the result. 13 | 14 | =head1 METHODS 15 | 16 | =over 4 17 | 18 | =cut 19 | 20 | package Bi::Visitor; 21 | 22 | use warnings; 23 | use strict; 24 | 25 | use Carp::Assert; 26 | 27 | =item B 28 | 29 | Constructor 30 | 31 | =cut 32 | sub new { 33 | my $class = shift; 34 | 35 | my $self = {}; 36 | bless $self, $class; 37 | 38 | return $self; 39 | } 40 | 41 | =item B(I, ...) 42 | 43 | Visit a node before visiting its children 44 | 45 | =cut 46 | sub visit_before { 47 | my $self = shift; 48 | my $node = shift; 49 | 50 | return $node; 51 | } 52 | 53 | =item B(I, ...) 54 | 55 | Visit a node after visiting its children 56 | 57 | =cut 58 | sub visit_after { 59 | my $self = shift; 60 | my $node = shift; 61 | 62 | return $node; 63 | } 64 | 65 | 1; 66 | 67 | =back 68 | 69 | =head1 AUTHOR 70 | 71 | Lawrence Murray 72 | 73 | =head1 VERSION 74 | 75 | $Rev$ $Date$ 76 | -------------------------------------------------------------------------------- /share/src/bi/cuda/updater/SparseStaticLogDensityGPU.cuh: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_UPDATER_SPARSESTATICLOGDENSITYGPU_HPP 9 | #define BI_CUDA_UPDATER_SPARSESTATICLOGDENSITYGPU_HPP 10 | 11 | #include "../../state/State.hpp" 12 | 13 | namespace bi { 14 | /** 15 | * Sparse static log-density updater, on device. 16 | * 17 | * @ingroup method_updater 18 | * 19 | * @tparam B Model type. 20 | * @tparam S Action type list. 21 | */ 22 | template 23 | class SparseStaticLogDensityGPU { 24 | public: 25 | /** 26 | * @copydoc SparseStaticLogDensity::logDensities(State&, const Mask&, V1) 27 | */ 28 | template 29 | static void logDensities(State& s, const Mask& mask, V1 lp); 30 | }; 31 | } 32 | 33 | #include "SparseStaticLogDensityKernel.cuh" 34 | #include "../device.hpp" 35 | 36 | template 37 | template 38 | void bi::SparseStaticLogDensityGPU::logDensities(State& s, 39 | const Mask& mask, V1 lp) { 40 | /* pre-condition */ 41 | BI_ASSERT(V1::on_device); 42 | 43 | const int P = s.size(); 44 | 45 | if (mask.size() > 0) { 46 | dim3 Dg, Db; 47 | 48 | Db.x = bi::min(deviceIdealThreadsPerBlock(), P); // over trajectories 49 | Dg.x = (P + Db.x - 1)/Db.x; 50 | 51 | kernelSparseStaticLogDensity<<>>(s, mask, lp); 52 | CUDA_CHECK; 53 | } 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /share/src/bi/host/updater/StaticSamplerMatrixVisitorHost.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_HOST_UPDATER_STATICSAMPLERMATRIXVISITORHOST_HPP 9 | #define BI_HOST_UPDATER_STATICSAMPLERMATRIXVISITORHOST_HPP 10 | 11 | namespace bi { 12 | /** 13 | * Visitor for StaticSamplerHost. 14 | */ 15 | template 16 | class StaticSamplerMatrixVisitorHost { 17 | public: 18 | static void accept(R1& rng, State& s, const int p, const PX& pax, 19 | OX& x); 20 | }; 21 | 22 | /** 23 | * @internal 24 | * 25 | * Base case of StaticSamplerMatrixVisitorHost. 26 | */ 27 | template 28 | class StaticSamplerMatrixVisitorHost { 29 | public: 30 | static void accept(R1& rng, State& s, const int p, const PX& pax, 31 | OX& x) { 32 | // 33 | } 34 | }; 35 | } 36 | 37 | #include "../../typelist/front.hpp" 38 | #include "../../typelist/pop_front.hpp" 39 | 40 | template 41 | void bi::StaticSamplerMatrixVisitorHost::accept(R1& rng, 42 | State& s, const int p, const PX& pax, OX& x) { 43 | typedef typename front::type front; 44 | typedef typename pop_front::type pop_front; 45 | 46 | front::samples(rng, s, p, pax, x); 47 | StaticSamplerMatrixVisitorHost::accept(rng, s, p, pax, 48 | x); 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /share/src/bi/cuda/resampler/StratifiedResamplerKernel.cuh: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_RESAMPLER_STRATIFIEDRESAMPLERKERNEL_CUH 9 | #define BI_CUDA_RESAMPLER_STRATIFIEDRESAMPLERKERNEL_CUH 10 | 11 | #include "misc.hpp" 12 | #include "../cuda.hpp" 13 | 14 | namespace bi { 15 | /** 16 | * Stratified resampling kernel. 17 | * 18 | * @tparam V1 Vector type. 19 | * @tparam V2 Vector type. 20 | * @tparam V3 Integer vector type. 21 | * 22 | * @param alphas Strata offsets. 23 | * @param Ws Cumulative weights. 24 | * @param Os[out] Cumulative offspring. 25 | * @param n Number of offspring. 26 | */ 27 | template 28 | CUDA_FUNC_GLOBAL void kernelStratifiedResamplerOp(const V1 alphas, 29 | const V2 Ws, V3 Os, const int n); 30 | 31 | } 32 | 33 | template 34 | CUDA_FUNC_GLOBAL void bi::kernelStratifiedResamplerOp(const V1 alphas, 35 | const V2 Ws, V3 Os, const int n) { 36 | typedef typename V1::value_type T1; 37 | 38 | const int P = Ws.size(); // number of particles 39 | const T1 W = Ws(P - 1); 40 | 41 | const int Q = gridDim.x*blockDim.x; // number of threads 42 | const int q = blockIdx.x*blockDim.x + threadIdx.x; // thread id 43 | int p; 44 | 45 | for (p = q; p < P; p += Q) { 46 | T1 reach = Ws(p)/W*n; 47 | int k = bi::min(n - 1, static_cast(reach)); 48 | 49 | Os(p) = bi::min(n, static_cast(reach + alphas(k))); 50 | } 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /lib/Bi/Block/orthogonal_std_.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | orthogonal_std_ - optimisation block for L actions with 4 | orthogonal covariance matrix. 5 | 6 | =cut 7 | 8 | package Bi::Block::orthogonal_std_; 9 | 10 | use parent 'Bi::Block'; 11 | use warnings; 12 | use strict; 13 | 14 | our $BLOCK_ARGS = []; 15 | 16 | sub validate { 17 | my $self = shift; 18 | 19 | $self->process_args($BLOCK_ARGS); 20 | 21 | my ($name, $action, $arg); 22 | 23 | if (@{$self->get_blocks} > 0) { 24 | die("an 'orthogonal_std_' block may not contain nested blocks\n"); 25 | } 26 | foreach $action (@{$self->get_actions}) { 27 | if ($action->get_name ne 'std_' && $action->get_name ne 'normal' && $action->get_name ne 'log_std_' && $action->get_name ne 'log_normal') { 28 | die("an 'orthogonal_std_' block may only contain 'std_', 'normal', 'log_std_' and 'log_normal' actions\n"); 29 | } else { 30 | foreach $name ('std') { 31 | if ($action->is_named_arg($name)) { 32 | $arg = $action->get_named_arg($name); 33 | if (!$arg->is_element && !$arg->is_scalar && !$arg->is_vector) { 34 | die("an 'orthogonal_std_' block may only contain actions with element, scalar or vector '$name' argument\n"); 35 | } 36 | } 37 | } 38 | } 39 | } 40 | } 41 | 42 | 1; 43 | 44 | =head1 AUTHOR 45 | 46 | Lawrence Murray 47 | 48 | =head1 VERSION 49 | 50 | $Rev$ $Date$ 51 | -------------------------------------------------------------------------------- /share/src/bi/cuda/updater/DynamicSamplerGPU.cuh: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_UPDATER_DYNAMICSAMPLERGPU_CUH 9 | #define BI_CUDA_UPDATER_DYNAMICSAMPLERGPU_CUH 10 | 11 | #include "../../random/Random.hpp" 12 | #include "../../state/State.hpp" 13 | #include "../../method/misc.hpp" 14 | 15 | namespace bi { 16 | /** 17 | * Dynamic sampler, on device. 18 | * 19 | * @ingroup method_updater 20 | * 21 | * @tparam B Model type. 22 | * @tparam S Action type list. 23 | */ 24 | template 25 | class DynamicSamplerGPU { 26 | public: 27 | /** 28 | * @copydoc DynamicSampler::samples(Random&, const T1, const T1, State&) 29 | */ 30 | template 31 | static void samples(Random& rng, const T1 t1, const T1 t2, 32 | State& s); 33 | }; 34 | } 35 | 36 | #include "DynamicSamplerKernel.cuh" 37 | #include "../device.hpp" 38 | 39 | template 40 | template 41 | void bi::DynamicSamplerGPU::samples(Random& rng, const T1 t1, 42 | const T1 t2, State& s) { 43 | const int N = (block_is_matrix::value) ? block_count::value : block_size::value; 44 | const int P = s.size(); 45 | dim3 Db, Dg; 46 | 47 | Db.x = bi::min(P, deviceIdealThreadsPerBlock()); 48 | Dg.x = (bi::min(P, deviceIdealThreads()) + Db.x - 1)/Db.x; 49 | 50 | if (N > 0) { 51 | kernelDynamicSampler<<>>(rng.devRngs, t1, t2, s); 52 | CUDA_CHECK; 53 | } 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /share/src/bi/math/sim_temp_vector.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_MATH_SIM_TEMP_VECTOR_HPP 9 | #define BI_MATH_SIM_TEMP_VECTOR_HPP 10 | 11 | #include "temp_vector.hpp" 12 | #include "../host/math/sim_temp_vector.hpp" 13 | #ifdef ENABLE_CUDA 14 | #include "../cuda/math/sim_temp_vector.hpp" 15 | #endif 16 | 17 | #include "boost/mpl/if.hpp" 18 | 19 | namespace bi { 20 | /** 21 | * Temporary vector type that is similar to some other given stencil type. 22 | * 23 | * @ingroup math_matvec 24 | * 25 | * @tparam VM1 Vector or matrix type. 26 | * @tparam size_value Static size, -1 for dynamic. 27 | * @tparam inc_value Static increment, -1 for dynamic. 28 | * 29 | * sim_temp_vector is a convenience class for creating a temporary vector 30 | * that is similar to the given vector or matrix type @p VM1 in the sense 31 | * that: 32 | * 33 | * @li it resides in the same location (host or device), and 34 | * @li it has the same scalar type. 35 | */ 36 | template 37 | struct sim_temp_vector { 38 | /** 39 | * @internal 40 | */ 41 | typedef typename VM1::value_type T; 42 | 43 | #ifdef ENABLE_CUDA 44 | typedef typename boost::mpl::if_c, 46 | temp_host_vector >::type::type type; 47 | #else 48 | typedef typename temp_host_vector::type type; 49 | #endif 50 | }; 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /share/src/bi/misc/omp.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * Utility functions for OpenMP. 5 | * 6 | * @author Lawrence Murray 7 | * $Rev$ 8 | * $Date$ 9 | */ 10 | #ifndef BI_MISC_OMP_HPP 11 | #define BI_MISC_OMP_HPP 12 | 13 | #include "compile.hpp" 14 | #ifdef ENABLE_CUDA 15 | #include "../cuda/cuda.hpp" 16 | #include "../cuda/math/cublas.hpp" 17 | #endif 18 | 19 | #if defined(ENABLE_OPENMP) and defined(HAVE_OMP_H) 20 | #include "omp.h" 21 | #endif 22 | 23 | /** 24 | * Thread id. 25 | */ 26 | extern BI_THREAD int bi_omp_tid; 27 | 28 | /** 29 | * Maximum number of threads. Saves function calls to omp_get_max_threads(). 30 | */ 31 | extern int bi_omp_max_threads; 32 | 33 | #ifdef ENABLE_CUDA 34 | /** 35 | * CUBLAS context handle for CUBLAS function calls (API v2). 36 | */ 37 | extern BI_THREAD cublasHandle_t bi_omp_cublas_handle; 38 | 39 | /** 40 | * CUDA stream. Default stream is used unless this explicitly specified. May 41 | * also be used for CUBLAS calls. 42 | */ 43 | extern BI_THREAD cudaStream_t bi_omp_cuda_stream; 44 | #endif 45 | 46 | #ifdef __ICC 47 | #pragma omp threadprivate(bi_omp_tid) 48 | #ifdef ENABLE_CUDA 49 | #pragma omp threadprivate(bi_omp_cublas_handle) 50 | #pragma omp threadprivate(bi_omp_cuda_stream) 51 | #endif 52 | #endif 53 | 54 | /** 55 | * Initialise OpenMP environment. 56 | * 57 | * @param threads Number of threads. Zero for the default. 58 | */ 59 | void bi_omp_init(const int threads = 0); 60 | 61 | /** 62 | * Terminate OpenMP environment. 63 | */ 64 | void bi_omp_term(); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /lib/Bi/Action/transpose.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | transpose - transpose a matrix. 4 | 5 | =head1 SYNOPSIS 6 | 7 | B <- transpose(A) 8 | 9 | =head1 DESCRIPTION 10 | 11 | A C action performs a matrix transpose. 12 | 13 | =cut 14 | 15 | package Bi::Action::transpose; 16 | 17 | use parent 'Bi::Action'; 18 | use warnings; 19 | use strict; 20 | 21 | =head1 PARAMETERS 22 | 23 | =over 4 24 | 25 | =item C (position 0, mandatory) 26 | 27 | The matrix. 28 | 29 | =back 30 | 31 | =cut 32 | our $ACTION_ARGS = [ 33 | { 34 | name => 'A', 35 | positional => 1, 36 | mandatory => 1 37 | } 38 | ]; 39 | 40 | sub validate { 41 | my $self = shift; 42 | 43 | Bi::Action::validate($self); 44 | $self->process_args($ACTION_ARGS); 45 | $self->ensure_op('<-'); 46 | $self->ensure_matrix('A'); 47 | 48 | my $A = $self->get_named_arg('A'); 49 | 50 | my $shape = []; 51 | push(@$shape, $A->get_shape->get_size2); 52 | if ($A->get_shape->get_size1 > 1) { 53 | push(@$shape, $A->get_shape->get_size1); 54 | } 55 | $self->set_shape(new Bi::Expression::Shape($shape)); 56 | unless ($self->get_left->get_shape->compat($self->get_shape)) { 57 | die("incompatible sizes on left and right sides of action.\n"); 58 | } 59 | 60 | $self->set_parent('matrix_'); 61 | $self->set_can_combine(1); 62 | $self->set_is_matrix(1); 63 | $self->set_can_nest(1); 64 | $self->set_unroll_target(1); 65 | } 66 | 67 | 1; 68 | 69 | =head1 AUTHOR 70 | 71 | Lawrence Murray 72 | -------------------------------------------------------------------------------- /share/src/bi/cuda/ode/RK4IntegratorGPU.cuh: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_ODE_RK4INTEGRATORGPU_CUH 9 | #define BI_CUDA_ODE_RK4INTEGRATORGPU_CUH 10 | 11 | #include "RK4KernelGPU.cuh" 12 | #include "../cuda.hpp" 13 | 14 | namespace bi { 15 | /** 16 | * @copydoc RK4Integrator 17 | */ 18 | template 19 | class RK4IntegratorGPU { 20 | public: 21 | /** 22 | * @copydoc RK4Integrator::integrate() 23 | */ 24 | static void update(const T1 t1, const T1 t2, State& s); 25 | }; 26 | } 27 | 28 | template 29 | void bi::RK4IntegratorGPU::update(const T1 t1, const T1 t2, 30 | State& s) { 31 | static const int N = block_size::value; 32 | if (N > 0) { 33 | /* execution config */ 34 | const size_t P = s.size(); 35 | const size_t maxDgx = 16384u; 36 | const size_t minDbx = P/maxDgx; 37 | const size_t maxDbx = 512/next_power_2(N); 38 | const size_t idealDbx = 32u; 39 | dim3 Db, Dg; 40 | size_t Ns; 41 | 42 | Db.x = bi::min(bi::max(bi::min(idealDbx, P), minDbx), maxDbx); 43 | Dg.x = bi::min((P + Db.x - 1)/Db.x, maxDgx); 44 | Db.y = N; 45 | Dg.y = 1; 46 | Ns = 0; 47 | 48 | BI_ERROR_MSG(P % Db.x == 0, "Number of trajectories must be multiple of " << 49 | Db.x << " for CUDA ODE integrator"); 50 | 51 | /* launch */ 52 | kernelRK4<<>>(t1, t2, s); 53 | CUDA_CHECK; 54 | } 55 | } 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /share/src/bi/cuda/updater/DynamicLogDensityGPU.cuh: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_UPDATER_DYNAMICLOGDENSITYGPU_CUH 9 | #define BI_CUDA_UPDATER_DYNAMICLOGDENSITYGPU_CUH 10 | 11 | #include "../../state/State.hpp" 12 | #include "../../method/misc.hpp" 13 | 14 | namespace bi { 15 | /** 16 | * Dynamic log-density updater, on device. 17 | * 18 | * @ingroup method_updater 19 | * 20 | * @tparam B Model type. 21 | * @tparam S Action type list. 22 | */ 23 | template 24 | class DynamicLogDensityGPU { 25 | public: 26 | template 27 | static void logDensities(const T1 t1, const T1 t2, State& s, 28 | V1 lp); 29 | }; 30 | } 31 | 32 | #include "DynamicLogDensityKernel.cuh" 33 | #include "../device.hpp" 34 | 35 | template 36 | template 37 | void bi::DynamicLogDensityGPU::logDensities(const T1 t1, const T1 t2, 38 | State& s, V1 lp) { 39 | /* pre-condition */ 40 | BI_ASSERT(V1::on_device); 41 | 42 | const int N = 43 | (block_is_matrix < S > ::value) ? 44 | block_count < S > ::value : block_size < S > ::value; 45 | const int P = s.size(); 46 | dim3 Db, Dg; 47 | 48 | Db.y = N; 49 | Dg.y = 1; 50 | Db.x = bi::max(1, bi::min(deviceIdealThreadsPerBlock()/N, P)); 51 | Dg.x = (P + Db.x - 1) / Db.x; 52 | 53 | if (N > 0) { 54 | kernelDynamicLogDensity<<>>(t1, t2, s, lp); 55 | CUDA_CHECK; 56 | } 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /inc/Module/Install/WriteAll.pm: -------------------------------------------------------------------------------- 1 | #line 1 2 | package Module::Install::WriteAll; 3 | 4 | use strict; 5 | use Module::Install::Base (); 6 | 7 | use vars qw{$VERSION @ISA $ISCORE}; 8 | BEGIN { 9 | $VERSION = '1.06'; 10 | @ISA = qw{Module::Install::Base}; 11 | $ISCORE = 1; 12 | } 13 | 14 | sub WriteAll { 15 | my $self = shift; 16 | my %args = ( 17 | meta => 1, 18 | sign => 0, 19 | inline => 0, 20 | check_nmake => 1, 21 | @_, 22 | ); 23 | 24 | $self->sign(1) if $args{sign}; 25 | $self->admin->WriteAll(%args) if $self->is_admin; 26 | 27 | $self->check_nmake if $args{check_nmake}; 28 | unless ( $self->makemaker_args->{PL_FILES} ) { 29 | # XXX: This still may be a bit over-defensive... 30 | unless ($self->makemaker(6.25)) { 31 | $self->makemaker_args( PL_FILES => {} ) if -f 'Build.PL'; 32 | } 33 | } 34 | 35 | # Until ExtUtils::MakeMaker support MYMETA.yml, make sure 36 | # we clean it up properly ourself. 37 | $self->realclean_files('MYMETA.yml'); 38 | 39 | if ( $args{inline} ) { 40 | $self->Inline->write; 41 | } else { 42 | $self->Makefile->write; 43 | } 44 | 45 | # The Makefile write process adds a couple of dependencies, 46 | # so write the META.yml files after the Makefile. 47 | if ( $args{meta} ) { 48 | $self->Meta->write; 49 | } 50 | 51 | # Experimental support for MYMETA 52 | if ( $ENV{X_MYMETA} ) { 53 | if ( $ENV{X_MYMETA} eq 'JSON' ) { 54 | $self->Meta->write_mymeta_json; 55 | } else { 56 | $self->Meta->write_mymeta_yaml; 57 | } 58 | } 59 | 60 | return 1; 61 | } 62 | 63 | 1; 64 | -------------------------------------------------------------------------------- /share/src/bi/cuda/updater/SparseStaticMaxLogDensityGPU.cuh: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_UPDATER_SPARSESTATICMAXLOGDENSITYGPU_HPP 9 | #define BI_CUDA_UPDATER_SPARSESTATICMAXLOGDENSITYGPU_HPP 10 | 11 | #include "../../state/State.hpp" 12 | 13 | namespace bi { 14 | /** 15 | * Sparse static maximum log-density updater, on device. 16 | * 17 | * @ingroup method_updater 18 | * 19 | * @tparam B Model type. 20 | * @tparam S Action type list. 21 | */ 22 | template 23 | class SparseStaticMaxLogDensityGPU { 24 | public: 25 | /** 26 | * @copydoc SparseStaticMaxLogDensity::maxLogDensities(State&, const Mask&, V1) 27 | */ 28 | template 29 | static void maxLogDensities(State& s, const Mask& mask, V1 lp); 30 | }; 31 | } 32 | 33 | #include "SparseStaticMaxLogDensityKernel.cuh" 34 | #include "../device.hpp" 35 | 36 | template 37 | template 38 | void bi::SparseStaticMaxLogDensityGPU::maxLogDensities(State& s, 39 | const Mask& mask, V1 lp) { 40 | /* pre-condition */ 41 | BI_ASSERT(V1::on_device); 42 | 43 | const int P = s.size(); 44 | 45 | if (mask.size() > 0) { 46 | dim3 Dg, Db; 47 | 48 | Db.x = bi::min(deviceIdealThreadsPerBlock(), P); // over trajectories 49 | Dg.x = (P + Db.x - 1)/Db.x; 50 | 51 | kernelSparseStaticMaxLogDensity<<>>(s, mask, lp); 52 | CUDA_CHECK; 53 | } 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /share/src/bi/typelist/push_front_list.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_TYPELIST_PUSH_FRONT_LIST_HPP 9 | #define BI_TYPELIST_PUSH_FRONT_LIST_HPP 10 | 11 | #include "typelist.hpp" 12 | 13 | namespace bi { 14 | /** 15 | * @internal 16 | * 17 | * Implementation, front item is different. 18 | */ 19 | template 21 | struct push_front_list_impl { 22 | typedef typelist > type; 23 | }; 24 | 25 | /** 26 | * Push value onto front of a type list. 27 | * 28 | * @ingroup typelist 29 | * 30 | * @tparam T A type list. 31 | * @tparam X A scalar type. 32 | * @tparam N Repetitions. 33 | */ 34 | template 35 | struct push_front_list { 36 | typedef typename push_front_list_impl::type type; 38 | }; 39 | 40 | /** 41 | * @internal 42 | * 43 | * Implementation, front item is same. 44 | */ 45 | template 47 | struct push_front_list_impl { 48 | typedef typelist type; 49 | }; 50 | 51 | /** 52 | * @internal 53 | * 54 | * Special case for empty_typelist. 55 | */ 56 | template 57 | struct push_front_list { 58 | typedef typelist type; 59 | }; 60 | } 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /share/src/bi/typelist/runtime.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_TYPELIST_RUNTIME_HPP 9 | #define BI_TYPELIST_RUNTIME_HPP 10 | 11 | #include "size.hpp" 12 | #include "../misc/assert.hpp" 13 | 14 | #include 15 | 16 | namespace bi { 17 | /** 18 | * Runtime functions for type lists. 19 | * 20 | * @ingroup typelist 21 | * 22 | * @tparam TS Type list. 23 | */ 24 | template 25 | struct runtime { 26 | /** 27 | * Runtime type check of object. 28 | * 29 | * @tparam T Object type. 30 | * 31 | * @param o Object to check. 32 | * @param i Index in the type list against which to check. 33 | * 34 | * @return True if the type of @p o is the same as the @p i th element of 35 | * the type list, false otherwise. 36 | */ 37 | template 38 | static bool check(const T& o, const int i) { 39 | /* pre-conditions */ 40 | BI_ASSERT(i < size::value); 41 | 42 | typedef typename front::type front; 43 | typedef typename pop_front::type pop_front; 44 | 45 | if (i == 0) { 46 | return typeid(o) == typeid(front); 47 | } else { 48 | return runtime::check(o, i - 1); 49 | } 50 | } 51 | }; 52 | 53 | /** 54 | * @internal 55 | * 56 | * Base case of runtime. 57 | */ 58 | template<> 59 | struct runtime { 60 | template 61 | static bool check(const T& o, const int i) { 62 | BI_ASSERT(false); 63 | 64 | return false; 65 | } 66 | }; 67 | 68 | } 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /share/src/bi/cuda/math/temp_matrix.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_MATH_TEMP_MATRIX_HPP 9 | #define BI_CUDA_MATH_TEMP_MATRIX_HPP 10 | 11 | #include "matrix.hpp" 12 | #include "../../primitive/device_allocator.hpp" 13 | #include "../../primitive/pooled_allocator.hpp" 14 | #include "../../primitive/pipelined_allocator.hpp" 15 | 16 | namespace bi { 17 | /** 18 | * Temporary matrix on device. 19 | * 20 | * @ingroup math_matvec 21 | * 22 | * @tparam T Scalar type. 23 | * @tparam size1_value Static number of rows, -1 for dynamic. 24 | * @tparam size2_value Static number of columns, -1 for dynamic. 25 | * @tparam lead_value Static lead, -1 for dynamic. 26 | * @tparam inc_value Static column increment, -1 for dynamic. 27 | * 28 | * temp_gpu_matrix is a convenience class for producing matrices in device 29 | * memory that are suitable for short-term use before destruction. It uses 30 | * pooled_allocator to reuse allocated buffers, as device memory allocations 31 | * can be slow. 32 | */ 33 | template 35 | struct temp_gpu_matrix { 36 | /** 37 | * @internal 38 | * 39 | * Allocator type. 40 | */ 41 | typedef pipelined_allocator > > allocator_type; 42 | 43 | /** 44 | * matrix type. 45 | */ 46 | typedef gpu_matrix type; 48 | }; 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /lib/Bi/Visitor/TargetReplacer.pm: -------------------------------------------------------------------------------- 1 | =head1 NAME 2 | 3 | Bi::Visitor::TargetReplacer - visitor for replacing targets of actions. 4 | 5 | =head1 SYNOPSIS 6 | 7 | use Bi::Visitor::TargetReplacer; 8 | Bi::Visitor::TargetReplacer->evaluate($block, $from, $to); 9 | 10 | =head1 INHERITS 11 | 12 | L 13 | 14 | =head1 METHODS 15 | 16 | =over 4 17 | 18 | =cut 19 | 20 | package Bi::Visitor::TargetReplacer; 21 | 22 | use parent 'Bi::Visitor'; 23 | use warnings; 24 | use strict; 25 | 26 | use Carp::Assert; 27 | use Bi::Utility qw(set_union set_intersect push_unique); 28 | 29 | =item B(I) 30 | 31 | Evaluate. 32 | 33 | =over 4 34 | 35 | =item I L object. 36 | 37 | =back 38 | 39 | No return value. 40 | 41 | =cut 42 | sub evaluate { 43 | my $class = shift; 44 | my $block = shift; 45 | my $from = shift; 46 | my $to = shift; 47 | 48 | my $self = new Bi::Visitor; 49 | bless $self, $class; 50 | 51 | $block->accept($self, $from, $to); 52 | } 53 | 54 | =item B(I) 55 | 56 | Visit node. 57 | 58 | =cut 59 | sub visit_after { 60 | my $self = shift; 61 | my $node = shift; 62 | my $from = shift; 63 | my $to = shift; 64 | 65 | if ($node->isa('Bi::Action')) { 66 | if ($node->get_left->get_var->equals($from)) { 67 | $node->get_left->set_var($to); 68 | } 69 | } 70 | 71 | return $node; 72 | } 73 | 74 | 1; 75 | 76 | =back 77 | 78 | =head1 AUTHOR 79 | 80 | Lawrence Murray 81 | 82 | =head1 VERSION 83 | 84 | $Rev$ $Date$ 85 | -------------------------------------------------------------------------------- /share/src/bi/cuda/updater/DynamicMaxLogDensityGPU.cuh: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_UPDATER_DYNAMICMAXLOGDENSITYGPU_CUH 9 | #define BI_CUDA_UPDATER_DYNAMICMAXLOGDENSITYGPU_CUH 10 | 11 | #include "../../state/State.hpp" 12 | #include "../../method/misc.hpp" 13 | 14 | namespace bi { 15 | /** 16 | * Dynamic max log-density updater, on device. 17 | * 18 | * @ingroup method_updater 19 | * 20 | * @tparam B Model type. 21 | * @tparam S Action type list. 22 | */ 23 | template 24 | class DynamicMaxLogDensityGPU { 25 | public: 26 | template 27 | static void maxLogDensities(const T1 t1, const T1 t2, State& s, 28 | V1 lp); 29 | }; 30 | } 31 | 32 | #include "DynamicLogDensityKernel.cuh" 33 | #include "../device.hpp" 34 | 35 | template 36 | template 37 | void bi::DynamicMaxLogDensityGPU::maxLogDensities(const T1 t1, const T1 t2, 38 | State& s, V1 lp) { 39 | /* pre-condition */ 40 | BI_ASSERT(V1::on_device); 41 | 42 | const int N = 43 | (block_is_matrix < S > ::value) ? 44 | block_count < S > ::value : block_size < S > ::value; 45 | const int P = s.size(); 46 | dim3 Db, Dg; 47 | 48 | Db.y = N; 49 | Dg.y = 1; 50 | Db.x = bi::max(1, bi::min(deviceIdealThreadsPerBlock() / N, P)); 51 | Dg.x = (P + Db.x - 1) / Db.x; 52 | 53 | if (N > 0) { 54 | kernelDynamicLogDensity<<>>(t1, t2, s, lp); 55 | CUDA_CHECK; 56 | } 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /share/src/bi/host/updater/StaticLogDensityMatrixVisitorHost.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_HOST_UPDATER_STATICLOGDENSITYMATRIXVISITORHOST_HPP 9 | #define BI_HOST_UPDATER_STATICLOGDENSITYMATRIXVISITORHOST_HPP 10 | 11 | namespace bi { 12 | /** 13 | * Visitor for StaticLogDensityHost. 14 | */ 15 | template 16 | class StaticLogDensityMatrixVisitorHost { 17 | public: 18 | template 19 | static void accept(State& s, const int p, const PX& pax, OX& x, 20 | T1& lp); 21 | }; 22 | 23 | /** 24 | * @internal 25 | * 26 | * Base case of StaticLogDensityMatrixVisitorHost. 27 | */ 28 | template 29 | class StaticLogDensityMatrixVisitorHost { 30 | public: 31 | template 32 | static void accept(State& s, const int p, const PX& pax, OX& x, 33 | T1& lp) { 34 | // 35 | } 36 | }; 37 | } 38 | 39 | #include "../../typelist/front.hpp" 40 | #include "../../typelist/pop_front.hpp" 41 | 42 | template 43 | template 44 | void bi::StaticLogDensityMatrixVisitorHost::accept( 45 | State& s, const int p, const PX& pax, OX& x, T1& lp) { 46 | typedef typename front::type front; 47 | typedef typename pop_front::type pop_front; 48 | 49 | front::logDensities(s, p, pax, x, lp); 50 | StaticLogDensityMatrixVisitorHost::accept(s, p, pax, x, 51 | lp); 52 | } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /share/src/bi/primitive/strided_pitched_range.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_MISC_STRIDEDPITCHEDRANGE_HPP 9 | #define BI_MISC_STRIDEDPITCHEDRANGE_HPP 10 | 11 | #include "strided_pitched_sequence.hpp" 12 | 13 | #include "thrust/iterator/permutation_iterator.h" 14 | #include "thrust/distance.h" 15 | 16 | namespace bi { 17 | /** 18 | * Strided and pitched range. 19 | * 20 | * @ingroup primitive_iterators 21 | */ 22 | template 23 | struct strided_pitched_range { 24 | typedef typename thrust::iterator_difference::type difference_type; 25 | typedef typename strided_pitched_sequence::iterator PitchedIterator; 26 | typedef thrust::permutation_iterator PermutationIterator; 27 | typedef PermutationIterator iterator; 28 | 29 | strided_pitched_range(Iterator first, Iterator last, 30 | const difference_type rows, const difference_type lead, 31 | const difference_type inc) : 32 | first(first), last(last), rows(rows), lead(lead), inc(inc) { 33 | // 34 | } 35 | 36 | iterator begin() const { 37 | return iterator(first, 38 | strided_pitched_sequence(0, rows, lead, inc).begin()); 39 | } 40 | 41 | iterator end() const { 42 | difference_type d = thrust::distance(first, last); 43 | return begin() + (d / lead * rows) + ((d % lead) + inc - 1) / inc; 44 | } 45 | 46 | private: 47 | Iterator first, last; 48 | difference_type rows, lead, inc; 49 | }; 50 | 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /share/src/bi/concept/Partitioner.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | * 8 | * Imported from dysii 1.4.0, originally indii/ml/aux/Partitioner.hpp 9 | */ 10 | #error "Concept documentation only, should not be #included" 11 | 12 | #include "../kd/kde.hpp" 13 | 14 | namespace bi { 15 | /** 16 | * %Partitioner concept. 17 | * 18 | * @ingroup concept 19 | * 20 | * Partitions a set of weighted points into two sets for constructing a 21 | * partition tree. 22 | * 23 | * @note This is a phony class, representing a concept, for documentation 24 | * purposes only. 25 | */ 26 | class Partitioner { 27 | public: 28 | /** 29 | * Initialise the partitioner. 30 | * 31 | * @tparam M1 Matrix type. 32 | * @tparam V1 Integer vector type. 33 | * 34 | * @param X Samples. Rows index samples, columns index variables. 35 | * @param is Indices of components of interest in the weighted sample 36 | * set. 37 | * 38 | * @return True if the partition is successful, false otherwise. The 39 | * partition may be unsuccessful if e.g. all points are identical or one 40 | * point in a pair has negligible or zero weight. 41 | */ 42 | template 43 | bool init(const M1 X, const V1 is); 44 | 45 | /** 46 | * Assign a sample to a partition. 47 | * 48 | * @tparam V1 Vector type. 49 | * 50 | * @param x The sample to assign. 51 | * 52 | * @return The partition to which the sample is assigned. 53 | */ 54 | template 55 | bi::Partition assign(const V1 x); 56 | }; 57 | } 58 | -------------------------------------------------------------------------------- /share/src/bi/cuda/updater/SparseStaticUpdaterKernel.cuh: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_CUDA_UPDATER_SPARSESTATICUPDATERKERNEL_CUH 9 | #define BI_CUDA_UPDATER_SPARSESTATICUPDATERKERNEL_CUH 10 | 11 | #include "../cuda.hpp" 12 | 13 | namespace bi { 14 | /** 15 | * Kernel function for sparse static updates. 16 | * 17 | * @tparam B Model type. 18 | * @tparam S Action type list. 19 | * 20 | * @param mask Mask. 21 | */ 22 | template 23 | CUDA_FUNC_GLOBAL void kernelSparseStaticUpdater(State s, 24 | const Mask mask); 25 | 26 | } 27 | 28 | #include "SparseStaticUpdaterMatrixVisitorGPU.cuh" 29 | #include "SparseStaticUpdaterVisitorGPU.cuh" 30 | #include "../constant.cuh" 31 | #include "../global.cuh" 32 | #include "../../state/Pa.hpp" 33 | 34 | template 35 | CUDA_FUNC_GLOBAL void bi::kernelSparseStaticUpdater(State s, 36 | const Mask mask) { 37 | typedef Pa PX; 38 | typedef Ou OX; 39 | typedef SparseStaticUpdaterMatrixVisitorGPU MatrixVisitor; 40 | typedef SparseStaticUpdaterVisitorGPU ElementVisitor; 41 | typedef typename boost::mpl::if_c::value,MatrixVisitor, 42 | ElementVisitor>::type Visitor; 43 | 44 | const int p = blockIdx.x*blockDim.x + threadIdx.x; 45 | PX pax; 46 | OX x; 47 | 48 | /* update */ 49 | if (p < s.size()) { 50 | Visitor::accept(s, mask, p, pax, x); 51 | } 52 | } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /share/tt/cpp/block/const_std_.hpp.tt: -------------------------------------------------------------------------------- 1 | [% 2 | ## @file 3 | ## 4 | ## @author Lawrence Murray 5 | ## $Rev$ 6 | ## $Date$ 7 | %] 8 | 9 | [% USE Math %] 10 | 11 | [%- 12 | std = block.get_actions.0.get_named_arg('std'); 13 | target = block.get_actions.0.get_left; 14 | -%] 15 | 16 | [%-PROCESS block/misc/header.hpp.tt-%] 17 | 18 | /** 19 | * Block: const_std_. 20 | */ 21 | class [% class_name %] { 22 | public: 23 | [% declare_block_static_function('simulate') %] 24 | [% declare_block_static_function('sample') %] 25 | [% declare_block_static_function('logdensity') %] 26 | [% declare_block_static_function('maxlogdensity') %] 27 | 28 | [% declare_block_dynamic_function('simulate') %] 29 | [% declare_block_dynamic_function('sample') %] 30 | [% declare_block_dynamic_function('logdensity') %] 31 | [% declare_block_dynamic_function('maxlogdensity') %] 32 | }; 33 | 34 | #include "bi/primitive/matrix_primitive.hpp" 35 | 36 | [% sig_block_static_function('simulate') %] { 37 | BOOST_AUTO(target, [% get_output_var(target) %]); 38 | int cols = [% Math.sqrt(target.get_var.get_size) %]; 39 | matrix_set_elements(columns(target, 0, cols, cols + 1), [% std.eval_const %]); 40 | } 41 | 42 | [% std_block_static_function('sample') %] 43 | [% std_block_static_function('logdensity') %] 44 | [% std_block_static_function('maxlogdensity') %] 45 | 46 | [% std_block_dynamic_function('simulate') %] 47 | [% std_block_dynamic_function('sample') %] 48 | [% std_block_dynamic_function('logdensity') %] 49 | [% std_block_dynamic_function('maxlogdensity') %] 50 | 51 | [% PROCESS 'block/misc/footer.hpp.tt' %] 52 | -------------------------------------------------------------------------------- /share/src/bi/host/updater/StaticMaxLogDensityMatrixVisitorHost.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * @author Lawrence Murray 5 | * $Rev$ 6 | * $Date$ 7 | */ 8 | #ifndef BI_HOST_UPDATER_STATICMAXLOGDENSITYMATRIXVISITORHOST_HPP 9 | #define BI_HOST_UPDATER_STATICMAXLOGDENSITYMATRIXVISITORHOST_HPP 10 | 11 | namespace bi { 12 | /** 13 | * Visitor for StaticMaxLogDensityHost. 14 | */ 15 | template 16 | class StaticMaxLogDensityMatrixVisitorHost { 17 | public: 18 | template 19 | static void accept(State& s, const int p, const PX& pax, OX& x, 20 | T1& lp); 21 | }; 22 | 23 | /** 24 | * @internal 25 | * 26 | * Base case of StaticMaxLogDensityMatrixVisitorHost. 27 | */ 28 | template 29 | class StaticMaxLogDensityMatrixVisitorHost { 30 | public: 31 | template 32 | static void accept(State& s, const int p, const PX& pax, OX& x, 33 | T1& lp) { 34 | // 35 | } 36 | }; 37 | } 38 | 39 | #include "../../typelist/front.hpp" 40 | #include "../../typelist/pop_front.hpp" 41 | 42 | template 43 | template 44 | void bi::StaticMaxLogDensityMatrixVisitorHost::accept( 45 | State& s, const int p, const PX& pax, OX& x, T1& lp) { 46 | typedef typename front::type front; 47 | typedef typename pop_front::type pop_front; 48 | 49 | front::maxLogDensities(s, p, pax, x, lp); 50 | StaticMaxLogDensityMatrixVisitorHost::accept(s, p, pax, 51 | x, lp); 52 | } 53 | 54 | #endif 55 | --------------------------------------------------------------------------------