File: target_query.cpp

package info (click to toggle)
halide 21.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • 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 (48 lines) | stat: -rw-r--r-- 1,449 bytes parent folder | download | duplicates (3)
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
47
48
#include "Halide.h"
#include <stdio.h>

using namespace Halide;

int main(int argc, char **argv) {
    // For simplicity, only run this test on hosts that we can predict.
    Target t = get_host_target();
    if (t.arch != Target::X86 || t.bits != 64 || t.os != Target::OSX) {
        printf("[SKIP] This test only runs on x86-64-osx.\n");
        return 0;
    }

    t = t.with_feature(Target::Debug);

    // Full specification round-trip, crazy features
    Target t1 = Target(Target::OSX, Target::X86, 64,
                       {Target::CUDA, Target::Debug});

    Expr is_arm = target_arch_is(Target::ARM);
    Expr is_x86 = target_arch_is(Target::X86);
    Expr bits = target_bits();
    Expr is_android = target_os_is(Target::Android);
    Expr is_osx = target_os_is(Target::OSX);
    Expr vec = target_natural_vector_size<float>();
    Expr has_cuda = target_has_feature(Target::CUDA);
    Expr has_vulkan = target_has_feature(Target::Vulkan);

    Func f;
    Var x;

    f(x) = select(is_arm, 1, 0) +
           select(is_x86, 2, 0) +
           select(vec == 4, 4, 0) +
           select(is_android, 8, 0) +
           select(is_osx, 16, 0) +
           select(bits == 32, 32, 0) +
           select(bits == 64, 64, 0) +
           select(has_cuda, 128, 0) +
           select(has_vulkan, 256, 0);

    Buffer<int> result = f.realize({1}, t1);

    assert(result(0) == 2 + 4 + 16 + 64 + 128);

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