rexlib is a high-performance Cryo-EM and Cryo-ET image processing library, written in C++ with a Python binding. Its operations run on whichever device a backend plugin provides: the CPU backend is built in, and a CUDA plugin runs them on NVIDIA GPUs.
pip install rexlibWheels are built for Python 3.11 and later on Linux x86_64 and aarch64, macOS arm64, and Windows x86_64 and arm64. On Linux, the CUDA plugin comes as an extra, for CUDA 12 or CUDA 13:
pip install "rexlib[cuda12]"The C++ library is installed from source with CMake, as below, and the wheel carries its headers and CMake package too.
import rexlib
descriptor = rexlib.make_contiguous_array_descriptor(
[2, 2], rexlib.NumericalType.float32
)
zeros = rexlib.zeros(descriptor, rexlib.hardware.MemoryResourceAffinity.host)
with rexlib.device("cuda"):
on_gpu = rexlib.zeros(
descriptor, rexlib.hardware.MemoryResourceAffinity.device
)The default catalog loads every installed plugin wheel on first use.
- Cryo-EM and Cryo-ET operations in
rexlib::emandrexlib.em, beside the array operations they are built on. - Device-agnostic execution model. Operations are dispatched through services and execution contexts instead of being tied to one device API.
- Pluggable backends. A backend plugin is a shared object defined with
REXLIB_DEFINE_PLUGIN, which the core loads only if it was built for a compatible rexlib and C++ ABI. A third party builds one against the installed library; the plugin guide says how. - Public headers as contract. The public interface is the headers in
include/rexlib/, documented directly in the C++ reference, and consumable from C++14.
core: operation model, dispatch, hardware abstraction, plugin loading, layouts and numerical infrastructure.ops: operation declarations.functional: user-facing functions that reach operation declarations.em: Cryo-EM and Cryo-ET operations and functions inrexlib::em.backends/cpu: the CPU backend.python/: the Python binding.plugins/cuda/: the CUDA plugin.
Image I/O is out of scope for rexlib and lives in vitrio.
find_package(rexlib REQUIRED)
target_link_libraries(my_program PRIVATE rexlib::rexlib)#include <rexlib/core/dispatch/dispatcher.hpp>
#include <rexlib/core/dispatch/execution_context.hpp>
#include <rexlib/core/dispatch/program_service.hpp>
#include <rexlib/core/hardware/buffer.hpp>
#include <rexlib/core/hardware/device_context.hpp>
#include <rexlib/core/hardware/device_index.hpp>
#include <rexlib/core/hardware/device_service.hpp>
#include <rexlib/core/hardware/memory_resource_affinity.hpp>
#include <rexlib/core/library_version.hpp>
#include <rexlib/core/numerical/numerical_type.hpp>
#include <rexlib/core/service_catalog.hpp>
#include <rexlib/functional/creation.hpp>
#include <cstdint>
#include <iostream>
int main()
{
std::cout << "rexlib " << rexlib::get_library_version() << "\n";
rexlib::service_catalog catalog;
const auto devices =
catalog.get_service<rexlib::device_service>();
const auto programs =
catalog.get_service<rexlib::program_service>();
const rexlib::execution_context context(
rexlib::device_context(
devices->create_device_session(rexlib::device_index("cpu", 0))
),
rexlib::make_eager_dispatcher(programs)
);
auto result = rexlib::arange(
5,
rexlib::numerical_type::int32,
rexlib::memory_resource_affinity::host,
context
);
const auto *values = static_cast<const std::int32_t*>(
result.get_storage()->get_host_ptr()
);
for (std::int32_t i = 0; i < 5; ++i)
{
if (values[i] != i)
{
return 1;
}
}
return 0;
}The dependencies' sources are git submodules, so clone with them:
git clone --recurse-submodules https://github.com/gigabit-clowns/rexlib.git
cd rexlib
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
cmake --build build -j
ctest --test-dir buildWith CMake 3.21 or newer, presets provide the same flow:
cmake --preset debug
cmake --build --preset debug
ctest --preset debugWith -DREXLIB_BUILD_PYTHON=ON the build includes the Python binding, and
pip install . builds the rexlib wheel. The CUDA plugin, in plugins/cuda/,
is built against an installed rexlib, as any plugin is. The
build guide
has the details.
To generate the C++ API reference:
cmake -S . -B build -DREXLIB_BUILD_DOCS=ON -DBUILD_TESTING=OFF
cmake --build build --target rexlib-docs