Skip to content
gigabit-clownsPublic

About

High-performace Cryo-EM and Cryo-ET primitive library for REX

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Latest commit

 

History

1,335 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rexlib

CI

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.

Installing

pip install rexlib

Wheels 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.

Using it from Python

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.

Highlights

  • Cryo-EM and Cryo-ET operations in rexlib::em and rexlib.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.

Components

  • 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 in rexlib::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.

Using it from CMake

find_package(rexlib REQUIRED)
target_link_libraries(my_program PRIVATE rexlib::rexlib)

Minimal C++ example

#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;
}

Building from source

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 build

With CMake 3.21 or newer, presets provide the same flow:

cmake --preset debug
cmake --build --preset debug
ctest --preset debug

With -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

About

High-performace Cryo-EM and Cryo-ET primitive library for REX

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages