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


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

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


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


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