Skip to content

CMake configuration and wrapper library

Ryan Curtin requested to merge rcurtin/bandicoot-code:wrapper-library into unstable

This (large) MR implements a wrapper library for Bandicoot and adds a CMake build system based on Armadillo's. Some bullet points describing the changes:

  • All OpenCL and CUDA library calls are wrapped with coot_wrapper(). This works the same way as arma_wrapper() in Armadillo; if COOT_USE_WRAPPER is defined, then coot_wrapper(func) expands to wrapper_func(), which is just a function that calls func() directly, found in src/wrapper_*.cpp. If COOT_USE_WRAPPER is not defined, then coot_wrapper(func) just expands to func() and the user will need to directly link against whatever library provides func().

  • All OpenCL and CUDA functions we wrap are defined in bandicoot_bits/opencl/def_*.hpp and bandicoot_bits/cuda/def_*.hpp, respectively.

  • The CMake configuration, by default, will search for both backends, and set the default preferring CUDA. (The rationale being that if CUDA is available, it'll likely be faster than the OpenCL driver that nvidia provides.)

  • The CMake configuration has a handful of useful variables:

    • FIND_OPENCL=(ON/OFF)
    • FIND_CUDA=(ON/OFF)
    • DEFAULT_BACKEND=(CL_BACKEND/CUDA_BACKEND)
    • BUILD_TESTS=(ON/OFF)
  • Since MAGMA requires some BLAS and LAPACK functions, the CMake configuration from Armadillo has been adapted and the ALLOW_FLEXIBLAS_LINUX, ALLOW_OPENBLAS_MACOS, ALLOW_BLAS_LAPACK_MACOS, and other related configuration variables are included.

  • If BUILD_TESTS is set to ON, then bandicoot_test will be created. This is just the tests/main program that used to be created via Makefile. ctest is integrated and can be used.

  • The act of linking bandicoot_test is a test for the wrapper library itself, as bandicoot_test specifically links only against the wrapper library.

  • This CMake configuration is not yet battle-tested, and I suspect there will be some small changes here and there to handle unexpected situations. (I guess that's true about all code, ever, but in any case I specifically highlight it here to say I am not yet 100% confident this will work everywhere.)

Merge request reports