Example #1
0
// Default implementation marks the data pointed to by the buffer_t as initialized
// (but *not* the buffer_t itself); it takes pains to only mark the active memory ranges
// (skipping padding), and sorting into ranges to always mark the smallest number of
// ranges, in monotonically increasing memory order.
WEAK void halide_msan_annotate_buffer_is_initialized(void *user_context, buffer_t *b) {
    if (b == NULL) {
        return;
    }

    Halide::Runtime::Internal::device_copy c = Halide::Runtime::Internal::make_host_to_device_copy(b);
    if (c.chunk_size == 0) {
        return;
    }

    if (b->dev_dirty) {
        // buffer has been computed on a gpu, but not copied back:
        // don't annotate as initialized. (We'll assume that subsequent
        // calls to halide_copy_to_host will force another call.)
        return;
    }

    // TODO: Is this 32-bit or 64-bit? Leaving signed for now
    // in case negative strides.
    for (int w = 0; w < (int)c.extent[3]; w++) {
        for (int z = 0; z < (int)c.extent[2]; z++) {
            for (int y = 0; y < (int)c.extent[1]; y++) {
                for (int x = 0; x < (int)c.extent[0]; x++) {
                    const uint64_t off = (x * c.stride_bytes[0] +
                                    y * c.stride_bytes[1] +
                                    z * c.stride_bytes[2] +
                                    w * c.stride_bytes[3]);
                    const void *from = (void *)(c.src + off);
                    halide_msan_annotate_memory_is_initialized(user_context, from, c.chunk_size);
                }
            }
        }
    }
}
Example #2
0
WEAK void annotate_helper(void *uc, const device_copy &c, int d, int64_t off) {
    while (d >= 0 && c.extent[d] == 1) d--;

    if (d == -1) {
        const void *from = (void *)(c.src + off);
        halide_msan_annotate_memory_is_initialized(uc, from, c.chunk_size);
    } else {
        for (uint64_t i = 0; i < c.extent[d]; i++) {
            annotate_helper(uc, c, d - 1, off);
            off += c.src_stride_bytes[d];
        }
    }
};
Example #3
0
WEAK void halide_default_error(void *user_context, const char *msg) {
    char buf[4096];
    char *dst = halide_string_to_string(buf, buf + 4094, "Error: ");
    dst = halide_string_to_string(dst, buf + 4094, msg);
    // We still have one character free. Add a newline if there
    // isn't one already.
    if (dst[-1] != '\n') {
        dst[0] = '\n';
        dst[1] = 0;
        dst += 1;
    }
    halide_msan_annotate_memory_is_initialized(user_context, buf, dst - buf + 1);
    halide_print(user_context, buf);
    Halide::Runtime::Internal::halide_abort();
}