<commit_before>#include "mini_ion.h"

namespace Halide { namespace Runtime { namespace Internal { namespace Ion {

// Allocate an ION buffer, and map it, returning the mapped pointer.
WEAK void *ion_alloc(void *user_context, size_t len, int heap_id, int *out_fd) {
    void *ret = halide_malloc(user_context, len);
    if (ret && out_fd) {
        *out_fd = -1;
    }

    return ret;
}

// Free a previously allocated ION buffer.
WEAK void ion_free(void *user_context, void *ion) {
    halide_free(user_context, ion);
}

}}}}  // namespace Halide::Runtime::Internal::Ion<commit_msg>fake_ion needs to align to 128-byte boundaries<commit_after>#include "mini_ion.h"

namespace Halide { namespace Runtime { namespace Internal { namespace Ion {

struct allocation_record {
    void *original;
};

// Allocate an ION buffer, and map it, returning the mapped pointer.
WEAK void *ion_alloc(void *user_context, size_t len, int heap_id, int *out_fd) {
    const size_t align = 128;

    // Align the allocation size.
    len = (len + align - 1) & ~(align - 1);

    // Allocate enough space to hold information about the allocation prior to the pointer we return.
    len += align;

    void *original = halide_malloc(user_context, len);

    // Store the original ptr before the pointer we return.
    allocation_record rec = { original };
    void *ret = reinterpret_cast<char *>(original) + align;
    halide_assert(user_context, sizeof(allocation_record) <= align);
    memcpy(reinterpret_cast<allocation_record *>(ret) - 1, &rec, sizeof(rec));

    if (ret && out_fd) {
        *out_fd = -1;
    }
    return ret;
}

// Free a previously allocated ION buffer.
WEAK void ion_free(void *user_context, void *ion) {
    if (!ion) return;
    allocation_record rec = *(reinterpret_cast<allocation_record *>(ion) - 1);
    halide_free(user_context, rec.original);
}

}}}}  // namespace Halide::Runtime::Internal::Ion
{'fraction_non_alphanumeric': 0.11536444677503933, 'fraction_numerical': 0.006292606187729418, 'mean_word_length': 3.722772277227723, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2194070', 'n_tokens_mistral': 617, 'n_tokens_neox': 596, 'n_words': 189}