Skip to content

Commit

Permalink
[Other]Add dlpack (PaddlePaddle#556)
Browse files Browse the repository at this point in the history
add dlpack
  • Loading branch information
heliqi authored Nov 10, 2022
1 parent d4995e5 commit 6bad973
Show file tree
Hide file tree
Showing 38 changed files with 4,181 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ if(BUILD_FASTDEPLOY_PYTHON)
${PYTHON_INCLUDE_DIR})

target_include_directories(${PY_LIBRARY_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/third_party/pybind11/include)
target_include_directories(${PY_LIBRARY_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/third_party/dlpack/include)

if(APPLE)
set_target_properties(${PY_LIBRARY_NAME}
Expand Down
39 changes: 39 additions & 0 deletions third_party/dlpack/.github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CI

on:
push:
branches:
- main

jobs:
test_linux:
name: Deploy Docs
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Configuring Test Environment
run: |
sudo apt-get update
sudo apt-get -y install build-essential doxygen ghp-import
python3 -m pip install -U pip wheel
- name: Installing dependencies
run: |
python3 -m pip install -r doc_requirements.txt
- name: Generating Docs
run: |
make doc
- name: Deploying on GitHub Pages
run: |
touch docs/build/.nojekyll
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
git config --global user.email "dlpack-gh-actions-bot@nomail"
git config --global user.name "dlpack-gh-actions-bot"
ghp-import -m "Generate DLPack website" -b gh-pages docs/build
git push origin gh-pages -f
49 changes: 49 additions & 0 deletions third_party/dlpack/.github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Build Doc

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test_linux:
name: Linux
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Configuring Test Environment
run: |
sudo apt-get update
sudo apt-get -y install build-essential doxygen
python3 -m pip install -U pip wheel
python3 -m pip install cmake ninja
python3 --version
python3 -m pip --version
doxygen --version
make --version
cmake --version
ninja --version
- name: Installing dependencies
run: |
python3 -m pip install -r doc_requirements.txt
- name: Testing CMakeLists.txt
run: |
mkdir build
cd build
cmake .. -G Ninja -DCMAKE_INSTALL_PREFIX=./install -DBUILD_DOCS=ON
ninja
ninja install
- name: Testing Makefile
run: |
make doc
35 changes: 35 additions & 0 deletions third_party/dlpack/.github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
Build:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2

- name: Setup Python
run: |
python3 -m pip install cpplint
- name: Setup@Ubuntu
if: startsWith(matrix.os, 'ubuntu')
run: |
sudo apt-get install -y doxygen wget graphviz unzip
- name: Lint
if: startsWith(matrix.os, 'ubuntu')
run: |
./tests/scripts/task_lint.sh
- name: Test
run: |
./tests/scripts/task_build.sh
32 changes: 32 additions & 0 deletions third_party/dlpack/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app
*~
build
bin
127 changes: 127 additions & 0 deletions third_party/dlpack/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
###
# Set minimum version of CMake. Since command 'project' use
# VERSION sub-option we need at least 3.0.
# Note: If you use 2.6 or 2.4, God kills a kitten. Seriously.
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)

####
# Set variables:
# * PROJECT_NAME
# * PROJECT_VERSION
project(dlpack VERSION 0.6 LANGUAGES C CXX)

#####
# Change the default build type from Debug to Release, while still
# supporting overriding the build type.
#
# The CACHE STRING logic here and elsewhere is needed to force CMake
# to pay attention to the value of these variables.
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type specified; defaulting to CMAKE_BUILD_TYPE=Release.")
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
else(NOT CMAKE_BUILD_TYPE)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message("==========================================================================================")
message(STATUS "Build type: Debug. Performance will be terrible!")
message(STATUS "Add -DCMAKE_BUILD_TYPE=Release to the CMake command line to get an optimized build.")
message("==========================================================================================")
endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
endif(NOT CMAKE_BUILD_TYPE)

####
# Setup the compiler options

# set c++ standard to c++11.
# Note: not working on CMake 2.8. We assume that user has
# a compiler with C++11 support.

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "C++11 support has been enabled by default.")

option(BUILD_DOCS "Set to ON to build documentation" OFF)
option(BUILD_MOCK "Build mock executable" ON)

if(BUILD_DOCS)
add_subdirectory(docs)
endif(BUILD_DOCS)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)

if(BUILD_MOCK)
set(DLPACK_MOCK_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/contrib/mock_main.cc
${CMAKE_CURRENT_SOURCE_DIR}/contrib/mock_c.c)
add_executable(mock ${DLPACK_MOCK_SRCS})
endif()

add_library(dlpack INTERFACE)
add_library(${PROJECT_NAME}::dlpack ALIAS dlpack)

target_include_directories(
dlpack
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/contrib>
)

if(BUILD_MOCK)
target_link_libraries(mock PRIVATE dlpack)
endif()

# Installation (https://github.com/forexample/package-example) {

# Introduce variables:
# * CMAKE_INSTALL_LIBDIR
# * CMAKE_INSTALL_BINDIR
# * CMAKE_INSTALL_INCLUDEDIR
include(GNUInstallDirs)

set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
set(namespace "${PROJECT_NAME}::")

include(CMakePackageConfigHelpers)

# Use:
# * PROJECT_VERSION
write_basic_package_version_file(
"${version_config}" COMPATIBILITY SameMajorVersion
)

# Use:
# * TARGETS_EXPORT_NAME
# * PROJECT_NAME
configure_package_config_file(
"cmake/template/Config.cmake.in"
"${project_config}"
INSTALL_DESTINATION "${config_install_dir}"
)

install(
TARGETS dlpack
EXPORT "${TARGETS_EXPORT_NAME}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)

install(
DIRECTORY include/
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)

install(
FILES "${project_config}" "${version_config}"
DESTINATION "${config_install_dir}"
)

install(
EXPORT "${TARGETS_EXPORT_NAME}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}"
)

# }
Loading

0 comments on commit 6bad973

Please sign in to comment.