• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ halide::Func类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中halide::Func的典型用法代码示例。如果您正苦于以下问题:C++ Func类的具体用法?C++ Func怎么用?C++ Func使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: prog01

void prog01()
{
  Halide::Var x;
  Halide::Func init_cond;
  init_cond(x) = 1.0f*x;
  Halide::Image<float_t> input, output;
  input=init_cond.realize(NX);

  Halide::ImageParam inPar(Halide::Float(32), 1, "inPar");
  Halide::Func cell;
  cell(x)=inPar(x)+1;
  
  {
    std::vector<Halide::Argument> arg_vect;
    arg_vect.push_back(Halide::Argument("inPar", true, Halide::Int(32)));
    cell.compile_to_bitcode("stencil-fusion-01.bc", arg_vect, "blur");
  }


  for (int t =0; t < 100000; ++t) {
    inPar.set(input);
    output = cell.realize(NX);
    swap(output,input);
  }

  for (int i = 0; i < NX; ++i) 
    cout << input(i) << " ";
  cout << endl;
}
开发者ID:nushio3,项目名称:practice,代码行数:29,代码来源:stencil-fusion.cpp


示例2: convolution_layer

Halide::Func convolution_layer(Halide::Func input, Halide::Func weights,
    Halide::Func bias, int filter_size, int input_layers, int pool_size) {

    // Convolution
    Halide::Func convolution;
    Halide::Var x, y, z, w;
    Halide::RDom r(0, filter_size, 0, filter_size, 0, input_layers);

    convolution(x, y, z, w) = 0.0f;
    convolution(x, y, z, w) += weights(r.x, r.y, r.z, z) * 
        input(x + r.x, y + r.y, r.z, w);

    // Max pool
    Halide::Func subsample;
    Halide::RDom s(0, pool_size, 0, pool_size);
    subsample(x, y, z, w) = 0.0f;
    subsample(x, y, z, w) = Halide::max(convolution(pool_size * x + s.x,
        pool_size * y + s.y, z, w), subsample(x, y, z, w));

    // Non-linear bias
    Halide::Func biased;
    biased(x, y, z, w) = tanh(subsample(x, y, z, w) + bias(z, 0));

    Halide::Var x_inner, x_outer, y_inner, y_outer;
    biased.parallel(w);
    biased.tile(x, y, x_outer, y_outer, x_inner, y_inner, VECTORS, 2);
    biased.vectorize(x_inner);
    biased.unroll(y_inner);

    return biased;
}
开发者ID:philiptmassey,项目名称:CaffeHalide,代码行数:31,代码来源:conv.cpp


示例3: main

int main(int argc, char **argv) {
		int i, j;
		Halide::Func black;
		Halide::Func white;
    Halide::Var x, y;
		
    black(x, y) = 0;
		white(x, y) = 254;
    
		Halide::Image<int32_t> output1 = black.realize(800, 600);
		Halide::Image<int32_t> output2 = white.realize(800, 600);

    // Save the output for inspection. It should look like a bright parrot.
    save(output1, "input1.png");
		save(output2, "input2.png");
		//Check to see everything is copacetic
		for( i = 0; i < 800; i ++ )
		{
			for( j = 0; j < 600; j ++ )
				if (output2(i, j) != 254 || output1(i, j) != 0)
				{
					printf("Failure! Failed at (%d, %d)\n", i, j);
					return 1;
				}	
		}
    printf("Success!\n");
    return 0;
}
开发者ID:djohnkirby,项目名称:PSC,代码行数:28,代码来源:make_images.cpp


示例4: main

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;
}
开发者ID:halide,项目名称:atom,代码行数:16,代码来源:main.cpp


示例5: _autotune_timing_stub

inline void _autotune_timing_stub(Halide::Func& func) {
    func.compile_jit();
    func.infer_input_bounds(1024,1024);
    timeval t1, t2;
    double rv = 0;
    for (int i = 0; i < 3; i++) {
      gettimeofday(&t1, NULL);
      func.realize(1024,1024);
      gettimeofday(&t2, NULL);
      double t = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec)/1000000.0;
      if(i == 0 || t < rv)
        rv = t;
    }
    printf("{\"time\": %.10f}\n", rv);
    exit(0);
}
开发者ID:jrk,项目名称:halide-autotune-errors,代码行数:16,代码来源:halideerror-1.cpp


