Commit ba73e2b8 authored by Jayaram Bobba's avatar Jayaram Bobba Committed by Robert Kimball

Jbobba/halide (#1971)

* Add missing halide dependency

* Bug fix in halide op creation

* Localize halide/llvm to cpu backend

* Added comments

* Pass NGRAPH_HALIDE to tests

* Resolve merge conflicts
parent f85b1b83
......@@ -51,6 +51,11 @@ ExternalProject_Add(
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_INSTALL_PREFIX=${EXTERNAL_PROJECTS_ROOT}/halide
-DHALIDE_SHARED_LIBRARY=OFF
-DWITH_APPS=OFF
-DWITH_TUTORIALS=OFF
-DWITH_TESTS=OFF
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
TMP_DIR "${EXTERNAL_PROJECTS_ROOT}/halide/tmp"
STAMP_DIR "${EXTERNAL_PROJECTS_ROOT}/halide/stamp"
DOWNLOAD_DIR "${EXTERNAL_PROJECTS_ROOT}/halide/download"
......@@ -59,3 +64,51 @@ ExternalProject_Add(
INSTALL_DIR "${EXTERNAL_PROJECTS_ROOT}/halide"
EXCLUDE_FROM_ALL TRUE
)
# Not sure if all of these are used by Halide but we can trim it down later
# if needed
set(HALIDE_LLVM_LINK_LIBS
${SOURCE_DIR}/lib/libLLVMX86AsmParser.a
${SOURCE_DIR}/lib/libLLVMX86CodeGen.a
${SOURCE_DIR}/lib/libLLVMGlobalISel.a
${SOURCE_DIR}/lib/libLLVMSelectionDAG.a
${SOURCE_DIR}/lib/libLLVMAsmPrinter.a
${SOURCE_DIR}/lib/libLLVMDebugInfoCodeView.a
${SOURCE_DIR}/lib/libLLVMX86Desc.a
${SOURCE_DIR}/lib/libLLVMMCDisassembler.a
${SOURCE_DIR}/lib/libLLVMX86Info.a
${SOURCE_DIR}/lib/libLLVMX86AsmPrinter.a
${SOURCE_DIR}/lib/libLLVMX86Utils.a
${SOURCE_DIR}/lib/libLLVMMCJIT.a
${SOURCE_DIR}/lib/libLLVMLineEditor.a
${SOURCE_DIR}/lib/libLLVMInterpreter.a
${SOURCE_DIR}/lib/libLLVMExecutionEngine.a
${SOURCE_DIR}/lib/libLLVMRuntimeDyld.a
${SOURCE_DIR}/lib/libLLVMCodeGen.a
${SOURCE_DIR}/lib/libLLVMTarget.a
${SOURCE_DIR}/lib/libLLVMCoroutines.a
${SOURCE_DIR}/lib/libLLVMipo.a
${SOURCE_DIR}/lib/libLLVMInstrumentation.a
${SOURCE_DIR}/lib/libLLVMVectorize.a
${SOURCE_DIR}/lib/libLLVMScalarOpts.a
${SOURCE_DIR}/lib/libLLVMLinker.a
${SOURCE_DIR}/lib/libLLVMIRReader.a
${SOURCE_DIR}/lib/libLLVMAsmParser.a
${SOURCE_DIR}/lib/libLLVMInstCombine.a
${SOURCE_DIR}/lib/libLLVMTransformUtils.a
${SOURCE_DIR}/lib/libLLVMBitWriter.a
${SOURCE_DIR}/lib/libLLVMAnalysis.a
${SOURCE_DIR}/lib/libLLVMProfileData.a
${SOURCE_DIR}/lib/libLLVMObject.a
${SOURCE_DIR}/lib/libLLVMMCParser.a
${SOURCE_DIR}/lib/libLLVMMC.a
${SOURCE_DIR}/lib/libLLVMBitReader.a
${SOURCE_DIR}/lib/libLLVMCore.a
${SOURCE_DIR}/lib/libLLVMBinaryFormat.a
${SOURCE_DIR}/lib/libLLVMSupport.a
)
add_library(libhalidellvm INTERFACE)
add_dependencies(libhalidellvm ext_halide_llvm)
target_include_directories(libhalidellvm SYSTEM INTERFACE ${EXTERNAL_PROJECTS_ROOT}/halide_llvm/include)
target_link_libraries(libhalidellvm INTERFACE ${HALIDE_LLVM_LINK_LIBS})
......@@ -76,6 +76,9 @@ if (NGRAPH_GPU_ENABLE OR (NGRAPH_CPU_ENABLE AND NOT NGRAPH_DEX_ONLY))
add_dependencies(codegen header_resource)
if (NGRAPH_CPU_ENABLE)
add_dependencies(codegen libmkldnn libeigen)
# --exclude-libs=ALL prevents symbols from statically-linked libraries (LLVM, in this case)
# from being automatically exported
set_property(TARGET codegen APPEND PROPERTY LINK_FLAGS "-Wl,--exclude-libs=ALL")
endif()
target_include_directories(codegen SYSTEM PRIVATE ${CMAKE_BINARY_DIR})
target_link_libraries(codegen PRIVATE libllvm ngraph)
......
......@@ -169,7 +169,8 @@ if (NGRAPH_CPU_ENABLE)
target_compile_definitions(cpu_backend PRIVATE "NGRAPH_HALIDE")
ExternalProject_Get_Property(ext_halide BINARY_DIR)
target_include_directories(cpu_backend SYSTEM PRIVATE ${BINARY_DIR}/include)
target_link_libraries(cpu_backend PRIVATE ${BINARY_DIR}/lib/libHalide.so)
target_link_libraries(cpu_backend PRIVATE ${BINARY_DIR}/lib/libHalide.a libhalidellvm)
add_dependencies(cpu_backend ext_halide)
endif()
if(OPENMP_FOUND)
......@@ -202,7 +203,7 @@ if (NGRAPH_CPU_ENABLE)
# CPU backend picking up the wrong version or even multiple versions of the
# third-party library. -Bsymbolic-functions tells the linker to prefer the internal
# version inside cpu_backend over what is available through the global symbol table
set_property(TARGET cpu_backend APPEND PROPERTY LINK_FLAGS "-Wl,-Bsymbolic-functions")
set_property(TARGET cpu_backend APPEND PROPERTY LINK_FLAGS "-Wl,-Bsymbolic-functions -Wl,--exclude-libs=ALL")
endif()
install(TARGETS cpu_backend LIBRARY DESTINATION ${NGRAPH_INSTALL_LIB})
......
......@@ -111,7 +111,7 @@ namespace ngraph
auto& terminal_func = halide_functions[out_tensor_name];
auto out_size = out[0].get_size();
auto functor = [&, out_size](CPURuntimeContext* ctx) {
auto functor = [&, out_size](CPURuntimeContext* ctx, CPUExecutionContext* ectx) {
for (auto& param : subgraph_params)
{
Halide::Buffer<float> param_buffer(
......
......@@ -116,11 +116,18 @@ bool runtime::cpu::pass::HalideSubgraphExtraction::run_on_function(
}
}
ordered_ops.reverse();
auto subgraph = make_shared<cpu::op::HalideOp>(liveins,
ordered_ops,
function->get_result()->get_element_type(),
function->get_result()->get_shape());
if (ordered_ops.size() > 1)
{
auto subgraph = make_shared<cpu::op::HalideOp>(liveins,
ordered_ops,
function->get_result()->get_element_type(),
function->get_result()->get_shape());
replace_node(function->get_result()->get_argument(0), subgraph);
return true;
replace_node(function->get_result()->get_argument(0), subgraph);
return true;
}
else
{
return false;
}
}
......@@ -197,6 +197,10 @@ if (NGRAPH_TBB_ENABLE)
target_compile_definitions(unit-test PRIVATE NGRAPH_TBB_ENABLE)
endif()
if (NGRAPH_HALIDE)
target_compile_definitions(unit-test PRIVATE "NGRAPH_HALIDE")
endif()
if (NGRAPH_INTERPRETER_ENABLE)
target_compile_definitions(unit-test PRIVATE NGRAPH_INTERPRETER_ENABLE)
target_link_libraries(unit-test PRIVATE interpreter_backend)
......
......@@ -32,9 +32,6 @@
#include "ngraph/pass/manager.hpp"
#include "ngraph/pass/visualize_tree.hpp"
#include "ngraph/runtime/cpu/op/convert_layout.hpp"
#include "ngraph/runtime/cpu/pass/cpu_assignment.hpp"
#include "ngraph/runtime/cpu/pass/cpu_fusion.hpp"
#include "ngraph/runtime/cpu/pass/cpu_layout.hpp"
#include "ngraph/serializer.hpp"
#include "ngraph/util.hpp"
#include "nlohmann/json.hpp"
......@@ -79,6 +76,7 @@ TEST(cpu_test, trivial_in_place_relu)
add->get_outputs().at(0).get_tensor().get_pool_offset());
}
#ifndef NGRAPH_HALIDE
TEST(cpu_test, trivial_in_place_relu_fail)
{
auto A = make_shared<op::Parameter>(element::f32, Shape{16, 1});
......@@ -92,6 +90,7 @@ TEST(cpu_test, trivial_in_place_relu_fail)
ASSERT_NE(relu->get_outputs().at(0).get_tensor().get_pool_offset(),
add->get_outputs().at(0).get_tensor().get_pool_offset());
}
#endif
#ifdef NGRAPH_TBB_ENABLE
TEST(cpu_test, abc_tbb)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment