Commit 4f4ac2ef by Ting PAN

Fix compiling errors at CPU && OSX support

1 parent 79a52211
......@@ -22,11 +22,11 @@ option(WITH_CUDA_FP16 "Set ON to use FP16" ON)
# Set your 3rdparty
set(3RDPARTY_DIR ${PROJECT_SOURCE_DIR}/../3rdparty)
# set your python "interpreter" if necessary
# Set your python "interpreter" if necessary
# if not, a default interpreter will be used
# here, provide several examples:
# set(PYTHON_EXECUTABLE /usr/bin/python) # Linux, OS
# set(PYTHON_EXECUTABLE /X/anaconda/bin/python) # Linux, Anaconda
# set(PYTHON_EXECUTABLE /usr/bin/python) # Linux & OSX, Builtin Python
# set(PYTHON_EXECUTABLE /X/anaconda/bin/python) # Linux & OSX, Anaconda
# set(PYTHON_EXECUTABLE X:/Anaconda/python) # Win, Anaconda
# Set CUDA compiling architecture
......@@ -37,9 +37,10 @@ set(CUDA_ARCH -gencode arch=compute_30,code=sm_30
-gencode arch=compute_60,code=sm_60
-gencode arch=compute_70,code=sm_70)
# Set CUDNN Library Dir if necessary (Linux Only)
# Set CUDNN Library Dir if necessary (Linux/OSX Only)
# For Win, Recommend to use ``3RDPARTY_DIR/lib``
set(CUDNN_LIBRARY_DIR /usr/local/cuda/lib64)
set(CUDNN_LIBRARY_DIR /usr/local/cuda/lib64) # Linux
# set(CUDNN_LIBRARY_DIR /usr/local/cuda/lib) # OSX
# ---------------- User Config ----------------
......@@ -178,7 +179,7 @@ endif()
if(UNIX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s -w -fPIC -O3 -m64 -std=c++11")
if (WITH_OMP)
if (WITH_OMP AND (NOT APPLE))
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
endif()
......
......@@ -24,6 +24,7 @@
#include <unordered_set>
#include <algorithm>
#include <mutex>
#include <functional>
#include "core/types.h"
#include "protos/dragon.pb.h"
......
......@@ -12,8 +12,6 @@
#ifndef DRAGON_CORE_TENSOR_H_
#define DRAONG_CORE_TENSOR_H_
#include <vector>
#include "core/common.h"
#include "core/mixedmem.h"
......
......@@ -13,20 +13,22 @@
#define DRAGON_UTILS_CUDA_DEVICE_H_
#ifdef WITH_CUDA
#include <cuda_runtime.h>
#include <cublas.h>
#include <curand.h>
#include <cuda.h>
#endif
#ifdef WITH_MPI_NCCL
#include <nccl.h>
#endif // WITH_MPI_NCCL
#endif
#include "core/common.h"
namespace dragon {
#ifdef WITH_CUDA
static const int CUDA_NUM_THREADS = 1024;
// We do have a server with 10 GPUs :-)
#define MAX_GPUS 10
......
......@@ -3,7 +3,7 @@ message(STATUS "Found CXX Module: ${CMAKE_CURRENT_LIST_DIR}")
FILE(GLOB_RECURSE MODULE_FILES *.h *.hpp *.c *.cpp *.cu *.cc)
FILE(GLOB_RECURSE SRC_FILES ../../src/*.c ../../src/*.cpp ../../src/*.cu ../../src/*.cc)
# ---[ complier
# ---[ Target
if (WITH_CUDA)
CUDA_ADD_LIBRARY(${PROJECT_NAME}_cxx SHARED ${MODULE_FILES} ${SRC_FILES})
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_cxx ${CUDA_LIBRARIES} ${CUDA_cublas_LIBRARY} ${CUDA_curand_LIBRARY})
......@@ -11,14 +11,13 @@ else ()
ADD_LIBRARY(${PROJECT_NAME}_cxx SHARED ${MODULE_FILES} ${SRC_FILES})
endif()
# ---[ link basics
# ---[ Linker(Basics)
FILE(GLOB targets ${3RDPARTY_LIBS}/*.so ${3RDPARTY_LIBS}/*.lib)
foreach(target ${targets})
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_cxx ${target})
endforeach()
# ---[ link optional libs
# ---[ Linker(OptionalLibs)
if (UNIX AND WITH_CUDNN)
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_cxx cudnn)
endif()
......@@ -29,15 +28,15 @@ if (UNIX AND WITH_MPI_NCCL)
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_cxx nccl)
endif()
# ---[ link platforms
# ---[ Linker(Platforms)
if(UNIX)
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_cxx protobuf pthread)
endif()
if(WIN32)
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_cxx shlwapi.lib)
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_cxx shlwapi.lib)
endif()
set_target_properties(${PROJECT_NAME}_cxx PROPERTIES OUTPUT_NAME dragon_cxx)
SET_TARGET_PROPERTIES(${PROJECT_NAME}_cxx PROPERTIES OUTPUT_NAME dragon_cxx)
# ---[ install
install (TARGETS ${PROJECT_NAME}_cxx DESTINATION ${PROJECT_BINARY_DIR}/../lib)
\ No newline at end of file
# ---[ Install
INSTALL(TARGETS ${PROJECT_NAME}_cxx DESTINATION ${PROJECT_BINARY_DIR}/../lib)
\ No newline at end of file
......@@ -7,7 +7,7 @@ endif()
FILE(GLOB_RECURSE MODULE_FILES *.h *.hpp *.c *.cpp *.cu *.cc)
FILE(GLOB_RECURSE SRC_FILES ../../src/*.c ../../src/*.cpp ../../src/*.cu ../../src/*.cc)
# ---[ complier
# ---[ Target
if (WITH_CUDA)
CUDA_ADD_LIBRARY(${PROJECT_NAME}_python SHARED ${MODULE_FILES} ${SRC_FILES})
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_python ${CUDA_LIBRARIES} ${CUDA_cublas_LIBRARY} ${CUDA_curand_LIBRARY})
......@@ -15,14 +15,13 @@ else ()
ADD_LIBRARY(${PROJECT_NAME}_python SHARED ${MODULE_FILES} ${SRC_FILES})
endif()
# ---[ link basics
# ---[ Linker(Basics)
FILE(GLOB targets ${3RDPARTY_LIBS}/*.so ${3RDPARTY_LIBS}/*.lib)
foreach(target ${targets})
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_python ${target})
endforeach()
# ---[ link optional libs
# ---[ Linker(OptionalLibs)
if (UNIX AND WITH_CUDNN)
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_python cudnn)
endif()
......@@ -33,15 +32,19 @@ if (UNIX AND WITH_MPI_NCCL)
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_python nccl)
endif()
# ---[ link platforms
# ---[ Linker(Platforms)
if(UNIX)
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_python protobuf pthread)
endif()
if(WIN32)
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_python shlwapi.lib)
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_python shlwapi.lib)
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_python ${PYTHON_LIBRARIES})
endif()
if (APPLE)
SET_TARGET_PROPERTIES(${PROJECT_NAME}_python PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
endif()
set_target_properties(${PROJECT_NAME}_python PROPERTIES OUTPUT_NAME dragon)
SET_TARGET_PROPERTIES(${PROJECT_NAME}_python PROPERTIES OUTPUT_NAME dragon)
# ---[ install
install (TARGETS ${PROJECT_NAME}_python DESTINATION ${PROJECT_BINARY_DIR}/../lib)
\ No newline at end of file
# ---[ Install
INSTALL(TARGETS ${PROJECT_NAME}_python DESTINATION ${PROJECT_BINARY_DIR}/../lib)
\ No newline at end of file
......@@ -14,17 +14,15 @@
#include "dragon.h"
#ifdef WITH_CUDA
inline PyObject* IsCUDADriverSufficientCC(PyObject* self, PyObject* args) {
#ifdef WITH_CUDA
int count;
cudaError_t err = cudaGetDeviceCount(&count);
if (err == cudaErrorInsufficientDriver) return PyBool_FromLong(0);
return PyBool_FromLong(1);
}
#else
CUDA_NOT_COMPILED;
#endif
}
#endif // DRAGON_PYTHON_PY_MPI_H_
\ No newline at end of file
......@@ -14,13 +14,17 @@ def find_packages(root_dir):
if filename == '__init__.py':
packages.append(root_dir)
def find_modules():
dragon_c_lib_win32 = '../lib/dragon.dll'
dragon_c_lib_other = '../lib/libdragon.so'
dragon_c_lib_linux = '../lib/libdragon.so'
dragon_c_lib_darwin = '../lib/libdragon.dylib'
if os.path.exists(dragon_c_lib_win32):
shutil.copy(dragon_c_lib_win32, 'dragon/libdragon.pyd')
elif os.path.exists(dragon_c_lib_other):
shutil.copy(dragon_c_lib_other, 'dragon/libdragon.so')
elif os.path.exists(dragon_c_lib_linux):
shutil.copy(dragon_c_lib_linux, 'dragon/libdragon.so')
elif os.path.exists(dragon_c_lib_darwin):
shutil.copy(dragon_c_lib_darwin, 'dragon/libdragon.so')
else:
print('ERROR: Unable to find modules. built Dragon using CMake.')
sys.exit()
......@@ -32,15 +36,17 @@ def find_resources():
others = []
return c_lib + protos + others
find_packages('dragon')
find_modules()
setup(name = 'dragon',
version='0.2.2.2',
version='0.2.2.3',
description = 'Dragon: A Computation Graph Virtual Machine Based Deep Learning Framework',
url='https://github.com/seetaresearch/Dragon',
author='Ting Pan',
license='BSD 2-Clause',
packages=packages,
package_dir={'dragon': 'dragon'},
package_data={'dragon': find_resources()})
package_data={'dragon': find_resources()})
\ No newline at end of file
......@@ -164,7 +164,9 @@ const Map<string, string> MixedMemory::info() const {
}
s2s["mem_at"] = _state_;
if (cpu_ptr_) s2s["CPU"] = "0";
#ifdef WITH_CUDA
if (cuda_ptr_) s2s["CUDA"] = dragon_cast<string, int>(CUDA_POINTER_DEVICE(cuda_ptr_));
#endif
return s2s;
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!