0

XlaComputation构建另一个时如何使用XlaComputation?例如,我想构建Add一个计算,我正在尝试这样做

xla::XlaBuilder add_builder("Add");
auto one = ConstantR0(&add_builder, 1);
auto two = ConstantR0(&add_builder, 2);
auto sum = Add(one, two);
add_builder.Build();

xla::XlaBuilder mul_builder("Mul");
auto three = ConstantR0(&mul_builder, 3);
auto res = Mul(sum, three);
mul_builder.Build();

但我明白了

试图获取值而不是处理错误无效的参数:带有句柄 3 的 XlaOp 由构建器“Add”构建,但试图在构建器“Mul”中使用它:

我知道我不应该在另一个计算中使用来自一个构建器的,但是当它对应于该计算的结果XlaOp时,我不明白如何避免这种情况。XlaOp阅读源代码中的以下注释后

// This represents an instruction that has been enqueued using the XlaBuilder.
// This is used to pass to subsequent computations that depends upon the
// instruction as an operand.
class XlaOp {

我猜这仅适用于XlaOps 使用相同的构建器。

4

0 回答 0