示例6: fully_connected_layer

Halide::Func fully_connected_layer(Halide::Func input, Halide::Func weights,
    Halide::Func bias, int size) {

    Halide::Func product;
    Halide::Var x, y, z;
    Halide::RDom r(0, size);

    // Only y = 0 should be used
    product(x, y, z) = 0.0f;
    product(x, y, z) += weights(r.x, x) * input(r.x, y, z);
    product(x, y, z) = tanh(product(x, y, z) + bias(x, 0));

    product.vectorize(x, VECTORS);

    return product;
}
开发者ID:philiptmassey,项目名称:CaffeHalide,代码行数:16,代码来源:conv.cpp


示例7: func_repr

std::string func_repr(const h::Func &func)
{
    std::string repr;
    boost::format f("<halide.Func '%s'>");
    repr = boost::str(f % func.name());
    return repr;
}
开发者ID:sppalkia,项目名称:Halide,代码行数:7,代码来源:Func.cpp


示例8: func_compile_to_file0

void func_compile_to_file0(h::Func &that, const std::string &filename_prefix,
                           const std::vector<h::Argument> &args,
                           const h::Target &target = h::get_target_from_environment())
{
    that.compile_to_file(filename_prefix, args, target);
    return;
}
开发者ID:sppalkia,项目名称:Halide,代码行数:7,代码来源:Func.cpp


示例9: mat

void NamedWindow::showImage2D(Halide::Image<uint8_t> im)
{
	static Halide::Func convert("convertToMat2D");
	static Halide::ImageParam ip(Halide::UInt(8), 2);
	static Halide::Var x, y;

	if (!convert.defined())
	{
		convert(x, y) = ip(x, y);
		convert.vectorize(x, 4).parallel(y, 4);
	}

	ip.set(im);
	cv::Mat mat(im.height(), im.width(), CV_8UC1, cv::Scalar(0));
	convert.realize(Halide::Buffer(Halide::UInt(8), im.width(), im.height(), 0, 0, mat.data));
	cv::imshow(name, mat);
}
开发者ID:yongyi781,项目名称:halide-magnify,代码行数:17,代码来源:NamedWindow.cpp


示例10: func_compile_to_header0

void func_compile_to_header0(h::Func &that, const std::string &filename,
                              const std::vector<h::Argument> &args,
                              const std::string fn_name = "",
                              const h::Target &target = h::get_target_from_environment())
{
    that.compile_to_header(filename, args, fn_name, target);
    return;
}
开发者ID:sppalkia,项目名称:Halide,代码行数:8,代码来源:Func.cpp


示例11: func_compile_to_lowered_stmt0

void func_compile_to_lowered_stmt0(h::Func &that,
                                   const std::string &filename,
                                   const std::vector<h::Argument> &args,
                                   h::StmtOutputFormat fmt = h::Text,
                                   const h::Target &target = h::get_target_from_environment())
{
    that.compile_to_lowered_stmt(filename, args, fmt, target);
    return;
}
开发者ID:sppalkia,项目名称:Halide,代码行数:9,代码来源:Func.cpp


示例12: _autotune_timing_stub

inline void _autotune_timing_stub(Halide::Func& func) {
    func.compile_jit();
    func.infer_input_bounds(AUTOTUNE_N);
    timeval t1, t2;
    double rv = 0;
    const unsigned int timeout = AUTOTUNE_LIMIT;
    alarm(timeout);
    for (int i = 0; i < AUTOTUNE_TRIALS; i++) {
      gettimeofday(&t1, NULL);
      func.realize(AUTOTUNE_N);
      gettimeofday(&t2, NULL);
      alarm(0); // disable alarm
      double t = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec)/1000000.0;
      if(i == 0 || t < rv)
        rv = t;
    }
    printf("{\"time\": %.10f}\n", rv);
    exit(0);
}
开发者ID:jrk,项目名称:halide-autotune-errors,代码行数:19,代码来源:interpolate-simplest-sched1.cpp


