Memory Management API

Unified memory allocation and synchronization

Overview

Parallax uses unified memory that is accessible from both CPU and GPU. This eliminates the need for manual memory transfers in most cases.

Functions

parallax_umalloc

C
void* parallax_umalloc(size_t size, unsigned flags);

Allocates unified memory accessible from both CPU and GPU.

Parameters:

  • size: Number of bytes to allocate
  • flags: Reserved for future use (pass 0)

Returns: Pointer to allocated memory, or NULL on failure

parallax_ufree

C
void parallax_ufree(void* ptr);

Frees memory previously allocated with parallax_umalloc.

Parameters:

  • ptr: Pointer returned by parallax_umalloc

Automatic Coherence

Parallax uses software-defined unified memory with block-level dirty tracking (4KB blocks). Memory coherence is maintained automatically by the runtime - no explicit synchronization needed!

How it works:
  • Runtime tracks which blocks are modified on CPU vs GPU
  • Dirty blocks are transferred automatically before kernel execution
  • Results are available immediately after algorithm completes
  • No hardware page faults required - works on any Vulkan device

Example

C++
#include <vector>
#include <algorithm>
#include <execution>

int main() {
    std::vector<float> data(1'000'000, 1.0f);
    
    // GPU acceleration with automatic coherence
    std::for_each(std::execution::par,
                  data.begin(), data.end(),
                  [](float& x) { x *= 2.0f; });
    
    // Results immediately available - no sync needed!
    return 0;
}