Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Porting schedules (except convolutions) to C++ #763

Merged
merged 78 commits into from
Jan 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
0534f82
Ported injective schedules to C++. Added some elementwise ops.
alex-weaver Jan 8, 2018
1ae471f
Fix lint errors
alex-weaver Jan 8, 2018
762bf43
Added reduction ops and schedules
alex-weaver Jan 10, 2018
fa126f6
Fix lint errors
alex-weaver Jan 10, 2018
08901a3
Fix lint errors
alex-weaver Jan 10, 2018
deb80ce
Fix lint errors
alex-weaver Jan 10, 2018
a574ee6
Added transform ops
alex-weaver Jan 10, 2018
6217d8c
Fix lint errors
alex-weaver Jan 10, 2018
8f9f77e
Fix lint errors
alex-weaver Jan 10, 2018
a5f35e9
Added softmax, log_softmax, leaky_relu and flatten ops.
alex-weaver Jan 11, 2018
66ad2a6
Fix lint
alex-weaver Jan 11, 2018
687b432
Fix lint
alex-weaver Jan 11, 2018
9bcf5d5
Added binary_dense, batch_norm_inference, dense, dilate, scale_shift_*,
alex-weaver Jan 12, 2018
0245df5
Fix lint
alex-weaver Jan 12, 2018
2db5040
Fix lint
alex-weaver Jan 12, 2018
321dbb2
Added CUDA schedules for dense, pool and global_pool
alex-weaver Jan 12, 2018
1b538a0
Added extern schedules for generic and CUDA
alex-weaver Jan 12, 2018
98e33a2
Fix lint
alex-weaver Jan 13, 2018
1ff94d3
Added x86 binary schedules
alex-weaver Jan 14, 2018
77c598a
Fix lint
alex-weaver Jan 14, 2018
c7c39dc
Added rocm dense schedule. Added rocBLAS and cuBLAS support to dense ops
alex-weaver Jan 15, 2018
f44cb7f
Added pow ops. Added x86 default and injective schedules
alex-weaver Jan 15, 2018
5a5e220
Fix lint
alex-weaver Jan 15, 2018
350a874
Fix lint
alex-weaver Jan 15, 2018
3558769
Fix lint
alex-weaver Jan 15, 2018
40cb234
Fix lint
alex-weaver Jan 15, 2018
14c7cdf
Fix lint
alex-weaver Jan 15, 2018
50c0480
Merge branch 'master' into master
alex-weaver Jan 15, 2018
a6cda63
Fix indent
alex-weaver Jan 16, 2018
e4b6bc9
Removed schedules directory
alex-weaver Jan 16, 2018
8285cb9
Merge branch 'master' of https://github.com/alex-weaver/tvm
alex-weaver Jan 16, 2018
ffb671c
Changed left_shift, right_shift to operators. Changed pad_value in pa…
alex-weaver Jan 16, 2018
cf9edd4
Fixed usage of pad in nn/pooling.h. Fixed declaration of operator>>
alex-weaver Jan 16, 2018
a040d32
Fixed comments for shift operators
alex-weaver Jan 16, 2018
6f4746b
Added comments to utility functions
alex-weaver Jan 16, 2018
53229f9
Added TOPI C++ library, exporting broadcast_add op
alex-weaver Jan 18, 2018
7ed572c
Fix lint
alex-weaver Jan 18, 2018
d109c0b
Share libinfo.py with TVM
alex-weaver Jan 18, 2018
11c1950
Fix lint
alex-weaver Jan 18, 2018
a786523
Add other broadcast ops
alex-weaver Jan 18, 2018
3218142
Fix lint
alex-weaver Jan 18, 2018
b4da8b2
Fix imports in topi
alex-weaver Jan 18, 2018
6c32832
Fix lib names
alex-weaver Jan 18, 2018
747f8d7
Fixed build issue where windows builds don't apply correct definitions
alex-weaver Jan 18, 2018
d7e3615
Removed TVM_EXPORTS from topi library
alex-weaver Jan 18, 2018
0cc6db8
Attempted CI build fix
alex-weaver Jan 18, 2018
d37e6dc
Add topi lib to tvm_multilib
alex-weaver Jan 18, 2018
24b51cd
Fix Jenkinsfile
alex-weaver Jan 18, 2018
05b9065
Added TOPI build target to Makefile
alex-weaver Jan 19, 2018
4aea500
Fix nn op namespaces.
alex-weaver Jan 19, 2018
5573f1a
Fix lint
alex-weaver Jan 19, 2018
7c84135
Renamed TOPI lib to libtvm_topi
alex-weaver Jan 19, 2018
0e3b9a4
Removed _ffi/base.py
alex-weaver Jan 19, 2018
e10706c
Remove _ffi from topi, now shared with tvm.
alex-weaver Jan 19, 2018
4ad0bb5
Make libtvm_topi loading optional
alex-weaver Jan 19, 2018
e6a6b58
Fix compiler warnings
alex-weaver Jan 19, 2018
c553d18
Fix lint
alex-weaver Jan 19, 2018
ab5003a
Fix lint
alex-weaver Jan 19, 2018
9caea91
Fix lint
alex-weaver Jan 19, 2018
99b7477
Fix build error by making new libs argument to Target optional
alex-weaver Jan 19, 2018
920bd65
Added C++ Target type interop. Added registration of remaining C++ op…
alex-weaver Jan 20, 2018
3f255d0
Fix lint
alex-weaver Jan 20, 2018
5968acd
Fix lint
alex-weaver Jan 20, 2018
6059254
Fix compile error
alex-weaver Jan 20, 2018
78fabd8
Fix compiler warnings
alex-weaver Jan 21, 2018
faf59b5
Fix compiler warnings
alex-weaver Jan 21, 2018
076aca1
Fixed int vector interop. Fixed argmin incorrectly invoking argmax. F…
alex-weaver Jan 21, 2018
b4eee54
Refactored reduce builders
alex-weaver Jan 22, 2018
2fa15c3
Fixed typos in topi.cc. Added basic test.
alex-weaver Jan 22, 2018
f505d04
Fixed padding size error. Added dense, dilate, pooling tests
alex-weaver Jan 22, 2018
8653a0f
Fixed issue where clip would output a different dtype to the input. A…
alex-weaver Jan 22, 2018
050a261
Changed extension type numbers to avoid clash with NNVM
alex-weaver Jan 22, 2018
082691c
Fix lint
alex-weaver Jan 22, 2018
11f764e
Fix compiler warnings
alex-weaver Jan 22, 2018
a507aaf
Removed use of std::vector from the public TOPI API
alex-weaver Jan 24, 2018
83fe698
Fix lint
alex-weaver Jan 24, 2018
408617d
Add TOPI C++ tests to CI
alex-weaver Jan 24, 2018
0dc1af5
Fixed detail namespacing. Improved comments.
alex-weaver Jan 26, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ if(MSVC)
add_definitions(-DWIN32_LEAN_AND_MEAN)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
add_definitions(-DTVM_EXPORTS)
add_definitions(-DHalide_SHARED)
add_definitions(-DHalide_EXPORTS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /bigobj")
Expand Down Expand Up @@ -81,6 +79,10 @@ file(GLOB COMPILER_SRCS
src/op/*.cc
src/schedule/*.cc
)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/topi/include)
file(GLOB TOPI_SRCS
topi/src/*.cc
)
file(GLOB_RECURSE HALIDEIR_SRCS HalideIR/src/*.cpp)
list(APPEND COMPILER_SRCS ${HALIDEIR_SRCS})
file(GLOB RUNTIME_SRCS src/runtime/*.cc)
Expand Down Expand Up @@ -195,8 +197,10 @@ endif()

list(APPEND RUNTIME_SRCS ${GROUP_Include})
add_library(tvm SHARED ${COMPILER_SRCS} ${RUNTIME_SRCS})
add_library(tvm_topi SHARED ${TOPI_SRCS})
add_library(tvm_runtime SHARED ${RUNTIME_SRCS})
target_link_libraries(tvm ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS})
target_link_libraries(tvm_topi tvm ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS})
target_link_libraries(tvm_runtime ${TVM_RUNTIME_LINKER_LIBS})
install(TARGETS tvm_runtime DESTINATION lib${LIB_SUFFIX})
if (INSTALL_DEV)
Expand Down Expand Up @@ -228,3 +232,10 @@ else(INSTALL_DEV)
PATTERN "*.h"
)
endif(INSTALL_DEV)

if(MSVC)
target_compile_definitions(tvm PRIVATE -DHalide_EXPORTS)
target_compile_definitions(tvm_runtime PRIVATE -DHalide_EXPORTS)
target_compile_definitions(tvm PRIVATE -DTVM_EXPORTS)
target_compile_definitions(tvm_runtime PRIVATE -DTVM_EXPORTS)
endif()
7 changes: 4 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
// See documents at https://jenkins.io/doc/book/pipeline/jenkinsfile/

// tvm libraries
tvm_runtime = "lib/libtvm_runtime.so, config.mk"
tvm_lib = "lib/libtvm.so, " + tvm_runtime
topi_lib = "lib/libtopi.so"
tvm_runtime = "lib/libtvm_runtime.so, config.mk, "
tvm_lib = "lib/libtvm.so, " + tvm_runtime + topi_lib
// LLVM upstream lib
tvm_multilib = "lib/libtvm_llvm40.so, lib/libtvm_llvm50.so, lib/libtvm_llvm60.so, " + tvm_runtime
tvm_multilib = "lib/libtvm_llvm40.so, lib/libtvm_llvm50.so, lib/libtvm_llvm60.so, " + tvm_runtime + topi_lib

// command to start a docker container
docker_run = 'tests/ci_build/ci_build.sh'
Expand Down
25 changes: 23 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ OPENCL_SRC = $(wildcard src/runtime/opencl/*.cc)
RPC_SRC = $(wildcard src/runtime/rpc/*.cc)
GRAPH_SRC = $(wildcard src/runtime/graph/*.cc)
RUNTIME_SRC = $(wildcard src/runtime/*.cc)
TOPI_SRC = $(wildcard topi/src/*.cc)

# Objectives
LLVM_BUILD = build/llvm${LLVM_VERSION}
Expand All @@ -69,17 +70,23 @@ RPC_OBJ = $(patsubst src/%.cc, build/%.o, $(RPC_SRC))
GRAPH_OBJ = $(patsubst src/%.cc, build/%.o, $(GRAPH_SRC))
CC_OBJ = $(patsubst src/%.cc, build/%.o, $(CC_SRC)) $(LLVM_OBJ)
RUNTIME_OBJ = $(patsubst src/%.cc, build/%.o, $(RUNTIME_SRC))
TOPI_OBJ = $(patsubst topi/%.cc, build/%.o, $(TOPI_SRC))
CONTRIB_OBJ =

# Deps
ALL_DEP = $(CC_OBJ) $(CONTRIB_OBJ) $(LIB_HALIDEIR)
RUNTIME_DEP = $(RUNTIME_OBJ)
TOPI_DEP = $(TOPI_OBJ)

# Dependency specific rules
ifdef CUDA_PATH
NVCC=$(CUDA_PATH)/bin/nvcc
CFLAGS += -I$(CUDA_PATH)/include
LDFLAGS += -L$(CUDA_PATH)/lib64
ifeq ($(UNAME_S),Darwin)
LDFLAGS += -L$(CUDA_PATH)/lib
else
LDFLAGS += -L$(CUDA_PATH)/lib64
endif
endif

ifeq ($(USE_CUDA), 1)
Expand Down Expand Up @@ -175,10 +182,11 @@ else
JVM_PKG_PROFILE := $(JVM_PKG_PROFILE)-cpu
endif

BUILD_TARGETS ?= lib/libtvm.$(SHARED_LIBRARY_SUFFIX) lib/libtvm_runtime.$(SHARED_LIBRARY_SUFFIX)
BUILD_TARGETS ?= lib/libtvm.$(SHARED_LIBRARY_SUFFIX) lib/libtvm_runtime.$(SHARED_LIBRARY_SUFFIX) lib/libtvm_topi.$(SHARED_LIBRARY_SUFFIX)
all: ${BUILD_TARGETS}
runtime: lib/libtvm_runtime.$(SHARED_LIBRARY_SUFFIX)
web: lib/libtvm_web_runtime.js lib/libtvm_web_runtime.bc
topi: lib/libtvm_topi.$(SHARED_LIBRARY_SUFFIX)

include tests/cpp/unittest.mk

Expand All @@ -203,10 +211,19 @@ build/%.o: src/%.cc
$(CXX) $(CFLAGS) -MM -MT build/$*.o $< >build/$*.d
$(CXX) -c $(CFLAGS) -c $< -o $@

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

lib/libtvm.dylib: $(ALL_DEP) $(RUNTIME_DEP)
@mkdir -p $(@D)
$(CXX) $(CFLAGS) $(FRAMEWORKS) -shared -o $@ $(filter %.o %.a, $^) $(LDFLAGS)

lib/libtvm_topi.dylib: lib/libtvm.so $(TOPI_DEP)
@mkdir -p $(@D)
$(CXX) $(CFLAGS) $(FRAMEWORKS) -L./lib -ltvm -shared -o $@ $(filter %.o %.a, $^) $(LDFLAGS)

lib/libtvm_runtime.dylib: $(RUNTIME_DEP)
@mkdir -p $(@D)
$(CXX) $(CFLAGS) $(FRAMEWORKS) -shared -o $@ $(filter %.o %.a, $^) $(LDFLAGS)
Expand All @@ -215,6 +232,10 @@ lib/libtvm.so: $(ALL_DEP) $(RUNTIME_DEP)
@mkdir -p $(@D)
$(CXX) $(CFLAGS) $(FRAMEWORKS) -shared -o $@ $(filter %.o %.a, $^) $(LDFLAGS)

lib/libtvm_topi.so: lib/libtvm.so $(TOPI_DEP)
@mkdir -p $(@D)
$(CXX) $(CFLAGS) $(FRAMEWORKS) -L./lib -ltvm -shared -o $@ $(filter %.o %.a, $^) $(LDFLAGS)

lib/libtvm_runtime.so: $(RUNTIME_DEP)
@mkdir -p $(@D)
$(CXX) $(CFLAGS) $(FRAMEWORKS) -shared -o $@ $(filter %.o %.a, $^) $(LDFLAGS)
Expand Down
8 changes: 6 additions & 2 deletions include/tvm/build_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,23 @@ struct Target {
std::unordered_set<std::string> keys;
/*! \brief Options for this target */
std::vector<std::string> options;
/*! \brief Set of imported libs */
std::unordered_set<std::string> libs;

Target(const std::string& target_name,
DLDeviceType device_type,
int max_num_threads,
int thread_warp_size,
const std::unordered_set<std::string>& keys,
const std::vector<std::string>& options) :
const std::vector<std::string>& options,
const std::unordered_set<std::string>& libs = {}) :
target_name(target_name),
device_type(device_type),
max_num_threads(max_num_threads),
thread_warp_size(thread_warp_size),
keys(keys),
options(options) {
options(options),
libs(libs) {
}

/*! \return the full device string to pass to codegen::Build */
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ inline int GetVectorBytes(Type dtype) {
/*! \brief a named variable in TVM */
class Var : public HalideIR::VarExpr {
public:
explicit Var(const std::string& name_hint = "v",
EXPORT explicit Var(const std::string& name_hint = "v",
Type t = Int(32)) : VarExpr(name_hint, t) {}
explicit Var(std::shared_ptr<Node> n) : VarExpr(n) {}
explicit Var(VarExpr v) : VarExpr(v) {}
Expand Down
8 changes: 7 additions & 1 deletion include/tvm/ir_operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,19 @@ TVM_DLL Expr min(Expr source, Array<IterVar> axis);
// Unary intrinsic operators
#define TVM_DECLARE_INTRIN_UNARY(OpName) \
inline Expr OpName(Expr x) { \
return ir::Call::make(x.type(), #OpName, {x}, ir::Call::PureExtern); \
return ir::Call::make(x.type(), #OpName, {x}, ir::Call::PureIntrinsic); \
} \

TVM_DECLARE_INTRIN_UNARY(exp);
TVM_DECLARE_INTRIN_UNARY(tanh);
TVM_DECLARE_INTRIN_UNARY(sigmoid);
TVM_DECLARE_INTRIN_UNARY(sqrt);
TVM_DECLARE_INTRIN_UNARY(log);

inline Expr pow(Expr x, Expr y) {
return ir::Call::make(x.type(), "pow", { x, y }, ir::Call::PureIntrinsic);
}

} // namespace tvm

#endif // TVM_IR_OPERATOR_H_
4 changes: 2 additions & 2 deletions include/tvm/ir_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace ir {
* \param vrange The range information about the variable.
* \return Canonicalized statement.
*/
Expr Simplify(Expr expr, Map<Var, Range> vrange = Map<Var, Range>());
EXPORT Expr Simplify(Expr expr, Map<Var, Range> vrange = Map<Var, Range>());

/*!
* \brief Simplify the statement.
Expand Down Expand Up @@ -62,7 +62,7 @@ Expr CanonicalSimplify(Expr expr,
* \param rhs The right operand
* \return The comparison result.
*/
bool Equal(const Expr& lhs, const Expr& rhs);
EXPORT bool Equal(const Expr& lhs, const Expr& rhs);

/*!
* \brief Deep compare lhs and rhs
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ class ExternOpNode : public OperationNode {
v->Visit("inputs", &inputs);
v->Visit("body", &body);
}
static Operation make(std::string name,
EXPORT static Operation make(std::string name,
std::string tag,
Array<Tensor> inputs,
Array<Buffer> input_placeholders,
Expand Down
Loading