Skip to content

Commit

Permalink
[Build] Prepare for 0.1 release
Browse files Browse the repository at this point in the history
[Build] Prepare for 0.1 release
  • Loading branch information
jermainewang committed Nov 29, 2019
2 parents 7b07abc + 3a8891c commit 4b305de
Show file tree
Hide file tree
Showing 23 changed files with 522 additions and 203 deletions.
128 changes: 121 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,123 @@
build/
.vscode/
# IDE
.idea

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so
.python-version
__pycache__
*.egg-info

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
.gdb_history
.pytest_cache
MANIFEST
*.whl

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

.DS_Store

# data directory
_download

# CTags & CScope
tags
cscope.*

# Vim
*.swp
*.swo
*.un~
*~
19 changes: 10 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ project(tfdlpack C CXX)

add_definitions(-std=c++11 -fPIC)
include(cmake/util/FindCUDA.cmake)
option(NO_CUDA "Only build TFDLPACK with cpu" OFF)

option(USE_CUDA "Build TF-DLPACK with CUDA support" ON)

if(NOT PYTHON_EXECUTABLE)
execute_process(
Expand Down Expand Up @@ -35,27 +36,27 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 ${TF_CFLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -D_GLIBCXX_USE_CXX11_ABI=0 ${TF_CFLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g3 -ggdb -D_GLIBCXX_USE_CXX11_ABI=0 ${TF_CFLAGS}")

if (NOT NO_CUDA)
if (USE_CUDA)
message(STATUS "Build with CUDA.")
add_definitions(-DTFDLPACK_USE_CUDA)
find_cuda(ON REQUIRED)
if(NOT CUDA_FOUND)
message(FATAL_ERROR "Cannot find CUDA.")
endif()
else()
message(STATUS "Build without CUDA.")
endif()

include_directories(third_party/dlpack/include)

file(GLOB SRC
src/dlpack_op.cc
src/to_dlpack_kernel.cc
src/get_device_and_dtype_kernel.cc
src/from_dlpack_kernel.cc
src/*.cc
)

if (NO_CUDA)
add_library(tfdlpack SHARED ${SRC})
else()
if (USE_CUDA)
cuda_add_library(tfdlpack SHARED ${SRC})
else()
add_library(tfdlpack SHARED ${SRC})
endif()

target_link_libraries(tfdlpack ${TF_LFLAGS})
Expand Down
9 changes: 4 additions & 5 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pipeline {
stage("Lint Check") {
agent {
docker {
image "dgllib/tfdlpack-test"
image "dgllib/tfdlpack-ci-gpu"
args "--runtime nvidia"
}
}
Expand All @@ -30,13 +30,13 @@ pipeline {
stage("Build and Test") {
agent {
docker {
image "dgllib/tfdlpack-test"
image "dgllib/tfdlpack-ci-gpu"
args "--runtime nvidia"
}
}
steps {
init_git()
sh "python -m pip install ."
sh "bash tests/scripts/task_build.sh"
sh "python -m pytest tests"
}
post {
Expand All @@ -45,6 +45,5 @@ pipeline {
}
}
}

}
}
}
38 changes: 18 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,49 @@

Notes: Currently only tested under tensorflow 2.0's eager mode. Implementation details could be found [here](https://github.com/VoVAllen/tf-dlpack/issues/3).


## Install
Set allow growth, otherwise tf would take over whole gpu
```bash
export TF_FORCE_GPU_ALLOW_GROWTH=true
```

### Pip install
Pip install
```bash
pip install git+https://github.com/VoVAllen/tf-dlpack.git
pip install tfdlpack # no cuda
# pip install tfdlpack-gpu # with cuda support
```

### Local install
## Usage
Set allow growth, otherwise tf would take over whole gpu
```bash
python setup.py install
# or
pip install .
export TF_FORCE_GPU_ALLOW_GROWTH=true
```

## Usage
Use `tfdlpack`

```python
import tfdlpack
dl_capsule = tfdlpack.to_dlpack(tf_tensor) # Convert tf tensor to dlpack capsule
tf_tensor = tfdlpack.from_dlpack(dl_capsule) # Convert dlpack capsule to tf tensor
```

## Build and develop locally

## Build Manually

Build
Build plugin library
```
mkdir build
cd build
cmake ..
cmake .. # To build without CUDA, add -DUSE_CUDA=OFF
make -j4
```

so file path is now fixed in `python/tfdlpack/__init__.py`
Need to change manually
Export the library path:
```bash
export TFDLPACK_LIBRARY_PATH=/path/to/tf-dlpack/repo/build
```

And export the python path to `import tfdlpack`
Export python path to `import tfdlpack`
```bash
export PYTHONPATH=/home/ubuntu/dev/tfdlpack/python/:${PYTHONPATH}
export PYTHONPATH=/path/to/tf-dlpack/repo/python/:${PYTHONPATH}
```


## License

[Apache License 2.0](LICENSE)
10 changes: 10 additions & 0 deletions docker/Dockerfile.cpu
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM tensorflow/tensorflow:2.0.0-py3

COPY install/ubuntu_install_core.sh /install/ubuntu_install_core.sh
RUN bash /install/ubuntu_install_core.sh

RUN pip3 install pytest cpplint pylint
RUN pip3 install https://download.pytorch.org/whl/cu100/torch-1.3.1%2Bcu100-cp36-cp36m-linux_x86_64.whl

COPY install/ubuntu_install_conda.sh /install/ubuntu_install_conda.sh
RUN bash /install/ubuntu_install_conda.sh cpu
6 changes: 4 additions & 2 deletions docker/Dockerfile.ci → docker/Dockerfile.gpu
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@

FROM tensorflow/tensorflow:2.0.0-gpu-py3

COPY install/ubuntu_install_core.sh /install/ubuntu_install_core.sh
RUN bash /install/ubuntu_install_core.sh

RUN pip3 install pytest gpustat cpplint pylint
RUN pip3 install https://download.pytorch.org/whl/cu100/torch-1.3.1%2Bcu100-cp36-cp36m-linux_x86_64.whl
RUN pip3 install https://download.pytorch.org/whl/cu100/torch-1.3.1%2Bcu100-cp36-cp36m-linux_x86_64.whl

COPY install/ubuntu_install_conda.sh /install/ubuntu_install_conda.sh
RUN bash /install/ubuntu_install_conda.sh gpu
3 changes: 2 additions & 1 deletion docker/build_docker.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#/usr/bin/sh
# From current directory
docker build -t dgllib/tfdlpack-test -f Dockerfile.ci .
docker build -t dgllib/tfdlpack-ci-cpu -f Dockerfile.cpu .
docker build -t dgllib/tfdlpack-ci-gpu -f Dockerfile.gpu .
25 changes: 25 additions & 0 deletions docker/install/ubuntu_install_conda.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
DEV=$1

if [ $DEV = "cpu" ]; then
TF="tensorflow"
TH="pytorch cpuonly"
else
TF="tensorflow-gpu"
TH="pytorch"
fi

wget -O /tmp/install.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
sh /tmp/install.sh -b

CONDA_PREFIX=$HOME/miniconda3/bin
export PATH=$CONDA_PREFIX:$PATH
for PY_VER in 3.6.4 3.7.0; do
echo "Create conda env for python $PY_VER"
conda create -n $PY_VER -y python=$PY_VER
source activate $PY_VER
conda install -y $TF==2.0 pytest
echo conda install -y $TH -c pytorch
conda install -y $TH -c pytorch
source deactivate
done
Loading

0 comments on commit 4b305de

Please sign in to comment.