Skip to content

Commit

Permalink
fix tensorflow_cc build
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoqing committed Jan 4, 2025
1 parent eb77ec7 commit 3e787ca
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ example-pycxpress:

example-graph: ./sample/saved_model/saved_model.pb
./sample/saved_model/saved_model.pb: ./sample/main.py
env -C $(THIS_MAKEFILE_DIR)/sample $(PYTHON) main.py
env -C $(THIS_MAKEFILE_DIR)/sample --unset=LD_LIBRARY_PATH $(PYTHON) main.py

example-tensorflow: build-sample example-graph
$(call message, Run ./build/sample/sample)
Expand Down Expand Up @@ -75,6 +75,7 @@ else
CMAKE_OPTIONS += -DCMAKE_PREFIX_PATH="$(REPO_DIR)/third_party/protobuf"
endif
endif
CMAKE_OPTIONS += -DUSE_LIBTENSORFLOW_CC=$(USE_LIBTENSORFLOW_CC)

ifneq ($(TYPE),)
BUILD_TYPE_R := Release
Expand Down Expand Up @@ -195,9 +196,11 @@ format-cpp:
#[Format.$(CMAKE)](https://github.com/TheLartians/Format.cmake)
format-cmake:
$(call message, Source CMAKE)
$(CMAKE) -S tests -B build/tests $(CMAKE_OPTIONS)
$(CMAKE) -B build $(CMAKE_OPTIONS)
$(call message, Format)
$(CMAKE) --build build --target fix-format
$(call message, Revert back all those tensorflow proto changes because of clang-format bug)
-git checkout src/TensorflowCpy/proto/tensorflow/

#* Linting
.PHONY: test test-pycxpress test-tfcpy
Expand Down Expand Up @@ -277,5 +280,6 @@ cleanup: pycache-remove dsstore-remove mypycache-remove ipynbcheckpoints-remove
distclean: cleanup
rm -rf $(REPO_DIR)/dist/
rm -rf $(REPO_DIR)/build/
rm -rf $(REPO_DIR)/sample/frozen_graph $(REPO_DIR)/sample/saved_model

FORCE:
14 changes: 7 additions & 7 deletions sample/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ auto main(int argc, char** argv) -> int {

std::string name;

// clang-format off
options.add_options()
("h,help", "Show help")
("v,version", "Print the current version number")
("n,name", "Name to greet", cxxopts::value(name)->default_value("whole_flow"))
;
// clang-format on
options.add_options()
// clang-format off
("h,help", "Show help")
("v,version", "Print the current version number")
("n,name", "Name to greet", cxxopts::value(name)->default_value("whole_flow"))
// clang-format on
;

auto result = options.parse(argc, argv);

Expand Down
6 changes: 3 additions & 3 deletions src/TensorflowCpy/proto/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
find_package(Protobuf CONFIG REQUIRED)

file(GLOB_RECURSE protos CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/**/*.proto")
file(GLOB_RECURSE tf_protos CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/**/*.proto")

add_library(proto-objects OBJECT ${protos})
set(PROTO_BINARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../include")
add_library(proto-objects OBJECT ${tf_protos})
set(PROTO_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
make_directory(${PROTO_BINARY_DIR})

protobuf_generate(
Expand Down
7 changes: 4 additions & 3 deletions src/TensorflowCpy/source/framework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ void wait_for_debugger_attach() {
}

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunknown-warning-option"

#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wpedantic"
#pragma GCC diagnostic ignored "-Wdeprecated-builtins"
Expand Down Expand Up @@ -49,11 +51,10 @@ namespace se = tensorflow_cpy::stream_executor;
# include <tensorflow/core/framework/tensor.h>
# include <tensorflow/core/framework/types.h>
# include <tensorflow/core/platform/env.h>
# include <tensorflow/core/platform/types.h>
# include <tensorflow/core/public/session.h>
# include <tensorflow/core/util/stream_executor_util.h>

# include "tensorflow/core/platform/types.h"

namespace tf = tensorflow;
namespace se = stream_executor;
#endif
Expand Down Expand Up @@ -89,6 +90,7 @@ int tensorflow_cpy::main_whole_flow(int argc, char** argv) {
if (argc == 0) {
return 1;
}
std::string model_path(argv[1]);

// configure session
tf::SessionOptions sessionOption;
Expand Down Expand Up @@ -138,7 +140,6 @@ int tensorflow_cpy::main_whole_flow(int argc, char** argv) {

// load model
tf::SavedModelBundle model;
std::string model_path(argv[1]);
auto status = tf::LoadSavedModel(sessionOption, runOption, model_path, {"serve"}, &model);
if (!status.ok()) {
std::cerr << status.ToString() << std::endl;
Expand Down

0 comments on commit 3e787ca

Please sign in to comment.