Skip to content

Commit 369b93a

Browse files
authored
Merge pull request #1053 from stan-dev/opencl-ci
Enable OpenCL tests in CI for Linux, Mac, WSL
2 parents 3b6cf27 + 95ce763 commit 369b93a

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

.github/workflows/R-CMD-check-wsl.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
2424
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
2525
NOT_CRAN: true
26+
CMDSTANR_OPENCL_TESTS: true
2627

2728
steps:
2829
- name: cmdstan env vars
@@ -54,7 +55,7 @@ jobs:
5455
- name: Install WSL Dependencies
5556
run: |
5657
sudo apt-get update
57-
sudo apt-get install -y build-essential libopenmpi-dev
58+
sudo apt-get install -y build-essential libopenmpi-dev ocl-icd-opencl-dev pocl-opencl-icd
5859
shell: wsl-bash {0}
5960

6061
- name: Install cmdstan

.github/workflows/R-CMD-check.yaml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,19 @@ jobs:
2323
fail-fast: false
2424
matrix:
2525
config:
26-
- {os: macOS-latest, r: 'devel', rtools: ''}
27-
- {os: macOS-latest, r: 'release', rtools: ''}
26+
- {os: macOS-latest, r: 'devel', rtools: '', opencl: true}
27+
- {os: macOS-latest, r: 'release', rtools: '', opencl: true}
2828
- {os: windows-latest, r: 'devel', rtools: '44'}
2929
- {os: windows-latest, r: 'release', rtools: '44'}
3030
- {os: windows-latest, r: 'oldrel', rtools: '43'}
31-
- {os: ubuntu-latest, r: 'devel', rtools: ''}
32-
- {os: ubuntu-latest, r: 'release', rtools: ''}
33-
- {os: ubuntu-latest, r: 'oldrel', rtools: ''}
31+
- {os: ubuntu-latest, r: 'devel', rtools: '', opencl: true}
32+
- {os: ubuntu-latest, r: 'release', rtools: '', opencl: true}
33+
- {os: ubuntu-latest, r: 'oldrel', rtools: '', opencl: true}
3434
env:
3535
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
3636
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
3737
NOT_CRAN: true
38+
CMDSTANR_OPENCL_TESTS: ${{ matrix.config.opencl }}
3839

3940
steps:
4041
- name: cmdstan env vars
@@ -64,8 +65,24 @@ jobs:
6465

6566
- uses: r-lib/actions/[email protected]
6667
with:
68+
cache: "always"
6769
extra-packages: any::rcmdcheck, local::.
6870

71+
- name: Install POCL on Ubuntu Runners
72+
if: ${{ matrix.config.os == 'ubuntu-latest' }}
73+
run: |
74+
sudo apt-get update && sudo apt-get install -y ocl-icd-opencl-dev pocl-opencl-icd
75+
shell: bash
76+
77+
- name: Install POCL on MacOS Runners
78+
if: ${{ matrix.config.os == 'macOS-latest' }}
79+
run: |
80+
brew install pocl
81+
# Set LDLIBS_OPENCL environment variable so that CPU OpenCL is found
82+
# instead of Apple's GPU OpenCL - which does not support double precision
83+
echo "LDLIBS_OPENCL=-L'/opt/homebrew/opt/opencl-icd-loader/lib' -lOpenCL" >> $GITHUB_ENV
84+
shell: bash
85+
6986
- name: Install cmdstan
7087
run: |
7188
cmdstanr::check_cmdstan_toolchain(fix = TRUE)

tests/testthat/test-opencl.R

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ test_that("all methods error when opencl_ids is used with non OpenCL model", {
3333
test_that("all methods error on invalid opencl_ids", {
3434
skip_if_not(Sys.getenv("CMDSTANR_OPENCL_TESTS") %in% c("1", "true"))
3535
stan_file <- testing_stan_file("bernoulli")
36-
mod <- cmdstan_model(stan_file = stan_file, cpp_options = list(stan_opencl = TRUE))
36+
mod <- cmdstan_model(stan_file = stan_file, cpp_options = list(stan_opencl = TRUE),
37+
force_recompile = TRUE)
3738
utils::capture.output(
3839
expect_warning(
3940
mod$sample(data = testing_data("bernoulli"), opencl_ids = c(1000, 1000), chains = 1),
@@ -74,33 +75,34 @@ test_that("all methods run with valid opencl_ids", {
7475
fit <- mod$sample(data = testing_data("bernoulli"), opencl_ids = c(0, 0), chains = 1)
7576
)
7677
expect_false(is.null(fit$metadata()$opencl_platform_name))
77-
expect_false(is.null(fit$metadata()$opencl_ids_name))
78+
expect_false(is.null(fit$metadata()$opencl_device_name))
7879

7980
stan_file_gq <- testing_stan_file("bernoulli_ppc")
80-
mod_gq <- cmdstan_model(stan_file = stan_file_gq, cpp_options = list(stan_opencl = TRUE))
81+
mod_gq <- cmdstan_model(stan_file = stan_file_gq, cpp_options = list(stan_opencl = TRUE),
82+
force_recompile = TRUE)
8183
expect_gq_output(
8284
fit <- mod_gq$generate_quantities(fitted_params = fit, data = testing_data("bernoulli"), opencl_ids = c(0, 0)),
8385
)
8486
expect_false(is.null(fit$metadata()$opencl_platform_name))
85-
expect_false(is.null(fit$metadata()$opencl_ids_name))
87+
expect_false(is.null(fit$metadata()$opencl_device_name))
8688

8789
expect_sample_output(
8890
fit <- mod$sample(data = testing_data("bernoulli"), opencl_ids = c(0, 0))
8991
)
9092
expect_false(is.null(fit$metadata()$opencl_platform_name))
91-
expect_false(is.null(fit$metadata()$opencl_ids_name))
93+
expect_false(is.null(fit$metadata()$opencl_device_name))
9294

9395
expect_optim_output(
9496
fit <- mod$optimize(data = testing_data("bernoulli"), opencl_ids = c(0, 0))
9597
)
9698
expect_false(is.null(fit$metadata()$opencl_platform_name))
97-
expect_false(is.null(fit$metadata()$opencl_ids_name))
99+
expect_false(is.null(fit$metadata()$opencl_device_name))
98100

99101
expect_vb_output(
100102
fit <- mod$variational(data = testing_data("bernoulli"), opencl_ids = c(0, 0))
101103
)
102104
expect_false(is.null(fit$metadata()$opencl_platform_name))
103-
expect_false(is.null(fit$metadata()$opencl_ids_name))
105+
expect_false(is.null(fit$metadata()$opencl_device_name))
104106
})
105107

106108
test_that("error for runtime selection of OpenCL devices if version less than 2.26", {
@@ -111,7 +113,7 @@ test_that("error for runtime selection of OpenCL devices if version less than 2.
111113
mod <- cmdstan_model(stan_file = stan_file, cpp_options = list(stan_opencl = TRUE),
112114
force_recompile = TRUE)
113115
expect_error(
114-
mod$sample(data = data_list, chains = 1, refresh = 0, opencl_ids = c(1,1)),
116+
mod$sample(data = testing_data("bernoulli"), chains = 1, refresh = 0, opencl_ids = c(1,1)),
115117
"Runtime selection of OpenCL devices is only supported with CmdStan version 2.26 or newer",
116118
fixed = TRUE
117119
)

0 commit comments

Comments
 (0)