示例13: classify

void classify(Halide::Func layer0, Halide::Func *weights, 
    Halide::Func *bias) {

    // Layer 1 -- Convolution
    Halide::Func layer1 = convolution_layer(layer0, weights[0], bias[0],
        FILTER_SIZE, LAYER0_NODES, POOL_SIZE);

    // Layer 2 -- Convolution
    Halide::Func layer2 = convolution_layer(layer1, weights[1], bias[1],
        FILTER_SIZE, LAYER1_NODES, POOL_SIZE);

    // Flatten many feature maps onto a single level for future layers
    Halide::Func flattened = flatten(layer2, REDUCE_IMAGE_SIZE);

    // Layer 3 -- Fully connected hidden layer
    Halide::Func layer3 = fully_connected_layer(flattened, weights[2],
        bias[2], LAYER2_NODES * REDUCE_IMAGE_SIZE * REDUCE_IMAGE_SIZE);

    // Layer 4 -- Fully connected hidden layer
    Halide::Func layer4 = fully_connected_layer(layer3, weights[3],
        bias[3], LAYER3_NODES);

    // Layer 5 -- Logostic Softmax / classification
    Halide::Func layer5 = classification(layer4, LAYER4_NODES);

    layer0.compute_root();
    layer1.compute_root();
    layer2.compute_root();
    flattened.compute_root();
    layer3.compute_root();
    layer4.compute_root();
   
    // Realize to perform computation
    Halide::Image<int> output(1, 1, NUM_IMAGES);
    layer5.realize(output);
}
开发者ID:philiptmassey,项目名称:CaffeHalide,代码行数:36,代码来源:conv.cpp


示例14: _autotune_timing_stub

inline void _autotune_timing_stub(Halide::Func& func) {
    func.compile_jit();

    // TODO: this assumes scalar/non-Tuple outputs - should generalize to a Realization
    Halide::Type out_type = func.output_types()[0];
    buffer_t out_size_buf;
    {
        // Use the Buffer constructor as a helper to set up the buffer_t,
        // but then throw away its allocation which we don't really want.
        Halide::Buffer bufinit(out_type, AUTOTUNE_N);
        out_size_buf = *bufinit.raw_buffer();
        out_size_buf.host = NULL;
    }
    Halide::Buffer out_size(out_type, &out_size_buf);
    assert(out_size.host_ptr() == NULL); // make sure we don't have an allocation

    func.infer_input_bounds(out_size);

    // allocate the real output using the inferred mins + extents
    Halide::Buffer output(  out_type,
                            out_size.extent(0),
                            out_size.extent(1),
                            out_size.extent(2),
                            out_size.extent(3),
                            NULL,
                            "output" );
    output.set_min( out_size.min(0),
                    out_size.min(1),
                    out_size.min(2),
                    out_size.min(3) );

    // re-run input inference on enlarged output buffer
    func.unbind_image_params(); // TODO: iterate to convergence
    func.infer_input_bounds(output);

    timeval t1, t2;
    double rv = 0;
    const unsigned int timeout = AUTOTUNE_LIMIT;
    alarm(timeout);
    for (int i = 0; i < AUTOTUNE_TRIALS; i++) {
      gettimeofday(&t1, NULL);
      func.realize(output);
      gettimeofday(&t2, NULL);
      alarm(0); // disable alarm
      double t = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec)/1000000.0;
      if(i == 0 || t < rv)
        rv = t;
    }
    printf("{\"time\": %.10f}\n", rv);
    exit(0);
}
开发者ID:jrk,项目名称:halide-autotune-errors,代码行数:51,代码来源:interpolate-simple-invalid-schedule2.cpp


示例15: func_compile_jit1

void func_compile_jit1(h::Func &that, const h::Target &target = h::get_target_from_environment())
{
    that.compile_jit(target);
    return;
}
开发者ID:sppalkia,项目名称:Halide,代码行数:5,代码来源:Func.cpp


