我正在编写Halide代码,并且我已经声明了一个Buffer< double>输入作为我的Halide函数的输入。然而,我不确定这是否有任何意义,因为哈利德tutorial#1说
// Halide does type inference for you. Var objects represent
// 32-bit integers, so the Expr object 'x + y' also represents a
// 32-bit integer, and so 'gradient' defines a 32-bit image, and
// so we got a 32-bit signed integer image out when we call
// 'realize'. Halide types and type-casting rules are equivalent
// to C.我可以毫无问题地运行这个函数,但我不确定是否在我不知道的情况下进行了一些类型转换,将我的double转换为float。
发布于 2019-11-23 11:04:16
问得好!(我们需要更多更好的文档。)
使用double是非常合理的。就像在C中一样(使用你引用的注释中提到的那些C风格的类型提升规则),double <op> float或double <op> int将在中执行计算,并将结果返回为double。
例如,如果你有你的Buffer<double> input,那么:
Func f; Var x, y;
f(x,y) = input(x,y)*2;将f的推断类型类型也设为double。如果您检查作为结果得到的缓冲区的类型,您将注意到这一点。与C一样,在乘法之前,int常量2将被提升为double,并将结果存储为double。每个Func的类型都是由右侧Expr的推断类型给出的,它首先定义它。
类型是自动提升的,永远不会降级。如果你想限制结果的类型,你可以在表达式中使用显式的cast。
这有意义吗?
https://stackoverflow.com/questions/59000433
复制相似问题