Frozen graph is deprecated in TF2. Using Saved model is the new approach. Instead of creating a configuration file and using bazel
in steps 1 and 2 described here, simply use the saved_model_cli
. The final compilation step of creating a binary can be performed using a makefile
instead of bazel
.
- Create a TF saved_model using
tf.saved_model.save
. - Use the
saved_model_cli
to perform XLA AOT compilation.
saved_model_cli aot_compile_cpu \
--dir resnet/1 \
--tag_set serve \
--signature_def_key serving_default \
--output_prefix foo \
--cpp_class Bar
This will create files foo.h
, foo.o
, foo_metadata.o
and foo_makefile.inc
. The file foo.h
has a class named Bar
.
- Create
libtf_xla_runtime.a
. If you installedtensorflow-2.*
as user, then
cd $HOME/.local/lib/python3.x/site-packages/tensorflow/xla_aot_runtime_src
cmake .
make
-
Follow the example here and create a
resnet_test.cc
. -
Use the
makefile
to compileresnet_test.cc
, the generated object filefoo.o
and the librarylibtf_xla_runtime.a
to create the final executable.