Skip to content

Commit

Permalink
[REFACTOR] topi -> tvm/topi (apache#6186)
Browse files Browse the repository at this point in the history
This PR migrates the topi library as a sub namespace of tvm.
  • Loading branch information
tqchen authored and Trevor Morris committed Aug 26, 2020
1 parent 01cbec1 commit 2841574
Show file tree
Hide file tree
Showing 485 changed files with 1,181 additions and 1,456 deletions.
18 changes: 2 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ file(GLOB DATATYPE_SRCS src/target/datatype/*.cc)
list(APPEND COMPILER_SRCS ${DATATYPE_SRCS})

file(GLOB TOPI_SRCS
topi/src/*.cc
src/topi/*.cc
)

file(GLOB RUNTIME_SRCS
Expand Down Expand Up @@ -356,7 +356,7 @@ else()
set(CMAKE_CUDA_STANDARD 14)
endif()

add_library(tvm SHARED ${COMPILER_SRCS} ${RUNTIME_SRCS})
add_library(tvm SHARED ${COMPILER_SRCS} ${RUNTIME_SRCS} ${TOPI_SRCS})
add_library(tvm_topi SHARED ${TOPI_SRCS})
add_library(tvm_runtime SHARED ${RUNTIME_SRCS})
add_library(tvm_runtime_static STATIC ${RUNTIME_SRCS})
Expand Down Expand Up @@ -419,15 +419,6 @@ if (HIDE_PRIVATE_SYMBOLS AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
target_link_libraries(tvm_runtime ${HIDE_SYMBOLS_LINKER_FLAGS})
endif()

# Related headers
target_include_directories(
tvm
PUBLIC "topi/include")
target_include_directories(
tvm_topi
PUBLIC "topi/include")


# Tests
set(TEST_EXECS "")
file(GLOB TEST_SRCS tests/cpp/*.cc)
Expand Down Expand Up @@ -472,11 +463,6 @@ if (INSTALL_DEV)
FILES_MATCHING
PATTERN "*.h"
)
install(
DIRECTORY "topi/include/." DESTINATION "include"
FILES_MATCHING
PATTERN "*.h"
)
install(
DIRECTORY "3rdparty/dlpack/include/." DESTINATION "include"
FILES_MATCHING
Expand Down
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,12 @@ $(OUTPUTDIR)/libtvm_web_runtime.js: $(OUTPUTDIR)/libtvm_web_runtime.bc
# Lint scripts
cpplint:
python3 3rdparty/dmlc-core/scripts/lint.py vta cpp vta/include vta/src
python3 3rdparty/dmlc-core/scripts/lint.py topi cpp topi/include;
python3 3rdparty/dmlc-core/scripts/lint.py tvm cpp \
include src \
examples/extension/src examples/graph_executor/src

pylint:
python3 -m pylint python/tvm --rcfile=$(ROOTDIR)/tests/lint/pylintrc
python3 -m pylint topi/python/topi --rcfile=$(ROOTDIR)/tests/lint/pylintrc
python3 -m pylint vta/python/vta --rcfile=$(ROOTDIR)/tests/lint/pylintrc

jnilint:
Expand Down
2 changes: 0 additions & 2 deletions apps/android_camera/app/src/main/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ LOCAL_LDFLAGS := -L$(SYSROOT)/usr/lib/ -llog
LOCAL_C_INCLUDES := $(ROOT_PATH)/include \
$(ROOT_PATH)/3rdparty/dlpack/include \
$(ROOT_PATH)/3rdparty/dmlc-core/include \
$(ROOT_PATH)/3rdparty/HalideIR/src \
$(ROOT_PATH)/topi/include

LOCAL_MODULE = tvm4j_runtime_packed

Expand Down
3 changes: 1 addition & 2 deletions apps/android_deploy/app/src/main/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ LOCAL_LDFLAGS := -L$(SYSROOT)/usr/lib/ -llog

LOCAL_C_INCLUDES := $(ROOT_PATH)/include \
$(ROOT_PATH)/3rdparty/dlpack/include \
$(ROOT_PATH)/3rdparty/dmlc-core/include \
$(ROOT_PATH)/topi/include
$(ROOT_PATH)/3rdparty/dmlc-core/include

LOCAL_MODULE = tvm4j_runtime_packed

Expand Down
3 changes: 1 addition & 2 deletions apps/android_rpc/app/src/main/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ LOCAL_LDFLAGS := -L$(SYSROOT)/usr/lib/ -llog

LOCAL_C_INCLUDES := $(ROOT_PATH)/include \
$(ROOT_PATH)/3rdparty/dlpack/include \
$(ROOT_PATH)/3rdparty/dmlc-core/include \
$(ROOT_PATH)/topi/include
$(ROOT_PATH)/3rdparty/dmlc-core/include

LOCAL_MODULE = tvm4j_runtime_packed

Expand Down
4 changes: 1 addition & 3 deletions apps/sgx/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ fn main() {
concat!(
mf_dir!("/../../python"),
":",
mf_dir!("/../../nnvm/python"),
":",
mf_dir!("/../../topi/python")
mf_dir!("/../../nnvm/python")
),
)
.output()
Expand Down
11 changes: 1 addition & 10 deletions topi/README.md → apps/topi_recipe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<!--- specific language governing permissions and limitations -->
<!--- under the License. -->

# TOPI: TVM Operator Inventory
# TOPI Recipe: TVM Operator Optimization Recipes

TOPI is the operator collection library for TVM intended at sharing the effort of crafting
and optimizing tvm generated kernels. The goal:
Expand All @@ -24,11 +24,6 @@ and optimizing tvm generated kernels. The goal:
- Give common primitives for fused op creation.
- Provide commonly used schedules under each architectures

## Organization
- [include](include) C++ library, header only
- [python](python) python library
- [recipe](recipe) Recipe collections containing useful operator examples.

## Guidelines
- Use numpy-style naming convention for known ops
- Seperate operator declaration from schedule when possible.
Expand All @@ -39,10 +34,6 @@ and optimizing tvm generated kernels. The goal:
- Data layout aware, if not specified in argument or in function, assume NCHW by default.


## Testcase
- Add testcases to testout the schedule and dataflow in the TOPI workflow
- Only do correctness testing without attaching compiler flags and only run it once.

## Performance Tuning Workflow
Since TVM is work in progress, some optimization might not be perfect.
One quick way I find useful is to do codegen plus manual modification.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from tvm.contrib import nvcc
import numpy as np

import topi
from tvm import topi


TASK = "reduce_map"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
from scipy import signal
from tvm.contrib import nvcc

import topi
from topi.util import get_const_tuple
from topi.cuda.depthwise_conv2d import schedule_depthwise_conv2d_nchw, schedule_depthwise_conv2d_nhwc
from tvm import topi
from tvm.topi.util import get_const_tuple
from tvm.topi.cuda.depthwise_conv2d import schedule_depthwise_conv2d_nchw, schedule_depthwise_conv2d_nhwc

TASK = "depthwise_conv2d"
USE_MANUAL_CODE = False
Expand Down Expand Up @@ -118,7 +118,7 @@ def check_device(device):
print("average time cost of 1000 runs (depthwise_conv2d + scale_shift) = %g us" % (tcost_2*1e6))
print("average time cost of 1000 runs (depthwise_conv2d + scale_shift + relu) = %g us" % (tcost_3*1e6))
# correctness
depthwise_conv2d_scipy = topi.testing.depthwise_conv2d_python_nchw(input_np, filter_np, stride=[stride_h, stride_w], padding=padding)
depthwise_conv2d_scipy = tvm.topi.testing.depthwise_conv2d_python_nchw(input_np, filter_np, stride=[stride_h, stride_w], padding=padding)
scale_shift_scipy = np.zeros(shape=get_const_tuple(ScaleShift.shape))
for c in range(in_channel * channel_multiplier):
scale_shift_scipy[:,c,:,:] = depthwise_conv2d_scipy[:,c,:,:] * scale_np[c] + shift_np[c]
Expand Down Expand Up @@ -207,7 +207,7 @@ def check_device(device):
print("average time cost of 1000 runs (depthwise_conv2d + scale_shift) = %g us" % (tcost_2*1e6))
print("average time cost of 1000 runs (depthwise_conv2d + scale_shift + relu) = %g us" % (tcost_3*1e6))
# correctness
depthwise_conv2d_scipy = topi.testing.depthwise_conv2d_python_nhwc(input_np, filter_np, stride=[stride_h, stride_w], padding=padding)
depthwise_conv2d_scipy = tvm.topi.testing.depthwise_conv2d_python_nhwc(input_np, filter_np, stride=[stride_h, stride_w], padding=padding)
scale_shift_scipy = np.zeros(shape=get_const_tuple(ScaleShift.shape))
for c in range(in_channel * channel_multiplier):
scale_shift_scipy[:,:,:,c] = depthwise_conv2d_scipy[:,:,:,c] * scale_np[c] + shift_np[c]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import tvm
from tvm import te
from tvm.contrib import nvcc
import topi
from topi.util import get_const_tuple
from tvm import topi
from tvm.topi.util import get_const_tuple

TASK = "conv2d_hwcn_map"
USE_MANUAL_CODE = False
Expand Down Expand Up @@ -65,7 +65,7 @@ def test_conv2d_hwcn_map():

a_np = np.random.uniform(size=get_const_tuple(A.shape)).astype(A.dtype)
w_np = np.random.uniform(size=get_const_tuple(W.shape)).astype(W.dtype)
b_np = topi.testing.conv2d_hwcn_python(a_np, w_np, stride, padding)
b_np = tvm.topi.testing.conv2d_hwcn_python(a_np, w_np, stride, padding)
c_np = np.maximum(b_np, 0)

def check_device(device):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import numpy as np
import tvm
from tvm import te
import topi
from tvm import topi

logging.basicConfig(stream=sys.stdout, level=logging.INFO)
LOGGER = logging.getLogger('test_conv_int8_intel')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import numpy as np
import tvm
from tvm import te
import topi
from tvm import topi

logging.basicConfig(stream=sys.stdout, level=logging.INFO)
LOGGER = logging.getLogger('test_conv_int8_intel')
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import tvm
from tvm import te
from tvm import autotvm
from topi.cuda.tensor_intrin import dp4a
from tvm.topi.cuda.tensor_intrin import dp4a

DO_TUNING = True
PRETUNED_INDEX = 75333
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from tvm.contrib import nvcc
import numpy as np

import topi
from tvm import topi


TASK = "reduce_map"
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 0 additions & 4 deletions conda/tvm/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,3 @@ set -u
cd python
$PYTHON setup.py install --single-version-externally-managed --record=/tmp/record.txt
cd ..

cd topi/python
$PYTHON setup.py install --single-version-externally-managed --record=/tmp/record.txt
cd ../..
2 changes: 1 addition & 1 deletion docker/Dockerfile.demo_android
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ RUN cd /usr && \
make -j10

# Environment variables
ENV PYTHONPATH=/usr/tvm/python:/usr/tvm/topi/python:/usr/tvm/vta/python:${PYTHONPATH}
ENV PYTHONPATH=/usr/tvm/python:/usr/tvm/vta/python:${PYTHONPATH}
ENV ANDROID_HOME=/opt/android-sdk-linux/
2 changes: 1 addition & 1 deletion docker/Dockerfile.demo_cpu
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ COPY install/install_tvm_cpu.sh /install/install_tvm_cpu.sh
RUN bash /install/install_tvm_cpu.sh

# Environment variables
ENV PYTHONPATH=/usr/tvm/python:/usr/tvm/topi/python:/usr/tvm/vta/python:${PYTHONPATH}
ENV PYTHONPATH=/usr/tvm/python:/usr/tvm/vta/python:${PYTHONPATH}
2 changes: 1 addition & 1 deletion docker/Dockerfile.demo_gpu
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ COPY install/install_tvm_gpu.sh /install/install_tvm_gpu.sh
RUN bash /install/install_tvm_gpu.sh

# Environment variables
ENV PYTHONPATH=/usr/tvm/python:/usr/tvm/topi/python:/usr/tvm/vta/python:${PYTHONPATH}
ENV PYTHONPATH=/usr/tvm/python:/usr/tvm/vta/python:${PYTHONPATH}
ENV PATH=/usr/local/nvidia/bin:${PATH}
ENV PATH=/usr/local/cuda/bin:${PATH}
ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/nvidia/lib64:${LD_LIBRARY_PATH}
3 changes: 1 addition & 2 deletions docker/Dockerfile.demo_opencl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,5 @@ RUN mkdir -p ${TVM_BUILD_DIR} && \
make -j6

RUN echo "Building Python package"
ENV PYTHONPATH=${TVM_HOME}/python:${TVM_HOME}/topi/python:${PYTHONPATH}
ENV PYTHONPATH=${TVM_HOME}/python:${PYTHONPATH}
RUN cd ${TVM_HOME}/python && python3 setup.py install --user
RUN cd ${TVM_HOME}/topi/python && python3 setup.py install --user
2 changes: 1 addition & 1 deletion docker/bash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ else
fi

if [[ "${DOCKER_IMAGE_NAME}" == *"ci"* ]]; then
CI_PY_ENV="-e PYTHONPATH=/workspace/python:/workspace/topi/python"
CI_PY_ENV="-e PYTHONPATH=/workspace/python"
else
CI_PY_ENV=""
fi
Expand Down
2 changes: 1 addition & 1 deletion docs/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ WARN_LOGFILE =
# spaces.
# Note: If this tag is empty the current directory is searched.

INPUT = include/tvm topi/include/topi
INPUT = include/tvm

# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
Expand Down
2 changes: 1 addition & 1 deletion docs/api/python/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ Python API
micro
contrib
graph_runtime
vta/index
topi
vta/index
Loading

0 comments on commit 2841574

Please sign in to comment.