Unverified Commit c3eef5ab authored by Sang Ik Lee's avatar Sang Ik Lee Committed by GitHub

Allow CPU build without TBB. (#2160)

* Allow TBB to be excluded from CPU build.

* Change some CMake scope.

* m_use_tbb can be removed if TBB is not enabled.

* Revert some CMake linkage scope as it breaks unit test.

* Migrate changes from #3652.
parent e2bddf19
...@@ -194,6 +194,9 @@ option(NGRAPH_INTERPRETER_STATIC_LIB_ENABLE "Enable build INTERPRETER backend as ...@@ -194,6 +194,9 @@ option(NGRAPH_INTERPRETER_STATIC_LIB_ENABLE "Enable build INTERPRETER backend as
option(NGRAPH_CPU_STATIC_LIB_ENABLE "Enable build CPU backend as a static library" FALSE) option(NGRAPH_CPU_STATIC_LIB_ENABLE "Enable build CPU backend as a static library" FALSE)
option(NGRAPH_PLAIDML_STATIC_LIB_ENABLE "Enable build PlaidML backend as a static library" FALSE) option(NGRAPH_PLAIDML_STATIC_LIB_ENABLE "Enable build PlaidML backend as a 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()
message(STATUS "NGRAPH_CXX_STANDARD: ${NGRAPH_CXX_STANDARD}") message(STATUS "NGRAPH_CXX_STANDARD: ${NGRAPH_CXX_STANDARD}")
message(STATUS "NGRAPH_UNIT_TEST_ENABLE: ${NGRAPH_UNIT_TEST_ENABLE}") message(STATUS "NGRAPH_UNIT_TEST_ENABLE: ${NGRAPH_UNIT_TEST_ENABLE}")
...@@ -296,6 +302,9 @@ message(STATUS "NGRAPH_INTERPRETER_STATIC_LIB_ENABLE: ${NGRAPH_INTERPRETER_STATI ...@@ -296,6 +302,9 @@ message(STATUS "NGRAPH_INTERPRETER_STATIC_LIB_ENABLE: ${NGRAPH_INTERPRETER_STATI
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_PLAIDML_STATIC_LIB_ENABLE: ${NGRAPH_PLAIDML_STATIC_LIB_ENABLE}") message(STATUS "NGRAPH_PLAIDML_STATIC_LIB_ENABLE: ${NGRAPH_PLAIDML_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...
......
...@@ -53,6 +53,7 @@ list(APPEND HEADER_SEARCH_DEFINES NGRAPH_HEADERS_PATH="${NGRAPH_INCLUDE_PATH}") ...@@ -53,6 +53,7 @@ list(APPEND HEADER_SEARCH_DEFINES NGRAPH_HEADERS_PATH="${NGRAPH_INCLUDE_PATH}")
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
#if defined(NGRAPH_USE_LEGACY_MKLDNN) #if defined(NGRAPH_USE_LEGACY_MKLDNN)
args.push_back("-DNGRAPH_USE_LEGACY_MKLDNN"); args.push_back("-DNGRAPH_USE_LEGACY_MKLDNN");
#endif #endif
......
...@@ -210,9 +210,8 @@ if (NGRAPH_CPU_ENABLE) ...@@ -210,9 +210,8 @@ if (NGRAPH_CPU_ENABLE)
if (NGRAPH_ENABLE_CPU_CONV_AUTO) if (NGRAPH_ENABLE_CPU_CONV_AUTO)
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")
...@@ -247,13 +246,15 @@ if (NGRAPH_CPU_ENABLE) ...@@ -247,13 +246,15 @@ if (NGRAPH_CPU_ENABLE)
endforeach() endforeach()
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()
if (NGRAPH_TBB_ENABLE)
target_link_libraries(cpu_backend PUBLIC libtbb)
endif() endif()
if (NOT NGRAPH_DEX_ONLY) if (NOT NGRAPH_DEX_ONLY)
target_link_libraries(cpu_backend PUBLIC codegen) target_link_libraries(cpu_backend PRIVATE codegen)
endif() endif()
target_include_directories(cpu_backend SYSTEM PUBLIC libmkldnn) target_include_directories(cpu_backend SYSTEM PUBLIC libmkldnn)
......
...@@ -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"
...@@ -42,7 +44,10 @@ extern "C" CPU_BACKEND_API void ngraph_register_cpu_backend() ...@@ -42,7 +44,10 @@ extern "C" CPU_BACKEND_API void ngraph_register_cpu_backend()
static bool is_initialized = false; static bool is_initialized = false;
if (!is_initialized) if (!is_initialized)
{ {
#if defined(NGRAPH_TBB_ENABLE)
// Force TBB to link to the backend
tbb::TBB_runtime_interface_version(); tbb::TBB_runtime_interface_version();
#endif
ngraph::runtime::cpu::register_builders(); ngraph::runtime::cpu::register_builders();
is_initialized = true; is_initialized = true;
} }
......
...@@ -226,7 +226,7 @@ void runtime::cpu::CPU_CallFrame::setup_runtime_context(Allocator* allocator) ...@@ -226,7 +226,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)
{ {
...@@ -238,6 +238,7 @@ void runtime::cpu::CPU_CallFrame::setup_runtime_context(Allocator* allocator) ...@@ -238,6 +238,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;
} }
...@@ -272,6 +273,7 @@ void runtime::cpu::CPU_CallFrame::cleanup_runtime_context() ...@@ -272,6 +273,7 @@ void runtime::cpu::CPU_CallFrame::cleanup_runtime_context()
delete ctx->scratchpad_buffer; delete ctx->scratchpad_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)
{ {
...@@ -292,6 +294,7 @@ void runtime::cpu::CPU_CallFrame::cleanup_runtime_context() ...@@ -292,6 +294,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"
...@@ -234,7 +236,9 @@ runtime::cpu::CPU_ExternalFunction::CPU_ExternalFunction( ...@@ -234,7 +236,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) ||
...@@ -503,6 +507,7 @@ void runtime::cpu::CPU_ExternalFunction::compile(ngraph::pass::PassConfig& pass_ ...@@ -503,6 +507,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)
...@@ -513,6 +518,8 @@ void runtime::cpu::CPU_ExternalFunction::compile(ngraph::pass::PassConfig& pass_ ...@@ -513,6 +518,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>
...@@ -770,6 +777,7 @@ using namespace ngraph::runtime; ...@@ -770,6 +777,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";
...@@ -780,6 +788,7 @@ using namespace ngraph::runtime; ...@@ -780,6 +788,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;
...@@ -1016,14 +1025,17 @@ using namespace ngraph::runtime; ...@@ -1016,14 +1025,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";
...@@ -1059,6 +1071,7 @@ using namespace ngraph::runtime; ...@@ -1059,6 +1071,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--;
...@@ -1373,12 +1386,14 @@ void runtime::cpu::CPU_ExternalFunction::build(ngraph::pass::PassConfig& pass_co ...@@ -1373,12 +1386,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
// stream writer to dump the debug manifest for the DEX // stream writer to dump the debug manifest for the DEX
static const string s_debug_dir = "cpu_codegen"; static const string s_debug_dir = "cpu_codegen";
...@@ -1735,6 +1750,7 @@ void runtime::cpu::CPU_ExternalFunction::build(ngraph::pass::PassConfig& pass_co ...@@ -1735,6 +1750,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
...@@ -1842,6 +1858,7 @@ void runtime::cpu::CPU_ExternalFunction::build(ngraph::pass::PassConfig& pass_co ...@@ -1842,6 +1858,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)
...@@ -1949,7 +1966,11 @@ void runtime::cpu::CPU_ExternalFunction::build(ngraph::pass::PassConfig& pass_co ...@@ -1949,7 +1966,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();
} }
......
...@@ -264,7 +264,9 @@ namespace ngraph ...@@ -264,7 +264,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,14 @@ ...@@ -20,11 +20,14 @@
#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
...@@ -69,8 +72,10 @@ namespace ngraph ...@@ -69,8 +72,10 @@ namespace ngraph
std::vector<mkldnn::memory::desc*> mkldnn_scratchpad_mds; std::vector<mkldnn::memory::desc*> mkldnn_scratchpad_mds;
AlignedBuffer* scratchpad_buffer; AlignedBuffer* scratchpad_buffer;
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;
......
...@@ -74,11 +74,16 @@ R"( ...@@ -74,11 +74,16 @@ 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::memory*> mkldnn_memories; std::vector<mkldnn::memory*> mkldnn_memories;
std::vector<mkldnn::primitive*> mkldnn_primitives; std::vector<mkldnn::primitive*> mkldnn_primitives;
...@@ -270,6 +275,7 @@ struct CPURuntimeContextCG ...@@ -270,6 +275,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"))
...@@ -299,6 +305,7 @@ private: ...@@ -299,6 +305,7 @@ private:
} }
} }
} }
#endif
void init_mkldnn_primitives(); void init_mkldnn_primitives();
......
...@@ -426,7 +426,7 @@ if (NGRAPH_PLAIDML_ENABLE) ...@@ -426,7 +426,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