Skip to content

Commit 48b006c

Browse files
shicongdcslin
authored andcommitted
added dnnl device
1 parent eecd2b3 commit 48b006c

5 files changed

Lines changed: 25 additions & 57 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ OPTION(USE_OPENCL "Use OpenCL" OFF)
6666
OPTION(ENABLE_DIST "Enable distributed training" OFF)
6767
OPTION(DISABLE_WARNINGS "Disable warnings under windows" ON)
6868
OPTION(USE_MODULES "Compile dependent libs as submodules together with singa" OFF)
69+
OPTION(USE_DNNL "Use dnnl libs" OFF)
6970
OPTION(USE_DIST "Use nccl distributed module" OFF)
7071

7172
# TODO: remove all USE_CBLAS in codes

cmake/Dependencies.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ IF(USE_JAVA)
142142
FIND_PACKAGE(SWIG 3.0 REQUIRED)
143143
ENDIF()
144144

145+
IF(USE_DNNL)
146+
FIND_PATH(DNNL_INCLUDE_DIR NAME "dnnl.hpp" PATHS "${CMAKE_CURRENT_SOURCE_DIR}/dnnl/include")
147+
FIND_LIBRARY(DNNL_LIBRARIES NAME "dnnl" PATHS "${CMAKE_CURRENT_SOURCE_DIR}/dnnl/lib")
148+
MESSAGE(STATUS "Found DNNL at ${DNNL_INCLUDE_DIR}")
149+
INCLUDE_DIRECTORIES(${DNNL_INCLUDE_DIR})
150+
LIST(APPEND SINGA_LINKER_LIBS ${DNNL_LIBRARIES})
151+
ENDIF()
145152

146153
IF(USE_DIST)
147154
FIND_PATH(MPI_INCLUDE_DIR NAME "mpi.h" PATHS "/home/ubuntu/mpich-3.3/build/include/")

include/singa/core/common.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
#endif
3535
#endif // USE_CUDA
3636

37+
#ifdef USE_DNNL
38+
#include <dnnl.hpp>
39+
#endif // USE_DNNL
40+
3741

3842
#ifdef USE_OPENCL
3943
#include "singa/utils/opencl_utils.h"
@@ -107,6 +111,11 @@ typedef struct _Context {
107111
#endif
108112
#endif // USE_CUDA
109113

114+
#ifdef USE_DNNL
115+
dnnl::engine *engine;
116+
dnnl::stream *stream;
117+
#endif // USE_DNNL
118+
110119
#ifdef USE_OPENCL
111120
// This stores the context ID of the OpenCL context controlled by ViennaCL.
112121
long vcl_ctx_id;

include/singa/utils/mkldnn_utils.h

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/core/device/cpp_cpu.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,18 @@ std::shared_ptr<Device> defaultDevice=std::make_shared<CppCPU>();
2424

2525
CppCPU::CppCPU() : Device(-1, 1) {
2626
lang_ = kCpp;
27+
#ifdef USE_DNNL
28+
ctx_.engine = new dnnl::engine(dnnl::engine::kind::cpu, 0);
29+
ctx_.stream = new dnnl::engine_stream(*ctx_.engine);
30+
#endif // USE_DNNL
2731
//host_ = nullptr;
2832
}
2933

3034
CppCPU::~CppCPU() {
31-
35+
#ifdef USE_DNNL
36+
delete(ctx_.engine);
37+
delete(ctx_.stream);
38+
#endif // USE_DNNL
3239
};
3340

3441
void CppCPU::SetRandSeed(unsigned seed) {

0 commit comments

Comments
 (0)