Vengineerの妄想(準備期間)

人生は短いけど、長いです。人生を楽しみましょう!

TensorFlowの中の TFRT

@Vengineerの戯言 : Twitter
SystemVerilogの世界へようこそすべては、SystemC v0.9公開から始まった 

TFRT、TensorFlowの compiler/MLIR のところにも来ていました。

github.com

Lower each TF op to a tfd.delegate_kernel op とあるので、tfd.delegate_kernel って何?

// %1 = "tf.ReadVariableOp"(%arg) {
// dtype = "tfdtype$DT_FLOAT"
// } : (tensor<*x!tf.resource>) -> tensor<10xf32>
//
// would be lowered to
//
// %1:2 = "tfd.delegate_kernel"(%chain_in, %arg) {
// _name = "tf.ReadVariableOp",
// attr0_name = "dtype", attr0_value = "tfdtype$DT_FLOAT"
// } : (!hex.chain, !tfd.tf_tensor) -> (!hex.chain, !tfd.tf_tensor)

どうやら、ここに tfd.delegate_kernel にあるようです。
例としては、こんな感じ。

%out_c, %out_tensor = "tfd.delegate_kernel"(
%in_c, %in1_tensor, %in2_tensor) {
_name = "MatMul",
attr1_name = "transpose_a", attr1_value = "bool$false",
attr2_name = "transpose_b", attr2_value = "bool$false"
} : (!hex.chain, !tfd.tf_tensor, !tfd.tf_tensor) -> (
!hex.chain, !tfd.tf_tensor)

 

また、ここ には、TF dialect の operations を CoreRT ExecuteOP に変換する例。

// Convert TF dialect operations with no side effects to CoreRT ExecuteOp. For
// example,
//
// %0 = "tf.MatMul"(%arg0, %arg1) {transpose_a = false, transpose_b = false} :
// (tensor<3x1xf32>, tensor<1x3xf32>) -> tensor<3x3xf32>
//
// is converted to
//
// %result = corert.executeop(%device)
// "tf.MatMul"(%arg0, %arg1) {transpose_a = false, transpose_b = false} :
// (!corert.tensorhandle, !corert.tensorhandle) -> !corert.tensorhandle
//