Compiling CmdStan 2.24.1 with STAN_OPENCL=true

Hello,

there is a problem when I am trying to build CmdStan 2.24.1 with STAN_OPENCL=true.
I set up the following flags in make/local (they are based on clinfo output):

STAN_OPENCL=true
OPENCL_DEVICE_ID=0
OPENCL_PLATFORM_ID=0

The build fails with the following error:

g++ -std=c++1y -pthread -D_REENTRANT -Wno-sign-compare -Wno-ignored-attributes   -I stan/lib/stan_math/lib/opencl_2.2.0   -I stan/lib/stan_math/lib/tbb_2019_U8/include -O3 -I src -I stan/src -I lib/rapidjson_1.1.0/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.7 -I stan/lib/stan_math/lib/boost_1.72.0 -I stan/lib/stan_math/lib/sundials_5.2.0/include    -DBOOST_DISABLE_ASSERTS  -DSTAN_OPENCL -DOPENCL_DEVICE_ID=0 -DOPENCL_PLATFORM_ID=0 -DCL_HPP_TARGET_OPENCL_VERSION=120 -DCL_HPP_MINIMUM_OPENCL_VERSION=120 -DCL_HPP_ENABLE_EXCEPTIONS -Wno-ignored-attributes          -Wl,-L,"/home/oleksandr/Projects/Stan/cmdstan-2.24.1/stan/lib/stan_math/lib/tbb" -Wl,-rpath,"/home/oleksandr/Projects/Stan/cmdstan-2.24.1/stan/lib/stan_math/lib/tbb"  bin/cmdstan/stansummary.o stan/lib/stan_math/lib/boost_1.72.0/stage/lib/libboost_program_options.a stan/lib/stan_math/lib/boost_1.72.0/stage/lib/libboost_program_options.a      -lOpenCL   -o bin/stansummary
bin/cmdstan/stansummary.o: In function `tbb::internal::task_scheduler_observer_v3::~task_scheduler_observer_v3()':
stansummary.cpp:(.text._ZN3tbb8internal26task_scheduler_observer_v3D2Ev[_ZN3tbb8internal26task_scheduler_observer_v3D5Ev]+0x14): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
bin/cmdstan/stansummary.o: In function `tbb::internal::task_scheduler_observer_v3::~task_scheduler_observer_v3()':
stansummary.cpp:(.text._ZN3tbb8internal26task_scheduler_observer_v3D0Ev[_ZN3tbb8internal26task_scheduler_observer_v3D5Ev]+0x18): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
bin/cmdstan/stansummary.o: In function `__static_initialization_and_destruction_0(int, int) [clone .constprop.2003]':
stansummary.cpp:(.text.startup+0x3e2b): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
bin/cmdstan/stansummary.o: In function `tbb::interface6::task_scheduler_observer::~task_scheduler_observer()':
stansummary.cpp:(.text._ZN3tbb10interface623task_scheduler_observerD2Ev[_ZN3tbb10interface623task_scheduler_observerD5Ev]+0x18): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
stansummary.cpp:(.text._ZN3tbb10interface623task_scheduler_observerD2Ev[_ZN3tbb10interface623task_scheduler_observerD5Ev]+0x36): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
bin/cmdstan/stansummary.o:stansummary.cpp:(.text._ZN3tbb10interface623task_scheduler_observerD0Ev[_ZN3tbb10interface623task_scheduler_observerD5Ev]+0x18): more undefined references to `tbb::internal::task_scheduler_observer_v3::observe(bool)' follow
collect2: error: ld returned 1 exit status
make/command:29: recipe for target 'bin/stansummary' failed
make: *** [bin/stansummary] Error 1

When I am making the same build but without STAN_OPENCL flag, then there is no error and build is successful.

Operating System: Ubuntu 18.04
Interface Version: CmdStan 2.24.1
Compiler/Toolkit: g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0, Make 4.1

I am working with Python and want to enjoy the speed up provided by use of GPU for Stan. Please help me with this issue.
P.S. Looked through existing topics and did not found one that can solve the problem (or, at least, I think so).

You can just build cmdstan normally without the flag, then turn it on for the model.

So something like:
ā€” clean the make/local
makr clean-all
make build
ā€” write opencl flags in the make/local
ā€” compile the model

This is the usual workflow but we will definitely take a look. Thanks for the report.

Thank you very much! This solved the issue.
As I see now, I misunderstood the documentation for CmdStan and Stan math library: there is no requirement nor suggestion to build CmdStan with STAN_OPENCL flag, and this flag is only mentioned in the context of Stan program compilation with GPU support.

1 Like

That is correct, though the error you experienced should not happen and will be fixed ASAP.

1 Like