Skip to content

Commit

Permalink
[BUILD/TEST] Formalize tests, project structure (#14)
Browse files Browse the repository at this point in the history
* [BUILD/TEST] Formalize tests, project structure

* update cmake to reflect version
  • Loading branch information
tqchen authored Jun 2, 2017
1 parent 29f826a commit 36e5738
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
*.app
*~
build
mock
bin
46 changes: 46 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
sudo: false

dist: trusty

language: cpp

os:
- linux
- osx

osx_image: xcode8

env:
# code analysis
- TASK=all_test

branches:
only:
- master

matrix:
exclude:
- os: osx
env: TASK=lint

# dependent apt packages
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- doxygen
- wget
- graphviz
- unzip

install:
- source tests/travis/setup.sh

script:
- tests/travis/run_test.sh

cache:
directories:
- ${HOME}/.cache/usr

10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
# Set variables:
# * PROJECT_NAME
# * PROJECT_VERSION
project(dlpack VERSION 0.0.0 LANGUAGES C CXX)
project(dlpack VERSION 0.1.0 LANGUAGES C CXX)

#####
# Change the default build type from Debug to Release, while still
Expand Down Expand Up @@ -48,8 +48,12 @@ if(BUILD_DOCS)
endif(BUILD_DOCS)

set(DLPACK_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)

list(APPEND DLPACK_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/contrib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
include_directories(${DLPACK_INCLUDE_DIR})
add_executable(mock ${CMAKE_CURRENT_SOURCE_DIR}/src/mock.cc)

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})


31 changes: 21 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
.PHONY: clean all test doc
.PHONY: clean all test doc lint

all: mock
all: bin/mock

LDFLAGS =
CFLAGS = -std=c++11 -Wall -O3 -Iinclude
CFLAGS = -Wall -O3 -Iinclude -Icontrib
CXXFLAGS = -std=c++11 $(CFLAGS)

SRC = $(wildcard src/*.cc src/*/*.cc src/*/*/*.cc)
ALL_OBJ = $(patsubst src/%.cc, build/%.o, $(SRC))
SRC = $(wildcard contrib/*.cc contrib/*.c)
ALL_CXX_OBJ = $(patsubst contrib/%.cc, build/%.o, $(SRC))
ALL_C_OBJ = $(patsubst contrib/%.c, build/%.o, $(SRC))
ALL_OBJ = $(ALL_CC_OBJ) $(ALL_CXX_OBJ)

doc:
doxygen docs/Doxyfile

build/%.o: src/%.cc
lint:
./tests/scripts/task_lint.sh

build/%.o: contrib/%.cc
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) -MM -MT build/$*.o $< >build/$*.d
$(CXX) -c $(CXXFLAGS) -c $< -o $@

build/%.o: contrib/%.c
@mkdir -p $(@D)
$(CXX) $(CFLAGS) -MM -MT build/$*.o $< >build/$*.d
$(CXX) -c $(CFLAGS) -c $< -o $@
$(CC) $(CFLAGS) -MM -MT build/$*.o $< >build/$*.d
$(CC) -c $(CFLAGS) -c $< -o $@

mock: $(ALL_OBJ)
bin/mock: $(ALL_OBJ)
@mkdir -p $(@D)
$(CXX) $(CFLAGS) -o $@ $(filter %.o %.a, $^) $(LDFLAGS)
$(CXX) $(CXXFLAGS) -o $@ $(filter %.o %.a, $^) $(LDFLAGS)

clean:
$(RM) -rf build */*/*/*~ */*.o */*/*.o */*/*/*.o */*.d */*/*.d */*/*/*.d
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DLPack Change Log
=================

This file records the changes in DLPack in reverse chronological order.

## v0.1
- Finalize DLTensor structure
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# DLPack

[![Build Status](https://travis-ci.org/dmlc/dlpack.svg?branch=master)](https://travis-ci.org/dmlc/dlpack)

RFC for common tensor and operator guidelines in deep learning systems.
Started by [this issue](https://github.com/dmlc/mxnet/issues/4735)

Expand All @@ -13,6 +15,11 @@ This enables:

We do not intend to implement of Tensor and Ops, but instead use this as common interface to reuse tensor and ops across frameworks.

## Project Structure
There are two major components so far
- include: stablized headers
- contrib: in progress unstable libraries

## Credit
The initial interface so far base on discussions between
@soumith @piiswrong @Yangqing @naibaf7 @bhack @edgarriba @tqchen
Expand Down
14 changes: 7 additions & 7 deletions include/dlpack/dlpackcpp.h → contrib/dlpack/dlpackcpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
* \file dlpackcpp.h
* \brief Example C++ wrapper of DLPack
*/
#ifndef DLPACKCPP_H_
#define DLPACKCPP_H_
#ifndef DLPACK_DLPACKCPP_H_
#define DLPACK_DLPACKCPP_H_

#include <dlpack/dlpack.h>

#include <cstdint> // for int64_t etc
#include <cstdlib> // for free()
Expand All @@ -13,8 +15,6 @@
#include <numeric>
#include <vector>

#include "./dlpack.h"

namespace dlpack {

// Example container wrapping of DLTensor.
Expand Down Expand Up @@ -47,8 +47,8 @@ class DLTContainer {
shape_ = shape;
int64_t sz = std::accumulate(std::begin(shape), std::end(shape),
int64_t(1), std::multiplies<int64_t>());
// Note: this won't work on OSX.
handle_.data = aligned_alloc(256, sz);
int ret = posix_memalign(&handle_.data, 256, sz);
if (ret != 0) throw std::bad_alloc();
handle_.shape = &shape_[0];
handle_.ndim = static_cast<uint32_t>(shape.size());
}
Expand All @@ -62,4 +62,4 @@ class DLTContainer {
};

} // namespace dlpack
#endif // DLPACKCPP_H_
#endif // DLPACK_DLPACKCPP_H_
7 changes: 7 additions & 0 deletions contrib/mock_c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright by contributors
// This file is used to make sure the package is C compatible
#include <dlpack/dlpack.h>

int GetNDim(DLTensor *t) {
return t->ndim;
}
1 change: 1 addition & 0 deletions src/mock.cc → contrib/mock_main.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright by contributors
#include <dlpack/dlpack.h>
#include <dlpack/dlpackcpp.h>

Expand Down
16 changes: 11 additions & 5 deletions include/dlpack/dlpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
* \file dlpack.h
* \brief The common header of DLPack.
*/
#ifndef DLPACK_H_
#define DLPACK_H_
#ifndef DLPACK_DLPACK_H_
#define DLPACK_DLPACK_H_

#ifdef __cplusplus
#define DLPACK_EXTERN_C extern "C"
#else
#define DLPACK_EXTERN_C
#endif

/*! \brief The current version of dlpack */
#define DLPACK_VERSION 010

/*! \brief DLPACK_DLL prefix for windows */
#ifdef _WIN32
#ifdef DLPACK_EXPORTS
Expand All @@ -26,7 +29,9 @@
#include <stdint.h>
#include <stddef.h>

DLPACK_EXTERN_C {
#ifdef __cplusplus
extern "C" {
#endif
/*!
* \brief The device type in DLContext.
*/
Expand Down Expand Up @@ -106,6 +111,7 @@ typedef struct {
/*! \brief The offset in bytes to the beginning pointer to data */
uint64_t byte_offset;
} DLTensor;

#ifdef __cplusplus
} // DLPACK_EXTERN_C
#endif // DLPACK_H_
#endif
#endif // DLPACK_DLPACK_H_
6 changes: 6 additions & 0 deletions tests/scripts/task_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
make || exit -1
mkdir -p build
cd build
cmake .. || exit -1
make || exit -1
23 changes: 23 additions & 0 deletions tests/scripts/task_lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
mkdir -p bin

if [ ! -f bin/lint.py ]; then
echo "Grab linter ..."
wget https://raw.githubusercontent.com/dmlc/dmlc-core/master/scripts/lint.py
mv lint.py bin/lint.py
fi

echo "Check codestyle of c++ code..."
python bin/lint.py dlpack cpp include contrib

echo "Check doxygen generation..."
make doc 2>log.txt
(cat log.txt| grep -v ENABLE_PREPROCESSING |grep -v "unsupported tag") > logclean.txt
echo "---------Error Log----------"
cat logclean.txt
echo "----------------------------"
(cat logclean.txt|grep warning) && exit -1
(cat logclean.txt|grep error) && exit -1
rm logclean.txt
rm log.txt
echo "All checks passed..."
12 changes: 12 additions & 0 deletions tests/travis/run_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
if [ ${TASK} == "lint" ] || [ ${TASK} == "all_test" ]; then
if [ ! ${TRAVIS_OS_NAME} == "osx" ]; then
./tests/scripts/task_lint.sh || exit -1
fi
fi

if [ ${TASK} == "build" ] || [ ${TASK} == "all_test" ]; then
./tests/scripts/task_build.sh || exit -1
fi

echo "All travis test passed.."
5 changes: 5 additions & 0 deletions tests/travis/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if [ ${TASK} == "lint" ] || [ ${TASK} == "all_test" ]; then
if [ ! ${TRAVIS_OS_NAME} == "osx" ]; then
pip install --user cpplint
fi
fi

0 comments on commit 36e5738

Please sign in to comment.