https://github.com/halide/Halide
Raw File
Tip revision: 6a2fa039123e1266f0e6facf4d942be9701eec65 authored by Alex Reinking on 28 June 2019, 15:52:16 UTC
Reorganizing code. Next step: implement fused stages.
Tip revision: 6a2fa03
pseudostack.cpp
#include "HalideRuntime.h"
#include "runtime_internal.h"

extern "C" {

inline WEAK __attribute__((always_inline)) __attribute__((used)) void *pseudostack_alloc(void *user_context, halide_pseudostack_slot_t *slot, size_t sz) {
    if (__builtin_expect(sz > slot->size, 0)) {
        if (slot->ptr) halide_free(user_context, slot->ptr);
        slot->ptr = halide_malloc(user_context, sz);
        slot->size = sz;
    }
    return slot->ptr;
}

// Only called as a destructor at function exit
inline WEAK __attribute__((always_inline)) __attribute__((used)) void pseudostack_free(void *user_context, void *ptr) {
    halide_pseudostack_slot_t *slot = (halide_pseudostack_slot_t *)ptr;
    slot->size = 0;
    if (slot->ptr) halide_free(user_context, slot->ptr);
    slot->ptr = NULL;
}

}
back to top