Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ find_package(Protobuf CONFIG REQUIRED)
set(protobuf_MODULE_COMPATIBLE TRUE)
find_package(Protobuf CONFIG REQUIRED)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib CACHE PATH "Output directory for static libraries")

include_directories(${Protobuf_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/include)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fPIC")
set (CMAKE_CXX_STANDARD 17)
Expand All @@ -28,7 +30,6 @@ if(NOT LLVM_MLBRIDGE)
find_package(LLVM 10.0.0 REQUIRED CONFIG)
include_directories(${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_DIR})
add_compile_definitions(C_LIBRARY)
endif()

if(MLBRIDGE_DEBUG_MODE)
Expand Down Expand Up @@ -65,25 +66,26 @@ else()
llvm_map_components_to_libnames(llvm_libs support core irreader analysis TransformUtils)

add_library(MLCompilerBridge STATIC tools.cpp)
target_link_libraries(MLCompilerBridge PUBLIC SerDesLib ModelRunnerLib ONNXModelRunnerLib ${llvm_libs})

add_executable(MLCompilerBridgeTest $<TARGET_OBJECTS:MLBridgeCPPTest>)
target_link_libraries(MLCompilerBridgeTest PUBLIC MLCompilerBridge)
target_link_libraries(MLCompilerBridge PUBLIC SerDesLib ModelRunnerLib ONNXModelRunnerLib ${llvm_libs} tf_xla_runtime protobuf::libprotobuf)
set_target_properties(MLCompilerBridge PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set_property(TARGET MLCompilerBridge PROPERTY POSITION_INDEPENDENT_CODE 1)
set_target_properties(MLCompilerBridgeTest PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
install(TARGETS MLCompilerBridgeTest DESTINATION bin)
install(TARGETS MLCompilerBridge DESTINATION lib)


add_library(MLCompilerBridgeC STATIC $<TARGET_OBJECTS:ModelRunnerCWrapper>)
target_link_libraries(MLCompilerBridgeC PUBLIC SerDesCLib ModelRunnerCLib ONNXModelRunnerLib ${llvm_libs})
target_include_directories(MLCompilerBridgeC PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${LLVM_INCLUDE_DIRS})

target_compile_features(MLCompilerBridgeC PRIVATE cxx_std_17)
target_compile_definitions(MLCompilerBridgeC PRIVATE C_LIBRARY)
set_property(TARGET MLCompilerBridgeC PROPERTY POSITION_INDEPENDENT_CODE 1)

set_target_properties(MLCompilerBridge PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set_target_properties(MLCompilerBridgeC PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
install(TARGETS MLCompilerBridgeC DESTINATION lib)
install(TARGETS MLCompilerBridge DESTINATION lib)

add_executable(MLCompilerBridgeTest $<TARGET_OBJECTS:MLBridgeCPPTest>)
target_link_libraries(MLCompilerBridgeTest PUBLIC MLCompilerBridge)
set_target_properties(MLCompilerBridgeTest PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
install(TARGETS MLCompilerBridgeTest DESTINATION bin)

endif(LLVM_MLBRIDGE)

install(DIRECTORY include/ DESTINATION include)
Expand Down
14 changes: 8 additions & 6 deletions MLModelRunner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,24 @@ add_subdirectory(C)
# # python3 -m pip install --upgrade pip && python3 -m pip install --user tf_nightly==2.3.0.dev20200528
# # Then set TENSORFLOW_AOT_PATH to the package install - usually it's ~/.local/lib/python3.7/site-packages/tensorflow
# #
if(LLVM_MLBRIDGE)
set(TENSORFLOW_AOT_PATH "" CACHE PATH "Path to TensorFlow pip install dir")

if (NOT TENSORFLOW_AOT_PATH STREQUAL "")
include_directories(${TENSORFLOW_AOT_PATH}/include)
add_subdirectory(${TENSORFLOW_AOT_PATH}/xla_aot_runtime_src
${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/tf_runtime)
install(TARGETS tf_xla_runtime EXPORT LLVMExports
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime)
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS tf_xla_runtime)
endif()

if(LLVM_MLBRIDGE)
install(TARGETS tf_xla_runtime EXPORT LLVMExports
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime)
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS tf_xla_runtime)
else()
install(TARGETS tf_xla_runtime ARCHIVE DESTINATION ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
endif()
endif()

add_library(ModelRunnerCLib OBJECT PipeModelRunner.cpp)
target_link_libraries(ModelRunnerCLib PUBLIC ModelRunnerCUtils ONNXModelRunnerLib)
target_compile_definitions(ModelRunnerCLib PRIVATE C_LIBRARY)

if(LLVM_MLBRIDGE)
add_llvm_library(ModelRunnerLib PipeModelRunner.cpp)
Expand Down
1 change: 0 additions & 1 deletion SerDes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ else()

add_library(SerDesCLib OBJECT TensorSpec.cpp jsonSerDes.cpp bitstreamSerDes.cpp JSON.cpp)
endif()

target_include_directories(SerDesLib PRIVATE ${TENSORFLOW_AOT_PATH}/include)
1 change: 1 addition & 0 deletions SerDes/TensorSpec.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "SerDes/TensorSpec.h"
#include "MLModelRunner/Utils/JSON.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Debug.h"

#include <array>
Expand Down
27 changes: 27 additions & 0 deletions include/MLModelRunner/TFModelRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,33 @@ template <class TGen> class TFModelRunner final : public MLModelRunner {
std::unique_ptr<TGen> CompiledModel;
};

/// A mock class satisfying the interface expected by ReleaseModeModelRunner for
/// its `TGen` parameter. Useful to avoid conditional compilation complexity, as
/// a compile-time replacement for a real AOT-ed model.
class NoopSavedModelImpl final {
#define NOOP_MODEL_ERRMSG \
"The mock AOT-ed saved model is a compile-time stub and should not be " \
"called."

public:
NoopSavedModelImpl() = default;
int LookupArgIndex(const std::string &) {
llvm_unreachable(NOOP_MODEL_ERRMSG);
}
int LookupResultIndex(const std::string &) {
llvm_unreachable(NOOP_MODEL_ERRMSG);
}
void Run() { llvm_unreachable(NOOP_MODEL_ERRMSG); }
void *result_data(int) { llvm_unreachable(NOOP_MODEL_ERRMSG); }
void *arg_data(int) { llvm_unreachable(NOOP_MODEL_ERRMSG); }
#undef NOOP_MODEL_ERRMSG
};

template <class T> bool isEmbeddedModelEvaluatorValid() { return true; }

template <> inline bool isEmbeddedModelEvaluatorValid<NoopSavedModelImpl>() {
return false;
}
} // namespace MLBridge

#endif // TFMODELRUNNER_H