示例16: func_realize3

void func_realize3(h::Func &that, h::Buffer dst, const h::Target &target = h::Target())
{
    that.realize(dst, target);
    return;
}
开发者ID:sppalkia,项目名称:Halide,代码行数:5,代码来源:Func.cpp


示例17: func_realize2

void func_realize2(h::Func &that, h::Realization dst, const h::Target &target = h::Target())
{
    that.realize(dst, target);
    return;
}
开发者ID:sppalkia,项目名称:Halide,代码行数:5,代码来源:Func.cpp


示例18: func_define_extern1

void func_define_extern1(h::Func &that,const std::string &function_name,
                         const std::vector<h::ExternFuncArgument> &params,
                         const std::vector<h::Type> &output_types,
                         int dimensionality) {
    return that.define_extern(function_name, params, output_types, dimensionality);
}
开发者ID:sppalkia,项目名称:Halide,代码行数:6,代码来源:Func.cpp


示例19: resize_with_halide

int resize_with_halide()
{
    Halide::ImageParam input {Halide::type_of<uint8_t>(), 3};
    
    //_/_/_/ load a source image and repeat its edges
    
    Halide::Func src_image {};
    src_image = Halide::BoundaryConditions::repeat_edge(input);
    
    //_/_/_/ describe algorithm
    Halide::Param<float> src_rows {};
    Halide::Param<float> src_cols {};
    Halide::Param<float> dst_rows {};
    Halide::Param<float> dst_cols {};
    
//    const float sc = 500.0f/4999;//static_cast<float>(src_cols.get()) / dst_cols.get();
//    const float sr = 350.0f/3499;//static_cast<float>(src_rows.get()) / dst_rows.get();
    const auto sc = src_cols / dst_cols;
    const auto sr = src_rows / dst_rows;

    Halide::Var i {};
    Halide::Var j {};
    Halide::Var c {};
    
    auto fj = j * sr;
    auto cj0 = Halide::cast<int>(fj);
    auto cj1 = cj0 + 1;
    auto dj = fj - cj0;
    
    auto fi = i * sc;
    auto ci0 = Halide::cast<int>(fi);
    auto ci1 = ci0 + 1;
    auto di = fi - ci0;
    
    const auto c0 = (1.0f - dj) * (1.0f - di);
    const auto c1 = (1.0f - dj) * di;
    const auto c2 = dj * (1.0f - di);
    const auto c3 = dj * di;

    const auto& src_pixel0 = src_image(ci0, cj0, c);
    const auto& src_pixel1 = src_image(ci1, cj0, c);
    const auto& src_pixel2 = src_image(ci0, cj1, c);
    const auto& src_pixel3 = src_image(ci1, cj1, c);

    Halide::Func resize {};
    resize(i, j, c) = Halide::saturating_cast<uint8_t>(c0 * src_pixel0 + c1 * src_pixel1 + c2 * src_pixel2 + c3 * src_pixel3);

    //_/_/_/ describe scheduling
    
    Halide::Var i_inner, j_inner;
    auto x_vector_size = 64;
    resize.compute_root();
    resize.tile(i, j, i_inner, j_inner, x_vector_size, 4).vectorize(i_inner, 16).parallel(j);

    //_/_/_/ save a static library
    const auto path = "/Users/kumada/Projects/cct_blog/halide/sample_4/sample_4/resize";
    resize.compile_to_static_library(
        path,
        {input, src_rows, src_cols, dst_rows, dst_cols},
        "resize");
    
    return 1;
}
开发者ID:congmonkey,项目名称:cct_blog,代码行数:63,代码来源:halide.cpp


示例20:

h::Realization func_realize1(h::Func &that, int x_size=0, int y_size=0, int z_size=0, int w_size=0,
                             const h::Target &target = h::Target())
{
    return that.realize(x_size, y_size, z_size, w_size, target);
}
开发者ID:sppalkia,项目名称:Halide,代码行数:5,代码来源:Func.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ harness::SpinBarrier类代码示例发布时间:2022-05-31
下一篇:
C++ hal::ScreenConfiguration类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap