Halide学习笔记--05--Realizing Funcs over arbitrary domains

前言

接上, 本文学习Halide lesson_06_realizing Funcs over arbitrary domains
** how to evaluate a Func over a domain that does not start at (0, 0); **

main

//
Func gradient("gradient");
Var x("x"), y("y");
gradient(x, y) = x + y;
gradient.trace_stores();
gradient.realize({8, 8});
//****************************
//This does three things internally:
//1) Generates code that can evaluate gradient over an arbitrary rectangle.
//2) Allocates a new 8 x 8 image.
//3) Runs the generated code to evaluate gradient for all x, y from (0, 0) to (7, 7) and puts the result into the image.
//4) Returns the new image as the result of the realize call.
//Evaluates the Func into an existing image;
Buffer<int> result(8, 8);
gradient.realize(result);
// evaluate gradient over a 5 x 7 rectangle that starts somewhere else -- at position (100, 50).
Buffer<int> shifted(5, 7);  // In the constructor we tell it the size.
shifted.set_min(100, 50);   // Then we tell it the top-left corner.
gradient.realize(shifted);

End

这一章比较简单:
The image 'shifted' stores the value of our Func over a domain that starts at (100, 50), so asking for shifted(0, 0) would in fact read out-of-bounds and probably crash.
Halide only does rectangles.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值