Skip to content

Commit

Permalink
Initial commit for DLR
Browse files Browse the repository at this point in the history
  • Loading branch information
AWS Neo committed Jan 27, 2019
1 parent 3dd1b1e commit eaa0465
Show file tree
Hide file tree
Showing 39 changed files with 1,960 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
dist
7 changes: 7 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[submodule "3rdparty/tvm"]
path = 3rdparty/tvm
url = https://github.com/neo-ai/tvm.git
branch = neo-ai
[submodule "3rdparty/neo-ai-treelite"]
path = 3rdparty/neo-ai-treelite
url = https://github.com/neo-ai/neo-ai-treelite.git
1 change: 1 addition & 0 deletions 3rdparty/neo-ai-treelite
Submodule neo-ai-treelite added at 2ada54
1 change: 1 addition & 0 deletions 3rdparty/tvm
Submodule tvm added at cedebf
172 changes: 172 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
cmake_minimum_required (VERSION 3.1)
project(dlr)
#include(cmake/Utils.cmake)

# Use RPATH on Mac OS X as flexible mechanism for locating dependencies
# See https://blog.kitware.com/upcoming-in-cmake-2-8-12-osx-rpath-support/
set(CMAKE_MACOSX_RPATH TRUE)

set(python-build "bp3-python setup.py build")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/build/lib")

# Set BUILD_SHARED_LIBS as option. By default, build shared libraries;
# User can set this to OFF to build static libraries instead.
option(BUILD_SHARED_LIBS "Build shared library" ON)
option(TEST_COVERAGE "C++ test coverage" OFF)

#set_default_configuration_release()

