当前位置: 首页>>代码示例>>C++>>正文


C++ Func::infer_input_bounds方法代码示例

本文整理汇总了C++中Func::infer_input_bounds方法的典型用法代码示例。如果您正苦于以下问题:C++ Func::infer_input_bounds方法的具体用法?C++ Func::infer_input_bounds怎么用?C++ Func::infer_input_bounds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Func的用法示例。


在下文中一共展示了Func::infer_input_bounds方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main


//.........这里部分代码省略.........
                   empty_allocs, nonempty_allocs, frees);
            return -1;
        }

        reset_alloc_counts();
        param.set(false);
        out.realize(100);

        if (empty_allocs != 2 || nonempty_allocs != 1 || frees != 3) {
            printf("There were supposed to be 2 empty allocs, 1 nonempty alloc, and 3 frees.\n"
                   "Instead we got %d empty allocs, %d nonempty allocs, and %d frees.\n",
                   empty_allocs, nonempty_allocs, frees);
            return -1;
        }
    }

    {
        // Specialize for interleaved vs planar inputs
        ImageParam im(Float(32), 1);
        im.set_stride(0, Expr()); // unconstrain the stride

        Func f;
        Var x;

        f(x) = im(x);

        // If we have a stride of 1 it's worth vectorizing, but only if the width is also > 8.
        f.specialize(im.stride(0) == 1 && im.width() >= 8).vectorize(x, 8);

        f.trace_stores();
        f.set_custom_trace(&my_trace);

        // Check bounds inference is still cool with widths < 8
        f.infer_input_bounds(5);
        int m = im.get().min(0), e = im.get().extent(0);
        if (m != 0 || e != 5) {
            printf("min, extent = %d, %d instead of 0, 5\n", m, e);
            return -1;
        }

        // Check we don't crash with the small input, and that it uses scalar stores
        reset_trace();
        f.realize(5);
        if (!scalar_store || vector_store) {
            printf("These stores were supposed to be scalar.\n");
            return -1;
        }

        // Check we don't crash with a larger input, and that it uses vector stores
        Image<float> image(100);
        im.set(image);

        reset_trace();
        f.realize(100);
        if (scalar_store || !vector_store) {
            printf("These stores were supposed to be vector.\n");
            return -1;
        }

    }

    {
        // Bounds required of the input change depending on the param
        ImageParam im(Float(32), 1);
        Param<bool> param;
开发者ID:Mengke-Yuan,项目名称:Halide,代码行数:66,代码来源:specialize.cpp

示例2: main


//.........这里部分代码省略.........
    {
        // Create a fully unrolled fibonacci routine composed almost
        // entirely of single assignment statements. The horror!
        Func f;
        f(x) = 1;
        for (int i = 2; i < 20; i++) {
            f(i) = f(i-1) + f(i-2);
        }

        Image<int> result = f.realize(20);

        int ref[20];
        ref[0] = 1;
        ref[1] = 1;
        for (int i = 2; i < 20; i++) {
            ref[i] = ref[i-1] + ref[i-2];
            if (ref[i] != result(i)) {
                printf("fibonacci(%d) = %d instead of %d\n",
                       i, result(i), ref[i]);
                return -1;
            }
        }
    }

    {
        // Make an integral image
        Func f;
        f(x, y) = sin(x + y);

        RDom r(1, 99);
        f(x, r) += f(x, r - 1);
        f(r, y) += f(r - 1, y);

        // Walk down the image in vectors
        f.update(0).vectorize(x, 4);

        // Walk across the image in parallel. We need to do an unsafe
        // reorder operation here to move y to the outer loop, because
        // we don't have the ability to reorder vars with rvars yet.
        f.update(1).reorder(Var(r.x.name()), y).parallel(y);

        Image<float> result = f.realize(100, 100);

        // Now the equivalent in C (cheating and using Halide for the initial image)
        Image<float> ref = lambda(x, y, sin(x+y)).realize(100, 100);
        for (int y = 1; y < 100; y++) {
            for (int x = 0; x < 100; x++) {
                ref(x, y) += ref(x, y - 1);
            }
        }
        for (int y = 0; y < 100; y++) {
            for (int x = 1; x < 100; x++) {
                ref(x, y) += ref(x - 1, y);
            }
        }

        // Check they're the same
        for (int y = 0; y < 100; y++) {
            for (int x = 0; x < 100; x++) {
                if (fabs(ref(x, y) - result(x, y)) > 0.0001f) {
                    printf("integral image at (%d, %d) = %f instead of %f\n",
                           x, y, result(x, y), ref(x, y));
                    return -1;
                }
            }
        }
    }

    {
        // Walk down an image using a few different factors of splits
        Func f;
        RDom r(1, 99);
        Var xo, xi;
        ImageParam input(Float(32), 2);
        f(x, y) = input(x, y);
        f(x, r) += f(x, r-1) + input(x, r);
        f(x, r) += f(x, r-1) + input(x, r);
        f(x, r) += f(x, r-1) + input(x, r);
        f(x, r) += f(x, r-1) + input(x, r);
        f.update(0).split(x, x, xi, 11);
        f.update(1).split(x, x, xi, 13);
        f.update(2).split(x, x, xi, 17);

        // So if we ask for an output of size 100x10, we'll need an
        // input of size 110 x 100. 110 is enough to cover rounding up
        // 100 to be a multiple of 11, 13, and 17.
        f.infer_input_bounds(100, 10);

        Image<float> in = input.get();
        if (in.width() != 110 || in.height() != 100) {
            printf("Unexpected image size: %d x %d instead of 144 x 100\n",
                   in.width(), in.height());
            return -1;
        }
    }

    printf("Success!\n");

    return 0;
}
开发者ID:EEmmanuel7,项目名称:Halide,代码行数:101,代码来源:multi_pass_reduction.cpp


注:本文中的Func::infer_input_bounds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。