示例#1
0
int main(int argc, char **argv) {
    ImageParam in(UInt(8), 3, "input");

    Var x("x"), y("y"), c("c"), x1, y1;
    Func f("f"), g("g"), h("h"), k("k");

    f(x, y, c) = cast<uint8_t>(255 - in(x, y, c));
    g(x, y, c) = cast<uint8_t>(2*in(x, y, c));
    h(x, y, c) = f(x, y, c) + g(x, y, c);
    k(x, y, c) = f(x, y, c) - g(x, y, c);

    f.reorder(c, x, y);
    g.reorder(c, x, y);
    h.reorder(c, x, y);
    k.reorder(c, x, y);

    //g.compute_with(f, y);
    f.gpu_tile(x, y, x1, y1, 16, 16);
    g.gpu_tile(x, y, x1, y1, 16, 16);
    h.gpu_tile(x, y, x1, y1, 16, 16);
    k.gpu_tile(x, y, x1, y1, 16, 16);


    Halide::Target target = Halide::get_host_target();
    target.set_feature(Halide::Target::CUDA, true);

    Pipeline({f, g, h, k}).compile_to_object("build/generated_fct_fusiongpu_ref.o", {in}, "fusiongpu_ref", target);

    Pipeline({f, g, h, k}).compile_to_lowered_stmt("build/generated_fct_fusiongpu_ref.txt", {in}, Halide::Text, target);

    return 0;
}
示例#2
0
int main(int argc, char* argv[]) {
    ImageParam in{UInt(8), 3, "input"};

    Func RGB2Gray{"RGB2Gray"};
    Var x, y, c, x0, y0, x1, y1;

    const Expr yuv_shift = cast<uint32_t>(14);
    const Expr R2Y = cast<uint32_t>(4899);
    const Expr G2Y = cast<uint32_t>(9617);
    const Expr B2Y = cast<uint32_t>(1868);

    RGB2Gray(x, y) = cast<uint8_t>(CV_DESCALE( (in(x, y, 2) * B2Y
                                                + in(x, y, 1) * G2Y
                                                + in(x, y, 0) * R2Y),
                                               yuv_shift));

    RGB2Gray.compute_root();
    RGB2Gray.gpu_tile(x, y, x0, y0, x1, y1, 16, 16);

    Halide::Target target = Halide::get_host_target();
    target.set_feature(Target::Feature::CUDA, true);

    RGB2Gray.compile_to_object("build/generated_fct_cvtcolorgpu_ref.o", {in}, "cvtcolorgpu_ref", target);

    RGB2Gray.compile_to_lowered_stmt("build/generated_fct_cvtcolorgpu_ref.txt", {in}, Text, target);

    return 0;
}
示例#3
0
文件: main.cpp 项目: halide/atom
int main(int argc, char **argv) {
    Halide::Func theFunc = getFunction();

    if (argc >= 3) {
        std::vector<Halide::Argument> arguments = theFunc.infer_arguments();

        Halide::Target target = Halide::get_target_from_environment();
        target.set_feature(Halide::Target::Feature::UserContext);

        theFunc.compile_to_object(argv[1] + std::string(".o"), arguments, argv[2], target);

        return 0;
    }

    return 1;
}
示例#4
0
HalideBackendWrapper::HalideBackendWrapper(int targetId, const cv::Mat& m)
    : BackendWrapper(DNN_BACKEND_HALIDE, targetId)
{
    managesDevMemory = true;
    buffer = wrapToHalideBuffer(m);
    if (targetId == DNN_TARGET_CPU)
    {
        return;
    }
    else if (targetId == DNN_TARGET_OPENCL)
    {
        Halide::Target t = Halide::get_host_target();
        t.set_feature(Halide::Target::OpenCL);
        buffer.copy_to_device(t);
    }
    else
        CV_Error(Error::StsNotImplemented, "Unknown target identifier");
}
示例#5
0
int main(int argc, char* argv[]) {
    ImageParam in(UInt(8), 3, "input");
    ImageParam kernelX(Float(32), 1, "kernelx");
    ImageParam kernelY(Float(32), 1, "kernely");

    Func gaussiangpu("gaussiangpu"), gaussiangpu_x("gaussiangpu_x");
    Var x("x"), y("y"), c("c");

    Expr e = 0.0f;
    for (int i = 0; i < 5; ++i) {
        e += cast<float>(in(x + i, y, c))  * kernelX(i);
    }
    gaussiangpu_x(x, y, c) = e;

    Expr f = 0.0f;
     for (int j = 0; j < 5; ++j) {
         f += gaussiangpu_x(x, y + j, c) * kernelY(j);
     }
    gaussiangpu(x, y, c) = cast<uint8_t>(f);

    // gaussiangpu_x.reorder(c, x, y);
    gaussiangpu.reorder(c, x, y);

     Var x_inner, y_inner, x_outer, y_outer, tile_index;
// //    gaussiangpu.tile(x, y, x_outer, y_outer, x_inner, y_inner, 8, 8)
// //            .fuse(x_outer, y_outer, tile_index)
// //            .compute_root();
// //            .parallel(x_outer);
    // gaussiangpu_x.compute_root();
 
    // gaussiangpu_x.gpu_tile(x, y, x_inner, y_inner, x_outer, y_outer, 32, 32);
    gaussiangpu.gpu_tile(x, y, x_inner, y_inner, x_outer, y_outer, 32, 32);

    Halide::Target target = Halide::get_host_target();
    target.set_feature(Target::Feature::CUDA, true);

    gaussiangpu.compile_to_object("build/generated_fct_gaussiangpu_ref.o", {in, kernelX, kernelY}, "gaussiangpu_ref", target);

    gaussiangpu.compile_to_lowered_stmt("build/generated_fct_gaussiangpu_ref.txt", {in, kernelX, kernelY}, Text, target);

  return 0;
}
示例#6
0
void compileHalide(const std::vector<Mat> &outputs, Ptr<BackendNode>& node, int targetId)
{
#ifdef HAVE_HALIDE
    CV_Assert(!node.empty());
    Halide::Func& top = node.dynamicCast<HalideBackendNode>()->funcs.back();

    int outW, outH, outC, outN;
    Halide::Var x("x"), y("y"), c("c"), n("n");
    getCanonicalSize(outputs[0].size, &outW, &outH, &outC, &outN);
    top.bound(x, 0, outW).bound(y, 0, outH)
       .bound(c, 0, outC).bound(n, 0, outN);

    Halide::Target target = Halide::get_host_target();
    target.set_feature(Halide::Target::NoAsserts);
    if (targetId == DNN_TARGET_OPENCL)
    {
        target.set_feature(Halide::Target::OpenCL);
    }
    CV_Assert(target.supported());
    top.compile_jit(target);
#endif  // HAVE_HALIDE
}