Skip to content

Commit

Permalink
Add testcases for Issue stan-dev#765
Browse files Browse the repository at this point in the history
* Model objects from exe file compiled with opencl fail to sample.
* stan_threads set in makefile not respected
  • Loading branch information
katrinabrock committed Aug 21, 2024
1 parent 8428615 commit 51d7302
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/testthat/test-opencl.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,13 @@ test_that("error for runtime selection of OpenCL devices if version less than 2.
)
reset_cmdstan_version()
})

test_that("model from exe_file retains open_cl option", {
skip_if_not(Sys.getenv("CMDSTANR_OPENCL_TESTS") %in% c("1", "true"))
stan_file <- testing_stan_file("bernoulli")
mod <- cmdstan_model(stan_file = stan_file, cpp_options = list(stan_opencl = TRUE))
mod_from_exe <- cmdstan_model(exe_file = mod$exe_file())
expect_sample_output(
fit <- mod_from_exe$sample(data = testing_data("bernoulli"), opencl_ids = c(0, 0), chains = 1)
)
})
19 changes: 19 additions & 0 deletions tests/testthat/test-threads.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,22 @@ test_that("correct output when stan_threads not TRUE", {
fixed = TRUE
)
})

test_that('correct output when stan threads set via make local',{
#TODO clean this up so no leftover changes to make local
file.copy(
file.path(cmdstan_path(), 'make', 'local'),
file.path(cmdstan_path(), 'make', 'local.save')
)
on.exit(file.rename(
file.path(cmdstan_path(), 'make', 'local.save'),
file.path(cmdstan_path(), 'make', 'local')
), add = TRUE, after = FALSE)
cmdstan_make_local(cpp_options = list(stan_threads = TRUE))
mod <- cmdstan_model(stan_program, force_recompile = TRUE)
expect_output(
f <- mod$sample(data = data_file_json, parallel_chains = 4, threads_per_chain = 1),
"Running MCMC with 4 parallel chains, with 1 thread(s) per chain..",
fixed = TRUE
)
})

0 comments on commit 51d7302

Please sign in to comment.