# Compiler flags
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -funroll-loops")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
if(TEST_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
endif()
set(TVM_RUNTIME_LINKER_LIBS "")

set(TVM_SRC "${PROJECT_SOURCE_DIR}/3rdparty/tvm")
set(TREELITE_SRC "${PROJECT_SOURCE_DIR}/3rdparty/neo-ai-treelite")
set(DMLC_CORE_SRC "${TVM_SRC}/3rdparty/dmlc-core")
set(DLPACK_SRC "${TVM_SRC}/3rdparty/dlpack")

include_directories("${TVM_SRC}/include")
include_directories("${TVM_SRC}/src/runtime")
include_directories("${DLPACK_SRC}/include")
include_directories("${DMLC_CORE_SRC}/include")
include_directories("${TREELITE_SRC}/include")
include_directories("${TREELITE_SRC}/runtime/native/include")
include_directories("${PROJECT_SOURCE_DIR}/include")

FILE(GLOB_RECURSE DLR_SRC
"src/*.cc"
${TVM_SRC}/src/runtime/dso_module.cc
${TVM_SRC}/src/runtime/cpu_device_api.cc
${TVM_SRC}/src/contrib/sort/sort.cc
)
FILE(GLOB_RECURSE DLR_INC
"src/*.h"
"include/*.h"
"${TVM_SRC}/src/*.h"
"${TVM_SRC}/include/*.h"
"${TREELITE_SRC}/src/*.h"
"${TREELITE_SRC}/include/*.h"
)

set(USE_CUDA OFF)
set(USE_CUDNN OFF)
set(USE_TENSORRT OFF)

if(USE_CUDA STREQUAL "ON")
message("USING CUDA")
set(USE_CUDA "/usr/local/cuda-9.0")
set(CUDA_TOOLKIT_ROOT_DIR ${USE_CUDA})
message(STATUS "Custom CUDA_PATH=" ${CUDA_TOOLKIT_ROOT_DIR})
set(CUDA_INCLUDE_DIRS ${CUDA_TOOLKIT_ROOT_DIR}/include)
include_directories(${CUDA_INCLUDE_DIRS})
find_library(_CUDA_CUDA_LIBRARY cuda
PATHS ${CUDA_TOOLKIT_ROOT_DIR}
PATH_SUFFIXES lib lib64 lib64/stubs)
message(STATUS "CUDA_CUDA_LIBRARY: " ${_CUDA_CUDA_LIBRARY})
if(_CUDA_CUDA_LIBRARY)
set(CUDA_CUDA_LIBRARY ${_CUDA_CUDA_LIBRARY})
endif()
find_library(CUDA_CUDART_LIBRARY cudart
PATHS ${CUDA_TOOLKIT_ROOT_DIR}
PATH_SUFFIXES lib lib64)
message(STATUS "CUDA_CUDART_LIBRARY: " ${CUDA_CUDART_LIBRARY})
list(APPEND TVM_RUNTIME_LINKER_LIBS ${CUDA_CUDART_LIBRARY})
list(APPEND TVM_RUNTIME_LINKER_LIBS ${CUDA_CUDA_LIBRARY})
list(APPEND TVM_RUNTIME_LINKER_LIBS ${CUDA_NVRTC_LIBRARY})
file(GLOB RUNTIME_CUDA_SRCS ${TVM_SRC}/src/runtime/cuda/*.cc)
list(APPEND DLR_SRC ${RUNTIME_CUDA_SRCS})
endif()
if(USE_CUDNN STREQUAL "ON")
message("USING CUDNN")
set(USE_CUDNN ${USE_CUDA})
set(CUDNN_TOOLKIT_ROOT_DIR ${USE_CUDNN})
message(STATUS "Custom CUDNN_PATH=" ${CUDNN_TOOLKIT_ROOT_DIR})
find_library(CUDA_CUDNN_LIBRARY cudnn
PATH ${CUDNN_TOOLKIT_ROOT_DIR}
PATH_SUFFIXES lib lib64)
if (CUDA_CUDNN_LIBRARY MATCHES "NOTFOUND")
set(CUDA_CUDNN_LIBRARY ${USE_CUDNN}/lib64/libcudnn.so)
endif()
message(STATUS "CUDA_CUDNN_LIBRARY: " ${CUDA_CUDNN_LIBRARY})
list(APPEND TVM_RUNTIME_LINKER_LIBS ${CUDA_CUDNN_LIBRARY})
file(GLOB CONTRIB_CUDNN_SRCS ${TVM_SRC}/src/contrib/cudnn/*.cc)
list(APPEND RUNTIME_SRCS ${CONTRIB_CUDNN_SRCS})
endif()
if(USE_TENSORRT STREQUAL "ON")
message("USING TENSORRT")
set(USE_TENSORRT "/home/ubuntu/TensorRT-4.0.1.6")
set(TENSORRT_ROOT_DIR ${USE_TENSORRT})
message(STATUS "Custom TensorRT path: " ${TENSORRT_ROOT_DIR})
set(TENSORRT_INCLUDE_DIR ${TENSORRT_ROOT_DIR}/include)
set(TENSORRT_LIB_DIR ${TENSORRT_ROOT_DIR}/lib)
include_directories(${TENSORRT_INCLUDE_DIR})
file(GLOB TENSORRT_SRCS ${TVM_SRC}/src/contrib/subgraph/*.cc)
list(APPEND DLR_SRC ${TENSORRT_SRCS})
find_library(TENSORRT_NVINFER_LIBRARY nvinfer
PATH ${TENSORRT_LIB_DIR}
PATH_SUFFIXES lib lib64)
if (TENSORRT_NVINFER_LIBRARY MATCHES "NOTFOUND")
set(TENSORRT_NVINFER_LIBRARY ${USE_TENSORRT}/lib/libnvinfer.so)
endif()
message(STATUS "TENSORRT_NVINFER_LIBRARY: " ${TENSORRT_NVINFER_LIBRARY})
list(APPEND TVM_RUNTIME_LINKER_LIBS ${TENSORRT_NVINFER_LIBRARY})
#set_source_files_properties(src/runtime/graph/graph_runtime.cc PROPERTIES COMPILE_DEFINITIONS "TVM_GRAPH_RUNTIME_TENSORRT")
#set_property(GLOBAL PROPERTY COMPILE_DEFINITIONS "TVM_GRAPH_RUNTIME_TENSORRT")
#set_target_properties(dlr PROPERTIES COMPILE_DEFINITIONS "TVM_GRAPH_RUNTIME_TENSORRT")
add_definitions(-DTVM_GRAPH_RUNTIME_TENSORRT)
endif()

set(MAIN_EXEC "")
FILE(GLOB MAIN_SRC src/*.cc)

add_subdirectory(${TVM_SRC} EXCLUDE_FROM_ALL)
add_subdirectory(${TREELITE_SRC} EXCLUDE_FROM_ALL)
add_library(objdlr OBJECT ${DLR_SRC})


#shared_library
find_package(Threads)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
add_library(dlr SHARED $<TARGET_OBJECTS:objdlr>)
set_target_properties(dlr PROPERTIES LINKER_LANGUAGE CXX)
message(STATUS "TVM_RUNTIME_LINKER_LIBS: " ${TVM_RUNTIME_LINKER_LIBS})
target_link_libraries(dlr treelite_runtime_static tvm_runtime_static ${TVM_RUNTIME_LINKER_LIBS})

set(OPREFIX object_)
add_custom_target(combined_lib
COMMAND mkdir -p ${OPREFIX}tvm_runtime || true && cd ${OPREFIX}tvm_runtime && ar -x ${TVM_RUNTIME}
COMMAND mkdir -p ${OPREFIX}treelite_runtime || true && cd ${OPREFIX}treelite_runtime && ar -x ${TREELITE_RUNTIME}
COMMAND g++ ${OPREFIX}*/*.o -shared -o ${CMAKE_CURRENT_SOURCE_DIR}/libcombined.so
COMMAND rm -rf ${OPREFIX}*
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

# Tests
set(TEST_EXECS "")
file(GLOB TEST_SRCS test/cpp/*.cc)
find_library(GTEST_LIB NAMES libgtest.a gtest)

if(GTEST_LIB)
foreach(__srcpath ${TEST_SRCS})
get_filename_component(__srcname ${__srcpath} NAME)
string(REPLACE ".cc" "" __execname ${__srcname})
add_executable(${__execname} ${__srcpath})
list(APPEND TEST_EXECS ${__execname})
target_link_libraries(${__execname}
dlr ${GTEST_LIB} pthread)
set_target_properties(${__execname} PROPERTIES EXCLUDE_FROM_ALL 1)
set_target_properties(${__execname} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1)
endforeach()
add_custom_target(dlrtest DEPENDS ${TEST_EXECS})
endif()

# Group sources
#auto_source_group("${SOURCES}")
4 changes: 4 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Code of Conduct
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
opensource-codeofconduct@amazon.com with any additional questions or comments.
61 changes: 61 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Contributing Guidelines

Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional
documentation, we greatly value feedback and contributions from our community.

Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
information to effectively respond to your bug report or contribution.


## Reporting Bugs/Feature Requests

We welcome you to use the GitHub issue tracker to report bugs or suggest features.

When filing an issue, please check [existing open](https://github.com/neo-ai/neo-ai/issues), or [recently closed](https://github.com/neo-ai/neo-ai/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), issues to make sure somebody else hasn't already
reported the issue. Please try to include as much information as you can. Details like these are incredibly useful:

* A reproducible test case or series of steps
* The version of our code being used
* Any modifications you've made relevant to the bug
* Anything unusual about your environment or deployment


## Contributing via Pull Requests
Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:

1. You are working against the latest source on the *master* branch.
2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already.
3. You open an issue to discuss any significant work - we would hate for your time to be wasted.

To send us a pull request, please:

1. Fork the repository.
2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
3. Ensure local tests pass.
4. Commit to your fork using clear commit messages.
5. Send us a pull request, answering any default questions in the pull request interface.
6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.

GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
[creating a pull request](https://help.github.com/articles/creating-a-pull-request/).


## Finding contributions to work on
Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/neo-ai/neo-ai/labels/help%20wanted) issues is a great place to start.


## Code of Conduct
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
opensource-codeofconduct@amazon.com with any additional questions or comments.


## Security issue notifications
If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue.


## Licensing

See the [LICENSE](https://github.com/neo-ai/neo-ai/blob/master/LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution.

We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes.
2 changes: 2 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# DLR

Loading

0 comments on commit eaa0465

Please sign in to comment.