File: buffer_t.cpp

package info (click to toggle)
halide 21.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 55,752 kB
  • sloc: cpp: 289,334; ansic: 22,751; python: 7,486; makefile: 4,299; sh: 2,508; java: 1,549; javascript: 282; pascal: 207; xml: 127; asm: 9
file content (46 lines) | stat: -rw-r--r-- 1,474 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "Halide.h"
#include <stdio.h>

using namespace Halide;

#define CHECK(f, s32, s64) \
    static_assert(offsetof(halide_buffer_t, f) == (sizeof(void *) == 8 ? (s64) : (s32)), #f " is wrong")

#ifdef _MSC_VER
// VC2013 doesn't support alignof, apparently
#define ALIGN_OF(x) __alignof(x)
#else
#define ALIGN_OF(x) alignof(x)
#endif

int main(int argc, char **argv) {

    CHECK(device, 0, 0);
    CHECK(device_interface, 8, 8);
    CHECK(host, 12, 16);
    CHECK(flags, 16, 24);
    CHECK(type, 24, 32);
    CHECK(dimensions, 28, 36);
    CHECK(dim, 32, 40);
    CHECK(padding, 36, 48);

    static_assert((sizeof(void *) == 8 && sizeof(halide_buffer_t) == 56) ||
                      (sizeof(void *) == 4 && sizeof(halide_buffer_t) == 40),
                  "size is wrong");

    static_assert(sizeof(halide_dimension_t) == 16, "size of halide_dimension_t is wrong");

    // Ensure alignment is at least that of a pointer.
    static_assert(ALIGN_OF(halide_buffer_t) >= ALIGN_OF(uint8_t *), "align is wrong");

    // Also check that Halide understands the size correctly:
    int runtime_size = evaluate<int>(
        Internal::Call::make(Int(32), Internal::Call::size_of_halide_buffer_t, {}, Internal::Call::Intrinsic));
    if (runtime_size != sizeof(halide_buffer_t)) {
        printf("size_of_halide_buffer_t intrinsic returned %d instead of %d\n",
               runtime_size, (int)sizeof(halide_buffer_t));
    }

    printf("Success!\n");
    return 0;
}