Commit 669532d8 authored by Sang Ik Lee's avatar Sang Ik Lee Committed by Scott Cyphers

Allow building nGraph CPU without TBB - r0.25.1 (#3652)

* Allow TBB to be excluded from CPU build.

* Change some CMake scope.

* m_use_tbb can be removed if TBB is not enabled.

* Fix some rebase errors

* Some files do not get definition.

* CPU codegen: Use different pregenerated code if TBB is not built.

* Fix codegen issues.

* Fix bug.

* Use NGRAPH_TBB_ENABLE only for CPU.
parent 0f8ea0eb
...@@ -189,6 +189,9 @@ option(NGRAPH_STATIC_LIB_ENABLE "Enable build nGraph static library" FALSE) ...@@ -189,6 +189,9 @@ option(NGRAPH_STATIC_LIB_ENABLE "Enable build nGraph static library" FALSE)
option(NGRAPH_INTERPRETER_STATIC_LIB_ENABLE "Enable build INTERPRETER backend static library" FALSE) option(NGRAPH_INTERPRETER_STATIC_LIB_ENABLE "Enable build INTERPRETER backend static library" FALSE)
option(NGRAPH_CPU_STATIC_LIB_ENABLE "Enable build CPU backend static library" FALSE) option(NGRAPH_CPU_STATIC_LIB_ENABLE "Enable build CPU backend static library" FALSE)
option(NGRAPH_DYNAMIC_COMPONENTS_ENABLE "Enable dynamic loading of components" TRUE) option(NGRAPH_DYNAMIC_COMPONENTS_ENABLE "Enable dynamic loading of components" TRUE)
if (NGRAPH_CPU_ENABLE)
option(NGRAPH_TBB_ENABLE "Control usage of TBB for CPU backend" TRUE)
endif()
if (NGRAPH_CPU_ENABLE if (NGRAPH_CPU_ENABLE
AND AND
...@@ -268,6 +271,9 @@ NORMALIZE_BOOL(NGRAPH_STATIC_LIB_ENABLE) ...@@ -268,6 +271,9 @@ NORMALIZE_BOOL(NGRAPH_STATIC_LIB_ENABLE)
NORMALIZE_BOOL(NGRAPH_INTERPRETER_STATIC_LIB_ENABLE) NORMALIZE_BOOL(NGRAPH_INTERPRETER_STATIC_LIB_ENABLE)
NORMALIZE_BOOL(NGRAPH_CPU_STATIC_LIB_ENABLE) NORMALIZE_BOOL(NGRAPH_CPU_STATIC_LIB_ENABLE)
NORMALIZE_BOOL(NGRAPH_DYNAMIC_COMPONENTS_ENABLE) NORMALIZE_BOOL(NGRAPH_DYNAMIC_COMPONENTS_ENABLE)
if (NGRAPH_CPU_ENABLE)
NORMALIZE_BOOL(NGRAPH_TBB_ENABLE)
endif()
# Turn off GPU build in 0.25.1 # Turn off GPU build in 0.25.1
set(NGRAPH_GPU_ENABLE FALSE) set(NGRAPH_GPU_ENABLE FALSE)
...@@ -298,6 +304,9 @@ message(STATUS "NGRAPH_STATIC_LIB_ENABLE: ${NGRAPH_STATIC_LIB_ENABLE ...@@ -298,6 +304,9 @@ message(STATUS "NGRAPH_STATIC_LIB_ENABLE: ${NGRAPH_STATIC_LIB_ENABLE
message(STATUS "NGRAPH_INTERPRETER_STATIC_LIB_ENABLE: ${NGRAPH_INTERPRETER_STATIC_LIB_ENABLE}") message(STATUS "NGRAPH_INTERPRETER_STATIC_LIB_ENABLE: ${NGRAPH_INTERPRETER_STATIC_LIB_ENABLE}")
message(STATUS "NGRAPH_CPU_STATIC_LIB_ENABLE: ${NGRAPH_CPU_STATIC_LIB_ENABLE}") message(STATUS "NGRAPH_CPU_STATIC_LIB_ENABLE: ${NGRAPH_CPU_STATIC_LIB_ENABLE}")
message(STATUS "NGRAPH_DYNAMIC_COMPONENTS_ENABLE: ${NGRAPH_DYNAMIC_COMPONENTS_ENABLE}") message(STATUS "NGRAPH_DYNAMIC_COMPONENTS_ENABLE: ${NGRAPH_DYNAMIC_COMPONENTS_ENABLE}")
if (NGRAPH_CPU_ENABLE)
message(STATUS "NGRAPH_TBB_ENABLE: ${NGRAPH_TBB_ENABLE}")
endif()
#----------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------
# Installation logic... # Installation logic...
...@@ -433,10 +442,6 @@ if (NGRAPH_DISTRIBUTED_ENABLE) ...@@ -433,10 +442,6 @@ if (NGRAPH_DISTRIBUTED_ENABLE)
endif() endif()
endif() endif()
if (NOT DEFINED NGRAPH_TBB_ENABLE)
set(NGRAPH_TBB_ENABLE ${NGRAPH_CPU_ENABLE})
endif()
# Since UNIX and APPLE support Bash we can use a Bash script to do the clang-format functions # Since UNIX and APPLE support Bash we can use a Bash script to do the clang-format functions
# This is much faster than the cmake method # This is much faster than the cmake method
if (UNIX OR APPLE) if (UNIX OR APPLE)
......
...@@ -60,6 +60,7 @@ endif() ...@@ -60,6 +60,7 @@ endif()
if(NGRAPH_TBB_ENABLE) if(NGRAPH_TBB_ENABLE)
get_target_property(TBB_INCLUDE_DIR libtbb INTERFACE_INCLUDE_DIRECTORIES) get_target_property(TBB_INCLUDE_DIR libtbb INTERFACE_INCLUDE_DIRECTORIES)
list(APPEND HEADER_SEARCH_DEFINES TBB_HEADERS_PATH="${TBB_INCLUDE_DIR}") list(APPEND HEADER_SEARCH_DEFINES TBB_HEADERS_PATH="${TBB_INCLUDE_DIR}")
set_source_files_properties(compiler.cpp PROPERTIES COMPILE_DEFINITIONS "NGRAPH_TBB_ENABLE")
endif() endif()
set_source_files_properties(compiler.cpp PROPERTIES COMPILE_DEFINITIONS "${HEADER_SEARCH_DEFINES}") set_source_files_properties(compiler.cpp PROPERTIES COMPILE_DEFINITIONS "${HEADER_SEARCH_DEFINES}")
......
...@@ -190,6 +190,11 @@ void codegen::CompilerCore::initialize() ...@@ -190,6 +190,11 @@ void codegen::CompilerCore::initialize()
// Prevent Eigen from using any LGPL3 code // Prevent Eigen from using any LGPL3 code
args.push_back("-DEIGEN_MPL2_ONLY"); args.push_back("-DEIGEN_MPL2_ONLY");
#if defined(NGRAPH_TBB_ENABLE)
// Enable TBB
args.push_back("-DNGRAPH_TBB_ENABLE");
#endif
// Prepare DiagnosticEngine // Prepare DiagnosticEngine
IntrusiveRefCntPtr<DiagnosticOptions> diag_options = new DiagnosticOptions(); IntrusiveRefCntPtr<DiagnosticOptions> diag_options = new DiagnosticOptions();
diag_options->ErrorLimit = 20; diag_options->ErrorLimit = 20;
......
...@@ -178,8 +178,7 @@ if (NGRAPH_CPU_ENABLE) ...@@ -178,8 +178,7 @@ if (NGRAPH_CPU_ENABLE)
target_compile_definitions(cpu_backend PRIVATE "NGRAPH_ENABLE_CPU_CONV_AUTO") target_compile_definitions(cpu_backend PRIVATE "NGRAPH_ENABLE_CPU_CONV_AUTO")
endif() endif()
if(NGRAPH_TBB_ENABLE) if(NGRAPH_TBB_ENABLE)
set_source_files_properties(cpu_external_function.cpp target_compile_definitions(cpu_backend PRIVATE "NGRAPH_TBB_ENABLE")
PROPERTIES COMPILE_DEFINITIONS "NGRAPH_TBB_ENABLE")
endif() endif()
if (NGRAPH_HALIDE) if (NGRAPH_HALIDE)
target_compile_definitions(cpu_backend PRIVATE "NGRAPH_HALIDE") target_compile_definitions(cpu_backend PRIVATE "NGRAPH_HALIDE")
...@@ -210,14 +209,16 @@ if (NGRAPH_CPU_ENABLE) ...@@ -210,14 +209,16 @@ if (NGRAPH_CPU_ENABLE)
target_compile_definitions(cpu_backend PRIVATE CPU_BACKEND_DLL_EXPORTS) target_compile_definitions(cpu_backend PRIVATE CPU_BACKEND_DLL_EXPORTS)
add_dependencies(cpu_backend libmkldnn ext_eigen) add_dependencies(cpu_backend libmkldnn ext_eigen)
target_link_libraries(cpu_backend PUBLIC ngraph libmkldnn libmkl libeigen libtbb) target_link_libraries(cpu_backend PUBLIC ngraph libmkldnn libmkl libeigen)
if (NGRAPH_JSON_ENABLE) if (NGRAPH_JSON_ENABLE)
target_link_libraries(cpu_backend PUBLIC libjson) target_link_libraries(cpu_backend PUBLIC libjson)
endif() endif()
if (NGRAPH_TBB_ENABLE)
target_link_libraries(cpu_backend PUBLIC libtbb)
endif()
if (NOT NGRAPH_DEX_ONLY) if (NOT NGRAPH_DEX_ONLY)
target_link_libraries(cpu_backend PUBLIC codegen) target_link_libraries(cpu_backend PUBLIC codegen)
endif() endif()
target_include_directories(cpu_backend SYSTEM PUBLIC libmkldnn)
if (NOT APPLE AND NOT MSVS) if (NOT APPLE AND NOT MSVS)
# CPU backend uses third-party libraries like Eigen that might be linked in and # CPU backend uses third-party libraries like Eigen that might be linked in and
......
...@@ -14,7 +14,9 @@ ...@@ -14,7 +14,9 @@
// limitations under the License. // limitations under the License.
//***************************************************************************** //*****************************************************************************
#if defined(NGRAPH_TBB_ENABLE)
#include <tbb/tbb_stddef.h> #include <tbb/tbb_stddef.h>
#endif
#include "cpu_backend_visibility.h" #include "cpu_backend_visibility.h"
#include "ngraph/graph_util.hpp" #include "ngraph/graph_util.hpp"
...@@ -40,8 +42,10 @@ runtime::BackendConstructor* runtime::cpu::get_backend_constructor_pointer() ...@@ -40,8 +42,10 @@ runtime::BackendConstructor* runtime::cpu::get_backend_constructor_pointer()
public: public:
std::shared_ptr<runtime::Backend> create(const std::string& /* config */) override std::shared_ptr<runtime::Backend> create(const std::string& /* config */) override
{ {
#if defined(NGRAPH_TBB_ENABLE)
// Force TBB to link to the backend // Force TBB to link to the backend
tbb::TBB_runtime_interface_version(); tbb::TBB_runtime_interface_version();
#endif
return make_shared<runtime::cpu::CPU_Backend>(); return make_shared<runtime::cpu::CPU_Backend>();
} }
}; };
......
...@@ -221,6 +221,7 @@ void runtime::cpu::CPU_CallFrame::setup_runtime_context(Allocator* allocator) ...@@ -221,6 +221,7 @@ void runtime::cpu::CPU_CallFrame::setup_runtime_context(Allocator* allocator)
ctx->states = m_external_function->m_states.data(); ctx->states = m_external_function->m_states.data();
#if defined(NGRAPH_TBB_ENABLE)
if (m_external_function->is_direct_execution() && if (m_external_function->is_direct_execution() &&
std::getenv("NGRAPH_CPU_USE_TBB") != nullptr) std::getenv("NGRAPH_CPU_USE_TBB") != nullptr)
{ {
...@@ -232,6 +233,7 @@ void runtime::cpu::CPU_CallFrame::setup_runtime_context(Allocator* allocator) ...@@ -232,6 +233,7 @@ void runtime::cpu::CPU_CallFrame::setup_runtime_context(Allocator* allocator)
ctx->c = ctx->c =
new tbb::global_control(tbb::global_control::max_allowed_parallelism, parallelism); new tbb::global_control(tbb::global_control::max_allowed_parallelism, parallelism);
} }
#endif
} }
m_num_ctx_available = m_num_ctx; m_num_ctx_available = m_num_ctx;
} }
...@@ -253,6 +255,7 @@ void runtime::cpu::CPU_CallFrame::cleanup_runtime_context() ...@@ -253,6 +255,7 @@ void runtime::cpu::CPU_CallFrame::cleanup_runtime_context()
{ {
delete buffer; delete buffer;
} }
#if defined(NGRAPH_TBB_ENABLE)
if (m_external_function->is_direct_execution() && if (m_external_function->is_direct_execution() &&
std::getenv("NGRAPH_CPU_USE_TBB") != nullptr) std::getenv("NGRAPH_CPU_USE_TBB") != nullptr)
{ {
...@@ -273,6 +276,7 @@ void runtime::cpu::CPU_CallFrame::cleanup_runtime_context() ...@@ -273,6 +276,7 @@ void runtime::cpu::CPU_CallFrame::cleanup_runtime_context()
} }
delete ctx->c; delete ctx->c;
} }
#endif
delete ctx; delete ctx;
} }
m_num_ctx_available = 0; m_num_ctx_available = 0;
......
...@@ -109,10 +109,13 @@ namespace ngraph ...@@ -109,10 +109,13 @@ namespace ngraph
m_thread_pool_devices.push_back( m_thread_pool_devices.push_back(
std::unique_ptr<Eigen::ThreadPoolDevice>(new Eigen::ThreadPoolDevice( std::unique_ptr<Eigen::ThreadPoolDevice>(new Eigen::ThreadPoolDevice(
m_thread_pools[i].get(), num_threads_per_pool))); m_thread_pools[i].get(), num_threads_per_pool)));
#if defined(NGRAPH_TBB_ENABLE)
m_tbb_arenas.emplace_back(1); m_tbb_arenas.emplace_back(1);
#endif
} }
} }
#if defined(NGRAPH_TBB_ENABLE)
void CPUExecutor::execute(CPUKernelFunctor& f, void CPUExecutor::execute(CPUKernelFunctor& f,
CPURuntimeContext* ctx, CPURuntimeContext* ctx,
CPUExecutionContext* ectx, CPUExecutionContext* ectx,
...@@ -128,6 +131,14 @@ namespace ngraph ...@@ -128,6 +131,14 @@ namespace ngraph
f(ctx, ectx); f(ctx, ectx);
} }
} }
#else
void CPUExecutor::execute(CPUKernelFunctor& f,
CPURuntimeContext* ctx,
CPUExecutionContext* ectx)
{
f(ctx, ectx);
}
#endif
CPUExecutor& GetCPUExecutor() CPUExecutor& GetCPUExecutor()
{ {
......
...@@ -26,7 +26,9 @@ ...@@ -26,7 +26,9 @@
#define EIGEN_USE_THREADS #define EIGEN_USE_THREADS
#include <unsupported/Eigen/CXX11/Tensor> #include <unsupported/Eigen/CXX11/Tensor>
#if defined(NGRAPH_TBB_ENABLE)
#include "tbb/task_arena.h" #include "tbb/task_arena.h"
#endif
namespace ngraph namespace ngraph
{ {
...@@ -49,16 +51,24 @@ namespace ngraph ...@@ -49,16 +51,24 @@ namespace ngraph
return *m_thread_pool_devices[id].get(); return *m_thread_pool_devices[id].get();
} }
#if defined(NGRAPH_TBB_ENABLE)
void execute(CPUKernelFunctor& f, void execute(CPUKernelFunctor& f,
CPURuntimeContext* ctx, CPURuntimeContext* ctx,
CPUExecutionContext* ectx, CPUExecutionContext* ectx,
bool use_tbb = false); bool use_tbb = false);
#else
void execute(CPUKernelFunctor& f,
CPURuntimeContext* ctx,
CPUExecutionContext* ectx);
#endif
int get_num_thread_pools() { return m_num_thread_pools; } int get_num_thread_pools() { return m_num_thread_pools; }
int get_num_cores() { return m_num_cores; } int get_num_cores() { return m_num_cores; }
private: private:
std::vector<std::unique_ptr<Eigen::ThreadPool>> m_thread_pools; std::vector<std::unique_ptr<Eigen::ThreadPool>> m_thread_pools;
std::vector<std::unique_ptr<Eigen::ThreadPoolDevice>> m_thread_pool_devices; std::vector<std::unique_ptr<Eigen::ThreadPoolDevice>> m_thread_pool_devices;
#if defined(NGRAPH_TBB_ENABLE)
std::vector<tbb::task_arena> m_tbb_arenas; std::vector<tbb::task_arena> m_tbb_arenas;
#endif
int m_num_thread_pools; int m_num_thread_pools;
int m_num_cores; int m_num_cores;
}; };
......
...@@ -23,9 +23,11 @@ ...@@ -23,9 +23,11 @@
#include <typeinfo> #include <typeinfo>
#include <unordered_map> #include <unordered_map>
#if defined(NGRAPH_TBB_ENABLE)
#define TBB_PREVIEW_FLOW_GRAPH_TRACE 1 #define TBB_PREVIEW_FLOW_GRAPH_TRACE 1
#include <tbb/flow_graph.h> #include <tbb/flow_graph.h>
#endif
#if !defined(NGRAPH_DEX_ONLY) #if !defined(NGRAPH_DEX_ONLY)
#include "ngraph/code_writer.hpp" #include "ngraph/code_writer.hpp"
...@@ -236,7 +238,9 @@ runtime::cpu::CPU_ExternalFunction::CPU_ExternalFunction( ...@@ -236,7 +238,9 @@ runtime::cpu::CPU_ExternalFunction::CPU_ExternalFunction(
: m_function(function) : m_function(function)
, m_release_function(release_function) , m_release_function(release_function)
, m_emit_timing(false) , m_emit_timing(false)
#if defined(NGRAPH_TBB_ENABLE)
, m_use_tbb(std::getenv("NGRAPH_CPU_USE_TBB") != nullptr) , m_use_tbb(std::getenv("NGRAPH_CPU_USE_TBB") != nullptr)
#endif
#if !defined(NGRAPH_DEX_ONLY) #if !defined(NGRAPH_DEX_ONLY)
, m_is_compiled(false) , m_is_compiled(false)
, m_direct_execution((std::getenv("NGRAPH_CODEGEN") == nullptr) || , m_direct_execution((std::getenv("NGRAPH_CODEGEN") == nullptr) ||
...@@ -508,6 +512,7 @@ void runtime::cpu::CPU_ExternalFunction::compile(ngraph::pass::PassConfig& pass_ ...@@ -508,6 +512,7 @@ void runtime::cpu::CPU_ExternalFunction::compile(ngraph::pass::PassConfig& pass_
CodeWriter writer; CodeWriter writer;
writer << "// Generated by the nGraph CPU backend\n"; writer << "// Generated by the nGraph CPU backend\n";
#if defined(NGRAPH_TBB_ENABLE)
if (m_use_tbb) if (m_use_tbb)
{ {
if (runtime::cpu::IsTracingEnabled() || m_emit_timing) if (runtime::cpu::IsTracingEnabled() || m_emit_timing)
...@@ -518,6 +523,8 @@ void runtime::cpu::CPU_ExternalFunction::compile(ngraph::pass::PassConfig& pass_ ...@@ -518,6 +523,8 @@ void runtime::cpu::CPU_ExternalFunction::compile(ngraph::pass::PassConfig& pass_
} }
writer << "#include <tbb/flow_graph.h>"; writer << "#include <tbb/flow_graph.h>";
} }
#endif
writer += writer +=
R"( R"(
#include <cmath> #include <cmath>
...@@ -769,6 +776,7 @@ using namespace ngraph::runtime; ...@@ -769,6 +776,7 @@ using namespace ngraph::runtime;
writer << "bool* t_en = (bool*)" << m_function->get_name() << "_t_en;\n"; writer << "bool* t_en = (bool*)" << m_function->get_name() << "_t_en;\n";
#if defined(NGRAPH_TBB_ENABLE)
if (m_use_tbb) if (m_use_tbb)
{ {
writer << "\n"; writer << "\n";
...@@ -779,6 +787,7 @@ using namespace ngraph::runtime; ...@@ -779,6 +787,7 @@ using namespace ngraph::runtime;
<< " = new tbb::flow::continue_node<tbb::flow::continue_msg> " << " = new tbb::flow::continue_node<tbb::flow::continue_msg> "
"(*(cg_ctx->tbb_graph), [&](const tbb::flow::continue_msg &msg)\n{});\n"; "(*(cg_ctx->tbb_graph), [&](const tbb::flow::continue_msg &msg)\n{});\n";
} }
#endif
// Add inputs to the variable name map // Add inputs to the variable name map
size_t arg_index = 0; size_t arg_index = 0;
...@@ -887,6 +896,7 @@ using namespace ngraph::runtime; ...@@ -887,6 +896,7 @@ using namespace ngraph::runtime;
t_out_attrs, t_out_attrs,
t_in_attrs); t_in_attrs);
} }
#if defined(NGRAPH_TBB_ENABLE)
if (m_use_tbb) if (m_use_tbb)
{ {
writer << "tbb::flow::continue_node<tbb::flow::continue_msg>* " writer << "tbb::flow::continue_node<tbb::flow::continue_msg>* "
...@@ -896,6 +906,7 @@ using namespace ngraph::runtime; ...@@ -896,6 +906,7 @@ using namespace ngraph::runtime;
"(*(cg_ctx->tbb_graph), [&](const tbb::flow::continue_msg &msg)\n{\n"; "(*(cg_ctx->tbb_graph), [&](const tbb::flow::continue_msg &msg)\n{\n";
writer.indent++; writer.indent++;
} }
#endif
if (runtime::cpu::IsTracingEnabled() && m_function->get_name() == m_function_name) if (runtime::cpu::IsTracingEnabled() && m_function->get_name() == m_function_name)
{ {
writer << "start_ts = cpu::Clock::now();\n"; writer << "start_ts = cpu::Clock::now();\n";
...@@ -1015,14 +1026,17 @@ using namespace ngraph::runtime; ...@@ -1015,14 +1026,17 @@ using namespace ngraph::runtime;
<< "(std::chrono::duration_cast<cpu::Timescale>(cpu::Clock::now() - " << "(std::chrono::duration_cast<cpu::Timescale>(cpu::Clock::now() - "
"start_ts)).count();\n"; "start_ts)).count();\n";
} }
#if defined(NGRAPH_TBB_ENABLE)
if (m_use_tbb) if (m_use_tbb)
{ {
writer.indent--; writer.indent--;
writer << "});\n"; writer << "});\n";
} }
#endif
} }
} }
#if defined(NGRAPH_TBB_ENABLE)
if (m_use_tbb) if (m_use_tbb)
{ {
writer << "\n"; writer << "\n";
...@@ -1058,6 +1072,7 @@ using namespace ngraph::runtime; ...@@ -1058,6 +1072,7 @@ using namespace ngraph::runtime;
<< "->try_put(tbb::flow::continue_msg());\n"; << "->try_put(tbb::flow::continue_msg());\n";
writer << "try { cg_ctx->tbb_graph->wait_for_all(); } catch(...) { throw; }\n"; writer << "try { cg_ctx->tbb_graph->wait_for_all(); } catch(...) { throw; }\n";
} }
#endif
writer << "ctx->first_iteration = false;\n"; writer << "ctx->first_iteration = false;\n";
writer.indent--; writer.indent--;
...@@ -1350,12 +1365,14 @@ void runtime::cpu::CPU_ExternalFunction::build(ngraph::pass::PassConfig& pass_co ...@@ -1350,12 +1365,14 @@ void runtime::cpu::CPU_ExternalFunction::build(ngraph::pass::PassConfig& pass_co
return; return;
} }
#if defined(NGRAPH_TBB_ENABLE)
if (m_use_tbb && (runtime::cpu::IsTracingEnabled() || m_emit_timing)) if (m_use_tbb && (runtime::cpu::IsTracingEnabled() || m_emit_timing))
{ {
throw ngraph_error( throw ngraph_error(
"CPU Backend: Tracing and performance breakdowns might not be accurate with TBB " "CPU Backend: Tracing and performance breakdowns might not be accurate with TBB "
"enabled due to concurrent graph execution"); "enabled due to concurrent graph execution");
} }
#endif
// reference all the builders for static library // reference all the builders for static library
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE #ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
...@@ -1717,6 +1734,7 @@ void runtime::cpu::CPU_ExternalFunction::build(ngraph::pass::PassConfig& pass_co ...@@ -1717,6 +1734,7 @@ void runtime::cpu::CPU_ExternalFunction::build(ngraph::pass::PassConfig& pass_co
} }
auto functor = functors.begin(); auto functor = functors.begin();
#if defined(NGRAPH_TBB_ENABLE)
if (m_use_tbb) if (m_use_tbb)
{ {
// Build the flow graph // Build the flow graph
...@@ -1824,6 +1842,7 @@ void runtime::cpu::CPU_ExternalFunction::build(ngraph::pass::PassConfig& pass_co ...@@ -1824,6 +1842,7 @@ void runtime::cpu::CPU_ExternalFunction::build(ngraph::pass::PassConfig& pass_co
} }
} }
else else
#endif
{ {
static const auto ddebug = std::getenv("NGRAPH_DEX_DEBUG"); static const auto ddebug = std::getenv("NGRAPH_DEX_DEBUG");
if (ddebug != nullptr) if (ddebug != nullptr)
...@@ -1930,7 +1949,11 @@ void runtime::cpu::CPU_ExternalFunction::build(ngraph::pass::PassConfig& pass_co ...@@ -1930,7 +1949,11 @@ void runtime::cpu::CPU_ExternalFunction::build(ngraph::pass::PassConfig& pass_co
m_is_built = true; m_is_built = true;
#if defined(NGRAPH_TBB_ENABLE)
if (m_release_function && !m_use_tbb) if (m_release_function && !m_use_tbb)
#else
if (m_release_function)
#endif
{ {
release_function(); release_function();
} }
......
...@@ -262,7 +262,9 @@ namespace ngraph ...@@ -262,7 +262,9 @@ namespace ngraph
bool m_release_function; bool m_release_function;
bool m_emit_timing; bool m_emit_timing;
#if defined(NGRAPH_TBB_ENABLE)
bool m_use_tbb; bool m_use_tbb;
#endif
#if !defined(NGRAPH_DEX_ONLY) #if !defined(NGRAPH_DEX_ONLY)
bool m_is_compiled; bool m_is_compiled;
#endif #endif
......
...@@ -20,11 +20,13 @@ ...@@ -20,11 +20,13 @@
#include <cstdint> #include <cstdint>
#include <set> #include <set>
#if defined(NGRAPH_TBB_ENABLE)
#define TBB_PREVIEW_GLOBAL_CONTROL 1 #define TBB_PREVIEW_GLOBAL_CONTROL 1
#define TBB_PREVIEW_FLOW_GRAPH_TRACE 1 #define TBB_PREVIEW_FLOW_GRAPH_TRACE 1
#include <tbb/flow_graph.h> #include <tbb/flow_graph.h>
#include <tbb/global_control.h> #include <tbb/global_control.h>
#include <tbb/task_scheduler_init.h> #include <tbb/task_scheduler_init.h>
#endif
#include "ngraph/op/experimental/compiled_kernel.hpp" #include "ngraph/op/experimental/compiled_kernel.hpp"
#ifdef NGRAPH_MLIR_ENABLE #ifdef NGRAPH_MLIR_ENABLE
...@@ -66,8 +68,10 @@ namespace ngraph ...@@ -66,8 +68,10 @@ namespace ngraph
std::vector<mkldnn::primitive*> mkldnn_primitives; std::vector<mkldnn::primitive*> mkldnn_primitives;
std::vector<AlignedBuffer*> memory_buffers; std::vector<AlignedBuffer*> memory_buffers;
std::vector<char*> mkldnn_workspaces; std::vector<char*> mkldnn_workspaces;
#if defined(NGRAPH_TBB_ENABLE)
tbb::flow::graph* G; tbb::flow::graph* G;
tbb::global_control* c; tbb::global_control* c;
#endif
State* const* states; State* const* states;
std::set<size_t> breakpoints; std::set<size_t> breakpoints;
size_t pc; size_t pc;
......
...@@ -23,11 +23,16 @@ ...@@ -23,11 +23,16 @@
R"( R"(
struct CPURuntimeContextCG struct CPURuntimeContextCG
{ {
#if defined(NGRAPH_TBB_ENABLE)
std::unique_ptr<tbb::flow::graph> tbb_graph; std::unique_ptr<tbb::flow::graph> tbb_graph;
std::unique_ptr<tbb::global_control> tbb_gcontrol; std::unique_ptr<tbb::global_control> tbb_gcontrol;
CPURuntimeContextCG() { init_tbb(); init_mkldnn_primitives();} CPURuntimeContextCG() { init_tbb(); init_mkldnn_primitives();}
~CPURuntimeContextCG() { cleanup_tbb(); cleanup_mkldnn_primitives();} ~CPURuntimeContextCG() { cleanup_tbb(); cleanup_mkldnn_primitives();}
#else
CPURuntimeContextCG() { init_mkldnn_primitives();}
~CPURuntimeContextCG() { cleanup_mkldnn_primitives();}
#endif
std::vector<mkldnn::primitive*> mkldnn_primitives; std::vector<mkldnn::primitive*> mkldnn_primitives;
std::vector<char*> mkldnn_workspaces; std::vector<char*> mkldnn_workspaces;
...@@ -57,6 +62,7 @@ struct CPURuntimeContextCG ...@@ -57,6 +62,7 @@ struct CPURuntimeContextCG
private: private:
#if defined(NGRAPH_TBB_ENABLE)
inline void init_tbb() inline void init_tbb()
{ {
if (std::getenv("NGRAPH_CPU_USE_TBB")) if (std::getenv("NGRAPH_CPU_USE_TBB"))
...@@ -86,6 +92,7 @@ private: ...@@ -86,6 +92,7 @@ private:
} }
} }
} }
#endif
void init_mkldnn_primitives(); void init_mkldnn_primitives();
......
...@@ -382,7 +382,7 @@ if (NGRAPH_PLAIDML_ENABLE) ...@@ -382,7 +382,7 @@ if (NGRAPH_PLAIDML_ENABLE)
endif() endif()
if (NGRAPH_TBB_ENABLE) if (NGRAPH_TBB_ENABLE)
target_compile_definitions(unit-test PRIVATE NGRAPH_TBB_ENABLE) target_compile_definitions(unit-test PRIVATE "NGRAPH_TBB_ENABLE")
endif() endif()
if (NGRAPH_HALIDE) if (NGRAPH_HALIDE)
......
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