OpenPFC  0.1.4
Phase Field Crystal simulation framework
Loading...
Searching...
No Matches
databuffer.hpp File Reference

Backend-agnostic memory buffer with tag-based dispatch. More...

#include <cstddef>
#include <stdexcept>
#include <vector>
#include <openpfc/core/backend_tags.hpp>
Include dependency graph for databuffer.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  pfc::core::DataBuffer< backend::CpuTag, T >
 CPU specialization of DataBuffer. More...
 

Detailed Description

Backend-agnostic memory buffer with tag-based dispatch.

DataBuffer provides a unified interface for memory management across different backends (CPU, CUDA, HIP) using template specialization. Each backend is conditionally compiled, ensuring that CPU-only builds work without GPU dependencies.

Key features:

  • Backend-agnostic interface (same API for all backends)
  • Zero runtime overhead (compile-time dispatch)
  • RAII memory management
  • CPU-GPU transfer methods
  • Move semantics supported
  • Copy semantics disabled for GPU backends
// CPU memory (always available)
cpu_buf[0] = 1.0; // Works - CPU has operator[]
#if defined(OpenPFC_ENABLE_CUDA)
// GPU memory (only when CUDA enabled)
// gpu_buf[0] = 1.0; // ERROR - can't dereference device pointer!
std::vector<double> host_data(1000, 1.0);
gpu_buf.copy_from_host(host_data);
#endif
Backend-agnostic memory buffer.
Definition databuffer.hpp:68
See also
core/backend_tags.hpp for backend tag definitions
core/memory_traits.hpp for backend metadata
Author
OpenPFC Development Team
Date
2025