Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Enable OpenCL tests in CI for Linux, Mac, WSL #1053

Merged
merged 6 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/R-CMD-check-wsl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
NOT_CRAN: true
CMDSTANR_OPENCL_TESTS: true

steps:
- name: cmdstan env vars
Expand Down Expand Up @@ -54,7 +55,7 @@ jobs:
- name: Install WSL Dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential libopenmpi-dev
sudo apt-get install -y build-essential libopenmpi-dev ocl-icd-opencl-dev pocl-opencl-icd
shell: wsl-bash {0}

- name: Install cmdstan
Expand Down
27 changes: 22 additions & 5 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: 'devel', rtools: ''}
- {os: macOS-latest, r: 'release', rtools: ''}
- {os: macOS-latest, r: 'devel', rtools: '', opencl: true}
- {os: macOS-latest, r: 'release', rtools: '', opencl: true}
- {os: windows-latest, r: 'devel', rtools: '44'}
- {os: windows-latest, r: 'release', rtools: '44'}
- {os: windows-latest, r: 'oldrel', rtools: '43'}
- {os: ubuntu-latest, r: 'devel', rtools: ''}
- {os: ubuntu-latest, r: 'release', rtools: ''}
- {os: ubuntu-latest, r: 'oldrel', rtools: ''}
- {os: ubuntu-latest, r: 'devel', rtools: '', opencl: true}
- {os: ubuntu-latest, r: 'release', rtools: '', opencl: true}
- {os: ubuntu-latest, r: 'oldrel', rtools: '', opencl: true}
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
NOT_CRAN: true
CMDSTANR_OPENCL_TESTS: ${{ matrix.config.opencl }}

steps:
- name: cmdstan env vars
Expand Down Expand Up @@ -64,8 +65,24 @@ jobs:

- uses: r-lib/actions/[email protected]
with:
cache: "always"
extra-packages: any::rcmdcheck, local::.

- name: Install POCL on Ubuntu Runners
if: ${{ matrix.config.os == 'ubuntu-latest' }}
run: |
sudo apt-get update && sudo apt-get install -y ocl-icd-opencl-dev pocl-opencl-icd
shell: bash

- name: Install POCL on MacOS Runners
if: ${{ matrix.config.os == 'macOS-latest' }}
run: |
brew install pocl
# Set LDLIBS_OPENCL environment variable so that CPU OpenCL is found
# instead of Apple's GPU OpenCL - which does not support double precision
echo "LDLIBS_OPENCL=-L'/opt/homebrew/opt/opencl-icd-loader/lib' -lOpenCL" >> $GITHUB_ENV
shell: bash

- name: Install cmdstan
run: |
cmdstanr::check_cmdstan_toolchain(fix = TRUE)
Expand Down
18 changes: 10 additions & 8 deletions tests/testthat/test-opencl.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ test_that("all methods error when opencl_ids is used with non OpenCL model", {
test_that("all methods error on invalid opencl_ids", {
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 <- cmdstan_model(stan_file = stan_file, cpp_options = list(stan_opencl = TRUE),
force_recompile = TRUE)
utils::capture.output(
expect_warning(
mod$sample(data = testing_data("bernoulli"), opencl_ids = c(1000, 1000), chains = 1),
Expand Down Expand Up @@ -74,33 +75,34 @@ test_that("all methods run with valid opencl_ids", {
fit <- mod$sample(data = testing_data("bernoulli"), opencl_ids = c(0, 0), chains = 1)
)
expect_false(is.null(fit$metadata()$opencl_platform_name))
expect_false(is.null(fit$metadata()$opencl_ids_name))
expect_false(is.null(fit$metadata()$opencl_device_name))

stan_file_gq <- testing_stan_file("bernoulli_ppc")
mod_gq <- cmdstan_model(stan_file = stan_file_gq, cpp_options = list(stan_opencl = TRUE))
mod_gq <- cmdstan_model(stan_file = stan_file_gq, cpp_options = list(stan_opencl = TRUE),
force_recompile = TRUE)
expect_gq_output(
fit <- mod_gq$generate_quantities(fitted_params = fit, data = testing_data("bernoulli"), opencl_ids = c(0, 0)),
)
expect_false(is.null(fit$metadata()$opencl_platform_name))
expect_false(is.null(fit$metadata()$opencl_ids_name))
expect_false(is.null(fit$metadata()$opencl_device_name))

expect_sample_output(
fit <- mod$sample(data = testing_data("bernoulli"), opencl_ids = c(0, 0))
)
expect_false(is.null(fit$metadata()$opencl_platform_name))
expect_false(is.null(fit$metadata()$opencl_ids_name))
expect_false(is.null(fit$metadata()$opencl_device_name))

expect_optim_output(
fit <- mod$optimize(data = testing_data("bernoulli"), opencl_ids = c(0, 0))
)
expect_false(is.null(fit$metadata()$opencl_platform_name))
expect_false(is.null(fit$metadata()$opencl_ids_name))
expect_false(is.null(fit$metadata()$opencl_device_name))

expect_vb_output(
fit <- mod$variational(data = testing_data("bernoulli"), opencl_ids = c(0, 0))
)
expect_false(is.null(fit$metadata()$opencl_platform_name))
expect_false(is.null(fit$metadata()$opencl_ids_name))
expect_false(is.null(fit$metadata()$opencl_device_name))
})

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