diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6ccc01214395..000000000000 --- a/.travis.yml +++ /dev/null @@ -1,68 +0,0 @@ -sudo: false - -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 - - git - - unzip - - gcc-4.8 - - g++-4.8 - - python-numpy - - python-nose - - python3-numpy - - python3-dev - - python3-nose - - graphviz - - bison - - flex - -before_install: - - export PYTHONPATH=${PYTHONPATH}:${PWD}/python - -install: - - source dmlc-core/scripts/travis/travis_setup_env.sh - - source tests/travis/setup.sh - -script: - - tests/travis/run_test.sh - -cache: - directories: - - ${HOME}/.cache/usr - -before_cache: - - dmlc-core/scripts/travis/travis_before_cache.sh - -after_failure: - - tests/travis/travis_after_failure.sh - -notifications: - email: - on_success: change - on_failure: always diff --git a/3rdparty/HalideIR b/3rdparty/HalideIR index 86351c40824d..55ba1778fd26 160000 --- a/3rdparty/HalideIR +++ b/3rdparty/HalideIR @@ -1 +1 @@ -Subproject commit 86351c40824dfc4cbb7447d70e5e63d9bd76eb90 +Subproject commit 55ba1778fd264c7507953552d8e51212ed11f748 diff --git a/CMakeLists.txt b/CMakeLists.txt index 862704caca01..4b022165c8a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,7 +59,7 @@ include_directories("3rdparty/compiler-rt") # initial variables set(TVM_LINKER_LIBS "") -set(TVM_RUNTIME_LINKER_LIBS "") +set(TVM_RUNTIME_LINKER_LIBS ${CMAKE_DL_LIBS}) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Generic compilation options diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 114b231c192a..0e518b14b132 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + TVM Contributors ================ TVM adopts the Apache way and governs by merit. We believe that it is important to create an inclusive community where everyone can use, diff --git a/Jenkinsfile b/Jenkinsfile index b1ba27d32764..dc3a56234509 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,23 @@ #!groovy // -*- mode: groovy -*- + +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + // Jenkins pipeline // See documents at https://jenkins.io/doc/book/pipeline/jenkinsfile/ diff --git a/Makefile b/Makefile index fb50b82c19e1..ce3c4757c474 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + ROOTDIR = $(CURDIR) .PHONY: clean all test doc pylint cpplint lint\ diff --git a/NEWS.md b/NEWS.md index 78213e1ce4c1..658848b3e3bb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + TVM Change Log ============== @@ -27,56 +44,56 @@ This release features several major improvements. Some of the highlights are: Ar - AutoTVM optimizations for CUDA - AutoTVM optimizations for x86 - Initial release of the differentiable programming IR, Relay - - Generic & informative Relay error reporting #2408 - - Relay IR text format support #1781 + - Generic & informative Relay error reporting #2408 + - Relay IR text format support #1781 - Support control flows - - A Normal Form Canonicalization #2251 + - A Normal Form Canonicalization #2251 - Type system support - End to end compilation - * Frontend support: Caffe2 #2507 , CoreML #2476 , Keras #2376 , MXNet #2163 , ONNX, TFLite #2365 - * Operator coverage #1799 #2051 - - FoldScaleAxis #2020 - - SimplifyInference #2033 + * Frontend support: Caffe2 #2507 , CoreML #2476 , Keras #2376 , MXNet #2163 , ONNX, TFLite #2365 + * Operator coverage #1799 #2051 + - FoldScaleAxis #2020 + - SimplifyInference #2033 - CombineParallelConv2D #2089 - - InstrumentBoundCheckers pass #2079 + - InstrumentBoundCheckers pass #2079 - Bind & FoldConstant #2100 - Alter Op Layout #2150 - General OpFusion #2090 - CodeGen - - Gcc / g++ compatible C code generator for TVM #2161 - - Device type annotation for heterogeneous compilation #2361 - - Cache packed func ptr, lift alloca #2070 - - Generalize compute to tensor region #1476 + - Gcc / g++ compatible C code generator for TVM #2161 + - Device type annotation for heterogeneous compilation #2361 + - Cache packed func ptr, lift alloca #2070 + - Generalize compute to tensor region #1476 - Runtime - - Relay interpreter and compiler #1954 - - Heterogeneous runtime #1695 - - Language bindings: Golang runtime #1470 , Rust runtime #1597 - - Add min_repeat_ms to time_evaluator #2200 - - Bundled interpreter demonstration #2297 + - Relay interpreter and compiler #1954 + - Heterogeneous runtime #1695 + - Language bindings: Golang runtime #1470 , Rust runtime #1597 + - Add min_repeat_ms to time_evaluator #2200 + - Bundled interpreter demonstration #2297 - Enable PlanMemory in the graph runtime #2120 - Language Binding - - Rust frontend #2292 + - Rust frontend #2292 - VTA - Improved RPC for VTA #2043 - Hybrid python programming model - - Support for scheduling #2416 - - Support for Inter-function call #2287 + - Support for scheduling #2416 + - Support for Inter-function call #2287 - Backend support #2477 - TOPI - Initial support for sparse tensor computation - - Improve ARM CPU depthwise convolution performance #2345 - - Port winograd ops to relay #2356 + - Improve ARM CPU depthwise convolution performance #2345 + - Port winograd ops to relay #2356 - Add faster-rcnn proposal op #2420 - Tutorials and docs - - Relay language docs #2232 + - Relay language docs #2232 - Tutorials on how to use SGX backend - How to write a pass in python - General lowering flow of TVM - How to do tensorize - - TFLite frontend tutorial #2508 - - Keras seq2seq model for translation tutorial #1815 + - TFLite frontend tutorial #2508 + - Keras seq2seq model for translation tutorial #1815 - Committer guide and tips #2468 - - Code review guideline on API designs #2459 + - Code review guideline on API designs #2459 diff --git a/README.md b/README.md index 82e29421dbe6..ce5c8a4af004 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + Open Deep Learning Compiler Stack ============================================== diff --git a/apps/README.md b/apps/README.md index 2345cc3ab548..685750633493 100644 --- a/apps/README.md +++ b/apps/README.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + # TVM Application Extensions and Examples This folder contains various extension projects using TVM, they also serve as examples on how to use TVM in your own project. diff --git a/apps/android_deploy/README.md b/apps/android_deploy/README.md index 2c2951b5332d..a786738ea9e8 100644 --- a/apps/android_deploy/README.md +++ b/apps/android_deploy/README.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + # Android TVM Demo This folder contains Android Demo app that allows us to show how to deploy model using TVM runtime api on a Android phone. diff --git a/apps/android_deploy/app/build.gradle b/apps/android_deploy/app/build.gradle index 6790308a9ec4..76471aefa4f6 100644 --- a/apps/android_deploy/app/build.gradle +++ b/apps/android_deploy/app/build.gradle @@ -1,3 +1,20 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + // import DownloadModels task project.ext.ASSET_DIR = projectDir.toString() + '/src/main/assets' project.ext.TMP_DIR = project.buildDir.toString() + '/downloads' diff --git a/apps/android_deploy/app/download-models.gradle b/apps/android_deploy/app/download-models.gradle index 5b0509fbca2b..ed660e0221ee 100644 --- a/apps/android_deploy/app/download-models.gradle +++ b/apps/android_deploy/app/download-models.gradle @@ -1,3 +1,20 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + /* * download-models.gradle * Downloads model files from ${MODEL_URL} into application's asset folder diff --git a/apps/android_deploy/app/src/main/AndroidManifest.xml b/apps/android_deploy/app/src/main/AndroidManifest.xml index bac82ee90faa..107dcfee54a8 100644 --- a/apps/android_deploy/app/src/main/AndroidManifest.xml +++ b/apps/android_deploy/app/src/main/AndroidManifest.xml @@ -1,4 +1,24 @@ + + + @@ -34,4 +54,4 @@ - \ No newline at end of file + diff --git a/apps/android_deploy/app/src/main/jni/build.sh b/apps/android_deploy/app/src/main/jni/build.sh index 1ca38ae5bd12..2d2e6f5e4a50 100644 --- a/apps/android_deploy/app/src/main/jni/build.sh +++ b/apps/android_deploy/app/src/main/jni/build.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. PATH="$PATH:/usr/local/bin" CURR_DIR=$(cd `dirname $0`; pwd) ROOT_DIR="$CURR_DIR/../../../../../.." diff --git a/apps/android_deploy/app/src/main/jni/tvm_runtime.h b/apps/android_deploy/app/src/main/jni/tvm_runtime.h index 0b5f4ee67237..3a909e0449ed 100644 --- a/apps/android_deploy/app/src/main/jni/tvm_runtime.h +++ b/apps/android_deploy/app/src/main/jni/tvm_runtime.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file tvm_runtime.h diff --git a/apps/android_deploy/app/src/main/res/layout/activity_main.xml b/apps/android_deploy/app/src/main/res/layout/activity_main.xml index b16a5c2548a6..741b04434765 100644 --- a/apps/android_deploy/app/src/main/res/layout/activity_main.xml +++ b/apps/android_deploy/app/src/main/res/layout/activity_main.xml @@ -1,4 +1,24 @@ + + + + + + + + + #3F51B5 #303F9F diff --git a/apps/android_deploy/app/src/main/res/values/strings.xml b/apps/android_deploy/app/src/main/res/values/strings.xml index cf1fa24069a1..734fc85d2db7 100644 --- a/apps/android_deploy/app/src/main/res/values/strings.xml +++ b/apps/android_deploy/app/src/main/res/values/strings.xml @@ -1,3 +1,23 @@ + + + TVM Android Demo - \ No newline at end of file + diff --git a/apps/android_deploy/app/src/main/res/values/styles.xml b/apps/android_deploy/app/src/main/res/values/styles.xml index 44f664f202f9..ff46174caf9d 100644 --- a/apps/android_deploy/app/src/main/res/values/styles.xml +++ b/apps/android_deploy/app/src/main/res/values/styles.xml @@ -1,3 +1,23 @@ + + + diff --git a/apps/android_deploy/app/src/main/res/xml/provider_paths.xml b/apps/android_deploy/app/src/main/res/xml/provider_paths.xml index 74a5cde1d8fd..d456cf24918f 100644 --- a/apps/android_deploy/app/src/main/res/xml/provider_paths.xml +++ b/apps/android_deploy/app/src/main/res/xml/provider_paths.xml @@ -1,4 +1,24 @@ - - - - \ No newline at end of file + + + + + + + diff --git a/apps/android_deploy/build.gradle b/apps/android_deploy/build.gradle index 1eeb9d686cfb..fc98e3479fe7 100644 --- a/apps/android_deploy/build.gradle +++ b/apps/android_deploy/build.gradle @@ -1,3 +1,20 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { diff --git a/apps/android_deploy/dev_tools/gen_keystore.sh b/apps/android_deploy/dev_tools/gen_keystore.sh index e91cd05ad957..56bdfd2200ee 100644 --- a/apps/android_deploy/dev_tools/gen_keystore.sh +++ b/apps/android_deploy/dev_tools/gen_keystore.sh @@ -1,3 +1,19 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. CURR_DIR=$(cd `dirname $0`; pwd) keytool -genkey -keystore $CURR_DIR/tvmdemo.keystore -alias tvmdemo -keyalg RSA -validity 10000 diff --git a/apps/android_deploy/dev_tools/sign_apk.sh b/apps/android_deploy/dev_tools/sign_apk.sh index fd8cee6b927a..2ef58046f4ae 100644 --- a/apps/android_deploy/dev_tools/sign_apk.sh +++ b/apps/android_deploy/dev_tools/sign_apk.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. CURR_DIR=$(cd `dirname $0`; pwd) APK_DIR=$CURR_DIR/../app/build/outputs/apk/release UNSIGNED_APK=$APK_DIR/app-release-unsigned.apk diff --git a/apps/android_deploy/settings.gradle b/apps/android_deploy/settings.gradle index e7b4def49cb5..ee503c22bf30 100644 --- a/apps/android_deploy/settings.gradle +++ b/apps/android_deploy/settings.gradle @@ -1 +1,18 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + include ':app' diff --git a/apps/android_rpc/README.md b/apps/android_rpc/README.md index 453263aa824e..36ace85405c0 100644 --- a/apps/android_rpc/README.md +++ b/apps/android_rpc/README.md @@ -1,3 +1,21 @@ + + + + + + + + + + + + + + + + + + # Android TVM RPC This folder contains Android RPC app that allows us to launch an RPC server on a Android device and connect to it through python script and do testing on the python side as normal TVM RPC. @@ -85,19 +103,19 @@ If everything goes well, you will find compile tools in `/opt/android-toolchain- ### Cross Compile and Upload to the Android Device -First start an RPC tracker using +First start an RPC tracker using -```python -m tvm.exec.rpc_tracker --port [PORT]``` +```python -m tvm.exec.rpc_tracker --port [PORT]``` and connect your Android device to this RPC tracker via the TVM RPC application. Open the app, set the `Address` and `Port` fields to the address and port of the RPC tracker respectively. The key should be set to "android" if you wish to avoid modifying the default test script. -After pushing "START RPC" button on the app, you can check the connect by run +After pushing "START RPC" button on the app, you can check the connect by run -```python -m tvm.exec.query_rpc_tracker --port [PORT]``` +```python -m tvm.exec.query_rpc_tracker --port [PORT]``` -on your host machine. +on your host machine. You are supposed to find a free "android" in the queue status. ``` diff --git a/apps/android_rpc/app/build.gradle b/apps/android_rpc/app/build.gradle index a91455fc5477..990d08ee3dac 100644 --- a/apps/android_rpc/app/build.gradle +++ b/apps/android_rpc/app/build.gradle @@ -1,3 +1,20 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + apply plugin: 'com.android.application' task buildJni(type: Exec, description: 'Build JNI libs') { diff --git a/apps/android_rpc/app/src/main/AndroidManifest.xml b/apps/android_rpc/app/src/main/AndroidManifest.xml index 2dbc06ece6e3..6c390ccd9325 100644 --- a/apps/android_rpc/app/src/main/AndroidManifest.xml +++ b/apps/android_rpc/app/src/main/AndroidManifest.xml @@ -1,4 +1,24 @@ + + + diff --git a/apps/android_rpc/app/src/main/jni/build.sh b/apps/android_rpc/app/src/main/jni/build.sh index 1ca38ae5bd12..2d2e6f5e4a50 100755 --- a/apps/android_rpc/app/src/main/jni/build.sh +++ b/apps/android_rpc/app/src/main/jni/build.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. PATH="$PATH:/usr/local/bin" CURR_DIR=$(cd `dirname $0`; pwd) ROOT_DIR="$CURR_DIR/../../../../../.." diff --git a/apps/android_rpc/app/src/main/jni/tvm_runtime.h b/apps/android_rpc/app/src/main/jni/tvm_runtime.h index c3c33b0fde37..60b41baaf8e7 100644 --- a/apps/android_rpc/app/src/main/jni/tvm_runtime.h +++ b/apps/android_rpc/app/src/main/jni/tvm_runtime.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file tvm_runtime.h diff --git a/apps/android_rpc/app/src/main/res/layout/activity_main.xml b/apps/android_rpc/app/src/main/res/layout/activity_main.xml index 53d48bbd60d9..35a2cfafab53 100644 --- a/apps/android_rpc/app/src/main/res/layout/activity_main.xml +++ b/apps/android_rpc/app/src/main/res/layout/activity_main.xml @@ -1,4 +1,24 @@ + + + + + + + + + + + + + + #3F51B5 #303F9F diff --git a/apps/android_rpc/app/src/main/res/values/strings.xml b/apps/android_rpc/app/src/main/res/values/strings.xml index f1ca2b90a001..72c19cd4e5b0 100644 --- a/apps/android_rpc/app/src/main/res/values/strings.xml +++ b/apps/android_rpc/app/src/main/res/values/strings.xml @@ -1,3 +1,23 @@ + + + TVM RPC RPC diff --git a/apps/android_rpc/app/src/main/res/values/styles.xml b/apps/android_rpc/app/src/main/res/values/styles.xml index 44f664f202f9..ff46174caf9d 100644 --- a/apps/android_rpc/app/src/main/res/values/styles.xml +++ b/apps/android_rpc/app/src/main/res/values/styles.xml @@ -1,3 +1,23 @@ + + + diff --git a/apps/android_rpc/build.gradle b/apps/android_rpc/build.gradle index 08140708d5ef..be00a5e5213e 100644 --- a/apps/android_rpc/build.gradle +++ b/apps/android_rpc/build.gradle @@ -1,3 +1,20 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { diff --git a/apps/android_rpc/dev_tools/gen_keystore.sh b/apps/android_rpc/dev_tools/gen_keystore.sh index 2078ef1c5a58..6a5d5bb6f6ca 100755 --- a/apps/android_rpc/dev_tools/gen_keystore.sh +++ b/apps/android_rpc/dev_tools/gen_keystore.sh @@ -1,3 +1,19 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. CURR_DIR=$(cd `dirname $0`; pwd) keytool -genkey -keystore $CURR_DIR/tvmrpc.keystore -alias tvmrpc -keyalg RSA -validity 10000 diff --git a/apps/android_rpc/dev_tools/sign_apk.sh b/apps/android_rpc/dev_tools/sign_apk.sh index 7dc6480f4bca..0541e893961a 100755 --- a/apps/android_rpc/dev_tools/sign_apk.sh +++ b/apps/android_rpc/dev_tools/sign_apk.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. CURR_DIR=$(cd `dirname $0`; pwd) APK_DIR=$CURR_DIR/../app/build/outputs/apk/release UNSIGNED_APK=$APK_DIR/app-release-unsigned.apk diff --git a/apps/android_rpc/settings.gradle b/apps/android_rpc/settings.gradle index e7b4def49cb5..ee503c22bf30 100644 --- a/apps/android_rpc/settings.gradle +++ b/apps/android_rpc/settings.gradle @@ -1 +1,18 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + include ':app' diff --git a/apps/android_rpc/tests/android_rpc_test.py b/apps/android_rpc/tests/android_rpc_test.py index 44618efd45c1..122d07faf9e5 100644 --- a/apps/android_rpc/tests/android_rpc_test.py +++ b/apps/android_rpc/tests/android_rpc_test.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Testcode for Android RPC. To use it, start an RPC tracker with "python -m tvm.exec.rpc_tracker". diff --git a/apps/benchmark/README.md b/apps/benchmark/README.md index 9806ddc05bae..93eb94e8b847 100644 --- a/apps/benchmark/README.md +++ b/apps/benchmark/README.md @@ -1,3 +1,21 @@ + + + + + + + + + + + + + + + + + + # Performance Benchmark ## Results @@ -55,7 +73,7 @@ python3 -m tvm.exec.rpc_tracker python3 -m tvm.exec.rpc_server --tracker=[HOST_IP]:9190 --key=[DEVICE_KEY] ``` replace `[HOST_IP]` with the IP address of the host machine, `[DEVICE_KEY]` with the name of device. - + E.g. Here is an example command for RK3399, `python3 -m tvm.exec.rpc_server --tracker=10.77.1.123:9190 --key=rk3399`, where 10.77.1.123 is the IP address of the tracker. @@ -63,34 +81,34 @@ python3 -m tvm.exec.rpc_tracker * Build and install tvm RPC apk on your device [Help](https://github.com/dmlc/tvm/tree/master/apps/android_rpc). Make sure you can pass the android rpc test. Then you have alreadly known how to register. -3. Verify the device registration +3. Verify the device registration We can query all registered devices by ```bash python3 -m tvm.exec.query_rpc_tracker ``` You should be able to find your devices in `Queue Status`. Make sure the registration is correct before going ahead. - For our test environment, one sample output can be + For our test environment, one sample output can be ```bash - Queue Status + Queue Status ---------------------------------- - key total free pending + key total free pending ---------------------------------- mate10pro 1 1 0 - p20pro 2 2 0 + p20pro 2 2 0 pixel2 2 2 0 rk3399 2 2 0 rasp3b 8 8 0 ``` -4. Run benchmark +4. Run benchmark ```bash # ARM CPU python3 arm_cpu_imagenet_bench.py --model rasp3b --rpc-key rasp3b python3 arm_cpu_imagenet_bench.py --model rk3399 --rpc-key rk3399 python3 arm_cpu_imagenet_bench.py --model pixel2 --rpc-key pixel2 python3 arm_cpu_imagenet_bench.py --model p20pro --rpc-key p20pro - python3 arm_cpu_imagenet_bench.py --model mate10pro --rpc-key mate10pro + python3 arm_cpu_imagenet_bench.py --model mate10pro --rpc-key mate10pro ``` ```bash diff --git a/apps/benchmark/arm_cpu_imagenet_bench.py b/apps/benchmark/arm_cpu_imagenet_bench.py index f84d42bcab82..29e9728c4000 100644 --- a/apps/benchmark/arm_cpu_imagenet_bench.py +++ b/apps/benchmark/arm_cpu_imagenet_bench.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Benchmark script for ImageNet models on ARM CPU. see README.md for the usage and results of this script. """ diff --git a/apps/benchmark/gpu_imagenet_bench.py b/apps/benchmark/gpu_imagenet_bench.py index 17c1fbc435b6..b24560ce9eb2 100644 --- a/apps/benchmark/gpu_imagenet_bench.py +++ b/apps/benchmark/gpu_imagenet_bench.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Benchmark script for ImageNet models on GPU. see README.md for the usage and results of this script. """ diff --git a/apps/benchmark/mobile_gpu_imagenet_bench.py b/apps/benchmark/mobile_gpu_imagenet_bench.py index cd3d7eca9f3c..c889b3d32430 100644 --- a/apps/benchmark/mobile_gpu_imagenet_bench.py +++ b/apps/benchmark/mobile_gpu_imagenet_bench.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Benchmark script for ImageNet models on mobile GPU. see README.md for the usage and results of this script. """ diff --git a/apps/benchmark/util.py b/apps/benchmark/util.py index ac732d7945b9..aa87efb6da9e 100644 --- a/apps/benchmark/util.py +++ b/apps/benchmark/util.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Utility for benchmark""" import sys @@ -5,7 +21,7 @@ def get_network(name, batch_size, dtype='float32'): """Get the symbol definition and random weight of a network - + Parameters ---------- name: str @@ -69,7 +85,7 @@ def get_network(name, batch_size, dtype='float32'): def print_progress(msg): """print progress message - + Parameters ---------- msg: str diff --git a/apps/bundle_deploy/Makefile b/apps/bundle_deploy/Makefile index 0bf1613c8d66..8550a0ee1f00 100644 --- a/apps/bundle_deploy/Makefile +++ b/apps/bundle_deploy/Makefile @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # Makefile Example to bundle TVM modules. TVM_ROOT=$(shell cd ../..; pwd) NNVM_PATH=nnvm diff --git a/apps/bundle_deploy/README.md b/apps/bundle_deploy/README.md index 2db8150b2659..6be9c4f91340 100644 --- a/apps/bundle_deploy/README.md +++ b/apps/bundle_deploy/README.md @@ -1,3 +1,21 @@ + + + + + + + + + + + + + + + + + + How to Bundle TVM Modules ========================= diff --git a/apps/bundle_deploy/build_model.py b/apps/bundle_deploy/build_model.py index 901996b8774e..dc4c14b47a01 100644 --- a/apps/bundle_deploy/build_model.py +++ b/apps/bundle_deploy/build_model.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Creates a simple TVM modules.""" import argparse diff --git a/apps/bundle_deploy/bundle.cc b/apps/bundle_deploy/bundle.cc index af1ef7225bcb..61169f17cf71 100644 --- a/apps/bundle_deploy/bundle.cc +++ b/apps/bundle_deploy/bundle.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #include #include #include diff --git a/apps/bundle_deploy/demo.cc b/apps/bundle_deploy/demo.cc index c888edcee772..325bae780260 100644 --- a/apps/bundle_deploy/demo.cc +++ b/apps/bundle_deploy/demo.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #include "tvm/runtime/c_runtime_api.h" #include #include //dlopen diff --git a/apps/bundle_deploy/runtime.cc b/apps/bundle_deploy/runtime.cc index 2284953b8c16..968554b5b34a 100644 --- a/apps/bundle_deploy/runtime.cc +++ b/apps/bundle_deploy/runtime.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #include #include #include diff --git a/apps/extension/Makefile b/apps/extension/Makefile index 41e9bf621cb6..14c71d92ca20 100644 --- a/apps/extension/Makefile +++ b/apps/extension/Makefile @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # Minimum Makefile for the extension package TVM_ROOT=$(shell cd ../..; pwd) PKG_CFLAGS = -std=c++11 -O2 -fPIC\ diff --git a/apps/extension/README.md b/apps/extension/README.md index cd17702c3973..9bb97b771aab 100644 --- a/apps/extension/README.md +++ b/apps/extension/README.md @@ -1,3 +1,21 @@ + + + + + + + + + + + + + + + + + + Example Extension Library ========================= This folder contains an example extension library of TVM. diff --git a/apps/extension/src/tvm_ext.cc b/apps/extension/src/tvm_ext.cc index 97e0ada25a2e..e440e1ab2831 100644 --- a/apps/extension/src/tvm_ext.cc +++ b/apps/extension/src/tvm_ext.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors diff --git a/apps/extension/tests/test_ext.py b/apps/extension/tests/test_ext.py index a6246d6be2e1..e481e82fefb3 100644 --- a/apps/extension/tests/test_ext.py +++ b/apps/extension/tests/test_ext.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm_ext import tvm import numpy as np diff --git a/apps/howto_deploy/Makefile b/apps/howto_deploy/Makefile index 39c5996233ab..12c9d179351a 100644 --- a/apps/howto_deploy/Makefile +++ b/apps/howto_deploy/Makefile @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # Makefile Example to deploy TVM modules. TVM_ROOT=$(shell cd ../..; pwd) NNVM_PATH=nnvm diff --git a/apps/howto_deploy/README.md b/apps/howto_deploy/README.md index fda6251ae9c5..8935c5b3b10e 100644 --- a/apps/howto_deploy/README.md +++ b/apps/howto_deploy/README.md @@ -1,3 +1,21 @@ + + + + + + + + + + + + + + + + + + How to Deploy TVM Modules ========================= This folder contains an example on how to deploy TVM modules. diff --git a/apps/howto_deploy/cpp_deploy.cc b/apps/howto_deploy/cpp_deploy.cc index 9a6c5ebca703..63c54363aee9 100644 --- a/apps/howto_deploy/cpp_deploy.cc +++ b/apps/howto_deploy/cpp_deploy.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief Example code on load and run TVM module.s diff --git a/apps/howto_deploy/prepare_test_libs.py b/apps/howto_deploy/prepare_test_libs.py index f8dd1684dd62..b620bc7a1d5f 100644 --- a/apps/howto_deploy/prepare_test_libs.py +++ b/apps/howto_deploy/prepare_test_libs.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Script to prepare test_addone.so""" import tvm import os diff --git a/apps/howto_deploy/run_example.sh b/apps/howto_deploy/run_example.sh index 899dc48b5f25..4bf10668967d 100755 --- a/apps/howto_deploy/run_example.sh +++ b/apps/howto_deploy/run_example.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. echo "Build the libraries.." mkdir -p lib make diff --git a/apps/howto_deploy/tvm_runtime_pack.cc b/apps/howto_deploy/tvm_runtime_pack.cc index c4b6e2a2d44e..736add6e9fa3 100644 --- a/apps/howto_deploy/tvm_runtime_pack.cc +++ b/apps/howto_deploy/tvm_runtime_pack.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * \brief This is an all in one TVM runtime file. * diff --git a/apps/ios_rpc/README.md b/apps/ios_rpc/README.md index a5ce4844049e..3c70a86f5d74 100644 --- a/apps/ios_rpc/README.md +++ b/apps/ios_rpc/README.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + # iOS TVM RPC This folder contains iOS RPC app that allows us to launch an rpc server on a iOS device(e.g. ipython) diff --git a/apps/ios_rpc/init_proj.py b/apps/ios_rpc/init_proj.py index 5df5bf9e3092..c47f590a7aba 100644 --- a/apps/ios_rpc/init_proj.py +++ b/apps/ios_rpc/init_proj.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import argparse import re diff --git a/apps/ios_rpc/tests/ios_rpc_test.py b/apps/ios_rpc/tests/ios_rpc_test.py index 4865da01a7e8..ac3718f7ba8e 100644 --- a/apps/ios_rpc/tests/ios_rpc_test.py +++ b/apps/ios_rpc/tests/ios_rpc_test.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Testcode for iOS RPC. To use it, start a rpc proxy with "python -m tvm.exec.rpc_proxy". diff --git a/apps/ios_rpc/tvmrpc/AppDelegate.h b/apps/ios_rpc/tvmrpc/AppDelegate.h index 805ea9efc554..649daad44651 100644 --- a/apps/ios_rpc/tvmrpc/AppDelegate.h +++ b/apps/ios_rpc/tvmrpc/AppDelegate.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file AppDelegate.h @@ -11,4 +30,3 @@ @end - diff --git a/apps/ios_rpc/tvmrpc/AppDelegate.m b/apps/ios_rpc/tvmrpc/AppDelegate.m index e1d2d31efc6f..091e20f9bb30 100644 --- a/apps/ios_rpc/tvmrpc/AppDelegate.m +++ b/apps/ios_rpc/tvmrpc/AppDelegate.m @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file AppDelegate.mm diff --git a/apps/ios_rpc/tvmrpc/TVMRuntime.h b/apps/ios_rpc/tvmrpc/TVMRuntime.h index fec351e7b22b..58b3b37dddf6 100644 --- a/apps/ios_rpc/tvmrpc/TVMRuntime.h +++ b/apps/ios_rpc/tvmrpc/TVMRuntime.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file TVMRuntime.h diff --git a/apps/ios_rpc/tvmrpc/TVMRuntime.mm b/apps/ios_rpc/tvmrpc/TVMRuntime.mm index 0dced65dbe3e..5d1d90e68b32 100644 --- a/apps/ios_rpc/tvmrpc/TVMRuntime.mm +++ b/apps/ios_rpc/tvmrpc/TVMRuntime.mm @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file TVMRuntime.mm diff --git a/apps/ios_rpc/tvmrpc/ViewController.h b/apps/ios_rpc/tvmrpc/ViewController.h index 27b0bf447431..3cd4723f94b7 100644 --- a/apps/ios_rpc/tvmrpc/ViewController.h +++ b/apps/ios_rpc/tvmrpc/ViewController.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file ViewController.h diff --git a/apps/ios_rpc/tvmrpc/ViewController.mm b/apps/ios_rpc/tvmrpc/ViewController.mm index 98527bd67b50..2506a5f2f9de 100644 --- a/apps/ios_rpc/tvmrpc/ViewController.mm +++ b/apps/ios_rpc/tvmrpc/ViewController.mm @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file ViewController.mm diff --git a/apps/ios_rpc/tvmrpc/main.m b/apps/ios_rpc/tvmrpc/main.m index cc783c242483..1b8b8bf90cc9 100644 --- a/apps/ios_rpc/tvmrpc/main.m +++ b/apps/ios_rpc/tvmrpc/main.m @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file main.m diff --git a/apps/ios_rpc/tvmrpcLauncher/tvmrpcLauncher.mm b/apps/ios_rpc/tvmrpcLauncher/tvmrpcLauncher.mm index 81b2828070b1..f2f03f95f3cb 100644 --- a/apps/ios_rpc/tvmrpcLauncher/tvmrpcLauncher.mm +++ b/apps/ios_rpc/tvmrpcLauncher/tvmrpcLauncher.mm @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief A hook to launch RPC server via xcodebuild test diff --git a/apps/pynq_rpc/start_rpc_server.sh b/apps/pynq_rpc/start_rpc_server.sh index 2dce74472414..a6f80e27f139 100755 --- a/apps/pynq_rpc/start_rpc_server.sh +++ b/apps/pynq_rpc/start_rpc_server.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. PROJROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../../" && pwd )" export PYTHONPATH=${PYTHONPATH}:${PROJROOT}/python:${PROJROOT}/vta/python diff --git a/apps/rocm_rpc/Makefile b/apps/rocm_rpc/Makefile index d4e3ec06ca99..8d30fb6ef780 100644 --- a/apps/rocm_rpc/Makefile +++ b/apps/rocm_rpc/Makefile @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # Makefile Example to deploy TVM modules. ROCM_PATH=/opt/rocm diff --git a/apps/rocm_rpc/README.md b/apps/rocm_rpc/README.md index 70ce9780a31d..f99c1282e6d1 100644 --- a/apps/rocm_rpc/README.md +++ b/apps/rocm_rpc/README.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + # TVM ROCm RPC This folder contains a simple recipe to make RPC work together with ROCm.TVM's RPC server relies on process diff --git a/apps/rocm_rpc/rocm_runtime_pack.cc b/apps/rocm_rpc/rocm_runtime_pack.cc index 174d9f0a8270..a137a9b28f8a 100644 --- a/apps/rocm_rpc/rocm_runtime_pack.cc +++ b/apps/rocm_rpc/rocm_runtime_pack.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * \brief This is an all in one file for ROCM runtime library. * diff --git a/apps/rocm_rpc/start_rpc_server.sh b/apps/rocm_rpc/start_rpc_server.sh index e082d9d63ee6..988cf07eb13a 100755 --- a/apps/rocm_rpc/start_rpc_server.sh +++ b/apps/rocm_rpc/start_rpc_server.sh @@ -1,4 +1,21 @@ -#/bin/bash +#!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + PROJ_ROOT=$(realpath $(dirname "$0")/../..) export PYTHONPATH=${PROJ_ROOT}/python:${PYTHONPATH} diff --git a/apps/sgx/Makefile b/apps/sgx/Makefile index 422d3e4f03ab..c867d65e9daa 100644 --- a/apps/sgx/Makefile +++ b/apps/sgx/Makefile @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + SGX_SDK ?= /opt/sgxsdk RUST_SGX_SDK ?= /opt/rust-sgx-sdk SGX_MODE ?= SIM diff --git a/apps/sgx/README.md b/apps/sgx/README.md index 10989ba4b90d..10dbcd94c586 100644 --- a/apps/sgx/README.md +++ b/apps/sgx/README.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + # TVM in Intel SGX Example This application demonstrates the use of a simple TVM model in the [Intel SGX](https://software.intel.com/en-us/blogs/2013/09/26/protecting-application-secrets-with-intel-sgx) trusted computing environment. @@ -56,6 +73,6 @@ Building this example performs the following steps: 3. Packages the bundle into an SGX enclave 4. Runs the enclave using the usual TVM Python `module` API -For more information on building, please refer to the `Makefile`. -For more information on the TVM module, please refer to `../howto_deploy`. +For more information on building, please refer to the `Makefile`. +For more information on the TVM module, please refer to `../howto_deploy`. For more in formation on SGX enclaves, please refer to the [SGX Enclave Demo](https://github.com/intel/linux-sgx/tree/master/SampleCode/SampleEnclave/) diff --git a/apps/sgx/enclave/Cargo.toml b/apps/sgx/enclave/Cargo.toml index cb128f3fbf94..70b7ec462675 100644 --- a/apps/sgx/enclave/Cargo.toml +++ b/apps/sgx/enclave/Cargo.toml @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + [package] name = "model-enclave" version = "0.1.0" diff --git a/apps/sgx/enclave/Makefile b/apps/sgx/enclave/Makefile index a28e05e03b13..8d6571b3cd69 100644 --- a/apps/sgx/enclave/Makefile +++ b/apps/sgx/enclave/Makefile @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + MODEL ?= resnet NUM_THREADS ?= 4 BATCH_SIZE ?= 64 diff --git a/apps/sgx/enclave/Xargo.toml b/apps/sgx/enclave/Xargo.toml index 57acf092b4d6..4b6b60aaa3c3 100644 --- a/apps/sgx/enclave/Xargo.toml +++ b/apps/sgx/enclave/Xargo.toml @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + [dependencies] alloc = {} panic_unwind = {} diff --git a/apps/sgx/enclave/build.rs b/apps/sgx/enclave/build.rs index a3beedaacda6..49596816819d 100644 --- a/apps/sgx/enclave/build.rs +++ b/apps/sgx/enclave/build.rs @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + use std::env; fn main() { diff --git a/apps/sgx/enclave/src/build_model.py b/apps/sgx/enclave/src/build_model.py index d1b45cc4a4df..5a6b10cfcd38 100644 --- a/apps/sgx/enclave/src/build_model.py +++ b/apps/sgx/enclave/src/build_model.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Creates a simple TVM modules.""" import argparse diff --git a/apps/sgx/enclave/src/lib.rs b/apps/sgx/enclave/src/lib.rs index 3310040d3657..bb0fc795d90d 100644 --- a/apps/sgx/enclave/src/lib.rs +++ b/apps/sgx/enclave/src/lib.rs @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ #![feature(try_from)] #[macro_use] diff --git a/apps/sgx/run_example.sh b/apps/sgx/run_example.sh index 811da3938dd6..c09807fb8acc 100755 --- a/apps/sgx/run_example.sh +++ b/apps/sgx/run_example.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. sgx_sdk=${SGX_SDK:=/opt/sgxsdk} diff --git a/apps/sgx/run_model.py b/apps/sgx/run_model.py index 232a03524801..9f21c2685d45 100644 --- a/apps/sgx/run_model.py +++ b/apps/sgx/run_model.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import os.path as osp import numpy as np import tvm diff --git a/cmake/modules/ANTLR.cmake b/cmake/modules/ANTLR.cmake index 82d866c0de01..4091465d1ec1 100644 --- a/cmake/modules/ANTLR.cmake +++ b/cmake/modules/ANTLR.cmake @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + if(USE_ANTLR) file(GLOB_RECURSE ANTLR4 /usr/local/lib/antlr-*-complete.jar diff --git a/cmake/modules/CUDA.cmake b/cmake/modules/CUDA.cmake index 8d7a157e79e2..a947c36688c9 100644 --- a/cmake/modules/CUDA.cmake +++ b/cmake/modules/CUDA.cmake @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # CUDA Module find_cuda(${USE_CUDA}) diff --git a/cmake/modules/LLVM.cmake b/cmake/modules/LLVM.cmake index 3e896a601056..55d5b8d48fb0 100644 --- a/cmake/modules/LLVM.cmake +++ b/cmake/modules/LLVM.cmake @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # LLVM rules add_definitions(-DDMLC_USE_FOPEN64=0) diff --git a/cmake/modules/Metal.cmake b/cmake/modules/Metal.cmake index 27aa5a226f2b..b6512982039e 100644 --- a/cmake/modules/Metal.cmake +++ b/cmake/modules/Metal.cmake @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + if(USE_METAL) message(STATUS "Build with Metal support") find_library(METAL_LIB Metal) diff --git a/cmake/modules/OpenCL.cmake b/cmake/modules/OpenCL.cmake index b30df1864522..300b70e9fb88 100644 --- a/cmake/modules/OpenCL.cmake +++ b/cmake/modules/OpenCL.cmake @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # OPENCL Module find_package(OpenCL QUIET) diff --git a/cmake/modules/OpenGL.cmake b/cmake/modules/OpenGL.cmake index 2b62c9f302d4..89d79f813f5f 100644 --- a/cmake/modules/OpenGL.cmake +++ b/cmake/modules/OpenGL.cmake @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + find_package(OpenGL QUIET) if(OpenGL_FOUND) diff --git a/cmake/modules/ROCM.cmake b/cmake/modules/ROCM.cmake index 0e45fdac66d9..a11133586cc0 100644 --- a/cmake/modules/ROCM.cmake +++ b/cmake/modules/ROCM.cmake @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # ROCM Module find_rocm(${USE_ROCM}) diff --git a/cmake/modules/SGX.cmake b/cmake/modules/SGX.cmake index 86e4c22f4331..ca40f8cd039b 100644 --- a/cmake/modules/SGX.cmake +++ b/cmake/modules/SGX.cmake @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + if(NOT USE_SGX STREQUAL "OFF") set(_sgx_src ${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/sgx) diff --git a/cmake/modules/VTA.cmake b/cmake/modules/VTA.cmake index ea5bb5ae916a..3c6390688f9a 100644 --- a/cmake/modules/VTA.cmake +++ b/cmake/modules/VTA.cmake @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # CMake Build rules for VTA find_program(PYTHON NAMES python python3 python3.6) diff --git a/cmake/modules/Vulkan.cmake b/cmake/modules/Vulkan.cmake index 4093f88f2e10..346d1357709f 100644 --- a/cmake/modules/Vulkan.cmake +++ b/cmake/modules/Vulkan.cmake @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # Be compatible with older version of CMake find_vulkan(${USE_VULKAN}) diff --git a/cmake/modules/contrib/BLAS.cmake b/cmake/modules/contrib/BLAS.cmake index 09526ef38f6b..e1e151d6a9f8 100644 --- a/cmake/modules/contrib/BLAS.cmake +++ b/cmake/modules/contrib/BLAS.cmake @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # Plugin rules for cblas file(GLOB CBLAS_CONTRIB_SRC src/contrib/cblas/*.cc) diff --git a/cmake/modules/contrib/HybridDump.cmake b/cmake/modules/contrib/HybridDump.cmake index c8d6d6e07756..f8de20a02bff 100644 --- a/cmake/modules/contrib/HybridDump.cmake +++ b/cmake/modules/contrib/HybridDump.cmake @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + message(STATUS "Build with contrib.hybriddump") file(GLOB HYBRID_CONTRIB_SRC src/contrib/hybrid/*.cc) list(APPEND COMPILER_SRCS ${HYBRID_CONTRIB_SRC}) diff --git a/cmake/modules/contrib/NNPack.cmake b/cmake/modules/contrib/NNPack.cmake index 4bf844d0c468..078efec45553 100644 --- a/cmake/modules/contrib/NNPack.cmake +++ b/cmake/modules/contrib/NNPack.cmake @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + if(USE_NNPACK) if(NNPACK_PATH STREQUAL "") set(NNPACK_PATH ${CMAKE_CURRENT_SOURCE_DIR}/NNPack) diff --git a/cmake/modules/contrib/Random.cmake b/cmake/modules/contrib/Random.cmake index a6980be8bb5b..1b28ec3b6945 100644 --- a/cmake/modules/contrib/Random.cmake +++ b/cmake/modules/contrib/Random.cmake @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + if(USE_RANDOM) message(STATUS "Build with contrib.random") file(GLOB RANDOM_CONTRIB_SRC src/contrib/random/random.cc) diff --git a/cmake/modules/contrib/Sort.cmake b/cmake/modules/contrib/Sort.cmake index 9ef637ecd99f..52edd3851d36 100644 --- a/cmake/modules/contrib/Sort.cmake +++ b/cmake/modules/contrib/Sort.cmake @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + if(USE_SORT) message(STATUS "Build with contrib.sort") file(GLOB SORT_CONTRIB_SRC src/contrib/sort/*.cc) diff --git a/cmake/util/FindCUDA.cmake b/cmake/util/FindCUDA.cmake index 9dfd3d62a8b8..4cec01c04db2 100644 --- a/cmake/util/FindCUDA.cmake +++ b/cmake/util/FindCUDA.cmake @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + ####################################################### # Enhanced version of find CUDA. # diff --git a/cmake/util/FindLLVM.cmake b/cmake/util/FindLLVM.cmake index f2ee945207b6..813c8adf456c 100644 --- a/cmake/util/FindLLVM.cmake +++ b/cmake/util/FindLLVM.cmake @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + ####################################################### # Enhanced version of find llvm. # diff --git a/cmake/util/FindROCM.cmake b/cmake/util/FindROCM.cmake index 317fea1b8f4e..2b2db2c14f11 100644 --- a/cmake/util/FindROCM.cmake +++ b/cmake/util/FindROCM.cmake @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + ####################################################### # Enhanced version of find rocm. # diff --git a/cmake/util/FindVulkan.cmake b/cmake/util/FindVulkan.cmake index 504058c66b62..850b99ceb299 100644 --- a/cmake/util/FindVulkan.cmake +++ b/cmake/util/FindVulkan.cmake @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + ####################################################### # Enhanced version of find Vulkan. # diff --git a/cmake/util/Util.cmake b/cmake/util/Util.cmake index fb3118bde9e0..d105c82a3082 100644 --- a/cmake/util/Util.cmake +++ b/cmake/util/Util.cmake @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + macro(__tvm_option variable description value) if(NOT DEFINED ${variable}) set(${variable} ${value} CACHE STRING ${description}) diff --git a/conda/Dockerfile.cuda100 b/conda/Dockerfile.cuda100 index 1286b7fdc013..def8c9ac5d6a 100644 --- a/conda/Dockerfile.cuda100 +++ b/conda/Dockerfile.cuda100 @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + FROM nvidia/cuda:10.0-devel-centos6 RUN curl -o ~/miniconda.sh -O https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ diff --git a/conda/Dockerfile.cuda92 b/conda/Dockerfile.cuda92 index eafea875750d..ad2d8ffca6e0 100644 --- a/conda/Dockerfile.cuda92 +++ b/conda/Dockerfile.cuda92 @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + FROM nvidia/cuda:9.2-devel-centos6 RUN curl -o ~/miniconda.sh -O https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ diff --git a/conda/build_cuda.sh b/conda/build_cuda.sh old mode 100644 new mode 100755 index 283366b37449..2f3207e22987 --- a/conda/build_cuda.sh +++ b/conda/build_cuda.sh @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. #/bin/sh condadir=`dirname $0` condadir=`readlink -f $condadir` diff --git a/conda/conda_build_config.yaml b/conda/conda_build_config.yaml index 66b89489b341..79d6bfe3c175 100644 --- a/conda/conda_build_config.yaml +++ b/conda/conda_build_config.yaml @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + python: - 3.5 - 3.6 diff --git a/conda/cross-linux.cmake b/conda/cross-linux.cmake index bb837eea5ba7..f84ba8e44a26 100644 --- a/conda/cross-linux.cmake +++ b/conda/cross-linux.cmake @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # this one is important set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_PLATFORM Linux) diff --git a/conda/nnvm/build.sh b/conda/nnvm/build.sh index 9f7889e610e7..bdd333f57734 100644 --- a/conda/nnvm/build.sh +++ b/conda/nnvm/build.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e diff --git a/conda/nnvm/meta.yaml b/conda/nnvm/meta.yaml index bae06740fd0b..883655f335cb 100644 --- a/conda/nnvm/meta.yaml +++ b/conda/nnvm/meta.yaml @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + {% set version = "0.6.dev" %} package: diff --git a/conda/topi/build.sh b/conda/topi/build.sh index a1f5e491c8eb..4e5aafb93766 100644 --- a/conda/topi/build.sh +++ b/conda/topi/build.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e diff --git a/conda/topi/meta.yaml b/conda/topi/meta.yaml index f13c95ac4032..bbba452a6422 100644 --- a/conda/topi/meta.yaml +++ b/conda/topi/meta.yaml @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + {% set version = "0.6.dev" %} package: diff --git a/conda/tvm-libs/build.sh b/conda/tvm-libs/build.sh index 772838e63ac6..d4cf2578b570 100644 --- a/conda/tvm-libs/build.sh +++ b/conda/tvm-libs/build.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # Fix for OSX build to hide the clang LLVM rm -f ${BUILD_PREFIX}/bin/llvm-config diff --git a/conda/tvm-libs/meta.yaml b/conda/tvm-libs/meta.yaml index fcb8f22cad25..5126f5b30359 100644 --- a/conda/tvm-libs/meta.yaml +++ b/conda/tvm-libs/meta.yaml @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + {% set version = "0.6.dev" %} package: diff --git a/conda/tvm/build.sh b/conda/tvm/build.sh index 9c958a32e629..6626aa592091 100644 --- a/conda/tvm/build.sh +++ b/conda/tvm/build.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e diff --git a/conda/tvm/meta.yaml b/conda/tvm/meta.yaml index 37adf5b4fe2e..693237ce07c0 100644 --- a/conda/tvm/meta.yaml +++ b/conda/tvm/meta.yaml @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + {% set version = "0.6.dev" %} package: diff --git a/dmlc_tvm_commit_id b/dmlc_tvm_commit_id index 5610de59452d..9c1312eed7e3 100644 --- a/dmlc_tvm_commit_id +++ b/dmlc_tvm_commit_id @@ -1 +1 @@ -a0537ecbf80fafee22ea64bb2994332d4488b81f +552d4aa3587aa3a0443d050ceb324386489ff793 \ No newline at end of file diff --git a/docker/Dockerfile.ci_cpu b/docker/Dockerfile.ci_cpu index 53a6828f0f07..f4f48c0e4afd 100644 --- a/docker/Dockerfile.ci_cpu +++ b/docker/Dockerfile.ci_cpu @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # CI docker CPU env # tag: v0.41 FROM ubuntu:16.04 diff --git a/docker/Dockerfile.ci_emscripten b/docker/Dockerfile.ci_emscripten index b4d5a63c52ef..e2a9a7b76dd9 100644 --- a/docker/Dockerfile.ci_emscripten +++ b/docker/Dockerfile.ci_emscripten @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # For CPU FROM ubuntu:16.04 diff --git a/docker/Dockerfile.ci_gpu b/docker/Dockerfile.ci_gpu index 4c1ffb14c1f2..8f3deb03af3f 100644 --- a/docker/Dockerfile.ci_gpu +++ b/docker/Dockerfile.ci_gpu @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # CI docker GPU env # tag: v0.50 FROM nvidia/cuda:8.0-cudnn7-devel diff --git a/docker/Dockerfile.ci_i386 b/docker/Dockerfile.ci_i386 index 42941fe240eb..13c3c6b41118 100644 --- a/docker/Dockerfile.ci_i386 +++ b/docker/Dockerfile.ci_i386 @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # CI docker i386 env # tag: v0.50 diff --git a/docker/Dockerfile.ci_lint b/docker/Dockerfile.ci_lint index 0d7b4a410033..7fa23adc99dc 100644 --- a/docker/Dockerfile.ci_lint +++ b/docker/Dockerfile.ci_lint @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # For lint test # CI docker lint env FROM ubuntu:16.04 diff --git a/docker/Dockerfile.demo_android b/docker/Dockerfile.demo_android index 2adcdb42f4e4..743f0a5fc938 100644 --- a/docker/Dockerfile.demo_android +++ b/docker/Dockerfile.demo_android @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # Minimum docker image for demo purposes FROM ubuntu:16.04 @@ -33,4 +50,3 @@ RUN bash /install/install_tvm_cpu.sh # Environment variables ENV PYTHONPATH=/usr/tvm/python:/usr/tvm/topi/python:/usr/tvm/nnvm/python/:/usr/tvm/vta/python:${PYTHONPATH} - diff --git a/docker/Dockerfile.demo_cpu b/docker/Dockerfile.demo_cpu index e8a20dec8fc1..a9f13bb288bc 100644 --- a/docker/Dockerfile.demo_cpu +++ b/docker/Dockerfile.demo_cpu @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # Minimum docker image for demo purposes # prebuilt-image: tvmai/demo-cpu FROM ubuntu:16.04 diff --git a/docker/Dockerfile.demo_gpu b/docker/Dockerfile.demo_gpu index 6fe6b2ae8b09..88cc00a615a6 100644 --- a/docker/Dockerfile.demo_gpu +++ b/docker/Dockerfile.demo_gpu @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # Minimum docker image for demo purposes # prebuilt-image: tvmai/demo-gpu FROM nvidia/cuda:9.0-cudnn7-devel diff --git a/docker/Dockerfile.demo_opencl b/docker/Dockerfile.demo_opencl index 2d0b45983902..58c62b335406 100644 --- a/docker/Dockerfile.demo_opencl +++ b/docker/Dockerfile.demo_opencl @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # USAGE: sudo docker build libs/tvm -f libs/tvm/docker/Dockerfile.ocl -t l4b/tvm:ocl # REFERENCE: https://docs.docker.com/engine/reference/builder diff --git a/docker/README.md b/docker/README.md index df9ea42af68a..c363814feb52 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + # TVM Docker This directory contains the TVM's docker infrastructure. diff --git a/docker/bash.sh b/docker/bash.sh index acec600eec42..23b2e209e01e 100755 --- a/docker/bash.sh +++ b/docker/bash.sh @@ -1,4 +1,22 @@ #!/usr/bin/env bash + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # # Start a bash, mount /workspace to be current directory. # diff --git a/docker/build.sh b/docker/build.sh index 5b6c4450f6e4..380ae8cb29df 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -1,4 +1,22 @@ #!/usr/bin/env bash + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # # Execute command within a docker container # diff --git a/docker/install/install_tvm_cpu.sh b/docker/install/install_tvm_cpu.sh index 04153559d27e..c67206aef762 100755 --- a/docker/install/install_tvm_cpu.sh +++ b/docker/install/install_tvm_cpu.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/install_tvm_gpu.sh b/docker/install/install_tvm_gpu.sh index d31e10ce9ab9..57bee0829c89 100755 --- a/docker/install/install_tvm_gpu.sh +++ b/docker/install/install_tvm_gpu.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_androidsdk.sh b/docker/install/ubuntu_install_androidsdk.sh index 96fdbe168d6d..fb1990d88406 100755 --- a/docker/install/ubuntu_install_androidsdk.sh +++ b/docker/install/ubuntu_install_androidsdk.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. . /etc/profile diff --git a/docker/install/ubuntu_install_antlr.sh b/docker/install/ubuntu_install_antlr.sh index 6dae3ae12d56..de713a6f6a32 100755 --- a/docker/install/ubuntu_install_antlr.sh +++ b/docker/install/ubuntu_install_antlr.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_caffe2.sh b/docker/install/ubuntu_install_caffe2.sh index bb9322704918..a9c1d19eca8a 100755 --- a/docker/install/ubuntu_install_caffe2.sh +++ b/docker/install/ubuntu_install_caffe2.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_core.sh b/docker/install/ubuntu_install_core.sh index c7e2918971fd..8ca7a38469f3 100755 --- a/docker/install/ubuntu_install_core.sh +++ b/docker/install/ubuntu_install_core.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_coreml.sh b/docker/install/ubuntu_install_coreml.sh index 51afc1423961..cbdc87666b4e 100755 --- a/docker/install/ubuntu_install_coreml.sh +++ b/docker/install/ubuntu_install_coreml.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_darknet.sh b/docker/install/ubuntu_install_darknet.sh index 5c350b848bf7..0238b920c844 100755 --- a/docker/install/ubuntu_install_darknet.sh +++ b/docker/install/ubuntu_install_darknet.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_emscripten.sh b/docker/install/ubuntu_install_emscripten.sh index 4671c898438a..0012cd08cf28 100755 --- a/docker/install/ubuntu_install_emscripten.sh +++ b/docker/install/ubuntu_install_emscripten.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_gluoncv.sh b/docker/install/ubuntu_install_gluoncv.sh index adfbdce7c7b1..cb24ff74e9ff 100755 --- a/docker/install/ubuntu_install_gluoncv.sh +++ b/docker/install/ubuntu_install_gluoncv.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_golang.sh b/docker/install/ubuntu_install_golang.sh index c29e764cbb3a..5b05b3886b05 100755 --- a/docker/install/ubuntu_install_golang.sh +++ b/docker/install/ubuntu_install_golang.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_gradle.sh b/docker/install/ubuntu_install_gradle.sh index 7f62406ca710..030be040c6e3 100755 --- a/docker/install/ubuntu_install_gradle.sh +++ b/docker/install/ubuntu_install_gradle.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. . /etc/profile diff --git a/docker/install/ubuntu_install_iverilog.sh b/docker/install/ubuntu_install_iverilog.sh index 2304f697affd..da20730d491e 100755 --- a/docker/install/ubuntu_install_iverilog.sh +++ b/docker/install/ubuntu_install_iverilog.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_java.sh b/docker/install/ubuntu_install_java.sh index e1f431bee845..aefe2e287e95 100755 --- a/docker/install/ubuntu_install_java.sh +++ b/docker/install/ubuntu_install_java.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -o errexit -o nounset set -o pipefail diff --git a/docker/install/ubuntu_install_keras.sh b/docker/install/ubuntu_install_keras.sh index b689949d0dff..f11629aed6b3 100755 --- a/docker/install/ubuntu_install_keras.sh +++ b/docker/install/ubuntu_install_keras.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_llvm.sh b/docker/install/ubuntu_install_llvm.sh index a562c3258628..944e2ec835a5 100755 --- a/docker/install/ubuntu_install_llvm.sh +++ b/docker/install/ubuntu_install_llvm.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_mxnet.sh b/docker/install/ubuntu_install_mxnet.sh index a15dca7def07..4ee33c46ac39 100755 --- a/docker/install/ubuntu_install_mxnet.sh +++ b/docker/install/ubuntu_install_mxnet.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_nnpack.sh b/docker/install/ubuntu_install_nnpack.sh index 45e2bcb8eccc..4f45f130e2e5 100755 --- a/docker/install/ubuntu_install_nnpack.sh +++ b/docker/install/ubuntu_install_nnpack.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_nodejs.sh b/docker/install/ubuntu_install_nodejs.sh index dfdd0432e4db..681f1b4a4641 100755 --- a/docker/install/ubuntu_install_nodejs.sh +++ b/docker/install/ubuntu_install_nodejs.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_onnx.sh b/docker/install/ubuntu_install_onnx.sh index 11cb2e3f7f60..ec5b7f3b4964 100755 --- a/docker/install/ubuntu_install_onnx.sh +++ b/docker/install/ubuntu_install_onnx.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_opencl.sh b/docker/install/ubuntu_install_opencl.sh index f16de615c4b1..ca6101675307 100755 --- a/docker/install/ubuntu_install_opencl.sh +++ b/docker/install/ubuntu_install_opencl.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_opengl.sh b/docker/install/ubuntu_install_opengl.sh index 82050c14f307..9b8b6057905a 100755 --- a/docker/install/ubuntu_install_opengl.sh +++ b/docker/install/ubuntu_install_opengl.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_python.sh b/docker/install/ubuntu_install_python.sh index 43c27b1b2def..4b1dc377ee87 100755 --- a/docker/install/ubuntu_install_python.sh +++ b/docker/install/ubuntu_install_python.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_python_package.sh b/docker/install/ubuntu_install_python_package.sh index 200fe6e47781..38cf36f237c7 100755 --- a/docker/install/ubuntu_install_python_package.sh +++ b/docker/install/ubuntu_install_python_package.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_redis.sh b/docker/install/ubuntu_install_redis.sh index d079170b0536..9679fddf1894 100755 --- a/docker/install/ubuntu_install_redis.sh +++ b/docker/install/ubuntu_install_redis.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_rocm.sh b/docker/install/ubuntu_install_rocm.sh index be7f2364bf63..196f4134db6e 100755 --- a/docker/install/ubuntu_install_rocm.sh +++ b/docker/install/ubuntu_install_rocm.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_rust.sh b/docker/install/ubuntu_install_rust.sh index f27ba7226179..60368b5b064d 100755 --- a/docker/install/ubuntu_install_rust.sh +++ b/docker/install/ubuntu_install_rust.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_sgx.sh b/docker/install/ubuntu_install_sgx.sh index 45f6e392dbd7..71494062aa2b 100755 --- a/docker/install/ubuntu_install_sgx.sh +++ b/docker/install/ubuntu_install_sgx.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_sphinx.sh b/docker/install/ubuntu_install_sphinx.sh index 50e1e92796c3..bc9caa044f6e 100755 --- a/docker/install/ubuntu_install_sphinx.sh +++ b/docker/install/ubuntu_install_sphinx.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_tensorflow.sh b/docker/install/ubuntu_install_tensorflow.sh index 4fdf9c0d46ab..e14c6ef9af5c 100755 --- a/docker/install/ubuntu_install_tensorflow.sh +++ b/docker/install/ubuntu_install_tensorflow.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_tflite.sh b/docker/install/ubuntu_install_tflite.sh index fc5d0e95356c..d70f9890053d 100755 --- a/docker/install/ubuntu_install_tflite.sh +++ b/docker/install/ubuntu_install_tflite.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/install/ubuntu_install_vulkan.sh b/docker/install/ubuntu_install_vulkan.sh index 6772b029cc90..2a53f8c50803 100755 --- a/docker/install/ubuntu_install_vulkan.sh +++ b/docker/install/ubuntu_install_vulkan.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/docker/with_the_same_user b/docker/with_the_same_user index 09129997e5da..1288afd006c0 100644 --- a/docker/with_the_same_user +++ b/docker/with_the_same_user @@ -1,5 +1,22 @@ #!/usr/bin/env bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # This script is a wrapper creating the same user inside container as the one # running the docker/build.sh outside the container. It also set the home directory # for the user inside container to match the same absolute path as the workspace diff --git a/docs/Doxyfile b/docs/Doxyfile index 5f5a4dbf0ddf..c52e14867a82 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # Doxyfile 1.8.8 # This file describes the settings to be used by the documentation system diff --git a/docs/Makefile b/docs/Makefile index d7a12839ba3d..ca4f6e9a08f0 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # Makefile for Sphinx documentation # diff --git a/docs/api/python/autotvm.rst b/docs/api/python/autotvm.rst index 93d6905077fb..f6a9ff5f6aa8 100644 --- a/docs/api/python/autotvm.rst +++ b/docs/api/python/autotvm.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.autotvm ----------- .. automodule:: tvm.autotvm diff --git a/docs/api/python/bridge.rst b/docs/api/python/bridge.rst index afc7dc298652..72ffaad53efb 100644 --- a/docs/api/python/bridge.rst +++ b/docs/api/python/bridge.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + Framework Bridge APIs --------------------- diff --git a/docs/api/python/build.rst b/docs/api/python/build.rst index 45e0d8983b62..5eee7a5b23c4 100644 --- a/docs/api/python/build.rst +++ b/docs/api/python/build.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.build --------- .. autofunction:: tvm.lower diff --git a/docs/api/python/container.rst b/docs/api/python/container.rst index 66c94e7b0e3d..5de9059a71ac 100644 --- a/docs/api/python/container.rst +++ b/docs/api/python/container.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.container ------------- .. automodule:: tvm.container diff --git a/docs/api/python/contrib.rst b/docs/api/python/contrib.rst index bc566759da99..be0d81aca9fd 100644 --- a/docs/api/python/contrib.rst +++ b/docs/api/python/contrib.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + Additional Contrib APIs ----------------------- .. automodule:: tvm.contrib diff --git a/docs/api/python/dev.rst b/docs/api/python/dev.rst index 3a1804f37d1e..e4b207bf4cbc 100644 --- a/docs/api/python/dev.rst +++ b/docs/api/python/dev.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + Developer API ------------- This page contains modules that are used by developers of TVM. diff --git a/docs/api/python/error.rst b/docs/api/python/error.rst index 3a1a5579fbc4..c32d82599af7 100644 --- a/docs/api/python/error.rst +++ b/docs/api/python/error.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.error --------- .. automodule:: tvm.error diff --git a/docs/api/python/function.rst b/docs/api/python/function.rst index 50a79729bc9a..195e7b54d100 100644 --- a/docs/api/python/function.rst +++ b/docs/api/python/function.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.Function ------------ .. autoclass:: tvm.Function diff --git a/docs/api/python/graph_runtime.rst b/docs/api/python/graph_runtime.rst index 89a223323e14..d82c7ce00e2e 100644 --- a/docs/api/python/graph_runtime.rst +++ b/docs/api/python/graph_runtime.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.contrib.graph_runtime ------------------------- .. automodule:: tvm.contrib.graph_runtime diff --git a/docs/api/python/hybrid.rst b/docs/api/python/hybrid.rst index ac4111cfe768..5acae640d2de 100644 --- a/docs/api/python/hybrid.rst +++ b/docs/api/python/hybrid.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.hybrid ---------- .. automodule:: tvm.hybrid diff --git a/docs/api/python/index.rst b/docs/api/python/index.rst index 16e03a6ca359..2773fefedee3 100644 --- a/docs/api/python/index.rst +++ b/docs/api/python/index.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + Python API ========== diff --git a/docs/api/python/intrin.rst b/docs/api/python/intrin.rst index 3bcf852b31b6..e774bb74bd9a 100644 --- a/docs/api/python/intrin.rst +++ b/docs/api/python/intrin.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.intrin ---------- .. automodule:: tvm.intrin diff --git a/docs/api/python/module.rst b/docs/api/python/module.rst index ac9da32ae7e3..2185d1698d18 100644 --- a/docs/api/python/module.rst +++ b/docs/api/python/module.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.module ---------- .. automodule:: tvm.module diff --git a/docs/api/python/ndarray.rst b/docs/api/python/ndarray.rst index 2c8f0c292a43..d4d0351ea035 100644 --- a/docs/api/python/ndarray.rst +++ b/docs/api/python/ndarray.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.ndarray ----------- .. automodule:: tvm.ndarray diff --git a/docs/api/python/nnvm/compiler.rst b/docs/api/python/nnvm/compiler.rst index 4b995b28cd9e..4cf1b083df60 100644 --- a/docs/api/python/nnvm/compiler.rst +++ b/docs/api/python/nnvm/compiler.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + nnvm.compiler ------------- diff --git a/docs/api/python/nnvm/frontend.rst b/docs/api/python/nnvm/frontend.rst index eb07a13e8340..ca8c4088fd08 100644 --- a/docs/api/python/nnvm/frontend.rst +++ b/docs/api/python/nnvm/frontend.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + nnvm.frontend ------------- diff --git a/docs/api/python/nnvm/graph.rst b/docs/api/python/nnvm/graph.rst index 5b36ab5194fd..e9f667e416e8 100644 --- a/docs/api/python/nnvm/graph.rst +++ b/docs/api/python/nnvm/graph.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + nnvm.graph ---------- .. automodule:: nnvm.graph diff --git a/docs/api/python/nnvm/index.rst b/docs/api/python/nnvm/index.rst index 64447bb793fb..493a8fc1a772 100644 --- a/docs/api/python/nnvm/index.rst +++ b/docs/api/python/nnvm/index.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + NNVM API ======== diff --git a/docs/api/python/nnvm/symbol.rst b/docs/api/python/nnvm/symbol.rst index c341d2ef71d7..46dcac97ddf9 100644 --- a/docs/api/python/nnvm/symbol.rst +++ b/docs/api/python/nnvm/symbol.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + nnvm.symbol ----------- .. automodule:: nnvm.symbol diff --git a/docs/api/python/nnvm/testing.rst b/docs/api/python/nnvm/testing.rst index 56783622648d..9ee72d41b2eb 100644 --- a/docs/api/python/nnvm/testing.rst +++ b/docs/api/python/nnvm/testing.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + nnvm.testing ------------ diff --git a/docs/api/python/nnvm/testing_new_ops.rst b/docs/api/python/nnvm/testing_new_ops.rst index dfe7df485b78..bf80b526a5d5 100644 --- a/docs/api/python/nnvm/testing_new_ops.rst +++ b/docs/api/python/nnvm/testing_new_ops.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + Testing new operations ---------------------- diff --git a/docs/api/python/nnvm/top.rst b/docs/api/python/nnvm/top.rst index fd28ff363f0d..ff946e7639c8 100644 --- a/docs/api/python/nnvm/top.rst +++ b/docs/api/python/nnvm/top.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + nnvm.top -------- .. automodule:: nnvm.top diff --git a/docs/api/python/relay/backend.rst b/docs/api/python/relay/backend.rst index a6085c3232ef..fa6ab883c20d 100644 --- a/docs/api/python/relay/backend.rst +++ b/docs/api/python/relay/backend.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.relay.backend ----------------- diff --git a/docs/api/python/relay/base.rst b/docs/api/python/relay/base.rst index f2d0db409100..a3c52485ab97 100644 --- a/docs/api/python/relay/base.rst +++ b/docs/api/python/relay/base.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.relay.base -------------- .. automodule:: tvm.relay.base diff --git a/docs/api/python/relay/build_module.rst b/docs/api/python/relay/build_module.rst index b33f1870d5a5..28dadea21e78 100644 --- a/docs/api/python/relay/build_module.rst +++ b/docs/api/python/relay/build_module.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.relay.build_module ---------------------- diff --git a/docs/api/python/relay/expr.rst b/docs/api/python/relay/expr.rst index c21e583f042b..f17fc2471725 100644 --- a/docs/api/python/relay/expr.rst +++ b/docs/api/python/relay/expr.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.relay.expr -------------- diff --git a/docs/api/python/relay/frontend.rst b/docs/api/python/relay/frontend.rst index 2a22982a1cdf..90da0a4d2808 100644 --- a/docs/api/python/relay/frontend.rst +++ b/docs/api/python/relay/frontend.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.relay.frontend ------------------ diff --git a/docs/api/python/relay/image.rst b/docs/api/python/relay/image.rst index 862dcbbd1fc7..075edec202ec 100644 --- a/docs/api/python/relay/image.rst +++ b/docs/api/python/relay/image.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.relay.image --------------- diff --git a/docs/api/python/relay/index.rst b/docs/api/python/relay/index.rst index da3d3a912dd0..39a68b6d1f5d 100644 --- a/docs/api/python/relay/index.rst +++ b/docs/api/python/relay/index.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + Relay API ========= diff --git a/docs/api/python/relay/ir_pass.rst b/docs/api/python/relay/ir_pass.rst index d02ef4d94b0a..0102ee9e6119 100644 --- a/docs/api/python/relay/ir_pass.rst +++ b/docs/api/python/relay/ir_pass.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.relay.ir_pass ----------------- .. automodule:: tvm.relay.ir_pass diff --git a/docs/api/python/relay/module.rst b/docs/api/python/relay/module.rst index ec9642b484ba..ae736db0532f 100644 --- a/docs/api/python/relay/module.rst +++ b/docs/api/python/relay/module.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.relay.module ---------------- diff --git a/docs/api/python/relay/nn.rst b/docs/api/python/relay/nn.rst index 8e3f47f7bead..39a1f78592d1 100644 --- a/docs/api/python/relay/nn.rst +++ b/docs/api/python/relay/nn.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.relay.nn ------------ .. automodule:: tvm.relay.nn diff --git a/docs/api/python/relay/op.rst b/docs/api/python/relay/op.rst index 36a7aa00d7b7..4c62a06d0959 100644 --- a/docs/api/python/relay/op.rst +++ b/docs/api/python/relay/op.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.relay.op ------------ .. automodule:: tvm.relay.op diff --git a/docs/api/python/relay/scope_builder.rst b/docs/api/python/relay/scope_builder.rst index 19fca89bf2d2..6d8e01428e31 100644 --- a/docs/api/python/relay/scope_builder.rst +++ b/docs/api/python/relay/scope_builder.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.relay.scope_builder ----------------------- diff --git a/docs/api/python/relay/ty.rst b/docs/api/python/relay/ty.rst index edf15275db03..5bd5321887a5 100644 --- a/docs/api/python/relay/ty.rst +++ b/docs/api/python/relay/ty.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.relay.ty ------------ diff --git a/docs/api/python/relay/vision.rst b/docs/api/python/relay/vision.rst index 7751dd688b15..624c6f177966 100644 --- a/docs/api/python/relay/vision.rst +++ b/docs/api/python/relay/vision.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.relay.vision ---------------- diff --git a/docs/api/python/rpc.rst b/docs/api/python/rpc.rst index 6c4ef59a493c..da7dc83b1889 100644 --- a/docs/api/python/rpc.rst +++ b/docs/api/python/rpc.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.rpc ------- .. automodule:: tvm.rpc diff --git a/docs/api/python/schedule.rst b/docs/api/python/schedule.rst index 59cdceafdf11..c5e902980692 100644 --- a/docs/api/python/schedule.rst +++ b/docs/api/python/schedule.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.schedule ------------ .. automodule:: tvm.schedule diff --git a/docs/api/python/target.rst b/docs/api/python/target.rst index e5723349b5c0..a0f3569c6060 100644 --- a/docs/api/python/target.rst +++ b/docs/api/python/target.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.target ---------- .. automodule:: tvm.target diff --git a/docs/api/python/tensor.rst b/docs/api/python/tensor.rst index dcbc166e7876..032de39bb976 100644 --- a/docs/api/python/tensor.rst +++ b/docs/api/python/tensor.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm.tensor ---------- .. automodule:: tvm.tensor diff --git a/docs/api/python/topi.rst b/docs/api/python/topi.rst index 84ded7b697d1..ce6d9e519ee5 100644 --- a/docs/api/python/topi.rst +++ b/docs/api/python/topi.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + TOPI ---- .. automodule:: topi diff --git a/docs/api/python/tvm.rst b/docs/api/python/tvm.rst index 8700da38273b..a04502b8f9a3 100644 --- a/docs/api/python/tvm.rst +++ b/docs/api/python/tvm.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + tvm --- The user facing API for computation declaration. diff --git a/docs/api/python/vta/index.rst b/docs/api/python/vta/index.rst index 014b789e5aa0..4975032179e4 100644 --- a/docs/api/python/vta/index.rst +++ b/docs/api/python/vta/index.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + VTA API ======= diff --git a/docs/api_links.rst b/docs/api_links.rst index d9b2406206b3..b2a66a5ccd85 100644 --- a/docs/api_links.rst +++ b/docs/api_links.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + Links to API References ================================== diff --git a/docs/conf.py b/docs/conf.py index 0d8b9e34dbbe..e458b5549207 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,22 @@ # -*- coding: utf-8 -*- + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # # documentation build configuration file, created by # sphinx-quickstart on Thu Jul 23 19:40:08 2015. diff --git a/docs/contribute/code_guide.rst b/docs/contribute/code_guide.rst index d7aef2b60d48..f9bd61c375d3 100644 --- a/docs/contribute/code_guide.rst +++ b/docs/contribute/code_guide.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + .. _code_guide: Code Guide and Tips diff --git a/docs/contribute/code_review.rst b/docs/contribute/code_review.rst index d024a82fe90a..920a29c6445e 100644 --- a/docs/contribute/code_review.rst +++ b/docs/contribute/code_review.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + .. _code_review_guide: Perform Code Reviews diff --git a/docs/contribute/committer_guide.rst b/docs/contribute/committer_guide.rst index 8d7e24ff216b..cc89a43aabdb 100644 --- a/docs/contribute/committer_guide.rst +++ b/docs/contribute/committer_guide.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + .. _committer_guide: Committer Guide diff --git a/docs/contribute/community.rst b/docs/contribute/community.rst index 52c9149d453f..d252eedd0659 100644 --- a/docs/contribute/community.rst +++ b/docs/contribute/community.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + .. _community_guide: TVM Community Guideline diff --git a/docs/contribute/document.rst b/docs/contribute/document.rst index ab67fbec9384..5df43adbfdb8 100644 --- a/docs/contribute/document.rst +++ b/docs/contribute/document.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + .. _doc_guide: Write Document and Tutorials diff --git a/docs/contribute/error_handling.rst b/docs/contribute/error_handling.rst index 63af17f6d287..152f613b8002 100644 --- a/docs/contribute/error_handling.rst +++ b/docs/contribute/error_handling.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + .. _error_guide: Error Handling Guide diff --git a/docs/contribute/git_howto.md b/docs/contribute/git_howto.md index 53ff89b127df..725ed0bc87ba 100644 --- a/docs/contribute/git_howto.md +++ b/docs/contribute/git_howto.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + # Git Usage Tips Here are some tips for git workflow. diff --git a/docs/contribute/index.rst b/docs/contribute/index.rst index a8a227b1e1c8..67d3b2041fec 100644 --- a/docs/contribute/index.rst +++ b/docs/contribute/index.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + Contribute to TVM ================= diff --git a/docs/contribute/pull_request.rst b/docs/contribute/pull_request.rst index d05fd0d2b2e9..96d4a99b6844 100644 --- a/docs/contribute/pull_request.rst +++ b/docs/contribute/pull_request.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + Submit a Pull Request ===================== diff --git a/docs/deploy/android.md b/docs/deploy/android.md index ca431693c63a..3e8c1293fb0f 100644 --- a/docs/deploy/android.md +++ b/docs/deploy/android.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + # Deploy to Android diff --git a/docs/deploy/aocl_fpga.md b/docs/deploy/aocl_fpga.md index c9c50dc56be6..71d9d0cb7485 100644 --- a/docs/deploy/aocl_fpga.md +++ b/docs/deploy/aocl_fpga.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + AOCL Backend Example ==================== diff --git a/docs/deploy/aws_fpga.md b/docs/deploy/aws_fpga.md index 9d8af7d97a94..97101efb7241 100644 --- a/docs/deploy/aws_fpga.md +++ b/docs/deploy/aws_fpga.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + HLS Backend Example =================== diff --git a/docs/deploy/cpp_deploy.md b/docs/deploy/cpp_deploy.md index d02d33d18694..3fc5732613c3 100644 --- a/docs/deploy/cpp_deploy.md +++ b/docs/deploy/cpp_deploy.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + Deploy TVM Module using C++ API =============================== diff --git a/docs/deploy/index.rst b/docs/deploy/index.rst index 0ef5cf5c8246..0dd1886b7ff2 100644 --- a/docs/deploy/index.rst +++ b/docs/deploy/index.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + .. _deploy-and-integration: Deploy and Integration diff --git a/docs/deploy/integrate.md b/docs/deploy/integrate.md index b6f3b1faa3da..42896149d283 100644 --- a/docs/deploy/integrate.md +++ b/docs/deploy/integrate.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + Integrate TVM into Your Project =============================== diff --git a/docs/deploy/nnvm.md b/docs/deploy/nnvm.md index 1e0d17f8b195..7299b3fae0db 100644 --- a/docs/deploy/nnvm.md +++ b/docs/deploy/nnvm.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + # Deploy NNVM Modules NNVM compiled modules are fully embedded in TVM runtime as long as ```GRAPH_RUNTIME``` option is enabled in tvm runtime. diff --git a/docs/dev/codebase_walkthrough.rst b/docs/dev/codebase_walkthrough.rst index 6f5cff8a06d6..956519b764a4 100644 --- a/docs/dev/codebase_walkthrough.rst +++ b/docs/dev/codebase_walkthrough.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + ======================================= **TVM Codebase Walkthrough by Example** ======================================= diff --git a/docs/dev/debugger.rst b/docs/dev/debugger.rst index a2a850a2dde4..254a82def6b8 100644 --- a/docs/dev/debugger.rst +++ b/docs/dev/debugger.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + ================= **Debugger** ================= diff --git a/docs/dev/hybrid_script.rst b/docs/dev/hybrid_script.rst index 0af02a56e72c..49c697728eeb 100644 --- a/docs/dev/hybrid_script.rst +++ b/docs/dev/hybrid_script.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + Hybrid Frontend Developer Guide =============================== diff --git a/docs/dev/index.rst b/docs/dev/index.rst index 3f4944fe1d52..0bf5cfb0de60 100644 --- a/docs/dev/index.rst +++ b/docs/dev/index.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + Design and Developer Guide ========================== diff --git a/docs/dev/nnvm_json_spec.rst b/docs/dev/nnvm_json_spec.rst index 31f2d2dc5c07..60d1b9b12bfe 100644 --- a/docs/dev/nnvm_json_spec.rst +++ b/docs/dev/nnvm_json_spec.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + NNVM Graph JSON Specification ============================= diff --git a/docs/dev/nnvm_overview.md b/docs/dev/nnvm_overview.md index 4f01fdda2a03..a34d71846918 100644 --- a/docs/dev/nnvm_overview.md +++ b/docs/dev/nnvm_overview.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + # NNVM Design Overview diff --git a/docs/dev/relay_add_op.rst b/docs/dev/relay_add_op.rst index 009adc7a2468..c17e8318bc1f 100644 --- a/docs/dev/relay_add_op.rst +++ b/docs/dev/relay_add_op.rst @@ -1,147 +1,164 @@ -.. _relay-add-op: - -Adding an Operator to Relay -=========================== - -In order to use TVM operators from within the Relay IR, the -operators need to be registered in Relay in order to ensure -that they will be integrated into Relay's type system. - -Registering an operator requires three steps: - -- Using the ``RELAY_REGISTER_OP`` macro in C++ to register the operator's arity and type information -- Defining a C++ function to produce a call node for the operator and registering a Python API hook for the function -- Wrapping the above Python API hook in a neater interface - -The file ``src/relay/op/tensor/binary.cc`` provides -examples of the first two steps, while -``python/tvm/relay/op/tensor.py`` gives examples of the -last. - -Registering an Operator ------------------------ - -TVM already has an operator registry, but Relay cannot properly -incorporate TVM operators without additional type information. - -To allow for flexibility in registering operators and greater -expressivity and granularity in expressing types in Relay, operators -are typed using relations between input and output types. These relations -are represented as functions that take in a list of input types and -output types (any of these types may be incomplete) and return a list -of input and output types that satisfies the relation. Essentially, a -relation for an operator can enforce all the necessary typing rules -(namely by inspecting the input types) in addition to computing the -output type. - -For example, see ``src/relay/op/type_relations.h`` and their -implementations. E.g., ``BroadcastRel`` takes two input types and an -output type, checks that they are all tensor types with the same underlying -data type, and finally ensures that the shape of the output type is the -broadcast of the input types' shapes. - -It may be necessary to add another type relation to ``type_relations.h`` -if the existing ones do not capture the behavior of the desired operator. - -The ``RELAY_REGISTER_OP`` macro in C++ allows a developer -to specify the following information about an operator in Relay: - -- Arity (number of arguments) -- Names and descriptions for positional arguments -- Support level (1 indicates an internal intrinsic; higher numbers indicate less integral or externally supported operators) -- A type relation for the operator - -The below example is from ``binary.cc`` and uses a broadcasting -add for tensors: - -.. code:: c - - RELAY_REGISTER_OP("add") - .set_num_inputs(2) - .add_argument("lhs", "Tensor", "The left hand side tensor.") - .add_argument("rhs", "Tensor", "The right hand side tensor.") - .set_support_level(1) - .add_type_rel("Broadcast", BroadcastRel); - -Creating a Call Node --------------------- - -This step requires simply writing a function that takes -the arguments to the operator (as Relay expressions) and -returning a call node to the operator (i.e., the node that -should be placed into the Relay AST where the call to the -operator is intended). - -At present call attributes and type arguments (the last two fields) -are not supported, so it suffices to use ``Op::Get`` to fetch -the operator's information from the operator registry and pass in -the arguments to the call node, as below. - -.. code:: c - - TVM_REGISTER_API("relay.op._make.add") - .set_body_typed([](Expr lhs, Expr rhs) { - static const Op& op = Op::Get("add"); - return CallNode::make(op, {lhs, rhs}, Attrs(), {}); - }); - -Including a Python API Hook ---------------------------- - -It is generally the convention in Relay, that functions exported -through ``TVM_REGISTER_API`` should be wrapped in a separate -Python function rather than called directly in Python. In the case -of the functions that produce calls to operators, it may be convenient -to bundle them, as in ``python/tvm/relay/op/tensor.py``, where -elementwise operators on tensors are all provided. For example, -the following is how the add function from the previous section is -exposed in Python: - -.. code:: python - - def add(lhs, rhs): - """Elementwise addition. - - Parameters - ---------- - lhs : relay.Expr - The left hand side input data - rhs : relay.Expr - The right hand side input data - - Returns - ------- - result : relay.Expr - The computed result. - """ - return _make.add(lhs, rhs) - -Note that these Python wrappers might also be good opportunities to -provide an easier interface to the operator. For example, the -``concat`` operator is registered as taking only one operator, -namely a tuple with the tensors to be concatenated, but the Python -wrapper takes the tensors as arguments and combines them into a tuple -before producing the call node: - -.. code:: python - - def concat(*args): - """Concatenate the input tensors along the zero axis. - - Parameters - ---------- - args: list of Tensor - - Returns - ------- - tensor: The concatenated tensor. - """ - tup = Tuple(list(args)) - return _make.concat(tup) - -Summary -------- - -- A TVM operator can be registered in Relay using a relation to express the appropriate type information. -- Using an operator in Relay requires a function to produce a call node for the operator. -- It is best to have a simple Python wrapper for producing the call node. +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +.. _relay-add-op: + +Adding an Operator to Relay +=========================== + +In order to use TVM operators from within the Relay IR, the +operators need to be registered in Relay in order to ensure +that they will be integrated into Relay's type system. + +Registering an operator requires three steps: + +- Using the ``RELAY_REGISTER_OP`` macro in C++ to register the operator's arity and type information +- Defining a C++ function to produce a call node for the operator and registering a Python API hook for the function +- Wrapping the above Python API hook in a neater interface + +The file ``src/relay/op/tensor/binary.cc`` provides +examples of the first two steps, while +``python/tvm/relay/op/tensor.py`` gives examples of the +last. + +Registering an Operator +----------------------- + +TVM already has an operator registry, but Relay cannot properly +incorporate TVM operators without additional type information. + +To allow for flexibility in registering operators and greater +expressivity and granularity in expressing types in Relay, operators +are typed using relations between input and output types. These relations +are represented as functions that take in a list of input types and +output types (any of these types may be incomplete) and return a list +of input and output types that satisfies the relation. Essentially, a +relation for an operator can enforce all the necessary typing rules +(namely by inspecting the input types) in addition to computing the +output type. + +For example, see ``src/relay/op/type_relations.h`` and their +implementations. E.g., ``BroadcastRel`` takes two input types and an +output type, checks that they are all tensor types with the same underlying +data type, and finally ensures that the shape of the output type is the +broadcast of the input types' shapes. + +It may be necessary to add another type relation to ``type_relations.h`` +if the existing ones do not capture the behavior of the desired operator. + +The ``RELAY_REGISTER_OP`` macro in C++ allows a developer +to specify the following information about an operator in Relay: + +- Arity (number of arguments) +- Names and descriptions for positional arguments +- Support level (1 indicates an internal intrinsic; higher numbers indicate less integral or externally supported operators) +- A type relation for the operator + +The below example is from ``binary.cc`` and uses a broadcasting +add for tensors: + +.. code:: c + + RELAY_REGISTER_OP("add") + .set_num_inputs(2) + .add_argument("lhs", "Tensor", "The left hand side tensor.") + .add_argument("rhs", "Tensor", "The right hand side tensor.") + .set_support_level(1) + .add_type_rel("Broadcast", BroadcastRel); + +Creating a Call Node +-------------------- + +This step requires simply writing a function that takes +the arguments to the operator (as Relay expressions) and +returning a call node to the operator (i.e., the node that +should be placed into the Relay AST where the call to the +operator is intended). + +At present call attributes and type arguments (the last two fields) +are not supported, so it suffices to use ``Op::Get`` to fetch +the operator's information from the operator registry and pass in +the arguments to the call node, as below. + +.. code:: c + + TVM_REGISTER_API("relay.op._make.add") + .set_body_typed([](Expr lhs, Expr rhs) { + static const Op& op = Op::Get("add"); + return CallNode::make(op, {lhs, rhs}, Attrs(), {}); + }); + +Including a Python API Hook +--------------------------- + +It is generally the convention in Relay, that functions exported +through ``TVM_REGISTER_API`` should be wrapped in a separate +Python function rather than called directly in Python. In the case +of the functions that produce calls to operators, it may be convenient +to bundle them, as in ``python/tvm/relay/op/tensor.py``, where +elementwise operators on tensors are all provided. For example, +the following is how the add function from the previous section is +exposed in Python: + +.. code:: python + + def add(lhs, rhs): + """Elementwise addition. + + Parameters + ---------- + lhs : relay.Expr + The left hand side input data + rhs : relay.Expr + The right hand side input data + + Returns + ------- + result : relay.Expr + The computed result. + """ + return _make.add(lhs, rhs) + +Note that these Python wrappers might also be good opportunities to +provide an easier interface to the operator. For example, the +``concat`` operator is registered as taking only one operator, +namely a tuple with the tensors to be concatenated, but the Python +wrapper takes the tensors as arguments and combines them into a tuple +before producing the call node: + +.. code:: python + + def concat(*args): + """Concatenate the input tensors along the zero axis. + + Parameters + ---------- + args: list of Tensor + + Returns + ------- + tensor: The concatenated tensor. + """ + tup = Tuple(list(args)) + return _make.concat(tup) + +Summary +------- + +- A TVM operator can be registered in Relay using a relation to express the appropriate type information. +- Using an operator in Relay requires a function to produce a call node for the operator. +- It is best to have a simple Python wrapper for producing the call node. diff --git a/docs/dev/relay_intro.rst b/docs/dev/relay_intro.rst index 1505dd00327f..526822afe422 100644 --- a/docs/dev/relay_intro.rst +++ b/docs/dev/relay_intro.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + .. _relay-dev-intro: Introduction to Relay IR diff --git a/docs/dev/runtime.md b/docs/dev/runtime.md index a5d8138c3372..317ba5d54e75 100644 --- a/docs/dev/runtime.md +++ b/docs/dev/runtime.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + # TVM Runtime System TVM supports multiple programming languages for the compiler stack development and deployment. diff --git a/docs/faq.md b/docs/faq.md index 9b735e54d5dd..74fc82e3bda0 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + Frequently Asked Questions ========================== This document contains frequently asked questions. diff --git a/docs/frontend/tensorflow.md b/docs/frontend/tensorflow.md index d47923bdd938..06a6fcc32b4f 100644 --- a/docs/frontend/tensorflow.md +++ b/docs/frontend/tensorflow.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + # Tensorflow Frontend Tensorflow frontend helps in importing tensorflow released model into TVM. diff --git a/docs/genindex.rst b/docs/genindex.rst index 9e530fa2fd58..662b67f2259e 100644 --- a/docs/genindex.rst +++ b/docs/genindex.rst @@ -1,2 +1,19 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + Index ===== diff --git a/docs/index.rst b/docs/index.rst index 20e64bfef641..9666fff0c5d3 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + TVM Documentation ================= diff --git a/docs/install/docker.rst b/docs/install/docker.rst index 8d089522761d..47503e70be97 100644 --- a/docs/install/docker.rst +++ b/docs/install/docker.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + .. _docker-images: Docker Images diff --git a/docs/install/from_source.rst b/docs/install/from_source.rst index 5c828957cc79..62f669ec77b4 100644 --- a/docs/install/from_source.rst +++ b/docs/install/from_source.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + .. _install-from-source: Install from Source diff --git a/docs/install/index.rst b/docs/install/index.rst index cc39f2433c7e..560811b5f78e 100644 --- a/docs/install/index.rst +++ b/docs/install/index.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + Installation ============ To install TVM, please read :ref:`install-from-source`. diff --git a/docs/install/nnpack.md b/docs/install/nnpack.md index d4e6e39e4023..035cf6029f09 100644 --- a/docs/install/nnpack.md +++ b/docs/install/nnpack.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + # NNPACK Contrib Installation [NNPACK](https://github.com/Maratyszcza/NNPACK) is an acceleration package diff --git a/docs/langref/hybrid_script.rst b/docs/langref/hybrid_script.rst index 9e80d5ba72ff..4a3707fdaee8 100644 --- a/docs/langref/hybrid_script.rst +++ b/docs/langref/hybrid_script.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + .. _hybrid-langref-label: Hybrid Frontend Language Reference diff --git a/docs/langref/index.rst b/docs/langref/index.rst index e586a052e4e4..0d296118da26 100644 --- a/docs/langref/index.rst +++ b/docs/langref/index.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + Language Reference ================== This document provides references to diff --git a/docs/langref/relay_adt.rst b/docs/langref/relay_adt.rst index 3ca2eab84434..e487684063ac 100644 --- a/docs/langref/relay_adt.rst +++ b/docs/langref/relay_adt.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + .. _adt-overview: ============================= diff --git a/docs/langref/relay_expr.rst b/docs/langref/relay_expr.rst index efa74d314198..a9f1cf8f18ba 100644 --- a/docs/langref/relay_expr.rst +++ b/docs/langref/relay_expr.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + ==================== Expressions in Relay ==================== diff --git a/docs/langref/relay_op.rst b/docs/langref/relay_op.rst index bbb27ec83b48..9bdac71b6ee4 100644 --- a/docs/langref/relay_op.rst +++ b/docs/langref/relay_op.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + Relay Core Tensor Operators =========================== @@ -92,6 +109,7 @@ This level enables additional math and transform operators. tvm.relay.zeros_like tvm.relay.ones tvm.relay.ones_like + tvm.relay.gather_nd tvm.relay.full tvm.relay.full_like tvm.relay.cast @@ -225,6 +243,7 @@ Level 3 Definitions .. autofunction:: tvm.relay.zeros_like .. autofunction:: tvm.relay.ones .. autofunction:: tvm.relay.ones_like +.. autofunction:: tvm.relay.gather_nd .. autofunction:: tvm.relay.full .. autofunction:: tvm.relay.full_like .. autofunction:: tvm.relay.cast diff --git a/docs/langref/relay_type.rst b/docs/langref/relay_type.rst index 45217b234e76..7c2497db33e8 100644 --- a/docs/langref/relay_type.rst +++ b/docs/langref/relay_type.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + =================== Relay's Type System =================== diff --git a/docs/nnvm_top.rst b/docs/nnvm_top.rst index f05eed3308b3..8679cae9b256 100644 --- a/docs/nnvm_top.rst +++ b/docs/nnvm_top.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + NNVM Core Tensor Operators ========================== diff --git a/docs/vta/dev/config.rst b/docs/vta/dev/config.rst index 5b0ee966872b..0ca6b99759c0 100644 --- a/docs/vta/dev/config.rst +++ b/docs/vta/dev/config.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + VTA Configuration ================= diff --git a/docs/vta/dev/hardware.rst b/docs/vta/dev/hardware.rst index ba7e07d8e44d..7ec073b7d905 100644 --- a/docs/vta/dev/hardware.rst +++ b/docs/vta/dev/hardware.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + VTA Hardware Guide ================== diff --git a/docs/vta/dev/index.rst b/docs/vta/dev/index.rst index 788bafe34b3e..575a9d4b2c51 100644 --- a/docs/vta/dev/index.rst +++ b/docs/vta/dev/index.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + VTA Design and Developer Guide ============================== diff --git a/docs/vta/hardware.rst b/docs/vta/hardware.rst index 294b99a8269f..cfd7be333081 100644 --- a/docs/vta/hardware.rst +++ b/docs/vta/hardware.rst @@ -1,2 +1,19 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + VTA Hardware Design Overview ============================ diff --git a/docs/vta/index.rst b/docs/vta/index.rst index d29dd9f2ffcf..9dc281da5715 100644 --- a/docs/vta/index.rst +++ b/docs/vta/index.rst @@ -1,3 +1,20 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + VTA: Deep Learning Accelerator Stack ==================================== diff --git a/docs/vta/install.md b/docs/vta/install.md index 4a05f9fd8318..233bb5ca0260 100644 --- a/docs/vta/install.md +++ b/docs/vta/install.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + VTA Installation Guide ====================== diff --git a/golang/Makefile b/golang/Makefile index 54019740c87a..c54fd0e0992c 100644 --- a/golang/Makefile +++ b/golang/Makefile @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + .PHONY: clean all TVM_BASE = $(CURDIR)/../ diff --git a/golang/README.md b/golang/README.md index 9c152dd7365c..fe0dc621a469 100644 --- a/golang/README.md +++ b/golang/README.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + # gotvm - Golang Frontend for TVM Runtime This folder contain golang interface for TVM runtime. It brings TVM runtime to Golang. @@ -47,7 +64,7 @@ make samples To Demonstrates sample TVM module compilation using python and deploy via golang. ```bash ./simple -``` +``` To deploy a realtime module with lib, graph and param. ```bash diff --git a/golang/sample/Makefile b/golang/sample/Makefile index 8ebea49da42f..5d9781d05bd6 100644 --- a/golang/sample/Makefile +++ b/golang/sample/Makefile @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + .PHONY: clean all SOURCES=$(wildcard *.go) diff --git a/golang/sample/complex.go b/golang/sample/complex.go index 7a8d0044375c..96bab6adc2a8 100644 --- a/golang/sample/complex.go +++ b/golang/sample/complex.go @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief Sample golang application deployment over tvm. diff --git a/golang/sample/deploy.py b/golang/sample/deploy.py index 065638299bc6..3b221369dbc4 100644 --- a/golang/sample/deploy.py +++ b/golang/sample/deploy.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Get Started with TVM Go ======================= diff --git a/golang/sample/pack_func_closure_arg.go b/golang/sample/pack_func_closure_arg.go index b31113160586..da38bc7e2d16 100644 --- a/golang/sample/pack_func_closure_arg.go +++ b/golang/sample/pack_func_closure_arg.go @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief Sample golang application to demonstrate go-closure given to a packed function argument. diff --git a/golang/sample/pack_func_closure_return.go b/golang/sample/pack_func_closure_return.go index 98de8e2e5146..cea14a80c00e 100644 --- a/golang/sample/pack_func_closure_return.go +++ b/golang/sample/pack_func_closure_return.go @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief Sample golang application to demonstrate go-closure returned from a callback function. diff --git a/golang/sample/pack_func_convert.go b/golang/sample/pack_func_convert.go index 6748d67fe75f..6a9c9d586aad 100644 --- a/golang/sample/pack_func_convert.go +++ b/golang/sample/pack_func_convert.go @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief Sample golang application to demonstrate function conversion to packed function. diff --git a/golang/sample/pack_func_handle_arg.go b/golang/sample/pack_func_handle_arg.go index ad1313f93f5f..9e6a44d27cea 100644 --- a/golang/sample/pack_func_handle_arg.go +++ b/golang/sample/pack_func_handle_arg.go @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief Sample golang application to demonstrate converted packed diff --git a/golang/sample/pack_func_register.go b/golang/sample/pack_func_register.go index 5da67e00c16c..8c82528e091c 100644 --- a/golang/sample/pack_func_register.go +++ b/golang/sample/pack_func_register.go @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief Sample golang application to demonstrate function register into TVM global functions. diff --git a/golang/sample/simple.go b/golang/sample/simple.go index ada3963662de..329520096ffb 100644 --- a/golang/sample/simple.go +++ b/golang/sample/simple.go @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief Sample golang application deployment over tvm. diff --git a/golang/src/array_test.go b/golang/src/array_test.go index 6917dd14e373..e7a283d7329f 100644 --- a/golang/src/array_test.go +++ b/golang/src/array_test.go @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief gotvm package diff --git a/golang/src/bytearray.go b/golang/src/bytearray.go index e40a630223dc..6fe305fc5c41 100644 --- a/golang/src/bytearray.go +++ b/golang/src/bytearray.go @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief gotvm package source for TVMByteArray interface. @@ -14,7 +33,7 @@ import ( ) // ByteArray type wraps the TVMByteArray of C runtime API. -// +// // This can be used to hold raw data like params of a model. type ByteArray uintptr diff --git a/golang/src/bytearray_test.go b/golang/src/bytearray_test.go index f49e75ee2fa6..b61137ee5b76 100644 --- a/golang/src/bytearray_test.go +++ b/golang/src/bytearray_test.go @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief gotvm package diff --git a/golang/src/context.go b/golang/src/context.go index 8a3b613ea6b9..1e1668ea2f9b 100644 --- a/golang/src/context.go +++ b/golang/src/context.go @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief gotvm package source for TVMContext interface diff --git a/golang/src/error.go b/golang/src/error.go index 00a24652953c..1679a2afc073 100644 --- a/golang/src/error.go +++ b/golang/src/error.go @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief gotvm package source for error related API interface. diff --git a/golang/src/error_test.go b/golang/src/error_test.go index 2a8c345b424b..2fc3ceb19575 100644 --- a/golang/src/error_test.go +++ b/golang/src/error_test.go @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief gotvm package @@ -25,4 +44,3 @@ func TestErrorTest(t *testing.T) { t.Error("Ah! TVM didn't report an error\n") } } - diff --git a/golang/src/function.go b/golang/src/function.go index fa1c53a5917f..783032494829 100644 --- a/golang/src/function.go +++ b/golang/src/function.go @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief gotvm package source for TVMFunction interface. @@ -259,13 +278,13 @@ func goTVMCallback(args C.native_voidp, typeCodes C.native_voidp, numArgs int32, return -1 } - // It's possible a packed function directly return + // It's possible a packed function directly return // the return value of another packed function. // // Inside a packed func : // ```return pfunc.Invoke(args)``` // - // In this case pfunc returns nil which is + // In this case pfunc returns nil which is // returned as an interface holding nil *Value. // Which becomes a valid retVal holding nil *Value. isRetNull := false diff --git a/golang/src/function_test.go b/golang/src/function_test.go index b91503f0f645..2895ea6b77b4 100644 --- a/golang/src/function_test.go +++ b/golang/src/function_test.go @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief gotvm package diff --git a/golang/src/gotvm.cc b/golang/src/gotvm.cc index cf84e670df79..adb93d3f76a1 100644 --- a/golang/src/gotvm.cc +++ b/golang/src/gotvm.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief gotvm native interface definition @@ -192,4 +211,3 @@ int _ConvertFunction(void* fptr, TVMFunctionHandle *fhandle) { #ifdef __cplusplus } #endif - diff --git a/golang/src/gotvm.go b/golang/src/gotvm.go index 3f7aac93d769..17d178fd2309 100644 --- a/golang/src/gotvm.go +++ b/golang/src/gotvm.go @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief gotvm package diff --git a/golang/src/gotvm.h b/golang/src/gotvm.h index e4487a362cca..97b844ea09ff 100644 --- a/golang/src/gotvm.h +++ b/golang/src/gotvm.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief gotvm native interface declaration. diff --git a/golang/src/gotvm_test.go b/golang/src/gotvm_test.go index 5058de400ba7..6ee80f629795 100644 --- a/golang/src/gotvm_test.go +++ b/golang/src/gotvm_test.go @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief gotvm package diff --git a/golang/src/module.go b/golang/src/module.go index 422cb6be20ff..c58590e45ee1 100644 --- a/golang/src/module.go +++ b/golang/src/module.go @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief gotvm package source for TVMModule interface. diff --git a/golang/src/module_test.go b/golang/src/module_test.go index fac094438e96..51fbfe125369 100644 --- a/golang/src/module_test.go +++ b/golang/src/module_test.go @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief gotvm package @@ -90,4 +109,3 @@ func TestModuleTestLoadErr(t *testing.T) { return } } - diff --git a/golang/src/ndarray.go b/golang/src/ndarray.go index 409cf86e6e87..548e48d0fbdf 100644 --- a/golang/src/ndarray.go +++ b/golang/src/ndarray.go @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief gotvm package source for TVMArray aka DLTensor diff --git a/golang/src/tvm_runtime_pack.cc b/golang/src/tvm_runtime_pack.cc index 718a79eb7445..70376cb166da 100644 --- a/golang/src/tvm_runtime_pack.cc +++ b/golang/src/tvm_runtime_pack.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief This is an all in one TVM runtime file. diff --git a/golang/src/type.go b/golang/src/type.go index 27364295bf8b..9d5f58b755ec 100644 --- a/golang/src/type.go +++ b/golang/src/type.go @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief gotvm package for TVMType interface diff --git a/golang/src/util.go b/golang/src/util.go index aa5a6016c97f..1c82443bfa1e 100644 --- a/golang/src/util.go +++ b/golang/src/util.go @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief gotvm package source for common utilities diff --git a/golang/src/value.go b/golang/src/value.go index c51805082beb..576331a8cfa0 100644 --- a/golang/src/value.go +++ b/golang/src/value.go @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief gotvm package source for TVMValue interface diff --git a/golang/src/value_test.go b/golang/src/value_test.go index 251af82cb7b9..16bce2a68e9d 100644 --- a/golang/src/value_test.go +++ b/golang/src/value_test.go @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief gotvm package diff --git a/include/tvm/api_registry.h b/include/tvm/api_registry.h index ca427e027636..e12d841519ca 100644 --- a/include/tvm/api_registry.h +++ b/include/tvm/api_registry.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2017 by Contributors * \file tvm/api_registry.h * \brief This file contains utilities related to * the TVM's global function registry. diff --git a/include/tvm/arithmetic.h b/include/tvm/arithmetic.h index d023f8f1cf7e..fe3dca483acb 100644 --- a/include/tvm/arithmetic.h +++ b/include/tvm/arithmetic.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2016 by Contributors * \file tvm/arithmetic.h * \brief Algebra and set operations and simplifications. */ @@ -218,6 +236,7 @@ class RewriteSimplifier { private: friend class Analyzer; friend class ConstraintContext; + friend class CanonicalSimplifier; explicit RewriteSimplifier(Analyzer* parent); ~RewriteSimplifier(); class Impl; @@ -225,6 +244,39 @@ class RewriteSimplifier { Impl* impl_; }; +/*! + * \brief Canonical-form based simplifier. + */ +class CanonicalSimplifier { + public: + /*! + * \brief analyze the expr + * \param expr The expression of interest. + * \return the result of the analysis. + */ + Expr operator()(const Expr& expr); + + /*! + * \brief Update binding of var to a new expression. + * + * \param var The variable of interest. + * \param new_expr + * \param override Whether do we allow override of existing information. + */ + void Update(const Var& var, + const Expr& new_expr, + bool override = false); + + private: + friend class Analyzer; + friend class ConstraintContext; + explicit CanonicalSimplifier(Analyzer* parent); + ~CanonicalSimplifier(); + class Impl; + /*! \brief Internal impl */ + Impl* impl_; +}; + /*! * \brief A RAII constraint context. * @@ -277,6 +329,8 @@ class Analyzer { ModularSetAnalyzer modular_set; /*! \brief sub-analyzer rewrite simplfy */ RewriteSimplifier rewrite_simplify; + /*! \brief sub-analyzer rewrite simplfy */ + CanonicalSimplifier canonical_simplify; /*! \brief constructor */ Analyzer(); /*! diff --git a/include/tvm/attrs.h b/include/tvm/attrs.h index 33edba241271..ed021beb5d35 100644 --- a/include/tvm/attrs.h +++ b/include/tvm/attrs.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2018 by Contributors * \file tvm/attrs.h * \brief TVM attribute module * diff --git a/include/tvm/base.h b/include/tvm/base.h index 7104688aa169..ae2d91ff8523 100644 --- a/include/tvm/base.h +++ b/include/tvm/base.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2016 by Contributors * \file tvm/base.h * \brief Defines the base data structure */ @@ -12,6 +30,7 @@ #include #include #include +#include #include "runtime/registry.h" namespace tvm { @@ -32,6 +51,44 @@ using ::tvm::AttrVisitor; using ContainerType = NodeName; \ }; \ +/*! + * \brief Macro to make it easy to define node ref type that + * has a CopyOnWrite member function. + * + * CopyOnWrite will generate a unique copy of the internal node. + * The node will be copied if it is referenced by multiple places. + * The function returns the raw pointer to the node to allow modification + * of the content. + * + * \code + * + * MyCOWNodeRef ref, ref2; + * ref2 = ref; + * ref.CopyOnWrite()->value = new_value; + * assert(ref2->value == old_value); + * assert(ref->value == new_value); + * + * \endcode + */ +#define TVM_DEFINE_COW_NODE_REF(TypeName, BaseType, NodeName) \ + class TypeName : public BaseType { \ + public: \ + TypeName() {} \ + explicit TypeName(::tvm::NodePtr<::tvm::Node> n) : BaseType(n) {} \ + const NodeName* operator->() const { \ + return static_cast(node_.get()); \ + } \ + inline NodeName* CopyOnWrite() { \ + CHECK(node_ != nullptr); \ + if (!node_.unique()) { \ + NodePtr n = make_node(*(operator->())); \ + NodePtr(std::move(n)).swap(node_); \ + } \ + return static_cast(node_.get()); \ + } \ + using ContainerType = NodeName; \ + }; + /*! * \brief save the node as well as all the node it depends on as json. diff --git a/include/tvm/buffer.h b/include/tvm/buffer.h index d95332c245b7..ed4ac5ea6a63 100644 --- a/include/tvm/buffer.h +++ b/include/tvm/buffer.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2016 by Contributors * \file tvm/buffer.h * \brief Symbolic n-dimensional array, to represent a memory buffer. */ diff --git a/include/tvm/build_module.h b/include/tvm/build_module.h index 86217ba10e76..3c136444229b 100644 --- a/include/tvm/build_module.h +++ b/include/tvm/build_module.h @@ -1,8 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! -* Copyright (c) 2017 by Contributors -* \file tvm/build_module.h -* \brief Functions for compiling ops. -*/ + * \file tvm/build_module.h + * \brief Functions for compiling ops. + */ #ifndef TVM_BUILD_MODULE_H_ #define TVM_BUILD_MODULE_H_ @@ -431,7 +449,7 @@ inline runtime::TVMRetValue GenericFunc::operator()(Args&& ...args) const { const int kArraySize = kNumArgs > 0 ? kNumArgs : 1; TVMValue values[kArraySize]; int type_codes[kArraySize]; - runtime::detail::for_each(TVMArgsSetter(values, type_codes), + runtime::detail::for_each(runtime::TVMArgsSetter(values, type_codes), std::forward(args)...); runtime::TVMRetValue rv; CallPacked(TVMArgs(values, type_codes, kNumArgs), &rv); diff --git a/include/tvm/c_dsl_api.h b/include/tvm/c_dsl_api.h index 027a3952d9d4..bbbb84926e8e 100644 --- a/include/tvm/c_dsl_api.h +++ b/include/tvm/c_dsl_api.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2016 by Contributors * \file tvm/c_dsl_api.h * * \brief TVM DSL Node C API, used to interact to DSL compilation. diff --git a/include/tvm/channel.h b/include/tvm/channel.h index 051b57a194c4..143d4295f3e3 100644 --- a/include/tvm/channel.h +++ b/include/tvm/channel.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2017 by Contributors * \file tvm/channel.h * \brief Channel object for pipeline. */ diff --git a/include/tvm/codegen.h b/include/tvm/codegen.h index fca88de6a238..2f4058eb354b 100644 --- a/include/tvm/codegen.h +++ b/include/tvm/codegen.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2016 by Contributors * \file tvm/codegen.h * \brief Collection of Lowlevel IR pass to codegen. */ diff --git a/include/tvm/data_layout.h b/include/tvm/data_layout.h index 3f5cb9a29546..ed61fd3903b1 100644 --- a/include/tvm/data_layout.h +++ b/include/tvm/data_layout.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2019 by Contributors * \file tvm/data_layout.h * \brief Layout expression to describe the data organization of a tensor. * And BijectiveLayout to mapping two data layouts between each other. diff --git a/include/tvm/expr.h b/include/tvm/expr.h index fd4f6024bb4d..57cd4fdadd75 100644 --- a/include/tvm/expr.h +++ b/include/tvm/expr.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2016 by Contributors * \file tvm/expr.h * \brief The Expr and related elements in DataFlow construction. */ diff --git a/include/tvm/expr_operator.h b/include/tvm/expr_operator.h index c4d2d555f3a3..25da5d0e4bf4 100644 --- a/include/tvm/expr_operator.h +++ b/include/tvm/expr_operator.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2018 by Contributors * \file tvm/expr_operator.h * \brief Common operators defined for Expr. * diff --git a/include/tvm/ir.h b/include/tvm/ir.h index 0f05c98e0722..e0c6297d5d03 100644 --- a/include/tvm/ir.h +++ b/include/tvm/ir.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2016 by Contributors * \file tvm/ir.h * \brief Additional high level nodes in the IR */ diff --git a/include/tvm/ir_functor_ext.h b/include/tvm/ir_functor_ext.h index 3507a9919043..f1f7bc9279d1 100644 --- a/include/tvm/ir_functor_ext.h +++ b/include/tvm/ir_functor_ext.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2017 by Contributors * \file tvm/ir_functor_ext.h * \brief More powerful Visitor that allows define function signatures. */ diff --git a/include/tvm/ir_mutator.h b/include/tvm/ir_mutator.h index 6cc80d55352b..61080078c176 100644 --- a/include/tvm/ir_mutator.h +++ b/include/tvm/ir_mutator.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2016 by Contributors * \file tvm/ir_mutator.h * \brief Defines general IRMutation pass */ diff --git a/include/tvm/ir_pass.h b/include/tvm/ir_pass.h index 3d0b2067d1d4..20b56e0676eb 100644 --- a/include/tvm/ir_pass.h +++ b/include/tvm/ir_pass.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2016 by Contributors * \file tvm/ir_pass.h * \brief Collection of IR pass functions * diff --git a/include/tvm/ir_visitor.h b/include/tvm/ir_visitor.h index c4fccfbe6b1b..f8898d67a18a 100644 --- a/include/tvm/ir_visitor.h +++ b/include/tvm/ir_visitor.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2016 by Contributors * \file tvm/ir_visitor.h * \brief Visitor to quickly visit IR trees */ diff --git a/include/tvm/logging.h b/include/tvm/logging.h index 070b6e092a2e..0190d0641d8b 100644 --- a/include/tvm/logging.h +++ b/include/tvm/logging.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2018 by Contributors * \file tvm/logging.h * \brief logging utilities on top of dmlc-core */ diff --git a/include/tvm/lowered_func.h b/include/tvm/lowered_func.h index 5cb59fd47712..cb03f6c9dae7 100644 --- a/include/tvm/lowered_func.h +++ b/include/tvm/lowered_func.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2017 by Contributors * \file tvm/lowered_func.h * \brief Information about a lowered TVM function. * This data structure is final step toward codegen. diff --git a/include/tvm/operation.h b/include/tvm/operation.h index eafce72375cf..15a8c1215177 100644 --- a/include/tvm/operation.h +++ b/include/tvm/operation.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2016 by Contributors * \file tvm/operation.h * \brief Operation node can generate one or multiple Tensors */ diff --git a/include/tvm/packed_func_ext.h b/include/tvm/packed_func_ext.h index 45366f3ad55a..8bbde878741d 100644 --- a/include/tvm/packed_func_ext.h +++ b/include/tvm/packed_func_ext.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2016 by Contributors * \file tvm/packed_func_ext.h * \brief Extension package to PackedFunc * This enales pass NodeRef types into/from PackedFunc. diff --git a/include/tvm/relay/adt.h b/include/tvm/relay/adt.h index 07c05e89aa86..9e4e00ca47ed 100644 --- a/include/tvm/relay/adt.h +++ b/include/tvm/relay/adt.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2018 by Contributors * \file tvm/relay/adt.h * \brief Algebraic data types for Relay */ diff --git a/include/tvm/relay/attrs/annotation.h b/include/tvm/relay/attrs/annotation.h index 85fe209d8bff..29750c576b36 100644 --- a/include/tvm/relay/attrs/annotation.h +++ b/include/tvm/relay/attrs/annotation.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2018 by Contributors * \file tvm/relay/attrs/annotation.h * \brief Attribute for annotation operators. */ diff --git a/include/tvm/relay/attrs/debug.h b/include/tvm/relay/attrs/debug.h index 8243dc0a3b91..82a2046ee73d 100644 --- a/include/tvm/relay/attrs/debug.h +++ b/include/tvm/relay/attrs/debug.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2018 by Contributors * \file tvm/relay/attrs/debug.h * \brief Auxiliary attributes for debug operators. */ diff --git a/include/tvm/relay/attrs/device_copy.h b/include/tvm/relay/attrs/device_copy.h index 6e73ea919ef7..2469c4b6e192 100644 --- a/include/tvm/relay/attrs/device_copy.h +++ b/include/tvm/relay/attrs/device_copy.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2018 by Contributors * \file tvm/relay/attrs/device_copy.h * \brief Attribute for the device copy operator. */ diff --git a/include/tvm/relay/attrs/image.h b/include/tvm/relay/attrs/image.h index 527bb647314f..f3caf213575d 100644 --- a/include/tvm/relay/attrs/image.h +++ b/include/tvm/relay/attrs/image.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2018 by Contributors * \file tvm/relay/attrs/image.h * \brief Auxiliary attributes for image operators. */ diff --git a/include/tvm/relay/attrs/nn.h b/include/tvm/relay/attrs/nn.h index 2c96a0745150..431b6032c8cd 100644 --- a/include/tvm/relay/attrs/nn.h +++ b/include/tvm/relay/attrs/nn.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2018 by Contributors * \file tvm/relay/attrs/nn.h * \brief Auxiliary attributes for nn operators. */ @@ -456,6 +474,67 @@ struct L2NormalizeAttrs : public tvm::AttrsNode { } }; + +/*! \brief Attributes for DeformableConv2D operator */ +struct DeformableConv2DAttrs : public tvm::AttrsNode { + Array strides; + Array padding; + Array dilation; + int deformable_groups; + int groups; + IndexExpr channels; + Array kernel_size; + std::string data_layout; + std::string kernel_layout; + std::string out_layout; + DataType out_dtype; + + TVM_DECLARE_ATTRS(DeformableConv2DAttrs, "relay.attrs.DeformableConv2DAttrs") { + TVM_ATTR_FIELD(strides).set_default(Array({1, 1})) + .describe("Specifies the strides of the convolution."); + TVM_ATTR_FIELD(padding).set_default(Array({0, 0})) + .describe("If padding is non-zero, then the input is implicitly zero-padded" + "on both sides for padding number of points"); + TVM_ATTR_FIELD(dilation).set_default(Array({1, 1})) + .describe("Specifies the dilation rate to use for dilated convolution."); + TVM_ATTR_FIELD(deformable_groups).set_default(1) + .describe("Controls the connections between inputs and offsets." + "Input channels are partitioned into multiple deformable groups. Offsets" + "are shared across input channels in the same deformable group."); + TVM_ATTR_FIELD(groups).set_default(1) + .describe("Controls the connections between inputs and outputs." + "At groups=1, all inputs are convolved to all outputs." + "At groups=2, the operation becomes equivalent to having two convolution" + "layers side by side, each seeing half the input channels, and producing" + "half the output channels, and both subsequently concatenated."); + TVM_ATTR_FIELD(channels) + .describe("The number of output channels in the convolution." + " If it is not set, inferred by shape of the weight.") + .set_default(NullValue()); + TVM_ATTR_FIELD(kernel_size) + .describe("Specifies the dimensions of the convolution window.") + .set_default(NullValue >()); + TVM_ATTR_FIELD(data_layout).set_default("NCHW") + .describe("Dimension ordering of input data. Can be 'NCHW', 'NHWC', etc." + "'N', 'C', 'H', 'W' stands for batch, channel, height, and width" + "dimensions respectively. Convolution is applied on the 'H' and" + "'W' dimensions."); + TVM_ATTR_FIELD(kernel_layout).set_default("OIHW") + .describe("Dimension ordering of weight. Can be 'OIHW', 'OIHW16o16i', etc." + "'O', 'I', 'H', 'W' stands for num_filter, input_channel, height, and width" + "dimensions respectively."); + TVM_ATTR_FIELD(out_layout).set_default("") + .describe("Dimension ordering of output. Can be 'NCHW', 'NHWC', etc." + "'N', 'C', 'H', 'W' stands for batch, channel, height, and width" + "dimensions respectively. Default to be same as input layout."); + + // use 0 bits to indicate none. + TVM_ATTR_FIELD(out_dtype) + .set_default(NullValue()) + .describe("Output data type, set to explicit type under mixed precision setting"); + } +}; + } // namespace relay } // namespace tvm #endif // TVM_RELAY_ATTRS_NN_H_ diff --git a/include/tvm/relay/attrs/transform.h b/include/tvm/relay/attrs/transform.h index af4938236054..1b82412d0482 100644 --- a/include/tvm/relay/attrs/transform.h +++ b/include/tvm/relay/attrs/transform.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2018 by Contributors * \file tvm/relay/attrs/transform.h * \brief Transform operators. */ @@ -75,10 +93,15 @@ struct ReshapeAttrs : public tvm::AttrsNode { struct TakeAttrs : public tvm::AttrsNode { Integer axis; + std::string mode; TVM_DECLARE_ATTRS(TakeAttrs, "relay.attrs.TakeAttrs") { TVM_ATTR_FIELD(axis).set_default(NullValue()) .describe("The axis over which to select values."); + TVM_ATTR_FIELD(mode).set_default("clip") + .describe("Specify how out-of-bound indices will behave." + "clip - clip to the range (default)" + "wrap - wrap around the indices"); } }; diff --git a/include/tvm/relay/attrs/vision.h b/include/tvm/relay/attrs/vision.h index ac2d9277ca62..2b3eb4f32b45 100644 --- a/include/tvm/relay/attrs/vision.h +++ b/include/tvm/relay/attrs/vision.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2018 by Contributors * \file tvm/relay/attrs/vision.h * \brief Auxiliary attributes for vision operators. */ diff --git a/include/tvm/relay/base.h b/include/tvm/relay/base.h index f90acdc9400b..f94ba5e26068 100644 --- a/include/tvm/relay/base.h +++ b/include/tvm/relay/base.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2018 by Contributors * \file tvm/relay/base.h * \brief Base classes for the Relay IR. */ diff --git a/include/tvm/relay/error.h b/include/tvm/relay/error.h index a15690b94763..6b9a1fa7b7c6 100644 --- a/include/tvm/relay/error.h +++ b/include/tvm/relay/error.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2018 by Contributors * \file error.h * \brief The set of errors raised by Relay. */ diff --git a/include/tvm/relay/expr.h b/include/tvm/relay/expr.h index 4513022687f8..47f5e9debae6 100644 --- a/include/tvm/relay/expr.h +++ b/include/tvm/relay/expr.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2018 by Contributors * \file tvm/relay/expr.h * \brief Relay expression language. */ @@ -544,16 +562,16 @@ inline const TTypeNode* ExprNode::type_as() const { } /*! - * \brief Print node as text format. - * \param node The node to be printed. + * \brief Render the node as a string in the Relay text format. + * \param node The node to be rendered. * \param show_meta_data Whether to print meta data section. * \param annotate An optional callback function for attaching * additional comment block to an expr. * \return The text representation. */ -std::string RelayPrint(const NodeRef& node, - bool show_meta_data = true, - runtime::TypedPackedFunc annotate = nullptr); +std::string AsText(const NodeRef& node, + bool show_meta_data = true, + runtime::TypedPackedFunc annotate = nullptr); } // namespace relay } // namespace tvm #endif // TVM_RELAY_EXPR_H_ diff --git a/include/tvm/relay/expr_functor.h b/include/tvm/relay/expr_functor.h index 446e4eec78ee..9c29aebe3e7c 100644 --- a/include/tvm/relay/expr_functor.h +++ b/include/tvm/relay/expr_functor.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2018 by Contributors * \file tvm/relay/expr_functor.h * \brief A more powerful visitor which enables defining arbitrary function * signatures with type based dispatch on first argument. diff --git a/include/tvm/relay/interpreter.h b/include/tvm/relay/interpreter.h index 42f0d4e9b0a5..15c96bb12822 100644 --- a/include/tvm/relay/interpreter.h +++ b/include/tvm/relay/interpreter.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2018 by Contributors * \file tvm/relay/interpreter.h * \brief An interpreter for Relay. * diff --git a/include/tvm/relay/logging.h b/include/tvm/relay/logging.h index c53cd15ee72e..709ab5a0a6b2 100644 --- a/include/tvm/relay/logging.h +++ b/include/tvm/relay/logging.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2018 by Contributors * \file tvm/relay/logging.h * \brief A wrapper around dmlc-core/logging.h which adds the ability * to toggle logging via an environment variable. diff --git a/include/tvm/relay/module.h b/include/tvm/relay/module.h index 6de3b22f6566..6441fb3f5b9c 100644 --- a/include/tvm/relay/module.h +++ b/include/tvm/relay/module.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2018 by Contributors * \file tvm/relay/module.h * \brief The global environment: contains information needed to * compile & optimize Relay programs. diff --git a/include/tvm/relay/op.h b/include/tvm/relay/op.h index 583491ca2613..e426ceba8b6d 100644 --- a/include/tvm/relay/op.h +++ b/include/tvm/relay/op.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2018 by Contributors * \file tvm/relay/op.h * \brief Primitive operator definition. */ diff --git a/include/tvm/relay/op_attr_types.h b/include/tvm/relay/op_attr_types.h index b9383f29f26e..464bc1cc0b64 100644 --- a/include/tvm/relay/op_attr_types.h +++ b/include/tvm/relay/op_attr_types.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2017 by Contributors * \file nnvm/compiler/op_attr_types.h * \brief The Expr and related elements in DataFlow construction. */ diff --git a/include/tvm/relay/pass.h b/include/tvm/relay/pass.h index 11273881e9ee..2f8a50b9e65b 100644 --- a/include/tvm/relay/pass.h +++ b/include/tvm/relay/pass.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2018 by Contributors * \file tvm/relay/pass.h * \brief The set of Relay passes written in C++. * diff --git a/include/tvm/relay/pattern_functor.h b/include/tvm/relay/pattern_functor.h index 747ab197ce3c..5c4020f11f0b 100644 --- a/include/tvm/relay/pattern_functor.h +++ b/include/tvm/relay/pattern_functor.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2018 by Contributors * \file tvm/relay/pattern_functor.h * \brief A more powerful visitor on ADT patterns that enables defining * arbitrary function signatures with type-based dispatch on first argument. diff --git a/include/tvm/relay/type.h b/include/tvm/relay/type.h index 6c164ab6bcea..452e3b6eb864 100644 --- a/include/tvm/relay/type.h +++ b/include/tvm/relay/type.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2018 by Contributors * \file tvm/relay/type.h * \brief Relay typed AST nodes. */ diff --git a/include/tvm/runtime/c_backend_api.h b/include/tvm/runtime/c_backend_api.h index f1e9f4f37bb0..eb938a7c4660 100644 --- a/include/tvm/runtime/c_backend_api.h +++ b/include/tvm/runtime/c_backend_api.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2017 by Contributors * \file tvm/runtime/c_backend_api.h * \brief TVM runtime backend API. * diff --git a/include/tvm/runtime/c_runtime_api.h b/include/tvm/runtime/c_runtime_api.h index 1a1a8da67aed..788eaf2019f3 100644 --- a/include/tvm/runtime/c_runtime_api.h +++ b/include/tvm/runtime/c_runtime_api.h @@ -1,5 +1,23 @@ -/*! - * Copyright (c) 2016 by Contributors +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* * \file tvm/runtime/c_runtime_api.h * \brief TVM runtime library. * diff --git a/include/tvm/runtime/device_api.h b/include/tvm/runtime/device_api.h index 882d90ae09aa..6986e62475fd 100644 --- a/include/tvm/runtime/device_api.h +++ b/include/tvm/runtime/device_api.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2016 by Contributors * \file tvm/runtime/device_api.h * \brief Abstract device memory management API */ diff --git a/include/tvm/runtime/module.h b/include/tvm/runtime/module.h index 347f03ef3b7c..02a042ca6518 100644 --- a/include/tvm/runtime/module.h +++ b/include/tvm/runtime/module.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2017 by Contributors * \file tvm/runtime/module.h * \brief Runtime container of the functions generated by TVM, * This is used to support dynamically link, load and save diff --git a/include/tvm/runtime/ndarray.h b/include/tvm/runtime/ndarray.h index 2b9674301607..5133d2861922 100644 --- a/include/tvm/runtime/ndarray.h +++ b/include/tvm/runtime/ndarray.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2017 by Contributors * \file tvm/runtime/ndarray.h * \brief Abstract device memory management API */ diff --git a/include/tvm/runtime/node_base.h b/include/tvm/runtime/node_base.h index bc62ac460cff..8b47c18a09a7 100644 --- a/include/tvm/runtime/node_base.h +++ b/include/tvm/runtime/node_base.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2018 by Contributors * \file tvm/runtime/node_base.h * \brief Base data structure for Node. * diff --git a/include/tvm/runtime/packed_func.h b/include/tvm/runtime/packed_func.h index 9e4dbd0add04..654f4e5efe50 100644 --- a/include/tvm/runtime/packed_func.h +++ b/include/tvm/runtime/packed_func.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2017 by Contributors * \file tvm/runtime/packed_func.h * \brief Type-erased function used across TVM API. */ diff --git a/include/tvm/runtime/registry.h b/include/tvm/runtime/registry.h index a53a76f4df2e..50bb5c5b967d 100644 --- a/include/tvm/runtime/registry.h +++ b/include/tvm/runtime/registry.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2017 by Contributors * \file tvm/runtime/registry.h * \brief This file defines the TVM global function registry. * diff --git a/include/tvm/runtime/serializer.h b/include/tvm/runtime/serializer.h index e9a7d1db50ec..ca968c4b58f4 100644 --- a/include/tvm/runtime/serializer.h +++ b/include/tvm/runtime/serializer.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2017 by Contributors * \file tvm/runtime/serializer.h * \brief Serializer extension to support TVM data types * Include this file to enable serialization of DLDataType, DLContext diff --git a/include/tvm/runtime/threading_backend.h b/include/tvm/runtime/threading_backend.h index e2da0a3c4446..f1984013e6a9 100644 --- a/include/tvm/runtime/threading_backend.h +++ b/include/tvm/runtime/threading_backend.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2018 by Contributors * \file tvm/runtime/threading_backend.h * \brief Utilities for manipulating thread pool threads. */ diff --git a/include/tvm/runtime/util.h b/include/tvm/runtime/util.h index 6ec168a250b6..e6c586563872 100644 --- a/include/tvm/runtime/util.h +++ b/include/tvm/runtime/util.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2017 by Contributors * \file tvm/runtime/util.h * \brief Useful runtime util. */ diff --git a/include/tvm/schedule.h b/include/tvm/schedule.h index 0529b9291327..9a556b6ce960 100644 --- a/include/tvm/schedule.h +++ b/include/tvm/schedule.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2016 by Contributors * \file tvm/schedule.h * \brief Define a schedule. */ diff --git a/include/tvm/schedule_pass.h b/include/tvm/schedule_pass.h index e2b4462b8d73..27444ab693cd 100644 --- a/include/tvm/schedule_pass.h +++ b/include/tvm/schedule_pass.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2016 by Contributors * \file tvm/schedule_pass.h * \brief Collection of Schedule pass functions. * diff --git a/include/tvm/target_info.h b/include/tvm/target_info.h index 338749cf832e..1e3a7686ca00 100644 --- a/include/tvm/target_info.h +++ b/include/tvm/target_info.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2017 by Contributors * \file tvm/target_info.h * \brief Various information about target. */ diff --git a/include/tvm/tensor.h b/include/tvm/tensor.h index b3b7ec51bdae..c6be52181f6c 100644 --- a/include/tvm/tensor.h +++ b/include/tvm/tensor.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2016 by Contributors * \file tvm/tensor.h * \brief Dataflow tensor object */ diff --git a/include/tvm/tensor_intrin.h b/include/tvm/tensor_intrin.h index 6cffc931d42a..e61ce6634bd3 100644 --- a/include/tvm/tensor_intrin.h +++ b/include/tvm/tensor_intrin.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2017 by Contributors * \file tvm/tensor_intrin.h * \brief Tensor intrinsic operations. */ diff --git a/include/tvm/tvm.h b/include/tvm/tvm.h index 5f81cb52fa31..507363d6a1cc 100644 --- a/include/tvm/tvm.h +++ b/include/tvm/tvm.h @@ -1,5 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! - * Copyright (c) 2016 by Contributors * \file tvm/tvm.h * \brief Header to include all C++ API. */ diff --git a/jvm/README.md b/jvm/README.md index 7de31d1576e9..626a87c84cf8 100644 --- a/jvm/README.md +++ b/jvm/README.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + # TVM4J - Java Frontend for TVM Runtime This folder contains the Java interface for TVM runtime. It brings TVM runtime to Java virtual machine. diff --git a/jvm/assembly/linux-x86_64/pom.xml b/jvm/assembly/linux-x86_64/pom.xml index c539b1434b60..6f45dbf9d148 100644 --- a/jvm/assembly/linux-x86_64/pom.xml +++ b/jvm/assembly/linux-x86_64/pom.xml @@ -1,4 +1,24 @@ + + + diff --git a/jvm/assembly/linux-x86_64/src/main/assembly/assembly.xml b/jvm/assembly/linux-x86_64/src/main/assembly/assembly.xml index d70f1544a9a6..8eba6c210ad6 100644 --- a/jvm/assembly/linux-x86_64/src/main/assembly/assembly.xml +++ b/jvm/assembly/linux-x86_64/src/main/assembly/assembly.xml @@ -1,3 +1,23 @@ + + + full diff --git a/jvm/assembly/osx-x86_64/pom.xml b/jvm/assembly/osx-x86_64/pom.xml index a0cb02d295ce..91545da9e641 100644 --- a/jvm/assembly/osx-x86_64/pom.xml +++ b/jvm/assembly/osx-x86_64/pom.xml @@ -1,4 +1,24 @@ + + + diff --git a/jvm/assembly/osx-x86_64/src/main/assembly/assembly.xml b/jvm/assembly/osx-x86_64/src/main/assembly/assembly.xml index caefd426af66..4a44de07c9bb 100644 --- a/jvm/assembly/osx-x86_64/src/main/assembly/assembly.xml +++ b/jvm/assembly/osx-x86_64/src/main/assembly/assembly.xml @@ -1,3 +1,23 @@ + + + full diff --git a/jvm/assembly/pom.xml b/jvm/assembly/pom.xml index 2380df497b56..33a7c13a56c9 100644 --- a/jvm/assembly/pom.xml +++ b/jvm/assembly/pom.xml @@ -1,4 +1,24 @@ + + + diff --git a/jvm/conf/google_checks.xml b/jvm/conf/google_checks.xml index 9bea0e85f46f..339b41e90d12 100644 --- a/jvm/conf/google_checks.xml +++ b/jvm/conf/google_checks.xml @@ -3,6 +3,25 @@ "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd"> + + + diff --git a/jvm/core/src/main/java/ml/dmlc/tvm/contrib/GraphModule.java b/jvm/core/src/main/java/ml/dmlc/tvm/contrib/GraphModule.java index 84f8fc2a1a95..d7f22a96f0ea 100644 --- a/jvm/core/src/main/java/ml/dmlc/tvm/contrib/GraphModule.java +++ b/jvm/core/src/main/java/ml/dmlc/tvm/contrib/GraphModule.java @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package ml.dmlc.tvm.contrib; import ml.dmlc.tvm.Function; diff --git a/jvm/core/src/test/java/ml/dmlc/tvm/TestUtils.java b/jvm/core/src/test/java/ml/dmlc/tvm/TestUtils.java index 23e22779adae..810fc04ac4d4 100644 --- a/jvm/core/src/test/java/ml/dmlc/tvm/TestUtils.java +++ b/jvm/core/src/test/java/ml/dmlc/tvm/TestUtils.java @@ -1,5 +1,25 @@ package ml.dmlc.tvm; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + import ml.dmlc.tvm.rpc.Server; import java.io.IOException; diff --git a/jvm/core/src/test/scripts/test_add_cpu.py b/jvm/core/src/test/scripts/test_add_cpu.py index 7a1e1caf1ed0..dd7e4a8de73a 100644 --- a/jvm/core/src/test/scripts/test_add_cpu.py +++ b/jvm/core/src/test/scripts/test_add_cpu.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import os import tvm diff --git a/jvm/core/src/test/scripts/test_add_gpu.py b/jvm/core/src/test/scripts/test_add_gpu.py index ca0d9729c844..f41992b8b15e 100644 --- a/jvm/core/src/test/scripts/test_add_gpu.py +++ b/jvm/core/src/test/scripts/test_add_gpu.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import os import tvm diff --git a/jvm/core/src/test/scripts/test_graph_runtime.py b/jvm/core/src/test/scripts/test_graph_runtime.py index a60736c2468d..4d82973ae031 100644 --- a/jvm/core/src/test/scripts/test_graph_runtime.py +++ b/jvm/core/src/test/scripts/test_graph_runtime.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import os import tvm diff --git a/jvm/core/src/test/scripts/test_rpc_proxy_server.py b/jvm/core/src/test/scripts/test_rpc_proxy_server.py index 09b7e4a6fe02..68dd19e12da8 100644 --- a/jvm/core/src/test/scripts/test_rpc_proxy_server.py +++ b/jvm/core/src/test/scripts/test_rpc_proxy_server.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import time from tvm.rpc import proxy diff --git a/jvm/native/linux-x86_64/pom.xml b/jvm/native/linux-x86_64/pom.xml index 82fb857db356..8ec24bc02c3c 100644 --- a/jvm/native/linux-x86_64/pom.xml +++ b/jvm/native/linux-x86_64/pom.xml @@ -1,4 +1,24 @@ + + + diff --git a/jvm/native/osx-x86_64/pom.xml b/jvm/native/osx-x86_64/pom.xml index 52203fcc9bd2..6ea59347726c 100644 --- a/jvm/native/osx-x86_64/pom.xml +++ b/jvm/native/osx-x86_64/pom.xml @@ -1,4 +1,24 @@ + + + diff --git a/jvm/native/pom.xml b/jvm/native/pom.xml index 8861a2e20662..504e0c594006 100644 --- a/jvm/native/pom.xml +++ b/jvm/native/pom.xml @@ -1,4 +1,24 @@ + + + diff --git a/jvm/native/src/main/native/jni_helper_func.h b/jvm/native/src/main/native/jni_helper_func.h index 181d9de040f1..d58224fb2f25 100644 --- a/jvm/native/src/main/native/jni_helper_func.h +++ b/jvm/native/src/main/native/jni_helper_func.h @@ -1,5 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ /*! - * Copyright (c) 2017 by Contributors * \file jni_helper_func.h * \brief Helper functions for operating JVM objects */ diff --git a/jvm/native/src/main/native/ml_dmlc_tvm_native_c_api.cc b/jvm/native/src/main/native/ml_dmlc_tvm_native_c_api.cc index fada50ca76e2..1eff6c45e1fc 100644 --- a/jvm/native/src/main/native/ml_dmlc_tvm_native_c_api.cc +++ b/jvm/native/src/main/native/ml_dmlc_tvm_native_c_api.cc @@ -1,5 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ /*! - * Copyright (c) 2017 by Contributors * \file ml_dmlc_tvm_native_c_api.cc * \brief tvm4j jni source file */ @@ -178,6 +195,10 @@ JNIEXPORT jint JNICALL Java_ml_dmlc_tvm_LibInfo_tvmFuncCall( int ret = TVMFuncCall(reinterpret_cast(jhandle), &argValues[0], &argTypes[0], numArgs, &retVal, &retTypeCode); + if (ret != 0) { + return ret; + } + for (auto iter = pushedStrs.cbegin(); iter != pushedStrs.cend(); iter++) { env->ReleaseStringUTFChars(iter->first, iter->second); env->DeleteGlobalRef(iter->first); diff --git a/nnvm/Makefile b/nnvm/Makefile index 8392aadc3f2d..39763cb59db8 100644 --- a/nnvm/Makefile +++ b/nnvm/Makefile @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + ROOTDIR = $(CURDIR) ifndef config diff --git a/nnvm/README.md b/nnvm/README.md index ed8a18e3fa1e..e3b451d63dcd 100644 --- a/nnvm/README.md +++ b/nnvm/README.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + # NNVM Compiler Module of TVM Stack ```python diff --git a/nnvm/amalgamation/Makefile b/nnvm/amalgamation/Makefile index 4305339e0075..eb1e08b740d7 100644 --- a/nnvm/amalgamation/Makefile +++ b/nnvm/amalgamation/Makefile @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + export NNVM_ROOT=`pwd`/.. export CFLAGS = -std=c++11 -Wall -O2 -Iinclude -fPIC diff --git a/nnvm/amalgamation/amalgamation.py b/nnvm/amalgamation/amalgamation.py index 310daa9d68e0..b5ab046b2799 100644 --- a/nnvm/amalgamation/amalgamation.py +++ b/nnvm/amalgamation/amalgamation.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import sys import os.path, re, StringIO diff --git a/nnvm/amalgamation/generate.py b/nnvm/amalgamation/generate.py index 84a5fc06fb03..bbd026c62f96 100644 --- a/nnvm/amalgamation/generate.py +++ b/nnvm/amalgamation/generate.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import os import sys diff --git a/nnvm/include/nnvm/base.h b/nnvm/include/nnvm/base.h index 39ff70093bed..43e0fb9b0c59 100644 --- a/nnvm/include/nnvm/base.h +++ b/nnvm/include/nnvm/base.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file nnvm/base.h diff --git a/nnvm/include/nnvm/c_api.h b/nnvm/include/nnvm/c_api.h index 1010e3c07227..75054e892d8e 100644 --- a/nnvm/include/nnvm/c_api.h +++ b/nnvm/include/nnvm/c_api.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file nnvm/c_api.h diff --git a/nnvm/include/nnvm/compiler/op_attr_types.h b/nnvm/include/nnvm/compiler/op_attr_types.h index 497a520db78e..4d9c919d2b60 100644 --- a/nnvm/include/nnvm/compiler/op_attr_types.h +++ b/nnvm/include/nnvm/compiler/op_attr_types.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file nnvm/compiler/op_attr_types.h diff --git a/nnvm/include/nnvm/compiler/packed_func_ext.h b/nnvm/include/nnvm/compiler/packed_func_ext.h index a79574fa0879..02319612809f 100644 --- a/nnvm/include/nnvm/compiler/packed_func_ext.h +++ b/nnvm/include/nnvm/compiler/packed_func_ext.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file nnvm/compiler/packed_func_ext.h diff --git a/nnvm/include/nnvm/compiler/util.h b/nnvm/include/nnvm/compiler/util.h index 0f7fb2a5c875..fa8b69f9b70a 100644 --- a/nnvm/include/nnvm/compiler/util.h +++ b/nnvm/include/nnvm/compiler/util.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file nnvm/compiler/util.h diff --git a/nnvm/include/nnvm/graph.h b/nnvm/include/nnvm/graph.h index 32e63833b01b..f67db5d1a7a4 100644 --- a/nnvm/include/nnvm/graph.h +++ b/nnvm/include/nnvm/graph.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file nnvm/graph.h diff --git a/nnvm/include/nnvm/graph_attr_types.h b/nnvm/include/nnvm/graph_attr_types.h index 8f7167337e67..579d6cc24996 100644 --- a/nnvm/include/nnvm/graph_attr_types.h +++ b/nnvm/include/nnvm/graph_attr_types.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file nnvm/graph_attr_types.h diff --git a/nnvm/include/nnvm/layout.h b/nnvm/include/nnvm/layout.h index 94813f5323f8..aad3754155c1 100644 --- a/nnvm/include/nnvm/layout.h +++ b/nnvm/include/nnvm/layout.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file nnvm/layout.h diff --git a/nnvm/include/nnvm/node.h b/nnvm/include/nnvm/node.h index c9c27a4d2403..782afba0a5ab 100644 --- a/nnvm/include/nnvm/node.h +++ b/nnvm/include/nnvm/node.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file nnvm/node.h diff --git a/nnvm/include/nnvm/op.h b/nnvm/include/nnvm/op.h index 88b59353e5e6..e1d596089a88 100644 --- a/nnvm/include/nnvm/op.h +++ b/nnvm/include/nnvm/op.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file nnvm/op.h diff --git a/nnvm/include/nnvm/op_attr_types.h b/nnvm/include/nnvm/op_attr_types.h index 58f51654f713..976ad929f496 100644 --- a/nnvm/include/nnvm/op_attr_types.h +++ b/nnvm/include/nnvm/op_attr_types.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file nnvm/op_attr_types.h diff --git a/nnvm/include/nnvm/pass.h b/nnvm/include/nnvm/pass.h index 2e8db6111887..492988f5c625 100644 --- a/nnvm/include/nnvm/pass.h +++ b/nnvm/include/nnvm/pass.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file nnvm/pass.h diff --git a/nnvm/include/nnvm/pass_functions.h b/nnvm/include/nnvm/pass_functions.h index d7c7f189a786..0172d6699797 100644 --- a/nnvm/include/nnvm/pass_functions.h +++ b/nnvm/include/nnvm/pass_functions.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file nnvm/pass_functions.h diff --git a/nnvm/include/nnvm/symbolic.h b/nnvm/include/nnvm/symbolic.h index 0a0b3897d733..a4e5d150ab68 100644 --- a/nnvm/include/nnvm/symbolic.h +++ b/nnvm/include/nnvm/symbolic.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file nnvm/symbolic.h diff --git a/nnvm/include/nnvm/top/nn.h b/nnvm/include/nnvm/top/nn.h index ed4e964383eb..424a6a0fa5e6 100644 --- a/nnvm/include/nnvm/top/nn.h +++ b/nnvm/include/nnvm/top/nn.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file nnvm/top/nn.h diff --git a/nnvm/include/nnvm/top/tensor.h b/nnvm/include/nnvm/top/tensor.h index fba4a78d3e68..b38c2fceb5f6 100644 --- a/nnvm/include/nnvm/top/tensor.h +++ b/nnvm/include/nnvm/top/tensor.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file nnvm/top/tensor.h diff --git a/nnvm/include/nnvm/tuple.h b/nnvm/include/nnvm/tuple.h index 36b8ef13c74a..ba0488f98ffd 100644 --- a/nnvm/include/nnvm/tuple.h +++ b/nnvm/include/nnvm/tuple.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file nnvm/tuple.h diff --git a/nnvm/python/nnvm/_base.py b/nnvm/python/nnvm/_base.py index dd797ba4489f..420392f17e92 100644 --- a/nnvm/python/nnvm/_base.py +++ b/nnvm/python/nnvm/_base.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # coding: utf-8 # pylint: disable=invalid-name, unused-import """ ctypes library of nnvm and helper functions """ diff --git a/nnvm/python/nnvm/_ctypes/symbol.py b/nnvm/python/nnvm/_ctypes/symbol.py index 843601c10f4e..8c7d58a65920 100644 --- a/nnvm/python/nnvm/_ctypes/symbol.py +++ b/nnvm/python/nnvm/_ctypes/symbol.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # coding: utf-8 # pylint: disable=invalid-name, protected-access, too-many-arguments, too-many-lines, # pylint: disable=len-as-condition, consider-iterating-dictionary diff --git a/nnvm/python/nnvm/_symbol_internal.py b/nnvm/python/nnvm/_symbol_internal.py index 6fadaf89c9d9..de2f85aa2f29 100644 --- a/nnvm/python/nnvm/_symbol_internal.py +++ b/nnvm/python/nnvm/_symbol_internal.py @@ -1 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Module space to register internal functions. Leave empty""" diff --git a/nnvm/python/nnvm/attribute.py b/nnvm/python/nnvm/attribute.py index 4a08bb622ed5..14341794bb64 100644 --- a/nnvm/python/nnvm/attribute.py +++ b/nnvm/python/nnvm/attribute.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # coding: utf-8 """Attribute scoping support for symbolic API.""" from __future__ import absolute_import diff --git a/nnvm/python/nnvm/compiler/build_module.py b/nnvm/python/nnvm/compiler/build_module.py index 4083e3adcbf1..0c1bc5047870 100644 --- a/nnvm/python/nnvm/compiler/build_module.py +++ b/nnvm/python/nnvm/compiler/build_module.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Namespace for building operators.""" from __future__ import absolute_import as _abs diff --git a/nnvm/python/nnvm/compiler/compile_engine.py b/nnvm/python/nnvm/compiler/compile_engine.py index e6158fb611fe..d7799bf7b0e7 100644 --- a/nnvm/python/nnvm/compiler/compile_engine.py +++ b/nnvm/python/nnvm/compiler/compile_engine.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Compiler engine interface to internal engine diff --git a/nnvm/python/nnvm/compiler/graph_attr.py b/nnvm/python/nnvm/compiler/graph_attr.py index 2f1f0350d71b..de557cce78b3 100644 --- a/nnvm/python/nnvm/compiler/graph_attr.py +++ b/nnvm/python/nnvm/compiler/graph_attr.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Utilities to access graph attributes""" from __future__ import absolute_import as _abs diff --git a/nnvm/python/nnvm/compiler/graph_pass.py b/nnvm/python/nnvm/compiler/graph_pass.py index a37e83a2c5c0..a11a80e43fe4 100644 --- a/nnvm/python/nnvm/compiler/graph_pass.py +++ b/nnvm/python/nnvm/compiler/graph_pass.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Namespace of graph pass. diff --git a/nnvm/python/nnvm/compiler/graph_util.py b/nnvm/python/nnvm/compiler/graph_util.py index e831298b27d9..3ce38dacacc3 100644 --- a/nnvm/python/nnvm/compiler/graph_util.py +++ b/nnvm/python/nnvm/compiler/graph_util.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Utility function to get information from graph.""" from __future__ import absolute_import as _abs diff --git a/nnvm/python/nnvm/compiler/lr_scheduler.py b/nnvm/python/nnvm/compiler/lr_scheduler.py index 791925e74960..3a33f390b6f4 100644 --- a/nnvm/python/nnvm/compiler/lr_scheduler.py +++ b/nnvm/python/nnvm/compiler/lr_scheduler.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=too-few-public-methods, no-member """API for scheduling learning rate.""" from .. import symbol as sym diff --git a/nnvm/python/nnvm/compiler/optimizer.py b/nnvm/python/nnvm/compiler/optimizer.py index bcf7498528af..ba739b8c7056 100644 --- a/nnvm/python/nnvm/compiler/optimizer.py +++ b/nnvm/python/nnvm/compiler/optimizer.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, no-member, too-few-public-methods, too-many-arguments, too-many-locals, protected-access """Optimizer API""" from . import graph_util diff --git a/nnvm/python/nnvm/compiler/param_dict.py b/nnvm/python/nnvm/compiler/param_dict.py index 3bb30e20bbc2..a543e0a827b3 100644 --- a/nnvm/python/nnvm/compiler/param_dict.py +++ b/nnvm/python/nnvm/compiler/param_dict.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Helper utility to save parameter dict""" import tvm diff --git a/nnvm/python/nnvm/contrib.py b/nnvm/python/nnvm/contrib.py index 976eb532b019..c3e943682db5 100644 --- a/nnvm/python/nnvm/contrib.py +++ b/nnvm/python/nnvm/contrib.py @@ -1 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Module space to register contrib functions. Leave empty""" diff --git a/nnvm/python/nnvm/cython/base.pyi b/nnvm/python/nnvm/cython/base.pyi index b1f67876598d..40ef71a20546 100644 --- a/nnvm/python/nnvm/cython/base.pyi +++ b/nnvm/python/nnvm/cython/base.pyi @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + ctypedef void* SymbolHandle ctypedef void* OpHandle ctypedef unsigned nn_uint diff --git a/nnvm/python/nnvm/cython/symbol.pyx b/nnvm/python/nnvm/cython/symbol.pyx index 6848699b3939..eedf2afbbc2a 100644 --- a/nnvm/python/nnvm/cython/symbol.pyx +++ b/nnvm/python/nnvm/cython/symbol.pyx @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + from __future__ import absolute_import as _abs import sys as _sys diff --git a/nnvm/python/nnvm/frontend/caffe2.py b/nnvm/python/nnvm/frontend/caffe2.py old mode 100755 new mode 100644 index 63b7913dd755..367834956a10 --- a/nnvm/python/nnvm/frontend/caffe2.py +++ b/nnvm/python/nnvm/frontend/caffe2.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=import-self, invalid-name, line-too-long, unused-argument """Caffe2 frontend""" from __future__ import absolute_import as _abs diff --git a/nnvm/python/nnvm/frontend/common.py b/nnvm/python/nnvm/frontend/common.py index 5a8defdb3d6e..610546d1973b 100644 --- a/nnvm/python/nnvm/frontend/common.py +++ b/nnvm/python/nnvm/frontend/common.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Shared functions and classes for frontends.""" from __future__ import absolute_import as _abs import logging diff --git a/nnvm/python/nnvm/frontend/coreml.py b/nnvm/python/nnvm/frontend/coreml.py index 1483e95cf6f0..c5b0c0a799ec 100644 --- a/nnvm/python/nnvm/frontend/coreml.py +++ b/nnvm/python/nnvm/frontend/coreml.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-argument """CoreML frontend.""" from __future__ import absolute_import as _abs diff --git a/nnvm/python/nnvm/frontend/darknet.py b/nnvm/python/nnvm/frontend/darknet.py index bf5a832258fa..a48913f1e453 100644 --- a/nnvm/python/nnvm/frontend/darknet.py +++ b/nnvm/python/nnvm/frontend/darknet.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ DarkNet symbol frontend. """ diff --git a/nnvm/python/nnvm/frontend/keras.py b/nnvm/python/nnvm/frontend/keras.py index 63b4122a4060..7af8cf8833dd 100644 --- a/nnvm/python/nnvm/frontend/keras.py +++ b/nnvm/python/nnvm/frontend/keras.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, import-self """Keras frontend.""" from __future__ import absolute_import as _abs diff --git a/nnvm/python/nnvm/frontend/mxnet.py b/nnvm/python/nnvm/frontend/mxnet.py index b3c3bc0aedf4..77671225aa3e 100644 --- a/nnvm/python/nnvm/frontend/mxnet.py +++ b/nnvm/python/nnvm/frontend/mxnet.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, import-self """MXNet symbol frontend.""" from __future__ import absolute_import as _abs diff --git a/nnvm/python/nnvm/frontend/onnx.py b/nnvm/python/nnvm/frontend/onnx.py index 18eb213bab7b..c3c4768a97db 100644 --- a/nnvm/python/nnvm/frontend/onnx.py +++ b/nnvm/python/nnvm/frontend/onnx.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=import-self, invalid-name, unused-argument, too-many-lines """ONNX: Open Neural Network Exchange frontend.""" from __future__ import absolute_import as _abs diff --git a/nnvm/python/nnvm/frontend/onnx_caffe2_utils.py b/nnvm/python/nnvm/frontend/onnx_caffe2_utils.py index ff74016cde06..18f9263ecc0b 100644 --- a/nnvm/python/nnvm/frontend/onnx_caffe2_utils.py +++ b/nnvm/python/nnvm/frontend/onnx_caffe2_utils.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Util functions shared by the ONNX and Caffe2 frontends.""" from __future__ import absolute_import as _abs from nnvm import graph as _graph diff --git a/nnvm/python/nnvm/frontend/tensorflow.py b/nnvm/python/nnvm/frontend/tensorflow.py index 322a5baec84e..84649038e82f 100644 --- a/nnvm/python/nnvm/frontend/tensorflow.py +++ b/nnvm/python/nnvm/frontend/tensorflow.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=import-self, invalid-name, unused-argument, too-many-lines """TF: Tensorflow frontend.""" from __future__ import absolute_import as _abs diff --git a/nnvm/python/nnvm/graph.py b/nnvm/python/nnvm/graph.py index 2ea365e67ef4..0d1e70f4e0f6 100644 --- a/nnvm/python/nnvm/graph.py +++ b/nnvm/python/nnvm/graph.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # coding: utf-8 # pylint: disable=invalid-name, protected-access, too-many-arguments, too-many-lines """NNVM Graph IR API. diff --git a/nnvm/python/nnvm/libinfo.py b/nnvm/python/nnvm/libinfo.py index 652433fc3d8c..b3bfc753b9c2 100644 --- a/nnvm/python/nnvm/libinfo.py +++ b/nnvm/python/nnvm/libinfo.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # coding: utf-8 """Information about nnvm.""" from __future__ import absolute_import diff --git a/nnvm/python/nnvm/name.py b/nnvm/python/nnvm/name.py index 081d2bae7242..fe3d8311f1a6 100644 --- a/nnvm/python/nnvm/name.py +++ b/nnvm/python/nnvm/name.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # coding: utf-8 """Automatic naming support for symbolic API.""" from __future__ import absolute_import as _abs diff --git a/nnvm/python/nnvm/symbol.py b/nnvm/python/nnvm/symbol.py index ec8853c3d118..297d2ba7405a 100644 --- a/nnvm/python/nnvm/symbol.py +++ b/nnvm/python/nnvm/symbol.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-import, protected-access """Symbolic graph construction API. diff --git a/nnvm/python/nnvm/testing/check_computation.py b/nnvm/python/nnvm/testing/check_computation.py index 68419b73523b..63b3a17880a2 100644 --- a/nnvm/python/nnvm/testing/check_computation.py +++ b/nnvm/python/nnvm/testing/check_computation.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=cell-var-from-loop,no-else-return """Helper utilities to check functions and their gradients.""" from __future__ import absolute_import as _abs diff --git a/nnvm/python/nnvm/testing/config.py b/nnvm/python/nnvm/testing/config.py index bf22ea7e3887..175478b6e14a 100644 --- a/nnvm/python/nnvm/testing/config.py +++ b/nnvm/python/nnvm/testing/config.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Configuration about tests""" from __future__ import absolute_import as _abs diff --git a/nnvm/python/nnvm/testing/darknet.py b/nnvm/python/nnvm/testing/darknet.py index 328ad2ae6a10..d4d673b7823f 100644 --- a/nnvm/python/nnvm/testing/darknet.py +++ b/nnvm/python/nnvm/testing/darknet.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable, unused-argument, no-init """ Compile DarkNet Models diff --git a/nnvm/python/nnvm/testing/dcgan.py b/nnvm/python/nnvm/testing/dcgan.py index 4adc63bd1f2a..714b3fbb1301 100644 --- a/nnvm/python/nnvm/testing/dcgan.py +++ b/nnvm/python/nnvm/testing/dcgan.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=unused-argument """ Symbol of the generator of DCGAN diff --git a/nnvm/python/nnvm/testing/densenet.py b/nnvm/python/nnvm/testing/densenet.py index e97d306af933..92ba2bf46a8f 100644 --- a/nnvm/python/nnvm/testing/densenet.py +++ b/nnvm/python/nnvm/testing/densenet.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ DenseNet, load model from gluon model zoo diff --git a/nnvm/python/nnvm/testing/inception_v3.py b/nnvm/python/nnvm/testing/inception_v3.py index 3faded3b2ece..e1614d7a9fed 100644 --- a/nnvm/python/nnvm/testing/inception_v3.py +++ b/nnvm/python/nnvm/testing/inception_v3.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Inception V3, suitable for images with around 299 x 299 diff --git a/nnvm/python/nnvm/testing/init.py b/nnvm/python/nnvm/testing/init.py index 36ddcc955f7c..611c81e69483 100644 --- a/nnvm/python/nnvm/testing/init.py +++ b/nnvm/python/nnvm/testing/init.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Initializer of parameters.""" import numpy as np diff --git a/nnvm/python/nnvm/testing/mobilenet.py b/nnvm/python/nnvm/testing/mobilenet.py index feab1ca765bc..e505ff499a54 100644 --- a/nnvm/python/nnvm/testing/mobilenet.py +++ b/nnvm/python/nnvm/testing/mobilenet.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Helper utility to get mobilenet workload for testing.""" # pylint: disable=invalid-name from __future__ import absolute_import as _abs diff --git a/nnvm/python/nnvm/testing/mobilenet_v2.py b/nnvm/python/nnvm/testing/mobilenet_v2.py index dc3c7cd85660..87c4a2c7e9f5 100644 --- a/nnvm/python/nnvm/testing/mobilenet_v2.py +++ b/nnvm/python/nnvm/testing/mobilenet_v2.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ MobileNetV2, load model from gluon model zoo diff --git a/nnvm/python/nnvm/testing/utils.py b/nnvm/python/nnvm/testing/utils.py index 9b228d595d6a..0bffc81a0663 100644 --- a/nnvm/python/nnvm/testing/utils.py +++ b/nnvm/python/nnvm/testing/utils.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Helper utility to create common workload for testing.""" from __future__ import absolute_import as _abs diff --git a/nnvm/python/nnvm/testing/yolo_detection.py b/nnvm/python/nnvm/testing/yolo_detection.py index 3d9f2cacd482..9ecb49ae04f0 100644 --- a/nnvm/python/nnvm/testing/yolo_detection.py +++ b/nnvm/python/nnvm/testing/yolo_detection.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable, unused-argument, no-init """ Yolo detection boxes helper functions diff --git a/nnvm/python/nnvm/to_relay.py b/nnvm/python/nnvm/to_relay.py index da2f394cb442..26dba0f94a27 100644 --- a/nnvm/python/nnvm/to_relay.py +++ b/nnvm/python/nnvm/to_relay.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=no-else-return, unidiomatic-typecheck, invalid-name, unused-argument """Convert an NNVM graph to Relay.""" import numpy diff --git a/nnvm/python/nnvm/top/attr_dict.py b/nnvm/python/nnvm/top/attr_dict.py index 58561e7d5111..5082a587d5a0 100644 --- a/nnvm/python/nnvm/top/attr_dict.py +++ b/nnvm/python/nnvm/top/attr_dict.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Attr dictionary object used by schedule functions""" import tvm diff --git a/nnvm/python/nnvm/top/image.py b/nnvm/python/nnvm/top/image.py index a9d0d8648c48..4367d982985c 100644 --- a/nnvm/python/nnvm/top/image.py +++ b/nnvm/python/nnvm/top/image.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-argument """Definition of image ops""" from __future__ import absolute_import diff --git a/nnvm/python/nnvm/top/nn.py b/nnvm/python/nnvm/top/nn.py index c496044788df..d0d714dcf506 100644 --- a/nnvm/python/nnvm/top/nn.py +++ b/nnvm/python/nnvm/top/nn.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-argument, missing-docstring, no-else-return """Definition of nn ops""" from __future__ import absolute_import diff --git a/nnvm/python/nnvm/top/reduction.py b/nnvm/python/nnvm/top/reduction.py index aef6e1dcc4a8..ce14d0d28831 100644 --- a/nnvm/python/nnvm/top/reduction.py +++ b/nnvm/python/nnvm/top/reduction.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-argument """Reduction ops""" from __future__ import absolute_import diff --git a/nnvm/python/nnvm/top/registry.py b/nnvm/python/nnvm/top/registry.py index 68ea80e7e017..7ad10620f304 100644 --- a/nnvm/python/nnvm/top/registry.py +++ b/nnvm/python/nnvm/top/registry.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Information registry to register operator information for compiler""" import tvm diff --git a/nnvm/python/nnvm/top/tensor.py b/nnvm/python/nnvm/top/tensor.py index 5dae01695e3a..9f12e3245e3a 100644 --- a/nnvm/python/nnvm/top/tensor.py +++ b/nnvm/python/nnvm/top/tensor.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-argument """Tensor ops""" from __future__ import absolute_import diff --git a/nnvm/python/nnvm/top/transform.py b/nnvm/python/nnvm/top/transform.py index 8fde9632a8af..e9051309734a 100644 --- a/nnvm/python/nnvm/top/transform.py +++ b/nnvm/python/nnvm/top/transform.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-argument """Tensor transformation ops""" from __future__ import absolute_import diff --git a/nnvm/python/nnvm/top/vision.py b/nnvm/python/nnvm/top/vision.py index 948f905f1e2b..a1000927c995 100644 --- a/nnvm/python/nnvm/top/vision.py +++ b/nnvm/python/nnvm/top/vision.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-argument """Definition of nn ops""" from __future__ import absolute_import diff --git a/nnvm/python/setup.py b/nnvm/python/setup.py index f680690a2e10..f89ac33a2e39 100644 --- a/nnvm/python/setup.py +++ b/nnvm/python/setup.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import os import sys from setuptools import find_packages @@ -51,7 +67,7 @@ def config_cython(): setup_kwargs = {} setup(name='nnvm', - version=__version__, + version=__version__, description="NNVM: Open Compiler for AI Frameworks", zip_safe=False, install_requires=[ diff --git a/nnvm/src/README.md b/nnvm/src/README.md index adae68105650..c1b66260625e 100644 --- a/nnvm/src/README.md +++ b/nnvm/src/README.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + Project Structure ================= diff --git a/nnvm/src/c_api/c_api_common.h b/nnvm/src/c_api/c_api_common.h index 7a38adc9f015..4e7e027119ff 100644 --- a/nnvm/src/c_api/c_api_common.h +++ b/nnvm/src/c_api/c_api_common.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file c_api_error.h diff --git a/nnvm/src/c_api/c_api_error.cc b/nnvm/src/c_api/c_api_error.cc index fd91bfb8b306..11509d79352e 100644 --- a/nnvm/src/c_api/c_api_error.cc +++ b/nnvm/src/c_api/c_api_error.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file c_api_error.cc diff --git a/nnvm/src/c_api/c_api_graph.cc b/nnvm/src/c_api/c_api_graph.cc index a0e84aef4482..831e1af57c5c 100644 --- a/nnvm/src/c_api/c_api_graph.cc +++ b/nnvm/src/c_api/c_api_graph.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file c_api_graph.cc diff --git a/nnvm/src/c_api/c_api_symbolic.cc b/nnvm/src/c_api/c_api_symbolic.cc index e175cfc7da25..ccf0a9a19241 100644 --- a/nnvm/src/c_api/c_api_symbolic.cc +++ b/nnvm/src/c_api/c_api_symbolic.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file c_api_symbolic.cc diff --git a/nnvm/src/compiler/alter_op_layout.cc b/nnvm/src/compiler/alter_op_layout.cc index f62e39efd9eb..d88f6eb9cae6 100644 --- a/nnvm/src/compiler/alter_op_layout.cc +++ b/nnvm/src/compiler/alter_op_layout.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file alter_op_layout.cc diff --git a/nnvm/src/compiler/compile_engine.cc b/nnvm/src/compiler/compile_engine.cc index c37572162a08..95ed87be5b86 100644 --- a/nnvm/src/compiler/compile_engine.cc +++ b/nnvm/src/compiler/compile_engine.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file compile_engine.cc diff --git a/nnvm/src/compiler/compile_engine.h b/nnvm/src/compiler/compile_engine.h index 23e5e1d1a49c..35287f5a9358 100644 --- a/nnvm/src/compiler/compile_engine.h +++ b/nnvm/src/compiler/compile_engine.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file compile_engine.h diff --git a/nnvm/src/compiler/fold_scale_axis.cc b/nnvm/src/compiler/fold_scale_axis.cc index 35e024efdc6a..54d7a3efd62b 100644 --- a/nnvm/src/compiler/fold_scale_axis.cc +++ b/nnvm/src/compiler/fold_scale_axis.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file fold_scale_axis.cc diff --git a/nnvm/src/compiler/graph_compile.cc b/nnvm/src/compiler/graph_compile.cc index 742de0386abc..c9330f3b665f 100644 --- a/nnvm/src/compiler/graph_compile.cc +++ b/nnvm/src/compiler/graph_compile.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file graph_compile.cc diff --git a/nnvm/src/compiler/graph_fuse.cc b/nnvm/src/compiler/graph_fuse.cc index d82dcfbe5035..2d9c64b12737 100644 --- a/nnvm/src/compiler/graph_fuse.cc +++ b/nnvm/src/compiler/graph_fuse.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file graph_fuse.cc diff --git a/nnvm/src/compiler/graph_fuse.h b/nnvm/src/compiler/graph_fuse.h index 72b2f627c6e4..1922acf72743 100644 --- a/nnvm/src/compiler/graph_fuse.h +++ b/nnvm/src/compiler/graph_fuse.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file graph_fuse.h diff --git a/nnvm/src/compiler/graph_hash.cc b/nnvm/src/compiler/graph_hash.cc index 0abba2591a1c..e825ef4efe57 100644 --- a/nnvm/src/compiler/graph_hash.cc +++ b/nnvm/src/compiler/graph_hash.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file graph_deep_compare.cc diff --git a/nnvm/src/compiler/graph_hash.h b/nnvm/src/compiler/graph_hash.h index 982c281a87ed..aed3462cf128 100644 --- a/nnvm/src/compiler/graph_hash.h +++ b/nnvm/src/compiler/graph_hash.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file graph_hash.h diff --git a/nnvm/src/compiler/graph_runtime.cc b/nnvm/src/compiler/graph_runtime.cc index 768e8f2be483..3bfebe3ba4e8 100644 --- a/nnvm/src/compiler/graph_runtime.cc +++ b/nnvm/src/compiler/graph_runtime.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file graph_runtime.cc diff --git a/nnvm/src/compiler/graph_runtime.h b/nnvm/src/compiler/graph_runtime.h index e5ba3681d2bf..3a847de83d9f 100644 --- a/nnvm/src/compiler/graph_runtime.h +++ b/nnvm/src/compiler/graph_runtime.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file graph_runtime.h diff --git a/nnvm/src/compiler/graph_transform.h b/nnvm/src/compiler/graph_transform.h index d5d7536ed369..df8fab126dce 100644 --- a/nnvm/src/compiler/graph_transform.h +++ b/nnvm/src/compiler/graph_transform.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file graph_transform.h diff --git a/nnvm/src/compiler/node_attr.h b/nnvm/src/compiler/node_attr.h index c4395ad98b69..74e064df59ee 100644 --- a/nnvm/src/compiler/node_attr.h +++ b/nnvm/src/compiler/node_attr.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file node_attr.h diff --git a/nnvm/src/compiler/packed_func_ext.cc b/nnvm/src/compiler/packed_func_ext.cc index 8530a5556b64..bbcc62a99ad8 100644 --- a/nnvm/src/compiler/packed_func_ext.cc +++ b/nnvm/src/compiler/packed_func_ext.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file packed_func_ext.cc diff --git a/nnvm/src/compiler/pattern_util.h b/nnvm/src/compiler/pattern_util.h index 1177e99bfbfc..83a142741e15 100644 --- a/nnvm/src/compiler/pattern_util.h +++ b/nnvm/src/compiler/pattern_util.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file pattern_util.h diff --git a/nnvm/src/compiler/precompute_prune.cc b/nnvm/src/compiler/precompute_prune.cc index c0c0c4b4c0ec..6116e9b2ca70 100644 --- a/nnvm/src/compiler/precompute_prune.cc +++ b/nnvm/src/compiler/precompute_prune.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file precompute_prune.cc diff --git a/nnvm/src/compiler/simplify_inference.cc b/nnvm/src/compiler/simplify_inference.cc index bf00bcb5a894..eade5a2df8b9 100644 --- a/nnvm/src/compiler/simplify_inference.cc +++ b/nnvm/src/compiler/simplify_inference.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file simplify_inference.cc diff --git a/nnvm/src/core/graph.cc b/nnvm/src/core/graph.cc index b8bcae70f2e0..0aae7edd9dd6 100644 --- a/nnvm/src/core/graph.cc +++ b/nnvm/src/core/graph.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file graph_attr_types.cc diff --git a/nnvm/src/core/node.cc b/nnvm/src/core/node.cc index fe04466a87d1..7cd5386997fb 100644 --- a/nnvm/src/core/node.cc +++ b/nnvm/src/core/node.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file node.cc diff --git a/nnvm/src/core/op.cc b/nnvm/src/core/op.cc index e554d36b4e8c..6c6c5e733d9f 100644 --- a/nnvm/src/core/op.cc +++ b/nnvm/src/core/op.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file op.cc diff --git a/nnvm/src/core/pass.cc b/nnvm/src/core/pass.cc index d72d4af00e65..dd14b51138d5 100644 --- a/nnvm/src/core/pass.cc +++ b/nnvm/src/core/pass.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file pass.cc diff --git a/nnvm/src/core/symbolic.cc b/nnvm/src/core/symbolic.cc index 938053aae688..32664b58ad10 100644 --- a/nnvm/src/core/symbolic.cc +++ b/nnvm/src/core/symbolic.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file symbolic.cc diff --git a/nnvm/src/pass/correct_layout.cc b/nnvm/src/pass/correct_layout.cc index cdf574b5fe29..4ce4b72a87dd 100644 --- a/nnvm/src/pass/correct_layout.cc +++ b/nnvm/src/pass/correct_layout.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file correct_layout.cc diff --git a/nnvm/src/pass/gradient.cc b/nnvm/src/pass/gradient.cc index 6e6d01d5f6a5..b29d24654c03 100644 --- a/nnvm/src/pass/gradient.cc +++ b/nnvm/src/pass/gradient.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file gradients.cc diff --git a/nnvm/src/pass/graph_algorithm.h b/nnvm/src/pass/graph_algorithm.h index e933ff6238bb..69b241b489d5 100644 --- a/nnvm/src/pass/graph_algorithm.h +++ b/nnvm/src/pass/graph_algorithm.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file graph_algorithm.h diff --git a/nnvm/src/pass/infer_shape_type.cc b/nnvm/src/pass/infer_shape_type.cc index d7ab212f3e9a..1f6c82a3c769 100644 --- a/nnvm/src/pass/infer_shape_type.cc +++ b/nnvm/src/pass/infer_shape_type.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file infer_shape.cc diff --git a/nnvm/src/pass/order_mutation.cc b/nnvm/src/pass/order_mutation.cc index e91d114ea101..0f74180bf5af 100644 --- a/nnvm/src/pass/order_mutation.cc +++ b/nnvm/src/pass/order_mutation.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file order_mutation.cc diff --git a/nnvm/src/pass/place_device.cc b/nnvm/src/pass/place_device.cc index 0c2307fb1a33..3e1e9b8db9e6 100644 --- a/nnvm/src/pass/place_device.cc +++ b/nnvm/src/pass/place_device.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file place_device.cc diff --git a/nnvm/src/pass/plan_memory.cc b/nnvm/src/pass/plan_memory.cc index eff7fb9a5939..9b8fa0c32de5 100644 --- a/nnvm/src/pass/plan_memory.cc +++ b/nnvm/src/pass/plan_memory.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file plan_memory.cc diff --git a/nnvm/src/pass/print_graph_ir.cc b/nnvm/src/pass/print_graph_ir.cc index e10185b1951f..cb94a0db6875 100644 --- a/nnvm/src/pass/print_graph_ir.cc +++ b/nnvm/src/pass/print_graph_ir.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file print_graph_ir.cc diff --git a/nnvm/src/pass/saveload_json.cc b/nnvm/src/pass/saveload_json.cc index 4a0706b6d501..2343a1229131 100644 --- a/nnvm/src/pass/saveload_json.cc +++ b/nnvm/src/pass/saveload_json.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file saveload_json.cc diff --git a/nnvm/src/top/elemwise_op_common.h b/nnvm/src/top/elemwise_op_common.h index ad8fc3d54ba8..af2c7523d415 100644 --- a/nnvm/src/top/elemwise_op_common.h +++ b/nnvm/src/top/elemwise_op_common.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file elemwise_op_common.h diff --git a/nnvm/src/top/image/resize.cc b/nnvm/src/top/image/resize.cc index b89070fe3897..5526f17c9b1e 100644 --- a/nnvm/src/top/image/resize.cc +++ b/nnvm/src/top/image/resize.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file resize.cc diff --git a/nnvm/src/top/image/resize.h b/nnvm/src/top/image/resize.h index 7237152f7525..831425e55094 100644 --- a/nnvm/src/top/image/resize.h +++ b/nnvm/src/top/image/resize.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file resize.h diff --git a/nnvm/src/top/nn/convolution.cc b/nnvm/src/top/nn/convolution.cc index 601e57ab325b..84ad737cf68a 100644 --- a/nnvm/src/top/nn/convolution.cc +++ b/nnvm/src/top/nn/convolution.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file convolution.cc diff --git a/nnvm/src/top/nn/nn.cc b/nnvm/src/top/nn/nn.cc index f213fa3a19ec..da73d3bcca73 100644 --- a/nnvm/src/top/nn/nn.cc +++ b/nnvm/src/top/nn/nn.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file nn.cc diff --git a/nnvm/src/top/nn/nn_common.h b/nnvm/src/top/nn/nn_common.h index 4dc9f7db54c0..a2ef789efd97 100644 --- a/nnvm/src/top/nn/nn_common.h +++ b/nnvm/src/top/nn/nn_common.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file nn_common.h diff --git a/nnvm/src/top/nn/pooling.cc b/nnvm/src/top/nn/pooling.cc index 6a53e1994fc1..13c698babc90 100644 --- a/nnvm/src/top/nn/pooling.cc +++ b/nnvm/src/top/nn/pooling.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors diff --git a/nnvm/src/top/nn/upsampling.cc b/nnvm/src/top/nn/upsampling.cc index f4bbeb62aa29..a7dab672ef25 100644 --- a/nnvm/src/top/nn/upsampling.cc +++ b/nnvm/src/top/nn/upsampling.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file upsampling.cc diff --git a/nnvm/src/top/op_common.h b/nnvm/src/top/op_common.h index 4cc17d9b62ef..64475fe3e6e8 100644 --- a/nnvm/src/top/op_common.h +++ b/nnvm/src/top/op_common.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file op_common.h diff --git a/nnvm/src/top/tensor/broadcast.cc b/nnvm/src/top/tensor/broadcast.cc index 6141ff1ae621..7916d41ffee7 100644 --- a/nnvm/src/top/tensor/broadcast.cc +++ b/nnvm/src/top/tensor/broadcast.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file broadcast.cc diff --git a/nnvm/src/top/tensor/elemwise.cc b/nnvm/src/top/tensor/elemwise.cc index 2d9813e22131..b8be1150286d 100644 --- a/nnvm/src/top/tensor/elemwise.cc +++ b/nnvm/src/top/tensor/elemwise.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file elemwise.cc diff --git a/nnvm/src/top/tensor/matrix_op.cc b/nnvm/src/top/tensor/matrix_op.cc index de95eddee1f6..ed54b8d75cba 100644 --- a/nnvm/src/top/tensor/matrix_op.cc +++ b/nnvm/src/top/tensor/matrix_op.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file matrix_op.cc diff --git a/nnvm/src/top/tensor/reduce.cc b/nnvm/src/top/tensor/reduce.cc index 105765fccc61..e95b16ddf6a4 100644 --- a/nnvm/src/top/tensor/reduce.cc +++ b/nnvm/src/top/tensor/reduce.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file reduce.cc diff --git a/nnvm/src/top/tensor/state_op.cc b/nnvm/src/top/tensor/state_op.cc index 13c3563c4201..c92e5c1c9dc5 100644 --- a/nnvm/src/top/tensor/state_op.cc +++ b/nnvm/src/top/tensor/state_op.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file state_op.cc diff --git a/nnvm/src/top/tensor/transform.cc b/nnvm/src/top/tensor/transform.cc index d12fa0a06063..cafb99926bfa 100644 --- a/nnvm/src/top/tensor/transform.cc +++ b/nnvm/src/top/tensor/transform.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file transform.cc diff --git a/nnvm/src/top/vision/nms.cc b/nnvm/src/top/vision/nms.cc index e69a7cb2f036..81761758aa14 100644 --- a/nnvm/src/top/vision/nms.cc +++ b/nnvm/src/top/vision/nms.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file nms.cc diff --git a/nnvm/src/top/vision/ssd/mutibox_op.cc b/nnvm/src/top/vision/ssd/mutibox_op.cc index 7f1aca5d2b82..4eaf91056be2 100644 --- a/nnvm/src/top/vision/ssd/mutibox_op.cc +++ b/nnvm/src/top/vision/ssd/mutibox_op.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file multibox_op.cc diff --git a/nnvm/src/top/vision/yolo/reorg.cc b/nnvm/src/top/vision/yolo/reorg.cc index e44d77c07953..569dc0f0daf5 100644 --- a/nnvm/src/top/vision/yolo/reorg.cc +++ b/nnvm/src/top/vision/yolo/reorg.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file reorg.cc diff --git a/nnvm/src/top/vision/yolo/reorg.h b/nnvm/src/top/vision/yolo/reorg.h index a16edeceaec2..8a9cace6848e 100644 --- a/nnvm/src/top/vision/yolo/reorg.h +++ b/nnvm/src/top/vision/yolo/reorg.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file reorg.h diff --git a/nnvm/tests/cpp/op_test.cc b/nnvm/tests/cpp/op_test.cc index c97952dda1b9..4c771655d87b 100644 --- a/nnvm/tests/cpp/op_test.cc +++ b/nnvm/tests/cpp/op_test.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #include #include #include diff --git a/nnvm/tests/cpp/tuple_test.cc b/nnvm/tests/cpp/tuple_test.cc index 806fdc42ac20..7bf59b5db7c8 100644 --- a/nnvm/tests/cpp/tuple_test.cc +++ b/nnvm/tests/cpp/tuple_test.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #include #include #include diff --git a/nnvm/tests/python/compiler/test_alter_op_layout.py b/nnvm/tests/python/compiler/test_alter_op_layout.py index cc3df61a28c7..aad634f03843 100644 --- a/nnvm/tests/python/compiler/test_alter_op_layout.py +++ b/nnvm/tests/python/compiler/test_alter_op_layout.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Unittest cases for AlterOpLayout pass""" from nnvm import symbol as sym from nnvm.compiler import graph_attr diff --git a/nnvm/tests/python/compiler/test_autotvm_task_extraction.py b/nnvm/tests/python/compiler/test_autotvm_task_extraction.py index fd14934f8ade..1ecbf053f923 100644 --- a/nnvm/tests/python/compiler/test_autotvm_task_extraction.py +++ b/nnvm/tests/python/compiler/test_autotvm_task_extraction.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test task extraction for autotvm""" import nnvm.testing diff --git a/nnvm/tests/python/compiler/test_build.py b/nnvm/tests/python/compiler/test_build.py index 387225f550ab..a2a5ac659c8f 100644 --- a/nnvm/tests/python/compiler/test_build.py +++ b/nnvm/tests/python/compiler/test_build.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import tvm diff --git a/nnvm/tests/python/compiler/test_compiler_cache.py b/nnvm/tests/python/compiler/test_compiler_cache.py index d50100741533..c974a1d7364d 100644 --- a/nnvm/tests/python/compiler/test_compiler_cache.py +++ b/nnvm/tests/python/compiler/test_compiler_cache.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import tvm from tvm.contrib import graph_runtime diff --git a/nnvm/tests/python/compiler/test_fold_axis.py b/nnvm/tests/python/compiler/test_fold_axis.py index a7611fbde797..2bceb652162a 100644 --- a/nnvm/tests/python/compiler/test_fold_axis.py +++ b/nnvm/tests/python/compiler/test_fold_axis.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Unittest cases for fold_axis""" import tvm import nnvm diff --git a/nnvm/tests/python/compiler/test_graph_pass.py b/nnvm/tests/python/compiler/test_graph_pass.py index ec5ab0479389..d65a2be9abf8 100644 --- a/nnvm/tests/python/compiler/test_graph_pass.py +++ b/nnvm/tests/python/compiler/test_graph_pass.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Unittest cases for graph pass""" import nnvm import nnvm.compiler diff --git a/nnvm/tests/python/compiler/test_nhwc_layout.py b/nnvm/tests/python/compiler/test_nhwc_layout.py index f1aced94a0b3..e3747daf8563 100644 --- a/nnvm/tests/python/compiler/test_nhwc_layout.py +++ b/nnvm/tests/python/compiler/test_nhwc_layout.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import tvm from tvm.contrib import graph_runtime as runtime diff --git a/nnvm/tests/python/compiler/test_op_fusion.py b/nnvm/tests/python/compiler/test_op_fusion.py index 4c4773773d47..bc0caeecf58c 100644 --- a/nnvm/tests/python/compiler/test_op_fusion.py +++ b/nnvm/tests/python/compiler/test_op_fusion.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import nnvm import numpy as np import tvm diff --git a/nnvm/tests/python/compiler/test_optimizer.py b/nnvm/tests/python/compiler/test_optimizer.py index 413227d88091..86a9b71b46dc 100644 --- a/nnvm/tests/python/compiler/test_optimizer.py +++ b/nnvm/tests/python/compiler/test_optimizer.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import tvm import nnvm diff --git a/nnvm/tests/python/compiler/test_param_dict.py b/nnvm/tests/python/compiler/test_param_dict.py index 447db305d98c..b30f8f99082c 100644 --- a/nnvm/tests/python/compiler/test_param_dict.py +++ b/nnvm/tests/python/compiler/test_param_dict.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import os import numpy as np import nnvm.compiler diff --git a/nnvm/tests/python/compiler/test_rpc_exec.py b/nnvm/tests/python/compiler/test_rpc_exec.py index 8177f1b153ab..1584f7c589a4 100644 --- a/nnvm/tests/python/compiler/test_rpc_exec.py +++ b/nnvm/tests/python/compiler/test_rpc_exec.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm from tvm import rpc from tvm.contrib import util, graph_runtime diff --git a/nnvm/tests/python/compiler/test_simplify_inference.py b/nnvm/tests/python/compiler/test_simplify_inference.py index fd0e1e3c182e..2f520bd6c125 100644 --- a/nnvm/tests/python/compiler/test_simplify_inference.py +++ b/nnvm/tests/python/compiler/test_simplify_inference.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Unittest cases for simplify batch_norm""" import nnvm from nnvm import symbol as sym diff --git a/nnvm/tests/python/compiler/test_to_relay.py b/nnvm/tests/python/compiler/test_to_relay.py index 25037cfd3587..e79831d06cf2 100644 --- a/nnvm/tests/python/compiler/test_to_relay.py +++ b/nnvm/tests/python/compiler/test_to_relay.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import nnvm from nnvm import testing from nnvm import to_relay diff --git a/nnvm/tests/python/compiler/test_top_assign.py b/nnvm/tests/python/compiler/test_top_assign.py index 95c16c96c443..dae0506edc36 100644 --- a/nnvm/tests/python/compiler/test_top_assign.py +++ b/nnvm/tests/python/compiler/test_top_assign.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import tvm diff --git a/nnvm/tests/python/compiler/test_top_level1.py b/nnvm/tests/python/compiler/test_top_level1.py index d89bf359f2ac..ae6266cdde54 100644 --- a/nnvm/tests/python/compiler/test_top_level1.py +++ b/nnvm/tests/python/compiler/test_top_level1.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import tvm from tvm.contrib import graph_runtime diff --git a/nnvm/tests/python/compiler/test_top_level2.py b/nnvm/tests/python/compiler/test_top_level2.py index 0585f3c974b7..b25feb74793f 100644 --- a/nnvm/tests/python/compiler/test_top_level2.py +++ b/nnvm/tests/python/compiler/test_top_level2.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import tvm diff --git a/nnvm/tests/python/compiler/test_top_level3.py b/nnvm/tests/python/compiler/test_top_level3.py index 11af2d0bc9c4..c60f0450b30a 100644 --- a/nnvm/tests/python/compiler/test_top_level3.py +++ b/nnvm/tests/python/compiler/test_top_level3.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import tvm from tvm.contrib import graph_runtime diff --git a/nnvm/tests/python/compiler/test_top_level4.py b/nnvm/tests/python/compiler/test_top_level4.py index 6a42047151e5..f8d4f5bf657e 100644 --- a/nnvm/tests/python/compiler/test_top_level4.py +++ b/nnvm/tests/python/compiler/test_top_level4.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import math import numpy as np import tvm diff --git a/nnvm/tests/python/frontend/caffe2/test_forward.py b/nnvm/tests/python/frontend/caffe2/test_forward.py index 68a1ab7eda2b..9f3c5c9fa85a 100644 --- a/nnvm/tests/python/frontend/caffe2/test_forward.py +++ b/nnvm/tests/python/frontend/caffe2/test_forward.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import nnvm import tvm diff --git a/nnvm/tests/python/frontend/caffe2/test_graph.py b/nnvm/tests/python/frontend/caffe2/test_graph.py old mode 100755 new mode 100644 index 425fc9a6201d..c8203815e6d0 --- a/nnvm/tests/python/frontend/caffe2/test_graph.py +++ b/nnvm/tests/python/frontend/caffe2/test_graph.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test graph equality of caffe2 models.""" import nnvm from nnvm.compiler import graph_util, graph_attr diff --git a/nnvm/tests/python/frontend/coreml/model_zoo/__init__.py b/nnvm/tests/python/frontend/coreml/model_zoo/__init__.py index d43768f1e376..aa28475776ef 100644 --- a/nnvm/tests/python/frontend/coreml/model_zoo/__init__.py +++ b/nnvm/tests/python/frontend/coreml/model_zoo/__init__.py @@ -18,7 +18,7 @@ def get_resnet50(): def get_cat_image(): url = 'https://gist.githubusercontent.com/zhreshold/bcda4716699ac97ea44f791c24310193/raw/fa7ef0e9c9a5daea686d6473a62aacd1a5885849/cat.png' dst = 'cat.png' - real_dst = download_testdata(url, dst, module='coreml') + real_dst = download_testdata(url, dst, module='data') img = Image.open(real_dst).resize((224, 224)) img = np.transpose(img, (2, 0, 1))[np.newaxis, :] return np.asarray(img) diff --git a/nnvm/tests/python/frontend/coreml/test_forward.py b/nnvm/tests/python/frontend/coreml/test_forward.py index 31ab4b89ef4f..679afe4e86bc 100644 --- a/nnvm/tests/python/frontend/coreml/test_forward.py +++ b/nnvm/tests/python/frontend/coreml/test_forward.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np from coremltools.models.neural_network import NeuralNetworkBuilder diff --git a/nnvm/tests/python/frontend/darknet/test_forward.py b/nnvm/tests/python/frontend/darknet/test_forward.py index 7cd47d382d22..7f45a6149efc 100644 --- a/nnvm/tests/python/frontend/darknet/test_forward.py +++ b/nnvm/tests/python/frontend/darknet/test_forward.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Compile Darknet Models ===================== @@ -5,14 +21,11 @@ All the required models and libraries will be downloaded from the internet by the script. """ -import os -import requests -import sys -import urllib import numpy as np import tvm from tvm.contrib import graph_runtime from tvm.contrib.download import download_testdata +download_testdata.__test__ = False from nnvm import frontend from nnvm.testing.darknet import LAYERTYPE from nnvm.testing.darknet import __darknetffi__ @@ -23,6 +36,10 @@ + DARKNET_LIB + '?raw=true' LIB = __darknetffi__.dlopen(download_testdata(DARKNETLIB_URL, DARKNET_LIB, module='darknet')) +DARKNET_TEST_IMAGE_NAME = 'dog.jpg' +DARKNET_TEST_IMAGE_URL = 'https://github.com/siju-samuel/darknet/blob/master/data/' + DARKNET_TEST_IMAGE_NAME +'?raw=true' +DARKNET_TEST_IMAGE_PATH = download_testdata(DARKNET_TEST_IMAGE_URL, DARKNET_TEST_IMAGE_NAME, module='data') + def _read_memory_buffer(shape, data, dtype='float32'): length = 1 for x in shape: @@ -60,7 +77,7 @@ def _load_net(cfg_url, cfg_name, weights_url, weights_name): net = LIB.load_network(cfg_path.encode('utf-8'), weights_path.encode('utf-8'), 0) return net -def test_forward(net, build_dtype='float32'): +def verify_darknet_frontend(net, build_dtype='float32'): '''Test network with given input image on both darknet and tvm''' def get_darknet_output(net, img): LIB.network_predict_image(net, img) @@ -101,10 +118,7 @@ def get_darknet_output(net, img): dtype = 'float32' - test_image = 'dog.jpg' - img_url = 'https://github.com/siju-samuel/darknet/blob/master/data/' + test_image +'?raw=true' - img_path = download_testdata(img_url, test_image, module='darknet') - img = LIB.letterbox_image(LIB.load_image_color(img_path.encode('utf-8'), 0, 0), net.w, net.h) + img = LIB.letterbox_image(LIB.load_image_color(DARKNET_TEST_IMAGE_PATH.encode('utf-8'), 0, 0), net.w, net.h) darknet_output = get_darknet_output(net, img) batch_size = 1 data = np.empty([batch_size, img.c, img.h, img.w], dtype) @@ -119,7 +133,7 @@ def get_darknet_output(net, img): for tvm_outs, darknet_out in zip(tvm_out, darknet_output): tvm.testing.assert_allclose(darknet_out, tvm_outs, rtol=1e-3, atol=1e-3) -def test_rnn_forward(net): +def verify_rnn_forward(net): '''Test network with given input data on both darknet and tvm''' def get_darknet_network_predict(net, data): return LIB.network_predict(net, data) @@ -146,7 +160,7 @@ def test_forward_extraction(): cfg_url = 'https://github.com/pjreddie/darknet/blob/master/cfg/' + cfg_name + '?raw=true' weights_url = 'http://pjreddie.com/media/files/' + weights_name + '?raw=true' net = _load_net(cfg_url, cfg_name, weights_url, weights_name) - test_forward(net) + verify_darknet_frontend(net) LIB.free_network(net) def test_forward_alexnet(): @@ -157,7 +171,7 @@ def test_forward_alexnet(): cfg_url = 'https://github.com/pjreddie/darknet/blob/master/cfg/' + cfg_name + '?raw=true' weights_url = 'http://pjreddie.com/media/files/' + weights_name + '?raw=true' net = _load_net(cfg_url, cfg_name, weights_url, weights_name) - test_forward(net) + verify_darknet_frontend(net) LIB.free_network(net) def test_forward_resnet50(): @@ -168,7 +182,7 @@ def test_forward_resnet50(): cfg_url = 'https://github.com/pjreddie/darknet/blob/master/cfg/' + cfg_name + '?raw=true' weights_url = 'http://pjreddie.com/media/files/' + weights_name + '?raw=true' net = _load_net(cfg_url, cfg_name, weights_url, weights_name) - test_forward(net) + verify_darknet_frontend(net) LIB.free_network(net) def test_forward_yolov2(): @@ -180,7 +194,7 @@ def test_forward_yolov2(): weights_url = 'http://pjreddie.com/media/files/' + weights_name + '?raw=true' net = _load_net(cfg_url, cfg_name, weights_url, weights_name) build_dtype = {} - test_forward(net, build_dtype) + verify_darknet_frontend(net, build_dtype) LIB.free_network(net) def test_forward_yolov3(): @@ -192,7 +206,7 @@ def test_forward_yolov3(): weights_url = 'http://pjreddie.com/media/files/' + weights_name + '?raw=true' net = _load_net(cfg_url, cfg_name, weights_url, weights_name) build_dtype = {} - test_forward(net, build_dtype) + verify_darknet_frontend(net, build_dtype) LIB.free_network(net) def test_forward_convolutional(): @@ -202,7 +216,7 @@ def test_forward_convolutional(): net.layers[0] = layer net.w = net.h = 224 LIB.resize_network(net, 224, 224) - test_forward(net) + verify_darknet_frontend(net) LIB.free_network(net) def test_forward_dense(): @@ -212,7 +226,7 @@ def test_forward_dense(): net.layers[0] = layer net.w = net.h = 5 LIB.resize_network(net, 5, 5) - test_forward(net) + verify_darknet_frontend(net) LIB.free_network(net) def test_forward_dense_batchnorm(): @@ -226,7 +240,7 @@ def test_forward_dense_batchnorm(): net.layers[0] = layer net.w = net.h = 2 LIB.resize_network(net, 2, 2) - test_forward(net) + verify_darknet_frontend(net) LIB.free_network(net) def test_forward_maxpooling(): @@ -236,7 +250,7 @@ def test_forward_maxpooling(): net.layers[0] = layer net.w = net.h = 224 LIB.resize_network(net, 224, 224) - test_forward(net) + verify_darknet_frontend(net) LIB.free_network(net) def test_forward_avgpooling(): @@ -246,7 +260,7 @@ def test_forward_avgpooling(): net.layers[0] = layer net.w = net.h = 224 LIB.resize_network(net, 224, 224) - test_forward(net) + verify_darknet_frontend(net) LIB.free_network(net) def test_forward_batch_norm(): @@ -259,7 +273,7 @@ def test_forward_batch_norm(): net.layers[0] = layer net.w = net.h = 224 LIB.resize_network(net, 224, 224) - test_forward(net) + verify_darknet_frontend(net) LIB.free_network(net) def test_forward_shortcut(): @@ -276,7 +290,7 @@ def test_forward_shortcut(): net.layers[2] = layer_3 net.w = net.h = 224 LIB.resize_network(net, 224, 224) - test_forward(net) + verify_darknet_frontend(net) LIB.free_network(net) def test_forward_reorg(): @@ -288,21 +302,21 @@ def test_forward_reorg(): net.layers[1] = layer_2 net.w = net.h = 222 LIB.resize_network(net, 222, 222) - test_forward(net) + verify_darknet_frontend(net) LIB.free_network(net) def test_forward_region(): '''test region layer''' net = LIB.make_network(2) - layer_1 = LIB.make_convolutional_layer(1, 224, 224, 3, 8, 1, 3, 2, 0, 1, 0, 0, 0, 0) - layer_2 = LIB.make_region_layer(1, 111, 111, 2, 2, 1) + layer_1 = LIB.make_convolutional_layer(1, 19, 19, 3, 425, 1, 1, 1, 0, 1, 0, 0, 0, 0) + layer_2 = LIB.make_region_layer(1, 19, 19, 5, 80, 4) layer_2.softmax = 1 net.layers[0] = layer_1 net.layers[1] = layer_2 - net.w = net.h = 224 - LIB.resize_network(net, 224, 224) + net.w = net.h = 19 + LIB.resize_network(net, 19, 19) build_dtype = {} - test_forward(net, build_dtype) + verify_darknet_frontend(net, build_dtype) LIB.free_network(net) def test_forward_yolo_op(): @@ -315,7 +329,7 @@ def test_forward_yolo_op(): net.w = net.h = 224 LIB.resize_network(net, 224, 224) build_dtype = {} - test_forward(net, build_dtype) + verify_darknet_frontend(net, build_dtype) LIB.free_network(net) def test_forward_upsample(): @@ -326,7 +340,7 @@ def test_forward_upsample(): net.layers[0] = layer net.w = net.h = 19 LIB.resize_network(net, 19, 19) - test_forward(net) + verify_darknet_frontend(net) LIB.free_network(net) def test_forward_l2normalize(): @@ -339,7 +353,7 @@ def test_forward_l2normalize(): net.layers[0] = layer net.w = net.h = 224 LIB.resize_network(net, 224, 224) - test_forward(net) + verify_darknet_frontend(net) LIB.free_network(net) def test_forward_elu(): @@ -350,7 +364,7 @@ def test_forward_elu(): net.layers[0] = layer_1 net.w = net.h = 224 LIB.resize_network(net, 224, 224) - test_forward(net) + verify_darknet_frontend(net) LIB.free_network(net) def test_forward_softmax(): @@ -361,7 +375,7 @@ def test_forward_softmax(): net.layers[0] = layer_1 net.w = net.h = 5 LIB.resize_network(net, net.w, net.h) - test_forward(net) + verify_darknet_frontend(net) LIB.free_network(net) def test_forward_softmax_temperature(): @@ -372,7 +386,7 @@ def test_forward_softmax_temperature(): net.layers[0] = layer_1 net.w = net.h = 5 LIB.resize_network(net, net.w, net.h) - test_forward(net) + verify_darknet_frontend(net) LIB.free_network(net) def test_forward_rnn(): @@ -391,10 +405,10 @@ def test_forward_rnn(): net.outputs = outputs net.w = net.h = 0 LIB.resize_network(net, net.w, net.h) - test_rnn_forward(net) + verify_rnn_forward(net) LIB.free_network(net) -def test_forward_crnn(): +def _test_forward_crnn(): '''test CRNN layer''' net = LIB.make_network(1) batch = 1 @@ -416,7 +430,7 @@ def test_forward_crnn(): net.w = w net.h = h LIB.resize_network(net, net.w, net.h) - test_forward(net) + verify_darknet_frontend(net) LIB.free_network(net) def test_forward_lstm(): @@ -434,7 +448,7 @@ def test_forward_lstm(): net.outputs = outputs net.w = net.h = 0 LIB.resize_network(net, net.w, net.h) - test_rnn_forward(net) + verify_rnn_forward(net) LIB.free_network(net) def test_forward_gru(): @@ -452,7 +466,7 @@ def test_forward_gru(): net.outputs = outputs net.w = net.h = 0 LIB.resize_network(net, net.w, net.h) - test_rnn_forward(net) + verify_rnn_forward(net) LIB.free_network(net) def test_forward_activation_logistic(): @@ -478,7 +492,7 @@ def test_forward_activation_logistic(): net.w = w net.h = h LIB.resize_network(net, net.w, net.h) - test_forward(net) + verify_darknet_frontend(net) LIB.free_network(net) if __name__ == '__main__': @@ -504,7 +518,8 @@ def test_forward_activation_logistic(): test_forward_l2normalize() test_forward_elu() test_forward_rnn() - test_forward_crnn() +# FIXME: Skip CRNN test since it causes segfault in libdarknet2.0.so +# _test_forward_crnn() test_forward_lstm() test_forward_gru() test_forward_activation_logistic() diff --git a/nnvm/tests/python/frontend/keras/test_forward.py b/nnvm/tests/python/frontend/keras/test_forward.py index 618af3b2e417..78e4204e8250 100644 --- a/nnvm/tests/python/frontend/keras/test_forward.py +++ b/nnvm/tests/python/frontend/keras/test_forward.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import nnvm import tvm diff --git a/nnvm/tests/python/frontend/mxnet/model_zoo/dcgan.py b/nnvm/tests/python/frontend/mxnet/model_zoo/dcgan.py index 8af030b6b184..e606b78e1597 100644 --- a/nnvm/tests/python/frontend/mxnet/model_zoo/dcgan.py +++ b/nnvm/tests/python/frontend/mxnet/model_zoo/dcgan.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=unused-argument """ The MXNet symbol of DCGAN generator diff --git a/nnvm/tests/python/frontend/mxnet/model_zoo/dqn.py b/nnvm/tests/python/frontend/mxnet/model_zoo/dqn.py index e037511efdf2..e661e18debcb 100644 --- a/nnvm/tests/python/frontend/mxnet/model_zoo/dqn.py +++ b/nnvm/tests/python/frontend/mxnet/model_zoo/dqn.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ The mxnet symbol of Nature DQN diff --git a/nnvm/tests/python/frontend/mxnet/model_zoo/inception_v3.py b/nnvm/tests/python/frontend/mxnet/model_zoo/inception_v3.py index b8585bf05037..8e8f36a3e644 100644 --- a/nnvm/tests/python/frontend/mxnet/model_zoo/inception_v3.py +++ b/nnvm/tests/python/frontend/mxnet/model_zoo/inception_v3.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Inception V3, suitable for images with around 299 x 299 diff --git a/nnvm/tests/python/frontend/mxnet/model_zoo/squeezenet.py b/nnvm/tests/python/frontend/mxnet/model_zoo/squeezenet.py index deb896a21385..093da51a78a7 100644 --- a/nnvm/tests/python/frontend/mxnet/model_zoo/squeezenet.py +++ b/nnvm/tests/python/frontend/mxnet/model_zoo/squeezenet.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Symbol of SqueezeNet diff --git a/nnvm/tests/python/frontend/mxnet/test_forward.py b/nnvm/tests/python/frontend/mxnet/test_forward.py index 581ae75a4bbc..db5534daee1a 100644 --- a/nnvm/tests/python/frontend/mxnet/test_forward.py +++ b/nnvm/tests/python/frontend/mxnet/test_forward.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import topi diff --git a/nnvm/tests/python/frontend/mxnet/test_graph.py b/nnvm/tests/python/frontend/mxnet/test_graph.py index e89224cd969e..1bbd0a97e8e1 100644 --- a/nnvm/tests/python/frontend/mxnet/test_graph.py +++ b/nnvm/tests/python/frontend/mxnet/test_graph.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import mxnet as mx import nnvm from nnvm.compiler import graph_util, graph_attr diff --git a/nnvm/tests/python/frontend/onnx/model_zoo/super_resolution.py b/nnvm/tests/python/frontend/onnx/model_zoo/super_resolution.py index 19662322a66b..a98478e58307 100644 --- a/nnvm/tests/python/frontend/onnx/model_zoo/super_resolution.py +++ b/nnvm/tests/python/frontend/onnx/model_zoo/super_resolution.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """NNVM symbol corresponding to super_resolution.onnx example.""" from nnvm import sym diff --git a/nnvm/tests/python/frontend/onnx/test_forward.py b/nnvm/tests/python/frontend/onnx/test_forward.py index a98ef297f1a9..24f84ee73efe 100644 --- a/nnvm/tests/python/frontend/onnx/test_forward.py +++ b/nnvm/tests/python/frontend/onnx/test_forward.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import math import nnvm diff --git a/nnvm/tests/python/frontend/onnx/test_graph.py b/nnvm/tests/python/frontend/onnx/test_graph.py deleted file mode 100755 index b3961c1a38fd..000000000000 --- a/nnvm/tests/python/frontend/onnx/test_graph.py +++ /dev/null @@ -1,34 +0,0 @@ -"""Test graph equality of onnx models.""" -import nnvm -import onnx -from nnvm.compiler import graph_util, graph_attr -from model_zoo import super_resolution, super_resolution_sym -from model_zoo import squeezenet as squeezenet - -def compare_graph(onnx_file, nnvm_sym, ishape): - onnx_model = onnx.load_model(onnx_file) - onnx_sym, params = nnvm.frontend.from_onnx(onnx_model) - g1 = nnvm.graph.create(onnx_sym) - g2 = nnvm.graph.create(nnvm_sym) - input_name = onnx_model.graph.input[0].name - ishapes = {input_name: ishape} - graph_attr.set_shape_inputs(g1, ishapes) - graph_attr.set_shape_inputs(g2, ishapes) - g1 = g1.apply("InferShape").apply("SimplifyInference") - g2 = g2.apply("InferShape").apply("SimplifyInference") - graph_util.check_graph_equal(g1, g2) - -def test_super_resolution_example(): - fname, symbol = "super_resolution.onnx", super_resolution_sym - compare_graph(fname, symbol, ishape=(1, 1, 224, 224)) - -def test_squeeze_net(): - # Only works for model downloaded from - # https://github.com/onnx/models/tree/master/squeezenet - fname = "squeezenet1_1.onnx" - symbol, params = squeezenet.get_workload(version='1.1') - compare_graph(fname, symbol, ishape=(1, 3, 224, 224)) - -if __name__ == '__main__': - test_super_resolution_example() - test_squeeze_net() diff --git a/nnvm/tests/python/frontend/tensorflow/test_forward.py b/nnvm/tests/python/frontend/tensorflow/test_forward.py index 0a7cfac91bfa..54bbe085f66d 100644 --- a/nnvm/tests/python/frontend/tensorflow/test_forward.py +++ b/nnvm/tests/python/frontend/tensorflow/test_forward.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=import-self, invalid-name, unused-argument """ Tensorflow testcases diff --git a/nnvm/tests/python/unittest/test_correct_layout.py b/nnvm/tests/python/unittest/test_correct_layout.py index 8961498a579e..5d313fbacb3e 100644 --- a/nnvm/tests/python/unittest/test_correct_layout.py +++ b/nnvm/tests/python/unittest/test_correct_layout.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import nnvm import nnvm.symbol as sym import nnvm.graph as graph diff --git a/nnvm/tests/python/unittest/test_graph.py b/nnvm/tests/python/unittest/test_graph.py index 09d249700ad9..1ba0a2487cee 100644 --- a/nnvm/tests/python/unittest/test_graph.py +++ b/nnvm/tests/python/unittest/test_graph.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import json import nnvm.symbol as sym import nnvm.graph as graph diff --git a/nnvm/tests/python/unittest/test_graph_gradient.py b/nnvm/tests/python/unittest/test_graph_gradient.py index d3f25097819b..4ae6053c946f 100644 --- a/nnvm/tests/python/unittest/test_graph_gradient.py +++ b/nnvm/tests/python/unittest/test_graph_gradient.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import nnvm.symbol as sym from nnvm.compiler import graph_util @@ -126,7 +142,7 @@ def test_multi_loss_graph_gradients(): # infer type in_dtypes, out_dtypes = graph_util.infer_dtype(grad_g) assert out_dtypes == ['float32', 'float32'] - + # test reverse infer type for label assert grad_g.apply('InferType').json_attr('dtype_num_unknown_nodes') == 0 diff --git a/nnvm/tests/python/unittest/test_infer_shape.py b/nnvm/tests/python/unittest/test_infer_shape.py index bbd92cea7b5f..c394fab562f2 100644 --- a/nnvm/tests/python/unittest/test_infer_shape.py +++ b/nnvm/tests/python/unittest/test_infer_shape.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import json import nnvm.symbol as sym import nnvm.graph as graph diff --git a/nnvm/tests/python/unittest/test_pass_saveload_json.py b/nnvm/tests/python/unittest/test_pass_saveload_json.py index 7b5f5ea6867a..a8b067c8fe24 100644 --- a/nnvm/tests/python/unittest/test_pass_saveload_json.py +++ b/nnvm/tests/python/unittest/test_pass_saveload_json.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import nnvm from tvm.contrib import util diff --git a/nnvm/tests/python/unittest/test_symbol.py b/nnvm/tests/python/unittest/test_symbol.py index 93d4fea26445..a54dec170aae 100644 --- a/nnvm/tests/python/unittest/test_symbol.py +++ b/nnvm/tests/python/unittest/test_symbol.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import nnvm.symbol as sym from nnvm import NNVMError diff --git a/nnvm/tests/python/unittest/test_top_level1.py b/nnvm/tests/python/unittest/test_top_level1.py index cf0baf4c3696..2d646dc16ae4 100644 --- a/nnvm/tests/python/unittest/test_top_level1.py +++ b/nnvm/tests/python/unittest/test_top_level1.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import nnvm.symbol as sym import nnvm.graph as graph diff --git a/nnvm/tests/python/unittest/test_top_level2.py b/nnvm/tests/python/unittest/test_top_level2.py index df34549fbe46..b327356b5cc0 100644 --- a/nnvm/tests/python/unittest/test_top_level2.py +++ b/nnvm/tests/python/unittest/test_top_level2.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import nnvm.symbol as sym def test_conv2d(): diff --git a/nnvm/tests/python/unittest/test_top_level3.py b/nnvm/tests/python/unittest/test_top_level3.py index 47e7a8bce100..f19e1fd4376e 100644 --- a/nnvm/tests/python/unittest/test_top_level3.py +++ b/nnvm/tests/python/unittest/test_top_level3.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import nnvm.symbol as sym def test_reshape(): diff --git a/nnvm/tests/python/unittest/test_top_level4.py b/nnvm/tests/python/unittest/test_top_level4.py index fe90b2b1cc5c..ad0829b59283 100644 --- a/nnvm/tests/python/unittest/test_top_level4.py +++ b/nnvm/tests/python/unittest/test_top_level4.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import nnvm.symbol as sym def test_binary_broadcast(): diff --git a/nnvm/tutorials/deploy_model_on_mali_gpu.py b/nnvm/tutorials/deploy_model_on_mali_gpu.py index 6e3962a6609f..da7a6356432b 100644 --- a/nnvm/tutorials/deploy_model_on_mali_gpu.py +++ b/nnvm/tutorials/deploy_model_on_mali_gpu.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ .. _tutorial-deploy-model-on-mali-gpu: @@ -15,6 +31,7 @@ import nnvm.testing from tvm import rpc from tvm.contrib import util, graph_runtime as runtime +from tvm.contrib.download import download_testdata ###################################################################### # Build TVM Runtime on Device @@ -27,7 +44,7 @@ # All instructions in both this section and next section should be # executed on the target device, e.g. Rk3399. And we assume it # has Linux running. -# +# # Since we do compilation on local machine, the remote device is only used # for running the generated code. We only need to build tvm runtime on # the remote device. Make sure you have opencl driver in your board. @@ -39,12 +56,12 @@ # git clone --recursive https://github.com/dmlc/tvm # cd tvm # cp cmake/config.cmake . -# sed -i "s/USE_OPENCL OFF/USE_OPENCL ON/" config.cmake +# sed -i "s/USE_OPENCL OFF/USE_OPENCL ON/" config.cmake # make runtime -j4 # # After building runtime successfully, we need to set environment varibles # in :code:`~/.bashrc` file. We can edit :code:`~/.bashrc` -# using :code:`vi ~/.bashrc` and add the line below (Assuming your TVM +# using :code:`vi ~/.bashrc` and add the line below (Assuming your TVM # directory is in :code:`~/tvm`): # # .. code-block:: bash @@ -75,13 +92,12 @@ # Prepare the Pre-trained Model # ----------------------------- # Back to the host machine, which should have a full TVM installed (with LLVM). -# +# # We will use pre-trained model from # `MXNet Gluon model zoo `_. # You can found more details about this part at tutorial :ref:`tutorial-from-mxnet`. from mxnet.gluon.model_zoo.vision import get_model -from mxnet.gluon.utils import download from PIL import Image import numpy as np @@ -92,8 +108,9 @@ # In order to test our model, here we download an image of cat and # transform its format. img_name = 'cat.png' -download('https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true', img_name) -image = Image.open(img_name).resize((224, 224)) +img_path = download_testdata('https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true', + img_name, module='data') +image = Image.open(img_path).resize((224, 224)) def transform_image(image): image = np.array(image) - np.array([123., 117., 104.]) @@ -112,9 +129,9 @@ def transform_image(image): '596b27d23537e5a1b5751d2b0481ef172f58b539/', 'imagenet1000_clsid_to_human.txt']) -synset_name = 'synset.txt' -download(synset_url, synset_name) -with open(synset_name) as f: +synset_name = 'imagenet1000_clsid_to_human.txt' +synset_path = download_testdata(synset_url, synset_name, module='data') +with open(synset_path) as f: synset = eval(f.read()) ###################################################################### @@ -156,7 +173,7 @@ def transform_image(image): target = "llvm" else: # Here is the setting for my rk3399 board - # If you don't use rk3399, you can query your target triple by + # If you don't use rk3399, you can query your target triple by # execute `gcc -v` on your board. target_host = "llvm -target=aarch64-linux-gnu" diff --git a/nnvm/tutorials/deploy_model_on_rasp.py b/nnvm/tutorials/deploy_model_on_rasp.py index c110d7ffdc5c..fb9905e16aa3 100644 --- a/nnvm/tutorials/deploy_model_on_rasp.py +++ b/nnvm/tutorials/deploy_model_on_rasp.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ .. _tutorial-deploy-model-on-rasp: @@ -14,6 +30,7 @@ import nnvm.testing from tvm import rpc from tvm.contrib import util, graph_runtime as runtime +from tvm.contrib.download import download_testdata ###################################################################### # .. _build-tvm-runtime-on-device: @@ -28,7 +45,7 @@ # All instructions in both this section and next section should be # executed on the target device, e.g. Raspberry Pi. And we assume it # has Linux running. -# +# # Since we do compilation on local machine, the remote device is only used # for running the generated code. We only need to build tvm runtime on # the remote device. @@ -41,7 +58,7 @@ # # After building runtime successfully, we need to set environment varibles # in :code:`~/.bashrc` file. We can edit :code:`~/.bashrc` -# using :code:`vi ~/.bashrc` and add the line below (Assuming your TVM +# using :code:`vi ~/.bashrc` and add the line below (Assuming your TVM # directory is in :code:`~/tvm`): # # .. code-block:: bash @@ -72,13 +89,12 @@ # Prepare the Pre-trained Model # ----------------------------- # Back to the host machine, which should have a full TVM installed (with LLVM). -# +# # We will use pre-trained model from # `MXNet Gluon model zoo `_. # You can found more details about this part at tutorial :ref:`tutorial-from-mxnet`. from mxnet.gluon.model_zoo.vision import get_model -from mxnet.gluon.utils import download from PIL import Image import numpy as np @@ -89,8 +105,9 @@ # In order to test our model, here we download an image of cat and # transform its format. img_name = 'cat.png' -download('https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true', img_name) -image = Image.open(img_name).resize((224, 224)) +img_path = download_testdata('https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true', + img_name, module='data') +image = Image.open(img_path).resize((224, 224)) def transform_image(image): image = np.array(image) - np.array([123., 117., 104.]) @@ -108,9 +125,9 @@ def transform_image(image): '4d0b62f3d01426887599d4f7ede23ee5/raw/', '596b27d23537e5a1b5751d2b0481ef172f58b539/', 'imagenet1000_clsid_to_human.txt']) -synset_name = 'synset.txt' -download(synset_url, synset_name) -with open(synset_name) as f: +synset_name = 'imagenet1000_clsid_to_human.txt' +synset_path = download_testdata(synset_url, synset_name, module='data') +with open(synset_path) as f: synset = eval(f.read()) ###################################################################### diff --git a/nnvm/tutorials/deploy_ssd_mxnet.py b/nnvm/tutorials/deploy_ssd_mxnet.py index 1a71c96eaa0c..c88c61984293 100644 --- a/nnvm/tutorials/deploy_ssd_mxnet.py +++ b/nnvm/tutorials/deploy_ssd_mxnet.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Deploy Single Shot Multibox Detector(SSD) model =============================================== @@ -18,7 +34,7 @@ from nnvm import compiler from nnvm.frontend import from_mxnet from tvm import relay -from tvm.contrib.download import download +from tvm.contrib.download import download_testdata from tvm.contrib import graph_runtime from mxnet.model import load_checkpoint @@ -65,28 +81,24 @@ inference_symbol_url = "https://gist.github.com/kevinthesun/c1904e900848df4548ce5dfb18c719c7/" \ "archive/a28c4856c827fe766aa3da0e35bad41d44f0fb26.zip" -dir = "ssd_model" -if not os.path.exists(dir): - os.makedirs(dir) -model_file_path = "%s/%s" % (dir, model_file) -test_image_path = "%s/%s" % (dir, test_image) -inference_symbol_path = "%s/inference_model.zip" % dir -download(model_url, model_file_path) -download(image_url, test_image_path) -download(inference_symbol_url, inference_symbol_path) +model_file_path = download_testdata(model_url, model_file, module=["mxnet", "ssd_model"]) +inference_symbol_path = download_testdata(inference_symbol_url, "inference_model.zip", + module=["mxnet", "ssd_model"]) +test_image_path = download_testdata(image_url, test_image, module="data") +model_dir = os.path.dirname(model_file_path) zip_ref = zipfile.ZipFile(model_file_path, 'r') -zip_ref.extractall(dir) +zip_ref.extractall(model_dir) zip_ref.close() zip_ref = zipfile.ZipFile(inference_symbol_path) -zip_ref.extractall(dir) +zip_ref.extractall(model_dir) zip_ref.close() ###################################################################### # Convert and compile model with NNVM or Relay for CPU. -sym = mx.sym.load("%s/%s/ssd_resnet50_inference.json" % (dir, inference_symbol_folder)) -_, arg_params, aux_params = load_checkpoint("%s/%s" % (dir, model_name), 0) +sym = mx.sym.load("%s/%s/ssd_resnet50_inference.json" % (model_dir, inference_symbol_folder)) +_, arg_params, aux_params = load_checkpoint("%s/%s" % (model_dir, model_name), 0) import argparse parser = argparse.ArgumentParser() diff --git a/nnvm/tutorials/from_coreml.py b/nnvm/tutorials/from_coreml.py index 1c958746247b..3eaced18728e 100644 --- a/nnvm/tutorials/from_coreml.py +++ b/nnvm/tutorials/from_coreml.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Compile CoreML Models ===================== @@ -21,19 +37,7 @@ import coremltools as cm import numpy as np from PIL import Image - -def download(url, path, overwrite=False): - import os - if os.path.isfile(path) and not overwrite: - print('File {} existed, skip.'.format(path)) - return - print('Downloading from url {} to {}'.format(url, path)) - try: - import urllib.request - urllib.request.urlretrieve(url, path) - except: - import urllib - urllib.urlretrieve(url, path) +from tvm.contrib.download import download_testdata ###################################################################### # Load pretrained CoreML model @@ -42,9 +46,9 @@ def download(url, path, overwrite=False): # provided by apple in this example model_url = 'https://docs-assets.developer.apple.com/coreml/models/MobileNet.mlmodel' model_file = 'mobilenet.mlmodel' -download(model_url, model_file) +model_path = download_testdata(model_url, model_file, module='coreml') # now you mobilenet.mlmodel on disk -mlmodel = cm.models.MLModel(model_file) +mlmodel = cm.models.MLModel(model_path) # we can load the graph as NNVM compatible model sym, params = nnvm.frontend.from_coreml(mlmodel) @@ -54,8 +58,8 @@ def download(url, path, overwrite=False): # A single cat dominates the examples! from PIL import Image img_url = 'https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true' -download(img_url, 'cat.png') -img = Image.open('cat.png').resize((224, 224)) +img_path = download_testdata(img_url, 'cat.png', module='data') +img = Image.open(img_path).resize((224, 224)) #x = np.transpose(img, (2, 0, 1))[np.newaxis, :] image = np.asarray(img) image = image.transpose((2, 0, 1)) @@ -95,8 +99,8 @@ def download(url, path, overwrite=False): '4d0b62f3d01426887599d4f7ede23ee5/raw/', '596b27d23537e5a1b5751d2b0481ef172f58b539/', 'imagenet1000_clsid_to_human.txt']) -synset_name = 'synset.txt' -download(synset_url, synset_name) -with open(synset_name) as f: +synset_name = 'imagenet1000_clsid_to_human.txt' +synset_path = download_testdata(synset_url, synset_name, module='data') +with open(synset_path) as f: synset = eval(f.read()) print('Top-1 id', top1, 'class name', synset[top1]) diff --git a/nnvm/tutorials/from_darknet.py b/nnvm/tutorials/from_darknet.py index f0eec98c00ea..607af1038628 100644 --- a/nnvm/tutorials/from_darknet.py +++ b/nnvm/tutorials/from_darknet.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Compile YOLO-V2 and YOLO-V3 in DarkNet Models ================================= @@ -25,7 +41,7 @@ import sys from ctypes import * -from tvm.contrib.download import download +from tvm.contrib.download import download_testdata from nnvm.testing.darknet import __darknetffi__ # Model name @@ -41,8 +57,8 @@ CFG_URL = REPO_URL + 'cfg/' + CFG_NAME + '?raw=true' WEIGHTS_URL = 'https://pjreddie.com/media/files/' + WEIGHTS_NAME -download(CFG_URL, CFG_NAME) -download(WEIGHTS_URL, WEIGHTS_NAME) +cfg_path = download_testdata(CFG_URL, CFG_NAME, module="darknet") +weights_path = download_testdata(WEIGHTS_URL, WEIGHTS_NAME, module="darknet") # Download and Load darknet library if sys.platform in ['linux', 'linux2']: @@ -55,12 +71,10 @@ err = "Darknet lib is not supported on {} platform".format(sys.platform) raise NotImplementedError(err) -download(DARKNET_URL, DARKNET_LIB) +lib_path = download_testdata(DARKNET_URL, DARKNET_LIB, module="darknet") -DARKNET_LIB = __darknetffi__.dlopen('./' + DARKNET_LIB) -cfg = "./" + str(CFG_NAME) -weights = "./" + str(WEIGHTS_NAME) -net = DARKNET_LIB.load_network(cfg.encode('utf-8'), weights.encode('utf-8'), 0) +DARKNET_LIB = __darknetffi__.dlopen(lib_path) +net = DARKNET_LIB.load_network(cfg_path.encode('utf-8'), weights_path.encode('utf-8'), 0) dtype = 'float32' batch_size = 1 @@ -88,9 +102,9 @@ print("Loading the test image...") img_url = 'https://github.com/siju-samuel/darknet/blob/master/data/' + \ test_image + '?raw=true' -download(img_url, test_image) +img_path = download_testdata(img_url, test_image, "data") -data = nnvm.testing.darknet.load_image(test_image, netw, neth) +data = nnvm.testing.darknet.load_image(img_path, netw, neth) ###################################################################### # Execute on TVM Runtime # ---------------------- @@ -150,10 +164,10 @@ coco_url = 'https://github.com/siju-samuel/darknet/blob/master/data/' + coco_name + '?raw=true' font_name = 'arial.ttf' font_url = 'https://github.com/siju-samuel/darknet/blob/master/data/' + font_name + '?raw=true' -download(coco_url, coco_name) -download(font_url, font_name) +coco_path = download_testdata(coco_url, coco_name, module='data') +font_path = download_testdata(font_url, font_name, module='data') -with open(coco_name) as f: +with open(coco_path) as f: content = f.readlines() names = [x.strip() for x in content] diff --git a/nnvm/tutorials/from_mxnet.py b/nnvm/tutorials/from_mxnet.py index b4c2c5b7dfbd..e4a30aa2c0e0 100644 --- a/nnvm/tutorials/from_mxnet.py +++ b/nnvm/tutorials/from_mxnet.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ .. _tutorial-from-mxnet: @@ -20,30 +36,31 @@ """ # some standard imports import mxnet as mx +import numpy as np import nnvm import tvm -import numpy as np +from tvm.contrib.download import download_testdata ###################################################################### # Download Resnet18 model from Gluon Model Zoo # --------------------------------------------- # In this section, we download a pretrained imagenet model and classify an image. from mxnet.gluon.model_zoo.vision import get_model -from mxnet.gluon.utils import download from PIL import Image from matplotlib import pyplot as plt block = get_model('resnet18_v1', pretrained=True) +img_url = 'https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true' img_name = 'cat.png' synset_url = ''.join(['https://gist.githubusercontent.com/zhreshold/', '4d0b62f3d01426887599d4f7ede23ee5/raw/', '596b27d23537e5a1b5751d2b0481ef172f58b539/', 'imagenet1000_clsid_to_human.txt']) -synset_name = 'synset.txt' -download('https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true', img_name) -download(synset_url, synset_name) -with open(synset_name) as f: +synset_name = 'imagenet1000_clsid_to_human.txt' +img_path = download_testdata(img_url, img_name, module='data') +synset_path = download_testdata(synset_url, synset_name, module='data') +with open(synset_path) as f: synset = eval(f.read()) -image = Image.open(img_name).resize((224, 224)) +image = Image.open(img_path).resize((224, 224)) plt.imshow(image) plt.show() diff --git a/nnvm/tutorials/from_mxnet_to_webgl.py b/nnvm/tutorials/from_mxnet_to_webgl.py index 4e7b57706de6..a54704cca381 100644 --- a/nnvm/tutorials/from_mxnet_to_webgl.py +++ b/nnvm/tutorials/from_mxnet_to_webgl.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Deploy Deep Learning Models to OpenGL and WebGL =============================================== @@ -33,6 +49,7 @@ import numpy as np import tvm +from tvm.contrib.download import download_testdata import nnvm.compiler import nnvm.testing @@ -106,16 +123,14 @@ def download_synset(): print("Downloading synset...") - from mxnet import gluon - url = "https://gist.githubusercontent.com/zhreshold/" + \ "4d0b62f3d01426887599d4f7ede23ee5/raw/" + \ "596b27d23537e5a1b5751d2b0481ef172f58b539/" + \ "imagenet1000_clsid_to_human.txt" - file_name = "synset.txt" + file_name = "imagenet1000_clsid_to_human.txt" - gluon.utils.download(url, file_name) - with open(file_name) as f: + file_path = download_testdata(url, file_name, module='data') + with open(file_path) as f: synset = eval(f.read()) print("- Synset downloaded!") @@ -144,14 +159,13 @@ def download_image(): print("Downloading cat image...") from matplotlib import pyplot as plt - from mxnet import gluon from PIL import Image url = "https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true" img_name = "cat.png" - gluon.utils.download(url, img_name) - image = Image.open(img_name).resize((224, 224)) + img_path = download_testdata(url, img_name, module='data') + image = Image.open(img_path).resize((224, 224)) print("- Cat image downloaded!") diff --git a/nnvm/tutorials/from_onnx.py b/nnvm/tutorials/from_onnx.py index 0fdef8afa98c..97d154615e67 100644 --- a/nnvm/tutorials/from_onnx.py +++ b/nnvm/tutorials/from_onnx.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Compile ONNX Models =================== @@ -18,22 +34,10 @@ """ import nnvm import tvm +from tvm.contrib.download import download_testdata import onnx import numpy as np -def download(url, path, overwrite=False): - import os - if os.path.isfile(path) and not overwrite: - print('File {} existed, skip.'.format(path)) - return - print('Downloading from url {} to {}'.format(url, path)) - try: - import urllib.request - urllib.request.urlretrieve(url, path) - except: - import urllib - urllib.urlretrieve(url, path) - ###################################################################### # Load pretrained ONNX model # --------------------------------------------- @@ -44,9 +48,9 @@ def download(url, path, overwrite=False): 'bcda4716699ac97ea44f791c24310193/raw/', '93672b029103648953c4e5ad3ac3aadf346a4cdc/', 'super_resolution_0.2.onnx']) -download(model_url, 'super_resolution.onnx', True) +model_path = download_testdata(model_url, 'super_resolution.onnx', module='onnx') # now you have super_resolution.onnx on disk -onnx_model = onnx.load_model('super_resolution.onnx') +onnx_model = onnx.load_model(model_path) # we can load the graph as NNVM compatible model sym, params = nnvm.frontend.from_onnx(onnx_model) @@ -56,8 +60,8 @@ def download(url, path, overwrite=False): # A single cat dominates the examples! from PIL import Image img_url = 'https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true' -download(img_url, 'cat.png') -img = Image.open('cat.png').resize((224, 224)) +img_path = download_testdata(img_url, 'cat.png', module='data') +img = Image.open(img_path).resize((224, 224)) img_ycbcr = img.convert("YCbCr") # convert to YCbCr img_y, img_cb, img_cr = img_ycbcr.split() x = np.array(img_y)[np.newaxis, np.newaxis, :, :] diff --git a/nnvm/tutorials/from_tensorflow.py b/nnvm/tutorials/from_tensorflow.py index ac632b122e76..6a30443dba60 100644 --- a/nnvm/tutorials/from_tensorflow.py +++ b/nnvm/tutorials/from_tensorflow.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Compile Tensorflow Models ========================= @@ -52,8 +68,8 @@ map_proto_url = os.path.join(repo_base, map_proto) # Human readable text for labels -lable_map = 'imagenet_synset_to_human_label_map.txt' -lable_map_url = os.path.join(repo_base, lable_map) +label_map = 'imagenet_synset_to_human_label_map.txt' +label_map_url = os.path.join(repo_base, label_map) # Target settings # Use these commented settings to build for cuda. @@ -70,19 +86,19 @@ # Download required files # ----------------------- # Download files listed above. -from mxnet.gluon.utils import download +from tvm.contrib.download import download_testdata -download(image_url, img_name) -download(model_url, model_name) -download(map_proto_url, map_proto) -download(lable_map_url, lable_map) +img_path = download_testdata(image_url, img_name, module='data') +model_path = download_testdata(model_url, model_name, module=['tf', 'InceptionV1']) +map_proto_path = download_testdata(map_proto_url, map_proto, module='data') +label_path = download_testdata(label_map_url, label_map, module='data') ###################################################################### # Import model # ------------ # Creates tensorflow graph definition from protobuf file. -with tf.gfile.FastGFile(os.path.join("./", model_name), 'rb') as f: +with tf.gfile.FastGFile(model_path, 'rb') as f: graph_def = tf.GraphDef() graph_def.ParseFromString(f.read()) graph = tf.import_graph_def(graph_def, name='') @@ -103,7 +119,7 @@ # from PIL import Image -image = Image.open(img_name).resize((299, 299)) +image = Image.open(img_path).resize((299, 299)) x = np.array(image) @@ -117,7 +133,7 @@ # params: params converted from tensorflow params (tensor protobuf). sym, params = nnvm.frontend.from_tensorflow(graph_def, layout=layout) -print ("Tensorflow protobuf imported as nnvm graph") +print("Tensorflow protobuf imported as nnvm graph") ###################################################################### # NNVM Compilation # ---------------- @@ -157,8 +173,8 @@ predictions = np.squeeze(predictions) # Creates node ID --> English string lookup. -node_lookup = tf_testing.NodeLookup(label_lookup_path=os.path.join("./", map_proto), - uid_lookup_path=os.path.join("./", lable_map)) +node_lookup = tf_testing.NodeLookup(label_lookup_path=map_proto_path, + uid_lookup_path=label_path) # Print top 5 predictions from TVM output. top_k = predictions.argsort()[-5:][::-1] @@ -175,7 +191,7 @@ def create_graph(): """Creates a graph from saved GraphDef file and returns a saver.""" # Creates graph from saved graph_def.pb. - with tf.gfile.FastGFile(model_name, 'rb') as f: + with tf.gfile.FastGFile(model_path, 'rb') as f: graph_def = tf.GraphDef() graph_def.ParseFromString(f.read()) graph = tf.import_graph_def(graph_def, name='') @@ -209,8 +225,8 @@ def run_inference_on_image(image): predictions = np.squeeze(predictions) # Creates node ID --> English string lookup. - node_lookup = tf_testing.NodeLookup(label_lookup_path=os.path.join("./", map_proto), - uid_lookup_path=os.path.join("./", lable_map)) + node_lookup = tf_testing.NodeLookup(label_lookup_path=map_proto_path, + uid_lookup_path=label_path) # Print top 5 predictions from tensorflow. top_k = predictions.argsort()[-5:][::-1] @@ -220,4 +236,4 @@ def run_inference_on_image(image): score = predictions[node_id] print('%s (score = %.5f)' % (human_string, score)) -run_inference_on_image (img_name) +run_inference_on_image(img_path) diff --git a/nnvm/tutorials/get_started.py b/nnvm/tutorials/get_started.py index f505853375df..46f711e7d347 100644 --- a/nnvm/tutorials/get_started.py +++ b/nnvm/tutorials/get_started.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Get Started with NNVM ===================== diff --git a/nnvm/tutorials/nlp/from_darknet_rnn.py b/nnvm/tutorials/nlp/from_darknet_rnn.py index 54013f04fca6..1bc9627dd62f 100644 --- a/nnvm/tutorials/nlp/from_darknet_rnn.py +++ b/nnvm/tutorials/nlp/from_darknet_rnn.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Compile Darknet Models for RNN ============================== @@ -22,9 +38,9 @@ """ import random import numpy as np -from mxnet.gluon.utils import download import tvm from tvm.contrib import graph_runtime +from tvm.contrib.download import download_testdata from nnvm.testing.darknet import __darknetffi__ import nnvm import nnvm.frontend.darknet @@ -49,17 +65,15 @@ CFG_URL = REPO_URL + 'cfg/' + CFG_NAME + '?raw=true' WEIGHTS_URL = REPO_URL + 'weights/' + WEIGHTS_NAME + '?raw=true' -download(CFG_URL, CFG_NAME) -download(WEIGHTS_URL, WEIGHTS_NAME) +cfg_path = download_testdata(CFG_URL, CFG_NAME, module='darknet') +weights_path = download_testdata(WEIGHTS_URL, WEIGHTS_NAME, module='darknet') # Download and Load darknet library DARKNET_LIB = 'libdarknet.so' DARKNET_URL = REPO_URL + 'lib/' + DARKNET_LIB + '?raw=true' -download(DARKNET_URL, DARKNET_LIB) -DARKNET_LIB = __darknetffi__.dlopen('./' + DARKNET_LIB) -cfg = "./" + str(CFG_NAME) -weights = "./" + str(WEIGHTS_NAME) -net = DARKNET_LIB.load_network(cfg.encode('utf-8'), weights.encode('utf-8'), 0) +lib_path = download_testdata(DARKNET_URL, DARKNET_LIB, module='darknet') +DARKNET_LIB = __darknetffi__.dlopen(lib_path) +net = DARKNET_LIB.load_network(cfg_path.encode('utf-8'), weights_path.encode('utf-8'), 0) dtype = 'float32' batch_size = 1 diff --git a/nnvm/tutorials/nlp/keras_s2s_translate.py b/nnvm/tutorials/nlp/keras_s2s_translate.py index 77c7f23902f4..16c737418c6f 100644 --- a/nnvm/tutorials/nlp/keras_s2s_translate.py +++ b/nnvm/tutorials/nlp/keras_s2s_translate.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Keras LSTM Sequence to Sequence Model for Translation ================================= @@ -59,9 +75,9 @@ data_url = os.path.join(repo_base, data_file) # Download files listed below. -from mxnet.gluon.utils import download -download(model_url, model_file) -download(data_url, model_file) +from tvm.contrib.download import download_testdata +model_path = download_testdata(model_url, model_file, module='keras') +data_path = download_testdata(data_url, data_file, module='data') latent_dim = 256 # Latent dimensionality of the encoding space. test_samples = 10000 # Number of samples used for testing. @@ -76,7 +92,7 @@ target_texts = [] input_characters = set() target_characters = set() -with open(data_file, 'r', encoding='utf-8') as f: +with open(data_path, 'r', encoding='utf-8') as f: lines = f.read().split('\n') test_samples = min(test_samples, len(lines)) max_encoder_seq_length = 0 @@ -112,7 +128,7 @@ # Load Keras Model # ---------------- # Restore the model and construct the encoder and decoder. -model = load_model(model_file) +model = load_model(model_path) encoder_inputs = model.input[0] # input_1 encoder_outputs, state_h_enc, state_c_enc = model.layers[2].output # lstm_1 diff --git a/nnvm/tutorials/tune_nnvm_arm.py b/nnvm/tutorials/tune_nnvm_arm.py index c89c6625b875..14e55ffb31d5 100644 --- a/nnvm/tutorials/tune_nnvm_arm.py +++ b/nnvm/tutorials/tune_nnvm_arm.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Auto-tuning a convolutional network for ARM CPU (NNVM) ====================================================== diff --git a/nnvm/tutorials/tune_nnvm_cuda.py b/nnvm/tutorials/tune_nnvm_cuda.py index 0dd8d24ae89f..c6dec422c2aa 100644 --- a/nnvm/tutorials/tune_nnvm_cuda.py +++ b/nnvm/tutorials/tune_nnvm_cuda.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Auto-tuning a convolutional network for NVIDIA GPU (NNVM) ========================================================= diff --git a/nnvm/tutorials/tune_nnvm_mobile_gpu.py b/nnvm/tutorials/tune_nnvm_mobile_gpu.py index 3850f093c722..293339c224e7 100644 --- a/nnvm/tutorials/tune_nnvm_mobile_gpu.py +++ b/nnvm/tutorials/tune_nnvm_mobile_gpu.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Auto-tuning a convolutional network for Mobile GPU (NNVM) ========================================================= diff --git a/nnvm/tutorials/tune_nnvm_x86.py b/nnvm/tutorials/tune_nnvm_x86.py index 875fa8878cd5..b7426271f06b 100644 --- a/nnvm/tutorials/tune_nnvm_x86.py +++ b/nnvm/tutorials/tune_nnvm_x86.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Auto-tuning a convolutional network for x86 CPU (NNVM) ====================================================== diff --git a/nnvm/tutorials/using_external_lib.py b/nnvm/tutorials/using_external_lib.py index 272dcbb2b808..cc52652ffa37 100644 --- a/nnvm/tutorials/using_external_lib.py +++ b/nnvm/tutorials/using_external_lib.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Using External Libraries in NNVM ================================ diff --git a/python/setup.py b/python/setup.py index 4127892925ef..11cd6642459d 100644 --- a/python/setup.py +++ b/python/setup.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, exec-used """Setup TVM package.""" from __future__ import absolute_import diff --git a/python/tvm/__init__.py b/python/tvm/__init__.py index e17e6203ed49..c0470ade60f9 100644 --- a/python/tvm/__init__.py +++ b/python/tvm/__init__.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=redefined-builtin, wildcard-import """TVM: Low level DSL/IR stack for tensor computation.""" from __future__ import absolute_import as _abs diff --git a/python/tvm/_api_internal.py b/python/tvm/_api_internal.py index 2435c6d54db2..571523757cac 100644 --- a/python/tvm/_api_internal.py +++ b/python/tvm/_api_internal.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Namespace of internal API The functions in this namespace are automatically exported from C++ side via PackedFunc diff --git a/python/tvm/_ffi/__init__.py b/python/tvm/_ffi/__init__.py index bb14c9203644..f19851c2407a 100644 --- a/python/tvm/_ffi/__init__.py +++ b/python/tvm/_ffi/__init__.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """C interfacing code. This namespace contains everything that interacts with C code. diff --git a/python/tvm/_ffi/_ctypes/__init__.py b/python/tvm/_ffi/_ctypes/__init__.py index a9f3be09cba4..b2851f4b27f3 100644 --- a/python/tvm/_ffi/_ctypes/__init__.py +++ b/python/tvm/_ffi/_ctypes/__init__.py @@ -1 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ctypes specific implementation of FFI""" diff --git a/python/tvm/_ffi/_ctypes/function.py b/python/tvm/_ffi/_ctypes/function.py index 2ead24af3b25..a000c27a5f60 100644 --- a/python/tvm/_ffi/_ctypes/function.py +++ b/python/tvm/_ffi/_ctypes/function.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # coding: utf-8 # pylint: disable=invalid-name, protected-access, too-many-branches, global-statement """Function configuration API.""" diff --git a/python/tvm/_ffi/_ctypes/ndarray.py b/python/tvm/_ffi/_ctypes/ndarray.py index da24b9cd41eb..9367160b811b 100644 --- a/python/tvm/_ffi/_ctypes/ndarray.py +++ b/python/tvm/_ffi/_ctypes/ndarray.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Runtime NDArray api""" from __future__ import absolute_import diff --git a/python/tvm/_ffi/_ctypes/node.py b/python/tvm/_ffi/_ctypes/node.py index ccfaa6dd77a2..39fe0ef35525 100644 --- a/python/tvm/_ffi/_ctypes/node.py +++ b/python/tvm/_ffi/_ctypes/node.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, protected-access # pylint: disable=no-member, missing-docstring, not-callable from __future__ import absolute_import diff --git a/python/tvm/_ffi/_ctypes/types.py b/python/tvm/_ffi/_ctypes/types.py index b3fcad9cfefb..31c4786b858f 100644 --- a/python/tvm/_ffi/_ctypes/types.py +++ b/python/tvm/_ffi/_ctypes/types.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """The C Types used in API.""" # pylint: disable=invalid-name from __future__ import absolute_import as _abs diff --git a/python/tvm/_ffi/_cy2/__init__.py b/python/tvm/_ffi/_cy2/__init__.py index d635c4820ec0..4d0a864416b3 100644 --- a/python/tvm/_ffi/_cy2/__init__.py +++ b/python/tvm/_ffi/_cy2/__init__.py @@ -1 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """cython2 namespace""" diff --git a/python/tvm/_ffi/_cy3/__init__.py b/python/tvm/_ffi/_cy3/__init__.py index ac02ea7d1c18..159f3254db1d 100644 --- a/python/tvm/_ffi/_cy3/__init__.py +++ b/python/tvm/_ffi/_cy3/__init__.py @@ -1 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """cython3 namespace""" diff --git a/python/tvm/_ffi/_cython/base.pxi b/python/tvm/_ffi/_cython/base.pxi index 22234953ae97..44e379de69bb 100644 --- a/python/tvm/_ffi/_cython/base.pxi +++ b/python/tvm/_ffi/_cython/base.pxi @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + from ..base import get_last_ffi_error from libcpp.vector cimport vector from cpython.version cimport PY_MAJOR_VERSION diff --git a/python/tvm/_ffi/_cython/core.pyx b/python/tvm/_ffi/_cython/core.pyx index e392b709c15c..3b07d7874884 100644 --- a/python/tvm/_ffi/_cython/core.pyx +++ b/python/tvm/_ffi/_cython/core.pyx @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + include "./base.pxi" include "./node.pxi" include "./function.pxi" diff --git a/python/tvm/_ffi/_cython/function.pxi b/python/tvm/_ffi/_cython/function.pxi index b72d0b694752..514d1b7b3dd4 100644 --- a/python/tvm/_ffi/_cython/function.pxi +++ b/python/tvm/_ffi/_cython/function.pxi @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + import ctypes import traceback from cpython cimport Py_INCREF, Py_DECREF diff --git a/python/tvm/_ffi/_cython/ndarray.pxi b/python/tvm/_ffi/_cython/ndarray.pxi index 4cd6709a0118..402c9de24ebc 100644 --- a/python/tvm/_ffi/_cython/ndarray.pxi +++ b/python/tvm/_ffi/_cython/ndarray.pxi @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + from ..runtime_ctypes import TVMArrayHandle cdef const char* _c_str_dltensor = "dltensor" diff --git a/python/tvm/_ffi/_cython/node.pxi b/python/tvm/_ffi/_cython/node.pxi index 73ead2b4b447..5e0c366e5600 100644 --- a/python/tvm/_ffi/_cython/node.pxi +++ b/python/tvm/_ffi/_cython/node.pxi @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + from ... import _api_internal from ..base import string_types from ..node_generic import _set_class_node_base diff --git a/python/tvm/_ffi/base.py b/python/tvm/_ffi/base.py index ea4e8436b5e1..e8435081c9ed 100644 --- a/python/tvm/_ffi/base.py +++ b/python/tvm/_ffi/base.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # coding: utf-8 # pylint: disable=invalid-name """Base library for TVM FFI.""" diff --git a/python/tvm/_ffi/function.py b/python/tvm/_ffi/function.py index 33013a4df5ef..60e7aeb9aec5 100644 --- a/python/tvm/_ffi/function.py +++ b/python/tvm/_ffi/function.py @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # pylint: disable=invalid-name, unused-import """Function namespace.""" from __future__ import absolute_import diff --git a/python/tvm/_ffi/libinfo.py b/python/tvm/_ffi/libinfo.py index 9ef0f498a7a4..68c372b6b589 100644 --- a/python/tvm/_ffi/libinfo.py +++ b/python/tvm/_ffi/libinfo.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Library information.""" from __future__ import absolute_import import sys diff --git a/python/tvm/_ffi/ndarray.py b/python/tvm/_ffi/ndarray.py index 3c5b170bdca7..3b6181a85c58 100644 --- a/python/tvm/_ffi/ndarray.py +++ b/python/tvm/_ffi/ndarray.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-import """Runtime NDArray api""" from __future__ import absolute_import diff --git a/python/tvm/_ffi/node.py b/python/tvm/_ffi/node.py index 98ece19f77f2..baca89d628b8 100644 --- a/python/tvm/_ffi/node.py +++ b/python/tvm/_ffi/node.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Node namespace""" # pylint: disable=unused-import from __future__ import absolute_import diff --git a/python/tvm/_ffi/node_generic.py b/python/tvm/_ffi/node_generic.py index 9f9c5383e3ba..ba5ccd0fcd11 100644 --- a/python/tvm/_ffi/node_generic.py +++ b/python/tvm/_ffi/node_generic.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Common implementation of Node generic related logic""" # pylint: disable=unused-import from __future__ import absolute_import diff --git a/python/tvm/_ffi/runtime_ctypes.py b/python/tvm/_ffi/runtime_ctypes.py index e1b78735a97d..cb30457b64c7 100644 --- a/python/tvm/_ffi/runtime_ctypes.py +++ b/python/tvm/_ffi/runtime_ctypes.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Common runtime ctypes.""" # pylint: disable=invalid-name from __future__ import absolute_import diff --git a/python/tvm/api.py b/python/tvm/api.py index 7b81f863f6b0..66fa4fa30e90 100644 --- a/python/tvm/api.py +++ b/python/tvm/api.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Functions defined in TVM.""" # pylint: disable=invalid-name,unused-import,redefined-builtin from __future__ import absolute_import as _abs diff --git a/python/tvm/arith.py b/python/tvm/arith.py index 3981a4815aeb..eda5cb825326 100644 --- a/python/tvm/arith.py +++ b/python/tvm/arith.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Arithmetic data structure and utility""" from __future__ import absolute_import as _abs @@ -97,6 +113,7 @@ def __init__(self): self._bind = _mod("bind") self._modular_set = _mod("modular_set") self._rewrite_simplify = _mod("rewrite_simplify") + self._canonical_simplify = _mod("canonical_simplify") self._enter_constraint_context = _mod("enter_constraint_context") def const_int_bound(self, expr): @@ -144,6 +161,21 @@ def rewrite_simplify(self, expr): """ return self._rewrite_simplify(expr) + def canonical_simplify(self, expr): + """Simplify expression via canonicalization. + + Parameters + ---------- + expr : tvm.Expr + The expression. + + Returns + ------- + result : Expr + The result. + """ + return self._canonical_simplify(expr) + def bind(self, var, expr): """Bind a variable to the expression. diff --git a/python/tvm/attrs.py b/python/tvm/attrs.py index 08548d181883..e2a27328fdcc 100644 --- a/python/tvm/attrs.py +++ b/python/tvm/attrs.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ TVM Attribute module, which is mainly used for defining attributes of operators""" from ._ffi.node import NodeBase, register_node as _register_tvm_node from ._ffi.function import _init_api diff --git a/python/tvm/autotvm/__init__.py b/python/tvm/autotvm/__init__.py index 08cfbb2a95da..cf8362ad8368 100644 --- a/python/tvm/autotvm/__init__.py +++ b/python/tvm/autotvm/__init__.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """The auto-tuning module of tvm This module includes: diff --git a/python/tvm/autotvm/database.py b/python/tvm/autotvm/database.py index c0c041cb18c9..9490cfe9cbc2 100644 --- a/python/tvm/autotvm/database.py +++ b/python/tvm/autotvm/database.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=consider-using-enumerate,invalid-name """ Database of MeasureInput/MeasureResult pair. diff --git a/python/tvm/autotvm/env.py b/python/tvm/autotvm/env.py index dc559a7bce1d..b1a5e3195974 100644 --- a/python/tvm/autotvm/env.py +++ b/python/tvm/autotvm/env.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Global configuration/variable scope for autotvm""" class AutotvmGlobalScope(object): diff --git a/python/tvm/autotvm/feature.py b/python/tvm/autotvm/feature.py index e0054628e686..3976ced54888 100644 --- a/python/tvm/autotvm/feature.py +++ b/python/tvm/autotvm/feature.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Extract feature of iter vars diff --git a/python/tvm/autotvm/measure/__init__.py b/python/tvm/autotvm/measure/__init__.py index 8a6126641a99..2c7cca0c89ce 100644 --- a/python/tvm/autotvm/measure/__init__.py +++ b/python/tvm/autotvm/measure/__init__.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Distributed executor infrastructure to scale up the tuning""" from .measure import MeasureInput, MeasureResult, MeasureErrorNo, measure_option, \ diff --git a/python/tvm/autotvm/measure/executor.py b/python/tvm/autotvm/measure/executor.py index ae48b9ba4c37..bcfdf39ede5f 100644 --- a/python/tvm/autotvm/measure/executor.py +++ b/python/tvm/autotvm/measure/executor.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Abstraction for asynchronous job execution """ class Executor(object): diff --git a/python/tvm/autotvm/measure/local_executor.py b/python/tvm/autotvm/measure/local_executor.py index 63d995c3580c..cf81e2b50e50 100644 --- a/python/tvm/autotvm/measure/local_executor.py +++ b/python/tvm/autotvm/measure/local_executor.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Local based implementation of the executor using multiprocessing""" import signal diff --git a/python/tvm/autotvm/measure/measure.py b/python/tvm/autotvm/measure/measure.py index 3afebfa5c9e3..0836fb741bd2 100644 --- a/python/tvm/autotvm/measure/measure.py +++ b/python/tvm/autotvm/measure/measure.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=pointless-string-statement,consider-using-enumerate,invalid-name """User facing API for specifying how to measure the generated code""" import multiprocessing diff --git a/python/tvm/autotvm/measure/measure_methods.py b/python/tvm/autotvm/measure/measure_methods.py index f77a13bcd2ed..31d688483294 100644 --- a/python/tvm/autotvm/measure/measure_methods.py +++ b/python/tvm/autotvm/measure/measure_methods.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name,too-many-function-args,too-many-nested-blocks """ Functions that run on executor for measurement. @@ -19,7 +35,7 @@ from ... import ir_pass, build, build_config, nd, TVMError, register_func, \ rpc as _rpc, target as _target -from ...contrib import nvcc, ndk +from ...contrib import nvcc, ndk, tar from ..util import get_const_tuple from ..env import AutotvmGlobalScope @@ -58,20 +74,20 @@ class LocalBuilder(Builder): build_func: callable or str If is 'default', use default build function If is 'ndk', use function for android ndk - If is callable, use it as custom build function + If is callable, use it as custom build function, expect lib_format field. """ def __init__(self, timeout=10, n_parallel=None, build_func='default'): super(LocalBuilder, self).__init__(timeout, n_parallel) if isinstance(build_func, str): if build_func == 'default': - build_func = default_build_func + build_func = tar.tar elif build_func == 'ndk': - build_func = android_ndk_build_func + build_func = ndk.create_shared else: raise ValueError("Invalid build_func" + build_func) - self.build_func = build_func + self.build_func = _wrap_build_func(build_func) self.executor = LocalExecutor(timeout=timeout) self.tmp_dir = tempfile.mkdtemp() @@ -349,46 +365,47 @@ def _build_func_common(measure_input, check_gpu=None, cuda_arch=None, build_opti return func, tuple((get_const_tuple(x.shape), x.dtype) for x in args) -def default_build_func(measure_input, tmp_dir, **kwargs): +def _wrap_build_func(build_func): """ - Default build func. This can work for cuda, opencl, llvm backend + Wrap build_func to a function that can be used in measure. Parameters ---------- - measure_input: MeasureInput - The input of measurement - tmp_dir: str - The path of temporary directory to export generated library - """ - tic = time.time() - try: - filename = os.path.join(tmp_dir, "tmp_func_%0x.tar" % getrandbits(64)) - func, arg_info = _build_func_common(measure_input, **kwargs) - func.export_library(filename) - except Exception as e: # pylint: disable=broad-except - return BuildResult(None, None, e, time.time() - tic) - return BuildResult(filename, arg_info, None, time.time() - tic) - - -def android_ndk_build_func(measure_input, tmp_dir, **kwargs): - """ - Build function for android device using ndk. + build_func : The compilation function + We expect fcompile to contain an attr "output_format" - Parameters - ---------- - measure_input: MeasureInput - The input of measurement - tmp_dir: str - The path of temporary directory to export generated library + Returns + ------- + wrapped_build_func : function + The wrapped build function """ - tic = time.time() - try: - filename = os.path.join(tmp_dir, "tmp_func_%0x.so" % getrandbits(64)) - func, arg_info = _build_func_common(measure_input, **kwargs) - func.export_library(filename, ndk.create_shared) - except Exception as e: # pylint: disable=broad-except - return BuildResult(None, None, e, time.time() - tic) - return BuildResult(filename, arg_info, None, time.time() - tic) + if not hasattr(build_func, "output_format"): + raise AttributeError("Expect build_func to have the attribute output_format.") + output_format = build_func.output_format + + def _wrapped(measure_input, tmp_dir, **kwargs): + """ + Wrapped build func. + + Parameters + ---------- + measure_input: MeasureInput + The input of measurement + + tmp_dir: str + The path of temporary directory to export generated library + """ + tic = time.time() + try: + filename = os.path.join(tmp_dir, "tmp_func_%0x.%s" % ( + getrandbits(64), output_format)) + # TODO(tvm-team) consider linline _build_func_common + func, arg_info = _build_func_common(measure_input, **kwargs) + func.export_library(filename, build_func) + except Exception as e: # pylint: disable=broad-except + return BuildResult(None, None, e, time.time() - tic) + return BuildResult(filename, arg_info, None, time.time() - tic) + return _wrapped def run_through_rpc(measure_input, build_result, diff --git a/python/tvm/autotvm/record.py b/python/tvm/autotvm/record.py index c09fc82fb72c..4c0f98347d4b 100644 --- a/python/tvm/autotvm/record.py +++ b/python/tvm/autotvm/record.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=superfluous-parens, redefined-outer-name, redefined-outer-name,pointless-string-statement # pylint: disable=consider-using-enumerate,invalid-name """Tuning record and serialization format""" diff --git a/python/tvm/autotvm/task/__init__.py b/python/tvm/autotvm/task/__init__.py index f6ea07c272d0..ff50a4ebc81d 100644 --- a/python/tvm/autotvm/task/__init__.py +++ b/python/tvm/autotvm/task/__init__.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Task is a tunable composition of template functions. Tuner takes a tunable task and optimizes the joint configuration diff --git a/python/tvm/autotvm/task/code_hash.py b/python/tvm/autotvm/task/code_hash.py index 48343272bbdc..9410f526c45f 100644 --- a/python/tvm/autotvm/task/code_hash.py +++ b/python/tvm/autotvm/task/code_hash.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Decorator functions for hashing schedule code diff --git a/python/tvm/autotvm/task/dispatcher.py b/python/tvm/autotvm/task/dispatcher.py index d2ef480b44ee..8cd87b058801 100644 --- a/python/tvm/autotvm/task/dispatcher.py +++ b/python/tvm/autotvm/task/dispatcher.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Template dispatcher module. diff --git a/python/tvm/autotvm/task/nnvm_integration.py b/python/tvm/autotvm/task/nnvm_integration.py index cd7337586519..dbcee0e516e1 100644 --- a/python/tvm/autotvm/task/nnvm_integration.py +++ b/python/tvm/autotvm/task/nnvm_integration.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=unused-variable,invalid-name """ Decorator and utilities for the integration with TOPI and NNVM diff --git a/python/tvm/autotvm/task/relay_integration.py b/python/tvm/autotvm/task/relay_integration.py index 82350dcebea8..14caa70c0b84 100644 --- a/python/tvm/autotvm/task/relay_integration.py +++ b/python/tvm/autotvm/task/relay_integration.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=unused-variable,invalid-name """ Decorator and utilities for the integration with TOPI and Relay @@ -50,9 +66,10 @@ def extract_from_program(func, params, ops, target, target_host=None): # relay op -> topi compute OP2TOPI = { tvm.relay.op.nn.conv2d: [topi.nn.conv2d, topi.nn.depthwise_conv2d_nchw, - topi.nn.group_conv2d_nchw], + topi.nn.group_conv2d_nchw, topi.nn.conv2d_NCHWc], tvm.relay.op.nn.conv2d_transpose: [topi.nn.conv2d_transpose_nchw], tvm.relay.op.nn.dense: [topi.nn.dense], + tvm.relay.op.nn.deformable_conv2d: [topi.nn.deformable_conv2d_nchw], } topi_funcs = [] @@ -126,6 +143,7 @@ def extract_from_multiple_program(funcs, params, ops, target, target_host=None): topi.nn.group_conv2d_nchw], tvm.relay.op.nn.conv2d_transpose: [topi.nn.conv2d_transpose_nchw], tvm.relay.op.nn.dense: [topi.nn.dense], + tvm.relay.op.nn.contrib_deformable_conv2d: [topi.nn.deformable_conv2d_nchw], } topi_funcs = [] diff --git a/python/tvm/autotvm/task/space.py b/python/tvm/autotvm/task/space.py index 09f2dd0576a5..e57f993f4807 100644 --- a/python/tvm/autotvm/task/space.py +++ b/python/tvm/autotvm/task/space.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=too-few-public-methods,invalid-name,unused-argument,arguments-differ # pylint: disable=consider-using-enumerate,too-many-lines """ diff --git a/python/tvm/autotvm/task/task.py b/python/tvm/autotvm/task/task.py index a0c992b07347..901183f46948 100644 --- a/python/tvm/autotvm/task/task.py +++ b/python/tvm/autotvm/task/task.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=unused-variable """Definition of task function. @@ -205,7 +221,7 @@ def args_to_workload(x, topi_compute_func=None): workload = tuple([args_to_workload(a) for a in x]) elif isinstance(x, (str, int, float, np.int, np.float)): workload = x - elif isinstance(x, (expr.StringImm, expr.IntImm, expr.FloatImm)): + elif isinstance(x, (expr.StringImm, expr.UIntImm, expr.IntImm, expr.FloatImm)): workload = x.value elif x is None: workload = 0 diff --git a/python/tvm/autotvm/task/topi_integration.py b/python/tvm/autotvm/task/topi_integration.py index 882f2df43a50..ee34c6da8607 100644 --- a/python/tvm/autotvm/task/topi_integration.py +++ b/python/tvm/autotvm/task/topi_integration.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=unused-variable,invalid-name,unused-argument """ Decorators for registering tunable templates to TOPI. @@ -67,7 +83,11 @@ def __init__(self): topi.nn.depthwise_conv2d_nchw: "topi_nn_depthwise_conv2d_nchw", topi.nn.group_conv2d_nchw: "topi_nn_group_conv2d_nchw", topi.nn.conv2d_transpose_nchw: "topi_nn_conv2d_transpose_nchw", + topi.nn.conv2d_NCHWc: "topi_x86_conv2d_NCHWc", topi.nn.dense: "topi_nn_dense", + topi.nn.bitserial_conv2d_nchw: "topi_nn_bitserial_conv2d_nchw", + topi.nn.bitserial_conv2d_nhwc: "topi_nn_bitserial_conv2d_nhwc", + topi.nn.deformable_conv2d_nchw: "topi_nn_deformable_conv2d_nchw", } self.topi_to_schedule = { @@ -77,7 +97,11 @@ def __init__(self): topi.generic.schedule_depthwise_conv2d_nhwc], topi.nn.group_conv2d_nchw: [topi.generic.schedule_group_conv2d_nchw], topi.nn.conv2d_transpose_nchw: [topi.generic.schedule_conv2d_transpose_nchw], + topi.nn.conv2d_NCHWc: [topi.generic.schedule_conv2d_NCHWc], topi.nn.dense: [topi.generic.schedule_dense], + topi.nn.bitserial_conv2d_nchw: [topi.generic.schedule_bitserial_conv2d_nchw], + topi.nn.bitserial_conv2d_nhwc: [topi.generic.schedule_bitserial_conv2d_nhwc], + topi.nn.deformable_conv2d_nchw: [topi.generic.schedule_deformable_conv2d_nchw], } self._register_tracing() @@ -102,7 +126,6 @@ def _tracing_topi_compute(*args, **kwargs): key = (self.topi_to_task[compute_func], serialize_args(args)) if key not in self.task_collection: self.task_collection.append(key) - return compute_func.fdefault(*args) _local_scope(topi_compute) @@ -172,6 +195,42 @@ def _topi_nn_dense(*args, **kwargs): return s, [data, weight, bias, C] return s, [data, weight, C] + @register("topi_nn_bitserial_conv2d_nhwc") + def _topi_bitserial_conv2d_nhwc(*args, **kwargs): + args = deserialize_args(args) + C = topi.nn.bitserial_conv2d_nhwc(*args, **kwargs) + s = topi.generic.nn.schedule_bitserial_conv2d_nhwc([C]) + data = args[0] + kernel = args[1] + return s, [data, kernel, C] + + @register("topi_nn_bitserial_conv2d_nchw") + def _topi_bitserial_conv2d_nchw(*args, **kwargs): + args = deserialize_args(args) + C = topi.nn.bitserial_conv2d_nchw(*args, **kwargs) + s = topi.generic.nn.schedule_bitserial_conv2d_nchw([C]) + data = args[0] + kernel = args[1] + return s, [data, kernel, C] + + @register("topi_nn_deformable_conv2d_nchw") + def _topi_nn_deformable_conv2d_nchw(*args, **kwargs): + assert not kwargs, "Do not support kwargs in template function call" + args = deserialize_args(args) + A, Offset, W = args[:3] + C = topi.nn.deformable_conv2d_nchw(*args, **kwargs) + s = topi.generic.schedule_deformable_conv2d_nchw([C]) + return s, [A, Offset, W, C] + + @register("topi_nn_conv2d_NCHWc") + def _topi_nn_conv2d_NCHWc(*args, **kwargs): + assert not kwargs, "Do not support kwargs in template function call" + args = deserialize_args(args) + A, W = args[:2] + C = topi.nn.conv2d_NCHWc(*args, **kwargs) + s = topi.generic.schedule_conv2d_NCHWc([C]) + return s, [A, W, C] + def reset(self, wanted_topi_funcs): """Reset task collections diff --git a/python/tvm/autotvm/tophub.py b/python/tvm/autotvm/tophub.py index 9ec9becc7245..1fa0409def58 100644 --- a/python/tvm/autotvm/tophub.py +++ b/python/tvm/autotvm/tophub.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ TopHub: Tensor Operator Hub To get the best performance, we typically need auto-tuning for the specific devices. diff --git a/python/tvm/autotvm/tuner/__init__.py b/python/tvm/autotvm/tuner/__init__.py index af81442e79f4..c5ad6bff112a 100644 --- a/python/tvm/autotvm/tuner/__init__.py +++ b/python/tvm/autotvm/tuner/__init__.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ A tuner takes a task as input. It proposes some promising :any:`ConfigEntity` in the :any:`ConfigSpace` and measure them on the real hardware. Then it diff --git a/python/tvm/autotvm/tuner/callback.py b/python/tvm/autotvm/tuner/callback.py index 6f66871f671c..a2a2f32bded6 100644 --- a/python/tvm/autotvm/tuner/callback.py +++ b/python/tvm/autotvm/tuner/callback.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=consider-using-enumerate,invalid-name """Namespace of callback utilities of AutoTVM""" import sys diff --git a/python/tvm/autotvm/tuner/ga_tuner.py b/python/tvm/autotvm/tuner/ga_tuner.py index 1afaca73ebb6..a4c36bcd385e 100644 --- a/python/tvm/autotvm/tuner/ga_tuner.py +++ b/python/tvm/autotvm/tuner/ga_tuner.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=consider-using-enumerate,invalid-name,abstract-method """Tuner with genetic algorithm""" diff --git a/python/tvm/autotvm/tuner/gridsearch_tuner.py b/python/tvm/autotvm/tuner/gridsearch_tuner.py index 21a17a132640..4e9a4a2821d7 100644 --- a/python/tvm/autotvm/tuner/gridsearch_tuner.py +++ b/python/tvm/autotvm/tuner/gridsearch_tuner.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=abstract-method """Grid search tuner and random tuner""" diff --git a/python/tvm/autotvm/tuner/metric.py b/python/tvm/autotvm/tuner/metric.py index c18f080ec0cb..5497ff4c91ab 100644 --- a/python/tvm/autotvm/tuner/metric.py +++ b/python/tvm/autotvm/tuner/metric.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Metrics for evaluating tuning process""" diff --git a/python/tvm/autotvm/tuner/model_based_tuner.py b/python/tvm/autotvm/tuner/model_based_tuner.py index 62fc57f2e869..432f7070c349 100644 --- a/python/tvm/autotvm/tuner/model_based_tuner.py +++ b/python/tvm/autotvm/tuner/model_based_tuner.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=no-else-return,invalid-name,consider-using-enumerate,abstract-method """Base class for model-based tuner This type of tuner will fit a cost model and use some optimization methods to diff --git a/python/tvm/autotvm/tuner/sa_model_optimizer.py b/python/tvm/autotvm/tuner/sa_model_optimizer.py index 77c7e919593b..5cc1b50a662d 100644 --- a/python/tvm/autotvm/tuner/sa_model_optimizer.py +++ b/python/tvm/autotvm/tuner/sa_model_optimizer.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=consider-using-enumerate, invalid-name """ Cost model optimizer based on simulated annealing diff --git a/python/tvm/autotvm/tuner/tuner.py b/python/tvm/autotvm/tuner/tuner.py index 120c97c2c003..76d088f4cfb3 100644 --- a/python/tvm/autotvm/tuner/tuner.py +++ b/python/tvm/autotvm/tuner/tuner.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=unused-argument, no-self-use, invalid-name """Base class of tuner""" import logging diff --git a/python/tvm/autotvm/tuner/xgboost_cost_model.py b/python/tvm/autotvm/tuner/xgboost_cost_model.py index a725a1eeabed..e278957c8af3 100644 --- a/python/tvm/autotvm/tuner/xgboost_cost_model.py +++ b/python/tvm/autotvm/tuner/xgboost_cost_model.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """XGBoost as cost model""" diff --git a/python/tvm/autotvm/tuner/xgboost_tuner.py b/python/tvm/autotvm/tuner/xgboost_tuner.py index 886c82a4d749..a7498c3b6309 100644 --- a/python/tvm/autotvm/tuner/xgboost_tuner.py +++ b/python/tvm/autotvm/tuner/xgboost_tuner.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Tuner that uses xgboost as cost model""" from .model_based_tuner import ModelBasedTuner, ModelOptimizer diff --git a/python/tvm/autotvm/util.py b/python/tvm/autotvm/util.py index 528eb24be380..192e9cd783ab 100644 --- a/python/tvm/autotvm/util.py +++ b/python/tvm/autotvm/util.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Utilities""" import logging diff --git a/python/tvm/build_module.py b/python/tvm/build_module.py old mode 100755 new mode 100644 index 7b81c55f1111..120bf629a959 --- a/python/tvm/build_module.py +++ b/python/tvm/build_module.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """The build utils in python. This module provides the functions to transform schedule to diff --git a/python/tvm/codegen.py b/python/tvm/codegen.py index d8097a0bd79c..61ee1f78f139 100644 --- a/python/tvm/codegen.py +++ b/python/tvm/codegen.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Code generation related functions.""" from ._ffi.function import _init_api diff --git a/python/tvm/container.py b/python/tvm/container.py index e384a742c36f..ebc8376b1872 100644 --- a/python/tvm/container.py +++ b/python/tvm/container.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Container data structures used in TVM DSL.""" from __future__ import absolute_import as _abs from ._ffi.node import NodeBase, register_node diff --git a/python/tvm/contrib/__init__.py b/python/tvm/contrib/__init__.py index 6bb9f11ef1d2..e887d65d8c78 100644 --- a/python/tvm/contrib/__init__.py +++ b/python/tvm/contrib/__init__.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Contrib APIs of TVM python package. Contrib API provides many useful not core features. diff --git a/python/tvm/contrib/cblas.py b/python/tvm/contrib/cblas.py index eb32cc490347..c656fcc2b966 100644 --- a/python/tvm/contrib/cblas.py +++ b/python/tvm/contrib/cblas.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """External function interface to BLAS libraries.""" from __future__ import absolute_import as _abs diff --git a/python/tvm/contrib/cc.py b/python/tvm/contrib/cc.py index ee84da820902..26ac672880a9 100644 --- a/python/tvm/contrib/cc.py +++ b/python/tvm/contrib/cc.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Util to invoke c++ compilers in the system.""" # pylint: disable=invalid-name from __future__ import absolute_import as _abs @@ -29,7 +45,7 @@ def create_shared(output, cc : str, optional The compile string. """ - if sys.platform == "darwin" or sys.platform.startswith('linux'): + if sys.platform == "darwin" or sys.platform.startswith("linux"): _linux_shared(output, objects, options, cc) elif sys.platform == "win32": _windows_shared(output, objects, options) @@ -37,6 +53,38 @@ def create_shared(output, raise ValueError("Unsupported platform") +# assign so as default output format +create_shared.output_format = "so" if sys.platform != "win32" else "dll" + + +def cross_compiler(cc, options=None, output_format="so"): + """Create a cross compiler function. + + Parameters + ---------- + cc : str + The cross compiler name. + + options : list, optional + List of additional optional string. + + output_format : str, optional + Library output format. + + Returns + ------- + fcompile : function + A compilation function that can be passed to export_library. + """ + def _fcompile(outputs, objects, opts=None): + opts = opts if opts else [] + if options: + opts += options + _linux_shared(outputs, objects, opts, cc=cc) + _fcompile.output_format = output_format + return _fcompile + + def _linux_shared(output, objects, options, cc="g++"): cmd = [cc] cmd += ["-shared", "-fPIC"] diff --git a/python/tvm/contrib/clang.py b/python/tvm/contrib/clang.py index 3e8ad663c58f..2aeb685c1f67 100644 --- a/python/tvm/contrib/clang.py +++ b/python/tvm/contrib/clang.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Util to invoke clang in the system.""" # pylint: disable=invalid-name from __future__ import absolute_import as _abs diff --git a/python/tvm/contrib/cublas.py b/python/tvm/contrib/cublas.py index eda09fead359..d7351a3ad856 100644 --- a/python/tvm/contrib/cublas.py +++ b/python/tvm/contrib/cublas.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """External function interface to cuBLAS libraries.""" from __future__ import absolute_import as _abs diff --git a/python/tvm/contrib/cudnn.py b/python/tvm/contrib/cudnn.py index 8f6708b145ad..8993e6b7d3ac 100644 --- a/python/tvm/contrib/cudnn.py +++ b/python/tvm/contrib/cudnn.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """External function interface to CuDNN v7 library.""" # pylint: disable-msg=C0103 import ctypes diff --git a/python/tvm/contrib/debugger/debug_result.py b/python/tvm/contrib/debugger/debug_result.py index 101af6887c47..c53a2c287339 100644 --- a/python/tvm/contrib/debugger/debug_result.py +++ b/python/tvm/contrib/debugger/debug_result.py @@ -1,9 +1,34 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Graph debug results dumping class.""" -import os +import collections import json +import os +import numpy as np import tvm GRAPH_DUMP_FILE_NAME = '_tvmdbg_graph_dump.json' +CHROME_TRACE_FILE_NAME = "_tvmdbg_execution_trace.json" + +ChromeTraceEvent = collections.namedtuple( + 'ChromeTraceEvent', + ['ts', 'tid', 'pid', 'name', 'ph'] +) + class DebugResult(object): """Graph debug data module. @@ -127,6 +152,45 @@ def dump_output_tensor(self): with open(os.path.join(self._dump_path, "output_tensors.params"), "wb") as param_f: param_f.write(save_tensors(output_tensors)) + def dump_chrome_trace(self): + """Dump the trace to the Chrome trace.json format. + """ + def s_to_us(t): + return t * 10 ** 6 + + starting_times = np.zeros(len(self._time_list) + 1) + starting_times[1:] = np.cumsum([times[0] for times in self._time_list]) + + def node_to_events(node, times, starting_time): + return [ + ChromeTraceEvent( + ts=s_to_us(starting_time), + tid=1, + pid=1, + ph='B', + name=node['name'], + ), + ChromeTraceEvent( + # Use start + duration instead of end to ensure precise timings. + ts=s_to_us(times[0] + starting_time), + tid=1, + pid=1, + ph='E', + name=node['name'], + ), + ] + events = [ + e for (node, times, starting_time) in zip( + self._nodes_list, self._time_list, starting_times) + for e in node_to_events(node, times, starting_time)] + result = dict( + displayTimeUnit='ns', + traceEvents=[e._asdict() for e in events] + ) + + with open(os.path.join(self._dump_path, CHROME_TRACE_FILE_NAME), "w") as trace_f: + json.dump(result, trace_f) + def dump_graph_json(self, graph): """Dump json formatted graph. diff --git a/python/tvm/contrib/debugger/debug_runtime.py b/python/tvm/contrib/debugger/debug_runtime.py index 725f212fce00..01cda35769a5 100644 --- a/python/tvm/contrib/debugger/debug_runtime.py +++ b/python/tvm/contrib/debugger/debug_runtime.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Graph debug runtime executes TVM debug packed functions.""" import os @@ -220,7 +236,9 @@ def run(self, **input_dict): self._run_debug() # Step 2. Dump the output tensors to the dump folder self.debug_datum.dump_output_tensor() - # Step 3. Display the collected information + # Step 3. Dump the Chrome trace to the dump folder + self.debug_datum.dump_chrome_trace() + # Step 4. Display the collected information self.debug_datum.display_debug_result() def run_individual(self, number, repeat=1, min_repeat_ms=0): diff --git a/python/tvm/contrib/dlpack.py b/python/tvm/contrib/dlpack.py index 11db29f98b3e..a42536745a7d 100644 --- a/python/tvm/contrib/dlpack.py +++ b/python/tvm/contrib/dlpack.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Wrapping functions to bridge frameworks with DLPack support to TVM""" from .. import ndarray diff --git a/python/tvm/contrib/download.py b/python/tvm/contrib/download.py index 26f285a0b29a..46a9a6d98879 100644 --- a/python/tvm/contrib/download.py +++ b/python/tvm/contrib/download.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Helper utility for downloading""" from __future__ import print_function from __future__ import absolute_import as _abs @@ -28,6 +44,9 @@ def download(url, path, overwrite=False, size_compare=False, verbose=1, retries= verbose: int, optional Verbose level + + retries: int, optional + Number of time to retry download, default at 3. """ if sys.version_info >= (3,): import urllib.request as urllib2 @@ -56,7 +75,7 @@ def download(url, path, overwrite=False, size_compare=False, verbose=1, retries= # Stateful start time start_time = time.time() dirpath = os.path.dirname(path) - if not os.path.isdir(dirpath): + if dirpath and not os.path.isdir(dirpath): os.makedirs(dirpath) random_uuid = str(uuid.uuid4()) tempfile = os.path.join(dirpath, random_uuid) diff --git a/python/tvm/contrib/emscripten.py b/python/tvm/contrib/emscripten.py index a722a0d673d9..7f31273451f7 100644 --- a/python/tvm/contrib/emscripten.py +++ b/python/tvm/contrib/emscripten.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Util to invoke emscripten compilers in the system.""" # pylint: disable=invalid-name from __future__ import absolute_import as _abs diff --git a/python/tvm/contrib/graph_runtime.py b/python/tvm/contrib/graph_runtime.py index 0d62a04a5571..4d0698a40db7 100644 --- a/python/tvm/contrib/graph_runtime.py +++ b/python/tvm/contrib/graph_runtime.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Minimum graph runtime that executes graph containing TVM PackedFunc.""" import numpy as np diff --git a/python/tvm/contrib/miopen.py b/python/tvm/contrib/miopen.py index b76e70688c4e..442ce99432dd 100644 --- a/python/tvm/contrib/miopen.py +++ b/python/tvm/contrib/miopen.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """External function interface to MIOpen library.""" # pylint: disable-msg=C0103 import ctypes diff --git a/python/tvm/contrib/mps.py b/python/tvm/contrib/mps.py index 86532f72153c..d9cab2471c6f 100644 --- a/python/tvm/contrib/mps.py +++ b/python/tvm/contrib/mps.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """External function interface to MPS libraries.""" from __future__ import absolute_import as _abs from .. import api as _api diff --git a/python/tvm/contrib/mxnet.py b/python/tvm/contrib/mxnet.py index 3a6c92f1b880..19c50f01819c 100644 --- a/python/tvm/contrib/mxnet.py +++ b/python/tvm/contrib/mxnet.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """MXNet bridge wrap Function MXNet's async function.""" from __future__ import absolute_import as _abs diff --git a/python/tvm/contrib/ndk.py b/python/tvm/contrib/ndk.py index a79aae96163d..931fa03a7308 100644 --- a/python/tvm/contrib/ndk.py +++ b/python/tvm/contrib/ndk.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Util to invoke NDK compiler toolchain.""" # pylint: disable=invalid-name from __future__ import absolute_import as _abs diff --git a/python/tvm/contrib/nnpack.py b/python/tvm/contrib/nnpack.py index 3aa874f3a65c..c6530dd49756 100644 --- a/python/tvm/contrib/nnpack.py +++ b/python/tvm/contrib/nnpack.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """External function interface to NNPACK libraries.""" from __future__ import absolute_import as _abs diff --git a/python/tvm/contrib/nvcc.py b/python/tvm/contrib/nvcc.py index f9970f6bceb2..37e4f2aa2c7f 100644 --- a/python/tvm/contrib/nvcc.py +++ b/python/tvm/contrib/nvcc.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Utility to invoke nvcc compiler in the system""" from __future__ import absolute_import as _abs diff --git a/python/tvm/contrib/peak.py b/python/tvm/contrib/peak.py index eefa7bfa0b52..bc93afbf165e 100644 --- a/python/tvm/contrib/peak.py +++ b/python/tvm/contrib/peak.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """measure bandwidth and compute peak""" diff --git a/python/tvm/contrib/pickle_memoize.py b/python/tvm/contrib/pickle_memoize.py index 32edd4025e84..c65797106fc5 100644 --- a/python/tvm/contrib/pickle_memoize.py +++ b/python/tvm/contrib/pickle_memoize.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Memoize result of function via pickle, used for cache testcases.""" # pylint: disable=broad-except,superfluous-parens import os diff --git a/python/tvm/contrib/random.py b/python/tvm/contrib/random.py index 6c32dd2d293b..a57fac0cad68 100644 --- a/python/tvm/contrib/random.py +++ b/python/tvm/contrib/random.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """External function interface to random library.""" from __future__ import absolute_import as _abs diff --git a/python/tvm/contrib/rocblas.py b/python/tvm/contrib/rocblas.py index 470cff662c4c..bdd6146e2ecf 100644 --- a/python/tvm/contrib/rocblas.py +++ b/python/tvm/contrib/rocblas.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """External function interface to rocBLAS libraries.""" from __future__ import absolute_import as _abs diff --git a/python/tvm/contrib/rocm.py b/python/tvm/contrib/rocm.py index 172d081ff96a..cf0c9ae8adc9 100644 --- a/python/tvm/contrib/rocm.py +++ b/python/tvm/contrib/rocm.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Utility for ROCm backend""" import subprocess from os.path import join, exists diff --git a/python/tvm/contrib/rpc.py b/python/tvm/contrib/rpc.py index 8f6611ddb905..c57efb65495a 100644 --- a/python/tvm/contrib/rpc.py +++ b/python/tvm/contrib/rpc.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Deprecation RPC module""" # pylint: disable=unused-import from __future__ import absolute_import as _abs diff --git a/python/tvm/contrib/sdaccel.py b/python/tvm/contrib/sdaccel.py index 6bc246ff1751..1234d546ebae 100644 --- a/python/tvm/contrib/sdaccel.py +++ b/python/tvm/contrib/sdaccel.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Utility for Interacting with SDAccel Tools""" import subprocess import os diff --git a/python/tvm/contrib/sparse.py b/python/tvm/contrib/sparse.py index 523039912aa9..b82da074576f 100644 --- a/python/tvm/contrib/sparse.py +++ b/python/tvm/contrib/sparse.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Tensor and Operation class for computation declaration.""" # pylint: disable=invalid-name from __future__ import absolute_import as _abs diff --git a/python/tvm/contrib/spirv.py b/python/tvm/contrib/spirv.py index 586da1a7487f..38228a9b5224 100644 --- a/python/tvm/contrib/spirv.py +++ b/python/tvm/contrib/spirv.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Utility for Interacting with SPIRV Tools""" import subprocess import os diff --git a/python/tvm/contrib/tar.py b/python/tvm/contrib/tar.py index 7e075d7a5697..f0de61628751 100644 --- a/python/tvm/contrib/tar.py +++ b/python/tvm/contrib/tar.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Util to invoke tarball in the system.""" # pylint: disable=invalid-name @@ -42,6 +58,9 @@ def tar(output, files): msg += py_str(out) raise RuntimeError(msg) +# assign output format +tar.output_format = "tar" + def untar(tar_file, directory): """Unpack all tar files into the directory diff --git a/python/tvm/contrib/util.py b/python/tvm/contrib/util.py index 0d94a8da5058..8db84cac952e 100644 --- a/python/tvm/contrib/util.py +++ b/python/tvm/contrib/util.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Common system utilities""" from __future__ import absolute_import as _abs import os diff --git a/python/tvm/contrib/verilog.py b/python/tvm/contrib/verilog.py index f904a0cb01bf..30fa6ce2c7dd 100644 --- a/python/tvm/contrib/verilog.py +++ b/python/tvm/contrib/verilog.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Verilog simulator modules.""" from __future__ import absolute_import diff --git a/python/tvm/contrib/xcode.py b/python/tvm/contrib/xcode.py index a43dc9ae2bfe..f78850d570e5 100644 --- a/python/tvm/contrib/xcode.py +++ b/python/tvm/contrib/xcode.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Utility to invoke Xcode compiler toolchain""" from __future__ import absolute_import as _abs @@ -98,6 +114,9 @@ def create_dylib(output, objects, arch, sdk="macosx"): raise RuntimeError(msg) +# assign so as default output format +create_dylib.output_format = "dylib" + def compile_metal(code, path_target=None, sdk="macosx"): """Compile metal with CLI tool from env. diff --git a/python/tvm/error.py b/python/tvm/error.py index d817e9a4a635..cf05e7a405fc 100644 --- a/python/tvm/error.py +++ b/python/tvm/error.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Structured error classes in TVM. Each error class takes an error message as its input. diff --git a/python/tvm/exec/__init__.py b/python/tvm/exec/__init__.py index 04441ba2f1e6..b9b535148f41 100644 --- a/python/tvm/exec/__init__.py +++ b/python/tvm/exec/__init__.py @@ -1 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Namespace of executables python files that directly run throw cmd""" diff --git a/python/tvm/exec/autotvm_log_editor.py b/python/tvm/exec/autotvm_log_editor.py index 458b6eff0e44..5d530547e0c2 100644 --- a/python/tvm/exec/autotvm_log_editor.py +++ b/python/tvm/exec/autotvm_log_editor.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Pick best log entries from a large file and store them to a small file""" diff --git a/python/tvm/exec/measure_peak.py b/python/tvm/exec/measure_peak.py index b477ac23d3af..c9759bfd2b69 100644 --- a/python/tvm/exec/measure_peak.py +++ b/python/tvm/exec/measure_peak.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """measure bandwidth and compute peak e.g. @@ -21,7 +37,7 @@ def main(): parser.add_argument('--rpc-host', type=str, default="0.0.0.0", help='the hostname of the server') parser.add_argument('--rpc-port', type=int, default=9090, - help='The port of the PRC') + help='The port of the RPC') args = parser.parse_args() logging.basicConfig(level=logging.INFO) diff --git a/python/tvm/exec/query_rpc_tracker.py b/python/tvm/exec/query_rpc_tracker.py index 32ec4f5da764..e61092304bb6 100644 --- a/python/tvm/exec/query_rpc_tracker.py +++ b/python/tvm/exec/query_rpc_tracker.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Tool to query RPC tracker status""" from __future__ import absolute_import @@ -12,7 +28,7 @@ def main(): parser.add_argument('--host', type=str, default="", help='the hostname of the tracker') parser.add_argument('--port', type=int, default=None, - help='The port of the PRC') + help='The port of the RPC') args = parser.parse_args() logging.basicConfig(level=logging.INFO) diff --git a/python/tvm/exec/rpc_proxy.py b/python/tvm/exec/rpc_proxy.py index 7efb7ae33066..4cf341335ea7 100644 --- a/python/tvm/exec/rpc_proxy.py +++ b/python/tvm/exec/rpc_proxy.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=redefined-outer-name, invalid-name """RPC web proxy, allows redirect to websocket based RPC servers(browsers)""" from __future__ import absolute_import @@ -56,7 +72,7 @@ def main(args): parser.add_argument('--host', type=str, default="0.0.0.0", help='the hostname of the server') parser.add_argument('--port', type=int, default=9090, - help='The port of the PRC') + help='The port of the RPC') parser.add_argument('--web-port', type=int, default=8888, help='The port of the http/websocket server') parser.add_argument('--example-rpc', type=bool, default=False, diff --git a/python/tvm/exec/rpc_server.py b/python/tvm/exec/rpc_server.py index 73c943366b4c..397238e0eef1 100644 --- a/python/tvm/exec/rpc_server.py +++ b/python/tvm/exec/rpc_server.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=redefined-outer-name, invalid-name """Start an RPC server""" from __future__ import absolute_import @@ -37,9 +53,9 @@ def main(args): parser.add_argument('--host', type=str, default="0.0.0.0", help='the hostname of the server') parser.add_argument('--port', type=int, default=9090, - help='The port of the PRC') + help='The port of the RPC') parser.add_argument('--port-end', type=int, default=9199, - help='The end search port of the PRC') + help='The end search port of the RPC') parser.add_argument('--tracker', type=str, help="The address of RPC tracker in host:port format. " "e.g. (10.77.1.234:9190)") diff --git a/python/tvm/exec/rpc_tracker.py b/python/tvm/exec/rpc_tracker.py index 8e606306760a..8f5bd1dc73a0 100644 --- a/python/tvm/exec/rpc_tracker.py +++ b/python/tvm/exec/rpc_tracker.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=redefined-outer-name, invalid-name """Tool to start RPC tracker""" from __future__ import absolute_import @@ -20,9 +36,9 @@ def main(args): parser.add_argument('--host', type=str, default="0.0.0.0", help='the hostname of the tracker') parser.add_argument('--port', type=int, default=9190, - help='The port of the PRC') + help='The port of the RPC') parser.add_argument('--port-end', type=int, default=9199, - help='The end search port of the PRC') + help='The end search port of the RPC') parser.add_argument('--no-fork', dest='fork', action='store_false', help="Use spawn mode to avoid fork. This option \ is able to avoid potential fork problems with Metal, OpenCL \ diff --git a/python/tvm/expr.py b/python/tvm/expr.py index dcfa3580d796..a234ac4da53b 100644 --- a/python/tvm/expr.py +++ b/python/tvm/expr.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Expression AST Node in TVM. User do not need to deal with expression AST node directly. diff --git a/python/tvm/generic.py b/python/tvm/generic.py index fb96ff0131ba..7f5c3d6aa8b2 100644 --- a/python/tvm/generic.py +++ b/python/tvm/generic.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Generic opertors in TVM. We follow the numpy naming convention for this interface (e.g., tvm.generic.multitply ~ numpy.multiply). diff --git a/python/tvm/hybrid/__init__.py b/python/tvm/hybrid/__init__.py index 645ef992833f..7aca007ecd94 100644 --- a/python/tvm/hybrid/__init__.py +++ b/python/tvm/hybrid/__init__.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Hybrid Programming APIs of TVM Python Package. This package maps a subset of python to HalideIR so that: diff --git a/python/tvm/hybrid/calls.py b/python/tvm/hybrid/calls.py index 56a73f784fa0..414822068e07 100644 --- a/python/tvm/hybrid/calls.py +++ b/python/tvm/hybrid/calls.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Intrinsics of TVM-Python Hybrid Script for Python compilation time semantic support.""" diff --git a/python/tvm/hybrid/module.py b/python/tvm/hybrid/module.py index 01557ba8b179..297dd0b9941a 100644 --- a/python/tvm/hybrid/module.py +++ b/python/tvm/hybrid/module.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Methods and data structures to support dumping HalideIR to Hybrid Script. This allows users to do quick hack to generated HalideIR and cast it back to TVM modules. diff --git a/python/tvm/hybrid/parser.py b/python/tvm/hybrid/parser.py index 67a6f6632d16..1c1525e11be8 100644 --- a/python/tvm/hybrid/parser.py +++ b/python/tvm/hybrid/parser.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Hybrid Script Parser""" import ast diff --git a/python/tvm/hybrid/preprocessor.py b/python/tvm/hybrid/preprocessor.py index a83fb2eae287..117ebd3091ed 100644 --- a/python/tvm/hybrid/preprocessor.py +++ b/python/tvm/hybrid/preprocessor.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Determines the declaration, r/w status, and last use of each variable""" import ast diff --git a/python/tvm/hybrid/runtime.py b/python/tvm/hybrid/runtime.py index b3c744f42652..7e4217c69c67 100644 --- a/python/tvm/hybrid/runtime.py +++ b/python/tvm/hybrid/runtime.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Intrinsics of TVM-Python Hybrid Script for Python emulation runtime""" import numpy diff --git a/python/tvm/hybrid/util.py b/python/tvm/hybrid/util.py index dcccaa465883..0dd1fa141329 100644 --- a/python/tvm/hybrid/util.py +++ b/python/tvm/hybrid/util.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Internal utilities for parsing Python subset to HalideIR""" import ast diff --git a/python/tvm/intrin.py b/python/tvm/intrin.py index a0dabfc8a6e2..71739ad4321b 100644 --- a/python/tvm/intrin.py +++ b/python/tvm/intrin.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Expression Intrinsics and math functions in TVM.""" # pylint: disable=redefined-builtin from __future__ import absolute_import as _abs diff --git a/python/tvm/ir_builder.py b/python/tvm/ir_builder.py index dcf5b9d0976b..d7f41a2669bf 100644 --- a/python/tvm/ir_builder.py +++ b/python/tvm/ir_builder.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Developer API of IR node builder make function.""" from __future__ import absolute_import as _abs diff --git a/python/tvm/ir_pass.py b/python/tvm/ir_pass.py index 35a07d8a4bff..5d5ddf0a8668 100644 --- a/python/tvm/ir_pass.py +++ b/python/tvm/ir_pass.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Namespace of IR pass functions. This namespace is used for developers. While you do not see any declarations. diff --git a/python/tvm/make.py b/python/tvm/make.py index 780bdc246508..7439952ad7ad 100644 --- a/python/tvm/make.py +++ b/python/tvm/make.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """namespace of IR node builder make function This namespace is used for developers. While you do not see any declarations. diff --git a/python/tvm/module.py b/python/tvm/module.py index d33a947dd7ed..42332be7cd2a 100644 --- a/python/tvm/module.py +++ b/python/tvm/module.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Container of compiled functions of TVM.""" from __future__ import absolute_import as _abs diff --git a/python/tvm/ndarray.py b/python/tvm/ndarray.py index 567aff6fba9c..c24a189b78d3 100644 --- a/python/tvm/ndarray.py +++ b/python/tvm/ndarray.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """TVM Runtime NDArray API. tvm.ndarray provides a minimum runtime array API to test diff --git a/python/tvm/node.py b/python/tvm/node.py index b47087773d95..1d5b506fabe7 100644 --- a/python/tvm/node.py +++ b/python/tvm/node.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Node is the base class of all TVM AST. Normally user do not need to touch this api. diff --git a/python/tvm/relay/__init__.py b/python/tvm/relay/__init__.py index a8d81b0cdf52..1ec09aac2606 100644 --- a/python/tvm/relay/__init__.py +++ b/python/tvm/relay/__init__.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=wildcard-import, redefined-builtin, invalid-name """The Relay IR namespace containing the IR definition and compiler.""" from __future__ import absolute_import diff --git a/python/tvm/relay/_base.py b/python/tvm/relay/_base.py index b23655a0406a..d7ecaa84b45c 100644 --- a/python/tvm/relay/_base.py +++ b/python/tvm/relay/_base.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=no-else-return, unidiomatic-typecheck, undefined-variable """The interface of expr function exposed from C++.""" from tvm._ffi.function import _init_api diff --git a/python/tvm/relay/_expr.py b/python/tvm/relay/_expr.py index 1a27c4efc410..07ef7e0588d4 100644 --- a/python/tvm/relay/_expr.py +++ b/python/tvm/relay/_expr.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=no-else-return, unidiomatic-typecheck, undefined-variable """The interface of expr function exposed from C++.""" from tvm._ffi.function import _init_api diff --git a/python/tvm/relay/_ir_pass.py b/python/tvm/relay/_ir_pass.py index 61fdcfa38c2f..3a0e0ac846b9 100644 --- a/python/tvm/relay/_ir_pass.py +++ b/python/tvm/relay/_ir_pass.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """FFI exposing the Relay type inference and checking.""" from tvm._ffi.function import _init_api diff --git a/python/tvm/relay/_ir_pass.pyi b/python/tvm/relay/_ir_pass.pyi index 534445d6d9ac..6aedb5248657 100644 --- a/python/tvm/relay/_ir_pass.pyi +++ b/python/tvm/relay/_ir_pass.pyi @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + import tvm from . import ir from .base import NodeBase diff --git a/python/tvm/relay/_make.py b/python/tvm/relay/_make.py index 20a582e76d6a..6081b2664ca8 100644 --- a/python/tvm/relay/_make.py +++ b/python/tvm/relay/_make.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ The constructors for all Relay AST nodes exposed from C++. diff --git a/python/tvm/relay/_module.py b/python/tvm/relay/_module.py index b6e74c451915..365c82736eec 100644 --- a/python/tvm/relay/_module.py +++ b/python/tvm/relay/_module.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=no-else-return, unidiomatic-typecheck, undefined-variable """The interface to the Module exposed from C++.""" from tvm._ffi.function import _init_api diff --git a/python/tvm/relay/_module.pyi b/python/tvm/relay/_module.pyi index de3aabefba4c..ae2d199de257 100644 --- a/python/tvm/relay/_module.pyi +++ b/python/tvm/relay/_module.pyi @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + from typing import Union, Tuple, Dict, List from relay.ir import GlobalId, OperatorId, Item, NodeBase, Span, FileId from relay.ir import ShapeExtension, Operator, Defn diff --git a/python/tvm/relay/_parser.py b/python/tvm/relay/_parser.py index de7e2ae24959..62f0ffe15cba 100644 --- a/python/tvm/relay/_parser.py +++ b/python/tvm/relay/_parser.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-import """A parser for Relay's text format.""" diff --git a/python/tvm/relay/adt.py b/python/tvm/relay/adt.py index abf78d565d62..2c76d95ed8c3 100644 --- a/python/tvm/relay/adt.py +++ b/python/tvm/relay/adt.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=no-else-return, unidiomatic-typecheck, invalid-name """Algebraic data types in Relay.""" from .base import RelayNode, register_relay_node, NodeBase diff --git a/python/tvm/relay/annotation.py b/python/tvm/relay/annotation.py index 51a7118986d3..5a4065313dcc 100644 --- a/python/tvm/relay/annotation.py +++ b/python/tvm/relay/annotation.py @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # pylint: disable=wildcard-import, unused-import, unused-wildcard-import """Annotation related operators.""" # Re-export in a specific file name so that autodoc can pick it up diff --git a/python/tvm/relay/backend/__init__.py b/python/tvm/relay/backend/__init__.py index 158989e9bf2f..1af8fc5ae897 100644 --- a/python/tvm/relay/backend/__init__.py +++ b/python/tvm/relay/backend/__init__.py @@ -1,2 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Backend codege modules for relay.""" from . import compile_engine diff --git a/python/tvm/relay/backend/_backend.py b/python/tvm/relay/backend/_backend.py index 70f91f8cfec5..50e9694b40df 100644 --- a/python/tvm/relay/backend/_backend.py +++ b/python/tvm/relay/backend/_backend.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """The interface of expr function exposed from C++.""" from __future__ import absolute_import diff --git a/python/tvm/relay/backend/compile_engine.py b/python/tvm/relay/backend/compile_engine.py index c101ed43469e..152da61c5d07 100644 --- a/python/tvm/relay/backend/compile_engine.py +++ b/python/tvm/relay/backend/compile_engine.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Backend code generation engine.""" from __future__ import absolute_import diff --git a/python/tvm/relay/backend/graph_runtime_codegen.py b/python/tvm/relay/backend/graph_runtime_codegen.py index 0409c8dd7390..cc3f14ba3951 100644 --- a/python/tvm/relay/backend/graph_runtime_codegen.py +++ b/python/tvm/relay/backend/graph_runtime_codegen.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ A compiler from a Relay expression to TVM's graph runtime. diff --git a/python/tvm/relay/backend/interpreter.py b/python/tvm/relay/backend/interpreter.py index e927df22b201..ddcbd79122e0 100644 --- a/python/tvm/relay/backend/interpreter.py +++ b/python/tvm/relay/backend/interpreter.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. #pylint: disable=no-else-return """The Python interface to the Relay reference interpreter.""" from __future__ import absolute_import diff --git a/python/tvm/relay/base.py b/python/tvm/relay/base.py index 548c0e35a342..eb604a405410 100644 --- a/python/tvm/relay/base.py +++ b/python/tvm/relay/base.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=no-else-return, unidiomatic-typecheck """The base node types for the Relay language.""" from __future__ import absolute_import as _abs @@ -62,7 +78,7 @@ def astext(self, show_meta_data=True, annotate=None): text : str The text format of the expression. """ - return _expr.RelayPrint(self, show_meta_data, annotate) + return _expr.AsText(self, show_meta_data, annotate) def set_span(self, span): _base.set_span(self, span) diff --git a/python/tvm/relay/build_module.py b/python/tvm/relay/build_module.py index e0784d53ee47..b16b5e28bf34 100644 --- a/python/tvm/relay/build_module.py +++ b/python/tvm/relay/build_module.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Construct the necessary state for the TVM graph runtime from a Relay expression. diff --git a/python/tvm/relay/debug.py b/python/tvm/relay/debug.py index 00ad7b4401b0..ee30f25d88c1 100644 --- a/python/tvm/relay/debug.py +++ b/python/tvm/relay/debug.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=wildcard-import, redefined-builtin, invalid-name """The Relay IR namespace containing the IR definition and compiler.""" from __future__ import absolute_import diff --git a/python/tvm/relay/expr.py b/python/tvm/relay/expr.py index bd28acc9e4b5..1530befb5d45 100644 --- a/python/tvm/relay/expr.py +++ b/python/tvm/relay/expr.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=no-else-return, unidiomatic-typecheck, invalid-name """The expression nodes of Relay.""" from __future__ import absolute_import diff --git a/python/tvm/relay/expr.pyi b/python/tvm/relay/expr.pyi index bc2e5115df0d..b7395c365390 100644 --- a/python/tvm/relay/expr.pyi +++ b/python/tvm/relay/expr.pyi @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + from typing import List import tvm from .base import Span, NodeBase diff --git a/python/tvm/relay/expr_functor.py b/python/tvm/relay/expr_functor.py index c5ab5cdbde5d..a924847fa238 100644 --- a/python/tvm/relay/expr_functor.py +++ b/python/tvm/relay/expr_functor.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=no-else-return, unidiomatic-typecheck, invalid-name """The expression functor of Relay.""" diff --git a/python/tvm/relay/frontend/__init__.py b/python/tvm/relay/frontend/__init__.py index dee3999ad3f1..8d308c7e8833 100644 --- a/python/tvm/relay/frontend/__init__.py +++ b/python/tvm/relay/frontend/__init__.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Frontends for constructing Relay programs. diff --git a/python/tvm/relay/frontend/caffe2.py b/python/tvm/relay/frontend/caffe2.py old mode 100755 new mode 100644 index 769740df0be3..e92a6226072f --- a/python/tvm/relay/frontend/caffe2.py +++ b/python/tvm/relay/frontend/caffe2.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=import-self, invalid-name, line-too-long, unused-argument """Caffe2 frontend""" from __future__ import absolute_import as _abs diff --git a/python/tvm/relay/frontend/common.py b/python/tvm/relay/frontend/common.py index 2871b7f73163..9b89936de015 100644 --- a/python/tvm/relay/frontend/common.py +++ b/python/tvm/relay/frontend/common.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Common utilities""" from __future__ import absolute_import as _abs import logging @@ -258,6 +274,9 @@ def set_expr(self, name, expr): if name not in self.exprs: self.exprs[name] = expr + def has_expr(self, name): + return True if name in self.exprs else False + def set_padding(self, paddings): self.paddings = paddings self.in_padding = True @@ -321,6 +340,10 @@ def __call__(self, inputs, attrs, *args): else: assert callable(self._op_name), "op_name can either be string or callable" op_name = self._op_name(attrs) + + # ignore 'tvm_custom' always + self._ignores.append('tvm_custom') + # convert attributes new_attrs = {} for k in attrs.keys(): @@ -329,7 +352,8 @@ def __call__(self, inputs, attrs, *args): elif k in self._disables: logging.warning("Attribute %s is disabled in relay.sym.%s", k, op_name) elif k in self._ignores: - logging.debug("Attribute %s is ignored in relay.sym.%s", k, op_name) + if k != 'tvm_custom': + logging.warning("Attribute %s is ignored in relay.sym.%s", k, op_name) elif k in self._transforms: new_name, defaults, transform = self._parse_default(self._transforms[k]) if defaults is None: @@ -416,4 +440,6 @@ def __init__(self, new_name): self._new_name = new_name def __call__(self, inputs, attrs, *args): + if 'tvm_custom' in attrs: + attrs.pop('tvm_custom') return get_relay_op(self._new_name)(*inputs, **attrs) diff --git a/python/tvm/relay/frontend/coreml.py b/python/tvm/relay/frontend/coreml.py index 963b21f38297..f4cfb09bb330 100644 --- a/python/tvm/relay/frontend/coreml.py +++ b/python/tvm/relay/frontend/coreml.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, import-self, unused-argument, unused-variable, inconsistent-return-statements """CoreML frontend.""" from __future__ import absolute_import as _abs diff --git a/python/tvm/relay/frontend/keras.py b/python/tvm/relay/frontend/keras.py index bd7cb4f3b110..cf712f793177 100644 --- a/python/tvm/relay/frontend/keras.py +++ b/python/tvm/relay/frontend/keras.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, import-self """Keras frontend.""" from __future__ import absolute_import as _abs diff --git a/python/tvm/relay/frontend/mxnet.py b/python/tvm/relay/frontend/mxnet.py index 69d779271be7..1218e65f53e1 100644 --- a/python/tvm/relay/frontend/mxnet.py +++ b/python/tvm/relay/frontend/mxnet.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, import-self, len-as-condition """MXNet symbol frontend.""" from __future__ import absolute_import as _abs @@ -34,7 +50,7 @@ def _mx_fully_connected(inputs, attrs): res = _op.nn.dense(inputs[0], inputs[1], units=units) if use_bias: assert len(inputs) == 3 - res = _op.nn.bias_add(res, inputs[2]) + res = _op.nn.bias_add(res, inputs[2], axis=-1) return res @@ -413,7 +429,7 @@ def _mx_batch_dot(inputs, attrs): raise tvm.error.OpAttributeInvalid(msg.format(transpose_a)) if transpose_b is False: b = _op.transpose(b, axes=[0, 2, 1]) - return _op.batch_matmul(a, b) + return _op.nn.batch_matmul(a, b) def _mx_arange(inputs, attrs): @@ -444,6 +460,15 @@ def _mx_tile(inputs, attrs): return _op.tile(inputs[0], **new_attrs) +def _mx_take(inputs, attrs): + assert len(inputs) == 2 + mode = attrs.get_str("mode", "clip") + if mode == "raise": + raise RuntimeError("take doesn't support raise mode") + axis = attrs.get_int("axis", 0) + return _op.take(inputs[0], inputs[1].astype("int32"), axis, mode) + + def _mx_reverse(inputs, attrs): assert len(inputs) == 1 new_attrs = {} @@ -459,17 +484,18 @@ def _mx_roi_align(inputs, attrs): new_attrs["layout"] = "NCHW" return _op.vision.roi_align(inputs[0], inputs[1], **new_attrs) -def _mx_upsampling(inputs, attrs): +def _mx_resize(inputs, attrs): scale_height = attrs.get_float("scale_height", None) scale_width = attrs.get_float("scale_width", None) height = attrs.get_int("height", 1) width = attrs.get_int("width", 1) + shape = ir_pass.infer_type(inputs[0]).checked_type.shape if scale_height is not None: - height = scale_height * inputs[0].shape[2] + height = (scale_height * shape[2]).astype("int32") if scale_width is not None: - width = scale_width * inputs[0].shape[3] - size = (inputs[0].shape[0], inputs[0].shape[1], height, width) - return _op.image.resize(inputs[0], size) + width = (scale_width * shape[3]).astype("int32") + size = (height, width) + return _op.image.resize(inputs[0], size, align_corners=True) def _mx_roi_pooling(inputs, attrs): new_attrs = {} @@ -603,6 +629,25 @@ def _mx_smooth_l1(inputs, attrs): _op.abs(inputs[0]) - _expr.const(0.5 / scalar_sq)) +def _mx_deformable_convolution(inputs, attrs): + new_attrs = {} + assert attrs.get_bool("no_bias") + new_attrs["kernel_size"] = attrs.get_int_tuple("kernel") + new_attrs["strides"] = attrs.get_int_tuple("stride") + new_attrs["padding"] = attrs.get_int_tuple("pad") + new_attrs["dilation"] = attrs.get_int_tuple("dilate") + new_attrs["channels"] = attrs.get_int("num_filter") + new_attrs["deformable_groups"] = attrs.get_int("num_deformable_group", 1) + new_attrs["groups"] = attrs.get_int("num_group", 1) + assert attrs.get_str("layout", "NCHW") == "NCHW", "Deformable conv2d only supports NCHW layout" + use_bias = not attrs.get_bool("no_bias", False) + res = _op.nn.deformable_conv2d(inputs[0], inputs[1], inputs[2], **new_attrs) + if use_bias: + assert len(inputs) == 4 + res = _op.nn.bias_add(res, inputs[3]) + return res + + # Note: due to attribute conversion constraint # ops in the identity set must be attribute free _identity_list = [ @@ -618,6 +663,7 @@ def _mx_smooth_l1(inputs, attrs): "zeros_like", "ones_like", "where", + "gather_nd", ] _convert_map = { @@ -730,6 +776,7 @@ def _mx_smooth_l1(inputs, attrs): "_full" : _mx_full, "repeat" : _mx_repeat, "tile" : _mx_tile, + "take" : _mx_take, "reverse" : _mx_reverse, "squeeze" : _mx_squeeze, "broadcast_axis": _mx_broadcast_axis, @@ -740,7 +787,7 @@ def _mx_smooth_l1(inputs, attrs): "SoftmaxActivation" : _mx_softmax_activation, "smooth_l1" : _mx_smooth_l1, # vision - "_contrib_BilinearResize2D" : _mx_upsampling, + "_contrib_BilinearResize2D" : _mx_resize, "_contrib_MultiBoxPrior" : _mx_multibox_prior, "_contrib_MultiBoxDetection" : _mx_multibox_detection, "_contrib_ROIAlign" : _mx_roi_align, @@ -748,11 +795,11 @@ def _mx_smooth_l1(inputs, attrs): "_contrib_Proposal" : _mx_proposal, "_contrib_MultiProposal" : _mx_proposal, "_contrib_box_nms" : _mx_box_nms, + "_contrib_DeformableConvolution" : _mx_deformable_convolution, # List of missing operators that are present in NNVMv1 # TODO(tvm-tvm): support all operators. # # "broadcast_to", - # "gather_nd", # "Crop" : _crop_like, } diff --git a/python/tvm/relay/frontend/nnvm_common.py b/python/tvm/relay/frontend/nnvm_common.py index 7fd6f409cfd3..be875cf471a3 100644 --- a/python/tvm/relay/frontend/nnvm_common.py +++ b/python/tvm/relay/frontend/nnvm_common.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, import-self, len-as-condition """Utility functions common to NNVM and MxNet conversion.""" from __future__ import absolute_import as _abs diff --git a/python/tvm/relay/frontend/onnx.py b/python/tvm/relay/frontend/onnx.py index a6851b833931..ebedc20375e5 100644 --- a/python/tvm/relay/frontend/onnx.py +++ b/python/tvm/relay/frontend/onnx.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, import-self, len-as-condition, unused-argument, too-many-lines """ONNX: Open Neural Network Exchange frontend for Relay.""" from __future__ import absolute_import as _abs @@ -106,7 +122,7 @@ def _impl_v1(cls, inputs, attr, params): 'pads': ('padding', (0, 0), revert_caffe2_pad) }, # very weird attributes here in onnx, force check - ignores=['dilations'], + ignores=['dilations', 'auto_pad'], # TODO(zhreshold): make sure ceil_mode in onnx, and layout? extras={'ceil_mode': False}, custom_check=dimension_constraint())(inputs, attr, params) @@ -160,6 +176,7 @@ def _impl_v1(cls, inputs, attr, params): 'dilations': ('dilation', (0, 0)), 'pads': ('padding', (0, 0), revert_caffe2_pad), 'group': ('groups', 1)}, + ignores=['auto_pad'], custom_check=dimension_constraint())(inputs[:2], attr, params) use_bias = len(inputs) == 3 if use_bias: @@ -332,7 +349,21 @@ def _impl_v1(cls, inputs, attr, params): shape = tuple(params[inputs[1].name_hint].asnumpy()) out = _op.reshape(inputs[0], shape) else: - out = _op.reshape_like(inputs[0], inputs[1]) + # Try to infer shape by precompute prune if possible. + # TODO: good to check inputs to be in params. + # to be enhanced when relay support list_input_names API of NNVM + logging.warning("Infering Reshape argument by precompute") + func = _expr.Function(ir_pass.free_vars(inputs[1]), inputs[1]) + with tvm.relay.build_config(opt_level=0): + graph, lib, params = tvm.relay.build(func, target="llvm", params=params) + ctx = tvm.context("llvm", 0) + from tvm.contrib import graph_runtime + m = graph_runtime.create(graph, lib, ctx) + m.set_input(**params) + m.run() + params_new = m.get_output(0) + inputs.pop(1) + out = _op.reshape(inputs[0], tuple(params_new.asnumpy().astype('int32').flatten())) return out @@ -477,10 +508,7 @@ class Shape(OnnxOpConverter): @classmethod def _impl_v1(cls, inputs, attr, params): - # Result of this operator is prominently used by reshape operator. - # Just pass the input as it is so that reshape_like can be used there. - logging.warning("Shape: Differently implemented in relay as a bypass (dummy operator)") - return inputs[0] + return _op.shape_of(inputs[0]) class Cast(OnnxOpConverter): """ Operator converter for Cast. @@ -494,7 +522,7 @@ def _impl_v1(cls, inputs, attr, params): def _impl_v5(cls, inputs, attr, params): try: from onnx.mapping import TENSOR_TYPE_TO_NP_TYPE - attr['to'] = TENSOR_TYPE_TO_NP_TYPE[attr['to']] + attr['to'] = str(TENSOR_TYPE_TO_NP_TYPE[attr['to']]) except ImportError as e: raise ImportError( "Unable to import onnx.mapping which is required {}".format(e)) @@ -674,6 +702,11 @@ class ReduceMean(Reduce): """ name = 'mean' +class ReduceProd(Reduce): + """ Operator converter for ArgMax. + """ + name = 'prod' + class ArgMax(OnnxOpConverter): """ Operator converter for ArgMax. """ @@ -818,7 +851,7 @@ def _get_convert_map(opset): # 'InstanceNormalization' # 'LpNormalization' 'Dropout': AttrCvt('dropout', {'ratio': 'rate'}, ignores=['is_test']), - 'Flatten': Renamer('flatten'), + 'Flatten': Renamer('batch_flatten'), 'LRN': LRN.get_converter(opset), # defs/reduction @@ -826,6 +859,7 @@ def _get_convert_map(opset): 'ReduceMin': ReduceMin.get_converter(opset), 'ReduceSum': ReduceSum.get_converter(opset), 'ReduceMean': ReduceMean.get_converter(opset), + 'ReduceProd': ReduceProd.get_converter(opset), # 'ReduceProd' # 'ReduceLogSumExp' 'ArgMax': ArgMax.get_converter(opset), @@ -842,8 +876,7 @@ def _get_convert_map(opset): 'Squeeze': AttrCvt('squeeze', {'axes': 'axis'}), 'Unsqueeze': Unsqueeze.get_converter(opset), 'Pad': Pad.get_converter(opset), - # TODO(zhreshold) Shape op is implemented as bypass op in relay - # 'Shape': Shape.get_converter(opset), + 'Shape': Shape.get_converter(opset), } @@ -883,6 +916,7 @@ def from_onnx(self, graph, opset): ---------- graph : onnx protobuf object The loaded onnx graph + opset : opset version Returns @@ -911,12 +945,12 @@ def from_onnx(self, graph, opset): dtype=self._params[i_name].dtype) else: self._num_input += 1 - shape = self._shape[i_name] if i_name in self._shape else () + tshape = self._shape[i_name] if i_name in self._shape else () if isinstance(self._dtype, dict): dtype = self._dtype[i_name] if i_name in self._dtype else d_type else: dtype = d_type - self._nodes[i_name] = new_var(i_name, shape=shape, dtype=dtype) + self._nodes[i_name] = new_var(i_name, shape=tshape, dtype=dtype) # construct nodes, nodes are stored as directed acyclic graph for node in graph.node: op_name = node.op_type @@ -936,6 +970,10 @@ def from_onnx(self, graph, opset): self._nodes[i_name] = new_var(node.output[0], shape=(), dtype=dtype) inputs.append(self._nodes[i_name]) + i_name = self._parse_value_proto(node) + attr['tvm_custom'] = {} + attr['tvm_custom']['name'] = i_name + op = self._convert_operator(op_name, inputs, attr, opset) node_output = self._fix_outputs(op_name, node.output) if not isinstance(op, _expr.TupleWrapper): diff --git a/python/tvm/relay/frontend/tensorflow.py b/python/tvm/relay/frontend/tensorflow.py index afeaee7e8f95..1b5318a83412 100644 --- a/python/tvm/relay/frontend/tensorflow.py +++ b/python/tvm/relay/frontend/tensorflow.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=import-self, invalid-name, unused-argument, too-many-lines, len-as-condition """TF: Tensorflow frontend.""" from __future__ import absolute_import as _abs @@ -543,25 +559,23 @@ def _impl(inputs, attr, params): op_name="reshape", extras={'newshape':tuple(shape_arg.asnumpy())}, ignores=['Tshape'])(inputs, attr) - except KeyError: + except AttributeError: # Shape operator is already pruned, hence # try to infer shape by precompute prune if possible. - if all(in_node in params for in_node in inputs[1].list_input_names()): - func = _expr.Function(ir_pass.free_vars(inputs[1]), inputs[1]) - with tvm.relay.build_config(opt_level=0): - graph, lib, params = tvm.relay.build(func, target="llvm", params=params) - ctx = tvm.context("llvm", 0) - from tvm.contrib import graph_runtime - m = graph_runtime.create(graph, lib, ctx) - m.set_input(**params) - m.run() - params_new = m.get_output(0) - inputs.pop(1) - return AttrCvt( - op_name="reshape", - extras={'newshape':tuple(params_new.asnumpy().flatten())}, - ignores=['Tshape'])(inputs, attr) - raise RuntimeError("Reshape with dynamic shape input not supported yet.") + func = _expr.Function(ir_pass.free_vars(inputs[1]), inputs[1]) + with tvm.relay.build_config(opt_level=0): + graph, lib, params = tvm.relay.build(func, target="llvm", params=params) + ctx = tvm.context("llvm", 0) + from tvm.contrib import graph_runtime + m = graph_runtime.create(graph, lib, ctx) + m.set_input(**params) + m.run() + params_new = m.get_output(0) + inputs.pop(1) + return AttrCvt( + op_name="reshape", + extras={'newshape':tuple(params_new.asnumpy().astype('int64').flatten())}, + ignores=['Tshape'])(inputs, attr) return _impl def _bias_add(): @@ -675,17 +689,20 @@ def _impl(inputs, attr, params): return _op.multiply(inputs[0], inputs[0]) return _impl -def _gather_v2(): - "Tensorflow now support only gatherv2" +def _gather(): + "GatherV2, Gather" def _impl(inputs, attr, params): - axis = params[inputs.pop(2).name_hint].asnumpy()[0] + + axis = 0 + if len(inputs) > 2: + axis = params[inputs.pop(2).name_hint].asnumpy()[0] new_input = [] new_input.append(inputs.pop(0)) new_input.append(inputs.pop(0)) - return AttrCvt(op_name="take", - extras={'axis': tvm.const(axis, 'int32')}, - ignores=['Tindices', 'Tparams', 'validate_indices', \ - 'Taxis', '_class'])(new_input, attr) + return AttrCvt(op_name="take", + extras={'axis': tvm.const(axis, 'int32')}, + ignores=['Tindices', 'Tparams', 'validate_indices', \ + 'Taxis', '_class'])(new_input, attr) return _impl def _infer_out_shapes(inputs, params): @@ -817,7 +834,6 @@ def _impl(inputs, attr, params): ignores=['Tpaddings'],)(new_inputs, attr) return _impl - def _transpose(): def _impl(inputs, attr, params): # If perm is not specified, axes is left empty, @@ -830,6 +846,11 @@ def _impl(inputs, attr, params): return _op.transpose(inputs[0], axes=axes) return _impl +def _where(): + def _impl(inputs, attr, params): + return AttrCvt(op_name="where")(inputs, attr) + return _impl + def _rank(): def _impl(inputs, attr, params): input_shape = attr['_input_shapes'][inputs[0]] @@ -1014,8 +1035,10 @@ def _impl(inputs, attr, params): 'DepthwiseConv2dNative' : _conv('depthwise'), 'Shape' : _shape(), 'Sigmoid' : AttrCvt('sigmoid'), + 'Select' : _where(), 'Fill' : _fill(), - 'GatherV2' : _gather_v2(), + 'GatherV2' : _gather(), + 'Gather' : _gather(), 'StridedSlice' : _stridedSlice(), 'LRN' : _lrn(), 'Pad' : _pad('Pad'), diff --git a/python/tvm/relay/frontend/tensorflow_parser.py b/python/tvm/relay/frontend/tensorflow_parser.py index 04c232b6d577..a9be162f2074 100644 --- a/python/tvm/relay/frontend/tensorflow_parser.py +++ b/python/tvm/relay/frontend/tensorflow_parser.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """TF: Tensorflow parser""" from __future__ import absolute_import as _abs from __future__ import print_function diff --git a/python/tvm/relay/frontend/tflite.py b/python/tvm/relay/frontend/tflite.py index 0e31500fe67d..2225d6c82f8d 100644 --- a/python/tvm/relay/frontend/tflite.py +++ b/python/tvm/relay/frontend/tflite.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-argument """Tensorflow lite frontend.""" from __future__ import absolute_import as _abs @@ -46,7 +62,8 @@ def __init__(self, model, subgraph, exp_tab): 'SOFTMAX': self.convert_softmax, 'SQUEEZE': self.convert_squeeze, 'MAX_POOL_2D': self.convert_max_pool2d, - "CONCATENATION": self.convert_concatenation + 'CONCATENATION': self.convert_concatenation, + 'ADD': self.convert_add } def check_unsupported_ops(self): @@ -292,6 +309,49 @@ def convert_concatenation(self, op): out = self.convert_fused_activation_function(out, fused_activation_fn) return out + def convert_add(self, op): + """Convert TFLite add""" + try: + from tflite.Operator import Operator + except ImportError: + raise ImportError("The tflite package must be installed") + + assert isinstance(op, Operator) + input_tensors = self.get_input_tensors(op) + assert len(input_tensors) == 2, "input tensors length should be 2" + + lhs_tensor = input_tensors[0] + lhs_expr = self.get_expr(lhs_tensor.tensor_idx) + + rhs_tensor = input_tensors[1] + if self.has_expr(rhs_tensor.tensor_idx): + # In most cases, we can assume that TOCO fuses ADD operators + # with constants - it means both will be tensors. + rhs_expr = self.get_expr(rhs_tensor.tensor_idx) + else: + # However, in some corner cases, the ADD operator is not fused, + # we can receive as constant. + rhs_type_str = self.get_tensor_type_str(rhs_tensor.tensor.Type()) + rhs_expr = self.exp_tab.new_const(self.get_tensor_value(rhs_tensor), + dtype=rhs_type_str) + + # In this case, we have to be careful about formatting. + input_shape_length = len(rhs_tensor.tensor.ShapeAsNumpy()) + if input_shape_length in (1, 2): + pass + elif input_shape_length == 3: + # N H*W C to N C H*W + rhs_expr = _op.transpose(rhs_expr, axes=(0, 2, 1)) + elif input_shape_length == 4: + # N H W C to N C H W + rhs_expr = _op.transpose(rhs_expr, axes=(0, 3, 1, 2)) + else: + msg = 'Input shape length {} for operator ADD is not valid.' + raise tvm.error.OpAttributeInvalid(msg.format(input_shape_length)) + + out = _op.add(lhs_expr, rhs_expr) + return out + def convert_squeeze(self, op): """Convert TFLite squeeze""" try: @@ -554,6 +614,9 @@ def convert_pool2d(self, op, pool_type): def get_expr(self, input_tensor_idx): return self.exp_tab.get_expr(get_tensor_name(self.subgraph, input_tensor_idx)) + def has_expr(self, input_tensor_idx): + return self.exp_tab.has_expr(get_tensor_name(self.subgraph, input_tensor_idx)) + def build_str_map(obj): """Build string map of TFLite enum int value diff --git a/python/tvm/relay/grammar/Relay.g4 b/python/tvm/relay/grammar/Relay.g4 index 0a2206265502..58546439e1ce 100644 --- a/python/tvm/relay/grammar/Relay.g4 +++ b/python/tvm/relay/grammar/Relay.g4 @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + grammar Relay; SEMVER: 'v0.0.1' ; diff --git a/python/tvm/relay/image.py b/python/tvm/relay/image.py index 90bb87d71c2e..4d5cc5a47448 100644 --- a/python/tvm/relay/image.py +++ b/python/tvm/relay/image.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=wildcard-import, unused-import, unused-wildcard-import """Image network related operators.""" # Re-export in a specific file name so that autodoc can pick it up diff --git a/python/tvm/relay/ir_pass.py b/python/tvm/relay/ir_pass.py index f3f8fea97412..8eb0adc3da1a 100644 --- a/python/tvm/relay/ir_pass.py +++ b/python/tvm/relay/ir_pass.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=no-else-return # pylint: disable=unidiomatic-typecheck """ diff --git a/python/tvm/relay/module.py b/python/tvm/relay/module.py index ef496333d828..3eb287c90040 100644 --- a/python/tvm/relay/module.py +++ b/python/tvm/relay/module.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=no-else-return, unidiomatic-typecheck, undefined-variable, wildcard-import """A global module storing everything needed to interpret or compile a Relay program.""" from .base import register_relay_node, RelayNode diff --git a/python/tvm/relay/nn.py b/python/tvm/relay/nn.py index 6f45aea8b544..2070eb9181e6 100644 --- a/python/tvm/relay/nn.py +++ b/python/tvm/relay/nn.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=wildcard-import, unused-import, unused-wildcard-import """Neural network related operators.""" # Re-export in a specific file name so that autodoc can pick it up diff --git a/python/tvm/relay/op/__init__.py b/python/tvm/relay/op/__init__.py index 9dd2bf88c934..fdc990ea6410 100644 --- a/python/tvm/relay/op/__init__.py +++ b/python/tvm/relay/op/__init__.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. #pylint: disable=wildcard-import, redefined-builtin """Relay core operators.""" # operator defs diff --git a/python/tvm/relay/op/_make.py b/python/tvm/relay/op/_make.py index 79c86cbb0254..d51fee717804 100644 --- a/python/tvm/relay/op/_make.py +++ b/python/tvm/relay/op/_make.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Constructor APIs""" from ..._ffi.function import _init_api diff --git a/python/tvm/relay/op/_reduce.py b/python/tvm/relay/op/_reduce.py index 5c720256bbd6..b97e3a8ce993 100644 --- a/python/tvm/relay/op/_reduce.py +++ b/python/tvm/relay/op/_reduce.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Backend compiler related feature registration""" from __future__ import absolute_import diff --git a/python/tvm/relay/op/_tensor.py b/python/tvm/relay/op/_tensor.py index 05d9acb27330..ef34ae9af8c8 100644 --- a/python/tvm/relay/op/_tensor.py +++ b/python/tvm/relay/op/_tensor.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. #pylint: disable=invalid-name, unused-argument """Backend compiler related feature registration""" from __future__ import absolute_import diff --git a/python/tvm/relay/op/_tensor_grad.py b/python/tvm/relay/op/_tensor_grad.py index 173e97a00496..158b2dc2ee4f 100644 --- a/python/tvm/relay/op/_tensor_grad.py +++ b/python/tvm/relay/op/_tensor_grad.py @@ -1,9 +1,25 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. #pylint: disable=invalid-name, unused-argument """Backend compiler related feature registration""" from __future__ import absolute_import from ..expr import const from .op import register_gradient -from .transform import collapse_sum_like, where +from .transform import collapse_sum_like, broadcast_to_like, where from .tensor import exp, negative, power, less from .tensor import zeros_like, ones_like @@ -77,3 +93,20 @@ def divide_grad(orig, grad): x, y = orig.args return [collapse_sum_like(grad / y, x), collapse_sum_like(- (grad * orig / y), y)] + + +@register_gradient("zeros_like") +def zeros_like_grad(orig, grad): + """Returns [0]""" + return [orig] + +@register_gradient("ones_like") +def ones_like_grad(orig, grad): + """Returns [0]""" + return [zeros_like(orig.args[0])] + +@register_gradient("collapse_sum_like") +def collapse_sum_like_grad(orig, grad): + """Returns [broadcast_to_like(grad, x), 0]""" + x, y = orig.args + return [broadcast_to_like(grad, x), zeros_like(y)] diff --git a/python/tvm/relay/op/_transform.py b/python/tvm/relay/op/_transform.py index 72fbca967555..2eec6d03e7cd 100644 --- a/python/tvm/relay/op/_transform.py +++ b/python/tvm/relay/op/_transform.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Backend compiler related feature registration""" # pylint: disable=invalid-name,unused-argument from __future__ import absolute_import @@ -32,6 +48,7 @@ _reg.register_schedule("stack", schedule_injective) _reg.register_schedule("concatenate", schedule_injective) _reg.register_schedule("_contrib_reverse_reshape", schedule_injective) +_reg.register_schedule("gather_nd", schedule_injective) # layout_transform _reg.register_schedule("layout_transform", schedule_injective) diff --git a/python/tvm/relay/op/annotation/__init__.py b/python/tvm/relay/op/annotation/__init__.py index 39d464db9ee3..366c5617092a 100644 --- a/python/tvm/relay/op/annotation/__init__.py +++ b/python/tvm/relay/op/annotation/__init__.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=wildcard-import """Annotation related operators.""" from __future__ import absolute_import as _abs diff --git a/python/tvm/relay/op/annotation/_make.py b/python/tvm/relay/op/annotation/_make.py index abbfffb71616..ae909eb8af3c 100644 --- a/python/tvm/relay/op/annotation/_make.py +++ b/python/tvm/relay/op/annotation/_make.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Constructor APIs""" from ...._ffi.function import _init_api diff --git a/python/tvm/relay/op/annotation/annotation.py b/python/tvm/relay/op/annotation/annotation.py index 8b11bfde7fe7..10c898538596 100644 --- a/python/tvm/relay/op/annotation/annotation.py +++ b/python/tvm/relay/op/annotation/annotation.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Annotation operations.""" from __future__ import absolute_import as _abs from . import _make diff --git a/python/tvm/relay/op/image/__init__.py b/python/tvm/relay/op/image/__init__.py index 5fa5c01575e0..4483bd7ac1bc 100644 --- a/python/tvm/relay/op/image/__init__.py +++ b/python/tvm/relay/op/image/__init__.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=wildcard-import """Image network related operators.""" from __future__ import absolute_import as _abs diff --git a/python/tvm/relay/op/image/_image.py b/python/tvm/relay/op/image/_image.py index e44748372374..cd0df3388b44 100644 --- a/python/tvm/relay/op/image/_image.py +++ b/python/tvm/relay/op/image/_image.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. #pylint: disable=invalid-name, unused-argument """Backend compiler related feature registration""" from __future__ import absolute_import diff --git a/python/tvm/relay/op/image/_make.py b/python/tvm/relay/op/image/_make.py index 1198258553fe..747684b63ed4 100644 --- a/python/tvm/relay/op/image/_make.py +++ b/python/tvm/relay/op/image/_make.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Constructor APIs""" from ...._ffi.function import _init_api diff --git a/python/tvm/relay/op/image/image.py b/python/tvm/relay/op/image/image.py index 36c8dd5fa548..2861bd51fcde 100644 --- a/python/tvm/relay/op/image/image.py +++ b/python/tvm/relay/op/image/image.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Image operations.""" from __future__ import absolute_import as _abs from . import _make diff --git a/python/tvm/relay/op/nn/__init__.py b/python/tvm/relay/op/nn/__init__.py index 0c2a0a4358c9..ebabbbcd9d3a 100644 --- a/python/tvm/relay/op/nn/__init__.py +++ b/python/tvm/relay/op/nn/__init__.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=wildcard-import """Neural network related operators.""" from __future__ import absolute_import as _abs diff --git a/python/tvm/relay/op/nn/_make.py b/python/tvm/relay/op/nn/_make.py index c4922ea8ab04..72496859d918 100644 --- a/python/tvm/relay/op/nn/_make.py +++ b/python/tvm/relay/op/nn/_make.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Constructor APIs""" from ...._ffi.function import _init_api diff --git a/python/tvm/relay/op/nn/_nn.py b/python/tvm/relay/op/nn/_nn.py index da58e9386c0f..5a47b1d42ed3 100644 --- a/python/tvm/relay/op/nn/_nn.py +++ b/python/tvm/relay/op/nn/_nn.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. #pylint: disable=invalid-name, unused-argument """Backend compiler related feature registration""" from __future__ import absolute_import @@ -426,3 +442,26 @@ def schedule_contrib_depthwise_conv2d_NCHWc(attrs, outs, target): reg.register_pattern("nn.contrib_depthwise_conv2d_NCHWc", OpPattern.OUT_ELEMWISE_FUSABLE) + +@reg.register_compute("nn.deformable_conv2d") +def compute_deformable_conv2d(attrs, inputs, out_dtype, target): + """Compute definition of deformable_conv2d""" + padding = get_const_tuple(attrs.padding) + strides = get_const_tuple(attrs.strides) + dilation = get_const_tuple(attrs.dilation) + deformable_groups = attrs.deformable_groups + groups = attrs.groups + out_dtype = attrs.out_dtype + out_dtype = inputs[0].dtype if out_dtype in ("same", "") else out_dtype + with target: + out = topi.nn.deformable_conv2d_nchw(inputs[0], inputs[1], inputs[2], strides, padding, + dilation, deformable_groups, groups, out_dtype) + return [out] + +@reg.register_schedule("nn.deformable_conv2d") +def schedule_deformable_conv2d(attrs, outs, target): + """Schedule definition of deformable_conv2d""" + with target: + return topi.generic.schedule_deformable_conv2d_nchw(outs) + +reg.register_pattern("nn.deformable_conv2d", OpPattern.OUT_ELEMWISE_FUSABLE) diff --git a/python/tvm/relay/op/nn/nn.py b/python/tvm/relay/op/nn/nn.py index 1a9e02a08c98..2d13f53f17fd 100644 --- a/python/tvm/relay/op/nn/nn.py +++ b/python/tvm/relay/op/nn/nn.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. #pylint: disable=invalid-name, too-many-lines """Neural network operations.""" from __future__ import absolute_import as _abs @@ -1105,3 +1121,76 @@ def contrib_conv2d_winograd_nnpack_weight_transform(weight, """ return _make.contrib_conv2d_winograd_nnpack_weight_transform( weight, convolution_algorithm, out_dtype) + + +def deformable_conv2d(data, + offset, + weight, + strides=(1, 1), + padding=(0, 0), + dilation=(1, 1), + deformable_groups=1, + groups=1, + channels=None, + kernel_size=None, + data_layout='NCHW', + kernel_layout='OIHW', + out_layout='', + out_dtype=''): + r""" Deformable 2d convolution. + + The deformable convolution operation is described in https://arxiv.org/abs/1703.06211 + + Parameters + ---------- + data : tvm.relay.Expr + The input data to the operator. + + offset : tvm.relay.Expr + The offset expressions. + + weight : tvm.relay.Expr + The weight expressions. + + strides : tuple of int, optional + The strides of convoltution. + + padding : tuple of int, optional + The padding of convolution on both sides of inputs before convolution. + + dilation : tuple of int, optional + Specifies the dilation rate to be used for dilated convolution. + + deformable_groups : int, optional + Number of deformable groups. + + groups : int, optional + Number of groups for grouped convolution. + + channels : int, optional + Number of output channels of this convolution. + + kernel_size : tuple of int, optional + The spatial of the convolution kernel. + + data_layout : str, optional + Layout of the input. + + kernel_layout : str, optional + Layout of the weight. + + out_layout : str, optional + Layout of the output, by default, out_layout is the same as data_layout + + out_dtype : str, optional + Specifies the output data type for mixed precision conv2d. + + Returns + ------- + result : tvm.relay.Expr + The computed result. + + """ + return _make.deformable_conv2d(data, offset, weight, strides, padding, dilation, + deformable_groups, groups, channels, kernel_size, data_layout, + kernel_layout, out_layout, out_dtype) diff --git a/python/tvm/relay/op/op.py b/python/tvm/relay/op/op.py index 37f1fc1ee2b5..6312f023df0d 100644 --- a/python/tvm/relay/op/op.py +++ b/python/tvm/relay/op/op.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. #pylint: disable=unused-argument """The base node types for the Relay language.""" import topi diff --git a/python/tvm/relay/op/op_attrs.py b/python/tvm/relay/op/op_attrs.py index 5f9b38a56aa6..abaa0e4c5d4f 100644 --- a/python/tvm/relay/op/op_attrs.py +++ b/python/tvm/relay/op/op_attrs.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """The attributes node used for Relay operators""" from ...attrs import Attrs diff --git a/python/tvm/relay/op/reduce.py b/python/tvm/relay/op/reduce.py index a4d5f66c009d..9d58a92041f3 100644 --- a/python/tvm/relay/op/reduce.py +++ b/python/tvm/relay/op/reduce.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Reduce operators.""" # pylint: disable=redefined-builtin diff --git a/python/tvm/relay/op/tensor.py b/python/tvm/relay/op/tensor.py index d51208d478aa..eef4ec9c5e48 100644 --- a/python/tvm/relay/op/tensor.py +++ b/python/tvm/relay/op/tensor.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Basic tensor operations.""" # pylint: disable=redefined-builtin from __future__ import absolute_import as _abs diff --git a/python/tvm/relay/op/transform.py b/python/tvm/relay/op/transform.py index 37aace5afe4a..5489ad1e2659 100644 --- a/python/tvm/relay/op/transform.py +++ b/python/tvm/relay/op/transform.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Transform operators.""" from . import _make @@ -186,7 +202,7 @@ def reshape_like(data, shape_like): return _make.reshape_like(data, shape_like) -def take(data, indices, axis=None): +def take(data, indices, axis=None, mode="clip"): """Take elements from an array along an axis. Parameters @@ -201,12 +217,17 @@ def take(data, indices, axis=None): The axis over which to select values. By default, the flattened input array is used. + mode : str, optional + Specifies how out-of-bound indices will behave. + clip - clip to the range (default) + wrap - wrap around the indices + Returns ------- ret : relay.Expr The computed result. """ - return _make.take(data, indices, axis) + return _make.take(data, indices, axis, mode) def full(fill_value, shape=(), dtype=""): @@ -646,3 +667,36 @@ def reverse_reshape(data, newshape): if isinstance(newshape, int): newshape = [newshape] return _make._contrib_reverse_reshape(data, list(newshape)) + + +def gather_nd(data, indices): + """Gather elements or slices from data and store to a tensor whose shape is + defined by indices. + + Parameters + ---------- + data : relay.Expr + The input data to the operator. + + indices : relay.Expr + The shape of output tensor. + + Returns + ------- + ret : relay.Expr + The computed result. + + Examples + -------- + .. code-block:: python + + data = [[0, 1], [2, 3]] + indices = [[1, 1, 0], [0, 1, 0]] + relay.gather_nd(data, indices) = [2, 3, 0] + + data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] + indices = [[0, 1], [1, 0]] + relay.gather_nd(data, indices) = [[3, 4], [5, 6]] + """ + + return _make.gather_nd(data, indices) diff --git a/python/tvm/relay/op/vision/__init__.py b/python/tvm/relay/op/vision/__init__.py index 0cee4e4faeec..da06ca65fbae 100644 --- a/python/tvm/relay/op/vision/__init__.py +++ b/python/tvm/relay/op/vision/__init__.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=wildcard-import """Vision network related operators.""" from __future__ import absolute_import as _abs diff --git a/python/tvm/relay/op/vision/_make.py b/python/tvm/relay/op/vision/_make.py index 614d42f47176..f0e31709194d 100644 --- a/python/tvm/relay/op/vision/_make.py +++ b/python/tvm/relay/op/vision/_make.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Constructor APIs""" from ...._ffi.function import _init_api diff --git a/python/tvm/relay/op/vision/_rcnn.py b/python/tvm/relay/op/vision/_rcnn.py index fa98c4fb4a9e..f35283961b27 100644 --- a/python/tvm/relay/op/vision/_rcnn.py +++ b/python/tvm/relay/op/vision/_rcnn.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-argument """Faster R-CNN and Mask R-CNN operations.""" import topi diff --git a/python/tvm/relay/op/vision/_vision.py b/python/tvm/relay/op/vision/_vision.py index c887076e6af8..bcf7e066ad15 100644 --- a/python/tvm/relay/op/vision/_vision.py +++ b/python/tvm/relay/op/vision/_vision.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-argument """Definition of vision ops""" from __future__ import absolute_import diff --git a/python/tvm/relay/op/vision/_yolo.py b/python/tvm/relay/op/vision/_yolo.py index 749ebfa26dd0..32fc62d5c23a 100644 --- a/python/tvm/relay/op/vision/_yolo.py +++ b/python/tvm/relay/op/vision/_yolo.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. #pylint: disable=invalid-name, unused-argument """Backend compiler related feature registration""" from __future__ import absolute_import diff --git a/python/tvm/relay/op/vision/multibox.py b/python/tvm/relay/op/vision/multibox.py index 90591da925f5..065a3e7c7f0c 100644 --- a/python/tvm/relay/op/vision/multibox.py +++ b/python/tvm/relay/op/vision/multibox.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Multibox operations.""" from __future__ import absolute_import as _abs from . import _make diff --git a/python/tvm/relay/op/vision/nms.py b/python/tvm/relay/op/vision/nms.py index 0124ee29ab9e..b8f9bf1b6782 100644 --- a/python/tvm/relay/op/vision/nms.py +++ b/python/tvm/relay/op/vision/nms.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Non-maximum suppression operations.""" from __future__ import absolute_import as _abs from . import _make diff --git a/python/tvm/relay/op/vision/rcnn.py b/python/tvm/relay/op/vision/rcnn.py index afb17163057f..d160228d300a 100644 --- a/python/tvm/relay/op/vision/rcnn.py +++ b/python/tvm/relay/op/vision/rcnn.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Faster R-CNN and Mask R-CNN operations.""" from . import _make diff --git a/python/tvm/relay/op/vision/yolo.py b/python/tvm/relay/op/vision/yolo.py index 71b7918dca0f..7ecf64cf21a0 100644 --- a/python/tvm/relay/op/vision/yolo.py +++ b/python/tvm/relay/op/vision/yolo.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Yolo operations.""" from . import _make diff --git a/python/tvm/relay/param_dict.py b/python/tvm/relay/param_dict.py index f7647beadeb2..4c3f6d142369 100644 --- a/python/tvm/relay/param_dict.py +++ b/python/tvm/relay/param_dict.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Helper utility to save parameter dicts.""" import tvm diff --git a/python/tvm/relay/parser.py b/python/tvm/relay/parser.py index ba0b1aac063e..2d27b7b53f89 100644 --- a/python/tvm/relay/parser.py +++ b/python/tvm/relay/parser.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """A parser for Relay's text format.""" from __future__ import absolute_import from .. import register_func diff --git a/python/tvm/relay/prelude.py b/python/tvm/relay/prelude.py index 6cf104ab388a..ff823c3413fa 100644 --- a/python/tvm/relay/prelude.py +++ b/python/tvm/relay/prelude.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=no-else-return, unidiomatic-typecheck, invalid-name """Adds certain standard global functions and ADT definitions to the module.""" from .ty import GlobalTypeVar, TypeVar, FuncType, TupleType, scalar_type @@ -142,6 +158,29 @@ def define_list_foldr(self): self.mod[self.foldr] = Function([f, bv, av], Match(av, [nil_case, cons_case]), b, [a, b]) + def define_list_foldr1(self): + """Defines a right-way fold over a nonempty list. + + foldr1(f, l) : fn(fn(a, a) -> a, list[a]) -> a + + foldr1(f, cons(a1, cons(a2, cons(..., cons(an, nil))))) + evalutes to f(a1, f(a2, f(..., f(an-1, an)))...) + """ + self.foldr1 = GlobalVar("foldr1") + a = TypeVar("a") + f = Var("f", FuncType([a, a], a)) + av = Var("av", self.l(a)) + x = Var("x") + y = Var("y") + z = Var("z") + one_case = Clause(PatternConstructor(self.cons, + [PatternVar(x), PatternConstructor(self.nil)]), x) + cons_case = Clause(PatternConstructor(self.cons, [PatternVar(y), PatternVar(z)]), + f(y, self.foldr1(f, z))) + self.mod[self.foldr1] = Function([f, av], + Match(av, [one_case, cons_case]), a, [a]) + + def define_list_concat(self): """Defines a function that concatenates two lists. @@ -471,6 +510,7 @@ def __init__(self, mod): self.define_list_map() self.define_list_foldl() self.define_list_foldr() + self.define_list_foldr1() self.define_list_concat() self.define_list_filter() self.define_list_zip() diff --git a/python/tvm/relay/quantize/__init__.py b/python/tvm/relay/quantize/__init__.py index bdb87b55518b..45bb62e66853 100644 --- a/python/tvm/relay/quantize/__init__.py +++ b/python/tvm/relay/quantize/__init__.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. #pylint: disable=wildcard-import, redefined-builtin """Automatic quantization utilities.""" from __future__ import absolute_import as _abs diff --git a/python/tvm/relay/quantize/_annotate.py b/python/tvm/relay/quantize/_annotate.py index 08d56a3ca23f..2fe1cb81675b 100644 --- a/python/tvm/relay/quantize/_annotate.py +++ b/python/tvm/relay/quantize/_annotate.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. #pylint: disable=unused-argument """Internal module for registering attribute for annotation.""" from __future__ import absolute_import @@ -253,11 +269,10 @@ def concatenate_rewrite(ref_call, new_args, ctx): # make sure the inputs of concatenate are all normal # expression or annotate expression - if kind_list[0] is None: - for k in kind_list: - assert k is None + if all([k is None for k in kind_list]): return None - for k in kind_list: - assert k is not None + for i, k in enumerate(kind_list): + if k is None: + expr_list[i] = attach_simulated_quantize(expr_list[i], QAnnotateKind.ACTIVATION) expr = _forward_op(ref_call, [_expr.Tuple(expr_list)]) return QAnnotateExpr(expr, QAnnotateKind.ACTIVATION) diff --git a/python/tvm/relay/quantize/_quantize.py b/python/tvm/relay/quantize/_quantize.py index 32f67cdc3d85..6f5c75f7b418 100644 --- a/python/tvm/relay/quantize/_quantize.py +++ b/python/tvm/relay/quantize/_quantize.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. #pylint: disable=unused-argument """Internal module for quantization.""" from __future__ import absolute_import diff --git a/python/tvm/relay/quantize/quantize.py b/python/tvm/relay/quantize/quantize.py index 56e0f586fc1f..607ee1821c86 100644 --- a/python/tvm/relay/quantize/quantize.py +++ b/python/tvm/relay/quantize/quantize.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. #pylint: disable=unused-argument """Automatic quantization toolkit.""" from __future__ import absolute_import diff --git a/python/tvm/relay/scope_builder.py b/python/tvm/relay/scope_builder.py index 074a4aa66c81..337044098cd5 100644 --- a/python/tvm/relay/scope_builder.py +++ b/python/tvm/relay/scope_builder.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """The scope builder interface """ from __future__ import absolute_import diff --git a/python/tvm/relay/testing/__init__.py b/python/tvm/relay/testing/__init__.py index aa4c1dbb8742..b4a8394e2659 100644 --- a/python/tvm/relay/testing/__init__.py +++ b/python/tvm/relay/testing/__init__.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Utilities for testing and benchmarks""" from __future__ import absolute_import as _abs diff --git a/python/tvm/relay/testing/config.py b/python/tvm/relay/testing/config.py index 677b72d979a1..68756e0a270f 100644 --- a/python/tvm/relay/testing/config.py +++ b/python/tvm/relay/testing/config.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Configuration about tests""" from __future__ import absolute_import as _abs diff --git a/python/tvm/relay/testing/dcgan.py b/python/tvm/relay/testing/dcgan.py index d6c1d55df01a..4ee0bd13a5a7 100644 --- a/python/tvm/relay/testing/dcgan.py +++ b/python/tvm/relay/testing/dcgan.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=unused-argument """ Net of the generator of DCGAN diff --git a/python/tvm/relay/testing/densenet.py b/python/tvm/relay/testing/densenet.py index 7abebc75ecee..de3ebe36eb7b 100644 --- a/python/tvm/relay/testing/densenet.py +++ b/python/tvm/relay/testing/densenet.py @@ -1,123 +1,123 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -# pylint: disable=invalid-name, line-too-long -""" -Port of MxNet version of Densenet to Relay. -https://github.com/apache/incubator-mxnet/blob/master/python/mxnet/gluon/model_zoo/vision/densenet.py -""" -# pylint: enable=line-too-long -from tvm import relay -from . import layers -from .init import create_workload - -def _make_dense_layer(data, growth_rate, bn_size, index): - """Single densenet layer.""" - bn1 = layers.batch_norm_infer(data, name="batch_1_%s" % index) - relu1 = relay.nn.relu(bn1) - conv1 = layers.conv2d(relu1, channels=bn_size * growth_rate, - kernel_size=(1, 1), name="conv2d_1_%s" % index) - bn2 = layers.batch_norm_infer(conv1, name="batch_2_" + index) - relu2 = relay.nn.relu(bn2) - conv2 = layers.conv2d(relu2, channels=growth_rate, kernel_size=(3, 3), - padding=(1, 1), name="conv2d_2_%s" % index) - return conv2 - -def _make_dense_block(data, num_layers, bn_size, growth_rate, index): - """Makes a block of dense layers of the specified size.""" - layer_out = data - for i in range(num_layers): - layer_out = _make_dense_layer(layer_out, growth_rate, bn_size, - "(%s, %s)" % (index, i)) - return layer_out - -def _make_transition(data, num_output_features, index): - """Transition between layers.""" - bn = layers.batch_norm_infer(data, name="batch_t_%s" % index) - relu = relay.nn.relu(bn) - conv = layers.conv2d(relu, channels=num_output_features, - kernel_size=(1, 1), name="conv_t_%s" % index) - return relay.nn.avg_pool2d(conv, pool_size=(2, 2), strides=(2, 2)) - -def _make_dense_net(num_init_features, growth_rate, block_config, - data_shape, data_dtype, bn_size=4, classes=1000): - """Builds up a densenet.""" - data = relay.Var("data", relay.TensorType(data_shape, data_dtype)) # (bn_size, 3, 224, 224))) - conv1 = layers.conv2d(data, channels=num_init_features, - kernel_size=(7, 7), strides=(2, 2), padding=(3, 3), - name='conv1') - bn1 = layers.batch_norm_infer(conv1, name='batch1') - relu1 = relay.nn.relu(bn1) - mp = relay.nn.max_pool2d(relu1, pool_size=(3, 3), strides=(2, 2), padding=(1, 1)) - - num_features = num_init_features - layer_out = mp - for i, num_layers in enumerate(block_config): - layer_out = _make_dense_block(layer_out, num_layers, growth_rate, bn_size, i) - num_features = num_features + num_layers*growth_rate - if i != len(block_config) - 1: - layer_out = _make_transition(layer_out, num_features // 2, i) - num_features = num_features // 2 - bn2 = layers.batch_norm_infer(layer_out, name='batch2') - relu2 = relay.nn.relu(bn2) - avg = relay.nn.avg_pool2d(relu2, pool_size=(7, 7)) - flat = relay.nn.batch_flatten(avg) - - ret = layers.dense_add_bias(flat, units=classes, name='dense') - - return relay.Function(relay.ir_pass.free_vars(ret), ret) - -def get_workload(densenet_size=121, classes=1000, batch_size=4, - image_shape=(3, 224, 224), dtype='float32'): - """Gets benchmark workload for densenet. - - Parameters - ---------- - densenet_size : int, optional (default 121) - Parameter for the network size. The supported sizes - are 121, 161, 169, and 201. - - classes : int, optional (default 1000) - The number of classes. - - batch_size : int, optional (detault 4) - The batch size for the network. - - image_shape : shape, optional (default (3, 224, 224)) - The shape of the input data. - - dtype : data type, optional (default 'float32') - The data type of the input data. - - Returns - ------- - net: relay.Function - The computation graph representing densenet. - - params : dict of str to NDArray - The benchmark paraeters. - """ - specs = {121: (64, 32, [6, 12, 24, 16]), - 161: (96, 48, [6, 12, 36, 24]), - 169: (69, 32, [6, 12, 32, 32]), - 201: (64, 32, [6, 12, 48, 32])} - - num_init_features, growth_rate, block_config = specs[densenet_size] - data_shape = tuple([batch_size] + list(image_shape)) - net = _make_dense_net(num_init_features, growth_rate, block_config, - data_shape, dtype, batch_size, classes) - return create_workload(net) +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# pylint: disable=invalid-name, line-too-long +""" +Port of MxNet version of Densenet to Relay. +https://github.com/apache/incubator-mxnet/blob/master/python/mxnet/gluon/model_zoo/vision/densenet.py +""" +# pylint: enable=line-too-long +from tvm import relay +from . import layers +from .init import create_workload + +def _make_dense_layer(data, growth_rate, bn_size, index): + """Single densenet layer.""" + bn1 = layers.batch_norm_infer(data, name="batch_1_%s" % index) + relu1 = relay.nn.relu(bn1) + conv1 = layers.conv2d(relu1, channels=bn_size * growth_rate, + kernel_size=(1, 1), name="conv2d_1_%s" % index) + bn2 = layers.batch_norm_infer(conv1, name="batch_2_" + index) + relu2 = relay.nn.relu(bn2) + conv2 = layers.conv2d(relu2, channels=growth_rate, kernel_size=(3, 3), + padding=(1, 1), name="conv2d_2_%s" % index) + return conv2 + +def _make_dense_block(data, num_layers, bn_size, growth_rate, index): + """Makes a block of dense layers of the specified size.""" + layer_out = data + for i in range(num_layers): + layer_out = _make_dense_layer(layer_out, growth_rate, bn_size, + "(%s, %s)" % (index, i)) + return layer_out + +def _make_transition(data, num_output_features, index): + """Transition between layers.""" + bn = layers.batch_norm_infer(data, name="batch_t_%s" % index) + relu = relay.nn.relu(bn) + conv = layers.conv2d(relu, channels=num_output_features, + kernel_size=(1, 1), name="conv_t_%s" % index) + return relay.nn.avg_pool2d(conv, pool_size=(2, 2), strides=(2, 2)) + +def _make_dense_net(num_init_features, growth_rate, block_config, + data_shape, data_dtype, bn_size=4, classes=1000): + """Builds up a densenet.""" + data = relay.Var("data", relay.TensorType(data_shape, data_dtype)) # (bn_size, 3, 224, 224))) + conv1 = layers.conv2d(data, channels=num_init_features, + kernel_size=(7, 7), strides=(2, 2), padding=(3, 3), + name='conv1') + bn1 = layers.batch_norm_infer(conv1, name='batch1') + relu1 = relay.nn.relu(bn1) + mp = relay.nn.max_pool2d(relu1, pool_size=(3, 3), strides=(2, 2), padding=(1, 1)) + + num_features = num_init_features + layer_out = mp + for i, num_layers in enumerate(block_config): + layer_out = _make_dense_block(layer_out, num_layers, growth_rate, bn_size, i) + num_features = num_features + num_layers*growth_rate + if i != len(block_config) - 1: + layer_out = _make_transition(layer_out, num_features // 2, i) + num_features = num_features // 2 + bn2 = layers.batch_norm_infer(layer_out, name='batch2') + relu2 = relay.nn.relu(bn2) + avg = relay.nn.avg_pool2d(relu2, pool_size=(7, 7)) + flat = relay.nn.batch_flatten(avg) + + ret = layers.dense_add_bias(flat, units=classes, name='dense') + + return relay.Function(relay.ir_pass.free_vars(ret), ret) + +def get_workload(densenet_size=121, classes=1000, batch_size=4, + image_shape=(3, 224, 224), dtype='float32'): + """Gets benchmark workload for densenet. + + Parameters + ---------- + densenet_size : int, optional (default 121) + Parameter for the network size. The supported sizes + are 121, 161, 169, and 201. + + classes : int, optional (default 1000) + The number of classes. + + batch_size : int, optional (detault 4) + The batch size for the network. + + image_shape : shape, optional (default (3, 224, 224)) + The shape of the input data. + + dtype : data type, optional (default 'float32') + The data type of the input data. + + Returns + ------- + net: relay.Function + The computation graph representing densenet. + + params : dict of str to NDArray + The benchmark paraeters. + """ + specs = {121: (64, 32, [6, 12, 24, 16]), + 161: (96, 48, [6, 12, 36, 24]), + 169: (69, 32, [6, 12, 32, 32]), + 201: (64, 32, [6, 12, 48, 32])} + + num_init_features, growth_rate, block_config = specs[densenet_size] + data_shape = tuple([batch_size] + list(image_shape)) + net = _make_dense_net(num_init_features, growth_rate, block_config, + data_shape, dtype, batch_size, classes) + return create_workload(net) diff --git a/python/tvm/relay/testing/inception_v3.py b/python/tvm/relay/testing/inception_v3.py index 7ac3ca35a0bd..c9ec3293ed0a 100644 --- a/python/tvm/relay/testing/inception_v3.py +++ b/python/tvm/relay/testing/inception_v3.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Inception V3, suitable for images with around 299 x 299 @@ -248,7 +264,7 @@ def get_net(batch_size, flatten = relay.nn.batch_flatten(pool) fc1 = relay.nn.dense(flatten, relay.var("fc1_weight"), units=num_classes) - fc1 = relay.nn.bias_add(fc1, relay.var("fc2_bias")) + fc1 = relay.nn.bias_add(fc1, relay.var("fc2_bias"), axis=-1) inception_v3 = relay.nn.softmax(data=fc1) args = relay.ir_pass.free_vars(inception_v3) return relay.Function(args, inception_v3) diff --git a/python/tvm/relay/testing/init.py b/python/tvm/relay/testing/init.py index 7f92b539a1a3..b246b4617276 100644 --- a/python/tvm/relay/testing/init.py +++ b/python/tvm/relay/testing/init.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Initializer of parameters.""" import numpy as np diff --git a/python/tvm/relay/testing/layers.py b/python/tvm/relay/testing/layers.py index 9d4d3b3b4e13..4c263a1b6756 100644 --- a/python/tvm/relay/testing/layers.py +++ b/python/tvm/relay/testing/layers.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Simple Layer DSL wrapper to ease creation of neural nets.""" from tvm import relay @@ -134,5 +150,5 @@ def dense_add_bias(data, weight=None, bias=None, units=None, **kwargs): if not bias: bias = relay.var(name + "_bias") data = relay.nn.dense(data, weight, units, **kwargs) - data = relay.nn.bias_add(data, bias) + data = relay.nn.bias_add(data, bias, axis=-1) return data diff --git a/python/tvm/relay/testing/mlp.py b/python/tvm/relay/testing/mlp.py index 3eac0a8f2654..562ef21ba9f1 100644 --- a/python/tvm/relay/testing/mlp.py +++ b/python/tvm/relay/testing/mlp.py @@ -50,13 +50,13 @@ def get_net(batch_size, dtype=dtype) data = relay.nn.batch_flatten(data) fc1 = relay.nn.dense(data, relay.var("fc1_weight"), units=128) - fc1 = relay.nn.bias_add(fc1, relay.var("fc1_bias")) + fc1 = relay.nn.bias_add(fc1, relay.var("fc1_bias"), axis=-1) act1 = relay.nn.relu(fc1) fc2 = relay.nn.dense(act1, relay.var("fc2_weight"), units=64) - fc2 = relay.nn.bias_add(fc2, relay.var("fc2_bias")) + fc2 = relay.nn.bias_add(fc2, relay.var("fc2_bias"), axis=-1) act2 = relay.nn.relu(fc2) fc3 = relay.nn.dense(act2, relay.var("fc3_weight"), units=num_classes) - fc3 = relay.nn.bias_add(fc3, relay.var("fc3_bias")) + fc3 = relay.nn.bias_add(fc3, relay.var("fc3_bias"), axis=-1) mlp = relay.nn.softmax(data=fc3) args = relay.ir_pass.free_vars(mlp) return relay.Function(args, mlp) diff --git a/python/tvm/relay/testing/tf.py b/python/tvm/relay/testing/tf.py index 0f22939768c5..d82ed0f46097 100644 --- a/python/tvm/relay/testing/tf.py +++ b/python/tvm/relay/testing/tf.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable, unused-argument, no-init """ Tensorflow Model Helpers @@ -331,7 +347,7 @@ def get_workload_ptb(): ptb_model_file = 'RNN/ptb/ptb_model_with_lstmblockcell.pb' import tarfile - file_path = download_testdata(sample_url, sample_data_file, module=['tf', 'ptb_data']) + file_path = download_testdata(sample_url, sample_data_file, module=['data', 'ptb_data']) dir_path = os.path.dirname(file_path) t = tarfile.open(file_path, 'r') t.extractall(dir_path) diff --git a/python/tvm/relay/ty.py b/python/tvm/relay/ty.py index 96ade4124a00..b1477b75d278 100644 --- a/python/tvm/relay/ty.py +++ b/python/tvm/relay/ty.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=no-else-return, unidiomatic-typecheck, invalid-name """The type nodes of the Relay language.""" from enum import IntEnum diff --git a/python/tvm/relay/ty.pyi b/python/tvm/relay/ty.pyi index c4d5df7ac06c..5a7ecffb372e 100644 --- a/python/tvm/relay/ty.pyi +++ b/python/tvm/relay/ty.pyi @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # pylint: disable=no-else-return, unidiomatic-typecheck, invalid-name """The type nodes of the Relay language.""" from enum import IntEnum diff --git a/python/tvm/relay/vision.py b/python/tvm/relay/vision.py index d2c08bc0cc45..f428295f03f4 100644 --- a/python/tvm/relay/vision.py +++ b/python/tvm/relay/vision.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=wildcard-import, unused-import, unused-wildcard-import """Vision network related operators.""" # Re-export in a specific file name so that autodoc can pick it up diff --git a/python/tvm/rpc/__init__.py b/python/tvm/rpc/__init__.py index 6a356e2d64ff..5f959eb44745 100644 --- a/python/tvm/rpc/__init__.py +++ b/python/tvm/rpc/__init__.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Lightweight TVM RPC module. RPC enables connect to a remote server, upload and launch functions. diff --git a/python/tvm/rpc/base.py b/python/tvm/rpc/base.py index 294b5c2e4060..a1e837cd0c1f 100644 --- a/python/tvm/rpc/base.py +++ b/python/tvm/rpc/base.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Base definitions for RPC.""" # pylint: disable=invalid-name diff --git a/python/tvm/rpc/client.py b/python/tvm/rpc/client.py index cf2e118f06c4..9c0dea5b0863 100644 --- a/python/tvm/rpc/client.py +++ b/python/tvm/rpc/client.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """RPC client tools""" from __future__ import absolute_import diff --git a/python/tvm/rpc/proxy.py b/python/tvm/rpc/proxy.py index 7f01fb1b7b02..02d109c18738 100644 --- a/python/tvm/rpc/proxy.py +++ b/python/tvm/rpc/proxy.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """RPC proxy, allows both client/server to connect and match connection. In normal RPC, client directly connect to server's IP address. diff --git a/python/tvm/rpc/server.py b/python/tvm/rpc/server.py index 2bc1ae7fde92..5fffbb2cb374 100644 --- a/python/tvm/rpc/server.py +++ b/python/tvm/rpc/server.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """RPC server implementation. Note diff --git a/python/tvm/rpc/tornado_util.py b/python/tvm/rpc/tornado_util.py index cc0398182a0e..b7b16188a5f6 100644 --- a/python/tvm/rpc/tornado_util.py +++ b/python/tvm/rpc/tornado_util.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Utilities used in tornado.""" import socket diff --git a/python/tvm/rpc/tracker.py b/python/tvm/rpc/tracker.py index 5644775ca416..f31625cd34ed 100644 --- a/python/tvm/rpc/tracker.py +++ b/python/tvm/rpc/tracker.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """RPC Tracker, tracks and distributes the TVM RPC resources. This folder implemements the tracker server logic. diff --git a/python/tvm/schedule.py b/python/tvm/schedule.py index e772735b5bfb..91fd291fb155 100644 --- a/python/tvm/schedule.py +++ b/python/tvm/schedule.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """The computation schedule api of TVM.""" from __future__ import absolute_import as _abs from ._ffi.base import string_types diff --git a/python/tvm/stmt.py b/python/tvm/stmt.py index f06958ab78ee..fc7f6e2cb173 100644 --- a/python/tvm/stmt.py +++ b/python/tvm/stmt.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Statement AST Node in TVM. User do not need to deal with AST node directly. diff --git a/python/tvm/tag.py b/python/tvm/tag.py index de9f8403de2a..d6e48e3a4c73 100644 --- a/python/tvm/tag.py +++ b/python/tvm/tag.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Tag class for TVM operators.""" import warnings from ._ffi.base import decorate diff --git a/python/tvm/target.py b/python/tvm/target.py index 75f82743f9fa..d3df3d705cb8 100644 --- a/python/tvm/target.py +++ b/python/tvm/target.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Target management API of TVM. TVM's target string is in fomat `` [-option=value]...``. diff --git a/python/tvm/tensor.py b/python/tvm/tensor.py index a9c862a268cf..1e297a471863 100644 --- a/python/tvm/tensor.py +++ b/python/tvm/tensor.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Tensor and Operation class for computation declaration.""" # pylint: disable=invalid-name from __future__ import absolute_import as _abs diff --git a/python/tvm/tensor_intrin.py b/python/tvm/tensor_intrin.py index f1f26655fe27..f97e6b7579a1 100644 --- a/python/tvm/tensor_intrin.py +++ b/python/tvm/tensor_intrin.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Tensor intrinsics""" from __future__ import absolute_import as _abs from . import _api_internal diff --git a/python/tvm/testing.py b/python/tvm/testing.py index 1a6666bdee2a..20cbe2431e6d 100644 --- a/python/tvm/testing.py +++ b/python/tvm/testing.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ TVM testing utilities """ import logging import numpy as np diff --git a/rust/.gitignore b/rust/.gitignore new file mode 100644 index 000000000000..0cc660650780 --- /dev/null +++ b/rust/.gitignore @@ -0,0 +1,4 @@ +target/ +*.rs.bk +Cargo.lock +c_runtime_api.rs diff --git a/rust/.rustfmt.toml b/rust/.rustfmt.toml index 9f852c00254c..597bec8d0484 100644 --- a/rust/.rustfmt.toml +++ b/rust/.rustfmt.toml @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + max_width = 100 hard_tabs = false tab_spaces = 4 diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 448cbfe30d1e..25466e08bdf9 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + [workspace] members = [ "common", diff --git a/rust/common/.gitignore b/rust/common/.gitignore deleted file mode 100644 index 84c2ae99001c..000000000000 --- a/rust/common/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -target -**/*.rs.bk -Cargo.lock -/tvm-sys/src/bindgen.rs diff --git a/rust/common/Cargo.toml b/rust/common/Cargo.toml index bcba5ad62fc9..8a19ad0449f9 100644 --- a/rust/common/Cargo.toml +++ b/rust/common/Cargo.toml @@ -1,13 +1,33 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + [package] name = "tvm-common" version = "0.1.0" authors = ["TVM Contributors"] license = "Apache-2.0" +edition = "2018" [features] -runtime = [] -frontend = ["tvm-sys"] +bindings = [] [dependencies] -error-chain = { version = "0.12.0", default-features = false } -tvm-sys = { version = "0.1.0", path = "tvm-sys", optional = true } +failure = "0.1.5" +ndarray = "0.12.1" + +[build-dependencies] +bindgen = "0.37.4" diff --git a/rust/common/build.rs b/rust/common/build.rs new file mode 100644 index 000000000000..5dac99ec54bb --- /dev/null +++ b/rust/common/build.rs @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +extern crate bindgen; + +use std::path::PathBuf; + +fn main() { + if cfg!(feature = "bindings") { + println!("cargo:rerun-if-env-changed=TVM_HOME"); + println!("cargo:rustc-link-lib=dylib=tvm_runtime"); + println!("cargo:rustc-link-search={}/build", env!("TVM_HOME")); + } + + // @see rust-bindgen#550 for `blacklist_type` + bindgen::Builder::default() + .header(format!( + "{}/include/tvm/runtime/c_runtime_api.h", + env!("TVM_HOME") + )) + .header(format!( + "{}/include/tvm/runtime/c_backend_api.h", + env!("TVM_HOME") + )) + .clang_arg(format!("-I{}/3rdparty/dlpack/include/", env!("TVM_HOME"))) + .blacklist_type("max_align_t") + .layout_tests(false) + .derive_partialeq(true) + .derive_eq(true) + .generate() + .expect("unable to generate bindings") + .write_to_file(PathBuf::from("src/c_runtime_api.rs")) + .expect("can not write the bindings!"); +} diff --git a/rust/common/src/array.rs b/rust/common/src/array.rs new file mode 100644 index 000000000000..4ccfb4bf42d9 --- /dev/null +++ b/rust/common/src/array.rs @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +use std::{ + any::TypeId, + mem, + os::raw::{c_int, c_void}, +}; + +use crate::ffi::{ + DLContext, DLDataType, DLDataTypeCode_kDLFloat, DLDataTypeCode_kDLInt, DLDataTypeCode_kDLUInt, + DLDeviceType_kDLCPU, DLTensor, +}; + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct DataType { + pub code: usize, + pub bits: usize, + pub lanes: usize, +} + +impl DataType { + /// Returns the number of bytes occupied by an element of this `DataType`. + pub fn itemsize(&self) -> usize { + (self.bits * self.lanes) >> 3 + } + + /// Returns whether this `DataType` represents primitive type `T`. + pub fn is_type(&self) -> bool { + if self.lanes != 1 { + return false; + } + let typ = TypeId::of::(); + (typ == TypeId::of::() && self.code == 0 && self.bits == 32) + || (typ == TypeId::of::() && self.code == 0 && self.bits == 64) + || (typ == TypeId::of::() && self.code == 1 && self.bits == 32) + || (typ == TypeId::of::() && self.code == 1 && self.bits == 64) + || (typ == TypeId::of::() && self.code == 2 && self.bits == 32) + || (typ == TypeId::of::() && self.code == 2 && self.bits == 64) + } + + pub fn code(&self) -> usize { + self.code + } + + pub fn bits(&self) -> usize { + self.bits + } + + pub fn lanes(&self) -> usize { + self.lanes + } +} + +impl<'a> From<&'a DataType> for DLDataType { + fn from(dtype: &'a DataType) -> Self { + Self { + code: dtype.code as u8, + bits: dtype.bits as u8, + lanes: dtype.lanes as u16, + } + } +} + +impl From for DataType { + fn from(dtype: DLDataType) -> Self { + Self { + code: dtype.code as usize, + bits: dtype.bits as usize, + lanes: dtype.lanes as usize, + } + } +} + +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct TVMContext { + pub device_type: usize, + pub device_id: usize, +} + +impl<'a> From<&'a TVMContext> for DLContext { + fn from(ctx: &'a TVMContext) -> Self { + Self { + device_type: ctx.device_type as u32, + device_id: ctx.device_id as i32, + } + } +} + +impl Default for TVMContext { + fn default() -> Self { + Self { + device_type: DLDeviceType_kDLCPU as usize, + device_id: 0, + } + } +} + +/// `From` conversions to `DLTensor` for `ndarray::Array`. +/// Takes a reference to the `ndarray` since `DLTensor` is not owned. +macro_rules! impl_dltensor_from_ndarray { + ($type:ty, $typecode:expr) => { + impl<'a, D: ndarray::Dimension> From<&'a mut ndarray::Array<$type, D>> for DLTensor { + fn from(arr: &'a mut ndarray::Array<$type, D>) -> Self { + DLTensor { + data: arr.as_mut_ptr() as *mut c_void, + ctx: DLContext { + device_type: DLDeviceType_kDLCPU, + device_id: 0, + }, + ndim: arr.ndim() as c_int, + dtype: DLDataType { + code: $typecode as u8, + bits: 8 * mem::size_of::<$type>() as u8, + lanes: 1, + }, + shape: arr.shape().as_ptr() as *const i64 as *mut i64, + strides: arr.strides().as_ptr() as *const isize as *mut i64, + byte_offset: 0, + } + } + } + }; +} + +impl_dltensor_from_ndarray!(f32, DLDataTypeCode_kDLFloat); +impl_dltensor_from_ndarray!(f64, DLDataTypeCode_kDLFloat); +impl_dltensor_from_ndarray!(i32, DLDataTypeCode_kDLInt); +impl_dltensor_from_ndarray!(i64, DLDataTypeCode_kDLInt); +impl_dltensor_from_ndarray!(u32, DLDataTypeCode_kDLUInt); +impl_dltensor_from_ndarray!(u64, DLDataTypeCode_kDLUInt); diff --git a/rust/common/src/c_runtime_api.rs b/rust/common/src/c_runtime_api.rs deleted file mode 100644 index 6facf9ca274f..000000000000 --- a/rust/common/src/c_runtime_api.rs +++ /dev/null @@ -1,770 +0,0 @@ -/* automatically generated by rust-bindgen for TVM revision 6292c78 */ - -pub const TVM_VERSION: &'static [u8; 8usize] = b"0.5.dev\0"; -pub const DLPACK_VERSION: u32 = 8; -pub const _STDINT_H: u32 = 1; -pub const _FEATURES_H: u32 = 1; -pub const _DEFAULT_SOURCE: u32 = 1; -pub const __USE_ISOC11: u32 = 1; -pub const __USE_ISOC99: u32 = 1; -pub const __USE_ISOC95: u32 = 1; -pub const __USE_POSIX_IMPLICITLY: u32 = 1; -pub const _POSIX_SOURCE: u32 = 1; -pub const _POSIX_C_SOURCE: u32 = 200809; -pub const __USE_POSIX: u32 = 1; -pub const __USE_POSIX2: u32 = 1; -pub const __USE_POSIX199309: u32 = 1; -pub const __USE_POSIX199506: u32 = 1; -pub const __USE_XOPEN2K: u32 = 1; -pub const __USE_XOPEN2K8: u32 = 1; -pub const _ATFILE_SOURCE: u32 = 1; -pub const __USE_MISC: u32 = 1; -pub const __USE_ATFILE: u32 = 1; -pub const __USE_FORTIFY_LEVEL: u32 = 0; -pub const _STDC_PREDEF_H: u32 = 1; -pub const __STDC_IEC_559__: u32 = 1; -pub const __STDC_IEC_559_COMPLEX__: u32 = 1; -pub const __STDC_ISO_10646__: u32 = 201505; -pub const __STDC_NO_THREADS__: u32 = 1; -pub const __GNU_LIBRARY__: u32 = 6; -pub const __GLIBC__: u32 = 2; -pub const __GLIBC_MINOR__: u32 = 23; -pub const _SYS_CDEFS_H: u32 = 1; -pub const __WORDSIZE: u32 = 64; -pub const __WORDSIZE_TIME64_COMPAT32: u32 = 1; -pub const __SYSCALL_WORDSIZE: u32 = 64; -pub const _BITS_WCHAR_H: u32 = 1; -pub const INT8_MIN: i32 = -128; -pub const INT16_MIN: i32 = -32768; -pub const INT32_MIN: i32 = -2147483648; -pub const INT8_MAX: u32 = 127; -pub const INT16_MAX: u32 = 32767; -pub const INT32_MAX: u32 = 2147483647; -pub const UINT8_MAX: u32 = 255; -pub const UINT16_MAX: u32 = 65535; -pub const UINT32_MAX: u32 = 4294967295; -pub const INT_LEAST8_MIN: i32 = -128; -pub const INT_LEAST16_MIN: i32 = -32768; -pub const INT_LEAST32_MIN: i32 = -2147483648; -pub const INT_LEAST8_MAX: u32 = 127; -pub const INT_LEAST16_MAX: u32 = 32767; -pub const INT_LEAST32_MAX: u32 = 2147483647; -pub const UINT_LEAST8_MAX: u32 = 255; -pub const UINT_LEAST16_MAX: u32 = 65535; -pub const UINT_LEAST32_MAX: u32 = 4294967295; -pub const INT_FAST8_MIN: i32 = -128; -pub const INT_FAST16_MIN: i64 = -9223372036854775808; -pub const INT_FAST32_MIN: i64 = -9223372036854775808; -pub const INT_FAST8_MAX: u32 = 127; -pub const INT_FAST16_MAX: u64 = 9223372036854775807; -pub const INT_FAST32_MAX: u64 = 9223372036854775807; -pub const UINT_FAST8_MAX: u32 = 255; -pub const UINT_FAST16_MAX: i32 = -1; -pub const UINT_FAST32_MAX: i32 = -1; -pub const INTPTR_MIN: i64 = -9223372036854775808; -pub const INTPTR_MAX: u64 = 9223372036854775807; -pub const UINTPTR_MAX: i32 = -1; -pub const PTRDIFF_MIN: i64 = -9223372036854775808; -pub const PTRDIFF_MAX: u64 = 9223372036854775807; -pub const SIG_ATOMIC_MIN: i32 = -2147483648; -pub const SIG_ATOMIC_MAX: u32 = 2147483647; -pub const SIZE_MAX: i32 = -1; -pub const WINT_MIN: u32 = 0; -pub const WINT_MAX: u32 = 4294967295; -pub type int_least8_t = ::std::os::raw::c_schar; -pub type int_least16_t = ::std::os::raw::c_short; -pub type int_least32_t = ::std::os::raw::c_int; -pub type int_least64_t = ::std::os::raw::c_long; -pub type uint_least8_t = ::std::os::raw::c_uchar; -pub type uint_least16_t = ::std::os::raw::c_ushort; -pub type uint_least32_t = ::std::os::raw::c_uint; -pub type uint_least64_t = ::std::os::raw::c_ulong; -pub type int_fast8_t = ::std::os::raw::c_schar; -pub type int_fast16_t = ::std::os::raw::c_long; -pub type int_fast32_t = ::std::os::raw::c_long; -pub type int_fast64_t = ::std::os::raw::c_long; -pub type uint_fast8_t = ::std::os::raw::c_uchar; -pub type uint_fast16_t = ::std::os::raw::c_ulong; -pub type uint_fast32_t = ::std::os::raw::c_ulong; -pub type uint_fast64_t = ::std::os::raw::c_ulong; -pub type intmax_t = ::std::os::raw::c_long; -pub type uintmax_t = ::std::os::raw::c_ulong; -pub type wchar_t = ::std::os::raw::c_int; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct max_align_t { - pub __clang_max_align_nonce1: ::std::os::raw::c_longlong, - pub __bindgen_padding_0: u64, - pub __clang_max_align_nonce2: f64, -} -pub const DLDeviceType_kDLCPU: DLDeviceType = 1; -pub const DLDeviceType_kDLGPU: DLDeviceType = 2; -pub const DLDeviceType_kDLCPUPinned: DLDeviceType = 3; -pub const DLDeviceType_kDLOpenCL: DLDeviceType = 4; -pub const DLDeviceType_kDLMetal: DLDeviceType = 8; -pub const DLDeviceType_kDLVPI: DLDeviceType = 9; -pub const DLDeviceType_kDLROCM: DLDeviceType = 10; -/// \brief The device type in DLContext. -pub type DLDeviceType = u32; -/// \brief A Device context for Tensor and operator. -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct DLContext { - /// \brief The device type used in the device. - pub device_type: DLDeviceType, - /// \brief The device index - pub device_id: ::std::os::raw::c_int, -} -pub const DLDataTypeCode_kDLInt: DLDataTypeCode = 0; -pub const DLDataTypeCode_kDLUInt: DLDataTypeCode = 1; -pub const DLDataTypeCode_kDLFloat: DLDataTypeCode = 2; -/// \brief The type code options DLDataType. -pub type DLDataTypeCode = u32; -/// \brief The data type the tensor can hold. -/// -/// Examples -/// - float: type_code = 2, bits = 32, lanes=1 -/// - float4(vectorized 4 float): type_code = 2, bits = 32, lanes=4 -/// - int8: type_code = 0, bits = 8, lanes=1 -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct DLDataType { - /// \brief Type code of base types. - /// We keep it uint8_t instead of DLDataTypeCode for minimal memory - /// footprint, but the value should be one of DLDataTypeCode enum values. - /// - pub code: u8, - /// \brief Number of bits, common choices are 8, 16, 32. - pub bits: u8, - /// \brief Number of lanes in the type, used for vector types. - pub lanes: u16, -} -/// \brief Plain C Tensor object, does not manage memory. -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct DLTensor { - /// \brief The opaque data pointer points to the allocated data. - /// This will be CUDA device pointer or cl_mem handle in OpenCL. - /// This pointer is always aligns to 256 bytes as in CUDA. - pub data: *mut ::std::os::raw::c_void, - /// \brief The device context of the tensor - pub ctx: DLContext, - /// \brief Number of dimensions - pub ndim: ::std::os::raw::c_int, - /// \brief The data type of the pointer - pub dtype: DLDataType, - /// \brief The shape of the tensor - pub shape: *mut i64, - /// \brief strides of the tensor, - /// can be NULL, indicating tensor is compact. - pub strides: *mut i64, - /// \brief The offset in bytes to the beginning pointer to data - pub byte_offset: u64, -} -/// \brief C Tensor object, manage memory of DLTensor. This data structure is -/// intended to faciliate the borrowing of DLTensor by another framework. It is -/// not meant to transfer the tensor. When the borrowing framework doesn't need -/// the tensor, it should call the deleter to notify the host that the resource -/// is no longer needed. -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct DLManagedTensor { - /// \brief DLTensor which is being memory managed - pub dl_tensor: DLTensor, - /// \brief the context of the original host framework of DLManagedTensor in - /// which DLManagedTensor is used in the framework. It can also be NULL. - pub manager_ctx: *mut ::std::os::raw::c_void, - /// \brief Destructor signature void (*)(void*) - this should be called - /// to destruct manager_ctx which holds the DLManagedTensor. It can be NULL - /// if there is no way for the caller to provide a reasonable destructor. - pub deleter: ::std::option::Option, -} -/// \brief type of array index. -pub type tvm_index_t = i64; -pub const TVMDeviceExtType_kDLAOCL: TVMDeviceExtType = 5; -pub const TVMDeviceExtType_kDLSDAccel: TVMDeviceExtType = 6; -pub const TVMDeviceExtType_kDLVulkan: TVMDeviceExtType = 7; -pub const TVMDeviceExtType_kOpenGL: TVMDeviceExtType = 11; -pub const TVMDeviceExtType_kExtDev: TVMDeviceExtType = 12; -/// \brief Extension device types in TVM -pub type TVMDeviceExtType = u32; -pub const TVMTypeCode_kHandle: TVMTypeCode = 3; -pub const TVMTypeCode_kNull: TVMTypeCode = 4; -pub const TVMTypeCode_kTVMType: TVMTypeCode = 5; -pub const TVMTypeCode_kTVMContext: TVMTypeCode = 6; -pub const TVMTypeCode_kArrayHandle: TVMTypeCode = 7; -pub const TVMTypeCode_kNodeHandle: TVMTypeCode = 8; -pub const TVMTypeCode_kModuleHandle: TVMTypeCode = 9; -pub const TVMTypeCode_kFuncHandle: TVMTypeCode = 10; -pub const TVMTypeCode_kStr: TVMTypeCode = 11; -pub const TVMTypeCode_kBytes: TVMTypeCode = 12; -pub const TVMTypeCode_kNDArrayContainer: TVMTypeCode = 13; -pub const TVMTypeCode_kExtBegin: TVMTypeCode = 15; -pub const TVMTypeCode_kNNVMFirst: TVMTypeCode = 16; -pub const TVMTypeCode_kNNVMLast: TVMTypeCode = 20; -pub const TVMTypeCode_kExtReserveEnd: TVMTypeCode = 64; -pub const TVMTypeCode_kExtEnd: TVMTypeCode = 128; -/// \brief The type code in TVMType -/// \note TVMType is used in two places. -pub type TVMTypeCode = u32; -/// \brief The data type used in TVM Runtime. -/// -/// Examples -/// - float: type_code = 2, bits = 32, lanes=1 -/// - float4(vectorized 4 float): type_code = 2, bits = 32, lanes=4 -/// - int8: type_code = 0, bits = 8, lanes=1 -/// -/// \note Arguments TVM API function always takes bits=64 and lanes=1 -pub type TVMType = DLDataType; -/// \brief The Device information, abstract away common device types. -pub type TVMContext = DLContext; -/// \brief The tensor array stucture to TVM API. -pub type TVMArray = DLTensor; -/// \brief the array handle -pub type TVMArrayHandle = *mut TVMArray; -/// \brief Union type of values -/// being passed through API and function calls. -#[repr(C)] -#[derive(Copy, Clone)] -pub union TVMValue { - pub v_int64: i64, - pub v_float64: f64, - pub v_handle: *mut ::std::os::raw::c_void, - pub v_str: *const ::std::os::raw::c_char, - pub v_type: TVMType, - pub v_ctx: TVMContext, - _bindgen_union_align: u64, -} -/// \brief Byte array type used to pass in byte array -/// When kBytes is used as data type. -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct TVMByteArray { - pub data: *const ::std::os::raw::c_char, - pub size: usize, -} -/// \brief Handle to TVM runtime modules. -pub type TVMModuleHandle = *mut ::std::os::raw::c_void; -/// \brief Handle to packed function handle. -pub type TVMFunctionHandle = *mut ::std::os::raw::c_void; -/// \brief Handle to hold return value. -pub type TVMRetValueHandle = *mut ::std::os::raw::c_void; -/// \brief The stream that is specific to device -/// can be NULL, which indicates the default one. -pub type TVMStreamHandle = *mut ::std::os::raw::c_void; -extern "C" { - /// \brief Used for implementing C API function. - /// Set last error message before return. - /// \param msg The error message to be set. - pub fn TVMAPISetLastError(msg: *const ::std::os::raw::c_char); -} -extern "C" { - /// \brief return str message of the last error - /// all function in this file will return 0 when success - /// and -1 when an error occured, - /// TVMGetLastError can be called to retrieve the error - /// - /// this function is threadsafe and can be called by different thread - /// \return error info - pub fn TVMGetLastError() -> *const ::std::os::raw::c_char; -} -extern "C" { - /// \brief Load module from file. - /// \param file_name The file name to load the module from. - /// \param format The format of the module. - /// \param out The result module - /// - /// \return 0 when success, -1 when failure happens - /// \note The resulting module do not contain import relation. - /// It can be reconstructed by TVMModImport. - pub fn TVMModLoadFromFile( - file_name: *const ::std::os::raw::c_char, - format: *const ::std::os::raw::c_char, - out: *mut TVMModuleHandle, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Add dep to mod's dependency. - /// This allows functions in this module to use modules. - /// - /// \param mod The module handle. - /// \param dep The dependent module to be imported. - /// \return 0 when success, -1 when failure happens - pub fn TVMModImport(mod_: TVMModuleHandle, dep: TVMModuleHandle) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Get function from the module. - /// \param mod The module handle. - /// \param func_name The name of the function. - /// \param query_imports Whether to query imported modules - /// \param out The result function, can be NULL if it is not available. - /// \return 0 when no error is thrown, -1 when failure happens - pub fn TVMModGetFunction( - mod_: TVMModuleHandle, - func_name: *const ::std::os::raw::c_char, - query_imports: ::std::os::raw::c_int, - out: *mut TVMFunctionHandle, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Free front-end extension type resource. - /// \param handle The extension handle. - /// \param type_code The type of of the extension type. - /// \return 0 when success, -1 when failure happens - pub fn TVMExtTypeFree( - handle: *mut ::std::os::raw::c_void, - type_code: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Free the Module - /// \param mod The module to be freed. - /// - /// \note This may not free up the module's resources. - /// If there is active TVMFunctionHandle uses the module - /// Or if this module is imported by another active module. - /// - /// The all functions remains valid until TVMFuncFree is called. - /// \return 0 when success, -1 when failure happens - pub fn TVMModFree(mod_: TVMModuleHandle) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Free the function when it is no longer needed. - /// \param func The function handle - /// \return 0 when success, -1 when failure happens - pub fn TVMFuncFree(func: TVMFunctionHandle) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Call a Packed TVM Function. - /// - /// \param func node handle of the function. - /// \param arg_values The arguments - /// \param type_codes The type codes of the arguments - /// \param num_args Number of arguments. - /// - /// \param ret_val The return value. - /// \param ret_type_code the type code of return value. - /// - /// \return 0 when success, -1 when failure happens - /// \note TVM calls always exchanges with type bits=64, lanes=1 - /// - /// \note API calls always exchanges with type bits=64, lanes=1 - /// If API call returns container handles (e.g. FunctionHandle) - /// these handles should be managed by the front-end. - /// The front-end need to call free function (e.g. TVMFuncFree) - /// to free these handles. - pub fn TVMFuncCall( - func: TVMFunctionHandle, - arg_values: *mut TVMValue, - type_codes: *mut ::std::os::raw::c_int, - num_args: ::std::os::raw::c_int, - ret_val: *mut TVMValue, - ret_type_code: *mut ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Set the return value of TVMPackedCFunc. - /// - /// This function is called by TVMPackedCFunc to set the return value. - /// When this function is not called, the function returns null by default. - /// - /// \param ret The return value handle, pass by ret in TVMPackedCFunc - /// \param value The value to be returned. - /// \param type_code The type of the value to be returned. - /// \param num_ret Number of return values, for now only 1 is supported. - pub fn TVMCFuncSetReturn( - ret: TVMRetValueHandle, - value: *mut TVMValue, - type_code: *mut ::std::os::raw::c_int, - num_ret: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Inplace translate callback argument value to return value. - /// This is only needed for non-POD arguments. - /// - /// \param value The value to be translated. - /// \param code The type code to be translated. - /// \note This function will do a shallow copy when necessary. - /// - /// \return 0 when success, -1 when failure happens. - pub fn TVMCbArgToReturn( - value: *mut TVMValue, - code: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -/// \brief C type of packed function. -/// -/// \param args The arguments -/// \param type_codes The type codes of the arguments -/// \param num_args Number of arguments. -/// \param ret The return value handle. -/// \param resource_handle The handle additional resouce handle from fron-end. -/// \return 0 if success, -1 if failure happens, set error via TVMAPISetLastError. -/// \sa TVMCFuncSetReturn -pub type TVMPackedCFunc = ::std::option::Option< - unsafe extern "C" fn( - args: *mut TVMValue, - type_codes: *mut ::std::os::raw::c_int, - num_args: ::std::os::raw::c_int, - ret: TVMRetValueHandle, - resource_handle: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int, ->; -/// \brief C callback to free the resource handle in C packed function. -/// \param resource_handle The handle additional resouce handle from fron-end. -pub type TVMPackedCFuncFinalizer = - ::std::option::Option; -/// \brief Signature for extension function declarer. -/// -/// TVM call this function to get the extension functions -/// The declarer will call register_func to register function and their name. -/// -/// \param register_func_handle The register function -/// \return 0 if success, -1 if failure happens -pub type TVMExtensionFuncDeclarer = ::std::option::Option< - unsafe extern "C" fn(register_func_handle: TVMFunctionHandle) -> ::std::os::raw::c_int, ->; -extern "C" { - /// \brief Wrap a TVMPackedCFunc to become a FunctionHandle. - /// - /// The resource_handle will be managed by TVM API, until the function is no longer used. - /// - /// \param func The packed C function. - /// \param resource_handle The resource handle from front-end, can be NULL. - /// \param fin The finalizer on resource handle when the FunctionHandle get freed, can be NULL - /// \param out the result function handle. - /// \return 0 when success, -1 when failure happens - pub fn TVMFuncCreateFromCFunc( - func: TVMPackedCFunc, - resource_handle: *mut ::std::os::raw::c_void, - fin: TVMPackedCFuncFinalizer, - out: *mut TVMFunctionHandle, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Register the function to runtime's global table. - /// - /// The registered function then can be pulled by the backend by the name. - /// - /// \param name The name of the function. - /// \param f The function to be registered. - /// \param override Whether allow override already registered function. - pub fn TVMFuncRegisterGlobal( - name: *const ::std::os::raw::c_char, - f: TVMFunctionHandle, - override_: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Get a global function. - /// - /// \param name The name of the function. - /// \param out the result function pointer, NULL if it does not exist. - /// - /// \note The function handle of global function is managed by TVM runtime, - /// So TVMFuncFree is should not be called when it get deleted. - pub fn TVMFuncGetGlobal( - name: *const ::std::os::raw::c_char, - out: *mut TVMFunctionHandle, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief List all the globally registered function name - /// \param out_size The number of functions - /// \param out_array The array of function names. - /// \return 0 when success, -1 when failure happens - pub fn TVMFuncListGlobalNames( - out_size: *mut ::std::os::raw::c_int, - out_array: *mut *mut *const ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Allocate a nd-array's memory, - /// including space of shape, of given spec. - /// - /// \param shape The shape of the array, the data content will be copied to out - /// \param ndim The number of dimension of the array. - /// \param dtype_code The type code of the dtype - /// \param dtype_bits The number of bits of dtype - /// \param dtype_lanes The number of lanes in the dtype. - /// \param device_type The device type of context - /// \param device_id The device id of context. - /// \param out The output handle. - /// \return 0 when success, -1 when failure happens - pub fn TVMArrayAlloc( - shape: *const tvm_index_t, - ndim: ::std::os::raw::c_int, - dtype_code: ::std::os::raw::c_int, - dtype_bits: ::std::os::raw::c_int, - dtype_lanes: ::std::os::raw::c_int, - device_type: ::std::os::raw::c_int, - device_id: ::std::os::raw::c_int, - out: *mut TVMArrayHandle, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Free the TVM Array. - /// \param handle The array handle to be freed. - /// \return 0 when success, -1 when failure happens - pub fn TVMArrayFree(handle: TVMArrayHandle) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Copy array data from CPU byte array. - /// \param handle The array handle. - /// \param data the data pointer - /// \param nbytes The number of bytes to copy. - /// \return 0 when success, -1 when failure happens - pub fn TVMArrayCopyFromBytes( - handle: TVMArrayHandle, - data: *mut ::std::os::raw::c_void, - nbytes: usize, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Copy array data to CPU byte array. - /// \param handle The array handle. - /// \param data the data pointer - /// \param nbytes The number of bytes to copy. - /// \return 0 when success, -1 when failure happens - pub fn TVMArrayCopyToBytes( - handle: TVMArrayHandle, - data: *mut ::std::os::raw::c_void, - nbytes: usize, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Copy the array, both from and to must be valid during the copy. - /// \param from The array to be copied from. - /// \param to The target space. - /// \param stream The stream where the copy happens, can be NULL. - /// \return 0 when success, -1 when failure happens - pub fn TVMArrayCopyFromTo( - from: TVMArrayHandle, - to: TVMArrayHandle, - stream: TVMStreamHandle, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Produce an array from the DLManagedTensor that shares data memory - /// with the DLManagedTensor. - /// \param from The source DLManagedTensor. - /// \param out The output array handle. - /// \return 0 when success, -1 when failure happens - pub fn TVMArrayFromDLPack( - from: *mut DLManagedTensor, - out: *mut TVMArrayHandle, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Produce a DLMangedTensor from the array that shares data memory with - /// the array. - /// \param from The source array. - /// \param out The DLManagedTensor handle. - /// \return 0 when success, -1 when failure happens - pub fn TVMArrayToDLPack( - from: TVMArrayHandle, - out: *mut *mut DLManagedTensor, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Delete (free) a DLManagedTensor's data. - /// \param dltensor Pointer to the DLManagedTensor. - pub fn TVMDLManagedTensorCallDeleter(dltensor: *mut DLManagedTensor); -} -extern "C" { - /// \brief Create a new runtime stream. - /// - /// \param device_type The device type of context - /// \param device_id The device id of context - /// \param out The new stream handle - /// \return 0 when success, -1 when failure happens - pub fn TVMStreamCreate( - device_type: ::std::os::raw::c_int, - device_id: ::std::os::raw::c_int, - out: *mut TVMStreamHandle, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Free a created stream handle. - /// - /// \param device_type The device type of context - /// \param device_id The device id of context - /// \param stream The stream to be freed - /// \return 0 when success, -1 when failure happens - pub fn TVMStreamFree( - device_type: ::std::os::raw::c_int, - device_id: ::std::os::raw::c_int, - stream: TVMStreamHandle, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Set the runtime stream of current thread to be stream. - /// The subsequent calls to the same device_type - /// will use the setted stream handle. - /// The specific type of stream is runtime device dependent. - /// - /// \param device_type The device type of context - /// \param device_id The device id of context. - /// \param handle The stream handle. - /// \return 0 when success, -1 when failure happens - pub fn TVMSetStream( - device_type: ::std::os::raw::c_int, - device_id: ::std::os::raw::c_int, - handle: TVMStreamHandle, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Wait until all computations on stream completes. - /// - /// \param device_type The device type of context - /// \param device_id The device id of context. - /// \param stream The stream to be synchronized. - /// \return 0 when success, -1 when failure happens - pub fn TVMSynchronize( - device_type: ::std::os::raw::c_int, - device_id: ::std::os::raw::c_int, - stream: TVMStreamHandle, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Synchronize two streams of execution. - /// - /// \param device_type The device type of context - /// \param device_id The device id of context - /// \param src The source stream to synchronize. - /// \param dst The destination stream to synchronize. - /// \return 0 when success, -1 when failure happens - pub fn TVMStreamStreamSynchronize( - device_type: ::std::os::raw::c_int, - device_id: ::std::os::raw::c_int, - src: TVMStreamHandle, - dst: TVMStreamHandle, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Backend function for modules to get function - /// from its environment mod_node (its imports and global function). - /// The user do should not call TVMFuncFree on func. - /// - /// \param mod_node The module handle. - /// \param func_name The name of the function. - /// \param out The result function. - /// \return 0 when no error is thrown, -1 when failure happens - pub fn TVMBackendGetFuncFromEnv( - mod_node: *mut ::std::os::raw::c_void, - func_name: *const ::std::os::raw::c_char, - out: *mut TVMFunctionHandle, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Backend function to register system-wide library symbol. - /// - /// \param name The name of the symbol - /// \param ptr The symbol address. - /// \return 0 when no error is thrown, -1 when failure happens - pub fn TVMBackendRegisterSystemLibSymbol( - name: *const ::std::os::raw::c_char, - ptr: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Backend function to allocate temporal workspace. - /// - /// \note The result allocate spaced is ensured to be aligned to kTempAllocaAlignment. - /// - /// \param nbytes The size of the space requested. - /// \param device_type The device type which the space will be allocated. - /// \param device_id The device id which the space will be allocated. - /// \param dtype_code_hint The type code of the array elements. Only used in - /// certain backends such as OpenGL. - /// \param dtype_bits_hint The type bits of the array elements. Only used in - /// certain backends such as OpenGL. - /// \return nullptr when error is thrown, a valid ptr if success - pub fn TVMBackendAllocWorkspace( - device_type: ::std::os::raw::c_int, - device_id: ::std::os::raw::c_int, - nbytes: u64, - dtype_code_hint: ::std::os::raw::c_int, - dtype_bits_hint: ::std::os::raw::c_int, - ) -> *mut ::std::os::raw::c_void; -} -extern "C" { - /// \brief Backend function to free temporal workspace. - /// - /// \param ptr The result allocated space pointer. - /// \param device_type The device type which the space will be allocated. - /// \param device_id The device id which the space will be allocated. - /// \return 0 when no error is thrown, -1 when failure happens - /// - /// \sa TVMBackendAllocWorkspace - pub fn TVMBackendFreeWorkspace( - device_type: ::std::os::raw::c_int, - device_id: ::std::os::raw::c_int, - ptr: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int; -} -/// \brief Environment for TVM parallel task. -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct TVMParallelGroupEnv { - /// \brief Auxiliary used for synchronization - pub sync_handle: *mut ::std::os::raw::c_void, - /// \brief total amount of task - pub num_task: i32, -} -/// \brief The callback function to execute a parallel lambda -/// \param task_id the task id of the function. -/// \param penv The parallel environment backs the execution. -/// \param cdata The supporting closure data. -pub type FTVMParallelLambda = ::std::option::Option< - unsafe extern "C" fn( - task_id: ::std::os::raw::c_int, - penv: *mut TVMParallelGroupEnv, - cdata: *mut ::std::os::raw::c_void, - ) -> ::std::os::raw::c_int, ->; -extern "C" { - /// \brief Backend function for running parallel jobs. - /// - /// \param flambda The parallel function to be launched. - /// \param cdata The closure data. - /// \param num_task Number of tasks to launch, can be 0, means launch - /// with all available threads. - /// - /// \return 0 when no error is thrown, -1 when failure happens - pub fn TVMBackendParallelLaunch( - flambda: FTVMParallelLambda, - cdata: *mut ::std::os::raw::c_void, - num_task: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief BSP barrrier between parallel threads - /// \param task_id the task id of the function. - /// \param penv The parallel environment backs the execution. - /// \return 0 when no error is thrown, -1 when failure happens - pub fn TVMBackendParallelBarrier( - task_id: ::std::os::raw::c_int, - penv: *mut TVMParallelGroupEnv, - ) -> ::std::os::raw::c_int; -} -extern "C" { - /// \brief Simple static initialization function. - /// Run f once and set handle to be not null. - /// This function is mainly used for test purpose. - /// - /// \param handle An global address to indicate f - /// \param f The function to be ran - /// \param cdata The closure data to pass to the function. - /// \param nbytes Number of bytes in the closure data. - /// \return 0 when no error is thrown, -1 when failure happens - pub fn TVMBackendRunOnce( - handle: *mut *mut ::std::os::raw::c_void, - f: ::std::option::Option< - unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int, - >, - cdata: *mut ::std::os::raw::c_void, - nbytes: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} diff --git a/rust/common/src/errors.rs b/rust/common/src/errors.rs index a81fab9f8c8f..4b8a9ffcb1eb 100644 --- a/rust/common/src/errors.rs +++ b/rust/common/src/errors.rs @@ -1,15 +1,47 @@ -//! Error types for `TVMArgValue` and `TVMRetValue` conversions. +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ -error_chain! { - errors { - TryFromTVMArgValueError(expected: String, actual: String) { - description("mismatched types while converting from TVMArgValue") - display("expected `{}` but given `{}`", expected, actual) - } +#[derive(Debug, Fail)] +#[fail( + display = "Could not downcast `{}` into `{}`", + expected_type, actual_type +)] +pub struct ValueDowncastError { + pub actual_type: String, + pub expected_type: &'static str, +} + +#[derive(Debug, Fail)] +#[fail(display = "Function call `{}` returned error: {}", context, message)] +pub struct FuncCallError { + context: String, + message: String, +} - TryFromTVMRetValueError(expected: String, actual: String) { - description("mismatched types while downcasting TVMRetValue") - display("invalid downcast: expected `{}` but given `{}`", expected, actual) +impl FuncCallError { + pub fn get_with_context(context: String) -> Self { + Self { + context, + message: unsafe { std::ffi::CStr::from_ptr(crate::ffi::TVMGetLastError()) } + .to_str() + .expect("double fault") + .to_owned(), } } } diff --git a/rust/common/src/lib.rs b/rust/common/src/lib.rs index ad4c4f23579e..c92865872caa 100644 --- a/rust/common/src/lib.rs +++ b/rust/common/src/lib.rs @@ -1,39 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + //! This crate contains the refactored basic components required //! for `runtime` and `frontend` TVM crates. -#![crate_name = "tvm_common"] -#![recursion_limit = "1024"] -#![allow(non_camel_case_types, unused_imports)] -#![feature(box_syntax, try_from)] +#![feature(box_syntax, type_alias_enum_variants, trait_alias)] #[macro_use] -extern crate error_chain; +extern crate failure; /// Unified ffi module for both runtime and frontend crates. pub mod ffi { #![allow(non_camel_case_types, non_snake_case, non_upper_case_globals, unused)] - #[cfg(feature = "frontend")] - pub extern crate tvm_sys as ts; - - #[cfg(feature = "runtime")] - pub mod runtime { - use std::os::raw::{c_char, c_int, c_void}; + use std::os::raw::{c_char, c_int, c_void}; - include!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/c_runtime_api.rs")); + include!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/c_runtime_api.rs")); - pub type BackendPackedCFunc = extern "C" fn( - args: *const TVMValue, - type_codes: *const c_int, - num_args: c_int, - ) -> c_int; - } + pub type BackendPackedCFunc = + extern "C" fn(args: *const TVMValue, type_codes: *const c_int, num_args: c_int) -> c_int; } +pub mod array; pub mod errors; -pub mod ty; +#[macro_use] +pub mod packed_func; pub mod value; pub use errors::*; -pub use ty::TVMTypeCode; -pub use value::{TVMArgValue, TVMRetValue, TVMValue}; +pub use ffi::{TVMByteArray, TVMContext, TVMType}; +pub use packed_func::{TVMArgValue, TVMRetValue}; diff --git a/rust/common/src/packed_func.rs b/rust/common/src/packed_func.rs new file mode 100644 index 000000000000..675b8ba5dc44 --- /dev/null +++ b/rust/common/src/packed_func.rs @@ -0,0 +1,343 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +use std::{ + convert::TryFrom, + ffi::{CStr, CString}, + os::raw::c_void, +}; + +pub use crate::ffi::TVMValue; +use crate::{errors::ValueDowncastError, ffi::*}; + +pub trait PackedFunc = + Fn(&[TVMArgValue]) -> Result + Send + Sync; + +/// Calls a packed function and returns a `TVMRetValue`. +/// +/// # Example +/// +/// `call_packed!(my_tvm_func, &mut arg1, &mut arg2)` +#[macro_export] +macro_rules! call_packed { + ($fn:expr, $($args:expr),+) => { + $fn(&[$($args.into(),)+]) + }; + ($fn:expr) => { + $fn(&Vec::new()) + }; +} + +/// Constructs a derivative of a TVMPodValue. +macro_rules! TVMPODValue { + { + $(#[$m:meta])+ + $name:ident $(<$a:lifetime>)? { + $($extra_variant:ident ( $variant_type:ty ) ),+ $(,)? + }, + match $value:ident { + $($tvm_type:ident => { $from_tvm_type:expr })+ + }, + match &self { + $($self_type:ident ( $val:ident ) => { $from_self_type:expr })+ + } + $(,)? + } => { + $(#[$m])+ + #[derive(Clone, Debug)] + pub enum $name $(<$a>)? { + Int(i64), + UInt(i64), + Float(f64), + Null, + Type(TVMType), + String(CString), + Context(TVMContext), + Handle(*mut c_void), + ArrayHandle(TVMArrayHandle), + NodeHandle(*mut c_void), + ModuleHandle(TVMModuleHandle), + FuncHandle(TVMFunctionHandle), + NDArrayContainer(*mut c_void), + $($extra_variant($variant_type)),+ + } + + impl $(<$a>)? $name $(<$a>)? { + pub fn from_tvm_value($value: TVMValue, type_code: u32) -> Self { + use $name::*; + #[allow(non_upper_case_globals)] + unsafe { + match type_code { + DLDataTypeCode_kDLInt => Int($value.v_int64), + DLDataTypeCode_kDLUInt => UInt($value.v_int64), + DLDataTypeCode_kDLFloat => Float($value.v_float64), + TVMTypeCode_kNull => Null, + TVMTypeCode_kTVMType => Type($value.v_type), + TVMTypeCode_kTVMContext => Context($value.v_ctx), + TVMTypeCode_kHandle => Handle($value.v_handle), + TVMTypeCode_kArrayHandle => ArrayHandle($value.v_handle as TVMArrayHandle), + TVMTypeCode_kNodeHandle => NodeHandle($value.v_handle), + TVMTypeCode_kModuleHandle => ModuleHandle($value.v_handle), + TVMTypeCode_kFuncHandle => FuncHandle($value.v_handle), + TVMTypeCode_kNDArrayContainer => NDArrayContainer($value.v_handle), + $( $tvm_type => { $from_tvm_type } ),+ + _ => unimplemented!("{}", type_code), + } + } + } + + pub fn to_tvm_value(&self) -> (TVMValue, TVMTypeCode) { + use $name::*; + match self { + Int(val) => (TVMValue { v_int64: *val }, DLDataTypeCode_kDLInt), + UInt(val) => (TVMValue { v_int64: *val as i64 }, DLDataTypeCode_kDLUInt), + Float(val) => (TVMValue { v_float64: *val }, DLDataTypeCode_kDLFloat), + Null => (TVMValue{ v_int64: 0 },TVMTypeCode_kNull), + Type(val) => (TVMValue { v_type: *val }, TVMTypeCode_kTVMType), + Context(val) => (TVMValue { v_ctx: val.clone() }, TVMTypeCode_kTVMContext), + String(val) => { + ( + TVMValue { v_handle: val.as_ptr() as *mut c_void }, + TVMTypeCode_kStr, + ) + } + Handle(val) => (TVMValue { v_handle: *val }, TVMTypeCode_kHandle), + ArrayHandle(val) => { + ( + TVMValue { v_handle: *val as *const _ as *mut c_void }, + TVMTypeCode_kArrayHandle, + ) + }, + NodeHandle(val) => (TVMValue { v_handle: *val }, TVMTypeCode_kNodeHandle), + ModuleHandle(val) => + (TVMValue { v_handle: *val }, TVMTypeCode_kModuleHandle), + FuncHandle(val) => ( + TVMValue { v_handle: *val }, + TVMTypeCode_kFuncHandle + ), + NDArrayContainer(val) => + (TVMValue { v_handle: *val }, TVMTypeCode_kNDArrayContainer), + $( $self_type($val) => { $from_self_type } ),+ + } + } + } + } +} + +TVMPODValue! { + /// A borrowed TVMPODValue. Can be constructed using `into()` but the preferred way + /// to obtain a `TVMArgValue` is automatically via `call_packed!`. + TVMArgValue<'a> { + Bytes(&'a TVMByteArray), + Str(&'a CStr), + }, + match value { + TVMTypeCode_kBytes => { Bytes(&*(value.v_handle as *const TVMByteArray)) } + TVMTypeCode_kStr => { Str(CStr::from_ptr(value.v_handle as *const i8)) } + }, + match &self { + Bytes(val) => { + (TVMValue { v_handle: val.clone() as *const _ as *mut c_void }, TVMTypeCode_kBytes) + } + Str(val) => { (TVMValue { v_handle: val.as_ptr() as *mut c_void }, TVMTypeCode_kStr)} + } +} + +TVMPODValue! { + /// An owned TVMPODValue. Can be converted from a variety of primitive and object types. + /// Can be downcasted using `try_from` if it contains the desired type. + /// + /// # Example + /// + /// ``` + /// let a = 42u32; + /// let b: i64 = TVMRetValue::from(a).try_into().unwrap(); + /// + /// let s = "hello, world!"; + /// let t: TVMRetValue = s.into(); + /// assert_eq!(String::try_from(t).unwrap(), s); + /// ``` + TVMRetValue { + Bytes(TVMByteArray), + Str(&'static CStr), + }, + match value { + TVMTypeCode_kBytes => { Bytes(*(value.v_handle as *const TVMByteArray)) } + TVMTypeCode_kStr => { Str(CStr::from_ptr(value.v_handle as *mut i8)) } + }, + match &self { + Bytes(val) => + { (TVMValue { v_handle: val as *const _ as *mut c_void }, TVMTypeCode_kBytes ) } + Str(val) => + { (TVMValue { v_str: val.as_ptr() }, TVMTypeCode_kStr ) } + } +} + +#[macro_export] +macro_rules! try_downcast { + ($val:ident -> $into:ty, $( |$pat:pat| { $converter:expr } ),+ ) => { + match $val { + $( $pat => { Ok($converter) } )+ + _ => Err($crate::errors::ValueDowncastError { + actual_type: format!("{:?}", $val), + expected_type: stringify!($into), + }), + } + }; +} + +/// Creates a conversion to a `TVMArgValue` for a primitive type and DLDataTypeCode. +macro_rules! impl_pod_value { + ($variant:ident, $inner_ty:ty, [ $( $type:ty ),+ ] ) => { + $( + impl<'a> From<$type> for TVMArgValue<'a> { + fn from(val: $type) -> Self { + Self::$variant(val as $inner_ty) + } + } + + impl<'a, 'v> From<&'a $type> for TVMArgValue<'v> { + fn from(val: &'a $type) -> Self { + Self::$variant(*val as $inner_ty) + } + } + + impl<'a> TryFrom> for $type { + type Error = $crate::errors::ValueDowncastError; + fn try_from(val: TVMArgValue<'a>) -> Result { + try_downcast!(val -> $type, |TVMArgValue::$variant(val)| { val as $type }) + } + } + + impl<'a, 'v> TryFrom<&'a TVMArgValue<'v>> for $type { + type Error = $crate::errors::ValueDowncastError; + fn try_from(val: &'a TVMArgValue<'v>) -> Result { + try_downcast!(val -> $type, |TVMArgValue::$variant(val)| { *val as $type }) + } + } + + impl From<$type> for TVMRetValue { + fn from(val: $type) -> Self { + Self::$variant(val as $inner_ty) + } + } + + impl TryFrom for $type { + type Error = $crate::errors::ValueDowncastError; + fn try_from(val: TVMRetValue) -> Result { + try_downcast!(val -> $type, |TVMRetValue::$variant(val)| { val as $type }) + } + } + )+ + }; +} + +impl_pod_value!(Int, i64, [i8, i16, i32, i64, isize]); +impl_pod_value!(UInt, i64, [u8, u16, u32, u64, usize]); +impl_pod_value!(Float, f64, [f32, f64]); +impl_pod_value!(Type, TVMType, [TVMType]); +impl_pod_value!(Context, TVMContext, [TVMContext]); + +impl<'a> From<&'a str> for TVMArgValue<'a> { + fn from(s: &'a str) -> Self { + Self::String(CString::new(s).unwrap()) + } +} + +impl<'a> From<&'a CStr> for TVMArgValue<'a> { + fn from(s: &'a CStr) -> Self { + Self::Str(s) + } +} + +impl<'a> TryFrom> for &'a str { + type Error = ValueDowncastError; + fn try_from(val: TVMArgValue<'a>) -> Result { + try_downcast!(val -> &str, |TVMArgValue::Str(s)| { s.to_str().unwrap() }) + } +} + +impl<'a, 'v> TryFrom<&'a TVMArgValue<'v>> for &'v str { + type Error = ValueDowncastError; + fn try_from(val: &'a TVMArgValue<'v>) -> Result { + try_downcast!(val -> &str, |TVMArgValue::Str(s)| { s.to_str().unwrap() }) + } +} + +/// Converts an unspecialized handle to a TVMArgValue. +impl From<*const T> for TVMArgValue<'static> { + fn from(ptr: *const T) -> Self { + Self::Handle(ptr as *mut c_void) + } +} + +/// Converts an unspecialized mutable handle to a TVMArgValue. +impl From<*mut T> for TVMArgValue<'static> { + fn from(ptr: *mut T) -> Self { + Self::Handle(ptr as *mut c_void) + } +} + +impl<'a> From<&'a mut DLTensor> for TVMArgValue<'a> { + fn from(arr: &'a mut DLTensor) -> Self { + Self::ArrayHandle(arr as *mut DLTensor) + } +} + +impl<'a> From<&'a DLTensor> for TVMArgValue<'a> { + fn from(arr: &'a DLTensor) -> Self { + Self::ArrayHandle(arr as *const _ as *mut DLTensor) + } +} + +impl TryFrom for String { + type Error = ValueDowncastError; + fn try_from(val: TVMRetValue) -> Result { + try_downcast!( + val -> String, + |TVMRetValue::String(s)| { s.into_string().unwrap() }, + |TVMRetValue::Str(s)| { s.to_str().unwrap().to_string() } + ) + } +} + +impl From for TVMRetValue { + fn from(s: String) -> Self { + Self::String(std::ffi::CString::new(s).unwrap()) + } +} + +impl From for TVMRetValue { + fn from(arr: TVMByteArray) -> Self { + Self::Bytes(arr) + } +} + +impl TryFrom for TVMByteArray { + type Error = ValueDowncastError; + fn try_from(val: TVMRetValue) -> Result { + try_downcast!(val -> TVMByteArray, |TVMRetValue::Bytes(val)| { val }) + } +} + +impl Default for TVMRetValue { + fn default() -> Self { + Self::Int(0) + } +} diff --git a/rust/common/src/ty.rs b/rust/common/src/ty.rs deleted file mode 100644 index 126bcd44527e..000000000000 --- a/rust/common/src/ty.rs +++ /dev/null @@ -1,144 +0,0 @@ -//! This module containes `TVMTypeCode` and `TVMType` with some conversion methods. -//! -//! # Example -//! -//! ``` -//! let dtype = TVMType::from("float"); -//! println!("dtype is: {}", dtype); -//! ``` - -use std::{ - ffi::{CStr, CString}, - fmt::{self, Display, Formatter}, -}; - -/// TVM type codes. -#[repr(u32)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum TVMTypeCode { - kDLInt = 0, - kDLUInt = 1, - kDLFloat = 2, - kHandle = 3, - kNull = 4, - kTVMType = 5, - kTVMContext = 6, - kArrayHandle = 7, - kNodeHandle = 8, - kModuleHandle = 9, - kFuncHandle = 10, - kStr = 11, - kBytes = 12, - kNDArrayContainer = 13, -} - -impl Default for TVMTypeCode { - fn default() -> Self { - TVMTypeCode::kDLInt - } -} - -impl From for i64 { - fn from(arg: TVMTypeCode) -> i64 { - match arg { - TVMTypeCode::kDLInt => 0, - TVMTypeCode::kDLUInt => 1, - TVMTypeCode::kDLFloat => 2, - TVMTypeCode::kHandle => 3, - TVMTypeCode::kNull => 4, - TVMTypeCode::kTVMType => 5, - TVMTypeCode::kTVMContext => 6, - TVMTypeCode::kArrayHandle => 7, - TVMTypeCode::kNodeHandle => 8, - TVMTypeCode::kModuleHandle => 9, - TVMTypeCode::kFuncHandle => 10, - TVMTypeCode::kStr => 11, - TVMTypeCode::kBytes => 12, - TVMTypeCode::kNDArrayContainer => 13, - } - } -} - -impl Into for i64 { - fn into(self) -> TVMTypeCode { - match self { - 0 => TVMTypeCode::kDLInt, - 1 => TVMTypeCode::kDLUInt, - 2 => TVMTypeCode::kDLFloat, - 3 => TVMTypeCode::kHandle, - 4 => TVMTypeCode::kNull, - 5 => TVMTypeCode::kTVMType, - 6 => TVMTypeCode::kTVMContext, - 7 => TVMTypeCode::kArrayHandle, - 8 => TVMTypeCode::kNodeHandle, - 9 => TVMTypeCode::kModuleHandle, - 10 => TVMTypeCode::kFuncHandle, - 11 => TVMTypeCode::kStr, - 12 => TVMTypeCode::kBytes, - 13 => TVMTypeCode::kNDArrayContainer, - _ => unreachable!(), - } - } -} - -impl Display for TVMTypeCode { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - write!( - f, - "{}", - match self { - TVMTypeCode::kDLInt => "int", - TVMTypeCode::kDLUInt => "uint", - TVMTypeCode::kDLFloat => "float", - TVMTypeCode::kHandle => "handle", - TVMTypeCode::kNull => "null", - TVMTypeCode::kTVMType => "TVM type", - TVMTypeCode::kTVMContext => "TVM context", - TVMTypeCode::kArrayHandle => "Array handle", - TVMTypeCode::kNodeHandle => "Node handle", - TVMTypeCode::kModuleHandle => "Module handle", - TVMTypeCode::kFuncHandle => "Function handle", - TVMTypeCode::kStr => "string", - TVMTypeCode::kBytes => "bytes", - TVMTypeCode::kNDArrayContainer => "ndarray container", - } - ) - } -} - -macro_rules! impl_prim_type { - ($type:ty, $variant:ident) => { - impl<'a> From<&'a $type> for TVMTypeCode { - fn from(_arg: &$type) -> Self { - TVMTypeCode::$variant - } - } - - impl<'a> From<&'a mut $type> for TVMTypeCode { - fn from(_arg: &mut $type) -> Self { - TVMTypeCode::$variant - } - } - }; -} - -impl_prim_type!(usize, kDLInt); -impl_prim_type!(i64, kDLInt); -impl_prim_type!(i32, kDLInt); -impl_prim_type!(i16, kDLInt); -impl_prim_type!(i8, kDLInt); - -impl_prim_type!(u64, kDLUInt); -impl_prim_type!(u32, kDLUInt); -impl_prim_type!(u16, kDLUInt); -impl_prim_type!(u8, kDLUInt); - -impl_prim_type!(f64, kDLFloat); -impl_prim_type!(f32, kDLFloat); - -impl_prim_type!(str, kStr); -impl_prim_type!(CStr, kStr); -impl_prim_type!(String, kStr); -impl_prim_type!(CString, kStr); - -impl_prim_type!([u8], kBytes); diff --git a/rust/common/src/value.rs b/rust/common/src/value.rs index 6da8b27e8660..94af95c62841 100644 --- a/rust/common/src/value.rs +++ b/rust/common/src/value.rs @@ -1,559 +1,173 @@ -//! This module provides the the wrapped `TVMValue`, `TVMArgValue` and `TVMRetValue` -//! required for using TVM functions. - -use std::{ - any::Any, - convert::TryFrom, - ffi::{CStr, CString}, - fmt::{self, Debug, Formatter}, - marker::PhantomData, - mem, - ops::Deref, - os::raw::{c_char, c_void}, -}; - -#[cfg(feature = "runtime")] -use ffi::runtime::TVMValue as _TVMValue; - -#[cfg(feature = "frontend")] -use ffi::ts::TVMValue as _TVMValue; - -use errors::*; - -use ty::TVMTypeCode; - -/// Wrapped TVMValue type. -#[derive(Clone, Copy)] -pub struct TVMValue { - pub inner: _TVMValue, -} - -impl TVMValue { - /// Creates TVMValue from the raw part. - pub fn new(inner: _TVMValue) -> Self { - TVMValue { inner } - } - - pub(crate) fn into_raw(self) -> _TVMValue { - self.inner - } -} - -impl Debug for TVMValue { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - unsafe { - write!( - f, - "TVMValue: [v_int64: {:?}], [v_float64: {:?}], [v_handle: {:?}],\ - [v_str: {:?}]", - self.inner.v_int64, self.inner.v_float64, self.inner.v_handle, self.inner.v_str - ) +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +use std::str::FromStr; + +use failure::Error; + +use crate::ffi::*; + +impl TVMType { + fn new(type_code: u8, bits: u8, lanes: u16) -> Self { + Self { + code: type_code, + bits, + lanes, } } } -impl Deref for TVMValue { - type Target = _TVMValue; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -macro_rules! impl_prim_val { - ($type:ty, $field:ident, $cast:ty) => { - impl From<$type> for TVMValue { - fn from(arg: $type) -> Self { - let inner = _TVMValue { - $field: arg as $cast, - }; - Self::new(inner) - } - } - - impl<'a> From<&'a $type> for TVMValue { - fn from(arg: &$type) -> Self { - let inner = _TVMValue { - $field: *arg as $cast, - }; - Self::new(inner) - } - } - - impl<'a> From<&'a mut $type> for TVMValue { - fn from(arg: &mut $type) -> Self { - let inner = _TVMValue { - $field: *arg as $cast, - }; - Self::new(inner) - } - } - - impl TryFrom for $type { - type Error = Error; - fn try_from(val: TVMValue) -> Result { - Ok(unsafe { val.inner.$field as $type }) - } - } - - impl<'a> TryFrom<&'a TVMValue> for $type { - type Error = Error; - fn try_from(val: &TVMValue) -> Result { - Ok(unsafe { val.into_raw().$field as $type }) - } +/// Implements TVMType conversion from `&str` of general format `{dtype}{bits}x{lanes}` +/// such as "int32", "float32" or with lane "float32x1". +impl FromStr for TVMType { + type Err = Error; + fn from_str(type_str: &str) -> Result { + if type_str == "bool" { + return Ok(TVMType::new(1, 1, 1)); } - impl<'a> TryFrom<&'a mut TVMValue> for $type { - type Error = Error; - fn try_from(val: &mut TVMValue) -> Result { - Ok(unsafe { val.into_raw().$field as $type }) + let mut type_lanes = type_str.split("x"); + let typ = type_lanes.next().expect("Missing dtype"); + let lanes = type_lanes + .next() + .map(|l| ::from_str_radix(l, 10)) + .unwrap_or(Ok(1))?; + let (type_name, bits) = match typ.find(char::is_numeric) { + Some(idx) => { + let (name, bits_str) = typ.split_at(idx); + (name, u8::from_str_radix(bits_str, 10)?) } - } - }; -} - -impl_prim_val!(isize, v_int64, i64); -impl_prim_val!(i64, v_int64, i64); -impl_prim_val!(i32, v_int64, i64); -impl_prim_val!(i16, v_int64, i64); -impl_prim_val!(i8, v_int64, i64); -impl_prim_val!(usize, v_int64, i64); -impl_prim_val!(u64, v_int64, i64); -impl_prim_val!(u32, v_int64, i64); -impl_prim_val!(u16, v_int64, i64); -impl_prim_val!(u8, v_int64, i64); - -impl_prim_val!(f64, v_float64, f64); -impl_prim_val!(f32, v_float64, f64); - -impl<'a> From<&'a str> for TVMValue { - fn from(arg: &str) -> TVMValue { - let arg = CString::new(arg).unwrap(); - let inner = _TVMValue { - v_str: arg.as_ptr() as *const c_char, - }; - mem::forget(arg); - Self::new(inner) - } -} - -impl<'a> From<&'a String> for TVMValue { - fn from(arg: &String) -> TVMValue { - let arg = CString::new(arg.as_bytes()).unwrap(); - let inner = _TVMValue { - v_str: arg.as_ptr() as *const c_char, + None => (typ, 32), }; - mem::forget(arg); - Self::new(inner) - } -} -impl<'a> From<&'a CString> for TVMValue { - fn from(arg: &CString) -> TVMValue { - let arg = arg.to_owned(); - let inner = _TVMValue { - v_str: arg.as_ptr() as *const c_char, + let type_code = match type_name { + "int" => 0, + "uint" => 1, + "float" => 2, + "handle" => 3, + _ => return Err(format_err!("Unknown type {}", type_name)), }; - mem::forget(arg); - Self::new(inner) - } -} -impl<'a> From<&'a [u8]> for TVMValue { - fn from(arg: &[u8]) -> TVMValue { - let arg = arg.to_owned(); - let inner = _TVMValue { - v_handle: &arg as *const _ as *mut c_void, - }; - mem::forget(arg); - Self::new(inner) + Ok(TVMType::new(type_code, bits, lanes)) } } -/// Captures both `TVMValue` and `TVMTypeCode` needed for TVM function. -/// The preferred way to obtain a `TVMArgValue` is automatically via `call_packed!`. -/// or in the frontend crate, with `function::Builder`. Checkout the methods for conversions. -/// -/// ## Example -/// -/// ``` -/// let s = "hello".to_string(); -/// let arg = TVMArgValue::from(&s); -/// let tvm: String = arg.try_into().unwrap(); -/// assert_eq!(arg, s); -/// ``` -#[derive(Debug, Clone, Copy)] -pub struct TVMArgValue<'a> { - /// The wrapped TVMValue - pub value: TVMValue, - /// The matching type code. - pub type_code: TVMTypeCode, - /// This is only exposed to runtime and frontend crates and is not meant to be used directly. - pub lifetime: PhantomData<&'a ()>, -} - -impl<'a> TVMArgValue<'a> { - pub fn new(value: TVMValue, type_code: TVMTypeCode) -> Self { - TVMArgValue { - value: value, - type_code: type_code, - lifetime: PhantomData, +impl std::fmt::Display for TVMType { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + if self.bits == 1 && self.lanes == 1 { + return write!(f, "bool"); } - } -} - -impl<'a, 'b> TryFrom<&'b TVMArgValue<'a>> for i64 { - type Error = Error; - fn try_from(arg: &TVMArgValue<'a>) -> Result { - if (arg.type_code == TVMTypeCode::kDLInt) - | (arg.type_code == TVMTypeCode::kDLUInt) - | (arg.type_code == TVMTypeCode::kNull) - { - Ok(unsafe { arg.value.inner.v_int64 }) - } else { - bail!(ErrorKind::TryFromTVMArgValueError( - stringify!(i64).to_string(), - arg.type_code.to_string() - )) + let mut type_str = match self.code { + 0 => "int", + 1 => "uint", + 2 => "float", + 4 => "handle", + _ => "unknown", } - } -} + .to_string(); -impl<'a, 'b> TryFrom<&'b TVMArgValue<'a>> for f64 { - type Error = Error; - fn try_from(arg: &TVMArgValue<'a>) -> Result { - if arg.type_code == TVMTypeCode::kDLFloat { - Ok(unsafe { arg.value.inner.v_float64 }) - } else { - bail!(ErrorKind::TryFromTVMArgValueError( - stringify!(f64).to_string(), - arg.type_code.to_string() - )) + type_str += &self.bits.to_string(); + if self.lanes > 1 { + type_str += &format!("x{}", self.lanes); } + f.write_str(&type_str) } } -impl<'a, 'b> TryFrom<&'b TVMArgValue<'a>> for String { - type Error = Error; - fn try_from(arg: &TVMArgValue<'a>) -> Result { - if arg.type_code == TVMTypeCode::kStr { - let ret_str = unsafe { - match CStr::from_ptr(arg.value.inner.v_str).to_str() { - Ok(s) => s, - Err(_) => "Invalid UTF-8 message", +macro_rules! impl_pod_tvm_value { + ($field:ident, $field_ty:ty, $( $ty:ty ),+) => { + $( + impl From<$ty> for TVMValue { + fn from(val: $ty) -> Self { + TVMValue { $field: val as $field_ty } } - }; - Ok(ret_str.to_string()) - } else { - bail!(ErrorKind::TryFromTVMArgValueError( - stringify!(String).to_string(), - arg.type_code.to_string() - )) - } - } -} - -/// Main way to create a TVMArgValue from suported Rust values. -impl<'b, 'a: 'b, T: 'b + ?Sized> From<&'b T> for TVMArgValue<'a> -where - TVMValue: From<&'b T>, - TVMTypeCode: From<&'b T>, -{ - fn from(arg: &'b T) -> Self { - TVMArgValue::new(TVMValue::from(arg), TVMTypeCode::from(arg)) - } -} - -/// Creates a conversion to a `TVMArgValue` for an object handle. -impl<'a, T> From<*const T> for TVMArgValue<'a> { - fn from(ptr: *const T) -> Self { - let value = TVMValue::new(_TVMValue { - v_handle: ptr as *mut T as *mut c_void, - }); - - TVMArgValue::new(value, TVMTypeCode::kArrayHandle) - } -} - -/// Creates a conversion to a `TVMArgValue` for a mutable object handle. -impl<'a, T> From<*mut T> for TVMArgValue<'a> { - fn from(ptr: *mut T) -> Self { - let value = TVMValue::new(_TVMValue { - v_handle: ptr as *mut c_void, - }); - - TVMArgValue::new(value, TVMTypeCode::kHandle) - } -} - -/// An owned version of TVMPODValue. It can be converted from varieties of -/// primitive and object types. -/// It can be downcasted using `try_from` if it contains the desired type. -/// -/// # Example -/// -/// ``` -/// let a = 42u32; -/// let b: i64 = TVMRetValue::from(a).try_into().unwrap(); -/// -/// let s = "hello, world!"; -/// let t: TVMRetValue = s.into(); -/// assert_eq!(String::try_from(t).unwrap(), s); -/// ``` -pub struct TVMRetValue { - /// A primitive return value, if any. - pub prim_value: usize, - /// An object return value, if any. - pub box_value: Box, - pub type_code: TVMTypeCode, -} - -impl TVMRetValue { - fn new(prim_value: usize, box_value: Box, type_code: TVMTypeCode) -> Self { - Self { - prim_value, - box_value, - type_code, - } - } - - /// unsafe function to create `TVMRetValue` from `TVMValue` and - /// its matching `TVMTypeCode`. - pub unsafe fn from_tvm_value(value: TVMValue, type_code: TVMTypeCode) -> Self { - let value = value.into_raw(); - match type_code { - TVMTypeCode::kDLInt | TVMTypeCode::kDLUInt => { - Self::new(value.v_int64 as usize, box (), type_code) - } - TVMTypeCode::kDLFloat => Self::new(value.v_float64 as usize, box (), type_code), - TVMTypeCode::kHandle - | TVMTypeCode::kArrayHandle - | TVMTypeCode::kNodeHandle - | TVMTypeCode::kModuleHandle - | TVMTypeCode::kFuncHandle => { - Self::new(value.v_handle as usize, box value.v_handle, type_code) - } - TVMTypeCode::kStr | TVMTypeCode::kBytes => { - Self::new(value.v_str as usize, box (value.v_str), type_code) - } - _ => Self::new(0usize, box (), type_code), - } - } - - /// Returns the underlying `TVMValue` and `TVMTypeCode`. - pub fn into_tvm_value(self) -> (TVMValue, TVMTypeCode) { - let val = match self.type_code { - TVMTypeCode::kDLInt | TVMTypeCode::kDLUInt => TVMValue::new(_TVMValue { - v_int64: self.prim_value as i64, - }), - TVMTypeCode::kDLFloat => TVMValue::new(_TVMValue { - v_float64: self.prim_value as f64, - }), - TVMTypeCode::kHandle - | TVMTypeCode::kArrayHandle - | TVMTypeCode::kNodeHandle - | TVMTypeCode::kModuleHandle - | TVMTypeCode::kFuncHandle - | TVMTypeCode::kNDArrayContainer => TVMValue::new(_TVMValue { - v_handle: self.prim_value as *const c_void as *mut c_void, - }), - TVMTypeCode::kStr | TVMTypeCode::kBytes => TVMValue::new(_TVMValue { - v_str: self.prim_value as *const c_char, - }), - _ => unreachable!(), - }; - (val, self.type_code) - } -} - -impl Default for TVMRetValue { - fn default() -> Self { - TVMRetValue { - prim_value: 0usize, - box_value: box (), - type_code: TVMTypeCode::default(), - } - } -} - -impl Clone for TVMRetValue { - fn clone(&self) -> Self { - match self.type_code { - TVMTypeCode::kDLInt | TVMTypeCode::kDLUInt | TVMTypeCode::kDLFloat => { - Self::new(self.prim_value.clone(), box (), self.type_code.clone()) } - TVMTypeCode::kHandle - | TVMTypeCode::kArrayHandle - | TVMTypeCode::kNodeHandle - | TVMTypeCode::kModuleHandle - | TVMTypeCode::kFuncHandle - | TVMTypeCode::kNDArrayContainer => Self::new( - self.prim_value.clone(), - box (self.prim_value.clone() as *const c_void as *mut c_void), - self.type_code.clone(), - ), - TVMTypeCode::kStr | TVMTypeCode::kBytes => Self::new( - self.prim_value.clone(), - box (self.prim_value.clone() as *const c_char), - self.type_code.clone(), - ), - _ => unreachable!(), - } - } -} - -impl Debug for TVMRetValue { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - write!( - f, - "prim_value: {:?}, box_value: {:?}, type_code: {:?}", - self.prim_value, self.prim_value as *const c_void as *mut c_void, self.type_code - ) - } -} -macro_rules! impl_prim_ret_value { - ($type:ty, $code:expr) => { - impl From<$type> for TVMRetValue { - fn from(val: $type) -> Self { - TVMRetValue { - prim_value: val as usize, - box_value: box (), - type_code: $code, + impl From for $ty { + fn from(val: TVMValue) -> Self { + unsafe { val.$field as $ty } } } - } - - impl<'a> From<&'a $type> for TVMRetValue { - fn from(val: &$type) -> Self { - TVMRetValue { - prim_value: *val as usize, - box_value: box (), - type_code: $code, - } - } - } - - impl<'a> From<&'a mut $type> for TVMRetValue { - fn from(val: &mut $type) -> Self { - TVMRetValue { - prim_value: *val as usize, - box_value: box (), - type_code: $code, - } - } - } - - impl TryFrom for $type { - type Error = Error; - fn try_from(ret: TVMRetValue) -> Result<$type> { - if ret.type_code == $code { - Ok(ret.prim_value as $type) - } else { - bail!(ErrorKind::TryFromTVMRetValueError( - stringify!($type).to_string(), - ret.type_code.to_string(), - )) - } - } - } + )+ }; + ($field:ident, $ty:ty) => { + impl_pod_tvm_value!($field, $ty, $ty); + } } -impl_prim_ret_value!(i8, TVMTypeCode::kDLInt); -impl_prim_ret_value!(i16, TVMTypeCode::kDLInt); -impl_prim_ret_value!(i32, TVMTypeCode::kDLInt); -impl_prim_ret_value!(i64, TVMTypeCode::kDLInt); -impl_prim_ret_value!(isize, TVMTypeCode::kDLInt); - -impl_prim_ret_value!(u8, TVMTypeCode::kDLUInt); -impl_prim_ret_value!(u16, TVMTypeCode::kDLUInt); -impl_prim_ret_value!(u32, TVMTypeCode::kDLUInt); -impl_prim_ret_value!(u64, TVMTypeCode::kDLUInt); -impl_prim_ret_value!(usize, TVMTypeCode::kDLUInt); +impl_pod_tvm_value!(v_int64, i64, i8, u8, i16, u16, i32, u32, i64, u64, isize, usize); +impl_pod_tvm_value!(v_float64, f64, f32, f64); +impl_pod_tvm_value!(v_type, TVMType); +impl_pod_tvm_value!(v_ctx, TVMContext); -impl_prim_ret_value!(f32, TVMTypeCode::kDLFloat); -impl_prim_ret_value!(f64, TVMTypeCode::kDLFloat); - -macro_rules! impl_ptr_ret_value { - ($type:ty) => { - impl From<$type> for TVMRetValue { - fn from(ptr: $type) -> Self { - TVMRetValue { - prim_value: ptr as usize, - box_value: box (), - type_code: TVMTypeCode::kHandle, - } +macro_rules! impl_tvm_context { + ( $( $dev_type:ident : [ $( $dev_name:ident ),+ ] ),+ ) => { + /// Creates a TVMContext from a string (e.g., "cpu", "gpu", "ext_dev") + impl FromStr for TVMContext { + type Err = Error; + fn from_str(type_str: &str) -> Result { + Ok(Self { + device_type: match type_str { + $( $( stringify!($dev_name) )|+ => $dev_type ),+, + _ => return Err(format_err!("device {} not supported", type_str).into()), + }, + device_id: 0, + }) } } - impl TryFrom for $type { - type Error = Error; - fn try_from(ret: TVMRetValue) -> Result<$type> { - if ret.type_code == TVMTypeCode::kHandle { - Ok(ret.prim_value as $type) - } else { - bail!(ErrorKind::TryFromTVMRetValueError( - stringify!($type).to_string(), - ret.type_code.to_string(), - )) - } - } + impl TVMContext { + $( + $( + pub fn $dev_name(device_id: usize) -> Self { + Self { + device_type: $dev_type, + device_id: device_id as i32, + } + } + )+ + )+ } }; } -impl_ptr_ret_value!(*const c_void); -impl_ptr_ret_value!(*mut c_void); - -impl From for TVMRetValue { - fn from(val: String) -> Self { - let pval = val.as_ptr() as *const c_char as usize; - let bval = box (val.as_ptr() as *const c_char); - mem::forget(val); - TVMRetValue::new(pval, bval, TVMTypeCode::kStr) - } -} - -impl TryFrom for String { - type Error = Error; - fn try_from(ret: TVMRetValue) -> Result { - // Note: simple downcast doesn't work for function call return values - let ret_str = unsafe { - match CStr::from_ptr(ret.prim_value as *const c_char).to_str() { - Ok(s) => s, - Err(_) => "Invalid UTF-8 message", - } - }; +impl_tvm_context!( + DLDeviceType_kDLCPU: [cpu, llvm, stackvm], + DLDeviceType_kDLGPU: [gpu, cuda, nvptx], + DLDeviceType_kDLOpenCL: [cl], + DLDeviceType_kDLMetal: [metal], + DLDeviceType_kDLVPI: [vpi], + DLDeviceType_kDLROCM: [rocm], + DLDeviceType_kDLExtDev: [ext_dev] +); - Ok(ret_str.to_string()) +impl TVMByteArray { + pub fn data(&self) -> &'static [u8] { + unsafe { std::slice::from_raw_parts(self.data as *const u8, self.size) } } } -#[cfg(test)] -mod tests { - use super::*; - use std::convert::TryInto; - - #[test] - fn numeric() { - macro_rules! arg_ret_tests { - ($v:expr; $($ty:ty),+) => {{ - $( - let v = $v as $ty; - let b = TVMRetValue::from(&v); - let b: $ty = b.try_into().unwrap(); - assert_eq!(b, v); - )+ - }}; +impl<'a> From<&'a [u8]> for TVMByteArray { + fn from(bytes: &[u8]) -> Self { + Self { + data: bytes.as_ptr() as *const i8, + size: bytes.len(), } - - arg_ret_tests!(42; i8, i16, i32, i64, f32, f64); - } - - #[test] - fn string() { - let s = "hello".to_string(); - let tvm_arg: String = TVMRetValue::from(s.clone()).try_into().unwrap(); - assert_eq!(tvm_arg, s); } } diff --git a/rust/common/tvm-sys/Cargo.toml b/rust/common/tvm-sys/Cargo.toml deleted file mode 100644 index 117d174b4cbd..000000000000 --- a/rust/common/tvm-sys/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "tvm-sys" -version = "0.1.0" -authors = ["TVM Contributors"] -license = "Apache-2.0" -description = "Raw C API" - -[build-dependencies] -bindgen = "0.37.4" diff --git a/rust/common/tvm-sys/build.rs b/rust/common/tvm-sys/build.rs deleted file mode 100644 index f842043a1d16..000000000000 --- a/rust/common/tvm-sys/build.rs +++ /dev/null @@ -1,25 +0,0 @@ -extern crate bindgen; - -use std::path::PathBuf; - -fn main() { - println!("cargo:rerun-if-env-changed=TVM_HOME"); - println!("cargo:rustc-link-lib=dylib=tvm_runtime"); - println!("cargo:rustc-link-search={}/build", env!("TVM_HOME")); - let bindings = bindgen::Builder::default() - .header(format!( - "{}/include/tvm/runtime/c_runtime_api.h", - env!("TVM_HOME") - )) - .clang_arg(format!("-I{}/3rdparty/dlpack/include/", env!("TVM_HOME"))) - .blacklist_type("max_align_t") // @see rust-bindgen#550 - .layout_tests(false) - .derive_partialeq(true) - .derive_eq(true) - .generate() - .expect("unable to generate bindings"); - - bindings - .write_to_file(PathBuf::from("src/bindgen.rs")) - .expect("can not write the bindings!"); -} diff --git a/rust/common/tvm-sys/src/lib.rs b/rust/common/tvm-sys/src/lib.rs deleted file mode 100644 index 15f1ea3a611c..000000000000 --- a/rust/common/tvm-sys/src/lib.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![allow( - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - dead_code, - improper_ctypes -)] - -include!("bindgen.rs"); diff --git a/rust/frontend/.travis.yml b/rust/frontend/.travis.yml index 63a3d0277c1b..e963b7c0ede5 100644 --- a/rust/frontend/.travis.yml +++ b/rust/frontend/.travis.yml @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + language: rust rust: - nightly diff --git a/rust/frontend/Cargo.toml b/rust/frontend/Cargo.toml index db261551e36f..fa05c5695ebd 100644 --- a/rust/frontend/Cargo.toml +++ b/rust/frontend/Cargo.toml @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + [package] name = "tvm-frontend" version = "0.1.0" @@ -9,17 +26,18 @@ readme = "README.md" keywords = ["rust", "tvm", "nnvm"] categories = ["api-bindings", "science"] authors = ["TVM Contributors"] +edition = "2018" [lib] name = "tvm_frontend" crate-type = ["dylib"] [dependencies] -error-chain = "0.12.0" +failure = "0.1.5" lazy_static = "1.1.0" ndarray = "0.12.1" num-traits = "0.2" -tvm-common = { version = "0.1.0", path = "../common/", features = ["frontend"] } +tvm-common = { version = "0.1.0", path = "../common/", features = ["bindings"] } [features] blas = ["ndarray/blas"] diff --git a/rust/frontend/README.md b/rust/frontend/README.md index 9f46cf760c91..31d4806b1ff6 100644 --- a/rust/frontend/README.md +++ b/rust/frontend/README.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + # TVM Runtime Frontend Support This crate provides an idiomatic Rust API for [TVM](https://github.com/dmlc/tvm) runtime frontend. Currently this requires **Nightly Rust** and tested on `rustc 1.32.0-nightly` diff --git a/rust/frontend/examples/resnet/Cargo.toml b/rust/frontend/examples/resnet/Cargo.toml index e8a3eb7f519d..0b547ba1458d 100644 --- a/rust/frontend/examples/resnet/Cargo.toml +++ b/rust/frontend/examples/resnet/Cargo.toml @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + [package] name = "resnet" version = "0.0.0" diff --git a/rust/frontend/examples/resnet/README.md b/rust/frontend/examples/resnet/README.md index 3d20d55a80c4..e84c099de411 100644 --- a/rust/frontend/examples/resnet/README.md +++ b/rust/frontend/examples/resnet/README.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + ## Resnet example This end-to-end example shows how to: diff --git a/rust/frontend/examples/resnet/build.rs b/rust/frontend/examples/resnet/build.rs index f913bf8b0aca..037c3bbd97d2 100644 --- a/rust/frontend/examples/resnet/build.rs +++ b/rust/frontend/examples/resnet/build.rs @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + use std::process::Command; fn main() { diff --git a/rust/frontend/examples/resnet/src/build_resnet.py b/rust/frontend/examples/resnet/src/build_resnet.py old mode 100755 new mode 100644 index e5b76aa821ee..5da1db63310e --- a/rust/frontend/examples/resnet/src/build_resnet.py +++ b/rust/frontend/examples/resnet/src/build_resnet.py @@ -1,4 +1,20 @@ #!/usr/bin/env python3 +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import argparse import csv diff --git a/rust/frontend/examples/resnet/src/main.rs b/rust/frontend/examples/resnet/src/main.rs index 869a35b3a3a4..e50d92795883 100644 --- a/rust/frontend/examples/resnet/src/main.rs +++ b/rust/frontend/examples/resnet/src/main.rs @@ -1,4 +1,21 @@ -#![feature(try_from)] +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ extern crate csv; extern crate image; @@ -10,6 +27,7 @@ use std::{ convert::TryInto, fs::{self, File}, path::Path, + str::FromStr, }; use image::{FilterType, GenericImageView}; @@ -44,8 +62,12 @@ fn main() { // make arr shape as [1, 3, 224, 224] acceptable to resnet let arr = arr.insert_axis(Axis(0)); // create input tensor from rust's ndarray - let input = - NDArray::from_rust_ndarray(&arr, TVMContext::cpu(0), TVMType::from("float32")).unwrap(); + let input = NDArray::from_rust_ndarray( + &arr, + TVMContext::cpu(0), + TVMType::from_str("float32").unwrap(), + ) + .unwrap(); println!( "input size is {:?}", input.shape().expect("cannot get the input shape") @@ -59,7 +81,7 @@ fn main() { ))) .unwrap(); // get the global TVM graph runtime function - let runtime_create_fn = Function::get("tvm.graph_runtime.create", true).unwrap(); + let runtime_create_fn = Function::get("tvm.graph_runtime.create").unwrap(); let runtime_create_fn_ret = call_packed!( runtime_create_fn, &graph, @@ -85,14 +107,19 @@ fn main() { .get_function("set_input", false) .unwrap(); - call_packed!(set_input_fn, "data", &input).unwrap(); + let data_str = "data".to_string(); + call_packed!(set_input_fn, &data_str, &input).unwrap(); // get `run` function from runtime module let ref run_fn = graph_runtime_module.get_function("run", false).unwrap(); // execute the run function. Note that it has no argument call_packed!(run_fn,).unwrap(); // prepare to get the output let output_shape = &mut [1, 1000]; - let output = NDArray::empty(output_shape, TVMContext::cpu(0), TVMType::from("float32")); + let output = NDArray::empty( + output_shape, + TVMContext::cpu(0), + TVMType::from_str("float32").unwrap(), + ); // get the `get_output` function from runtime module let ref get_output_fn = graph_runtime_module .get_function("get_output", false) diff --git a/rust/frontend/src/bytearray.rs b/rust/frontend/src/bytearray.rs index 395f34c2428d..a1d183d9f525 100644 --- a/rust/frontend/src/bytearray.rs +++ b/rust/frontend/src/bytearray.rs @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + //! Provides [`TVMByteArray`] used for passing the model parameters //! (stored as byte-array) to a runtime module. //! @@ -5,7 +24,7 @@ use std::os::raw::c_char; -use crate::ts; +use tvm_common::ffi; /// A struct holding TVM byte-array. /// @@ -19,11 +38,11 @@ use crate::ts; /// ``` #[derive(Debug, Clone)] pub struct TVMByteArray { - pub(crate) inner: ts::TVMByteArray, + pub(crate) inner: ffi::TVMByteArray, } impl TVMByteArray { - pub(crate) fn new(barr: ts::TVMByteArray) -> TVMByteArray { + pub(crate) fn new(barr: ffi::TVMByteArray) -> TVMByteArray { TVMByteArray { inner: barr } } @@ -44,9 +63,10 @@ impl TVMByteArray { } } -impl<'a> From<&'a Vec> for TVMByteArray { - fn from(arg: &Vec) -> Self { - let barr = ts::TVMByteArray { +impl<'a, T: AsRef<[u8]>> From for TVMByteArray { + fn from(arg: T) -> Self { + let arg = arg.as_ref(); + let barr = ffi::TVMByteArray { data: arg.as_ptr() as *const c_char, size: arg.len(), }; diff --git a/rust/frontend/src/context.rs b/rust/frontend/src/context.rs index 65e11d82e2d0..a5f0dd7b1019 100644 --- a/rust/frontend/src/context.rs +++ b/rust/frontend/src/context.rs @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + //! Provides [`TVMContext`] and related device specific queries. //! //! Create a new context by device type (cpu is 1) and device id. @@ -18,12 +37,17 @@ //! ``` use std::{ + convert::TryInto, fmt::{self, Display, Formatter}, os::raw::c_void, ptr, }; -use crate::{function, ts, Result}; +use failure::Error; + +use tvm_common::ffi; + +use crate::function; /// Device type can be from a supported device name. See the supported devices /// in [TVM](https://github.com/dmlc/tvm). @@ -45,35 +69,35 @@ impl Default for TVMDeviceType { } } -impl From for ts::DLDeviceType { +impl From for ffi::DLDeviceType { fn from(device_type: TVMDeviceType) -> Self { match device_type.0 { - 1 => ts::DLDeviceType_kDLCPU, - 2 => ts::DLDeviceType_kDLGPU, - 3 => ts::DLDeviceType_kDLCPUPinned, - 4 => ts::DLDeviceType_kDLOpenCL, - 7 => ts::DLDeviceType_kDLVulkan, - 8 => ts::DLDeviceType_kDLMetal, - 9 => ts::DLDeviceType_kDLVPI, - 10 => ts::DLDeviceType_kDLROCM, - 12 => ts::DLDeviceType_kDLExtDev, + 1 => ffi::DLDeviceType_kDLCPU, + 2 => ffi::DLDeviceType_kDLGPU, + 3 => ffi::DLDeviceType_kDLCPUPinned, + 4 => ffi::DLDeviceType_kDLOpenCL, + 7 => ffi::DLDeviceType_kDLVulkan, + 8 => ffi::DLDeviceType_kDLMetal, + 9 => ffi::DLDeviceType_kDLVPI, + 10 => ffi::DLDeviceType_kDLROCM, + 12 => ffi::DLDeviceType_kDLExtDev, _ => panic!("device type not found!"), } } } -impl From for TVMDeviceType { - fn from(device_type: ts::DLDeviceType) -> Self { +impl From for TVMDeviceType { + fn from(device_type: ffi::DLDeviceType) -> Self { match device_type { - ts::DLDeviceType_kDLCPU => TVMDeviceType(1), - ts::DLDeviceType_kDLGPU => TVMDeviceType(2), - ts::DLDeviceType_kDLCPUPinned => TVMDeviceType(3), - ts::DLDeviceType_kDLOpenCL => TVMDeviceType(4), - ts::DLDeviceType_kDLVulkan => TVMDeviceType(7), - ts::DLDeviceType_kDLMetal => TVMDeviceType(8), - ts::DLDeviceType_kDLVPI => TVMDeviceType(9), - ts::DLDeviceType_kDLROCM => TVMDeviceType(10), - ts::DLDeviceType_kDLExtDev => TVMDeviceType(12), + ffi::DLDeviceType_kDLCPU => TVMDeviceType(1), + ffi::DLDeviceType_kDLGPU => TVMDeviceType(2), + ffi::DLDeviceType_kDLCPUPinned => TVMDeviceType(3), + ffi::DLDeviceType_kDLOpenCL => TVMDeviceType(4), + ffi::DLDeviceType_kDLVulkan => TVMDeviceType(7), + ffi::DLDeviceType_kDLMetal => TVMDeviceType(8), + ffi::DLDeviceType_kDLVPI => TVMDeviceType(9), + ffi::DLDeviceType_kDLROCM => TVMDeviceType(10), + ffi::DLDeviceType_kDLExtDev => TVMDeviceType(12), _ => panic!("device type not found!"), } } @@ -138,15 +162,15 @@ pub struct TVMContext { /// Supported device types pub device_type: TVMDeviceType, /// Device id - pub device_id: usize, + pub device_id: i32, } impl TVMContext { /// Creates context from device type and id. - pub fn new(device_type: TVMDeviceType, device_id: usize) -> Self { + pub fn new(device_type: TVMDeviceType, device_id: i32) -> Self { TVMContext { - device_type: device_type, - device_id: device_id, + device_type, + device_id, } } } @@ -155,7 +179,7 @@ macro_rules! impl_ctxs { ($(($ctx:ident, $dldevt:expr));+) => { $( impl TVMContext { - pub fn $ctx(device_id: usize) -> Self { + pub fn $ctx(device_id: i32) -> Self { Self::new(TVMDeviceType($dldevt), device_id) } } @@ -185,20 +209,20 @@ impl<'a> From<&'a str> for TVMContext { impl TVMContext { /// Checks whether the context exists or not. pub fn exist(&self) -> bool { - let func = function::Function::get("_GetDeviceAttr", true /* is_global */) - .expect("API function always exists"); + let func = function::Function::get("_GetDeviceAttr").expect("API function always exists"); let dt = self.device_type.0 as usize; // `unwrap` is ok here because if there is any error, // if would occure inside `call_packed!` - let ret = call_packed!(func, &dt, &self.device_id, &0) + let ret: u64 = call_packed!(func, dt, self.device_id, 0) .unwrap() - .prim_value; + .try_into() + .unwrap(); ret != 0 } /// Synchronize the context stream. - pub fn sync(&self) -> Result<()> { - check_call!(ts::TVMSynchronize( + pub fn sync(&self) -> Result<(), Error> { + check_call!(ffi::TVMSynchronize( self.device_type.0 as i32, self.device_id as i32, ptr::null_mut() as *mut c_void @@ -212,16 +236,19 @@ macro_rules! impl_device_attrs { $( impl TVMContext { pub fn $attr_name(&self) -> usize { - let func = function::Function::get("_GetDeviceAttr", true /* is_global */) + let func = function::Function::get("_GetDeviceAttr") .expect("API function always exists"); let dt = self.device_type.0 as usize; // `unwrap` is ok here because if there is any error, // if would occur in function call. - let ret = function::Builder::from(func) - .args(&[dt, self.device_id, $attr_kind]) + function::Builder::from(func) + .arg(dt) + .arg(self.device_id as usize) + .arg($attr_kind) .invoke() - .unwrap(); - ret.prim_value as usize + .unwrap() + .try_into() + .unwrap() } } )+ @@ -237,18 +264,18 @@ impl_device_attrs!((max_threads_per_block, 1); (multi_processor_count, 7); (max_thread_dimensions, 8)); -impl From for TVMContext { - fn from(ctx: ts::DLContext) -> Self { +impl From for TVMContext { + fn from(ctx: ffi::DLContext) -> Self { TVMContext { device_type: TVMDeviceType::from(ctx.device_type), - device_id: ctx.device_id as usize, + device_id: ctx.device_id, } } } -impl From for ts::DLContext { +impl From for ffi::DLContext { fn from(ctx: TVMContext) -> Self { - ts::DLContext { + ffi::DLContext { device_type: ctx.device_type.into(), device_id: ctx.device_id as i32, } diff --git a/rust/frontend/src/errors.rs b/rust/frontend/src/errors.rs index a10f83c4110d..ceda69773a38 100644 --- a/rust/frontend/src/errors.rs +++ b/rust/frontend/src/errors.rs @@ -1,51 +1,45 @@ -//! This module implements TVM custom [`Error`], [`ErrorKind`] and [`Result`] types. - -use std::{ffi, option}; - -use crate::{common_errors, rust_ndarray}; - -error_chain! { - errors { - EmptyArray { - description("cannot convert from an empty array") - } - - NullHandle(name: String) { - description("null handle") - display("requested `{}` handle is null", name) - } - - FunctionNotFound { - description("function not found") - display("function was not set in `function::Builder`") - } - - TypeMismatch(expected: String, found: String) { - description("type mismatch!") - display("expected type `{}`, but found `{}`", expected, found) - } - - MissingShapeError { - description("ndarray `shape()` returns `None`") - display("called `Option::unwrap()` on a `None` value") - } - - AtMostOneReturn { - description("TVM functions accept at most one return value") - } +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +pub use failure::Error; + +#[derive(Debug, Fail)] +#[fail(display = "Cannot convert from an empty array.")] +pub struct EmptyArrayError; + +#[derive(Debug, Fail)] +#[fail(display = "Handle `{}` is null.", name)] +pub struct NullHandleError { + pub name: String, +} - } +#[derive(Debug, Fail)] +#[fail(display = "Function was not set in `function::Builder`")] +pub struct FunctionNotFoundError; - foreign_links { - ShapeError(rust_ndarray::ShapeError); - NulError(ffi::NulError); - IntoStringError(ffi::IntoStringError); - CommonError(common_errors::Error); - } +#[derive(Debug, Fail)] +#[fail(display = "Expected type `{}` but found `{}`", expected, actual)] +pub struct TypeMismatchError { + pub expected: String, + pub actual: String, } -impl From for Error { - fn from(_err: option::NoneError) -> Self { - ErrorKind::MissingShapeError.into() - } -} +#[derive(Debug, Fail)] +#[fail(display = "Missing NDArray shape.")] +pub struct MissingShapeError; diff --git a/rust/frontend/src/function.rs b/rust/frontend/src/function.rs index fa6bed141076..948711276304 100644 --- a/rust/frontend/src/function.rs +++ b/rust/frontend/src/function.rs @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + //! This module provides an idiomatic Rust API for creating and working with TVM functions. //! //! For calling an already registered TVM function use [`function::Builder`] @@ -15,14 +34,20 @@ use std::{ sync::Mutex, }; -use crate::{ts, ErrorKind, Module, Result, TVMArgValue, TVMRetValue, TVMTypeCode, TVMValue}; +use failure::Error; + +use crate::{ + errors, + ffi::{self, TVMValue}, + Module, TVMArgValue, TVMRetValue, +}; lazy_static! { static ref GLOBAL_FUNCTIONS: Mutex>> = { let mut out_size = 0 as c_int; let name = ptr::null_mut() as *mut c_char; let mut out_array = name as *mut _; - check_call!(ts::TVMFuncListGlobalNames( + check_call!(ffi::TVMFuncListGlobalNames( &mut out_size as *mut _, &mut out_array )); @@ -37,17 +62,14 @@ lazy_static! { } /// Wrapper around TVM function handle which includes `is_global` -/// indicating whether the function is global or not, `is_released` -/// to hint dropping the function handle and `is_cloned` showing +/// indicating whether the function is global or not, and `is_cloned` showing /// not to drop a cloned function from Rust side. /// The value of these fields can be accessed through their respective methods. #[derive(Debug, Hash)] pub struct Function { - pub(crate) handle: ts::TVMFunctionHandle, + pub(crate) handle: ffi::TVMFunctionHandle, // whether the registered function is global or not. is_global: bool, - // whether the function has been dropped from frontend or not. - is_released: bool, // whether the function has been cloned from frontend or not. is_cloned: bool, } @@ -56,29 +78,30 @@ unsafe impl Send for Function {} unsafe impl Sync for Function {} impl Function { - pub(crate) fn new(handle: ts::TVMFunctionHandle, is_global: bool, is_released: bool) -> Self { + pub(crate) fn new(handle: ffi::TVMFunctionHandle) -> Self { Function { handle: handle, - is_global: is_global, - is_released: is_released, + is_global: false, is_cloned: false, } } /// For a given function, it returns a function by name. - pub fn get>(name: S, is_global: bool) -> Option<&'static Function> { + pub fn get>(name: S) -> Option<&'static Function> { let mut globals = GLOBAL_FUNCTIONS.lock().unwrap(); globals.get_mut(name.as_ref()).and_then(|maybe_func| { if maybe_func.is_none() { let name = CString::new(name.as_ref()).unwrap(); - let mut handle = ptr::null_mut() as ts::TVMFunctionHandle; - check_call!(ts::TVMFuncGetGlobal( + let mut handle = ptr::null_mut() as ffi::TVMFunctionHandle; + check_call!(ffi::TVMFuncGetGlobal( name.as_ptr() as *const c_char, &mut handle as *mut _ )); - maybe_func.replace(Function::new( - handle, is_global, false, /* is_released */ - )); + maybe_func.replace(Function { + handle: handle, + is_global: true, + is_cloned: false, + }); } unsafe { std::mem::transmute::, Option<&'static Function>>( @@ -89,7 +112,7 @@ impl Function { } /// Returns the underlying TVM function handle. - pub fn handle(&self) -> ts::TVMFunctionHandle { + pub fn handle(&self) -> ffi::TVMFunctionHandle { self.handle } @@ -98,12 +121,6 @@ impl Function { self.is_global } - /// Returns `true` if the underlying TVM function has been released - /// from the frontend and `false` otherwise. - pub fn is_released(&self) -> bool { - self.is_released - } - /// Returns `true` if the underlying TVM function has been cloned /// from the frontend and `false` otherwise. pub fn is_cloned(&self) -> bool { @@ -113,24 +130,18 @@ impl Function { impl Clone for Function { fn clone(&self) -> Function { - if !self.is_released && !self.is_cloned { - Self { - handle: self.handle, - is_global: self.is_global, - is_released: self.is_released, - is_cloned: true, - } - } else { - Function::new(self.handle, self.is_global, self.is_released) + Self { + handle: self.handle, + is_global: self.is_global, + is_cloned: true, } } } impl Drop for Function { fn drop(&mut self) { - if !self.is_released && !self.is_global && !self.is_cloned { - check_call!(ts::TVMFuncFree(self.handle)); - self.is_released = true; + if !self.is_global && !self.is_cloned { + check_call!(ffi::TVMFuncFree(self.handle)); } } } @@ -138,17 +149,17 @@ impl Drop for Function { /// Function builder in order to create and call functions. /// /// *Note:* Currently TVM functions accept *at most* one return value. -#[derive(Debug, Clone, Default)] +#[derive(Default)] pub struct Builder<'a, 'm> { pub func: Option<&'m Function>, - pub arg_buf: Option]>>, + pub arg_buf: Vec>, pub ret_buf: Option, } impl<'a, 'm> Builder<'a, 'm> { pub fn new( func: Option<&'m Function>, - arg_buf: Option]>>, + arg_buf: Vec>, ret_buf: Option, ) -> Self { Self { @@ -158,123 +169,63 @@ impl<'a, 'm> Builder<'a, 'm> { } } - pub fn get_function(&mut self, name: &'m str, is_global: bool) -> &mut Self { - self.func = Function::get(name, is_global); + pub fn get_function(&mut self, name: &'m str) -> &mut Self { + self.func = Function::get(name); self } /// Pushes a [`TVMArgValue`] into the function argument buffer. - pub fn arg<'b, T: ?Sized>(&mut self, arg: &'b T) -> &mut Self + pub fn arg(&mut self, arg: T) -> &mut Self where - TVMValue: From<&'b T>, - TVMTypeCode: From<&'b T>, + TVMArgValue<'a>: From, { - let tvm_arg = TVMArgValue::from(arg); - if self.arg_buf.is_none() { - self.arg_buf = Some(Box::new([tvm_arg])); - } else { - let new_arg_buf = self.arg_buf.take().map(|bbuf| { - let mut new_arg_buf = Vec::from(bbuf); - new_arg_buf.push(tvm_arg); - let new_len = new_arg_buf.len(); - new_arg_buf.truncate(new_len); - new_arg_buf.into_boxed_slice() - }); - self.arg_buf = new_arg_buf; - } + self.arg_buf.push(arg.into()); self } /// Pushes multiple [`TVMArgValue`]s into the function argument buffer. - pub fn args<'b, T: 'b + ?Sized, I>(&mut self, args: I) -> &mut Self + pub fn args(&mut self, args: I) -> &mut Self where - I: IntoIterator, - TVMValue: From<&'b T>, - TVMTypeCode: From<&'b T>, + I: IntoIterator, + TVMArgValue<'a>: From<&'a T>, { - for arg in args { + args.into_iter().for_each(|arg| { self.arg(&arg); - } + }); self } /// Sets an output for a function that requirs a mutable output to be provided. /// See the `basics` in tests for an example. - pub fn set_output<'b, T: 'b + ?Sized>(&mut self, arg: &'b mut T) -> Result<&mut Self> + pub fn set_output(&mut self, ret: T) -> &mut Self where - TVMValue: From<&'b T>, - TVMTypeCode: From<&'b T>, + TVMRetValue: From, { - if self.ret_buf.is_none() { - let tvm_ret = - unsafe { TVMRetValue::from_tvm_value(TVMValue::from(arg), TVMTypeCode::from(arg)) }; - self.ret_buf = Some(tvm_ret); - } else { - bail!(ErrorKind::AtMostOneReturn) - } - Ok(self) + self.ret_buf = Some(ret.into()); + self } /// Calls the function that created from `Builder`. - pub fn invoke(&mut self) -> Result { - self.clone()(()) - } -} - -impl<'a, 'm> FnOnce<((),)> for Builder<'a, 'm> { - type Output = Result; - extern "rust-call" fn call_once(self, _: ((),)) -> Self::Output { - if self.func.is_none() { - bail!("{}", ErrorKind::FunctionNotFound); - } - - let mut ret_val = unsafe { mem::uninitialized::() }; - let mut ret_type_code = 0 as c_int; - if self.arg_buf.is_some() { - let arg_buf = self.arg_buf?; - let mut num_args = arg_buf.len(); - let mut values = arg_buf - .iter() - .map(|tav| tav.value.inner) - .collect::>(); - let mut tcodes = arg_buf - .iter() - .map(|tav| tav.type_code as c_int) - .collect::>(); - - if self.ret_buf.is_some() { - num_args = num_args + 1; - let ret_buf = self.ret_buf?; - let (ret_val, ret_type_code) = TVMRetValue::into_tvm_value(ret_buf); - values.append(&mut vec![ret_val.inner]); - tcodes.append(&mut vec![ret_type_code as c_int]); - } - - values.truncate(num_args); - tcodes.truncate(num_args); - check_call!(ts::TVMFuncCall( - self.func?.handle, - values.as_mut_ptr(), - tcodes.as_mut_ptr(), - num_args as c_int, - &mut ret_val as *mut _, - &mut ret_type_code as *mut _ - )); - } else { - check_call!(ts::TVMFuncCall( - self.func?.handle, - ptr::null_mut(), - ptr::null_mut(), - 0 as c_int, - &mut ret_val as *mut _, - &mut ret_type_code as *mut _ - )); - } + pub fn invoke(&mut self) -> Result { + #![allow(unused_unsafe)] + ensure!(self.func.is_some(), errors::FunctionNotFoundError); + + let num_args = self.arg_buf.len(); + let (mut values, mut type_codes): (Vec, Vec) = + self.arg_buf.iter().map(|arg| arg.to_tvm_value()).unzip(); + + let mut ret_val = unsafe { std::mem::uninitialized::() }; + let mut ret_type_code = 0i32; + check_call!(ffi::TVMFuncCall( + self.func.ok_or(errors::FunctionNotFoundError)?.handle, + values.as_mut_ptr(), + type_codes.as_mut_ptr() as *mut i32, + num_args as c_int, + &mut ret_val as *mut _, + &mut ret_type_code as *mut _ + )); - let ret = unsafe { - TVMRetValue::from_tvm_value(TVMValue::new(ret_val), (ret_type_code as i64).into()) - }; - Ok(ret) + Ok(unsafe { TVMRetValue::from_tvm_value(ret_val, ret_type_code as u32) }) } } @@ -282,46 +233,44 @@ impl<'a, 'm> FnOnce<((),)> for Builder<'a, 'm> { /// TVM functions. impl<'a, 'm> From<&'m Function> for Builder<'a, 'm> { fn from(func: &'m Function) -> Self { - Builder::new(Some(func), None, None) + Builder::new(Some(func), Vec::new(), None) } } /// Converts a mutable reference of a [`Module`] to [`Builder`]. impl<'a, 'm> From<&'m mut Module> for Builder<'a, 'm> { fn from(module: &'m mut Module) -> Self { - Builder::new(module.entry(), None, None) + Builder::new(module.entry(), Vec::new(), None) } } unsafe extern "C" fn tvm_callback( - args: *mut ts::TVMValue, + args: *mut ffi::TVMValue, type_codes: *mut c_int, num_args: c_int, - ret: ts::TVMRetValueHandle, + ret: ffi::TVMRetValueHandle, fhandle: *mut c_void, ) -> c_int { // turning off the incorrect linter complaints - #![allow(unused_assignments)] + #![allow(unused_assignments, unused_unsafe)] let len = num_args as usize; let args_list = slice::from_raw_parts_mut(args, len); let type_codes_list = slice::from_raw_parts_mut(type_codes, len); let mut local_args: Vec = Vec::new(); - let mut value = mem::uninitialized::(); + let mut value = mem::uninitialized::(); let mut tcode = mem::uninitialized::(); - let rust_fn = mem::transmute::<*mut c_void, fn(&[TVMArgValue]) -> Result>(fhandle); + let rust_fn = + mem::transmute::<*mut c_void, fn(&[TVMArgValue]) -> Result>(fhandle); for i in 0..len { value = args_list[i]; tcode = type_codes_list[i]; - if tcode == ts::TVMTypeCode_kNodeHandle as c_int - || tcode == ts::TVMTypeCode_kFuncHandle as c_int - || tcode == ts::TVMTypeCode_kModuleHandle as c_int + if tcode == ffi::TVMTypeCode_kNodeHandle as c_int + || tcode == ffi::TVMTypeCode_kFuncHandle as c_int + || tcode == ffi::TVMTypeCode_kModuleHandle as c_int { - check_call!(ts::TVMCbArgToReturn(&mut value as *mut _, tcode)); + check_call!(ffi::TVMCbArgToReturn(&mut value as *mut _, tcode)); } - local_args.push(TVMArgValue::new( - TVMValue::new(value), - (tcode as i64).into(), - )); + local_args.push(TVMArgValue::from_tvm_value(value.into(), tcode as u32)); } let rv = match rust_fn(local_args.as_slice()) { @@ -332,10 +281,9 @@ unsafe extern "C" fn tvm_callback( } }; - let (ret_val, ret_tcode) = TVMRetValue::into_tvm_value(rv); - let mut ret_val = ret_val.inner; + let (mut ret_val, ret_tcode) = rv.to_tvm_value(); let mut ret_type_code = ret_tcode as c_int; - check_call!(ts::TVMCFuncSetReturn( + check_call!(ffi::TVMCFuncSetReturn( ret, &mut ret_val as *mut _, &mut ret_type_code as *mut _, @@ -345,24 +293,25 @@ unsafe extern "C" fn tvm_callback( } unsafe extern "C" fn tvm_callback_finalizer(fhandle: *mut c_void) { - let rust_fn = mem::transmute::<*mut c_void, fn(&[TVMArgValue]) -> Result>(fhandle); + let rust_fn = + mem::transmute::<*mut c_void, fn(&[TVMArgValue]) -> Result>(fhandle); mem::drop(rust_fn); } -fn convert_to_tvm_func(f: fn(&[TVMArgValue]) -> Result) -> Function { - let mut fhandle = ptr::null_mut() as ts::TVMFunctionHandle; - let resource_handle = f as *mut fn(&[TVMArgValue]) -> Result; - check_call!(ts::TVMFuncCreateFromCFunc( +fn convert_to_tvm_func(f: fn(&[TVMArgValue]) -> Result) -> Function { + let mut fhandle = ptr::null_mut() as ffi::TVMFunctionHandle; + let resource_handle = f as *mut fn(&[TVMArgValue]) -> Result; + check_call!(ffi::TVMFuncCreateFromCFunc( Some(tvm_callback), resource_handle as *mut c_void, Some(tvm_callback_finalizer), &mut fhandle as *mut _ )); - Function::new(fhandle, false, false) + Function::new(fhandle) } /// Registers a Rust function with signature -/// `fn(&[TVMArgValue]) -> Result` +/// `fn(&[TVMArgValue]) -> Result` /// as a **global TVM packed function** from frontend to TVM backend. /// /// Use [`register_global_func`] if overriding an existing global TVM function @@ -373,7 +322,7 @@ fn convert_to_tvm_func(f: fn(&[TVMArgValue]) -> Result) -> Function /// ``` /// use std::convert::TryInto; /// -/// fn sum(args: &[TVMArgValue]) -> Result { +/// fn sum(args: &[TVMArgValue]) -> Result { /// let mut ret = 0i64; /// for arg in args.iter() { /// let arg: i64 = arg.try_into()?; @@ -391,18 +340,17 @@ fn convert_to_tvm_func(f: fn(&[TVMArgValue]) -> Result) -> Function /// assert_eq!(ret, 60); /// ``` pub fn register>( - f: fn(&[TVMArgValue]) -> Result, + f: fn(&[TVMArgValue]) -> Result, name: S, override_: bool, -) -> Result<()> { +) -> Result<(), Error> { let func = convert_to_tvm_func(f); let name = CString::new(name.as_ref())?; - check_call!(ts::TVMFuncRegisterGlobal( - name.as_ref().as_ptr() as *const c_char, + check_call!(ffi::TVMFuncRegisterGlobal( + name.into_raw(), func.handle(), override_ as c_int )); - mem::forget(name); Ok(()) } @@ -416,7 +364,7 @@ pub fn register>( /// use std::convert::TryInto; /// /// register_global_func! { -/// fn sum(args: &[TVMArgValue]) -> Result { +/// fn sum(args: &[TVMArgValue]) -> Result { /// let mut ret = 0f64; /// for arg in args.iter() { /// let arg: f64 = arg.try_into()?; @@ -437,12 +385,12 @@ pub fn register>( macro_rules! register_global_func { { $(#[$m:meta])* - fn $fn_name:ident($args:ident : &[TVMArgValue]) -> Result { + fn $fn_name:ident($args:ident : &[TVMArgValue]) -> Result { $($code:tt)* } } => {{ $(#[$m])* - fn $fn_name($args: &[TVMArgValue]) -> Result { + fn $fn_name($args: &[TVMArgValue]) -> Result { $($code)* } @@ -496,17 +444,18 @@ mod tests { #[test] fn get_fn() { - assert!(Function::get(CANARY, true).is_some()); - assert!(Function::get("does not exists!", false).is_none()); + assert!(Function::get(CANARY).is_some()); + assert!(Function::get("does not exists!").is_none()); } #[test] fn provide_args() { + let str_arg = CString::new("test").unwrap(); let mut func = Builder::default(); - func.get_function("tvm.graph_runtime.remote_create", true) - .args(&[10, 20]) - .arg(&"test".to_owned()); - assert!(func.arg_buf.is_some()); - assert_eq!(func.arg_buf.take().map(|bv| Vec::from(bv).len()), Some(3)); + func.get_function("tvm.graph_runtime.remote_create") + .arg(10) + .arg(20) + .arg(str_arg.as_c_str()); + assert_eq!(func.arg_buf.len(), 3); } } diff --git a/rust/frontend/src/lib.rs b/rust/frontend/src/lib.rs index 6e15e4f8d046..6e4123cb6217 100644 --- a/rust/frontend/src/lib.rs +++ b/rust/frontend/src/lib.rs @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + //! [TVM](https://github.com/dmlc/tvm) is a compiler stack for deep learning systems. //! //! This crate provides an idiomatic Rust API for TVM runtime frontend. @@ -11,32 +30,36 @@ //! //! Checkout the `examples` repository for more details. -#![crate_name = "tvm_frontend"] -#![recursion_limit = "1024"] -#![allow(non_camel_case_types, unused_unsafe)] -#![feature( - try_from, - try_trait, - fn_traits, - unboxed_closures, - box_syntax, - option_replace -)] +#![feature(box_syntax)] #[macro_use] -extern crate error_chain; -extern crate tvm_common as common; +extern crate failure; #[macro_use] extern crate lazy_static; extern crate ndarray as rust_ndarray; extern crate num_traits; +extern crate tvm_common; use std::{ ffi::{CStr, CString}, str, }; -use crate::common::ffi::ts; +use failure::Error; + +pub use crate::{ + bytearray::TVMByteArray, + context::{TVMContext, TVMDeviceType}, + errors::*, + function::Function, + module::Module, + ndarray::NDArray, + tvm_common::{ + errors as common_errors, + ffi::{self, TVMType}, + packed_func::{TVMArgValue, TVMRetValue}, + }, +}; // Macro to check the return call to TVM runtime shared library. macro_rules! check_call { @@ -50,7 +73,7 @@ macro_rules! check_call { /// Gets the last error message. pub fn get_last_error() -> &'static str { unsafe { - match CStr::from_ptr(ts::TVMGetLastError()).to_str() { + match CStr::from_ptr(ffi::TVMGetLastError()).to_str() { Ok(s) => s, Err(_) => "Invalid UTF-8 message", } @@ -60,7 +83,7 @@ pub fn get_last_error() -> &'static str { pub(crate) fn set_last_error(err: &Error) { let c_string = CString::new(err.to_string()).unwrap(); unsafe { - ts::TVMAPISetLastError(c_string.as_ptr()); + ffi::TVMAPISetLastError(c_string.as_ptr()); } } @@ -71,27 +94,11 @@ pub mod context; pub mod errors; pub mod module; pub mod ndarray; -pub mod ty; pub mod value; -pub use crate::{ - bytearray::TVMByteArray, - common::{ - errors as common_errors, - ty::TVMTypeCode, - value::{TVMArgValue, TVMRetValue, TVMValue}, - }, - context::{TVMContext, TVMDeviceType}, - errors::*, - function::Function, - module::Module, - ndarray::NDArray, - ty::TVMType, -}; - /// Outputs the current TVM version. pub fn version() -> &'static str { - match str::from_utf8(ts::TVM_VERSION) { + match str::from_utf8(ffi::TVM_VERSION) { Ok(s) => s, Err(_) => "Invalid UTF-8 string", } @@ -108,8 +115,8 @@ mod tests { #[test] fn set_error() { - let err = ErrorKind::EmptyArray; + let err = errors::EmptyArrayError; set_last_error(&err.into()); - assert_eq!(get_last_error().trim(), ErrorKind::EmptyArray.to_string()); + assert_eq!(get_last_error().trim(), errors::EmptyArrayError.to_string()); } } diff --git a/rust/frontend/src/module.rs b/rust/frontend/src/module.rs index c12d9d48cf13..4fbe0b5cc8ab 100644 --- a/rust/frontend/src/module.rs +++ b/rust/frontend/src/module.rs @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + //! Provides the [`Module`] type and methods for working with runtime TVM modules. use std::{ @@ -8,30 +27,27 @@ use std::{ ptr, }; -use crate::ts; +use failure::Error; +use tvm_common::ffi; -use crate::{function::Function, ErrorKind, Result}; +use crate::{errors, function::Function}; const ENTRY_FUNC: &'static str = "__tvm_main__"; /// Wrapper around TVM module handle which contains an entry function. /// The entry function can be applied to an imported module through [`entry_func`]. -/// Also [`is_released`] shows whether the module is dropped or not. /// /// [`entry_func`]:struct.Module.html#method.entry_func -/// [`is_released`]:struct.Module.html#method.is_released #[derive(Debug, Clone)] pub struct Module { - pub(crate) handle: ts::TVMModuleHandle, - is_released: bool, + pub(crate) handle: ffi::TVMModuleHandle, entry_func: Option, } impl Module { - pub(crate) fn new(handle: ts::TVMModuleHandle, is_released: bool) -> Self { + pub(crate) fn new(handle: ffi::TVMModuleHandle) -> Self { Self { handle, - is_released, entry_func: None, } } @@ -44,62 +60,70 @@ impl Module { } /// Gets a function by name from a registered module. - pub fn get_function(&self, name: &str, query_import: bool) -> Result { + pub fn get_function(&self, name: &str, query_import: bool) -> Result { let name = CString::new(name)?; - let mut fhandle = ptr::null_mut() as ts::TVMFunctionHandle; - check_call!(ts::TVMModGetFunction( + let mut fhandle = ptr::null_mut() as ffi::TVMFunctionHandle; + check_call!(ffi::TVMModGetFunction( self.handle, name.as_ptr() as *const c_char, query_import as c_int, &mut fhandle as *mut _ )); - if fhandle.is_null() { - bail!(ErrorKind::NullHandle(format!("{}", name.into_string()?))) - } else { - Ok(Function::new(fhandle, false, false)) - } + ensure!( + !fhandle.is_null(), + errors::NullHandleError { + name: format!("{}", name.into_string()?) + } + ); + Ok(Function::new(fhandle)) } /// Imports a dependent module such as `.ptx` for gpu. pub fn import_module(&self, dependent_module: Module) { - check_call!(ts::TVMModImport(self.handle, dependent_module.handle)) + check_call!(ffi::TVMModImport(self.handle, dependent_module.handle)) } /// Loads a module shared library from path. - pub fn load>(path: &P) -> Result { - let ext = path.as_ref().extension()?.to_str()?; - let func = Function::get("module._LoadFromFile", true /* is_global */) - .expect("API function always exists"); - let ret: Module = call_packed!(func, path.as_ref().to_str()?, ext)?.try_into()?; + pub fn load>(path: &P) -> Result { + let ext = CString::new( + path.as_ref() + .extension() + .unwrap_or(std::ffi::OsStr::new("")) + .to_str() + .ok_or_else(|| { + format_err!("Bad module load path: `{}`.", path.as_ref().display()) + })?, + )?; + let func = Function::get("module._LoadFromFile").expect("API function always exists"); + let cpath = + CString::new(path.as_ref().to_str().ok_or_else(|| { + format_err!("Bad module load path: `{}`.", path.as_ref().display()) + })?)?; + let ret: Module = call_packed!(func, cpath.as_c_str(), ext.as_c_str())?.try_into()?; Ok(ret) } /// Checks if a target device is enabled for a module. pub fn enabled(&self, target: &str) -> bool { - let func = Function::get("module._Enabled", true /* is_global */) - .expect("API function always exists"); + let func = Function::get("module._Enabled").expect("API function always exists"); // `unwrap` is safe here because if there is any error during the // function call, it would occur in `call_packed!`. - let ret: i64 = call_packed!(func, target).unwrap().try_into().unwrap(); + let tgt = CString::new(target).unwrap(); + let ret: i64 = call_packed!(func, tgt.as_c_str()) + .unwrap() + .try_into() + .unwrap(); ret != 0 } /// Returns the underlying module handle. - pub fn handle(&self) -> ts::TVMModuleHandle { + pub fn handle(&self) -> ffi::TVMModuleHandle { self.handle } - - /// Returns true if the underlying module has been dropped and false otherwise. - pub fn is_released(&self) -> bool { - self.is_released - } } impl Drop for Module { fn drop(&mut self) { - if !self.is_released { - check_call!(ts::TVMModFree(self.handle)); - self.is_released = true; - } + check_call!(ffi::TVMModFree(self.handle)); } } diff --git a/rust/frontend/src/ndarray.rs b/rust/frontend/src/ndarray.rs index 44dfcca3b320..885fcfac8e3d 100644 --- a/rust/frontend/src/ndarray.rs +++ b/rust/frontend/src/ndarray.rs @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + //! This module implements the [`NDArray`] type for working with *TVM tensors* or //! coverting from a Rust's ndarray to TVM `NDArray`. //! @@ -23,34 +42,34 @@ //! [`copy_from_buffer`]:struct.NDArray.html#method.copy_from_buffer //! [`copy_to_ctx`]:struct.NDArray.html#method.copy_to_ctx -use std::{convert::TryFrom, mem, os::raw::c_int, ptr, slice}; +use std::{convert::TryFrom, mem, os::raw::c_int, ptr, slice, str::FromStr}; -use crate::rust_ndarray::{Array, ArrayD}; +use failure::Error; use num_traits::Num; +use rust_ndarray::{Array, ArrayD}; +use tvm_common::{ffi, TVMType}; -use crate::ts; - -use crate::{Error, ErrorKind, Result, TVMByteArray, TVMContext, TVMType}; +use crate::{errors, TVMByteArray, TVMContext}; /// See the [`module-level documentation`](../ndarray/index.html) for more details. /// /// Wrapper around TVM array handle. #[derive(Debug)] pub struct NDArray { - pub(crate) handle: ts::TVMArrayHandle, + pub(crate) handle: ffi::TVMArrayHandle, is_view: bool, } impl NDArray { - pub(crate) fn new(handle: ts::TVMArrayHandle, is_view: bool) -> Self { + pub(crate) fn new(handle: ffi::TVMArrayHandle) -> Self { NDArray { handle: handle, - is_view: is_view, + is_view: true, } } /// Returns the underlying array handle. - pub fn handle(&self) -> ts::TVMArrayHandle { + pub fn handle(&self) -> ffi::TVMArrayHandle { self.handle } @@ -99,12 +118,13 @@ impl NDArray { } /// Shows whether the underlying ndarray is contiguous in memory or not. - pub fn is_contiguous(&self) -> Result { + pub fn is_contiguous(&self) -> Result { Ok(match self.strides() { None => true, Some(strides) => { - // MissingShapeError in case shape is not determined - self.shape()? + // errors::MissingShapeError in case shape is not determined + self.shape() + .ok_or(errors::MissingShapeError)? .iter() .zip(strides) .rfold( @@ -138,14 +158,16 @@ impl NDArray { /// assert_eq!(ndarray.shape(), Some(shape)); /// assert_eq!(ndarray.to_vec::().unwrap(), data); /// ``` - pub fn to_vec(&self) -> Result> { - if self.shape().is_none() { - bail!("{}", ErrorKind::EmptyArray); - } - let earr = NDArray::empty(self.shape()?, TVMContext::cpu(0), self.dtype()); + pub fn to_vec(&self) -> Result, Error> { + ensure!(self.shape().is_some(), errors::EmptyArrayError); + let earr = NDArray::empty( + self.shape().ok_or(errors::MissingShapeError)?, + TVMContext::cpu(0), + self.dtype(), + ); let target = self.copy_to_ndarray(earr)?; let arr = unsafe { *(target.handle) }; - let sz = self.size()? as usize; + let sz = self.size().ok_or(errors::MissingShapeError)?; let mut v: Vec = Vec::with_capacity(sz * mem::size_of::()); unsafe { v.as_mut_ptr() @@ -156,9 +178,9 @@ impl NDArray { } /// Converts the NDArray to [`TVMByteArray`]. - pub fn to_bytearray(&self) -> Result { + pub fn to_bytearray(&self) -> Result { let v = self.to_vec::()?; - Ok(TVMByteArray::from(&v)) + Ok(TVMByteArray::from(v)) } /// Creates an NDArray from a mutable buffer of types i32, u32 or f32 in cpu. @@ -176,7 +198,7 @@ impl NDArray { /// *Note*: if something goes wrong during the copy, it will panic /// from TVM side. See `TVMArrayCopyFromBytes` in `include/tvm/runtime/c_runtime_api.h`. pub fn copy_from_buffer(&mut self, data: &mut [T]) { - check_call!(ts::TVMArrayCopyFromBytes( + check_call!(ffi::TVMArrayCopyFromBytes( self.handle, data.as_ptr() as *mut _, data.len() * mem::size_of::() @@ -184,27 +206,31 @@ impl NDArray { } /// Copies the NDArray to another target NDArray. - pub fn copy_to_ndarray(&self, target: NDArray) -> Result { + pub fn copy_to_ndarray(&self, target: NDArray) -> Result { if self.dtype() != target.dtype() { bail!( "{}", - ErrorKind::TypeMismatch( - format!("{}", self.dtype().to_string()), - format!("{}", target.dtype().to_string()), - ) + errors::TypeMismatchError { + expected: format!("{}", self.dtype().to_string()), + actual: format!("{}", target.dtype().to_string()), + } ); } - check_call!(ts::TVMArrayCopyFromTo( + check_call!(ffi::TVMArrayCopyFromTo( self.handle, target.handle, - ptr::null_mut() as ts::TVMStreamHandle + ptr::null_mut() as ffi::TVMStreamHandle )); Ok(target) } /// Copies the NDArray to a target context. - pub fn copy_to_ctx(&self, target: &TVMContext) -> Result { - let tmp = NDArray::empty(self.shape()?, target.clone(), self.dtype()); + pub fn copy_to_ctx(&self, target: &TVMContext) -> Result { + let tmp = NDArray::empty( + self.shape().ok_or(errors::MissingShapeError)?, + target.clone(), + self.dtype(), + ); let copy = self.copy_to_ndarray(tmp)?; Ok(copy) } @@ -214,28 +240,34 @@ impl NDArray { rnd: &ArrayD, ctx: TVMContext, dtype: TVMType, - ) -> Result { + ) -> Result { let mut shape = rnd.shape().to_vec(); let mut nd = NDArray::empty(&mut shape, ctx, dtype); let mut buf = Array::from_iter(rnd.into_iter().map(|&v| v as T)); - nd.copy_from_buffer(buf.as_slice_mut()?); + nd.copy_from_buffer( + buf.as_slice_mut() + .expect("Array from iter must be contiguous."), + ); Ok(nd) } /// Allocates and creates an empty NDArray given the shape, context and dtype. pub fn empty(shape: &[usize], ctx: TVMContext, dtype: TVMType) -> NDArray { - let mut handle = ptr::null_mut() as ts::TVMArrayHandle; - check_call!(ts::TVMArrayAlloc( + let mut handle = ptr::null_mut() as ffi::TVMArrayHandle; + check_call!(ffi::TVMArrayAlloc( shape.as_ptr() as *const i64, shape.len() as c_int, - dtype.inner.code as c_int, - dtype.inner.bits as c_int, - dtype.inner.lanes as c_int, + dtype.code as c_int, + dtype.bits as c_int, + dtype.lanes as c_int, ctx.device_type.0 as c_int, ctx.device_id as c_int, &mut handle as *mut _, )); - NDArray::new(handle, false) + NDArray { + handle, + is_view: false, + } } } @@ -243,23 +275,25 @@ macro_rules! impl_from_ndarray_rustndarray { ($type:ty, $type_name:tt) => { impl<'a> TryFrom<&'a NDArray> for ArrayD<$type> { type Error = Error; - fn try_from(nd: &NDArray) -> Result> { - if nd.shape().is_none() { - bail!("{}", ErrorKind::EmptyArray); - } - assert_eq!(nd.dtype(), TVMType::from($type_name), "Type mismatch"); - Ok(Array::from_shape_vec(&*nd.shape()?, nd.to_vec::<$type>()?)?) + fn try_from(nd: &NDArray) -> Result, Self::Error> { + ensure!(nd.shape().is_some(), errors::MissingShapeError); + assert_eq!(nd.dtype(), TVMType::from_str($type_name)?, "Type mismatch"); + Ok(Array::from_shape_vec( + &*nd.shape().ok_or(errors::MissingShapeError)?, + nd.to_vec::<$type>()?, + )?) } } impl<'a> TryFrom<&'a mut NDArray> for ArrayD<$type> { type Error = Error; - fn try_from(nd: &mut NDArray) -> Result> { - if nd.shape().is_none() { - bail!("{}", ErrorKind::EmptyArray); - } - assert_eq!(nd.dtype(), TVMType::from($type_name), "Type mismatch"); - Ok(Array::from_shape_vec(&*nd.shape()?, nd.to_vec::<$type>()?)?) + fn try_from(nd: &mut NDArray) -> Result, Self::Error> { + ensure!(nd.shape().is_some(), errors::MissingShapeError); + assert_eq!(nd.dtype(), TVMType::from_str($type_name)?, "Type mismatch"); + Ok(Array::from_shape_vec( + &*nd.shape().ok_or(errors::MissingShapeError)?, + nd.to_vec::<$type>()?, + )?) } } }; @@ -272,7 +306,7 @@ impl_from_ndarray_rustndarray!(f32, "float"); impl Drop for NDArray { fn drop(&mut self) { if !self.is_view { - check_call!(ts::TVMArrayFree(self.handle)); + check_call!(ffi::TVMArrayFree(self.handle)); } } } @@ -306,7 +340,7 @@ mod tests { fn basics() { let shape = &mut [1, 2, 3]; let ctx = TVMContext::cpu(0); - let ndarray = NDArray::empty(shape, ctx, TVMType::from("int32")); + let ndarray = NDArray::empty(shape, ctx, TVMType::from_str("int32").unwrap()); assert_eq!(ndarray.shape().unwrap(), shape); assert_eq!( ndarray.size().unwrap(), @@ -322,7 +356,7 @@ mod tests { let shape = &mut [4]; let mut data = vec![1i32, 2, 3, 4]; let ctx = TVMContext::cpu(0); - let mut ndarray = NDArray::empty(shape, ctx, TVMType::from("int32")); + let mut ndarray = NDArray::empty(shape, ctx, TVMType::from_str("int32").unwrap()); assert!(ndarray.to_vec::().is_ok()); ndarray.copy_from_buffer(&mut data); assert_eq!(ndarray.shape().unwrap(), shape); @@ -331,7 +365,11 @@ mod tests { assert!(ndarray.is_contiguous().is_ok()); assert_eq!(ndarray.byte_offset(), 0); let mut shape = vec![4]; - let e = NDArray::empty(&mut shape, TVMContext::cpu(0), TVMType::from("int32")); + let e = NDArray::empty( + &mut shape, + TVMContext::cpu(0), + TVMType::from_str("int32").unwrap(), + ); let nd = ndarray.copy_to_ndarray(e); assert!(nd.is_ok()); assert_eq!(nd.unwrap().to_vec::().unwrap(), data); @@ -343,9 +381,13 @@ mod tests { let mut shape = vec![4]; let mut data = vec![1f32, 2., 3., 4.]; let ctx = TVMContext::cpu(0); - let mut nd_float = NDArray::empty(&mut shape, ctx.clone(), TVMType::from("float32")); + let mut nd_float = NDArray::empty( + &mut shape, + ctx.clone(), + TVMType::from_str("float32").unwrap(), + ); nd_float.copy_from_buffer(&mut data); - let empty_int = NDArray::empty(&mut shape, ctx, TVMType::from("int32")); + let empty_int = NDArray::empty(&mut shape, ctx, TVMType::from_str("int32").unwrap()); nd_float.copy_to_ndarray(empty_int).unwrap(); } @@ -354,8 +396,12 @@ mod tests { let a = Array::from_shape_vec((2, 2), vec![1f32, 2., 3., 4.]) .unwrap() .into_dyn(); - let nd = - NDArray::from_rust_ndarray(&a, TVMContext::cpu(0), TVMType::from("float32")).unwrap(); + let nd = NDArray::from_rust_ndarray( + &a, + TVMContext::cpu(0), + TVMType::from_str("float32").unwrap(), + ) + .unwrap(); assert_eq!(nd.shape().unwrap(), &mut [2, 2]); let rnd: ArrayD = ArrayD::try_from(&nd).unwrap(); assert!(rnd.all_close(&a, 1e-8f32)); diff --git a/rust/frontend/src/ty.rs b/rust/frontend/src/ty.rs deleted file mode 100644 index 7e912a517e1d..000000000000 --- a/rust/frontend/src/ty.rs +++ /dev/null @@ -1,150 +0,0 @@ -//! This module implements the required conversions from Rust types to TVM types. -//! -//! In TVM frontend only conversions from Rust's 32-bits (POD) numeric types (i32, u32, f32) -//! and 64-bits pointers are supported. - -use std::{ - fmt::{self, Display, Formatter}, - ops::{Deref, DerefMut}, -}; - -use crate::ts; - -use crate::{Function, Module, NDArray, TVMByteArray, TVMContext, TVMDeviceType, TVMTypeCode}; - -macro_rules! impl_prim_type { - ($type:ty, $variant:ident) => { - impl From<$type> for TVMTypeCode { - fn from(_arg: $type) -> Self { - TVMTypeCode::$variant - } - } - - impl<'a> From<&'a $type> for TVMTypeCode { - fn from(_arg: &$type) -> Self { - TVMTypeCode::$variant - } - } - - impl<'a> From<&'a mut $type> for TVMTypeCode { - fn from(_arg: &mut $type) -> Self { - TVMTypeCode::$variant - } - } - }; -} - -impl_prim_type!(TVMDeviceType, kDLInt); -impl_prim_type!(TVMContext, kTVMContext); -impl_prim_type!(TVMType, kTVMType); -impl_prim_type!(Function, kFuncHandle); -impl_prim_type!(Module, kModuleHandle); -impl_prim_type!(NDArray, kArrayHandle); -impl_prim_type!(TVMByteArray, kBytes); - -/// See the [module-level documentation](../ty/index.html) for more details. -/// -/// Wrapper around underlying TVMType -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub struct TVMType { - // inner fields are (code: u8, bits: u8, lanes: u16) - pub inner: ts::TVMType, -} - -impl TVMType { - pub(crate) fn new(type_code: u8, bits: u8, lanes: u16) -> Self { - TVMType { - inner: ts::TVMType { - code: type_code, - bits: bits, - lanes: lanes, - }, - } - } -} - -/// Implements TVMType conversion from `&str` of general format `{dtype}{bits}x{lanes}` -/// such as "int32", "float32" or with lane "float32x1". -impl<'a> From<&'a str> for TVMType { - fn from(type_str: &'a str) -> Self { - if type_str == "bool" { - return TVMType::new(1, 1, 1); - } - - let mut type_lanes = type_str.split("x"); - let typ = type_lanes.next().expect("Missing dtype"); - let lanes = type_lanes - .next() - .map(|l| u16::from_str_radix(l, 10).expect(&format!("Bad dtype lanes: {}", l))) - .unwrap_or(1); - let (type_name, bits) = match typ.find(char::is_numeric) { - Some(idx) => { - let (name, bits_str) = typ.split_at(idx); - ( - name, - u8::from_str_radix(bits_str, 10) - .expect(&format!("Bad dtype bits: {}", bits_str)), - ) - } - None => (typ, 32), - }; - - let type_code = match type_name { - "int" => 0, - "uint" => 1, - "float" => 2, - "handle" => 3, - _ => unimplemented!(), - }; - - TVMType::new(type_code, bits, lanes) - } -} - -impl Display for TVMType { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - let ts::TVMType { code, bits, lanes } = self.inner; - if bits == 1 && lanes == 1 { - return write!(f, "bool"); - } - let mut tcode_str = match code { - 0 => "int", - 1 => "uint", - 2 => "float", - 4 => "handle", - _ => "Unknown", - } - .to_string(); - - tcode_str += &bits.to_string(); - if lanes > 1 { - tcode_str += &format!("x{}", lanes.to_string()); - } - f.write_str(&tcode_str) - } -} - -impl From for ts::DLDataType { - fn from(dtype: TVMType) -> Self { - dtype.inner - } -} - -impl From for TVMType { - fn from(dtype: ts::DLDataType) -> Self { - Self::new(dtype.code, dtype.bits, dtype.lanes) - } -} - -impl Deref for TVMType { - type Target = ts::TVMType; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl DerefMut for TVMType { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.inner - } -} diff --git a/rust/frontend/src/value.rs b/rust/frontend/src/value.rs index 9fad7de4984a..b829d9183703 100644 --- a/rust/frontend/src/value.rs +++ b/rust/frontend/src/value.rs @@ -1,240 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + //! This module implements [`TVMArgValue`] and [`TVMRetValue`] types //! and their conversions needed for the types used in frontend crate. //! `TVMRetValue` is the owned version of `TVMPODValue`. -use std::{convert::TryFrom, mem, os::raw::c_void}; +use std::convert::TryFrom; -use crate::{ - common_errors::*, ts, Function, Module, NDArray, TVMArgValue, TVMByteArray, TVMContext, - TVMDeviceType, TVMRetValue, TVMType, TVMTypeCode, TVMValue, +use tvm_common::{ + errors::ValueDowncastError, + ffi::{TVMArrayHandle, TVMFunctionHandle, TVMModuleHandle}, + try_downcast, }; -macro_rules! impl_tvm_val_from_handle { - ($($ty:ty),+) => { - $( - impl<'a> From<&'a $ty> for TVMValue { - fn from(arg: &$ty) -> Self { - let inner = ts::TVMValue { - v_handle: arg.handle as *mut _ as *mut c_void, - }; - Self::new(inner) - } - } - )+ - } -} - -impl_tvm_val_from_handle!(Module, Function, NDArray); - -impl<'a> From<&'a TVMType> for TVMValue { - fn from(ty: &TVMType) -> Self { - let inner = ts::TVMValue { v_type: ty.inner }; - Self::new(inner) - } -} - -impl<'a> From<&'a TVMContext> for TVMValue { - fn from(ctx: &TVMContext) -> Self { - let inner = ts::TVMValue { - v_ctx: ctx.clone().into(), - }; - Self::new(inner) - } -} +use crate::{Function, Module, NDArray, TVMArgValue, TVMRetValue}; -impl<'a> From<&'a TVMDeviceType> for TVMValue { - fn from(dev: &TVMDeviceType) -> Self { - let inner = ts::TVMValue { - v_int64: dev.0 as i64, - }; - Self::new(inner) - } -} - -impl<'a> From<&'a TVMByteArray> for TVMValue { - fn from(barr: &TVMByteArray) -> Self { - let inner = ts::TVMValue { - v_handle: &barr.inner as *const ts::TVMByteArray as *mut c_void, - }; - Self::new(inner) - } -} - -impl<'a, 'b> TryFrom<&'b TVMArgValue<'a>> for NDArray { - type Error = Error; - fn try_from(arg: &TVMArgValue<'a>) -> Result { - if arg.type_code == TVMTypeCode::kArrayHandle { - let handle = unsafe { arg.value.inner.v_handle }; - let arr_handle = unsafe { mem::transmute::<*mut c_void, ts::TVMArrayHandle>(handle) }; - Ok(Self::new(arr_handle, true)) - } else { - bail!(ErrorKind::TryFromTVMArgValueError( - stringify!(NDArray).to_string(), - arg.type_code.to_string() - )) - } - } -} - -impl<'a, 'b> TryFrom<&'b TVMArgValue<'a>> for Module { - type Error = Error; - fn try_from(arg: &TVMArgValue<'a>) -> Result { - if arg.type_code == TVMTypeCode::kModuleHandle { - let handle = unsafe { arg.value.inner.v_handle }; - Ok(Self::new(handle, false)) - } else { - bail!(ErrorKind::TryFromTVMArgValueError( - stringify!(Module).to_string(), - arg.type_code.to_string() - )) +macro_rules! impl_handle_val { + ($type:ty, $variant:ident, $inner_type:ty, $ctor:path) => { + impl<'a> From<&'a $type> for TVMArgValue<'a> { + fn from(arg: &'a $type) -> Self { + TVMArgValue::$variant(arg.handle() as $inner_type) + } } - } -} -impl<'a, 'b> TryFrom<&'b TVMArgValue<'a>> for TVMByteArray { - type Error = Error; - fn try_from(arg: &TVMArgValue<'a>) -> Result { - if arg.type_code == TVMTypeCode::kBytes { - unsafe { - let barr_ptr = - mem::transmute::<*mut c_void, *mut ts::TVMByteArray>(arg.value.inner.v_handle); - Ok(Self::new(*barr_ptr)) + impl<'a> From<&'a mut $type> for TVMArgValue<'a> { + fn from(arg: &'a mut $type) -> Self { + TVMArgValue::$variant(arg.handle() as $inner_type) } - } else { - bail!(ErrorKind::TryFromTVMArgValueError( - stringify!(TVMByteArray).to_string(), - arg.type_code.to_string() - )) } - } -} -impl<'a, 'b> TryFrom<&'b TVMArgValue<'a>> for TVMType { - type Error = Error; - fn try_from(arg: &TVMArgValue<'a>) -> Result { - if arg.type_code == TVMTypeCode::kTVMType { - let ty = unsafe { arg.value.inner.v_type }; - Ok(TVMType::from(ty)) - } else { - bail!(ErrorKind::TryFromTVMArgValueError( - stringify!(TVMType).to_string(), - arg.type_code.to_string() - )) + impl<'a> TryFrom> for $type { + type Error = ValueDowncastError; + fn try_from(val: TVMArgValue<'a>) -> Result<$type, Self::Error> { + try_downcast!(val -> $type, |TVMArgValue::$variant(val)| { $ctor(val) }) + } } - } -} -impl<'a, 'b> TryFrom<&'b TVMArgValue<'a>> for TVMContext { - type Error = Error; - fn try_from(arg: &TVMArgValue<'a>) -> Result { - if arg.type_code == TVMTypeCode::kTVMContext { - let ty = unsafe { arg.value.inner.v_ctx }; - Ok(TVMContext::from(ty)) - } else { - bail!(ErrorKind::TryFromTVMArgValueError( - stringify!(TVMContext).to_string(), - arg.type_code.to_string() - )) + impl<'a, 'v> TryFrom<&'a TVMArgValue<'v>> for $type { + type Error = ValueDowncastError; + fn try_from(val: &'a TVMArgValue<'v>) -> Result<$type, Self::Error> { + try_downcast!(val -> $type, |TVMArgValue::$variant(val)| { $ctor(*val) }) + } } - } -} -macro_rules! impl_boxed_ret_value { - ($type:ty, $code:expr) => { impl From<$type> for TVMRetValue { - fn from(val: $type) -> Self { - TVMRetValue { - prim_value: 0, - box_value: box val, - type_code: $code, - } + fn from(val: $type) -> TVMRetValue { + TVMRetValue::$variant(val.handle() as $inner_type) } } + impl TryFrom for $type { - type Error = Error; - fn try_from(ret: TVMRetValue) -> Result<$type> { - if let Ok(val) = ret.box_value.downcast::<$type>() { - Ok(*val) - } else { - bail!(ErrorKind::TryFromTVMRetValueError( - stringify!($type).to_string(), - ret.type_code.to_string() - )) - } + type Error = ValueDowncastError; + fn try_from(val: TVMRetValue) -> Result<$type, Self::Error> { + try_downcast!(val -> $type, |TVMRetValue::$variant(val)| { $ctor(val) }) } } }; } -impl_boxed_ret_value!(TVMType, TVMTypeCode::kTVMType); -impl_boxed_ret_value!(TVMContext, TVMTypeCode::kTVMContext); -impl_boxed_ret_value!(TVMByteArray, TVMTypeCode::kBytes); - -impl TryFrom for Module { - type Error = Error; - fn try_from(ret: TVMRetValue) -> Result { - if let Ok(handle) = ret.box_value.downcast::() { - Ok(Module::new(*handle, false)) - } else { - bail!(ErrorKind::TryFromTVMRetValueError( - stringify!(TVMTypeCode::kModuleHandle).to_string(), - ret.type_code.to_string() - )) - } - } -} - -impl TryFrom for Function { - type Error = Error; - fn try_from(ret: TVMRetValue) -> Result { - if let Ok(handle) = ret.box_value.downcast::() { - Ok(Function::new(*handle, false, false)) - } else { - bail!(ErrorKind::TryFromTVMRetValueError( - stringify!(TVMTypeCode::kFuncHandle).to_string(), - ret.type_code.to_string() - )) - } - } -} - -impl TryFrom for NDArray { - type Error = Error; - fn try_from(ret: TVMRetValue) -> Result { - if let Ok(handle) = ret.box_value.downcast::() { - Ok(NDArray::new(*handle, false)) - } else { - bail!(ErrorKind::TryFromTVMRetValueError( - stringify!(TVMTypeCode::kArrayHandle).to_string(), - ret.type_code.to_string() - )) - } - } -} +impl_handle_val!(Function, FuncHandle, TVMFunctionHandle, Function::new); +impl_handle_val!(Module, ModuleHandle, TVMModuleHandle, Module::new); +impl_handle_val!(NDArray, ArrayHandle, TVMArrayHandle, NDArray::new); #[cfg(test)] mod tests { + use std::{convert::TryInto, str::FromStr}; + + use tvm_common::{TVMByteArray, TVMContext, TVMType}; + use super::*; - use std::convert::TryInto; #[test] fn bytearray() { let w = vec![1u8, 2, 3, 4, 5]; - let v = TVMByteArray::from(&w); + let v = TVMByteArray::from(w.as_slice()); let tvm: TVMByteArray = TVMRetValue::from(v).try_into().unwrap(); - assert_eq!(tvm.data(), w.iter().map(|e| *e as i8).collect::>()); + assert_eq!( + tvm.data(), + w.iter().map(|e| *e).collect::>().as_slice() + ); } #[test] fn ty() { - let t = TVMType::from("int32"); + let t = TVMType::from_str("int32").unwrap(); let tvm: TVMType = TVMRetValue::from(t).try_into().unwrap(); assert_eq!(tvm, t); } #[test] fn ctx() { - let c = TVMContext::from("gpu"); + let c = TVMContext::from_str("gpu").unwrap(); let tvm: TVMContext = TVMRetValue::from(c).try_into().unwrap(); assert_eq!(tvm, c); } diff --git a/rust/frontend/tests/basics/Cargo.toml b/rust/frontend/tests/basics/Cargo.toml index 496c0dd022e1..11fbda2bb15e 100644 --- a/rust/frontend/tests/basics/Cargo.toml +++ b/rust/frontend/tests/basics/Cargo.toml @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + [package] name = "basics" version = "0.0.0" diff --git a/rust/frontend/tests/basics/build.rs b/rust/frontend/tests/basics/build.rs index 67c21e004d02..77a3bae3627d 100644 --- a/rust/frontend/tests/basics/build.rs +++ b/rust/frontend/tests/basics/build.rs @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + fn main() { let out_dir = std::env::var("OUT_DIR").unwrap(); diff --git a/rust/frontend/tests/basics/src/main.rs b/rust/frontend/tests/basics/src/main.rs index 69b948e9117d..3690a7a69913 100644 --- a/rust/frontend/tests/basics/src/main.rs +++ b/rust/frontend/tests/basics/src/main.rs @@ -1,6 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + extern crate ndarray as rust_ndarray; extern crate tvm_frontend as tvm; +use std::str::FromStr; + use tvm::*; fn main() { @@ -12,7 +33,7 @@ fn main() { } else { (TVMContext::gpu(0), "gpu") }; - let dtype = TVMType::from("float32"); + let dtype = TVMType::from_str("float32").unwrap(); let mut arr = NDArray::empty(shape, ctx, dtype); arr.copy_from_buffer(data.as_mut_slice()); let mut ret = NDArray::empty(shape, ctx, dtype); @@ -26,8 +47,7 @@ fn main() { function::Builder::from(&mut fadd) .arg(&arr) .arg(&arr) - .set_output(&mut ret) - .unwrap() + .arg(&mut ret) .invoke() .unwrap(); diff --git a/rust/frontend/tests/basics/src/tvm_add.py b/rust/frontend/tests/basics/src/tvm_add.py index 2f3b7c8a84dd..32a605b5e227 100755 --- a/rust/frontend/tests/basics/src/tvm_add.py +++ b/rust/frontend/tests/basics/src/tvm_add.py @@ -1,4 +1,20 @@ #!/usr/bin/env python3 +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import os.path as osp import sys diff --git a/rust/frontend/tests/callback/Cargo.toml b/rust/frontend/tests/callback/Cargo.toml index 1795c5745c1f..e6df1d2c0ad3 100644 --- a/rust/frontend/tests/callback/Cargo.toml +++ b/rust/frontend/tests/callback/Cargo.toml @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + [package] name = "callback" version = "0.0.0" diff --git a/rust/frontend/tests/callback/src/bin/array.rs b/rust/frontend/tests/callback/src/bin/array.rs index 81dcadc30851..8ad010b3c859 100644 --- a/rust/frontend/tests/callback/src/bin/array.rs +++ b/rust/frontend/tests/callback/src/bin/array.rs @@ -1,4 +1,22 @@ -#![feature(extern_crate_item_prelude, try_from)] +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #![allow(unused_imports)] extern crate ndarray as rust_ndarray; @@ -6,17 +24,23 @@ extern crate ndarray as rust_ndarray; extern crate tvm_frontend as tvm; use rust_ndarray::ArrayD; -use std::convert::{TryFrom, TryInto}; +use std::{ + convert::{TryFrom, TryInto}, + str::FromStr, +}; -use tvm::*; +use tvm::{errors::Error, *}; fn main() { register_global_func! { - fn sum(args: &[TVMArgValue]) -> Result { + fn sum(args: &[TVMArgValue]) -> Result { let mut ret = 0f32; let shape = &mut [2]; for arg in args.iter() { - let e = NDArray::empty(shape, TVMContext::cpu(0), TVMType::from("float32")); + let e = NDArray::empty( + shape, TVMContext::cpu(0), + TVMType::from_str("float32").unwrap() + ); let arg: NDArray = arg.try_into()?; let arr = arg.copy_to_ndarray(e)?; let rnd: ArrayD = ArrayD::try_from(&arr)?; @@ -28,12 +52,16 @@ fn main() { let shape = &mut [2]; let mut data = vec![3f32, 4.0]; - let mut arr = NDArray::empty(shape, TVMContext::cpu(0), TVMType::from("float32")); + let mut arr = NDArray::empty( + shape, + TVMContext::cpu(0), + TVMType::from_str("float32").unwrap(), + ); arr.copy_from_buffer(data.as_mut_slice()); let mut registered = function::Builder::default(); let ret: f32 = registered - .get_function("sum", true) + .get_function("sum") .arg(&arr) .arg(&arr) .invoke() diff --git a/rust/frontend/tests/callback/src/bin/error.rs b/rust/frontend/tests/callback/src/bin/error.rs index f40f0f157815..da1812942e0d 100644 --- a/rust/frontend/tests/callback/src/bin/error.rs +++ b/rust/frontend/tests/callback/src/bin/error.rs @@ -1,4 +1,23 @@ -#![feature(extern_crate_item_prelude, panic_info_message)] +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#![feature(panic_info_message)] #![allow(unused_imports)] use std::panic; @@ -6,20 +25,20 @@ use std::panic; #[macro_use] extern crate tvm_frontend as tvm; -use tvm::*; +use tvm::{errors::Error, *}; fn main() { register_global_func! { - fn error(_args: &[TVMArgValue]) -> Result { - Err(ErrorKind::TypeMismatch( - format!("{}", "i64".to_string()), - format!("{}", "f64".to_string()), - ).into()) + fn error(_args: &[TVMArgValue]) -> Result { + Err(errors::TypeMismatchError{ + expected: "i64".to_string(), + actual: "f64".to_string(), + }.into()) } } let mut registered = function::Builder::default(); - registered.get_function("error", true); + registered.get_function("error"); assert!(registered.func.is_some()); registered.args(&[10, 20]); diff --git a/rust/frontend/tests/callback/src/bin/float.rs b/rust/frontend/tests/callback/src/bin/float.rs index 3070552843d7..7111e287187f 100644 --- a/rust/frontend/tests/callback/src/bin/float.rs +++ b/rust/frontend/tests/callback/src/bin/float.rs @@ -1,26 +1,44 @@ -#![feature(extern_crate_item_prelude, try_from)] +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #![allow(unused_imports)] #[macro_use] extern crate tvm_frontend as tvm; use std::convert::TryInto; -use tvm::*; +use tvm::{errors::Error, *}; fn main() { register_global_func! { - fn sum(args: &[TVMArgValue]) -> Result { + fn sum(args: &[TVMArgValue]) -> Result { let mut ret = 0.0; - for arg in args.iter() { + for arg in args.into_iter() { let val: f64 = arg.try_into()?; ret += val; } - Ok(TVMRetValue::from(&ret)) + Ok(TVMRetValue::from(ret)) } } let mut registered = function::Builder::default(); - registered.get_function("sum", true); + registered.get_function("sum"); assert!(registered.func.is_some()); let ret: f64 = registered .args(&[10.0f64, 20.0, 30.0]) diff --git a/rust/frontend/tests/callback/src/bin/int.rs b/rust/frontend/tests/callback/src/bin/int.rs index 30188222054a..23910a3244f7 100644 --- a/rust/frontend/tests/callback/src/bin/int.rs +++ b/rust/frontend/tests/callback/src/bin/int.rs @@ -1,25 +1,43 @@ -#![feature(extern_crate_item_prelude, try_from)] +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #![allow(unused_imports)] extern crate tvm_frontend as tvm; use std::convert::TryInto; -use tvm::*; +use tvm::{errors::Error, *}; fn main() { - fn sum(args: &[TVMArgValue]) -> Result { + fn sum(args: &[TVMArgValue]) -> Result { let mut ret = 0i64; for arg in args.iter() { let val: i64 = arg.try_into()?; ret += val; } - Ok(TVMRetValue::from(&ret)) + Ok(TVMRetValue::from(ret)) } tvm::function::register(sum, "mysum".to_owned(), false).unwrap(); let mut registered = function::Builder::default(); - registered.get_function("mysum", true); + registered.get_function("mysum"); assert!(registered.func.is_some()); let ret: i64 = registered .args(&[10, 20, 30]) diff --git a/rust/frontend/tests/callback/src/bin/string.rs b/rust/frontend/tests/callback/src/bin/string.rs index eafee31796bd..9ead58733bbb 100644 --- a/rust/frontend/tests/callback/src/bin/string.rs +++ b/rust/frontend/tests/callback/src/bin/string.rs @@ -1,31 +1,51 @@ -#![feature(extern_crate_item_prelude, try_from)] +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #![allow(unused_imports)] #[macro_use] extern crate tvm_frontend as tvm; use std::convert::TryInto; -use tvm::*; +use tvm::{errors::Error, *}; // FIXME fn main() { register_global_func! { - fn concate_str(args: &[TVMArgValue]) -> Result { + fn concate_str(args: &[TVMArgValue]) -> Result { let mut ret = "".to_string(); for arg in args.iter() { - let val: String = arg.try_into()?; - ret += val.as_str(); + let val: &str = arg.try_into()?; + ret += val; } Ok(TVMRetValue::from(ret)) } } + let a = std::ffi::CString::new("a").unwrap(); + let b = std::ffi::CString::new("b").unwrap(); + let c = std::ffi::CString::new("c").unwrap(); let mut registered = function::Builder::default(); - registered.get_function("concate_str", true); + registered.get_function("concate_str"); assert!(registered.func.is_some()); - let a = "a".to_string(); - let b = "b".to_string(); - let c = "c".to_string(); let ret: String = registered - .args(&[a, b, c]) + .arg(a.as_c_str()) + .arg(b.as_c_str()) + .arg(c.as_c_str()) .invoke() .unwrap() .try_into() diff --git a/rust/runtime/.gitignore b/rust/runtime/.gitignore deleted file mode 100644 index 230ab66104df..000000000000 --- a/rust/runtime/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -Cargo.lock -target/ -**/*.rs.bk diff --git a/rust/runtime/.travis.yml b/rust/runtime/.travis.yml index 63a3d0277c1b..e963b7c0ede5 100644 --- a/rust/runtime/.travis.yml +++ b/rust/runtime/.travis.yml @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + language: rust rust: - nightly diff --git a/rust/runtime/Cargo.toml b/rust/runtime/Cargo.toml index d48c0d98c051..8e70565a6c13 100644 --- a/rust/runtime/Cargo.toml +++ b/rust/runtime/Cargo.toml @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + [package] name = "tvm-runtime" version = "0.1.0" @@ -8,6 +25,7 @@ readme = "README.md" keywords = ["tvm", "nnvm"] categories = ["api-bindings", "science"] authors = ["TVM Contributors"] +edition = "2018" [features] default = ["nom/std"] @@ -15,15 +33,15 @@ sgx = ["nom/alloc"] [dependencies] bounded-spsc-queue = "0.4.0" -error-chain = { version = "0.12.0", default-features = false } +failure = "0.1.5" itertools = "0.7.8" lazy_static = "1.1.0" -ndarray = "0.11.2" +ndarray="0.12.1" nom = {version = "4.0.0", default-features = false } serde = "1.0.59" serde_derive = "1.0.79" serde_json = "1.0.17" -tvm-common = { version = "0.1.0", path = "../common/", features = ["runtime"] } +tvm-common = { version = "0.1.0", path = "../common/" } [target.'cfg(not(target_env = "sgx"))'.dependencies] num_cpus = "1.8.0" diff --git a/rust/runtime/src/allocator.rs b/rust/runtime/src/allocator.rs index 5f77037e25f3..97634e61e05c 100644 --- a/rust/runtime/src/allocator.rs +++ b/rust/runtime/src/allocator.rs @@ -1,9 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #[cfg(target_env = "sgx")] -use alloc::alloc::{self, Layout}; +use alloc::alloc::{self, Layout, LayoutErr}; #[cfg(not(target_env = "sgx"))] -use std::alloc::{self, Layout}; - -use crate::errors::*; +use std::alloc::{self, Layout, LayoutErr}; const DEFAULT_ALIGN_BYTES: usize = 4; @@ -15,7 +32,7 @@ pub struct Allocation { impl Allocation { /// Allocates a chunk of memory of `size` bytes with optional alignment. - pub fn new(size: usize, align: Option) -> Result { + pub fn new(size: usize, align: Option) -> Result { let alignment = align.unwrap_or(DEFAULT_ALIGN_BYTES); let layout = Layout::from_size_align(size, alignment)?; let ptr = unsafe { alloc::alloc(layout.clone()) }; diff --git a/rust/runtime/src/array.rs b/rust/runtime/src/array.rs index 5c49515a0da3..3de7a8590fde 100644 --- a/rust/runtime/src/array.rs +++ b/rust/runtime/src/array.rs @@ -1,23 +1,36 @@ -use std::{ - any::TypeId, - convert::TryFrom, - mem, - ops::{Deref, DerefMut}, - os::raw::{c_int, c_void}, - ptr, slice, -}; - +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +use std::{convert::TryFrom, mem, os::raw::c_void, ptr, slice}; + +use failure::Error; use ndarray; - -use crate::{ - allocator::Allocation, - errors::*, - ffi::runtime::{ +use tvm_common::{ + array::{DataType, TVMContext}, + ffi::{ DLContext, DLDataType, DLDataTypeCode_kDLFloat, DLDataTypeCode_kDLInt, - DLDataTypeCode_kDLUInt, DLDeviceType_kDLCPU, DLTensor as _DLTensor, + DLDataTypeCode_kDLUInt, DLTensor, }, }; +use crate::allocator::Allocation; + /// A `Storage` is a container which holds `Tensor` data. #[derive(PartialEq)] pub enum Storage<'a> { @@ -29,7 +42,7 @@ pub enum Storage<'a> { } impl<'a> Storage<'a> { - pub fn new(size: usize, align: Option) -> Result> { + pub fn new(size: usize, align: Option) -> Result, Error> { Ok(Storage::Owned(Allocation::new(size, align)?)) } @@ -237,6 +250,27 @@ impl<'a> Tensor<'a> { byte_offset: 0, } } + + pub(crate) fn as_dltensor(&self, flatten: bool) -> DLTensor { + assert!(!flatten || self.is_contiguous()); + DLTensor { + data: unsafe { self.data.as_mut_ptr().offset(self.byte_offset) } as *mut c_void, + ctx: DLContext::from(&self.ctx), + ndim: if flatten { 1 } else { self.shape.len() } as i32, + dtype: DLDataType::from(&self.dtype), + shape: if flatten { + &self.size as *const _ as *mut i64 + } else { + self.shape.as_ptr() + } as *mut i64, + strides: if flatten || self.is_contiguous() { + ptr::null_mut() + } else { + self.strides.as_ref().unwrap().as_ptr() + } as *mut i64, + byte_offset: 0, + } + } } /// Conversions to `ndarray::Array` from `Tensor`, if the types match. @@ -244,7 +278,7 @@ macro_rules! impl_ndarray_try_from_tensor { ($type:ty, $dtype:expr) => { impl<'a, 't> TryFrom<&'a Tensor<'t>> for ndarray::ArrayD<$type> { type Error = Error; - fn try_from(tensor: &'a Tensor) -> Result> { + fn try_from(tensor: &'a Tensor) -> Result, Error> { ensure!( tensor.dtype == $dtype, "Cannot convert Tensor with dtype {:?} to ndarray", @@ -263,120 +297,9 @@ macro_rules! impl_ndarray_try_from_tensor { }; } -impl_ndarray_try_from_tensor!(i32, DTYPE_INT32); -impl_ndarray_try_from_tensor!(u32, DTYPE_UINT32); -impl_ndarray_try_from_tensor!(f32, DTYPE_FLOAT32); -impl_ndarray_try_from_tensor!(f64, DTYPE_FLOAT64); - -pub struct DLTensor { - pub(crate) inner: _DLTensor, -} - -impl Deref for DLTensor { - type Target = _DLTensor; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl DerefMut for DLTensor { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.inner - } -} - -impl DLTensor { - pub(crate) fn new(raw: _DLTensor) -> Self { - Self { inner: raw } - } - - pub(crate) fn from_tensor<'a>(tensor: &'a Tensor, flatten: bool) -> Self { - assert!(!flatten || tensor.is_contiguous()); - Self { - inner: _DLTensor { - data: unsafe { tensor.data.as_mut_ptr().offset(tensor.byte_offset) } as *mut c_void, - ctx: DLContext::from(&tensor.ctx), - ndim: if flatten { 1 } else { tensor.shape.len() } as i32, - dtype: DLDataType::from(&tensor.dtype), - shape: if flatten { - &tensor.size as *const _ as *mut i64 - } else { - tensor.shape.as_ptr() - } as *mut i64, - strides: if flatten || tensor.is_contiguous() { - ptr::null_mut() - } else { - tensor.strides.as_ref().unwrap().as_ptr() - } as *mut i64, - byte_offset: 0, - }, - } - } -} - -impl<'a, 't> From<&'a Tensor<'t>> for DLTensor { - fn from(tensor: &'a Tensor<'t>) -> Self { - DLTensor::from_tensor(tensor, false /* flatten */) - } -} - -impl<'a, 't> From<&'a mut Tensor<'t>> for DLTensor { - fn from(tensor: &'a mut Tensor<'t>) -> Self { - DLTensor::from_tensor(tensor, false /* flatten */) - } -} - -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub struct DataType { - pub(crate) code: usize, - pub(crate) bits: usize, - pub(crate) lanes: usize, -} - -impl DataType { - /// Returns the number of bytes occupied by an element of this `DataType`. - pub fn itemsize(&self) -> usize { - (self.bits * self.lanes) >> 3 - } - - /// Returns whether this `DataType` represents primitive type `T`. - pub fn is_type(&self) -> bool { - if self.lanes != 1 { - return false; - } - let typ = TypeId::of::(); - (typ == TypeId::of::() && self.code == 0 && self.bits == 32) - || (typ == TypeId::of::() && self.code == 0 && self.bits == 64) - || (typ == TypeId::of::() && self.code == 1 && self.bits == 32) - || (typ == TypeId::of::() && self.code == 1 && self.bits == 64) - || (typ == TypeId::of::() && self.code == 2 && self.bits == 32) - || (typ == TypeId::of::() && self.code == 2 && self.bits == 64) - } -} - -impl<'a> From<&'a DataType> for DLDataType { - fn from(dtype: &'a DataType) -> Self { - Self { - code: dtype.code as u8, - bits: dtype.bits as u8, - lanes: dtype.lanes as u16, - } - } -} - -impl From for DataType { - fn from(dtype: DLDataType) -> Self { - Self { - code: dtype.code as usize, - bits: dtype.bits as usize, - lanes: dtype.lanes as usize, - } - } -} - macro_rules! make_dtype_const { ($name: ident, $code: ident, $bits: expr, $lanes: expr) => { - const $name: DataType = DataType { + pub const $name: DataType = DataType { code: $code as usize, bits: $bits, lanes: $lanes, @@ -389,28 +312,20 @@ make_dtype_const!(DTYPE_UINT32, DLDataTypeCode_kDLUInt, 32, 1); // make_dtype_const!(DTYPE_FLOAT16, DLDataTypeCode_kDLFloat, 16, 1); make_dtype_const!(DTYPE_FLOAT32, DLDataTypeCode_kDLFloat, 32, 1); make_dtype_const!(DTYPE_FLOAT64, DLDataTypeCode_kDLFloat, 64, 1); +impl_ndarray_try_from_tensor!(i32, DTYPE_INT32); +impl_ndarray_try_from_tensor!(u32, DTYPE_UINT32); +impl_ndarray_try_from_tensor!(f32, DTYPE_FLOAT32); +impl_ndarray_try_from_tensor!(f64, DTYPE_FLOAT64); -#[derive(Debug, Clone, Copy, PartialEq)] -pub struct TVMContext { - pub(crate) device_type: usize, - pub(crate) device_id: usize, -} - -impl<'a> From<&'a TVMContext> for DLContext { - fn from(ctx: &'a TVMContext) -> Self { - Self { - device_type: ctx.device_type as u32, - device_id: ctx.device_id as i32, - } +impl<'a, 't> From<&'a Tensor<'t>> for DLTensor { + fn from(tensor: &'a Tensor<'t>) -> Self { + Tensor::as_dltensor(tensor, false /* flatten */) } } -impl Default for TVMContext { - fn default() -> Self { - Self { - device_type: DLDeviceType_kDLCPU as usize, - device_id: 0, - } +impl<'a, 't> From<&'a mut Tensor<'t>> for DLTensor { + fn from(tensor: &'a mut Tensor<'t>) -> Self { + Tensor::as_dltensor(tensor, false /* flatten */) } } @@ -463,42 +378,6 @@ macro_rules! impl_tensor_from_ndarray { }; } -/// `From` conversions to `DLTensor` for `ndarray::Array`. -/// Takes a reference to the `ndarray` since `DLTensor` is not owned. -macro_rules! impl_dltensor_from_ndarray { - ($type:ty, $typecode:expr) => { - impl<'a, D: ndarray::Dimension> From<&'a mut ndarray::Array<$type, D>> for DLTensor { - fn from(arr: &'a mut ndarray::Array<$type, D>) -> Self { - DLTensor { - inner: _DLTensor { - data: arr.as_mut_ptr() as *mut c_void, - ctx: DLContext { - device_type: DLDeviceType_kDLCPU, - device_id: 0, - }, - ndim: arr.ndim() as c_int, - dtype: DLDataType { - code: $typecode as u8, - bits: 8 * mem::size_of::<$type>() as u8, - lanes: 1, - }, - shape: arr.shape().as_ptr() as *const i64 as *mut i64, - strides: arr.strides().as_ptr() as *const isize as *mut i64, - byte_offset: 0, - }, - } - } - } - }; -} - -impl_dltensor_from_ndarray!(f32, DLDataTypeCode_kDLFloat); -impl_dltensor_from_ndarray!(f64, DLDataTypeCode_kDLFloat); -impl_dltensor_from_ndarray!(i32, DLDataTypeCode_kDLInt); -impl_dltensor_from_ndarray!(i64, DLDataTypeCode_kDLInt); -impl_dltensor_from_ndarray!(u32, DLDataTypeCode_kDLUInt); -impl_dltensor_from_ndarray!(u64, DLDataTypeCode_kDLUInt); - impl_tensor_from_ndarray!(f32, DLDataTypeCode_kDLFloat); impl_tensor_from_ndarray!(f64, DLDataTypeCode_kDLFloat); impl_tensor_from_ndarray!(i32, DLDataTypeCode_kDLInt); diff --git a/rust/runtime/src/errors.rs b/rust/runtime/src/errors.rs index cf7723034882..d8ee5930b213 100644 --- a/rust/runtime/src/errors.rs +++ b/rust/runtime/src/errors.rs @@ -1,36 +1,38 @@ -#[cfg(target_env = "sgx")] -use alloc::alloc; -#[cfg(not(target_env = "sgx"))] -use std::alloc; -use std::num; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ -use crate::common::errors as common_errors; -use ndarray; -use serde_json; - -error_chain! { - errors { - GraphFormatError(msg: String) { - description("unable to load graph") - display("could not load graph json: {}", msg) - } - - LoadGraphParamsError(msg: String) { - description("unable to load graph params") - display("could not load graph params: {}", msg) - } - } - foreign_links { - Alloc(alloc::AllocErr); - GraphDeserialize(serde_json::Error); - ParseInt(num::ParseIntError); - ShapeError(ndarray::ShapeError); - CommonError(common_errors::Error); - } +#[derive(Debug, Fail)] +pub enum GraphFormatError { + #[fail(display = "Could not parse graph json")] + Parse(#[fail(cause)] failure::Error), + #[fail(display = "Could not parse graph params")] + Params, + #[fail(display = "{} is missing attr: {}", 0, 1)] + MissingAttr(String, String), + #[fail(display = "Missing field: {}", 0)] + MissingField(&'static str), + #[fail(display = "Invalid DLType: {}", 0)] + InvalidDLType(String), } -impl From for Error { - fn from(_err: alloc::LayoutErr) -> Error { - Error::from_kind(ErrorKind::Msg("Layout error".to_string())) - } +#[derive(Debug, Fail)] +#[fail(display = "SGX error: 0x{:x}", code)] +pub struct SgxError { + pub code: u32, } diff --git a/rust/runtime/src/graph.rs b/rust/runtime/src/graph.rs index 0d5e281f3f77..bff02f504a5e 100644 --- a/rust/runtime/src/graph.rs +++ b/rust/runtime/src/graph.rs @@ -1,16 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + use std::{cmp, collections::HashMap, convert::TryFrom, iter::FromIterator, mem, str}; +use failure::Error; use nom::{alpha1, digit1, le_i32, le_i64, le_u16, le_u32, le_u64, le_u8, types::CompleteStr}; use serde; use serde_json; - -use super::{DLTensor, DataType, Module, Storage, TVMContext, Tensor}; -use crate::{ - common::value::TVMArgValue, - errors::{Error, ErrorKind, Result}, - ffi::runtime::{DLDataTypeCode_kDLFloat, DLDataTypeCode_kDLInt, DLDataTypeCode_kDLUInt}, +use tvm_common::{ + array::{DataType, TVMContext}, + ffi::{DLDataTypeCode_kDLFloat, DLDataTypeCode_kDLInt, DLDataTypeCode_kDLUInt, DLTensor}, + TVMArgValue, }; +use crate::{errors::GraphFormatError, Module, Storage, Tensor}; + // @see `kTVMNDArrayMagic` in `ndarray.h` const _NDARRAY_MAGIC: u64 = 0xDD5E40F096B4A13F; // @see `kTVMNDArrayListMagic` in `graph_runtime.h` @@ -21,7 +41,7 @@ const _NDARRAY_LIST_MAGIC: u64 = 0xF7E58D4F05049CB7; /// # Examples /// /// ``` -/// let graph_json = fs::read_to_string("graph.json")).unwrap(); +/// let graph_json = fs::read_to_string("graph.json").unwrap(); /// let graph = Graph::try_from(&graph_json).unwrap(); /// ``` #[derive(Serialize, Deserialize, Debug)] @@ -41,28 +61,26 @@ pub struct Entry { } impl Graph { - fn entry_index(&self, entry: &Entry) -> Result { + fn entry_index(&self, entry: &Entry) -> Result { self.node_row_ptr .as_ref() .map(|nrp| nrp[entry.id] + entry.index) - .ok_or("Missing node_row_ptr.".into()) + .ok_or_else(|| GraphFormatError::MissingField("node_row_ptr")) } /// Attempt to deserialize a JSON attribute to a type `T`. - fn get_attr(&self, attr: &str) -> Result { + fn get_attr(&self, attr: &str) -> Result { Ok(serde_json::from_value::( self.attrs .as_ref() - .ok_or(ErrorKind::GraphFormatError( - "Missing graph attrs".to_string(), - ))? + .ok_or(GraphFormatError::MissingField("attrs"))? .get(attr) - .ok_or(ErrorKind::GraphFormatError(format!( - "Missing {} attr", - attr - )))? + .ok_or_else(|| { + GraphFormatError::MissingAttr("graph".to_string(), attr.to_string()) + })? .to_owned(), - )?) + ) + .map_err(|err| GraphFormatError::Parse(err.into()))?) } } @@ -81,39 +99,31 @@ struct NodeAttrs { flatten_data: bool, } +macro_rules! get_node_attr { + ($node:expr, $attrs:ident, $attr:literal) => { + $attrs + .get($attr) + .ok_or_else(|| GraphFormatError::MissingAttr($node.to_owned(), $attr.to_owned())) + }; +} + impl Node { - fn parse_attrs(&self) -> Result { + fn parse_attrs(&self) -> Result { let attrs = self .attrs .as_ref() - .ok_or(format!("Missing node.attrs for `{}`", self.name))?; - let func_name = attrs - .get("func_name") - .ok_or(format!("Node `{}` is missing attrs.func_name", self.name))? - .to_string(); - let num_outputs = attrs - .get("num_outputs") - .ok_or(format!("Node `{}` is missing attrs.num_outputs", self.name))? - .parse::()?; - let flatten_data = attrs - .get("flatten_data") - .ok_or(format!( - "Node `{}` is missing attrs.flatten_data", - self.name - ))? - .parse::()? - == 1; + .ok_or_else(|| GraphFormatError::MissingAttr(self.name.clone(), "attrs".to_owned()))?; Ok(NodeAttrs { - func_name, - num_outputs, - flatten_data, + func_name: get_node_attr!(self.name, attrs, "func_name")?.to_owned(), + num_outputs: get_node_attr!(self.name, attrs, "num_outputs")?.parse::()?, + flatten_data: get_node_attr!(self.name, attrs, "flatten_data")?.parse::()? == 1, }) } } impl<'a> TryFrom<&'a String> for Graph { type Error = Error; - fn try_from(graph_json: &String) -> Result { + fn try_from(graph_json: &String) -> Result { let graph = serde_json::from_str(graph_json)?; Ok(graph) } @@ -121,7 +131,7 @@ impl<'a> TryFrom<&'a String> for Graph { impl<'a> TryFrom<&'a str> for Graph { type Error = Error; - fn try_from(graph_json: &'a str) -> Result { + fn try_from(graph_json: &'a str) -> Result { let graph = serde_json::from_str(graph_json)?; Ok(graph) } @@ -161,7 +171,7 @@ pub struct GraphExecutor<'m, 't> { unsafe impl<'m, 't> Send for GraphExecutor<'m, 't> {} impl<'m, 't> GraphExecutor<'m, 't> { - pub fn new(graph: Graph, lib: &'m M) -> Result { + pub fn new(graph: Graph, lib: &'m M) -> Result { let tensors = Self::setup_storages(&graph)?; Ok(GraphExecutor { op_execs: Self::setup_op_execs(&graph, lib, &tensors)?, @@ -178,7 +188,7 @@ impl<'m, 't> GraphExecutor<'m, 't> { } /// Allocates `Storages` for each `storage_id` and returns `Tensor`s to hold each output. - fn setup_storages<'a>(graph: &'a Graph) -> Result>> { + fn setup_storages<'a>(graph: &'a Graph) -> Result>, Error> { let storage_ids = graph.get_attr::<(String, Vec)>("storage_id")?.1; let shapes = graph.get_attr::<(String, Vec>)>("shape")?.1; let dtypes = graph @@ -189,18 +199,15 @@ impl<'m, 't> GraphExecutor<'m, 't> { if let Ok((_, dtype)) = tvm_str_to_type(CompleteStr(dltype)) { Ok(dtype) } else { - Err(ErrorKind::GraphFormatError( - format!("Invalid dltype: {}", dltype).to_string(), - ) - .into()) + Err(GraphFormatError::InvalidDLType(dltype.to_string())) } }) - .collect::>>()?; + .collect::, GraphFormatError>>()?; - let align = dtypes.iter().map(|dtype| dtype.bits as usize).max(); + let align = dtypes.iter().map(|dtype| dtype.bits() as usize).max(); let mut storage_num_bytes = vec![0usize; *storage_ids.iter().max().unwrap_or(&1) + 1]; for (i, &storage_id) in storage_ids.iter().enumerate() { - let dtype_size = dtypes[i].bits * dtypes[i].lanes >> 3; + let dtype_size = dtypes[i].bits() * dtypes[i].lanes() >> 3; let nbytes = dtype_size * shapes[i].iter().product::() as usize; storage_num_bytes[storage_id] = cmp::max(nbytes, storage_num_bytes[storage_id]); } @@ -208,7 +215,7 @@ impl<'m, 't> GraphExecutor<'m, 't> { let mut storages: Vec = storage_num_bytes .into_iter() .map(|nbytes| Storage::new(nbytes, align)) - .collect::>>()?; + .collect::, Error>>()?; let tensors = izip!(storage_ids, shapes, dtypes) .map(|(storage_id, shape, dtype)| { @@ -233,7 +240,7 @@ impl<'m, 't> GraphExecutor<'m, 't> { graph: &Graph, lib: &'m M, tensors: &Vec>, - ) -> Result>> { + ) -> Result>, Error> { ensure!(graph.node_row_ptr.is_some(), "Missing node_row_ptr."); let node_row_ptr = graph.node_row_ptr.as_ref().unwrap(); @@ -251,9 +258,10 @@ impl<'m, 't> GraphExecutor<'m, 't> { continue; } - let func = lib - .get_function(&attrs.func_name) - .ok_or(format!("Missing function {}", attrs.func_name))?; + let func = lib.get_function(&attrs.func_name).ok_or(format_err!( + "Library is missing function {}", + attrs.func_name + ))?; let arg_indices = node .inputs .iter() @@ -264,19 +272,19 @@ impl<'m, 't> GraphExecutor<'m, 't> { .map(|idx| { let tensor = &tensors[idx?]; Ok(if attrs.flatten_data { - DLTensor::from_tensor(tensor, true /* flatten */) + Tensor::as_dltensor(tensor, true /* flatten */) } else { DLTensor::from(tensor) }) }) - .collect::>>() + .collect::, Error>>() .unwrap(); let op: Box = box move || { let args = dl_tensors .iter() .map(|t| t.into()) .collect::>(); - func(args.as_slice()); + func(&args).unwrap(); }; op_execs.push(op); } @@ -294,7 +302,7 @@ impl<'m, 't> GraphExecutor<'m, 't> { // TODO: consider `new_with_params` to avoid ever allocating let ptr = self.tensors[idx].data.as_ptr(); let mut to_replace = self.tensors.iter_mut().filter(|t| t.data.as_ptr() == ptr); - let mut owner = to_replace.nth(0).unwrap(); + let owner = to_replace.nth(0).unwrap(); if value.data.is_owned() { // FIXME: for no-copy, need setup_op_execs to not capture tensor ptr // mem::replace(&mut (*owner), value); @@ -344,7 +352,7 @@ impl<'m, 't> GraphExecutor<'m, 't> { } } -/// Converts a string to TVM DLDataTypeCode. @see `String2TVMType` in packed_func.h +// Converts a string to TVM DLDataTypeCode. @see `String2TVMType` in packed_func.h named!( tvm_str_to_type, do_parse!( @@ -367,7 +375,7 @@ named!( ) ); -/// Converts a bytes to String. +// Converts a bytes to String. named!( name, map_res!(length_bytes!(le_u64), |b: &[u8]| String::from_utf8( @@ -375,7 +383,7 @@ named!( )) ); -/// Parses a TVMContext +// Parses a TVMContext named!( tvm_ctx<&[u8], TVMContext>, do_parse!( @@ -385,7 +393,7 @@ named!( ) ); -/// Parses a DataType +// Parses a DataType named!( data_type<&[u8], DataType>, do_parse!( @@ -396,7 +404,7 @@ named!( ) ); -/// Parses a Tensor from a TVM array file. +// Parses a Tensor from a TVM array file. named!( tensor, do_parse!( @@ -420,7 +428,7 @@ named!( ) ); -/// Parses a graph params dict from a params binary file. +// Parses a graph params dict from a params binary file. named!( parse_param_dict>, do_parse!( @@ -433,17 +441,15 @@ named!( ); /// Loads a param dict saved using `nnvm.compiler.save_param_dict`. -pub fn load_param_dict(bytes: &[u8]) -> Result> { +pub fn load_param_dict(bytes: &[u8]) -> Result, GraphFormatError> { if let Ok((remaining_bytes, param_dict)) = parse_param_dict(bytes) { - if remaining_bytes.len() > 0 { - bail!(ErrorKind::LoadGraphParamsError("extra input".to_string())) - } else { + if remaining_bytes.len() == 0 { Ok(param_dict) + } else { + Err(GraphFormatError::Params) } } else { - bail!(ErrorKind::LoadGraphParamsError( - "invalid parameters file".to_string() - )) + Err(GraphFormatError::Params) } } diff --git a/rust/runtime/src/lib.rs b/rust/runtime/src/lib.rs index da030bc4be65..c774d5bbc983 100644 --- a/rust/runtime/src/lib.rs +++ b/rust/runtime/src/lib.rs @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + //! This crate is an implementation of the TVM runtime for modules compiled with `--system-lib`. //! It's mainly useful for compiling to WebAssembly and SGX, //! but also native if you prefer Rust to C++. @@ -14,7 +33,6 @@ allocator_api, box_syntax, fn_traits, - try_from, unboxed_closures, vec_remove_item )] @@ -25,7 +43,7 @@ extern crate bounded_spsc_queue; #[cfg(target_env = "sgx")] extern crate core; #[macro_use] -extern crate error_chain; +extern crate failure; #[macro_use] extern crate itertools; #[macro_use] @@ -39,36 +57,45 @@ extern crate serde; #[macro_use] extern crate serde_derive; extern crate serde_json; -extern crate tvm_common as common; +extern crate tvm_common; mod allocator; mod array; pub mod errors; -mod module; -#[macro_use] -mod packed_func; mod graph; +mod module; #[cfg(target_env = "sgx")] #[macro_use] pub mod sgx; mod threading; mod workspace; -pub use crate::common::{errors::*, ffi, TVMArgValue, TVMRetValue}; - -pub use self::{ - array::*, errors::*, graph::*, module::*, packed_func::*, threading::*, workspace::*, +pub use tvm_common::{ + call_packed, + errors::*, + ffi::{self, DLTensor}, + packed_func::{self, *}, + TVMArgValue, TVMRetValue, }; -#[cfg(target_env = "sgx")] -use self::sgx::ocall_packed_func; +pub use self::{array::*, errors::*, graph::*, module::*, threading::*, workspace::*}; + +lazy_static! { + static ref LAST_ERROR: std::sync::RwLock> = + std::sync::RwLock::new(None); +} #[no_mangle] pub extern "C" fn TVMAPISetLastError(cmsg: *const i8) { - #[cfg(not(target_env = "sgx"))] - unsafe { - panic!(std::ffi::CStr::from_ptr(cmsg).to_str().unwrap()); - } + *LAST_ERROR.write().unwrap() = Some(unsafe { std::ffi::CStr::from_ptr(cmsg) }); #[cfg(target_env = "sgx")] ocall_packed!("__sgx_set_last_error__", cmsg); } + +#[no_mangle] +pub extern "C" fn TVMGetLastError() -> *const std::os::raw::c_char { + match *LAST_ERROR.read().unwrap() { + Some(err) => err.as_ptr(), + None => std::ptr::null(), + } +} diff --git a/rust/runtime/src/module.rs b/rust/runtime/src/module.rs index 8e6f7d665dd4..865338f848fa 100644 --- a/rust/runtime/src/module.rs +++ b/rust/runtime/src/module.rs @@ -1,30 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + use std::{ collections::HashMap, convert::AsRef, ffi::CStr, os::raw::c_char, string::String, sync::Mutex, }; -use crate::{ - ffi::runtime::BackendPackedCFunc, - packed_func::{wrap_backend_packed_func, PackedFunc}, +use tvm_common::{ + ffi::BackendPackedCFunc, + packed_func::{PackedFunc, TVMArgValue, TVMRetValue, TVMValue}, }; pub trait Module { - fn get_function>(&self, name: S) -> Option; + fn get_function>(&self, name: S) -> Option<&(dyn PackedFunc)>; } pub struct SystemLibModule; lazy_static! { - static ref SYSTEM_LIB_FUNCTIONS: Mutex> = + static ref SYSTEM_LIB_FUNCTIONS: Mutex> = Mutex::new(HashMap::new()); } impl Module for SystemLibModule { - fn get_function>(&self, name: S) -> Option { + fn get_function>(&self, name: S) -> Option<&(dyn PackedFunc)> { SYSTEM_LIB_FUNCTIONS .lock() .unwrap() .get(name.as_ref()) - .map(|func| wrap_backend_packed_func(func.to_owned())) + .map(|f| *f) } } @@ -34,15 +53,39 @@ impl Default for SystemLibModule { } } +// @see `WrapPackedFunc` in `llvm_module.cc`. +pub(super) fn wrap_backend_packed_func( + func_name: String, + func: BackendPackedCFunc, +) -> Box { + box move |args: &[TVMArgValue]| { + let (values, type_codes): (Vec, Vec) = args + .into_iter() + .map(|arg| { + let (val, code) = arg.to_tvm_value(); + (val, code as i32) + }) + .unzip(); + let exit_code = func(values.as_ptr(), type_codes.as_ptr(), values.len() as i32); + if exit_code == 0 { + Ok(TVMRetValue::default()) + } else { + Err(tvm_common::errors::FuncCallError::get_with_context( + func_name.clone(), + )) + } + } +} + #[no_mangle] pub extern "C" fn TVMBackendRegisterSystemLibSymbol( cname: *const c_char, func: BackendPackedCFunc, ) -> i32 { let name = unsafe { CStr::from_ptr(cname).to_str().unwrap() }; - SYSTEM_LIB_FUNCTIONS - .lock() - .unwrap() - .insert(name.to_string(), func); + SYSTEM_LIB_FUNCTIONS.lock().unwrap().insert( + name.to_string(), + &*Box::leak(wrap_backend_packed_func(name.to_string(), func)), + ); return 0; } diff --git a/rust/runtime/src/packed_func.rs b/rust/runtime/src/packed_func.rs deleted file mode 100644 index 2fe0086e9a0d..000000000000 --- a/rust/runtime/src/packed_func.rs +++ /dev/null @@ -1,118 +0,0 @@ -use std::{convert::TryFrom, marker::PhantomData, os::raw::c_void}; - -use super::Tensor; -use crate::ffi::runtime::{ - BackendPackedCFunc, DLTensor as _DLTensor, TVMTypeCode_kArrayHandle, - TVMTypeCode_kNDArrayContainer, TVMValue as _TVMValue, -}; - -use super::DLTensor; -use crate::{ - common::{TVMArgValue, TVMRetValue, TVMTypeCode, TVMValue}, - errors::*, -}; - -pub type PackedFunc = Box TVMRetValue + Send + Sync>; - -/// Calls a packed function and returns a `TVMRetValue`. -/// -/// # Example -/// -/// `call_packed!(my_tvm_func, &mut arg1, &mut arg2)` -#[macro_export] -macro_rules! call_packed { - ($fn:expr, $($args:expr),+) => { - $fn(&[$($args.into(),)+]) - }; - ($fn:expr) => { - $fn(&Vec::new()) - }; -} - -impl<'a> From<&'a DLTensor> for TVMArgValue<'a> { - fn from(arr: &'a DLTensor) -> Self { - let raw = _TVMValue { - v_handle: arr as *const _ as *mut DLTensor as *mut c_void, - }; - TVMArgValue { - value: TVMValue::new(raw), - type_code: TVMTypeCode::kArrayHandle, - lifetime: PhantomData, - } - } -} - -impl<'a> From<&'a mut DLTensor> for TVMArgValue<'a> { - fn from(arr: &'a mut DLTensor) -> Self { - let raw = _TVMValue { - v_handle: arr as *mut _ as *mut c_void, - }; - TVMArgValue { - value: TVMValue::new(raw), - type_code: TVMTypeCode::kArrayHandle, - lifetime: PhantomData, - } - } -} - -impl<'a> TryFrom> for Tensor<'a> { - type Error = Error; - fn try_from(val: TVMArgValue<'a>) -> Result { - ensure!( - val.type_code == TVMTypeCode::kArrayHandle - || val.type_code == TVMTypeCode::kNDArrayContainer, - "Could not downcast arg. Expected `{}` or `{}`, but got `{}`", - TVMTypeCode::kArrayHandle, - TVMTypeCode::kNDArrayContainer, - val.type_code, - ); - - let dlt = unsafe { *(val.value.v_handle as *mut _DLTensor as *const _DLTensor) }; - Ok(DLTensor::new(dlt).into()) - } -} - -impl<'a, 't> From<&'t Tensor<'a>> for TVMRetValue { - fn from(val: &'t Tensor<'a>) -> Self { - TVMRetValue { - prim_value: 0, - box_value: box DLTensor::from(val), - type_code: TVMTypeCode::kNDArrayContainer, - } - } -} - -impl<'a> TryFrom for Tensor<'a> { - type Error = Error; - fn try_from(ret: TVMRetValue) -> Result { - ensure!( - ret.type_code == TVMTypeCode::kArrayHandle - || ret.type_code == TVMTypeCode::kNDArrayContainer, - "Could not downcast arg. Expected `{}` or `{}`, but got `{}`", - TVMTypeCode_kArrayHandle, - TVMTypeCode_kNDArrayContainer, - ret.type_code, - ); - - let dlt = unsafe { *(ret.prim_value as *mut _DLTensor as *const _DLTensor) }; - Ok(DLTensor::new(dlt).into()) - } -} - -// @see `WrapPackedFunc` in `llvm_module.cc`. -pub(crate) fn wrap_backend_packed_func(func: BackendPackedCFunc) -> PackedFunc { - box move |args: &[TVMArgValue]| { - func( - args.iter() - .map(|ref arg| arg.value.inner) - .collect::>() - .as_ptr(), - args.iter() - .map(|ref arg| arg.type_code as i32) - .collect::>() - .as_ptr() as *const i32, - args.len() as i32, - ); - TVMRetValue::default() - } -} diff --git a/rust/runtime/src/sgx.rs b/rust/runtime/src/sgx.rs index 1edf3ef497e7..3c1768518b96 100644 --- a/rust/runtime/src/sgx.rs +++ b/rust/runtime/src/sgx.rs @@ -1,20 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + use std::{ ffi::CString, os::raw::{c_char, c_int}, }; -use errors::Result; -use ffi::runtime::TVMValue; -use runtime::{threading::sgx_join_threads, SystemLibModule, TVMArgValue, TVMRetValue}; - -pub use runtime::threading::tvm_run_worker as run_worker; +pub use crate::threading::tvm_run_worker as run_worker; +use crate::{threading::sgx_join_threads, SystemLibModule, TVMArgValue, TVMRetValue}; +use errors::SgxError; +use ffi::TVMValue; #[macro_export] macro_rules! tvm_ocall { ($func: expr) => { match $func { 0 => Ok(()), - err => Err(format!("SGX error: {}", err)), + code => Err(SgxError { code }), } }; } @@ -33,7 +51,10 @@ extern "C" { ) -> SgxStatus; } -pub fn ocall_packed_func>(fn_name: S, args: &[TVMArgValue]) -> Result { +pub fn ocall_packed_func>( + fn_name: S, + args: &[TVMArgValue], +) -> Result { let mut ret_val = TVMValue { v_int64: 0 }; let ret_type_code = 0i64; unsafe { @@ -58,11 +79,11 @@ pub fn ocall_packed_func>(fn_name: S, args: &[TVMArgValue]) -> Res #[macro_export] macro_rules! ocall_packed { ($fn_name:expr, $($args:expr),+) => { - ocall_packed_func($fn_name, &[$($args.into(),)+]) + $crate::sgx::ocall_packed_func($fn_name, &[$($args.into(),)+]) .expect(concat!("Error calling `", $fn_name, "`")) }; ($fn_name:expr) => { - ocall_packed_func($fn_name, &Vec::new()) + $crate::sgx::ocall_packed_func($fn_name, &Vec::new()) .expect(concat!("Error calling `", $fn_name, "`")) } } diff --git a/rust/runtime/src/threading.rs b/rust/runtime/src/threading.rs index 38f4b7d23f0f..96143848f5e2 100644 --- a/rust/runtime/src/threading.rs +++ b/rust/runtime/src/threading.rs @@ -1,7 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + use std::{ os::raw::{c_int, c_void}, sync::{ - atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT}, + atomic::{AtomicUsize, Ordering}, Arc, Barrier, }, }; @@ -18,11 +37,10 @@ use std::{ use std::{collections::VecDeque, ptr, sync::Mutex}; use bounded_spsc_queue::{self, Producer}; - -use crate::{errors::*, ffi::runtime::TVMParallelGroupEnv}; +use tvm_common::ffi::TVMParallelGroupEnv; #[cfg(target_env = "sgx")] -use super::{sgx::ocall_packed_func, TVMArgValue, TVMRetValue}; +use super::{TVMArgValue, TVMRetValue}; type FTVMParallelLambda = extern "C" fn(task_id: usize, penv: *const TVMParallelGroupEnv, cdata: *const c_void) -> i32; @@ -62,12 +80,11 @@ impl Job { } /// Waits for all tasks in this `Job` to be completed. - fn wait(&self) -> Result<()> { + fn wait(&self) { while self.pending.load(Ordering::Acquire) > 0 { #[cfg(not(target_env = "sgx"))] thread::yield_now(); } - Ok(()) } } @@ -161,7 +178,7 @@ impl ThreadPool { } tasks.pop().unwrap()(); - job.wait().unwrap(); + job.wait(); } fn run_worker(queue: Consumer) { @@ -251,7 +268,7 @@ pub extern "C" fn TVMBackendParallelLaunch( cb: cb, cdata: cdata, req_num_tasks: num_task, - pending: Arc::new(ATOMIC_USIZE_INIT), + pending: Arc::new(AtomicUsize::new(0)), }); }); } @@ -273,7 +290,7 @@ pub(crate) fn sgx_join_threads() { cb: poison_pill, cdata: ptr::null(), req_num_tasks: 0, - pending: Arc::new(ATOMIC_USIZE_INIT), + pending: Arc::new(AtomicUsize::new(0)), }); }); ocall_packed!("__sgx_thread_group_join__", 0); @@ -322,8 +339,8 @@ mod tests { #[test] fn test_parallel_launch() { TVMBackendParallelLaunch(flambda, ptr::null(), 6); - let counter = ATOMIC_USIZE_INIT; - let task_ids_sum = ATOMIC_USIZE_INIT; + let counter = AtomicUsize::new(0); + let task_ids_sum = AtomicUsize::new(0); let cdata = (counter, task_ids_sum); let num_tasks = 3; TVMBackendParallelLaunch(flambda, &cdata as *const _ as *const c_void, num_tasks); diff --git a/rust/runtime/src/workspace.rs b/rust/runtime/src/workspace.rs index a12a27e4c47c..888daa052993 100644 --- a/rust/runtime/src/workspace.rs +++ b/rust/runtime/src/workspace.rs @@ -1,11 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + use std::{ cell::RefCell, os::raw::{c_int, c_void}, ptr, }; -use super::allocator::Allocation; -use crate::errors::*; +use failure::Error; + +use crate::allocator::Allocation; const WS_ALIGN: usize = 64; // taken from `kTempAllocaAlignment` in `device_api.h` @@ -24,13 +44,13 @@ impl WorkspacePool { } } - fn alloc_new(&mut self, size: usize) -> Result<*mut u8> { + fn alloc_new(&mut self, size: usize) -> Result<*mut u8, Error> { self.workspaces.push(Allocation::new(size, Some(WS_ALIGN))?); self.in_use.push(self.workspaces.len() - 1); Ok(self.workspaces[self.workspaces.len() - 1].as_mut_ptr()) } - fn alloc(&mut self, size: usize) -> Result<*mut u8> { + fn alloc(&mut self, size: usize) -> Result<*mut u8, Error> { if self.free.len() == 0 { return self.alloc_new(size); } @@ -60,7 +80,7 @@ impl WorkspacePool { } } - fn free(&mut self, ptr: *mut u8) -> Result<()> { + fn free(&mut self, ptr: *mut u8) -> Result<(), Error> { let mut ws_idx = None; for i in 0..self.in_use.len() { let idx = self.in_use[i]; @@ -72,7 +92,7 @@ impl WorkspacePool { } Ok(self .free - .push(ws_idx.ok_or("Tried to free nonexistent workspace.")?)) + .push(ws_idx.ok_or(format_err!("Tried to free nonexistent workspace."))?)) } } diff --git a/rust/runtime/tests/build_model.py b/rust/runtime/tests/build_model.py index ea55ce434dd9..bed3c0aa2da8 100755 --- a/rust/runtime/tests/build_model.py +++ b/rust/runtime/tests/build_model.py @@ -1,4 +1,20 @@ #!/usr/bin/env python3 +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Builds a simple NNVM graph for testing.""" diff --git a/rust/runtime/tests/test_graph_serde.rs b/rust/runtime/tests/test_graph_serde.rs index 18ac19a79df3..846f8a30bc7e 100644 --- a/rust/runtime/tests/test_graph_serde.rs +++ b/rust/runtime/tests/test_graph_serde.rs @@ -1,4 +1,21 @@ -#![feature(try_from)] +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ extern crate serde; extern crate serde_json; diff --git a/rust/runtime/tests/test_nnvm/Cargo.toml b/rust/runtime/tests/test_nnvm/Cargo.toml index 14d0b3961ad3..93fdef4f61c3 100644 --- a/rust/runtime/tests/test_nnvm/Cargo.toml +++ b/rust/runtime/tests/test_nnvm/Cargo.toml @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + [package] name = "test-nnvm" version = "0.0.0" @@ -5,7 +22,7 @@ license = "Apache-2.0" authors = ["TVM Contributors"] [dependencies] -ndarray = "0.11.2" +ndarray="0.12.1" serde = "1.0.59" serde_json = "1.0.17" tvm-runtime = { path = "../../" } diff --git a/rust/runtime/tests/test_nnvm/build.rs b/rust/runtime/tests/test_nnvm/build.rs index 3a4fc0a09484..2d0b06675617 100644 --- a/rust/runtime/tests/test_nnvm/build.rs +++ b/rust/runtime/tests/test_nnvm/build.rs @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + extern crate ar; use std::{env, fs::File, path::Path, process::Command}; diff --git a/rust/runtime/tests/test_nnvm/src/build_test_graph.py b/rust/runtime/tests/test_nnvm/src/build_test_graph.py index e9f74ecca27a..69ec6d24dbef 100755 --- a/rust/runtime/tests/test_nnvm/src/build_test_graph.py +++ b/rust/runtime/tests/test_nnvm/src/build_test_graph.py @@ -1,4 +1,20 @@ #!/usr/bin/env python3 +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Builds a simple NNVM graph for testing.""" @@ -58,7 +74,7 @@ def main(): lib.save(osp.join(sys.argv[1], 'graph.o')) with open(osp.join(out_dir, 'graph.json'), 'w') as f_resnet: f_resnet.write(graph.json()) - + with open(osp.join(out_dir, 'graph.params'), 'wb') as f_params: f_params.write(nnvm.compiler.save_param_dict(params)) diff --git a/rust/runtime/tests/test_nnvm/src/main.rs b/rust/runtime/tests/test_nnvm/src/main.rs index 50179798cd32..9543b35332a3 100644 --- a/rust/runtime/tests/test_nnvm/src/main.rs +++ b/rust/runtime/tests/test_nnvm/src/main.rs @@ -1,4 +1,21 @@ -#![feature(try_from)] +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ #[macro_use] extern crate ndarray; diff --git a/rust/runtime/tests/test_tvm_basic/Cargo.toml b/rust/runtime/tests/test_tvm_basic/Cargo.toml index 2a753b430c47..e821487b12b2 100644 --- a/rust/runtime/tests/test_tvm_basic/Cargo.toml +++ b/rust/runtime/tests/test_tvm_basic/Cargo.toml @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + [package] name = "test-tvm-basic" version = "0.0.0" @@ -5,7 +22,7 @@ license = "Apache-2.0" authors = ["TVM Contributors"] [dependencies] -ndarray = "0.11.2" +ndarray="0.12.1" tvm-runtime = { path = "../../" } [build-dependencies] diff --git a/rust/runtime/tests/test_tvm_basic/build.rs b/rust/runtime/tests/test_tvm_basic/build.rs index d8775857d686..ea3bfcb85136 100644 --- a/rust/runtime/tests/test_tvm_basic/build.rs +++ b/rust/runtime/tests/test_tvm_basic/build.rs @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + extern crate ar; use std::{env, path::Path, process::Command}; diff --git a/rust/runtime/tests/test_tvm_basic/src/build_test_lib.py b/rust/runtime/tests/test_tvm_basic/src/build_test_lib.py index 7289a778fcec..38c1f3a7a223 100755 --- a/rust/runtime/tests/test_tvm_basic/src/build_test_lib.py +++ b/rust/runtime/tests/test_tvm_basic/src/build_test_lib.py @@ -1,4 +1,20 @@ #!/usr/bin/env python3 +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Prepares a simple TVM library for testing.""" diff --git a/rust/runtime/tests/test_tvm_basic/src/main.rs b/rust/runtime/tests/test_tvm_basic/src/main.rs index f14fbec8c439..14bb7c20c680 100644 --- a/rust/runtime/tests/test_tvm_basic/src/main.rs +++ b/rust/runtime/tests/test_tvm_basic/src/main.rs @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + extern crate ndarray; #[macro_use] extern crate tvm_runtime; @@ -17,6 +36,6 @@ fn main() { let mut a_dl: DLTensor = (&mut a).into(); let mut b_dl: DLTensor = (&mut b).into(); let mut c_dl: DLTensor = (&mut c).into(); - call_packed!(add, &mut a_dl, &mut b_dl, &mut c_dl); + call_packed!(add, &mut a_dl, &mut b_dl, &mut c_dl).unwrap(); assert!(c.all_close(&e, 1e-8f32)); } diff --git a/src/README.md b/src/README.md index b0363a04411a..0c6f30a881b8 100644 --- a/src/README.md +++ b/src/README.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + # Code Organization Header files in include are public APIs that share across modules. diff --git a/src/api/api_arith.cc b/src/api/api_arith.cc index cc7d814617a9..ca0bed18f554 100644 --- a/src/api/api_arith.cc +++ b/src/api/api_arith.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * Implementation of API functions related to arith @@ -102,6 +121,10 @@ TVM_REGISTER_API("arith._CreateAnalyzer") return PackedFunc([self](TVMArgs args, TVMRetValue *ret) { *ret = self->rewrite_simplify(args[0]); }); + } else if (name == "canonical_simplify") { + return PackedFunc([self](TVMArgs args, TVMRetValue *ret) { + *ret = self->canonical_simplify(args[0]); + }); } else if (name == "bind") { return PackedFunc([self](TVMArgs args, TVMRetValue *ret) { auto& sptr = args[1].node_sptr(); diff --git a/src/api/api_base.cc b/src/api/api_base.cc index 47895c61e2c0..23d1f5c67f7c 100644 --- a/src/api/api_base.cc +++ b/src/api/api_base.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * Implementation of basic API functions diff --git a/src/api/api_codegen.cc b/src/api/api_codegen.cc index 372cd0e262b7..e44ebbec7085 100644 --- a/src/api/api_codegen.cc +++ b/src/api/api_codegen.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * Implementation of API functions related to Codegen diff --git a/src/api/api_ir.cc b/src/api/api_ir.cc index a4c7842ffe90..c5680bb3df8d 100644 --- a/src/api/api_ir.cc +++ b/src/api/api_ir.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * Implementation of API functions related to IR build diff --git a/src/api/api_lang.cc b/src/api/api_lang.cc index 50f81644b0b5..aac73f1878f8 100644 --- a/src/api/api_lang.cc +++ b/src/api/api_lang.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * Implementation of API functions related to Higher DSL build. diff --git a/src/api/api_pass.cc b/src/api/api_pass.cc index bf9e85e8134a..2e1ab42e4cbe 100644 --- a/src/api/api_pass.cc +++ b/src/api/api_pass.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * Exposre of pass functions. diff --git a/src/api/api_schedule.cc b/src/api/api_schedule.cc index 14191d79ec02..45e2eb4c9375 100644 --- a/src/api/api_schedule.cc +++ b/src/api/api_schedule.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * Implementation of API functions related to schedule pass. diff --git a/src/api/api_test.cc b/src/api/api_test.cc index 4bd480b3cc7e..f04bddbc1298 100644 --- a/src/api/api_test.cc +++ b/src/api/api_test.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * Code mainly used for test purposes. diff --git a/src/api/dsl_api.cc b/src/api/dsl_api.cc index 1c2c294a5f30..5e01383e9cb2 100644 --- a/src/api/dsl_api.cc +++ b/src/api/dsl_api.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * Implementation of DSL API diff --git a/src/arithmetic/analyzer.cc b/src/arithmetic/analyzer.cc index 81195eba2747..420d6f9c1d0d 100644 --- a/src/arithmetic/analyzer.cc +++ b/src/arithmetic/analyzer.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2019 by Contributors * \file tvm/arithmetic/analyzer.cc @@ -11,14 +30,21 @@ namespace arith { Analyzer::Analyzer() : const_int_bound(this), modular_set(this), - rewrite_simplify(this) { + rewrite_simplify(this), + canonical_simplify(this) { } void Analyzer::Bind(const VarExpr& v, const Expr& expr) { Var var(v.node_); - this->const_int_bound.Update(var, this->const_int_bound(expr)); - this->modular_set.Update(var, this->modular_set(expr)); - this->rewrite_simplify.Update(var, this->rewrite_simplify(expr)); + + Expr new_expr = expr; + new_expr = this->canonical_simplify(new_expr); + new_expr = this->rewrite_simplify(new_expr); + + this->const_int_bound.Update(var, this->const_int_bound(new_expr)); + this->modular_set.Update(var, this->modular_set(new_expr)); + this->rewrite_simplify.Update(var, new_expr); + this->canonical_simplify.Update(var, new_expr); } void Analyzer::Bind(const VarExpr& v, const Range& range) { @@ -47,5 +73,6 @@ bool Analyzer::CanProveGreaterEqual(const Expr& expr, int64_t lower_bound) { if (bd->min_value >= lower_bound) return true; return false; } + } // namespace arith } // namespace tvm diff --git a/src/arithmetic/bound_deducer.cc b/src/arithmetic/bound_deducer.cc index c9779bbbe24d..c35dffb848d6 100644 --- a/src/arithmetic/bound_deducer.cc +++ b/src/arithmetic/bound_deducer.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file bound_deducer.cc diff --git a/src/arithmetic/canonical.cc b/src/arithmetic/canonical.cc deleted file mode 100644 index 77c44f184e0f..000000000000 --- a/src/arithmetic/canonical.cc +++ /dev/null @@ -1,938 +0,0 @@ -/*! - * Copyright (c) 2017 by Contributors - * \file canonical.cc - * \brief Canonicalize simplification. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "canonical.h" -#include "compute_expr.h" -#include "arithmetic/Simplify.h" - -namespace tvm { -namespace arith { -using namespace ir; - -// Canonical entry for communicative ops. -struct ComExprEntry { - // the value of the expression. - Expr value; - // the level of the expression. - int level{0}; - // The integer scale on value - int64_t scale{1}; - - ComExprEntry() {} - ComExprEntry(Expr value, int level) - : value(value), level(level) {} - inline bool operator<(const ComExprEntry& other) const { - if (level < other.level) return true; - if (level > other.level) return false; - // compare top operator of entries and sort on that if possible (fast check) - if (value.type_index() < other.value.type_index()) return true; - if (value.type_index() > other.value.type_index()) return false; - // if none of the above distinguishes the terms, compare the expression tree of the entries. - // This is a slower check. - int compare_result = Compare(value, other.value); - if (compare_result < 0) return true; - if (compare_result > 0) return false; - // it's a problem if we see identical entries at this point. They should've been merged earlier. - LOG(WARNING) << "we should not have identical entries at this point"; - return false; - } -}; - -// canonical expression for communicative expression. -struct ComExprNode : public NodeBase { - // base constant value. - int64_t base{0}; - // The values to be sumed. - std::vector elem; -}; - -// canonical communicative expression -struct ComExpr { - public: - // constructor - ComExpr() {} - explicit ComExpr(NodePtr ptr) : ptr_(ptr) {} - // get member - ComExprNode* operator->() const { - return ptr_.get(); - } - void reset() { - ptr_.reset(); - } - bool defined() const { - return ptr_.get() != nullptr; - } - // comparator - bool operator<(const ComExpr& b) const { - const ComExpr& a = *this; - if (a->base < b->base) return true; - if (a->base > b->base) return false; - if (a->elem.size() < b->elem.size()) return true; - if (a->elem.size() > b->elem.size()) return false; - for (size_t i = 0; i < a->elem.size(); ++i) { - const ComExprEntry& ea = a->elem[i]; - const ComExprEntry& eb = b->elem[i]; - if (ea.level < eb.level) return true; - if (ea.level > eb.level) return false; - if (ea.value.get() < eb.value.get()) return true; - if (ea.value.get() > eb.value.get()) return false; - if (ea.scale < eb.scale) return true; - if (ea.scale > eb.scale) return false; - } - return false; - } - // equality - bool operator==(const ComExpr& b) const { - const ComExpr& a = *this; - if (a->base != b->base) return false; - if (a->elem.size() != b->elem.size()) return false; - for (size_t i = 0; i < a->elem.size(); ++i) { - const ComExprEntry& ea = a->elem[i]; - const ComExprEntry& eb = b->elem[i]; - if (ea.level != eb.level) return false; - if (ea.value.get() != eb.value.get()) return false; - if (ea.scale != eb.scale) return false; - } - return true; - } - - private: - NodePtr ptr_; -}; - -// binary comparison op. -struct BinaryExpr { - int kind; - Expr lhs, rhs; - // comparator - bool operator<(const BinaryExpr& b) const { - if (kind < b.kind) return true; - if (kind > b.kind) return false; - if (lhs.get() < b.lhs.get()) return true; - if (lhs.get() > b.lhs.get()) return false; - return rhs.get() < b.rhs.get(); - } - // equality - bool operator==(const BinaryExpr& b) const { - return kind == b.kind && - lhs.same_as(b.lhs) && - rhs.same_as(b.rhs); - } -}; - - -template -inline Expr Binary_(const T* op, - const Expr& e, - Expr a, Expr b) { - if (a.same_as(op->a) && b.same_as(op->b)) { - return e; - } else { - return T::make(a, b); - } -} - -// internal of canonical engine. -class Canonical::Internal : public IRMutator { - public: - explicit Internal(Map vrange) { - for (auto kv : vrange) { - SetRange(kv.first, kv.second, 0); - } - } - // stack entry. - struct StackEntry { - int max_level{0}; - bool has_side_effect{false}; - }; - // aggressively canonicalized expression - struct CacheEntry { - // The canonical value of the expression. - Expr value; - // The level of the expression. - int max_level{0}; - // whether the expression might have side effect. - bool has_side_effect{false}; - // if not null, corresponds to to sum - ComExpr sum; - // reset the return entry. - void reset() { - sum.reset(); - } - // as sum expr - ComExpr AsSum() const { - if (sum.defined()) return sum; - const int64_t *v1 = as_const_int(value); - const uint64_t *v2 = as_const_uint(value); - auto n = make_node(); - if (v1) { - n->base = *v1; - } else if (v2) { - CHECK_LE(*v2, - static_cast(std::numeric_limits::max())); - n->base = static_cast(*v2); - } else { - n->elem.push_back(ComExprEntry(value, max_level)); - } - return ComExpr(n); - } - }; - // Set range and level of var. - void SetRange(Var v, Range r, int level) { - var_range_[v.get()] = IntSet::range(r); - var_level_[v.get()] = level; - var_rec_.push_back(v); - } - // functions - Stmt Mutate(Stmt stmt) final { - stmt = IRMutator::Mutate(stmt); - return stmt; - } - Expr MutateExpr_(Expr expr) { - stack_.push_back(StackEntry()); - expr = IRMutator::Mutate(expr); - // update result of parent automatically during pop - if (stack_.size() > 1) { - StackEntry& back = stack_[stack_.size() - 1]; - StackEntry& prev = stack_[stack_.size() - 2]; - prev.max_level = std::max(prev.max_level, back.max_level); - if (back.has_side_effect) prev.has_side_effect = true; - } - // copy result from stack - ret_entry_.has_side_effect = stack_.back().has_side_effect; - ret_entry_.max_level = stack_.back().max_level; - stack_.pop_back(); - CHECK(expr.defined()); - if (const IntImm* op = expr.as()) { - return Mutate_(op, expr); - } - return expr; - } - // call produce to get a cache entry. - CacheEntry Produce(Expr expr) { - ret_entry_.reset(); - ret_entry_.value = MutateExpr_(expr); - CacheEntry ret = ret_entry_; - ret_entry_.reset(); - return ret; - } - Expr Mutate(Expr expr) final { - ret_entry_.reset(); - expr = MutateExpr_(expr); - ret_entry_.reset(); - return expr; - } - - // Check whether do special canonicalization. - bool EnableOpt(Type t) const { - return (t.lanes() == 1 && (t.is_int() || t.is_uint())); - } - // Max - Expr Mutate_(const Max* op, const Expr& e) final { - CacheEntry a = Produce(op->a); - CacheEntry b = Produce(op->b); - if (a.has_side_effect || b.has_side_effect) { - return Binary_(op, e, a.value, b.value); - } - return Binary(op, e); - } - // Min - Expr Mutate_(const Min* op, const Expr& e) final { - CacheEntry a = Produce(op->a); - CacheEntry b = Produce(op->b); - if (a.has_side_effect || b.has_side_effect) { - return Binary_(op, e, a.value, b.value); - } - return Binary(op, e); - } - // Add - Expr Mutate_(const Add* op, const Expr& e) final { - if (!EnableOpt(op->type)) { - return Binary(op, e); - } - CacheEntry a = Produce(op->a); - CacheEntry b = Produce(op->b); - if (a.has_side_effect || b.has_side_effect) { - return Binary_(op, e, a.value, b.value); - } - return SumAdd(a, b, +1); - } - // Sub - Expr Mutate_(const Sub* op, const Expr& e) final { - if (!EnableOpt(op->type)) { - return Binary(op, e); - } - CacheEntry a = Produce(op->a); - CacheEntry b = Produce(op->b); - if (a.has_side_effect || b.has_side_effect) { - return Binary_(op, e, a.value, b.value); - } - return SumAdd(a, b, -1); - } - // Mul - Expr Mutate_(const Mul* op, const Expr& e) final { - if (!EnableOpt(op->type)) { - return Binary(op, e); - } - CacheEntry a = Produce(op->a); - CacheEntry b = Produce(op->b); - if (a.has_side_effect || b.has_side_effect) { - return Binary_(op, e, a.value, b.value); - } - if (is_const(a.value) && is_const(b.value)) { - return ComputeExpr(a.value, b.value); - } else if (is_const(a.value)) { - return SumMulConst(b.AsSum(), a.value); - } else if (is_const(b.value)) { - return SumMulConst(a.AsSum(), b.value); - } else { - return Binary(op, e); - } - } - // Variable - Expr Mutate_(const Variable* op, const Expr& e) final { - auto it = var_level_.find(op); - if (it != var_level_.end()) { - stack_.back().max_level = it->second; - } - return IRMutator::Mutate_(op, e); - } - // comparison - Expr Mutate_(const LT* op, const Expr& e) { - if (!EnableOpt(op->a.type())) { - return Binary(op, e); - } - CacheEntry a = Produce(op->a); - CacheEntry b = Produce(op->b); - if (a.has_side_effect || b.has_side_effect) { - return Binary_(op, e, a.value, b.value); - } - Expr b_sub_a = SumAdd(b, a, -1); - if (EvalSet(b_sub_a, var_range_).can_prove_positive()) { - return make_const(op->type, true); - } else { - return Binary_(op, e, a.value, b.value); - } - } - // IntImm - Expr Mutate_(const IntImm* op, const Expr& e) final { - if (op->type != Int(32)) return e; - auto it = cache_intimm_.find(op->value); - if (it != cache_intimm_.end()) { - return it->second; - } else { - cache_intimm_[op->value] = e; - return e; - } - } - // Div operator - Expr Mutate_(const Div* op, const Expr& e) final { - if (!EnableOpt(op->type)) { - return Binary(op, e); - } - CacheEntry a = Produce(op->a); - CacheEntry b = Produce(op->b); - if (a.has_side_effect || b.has_side_effect) { - return Binary_(op, e, a.value, b.value); - } - if (is_const(a.value) && is_const(b.value)) { - return ComputeExpr
(a.value, b.value); - } else if (is_const(b.value)) { - return SumDivConst(a.AsSum(), b.value); - } else { - return Binary(op, e); - } - } - // Mod operator - Expr Mutate_(const Mod* op, const Expr& e) final { - if (!EnableOpt(op->type)) { - return Binary(op, e); - } - CacheEntry a = Produce(op->a); - CacheEntry b = Produce(op->b); - if (a.has_side_effect || b.has_side_effect) { - return Binary_(op, e, a.value, b.value); - } - if (is_const(a.value) && is_const(b.value)) { - return ComputeExpr(a.value, b.value); - } else if (is_const(b.value)) { - return SumModConst(a.AsSum(), b.value); - } else { - return Binary(op, e); - } - } - - Expr Mutate_(const And* op, const Expr& e) final { - Expr expr = IRMutator::Mutate_(op, e); - op = expr.as(); - if (is_one(op->a)) return op->b; - if (is_one(op->b)) return op->a; - return expr; - } - // Call - Expr Mutate_(const Call* op, const Expr& e) final { - if (!op->is_pure()) { - stack_.back().has_side_effect = true; - } - Expr expr = IRMutator::Mutate_(op, e); - op = expr.as(); - if (op->is_intrinsic(Call::likely) && is_const(op->args[0])) { - return op->args[0]; - } else { - return expr; - } - } - // For - Stmt Mutate_(const For* op, const Stmt& s) { - ++level_counter_; - Var loop_var(op->loop_var.node_); - this->SetRange(loop_var, - Range::make_by_min_extent(op->min, op->extent), - level_counter_); - Stmt stmt = IRMutator::Mutate_(op, s); - --level_counter_; - return stmt; - } - // IfThenElse - Stmt Mutate_(const IfThenElse* op, const Stmt& s) { - Stmt stmt = IRMutator::Mutate_(op, s); - op = stmt.as(); - if (is_one(op->condition)) return op->then_case; - return stmt; - } - // AttrStmt - Stmt Mutate_(const AttrStmt* op, const Stmt& s) { - if (op->attr_key == attr::thread_extent || - op->attr_key == attr::virtual_thread) { - ++level_counter_; - IterVar iv(op->node.node_); - CHECK_NE(iv->thread_tag.length(), 0U); - if (!var_level_.count(iv->var.get())) { - this->SetRange(iv->var, - Range::make_by_min_extent(0, op->value), - level_counter_); - } - Stmt stmt = IRMutator::Mutate_(op, s); - --level_counter_; - return stmt; - } else { - return IRMutator::Mutate_(op, s); - } - } - // The simplify statement. - static FMutateExpr& vtable_expr() { // NOLINT(*) - static FMutateExpr inst; return inst; - } - - private: - template - Expr Binary(const T* op, Expr e) { - Expr a = this->Mutate(op->a); - Expr b = this->Mutate(op->b); - BinaryExpr key{static_cast(T::_type_info), a, b}; - auto it = cache_binary_.find(key); - if (it != cache_binary_.end()) { - return it->second; - } else { - Expr ret = Binary_(op, e, a, b); - cache_binary_[key] = ret; - return ret; - } - } - // return entry - CacheEntry ret_entry_; - // internal information stack - std::vector stack_; - // cache sum - std::map cache_sum_; - // cache of normal binary op - std::map cache_binary_; - // cache of int constant - std::unordered_map cache_intimm_; - // range of each var - std::unordered_map var_range_; - // level of each var - std::unordered_map var_level_; - // record history vars, to avoid false positive. - std::vector var_rec_; - // level counter - int level_counter_{0}; - // get constant int value - int64_t GetConstIntValue(const Expr& v) { - int64_t value = 0; - const int64_t *v1 = as_const_int(v); - const uint64_t *v2 = as_const_uint(v); - CHECK(v1 || v2); - if (v1) { - value = *v1; - } else if (v2) { - CHECK_LE(*v2, - static_cast(std::numeric_limits::max())); - value = static_cast(*v2); - } - return value; - } - // Detect if a = q * coeff + r, where r \in [0, coeff), coeff > 0 - // (in Euclidean division) - // returns pair (q, r) if such detection is successful - // returns empty vector otherwise. - // Assumes that coeff is a constant integer - std::vector TryLinearEquation(const ComExpr& a, - const Expr& coeff) { - Type type = coeff.type(); - int64_t value = GetConstIntValue(coeff); - CHECK_NE(value, 0); - if (value < 0) return {}; - // Given that denominator (value variable) is positive, truncated division - // (i.e., TVM's division semantics) is equivalent to Euclidean division if and only if - // numerator is non-negative or numerator is divisible by denominator (i.e., value) - IntSet numerator_int_set = EvalSet(Sum2Expr(a, type), var_range_); - bool numerator_is_non_neg = numerator_int_set.can_prove_non_negative(); - // Try to separate terms of a into ones that can be proven to be - // divisible by coeff and ones that are not - // We will build q and r from divisible and non_divisible respectively - auto divisible = make_node(); - auto non_divisible = make_node(); - if (a->base % value == 0) { - divisible->base = a->base; - } else { - non_divisible->base = a->base; - } - for (const auto& e : a->elem) { - if (e.scale % value == 0) { - divisible->elem.push_back(e); - } else { - non_divisible->elem.push_back(e); - } - } - bool non_divisible_is_simplified = false; - int64_t div_result; - Expr non_divisible_res = Sum2Expr(ComExpr(non_divisible), type); - // if non_divisible part consists of only an integer and numerator is non-negative, - // we can simply divide it by coeff - if (is_const(non_divisible_res)) { - int64_t non_divisible_const = GetConstIntValue(non_divisible_res); - if (numerator_is_non_neg || non_divisible_const == 0) { - non_divisible_is_simplified = true; - // We need to do an Euclidean division here because (a*b + c)/b == a + c/b - // holds true only if division is Euclidean - div_result = HalideIR::Internal::div_imp(non_divisible_const , value); - } - } else { - // If we can prove that non_divisible part lies within [0, coeff), then - // non_divisible itself will be our r - IntSet non_divisible_set = EvalSet(non_divisible_res, var_range_); - if (non_divisible_set.min().type() == type && - non_divisible_set.max().type() == type) { - if ( (non_divisible_set.is_single_point() && - can_prove(non_divisible_set.point_value() == 0)) || - (numerator_is_non_neg && - can_prove(non_divisible_set.min() >= make_zero(type)) && - can_prove(non_divisible_set.max() < coeff)) ) { - non_divisible_is_simplified = true; - div_result = 0; - } - } - } - if (non_divisible_is_simplified) { - non_divisible->base -= div_result * value; - divisible->base /= value; - divisible->base += div_result; - for (auto& e : divisible->elem) { - e.scale /= value; - } - return {ComExpr(divisible), ComExpr(non_divisible)}; - } else { - return {}; - } - } - // subroutine to do produce a % v - Expr SumModConst(ComExpr a, Expr v) { - std::vector pair = TryLinearEquation(a, v); - if (pair.size() == 0) { - int64_t value = GetConstIntValue(v); - auto n = make_node(); - // FIXME(derisavi) : The following can be done only for Euclidean division/mod. - // Therefore, it's only valid when truncated division/mod is equivalent to Euclidean one, - // that is, if and only if a and v are - // both negative or both positive or a is divisible by v. - // Extend the code to handle cases where the above condition is not satisfied, i.e., - // a and v are of different signs and a is not divisible by v. - n->base = a->base % value; - for (auto e : a->elem) { - if (e.scale % value == 0) continue; - e.scale = e.scale % value; - n->elem.push_back(e); - } - Expr ret = Sum2Expr(ComExpr(n), v.type()) % v; - if (const Mod* mod = ret.as()) { - return Binary(mod, ret); - } else { - // Sometimes the result is a constant, this may happen when value is -1 - CHECK(is_const(ret)) << "CanonicalSimplify: " - << Sum2Expr(ComExpr(n), v.type()) << " % " << v << " is " << ret - << " which is neither Mod, nor a constant"; - return ret; - } - } - ret_entry_.sum = pair[1]; - ret_entry_.max_level = stack_.back().max_level; - ret_entry_.has_side_effect = stack_.back().has_side_effect; - auto it = cache_sum_.find(ret_entry_.sum); - if (it != cache_sum_.end()) { - ret_entry_ = it->second; - } else { - ret_entry_.value = Sum2Expr(ret_entry_.sum, v.type()); - cache_sum_[ret_entry_.sum] = ret_entry_; - } - return ret_entry_.value; - } - // subroutine to do produce a % v - Expr SumDivConst(ComExpr a, Expr v) { - std::vector pair = TryLinearEquation(a, v); - if (pair.size() == 0) { - Expr ret = Sum2Expr(a, v.type()) / v; - return Binary(ret.as
(), ret); - } - ret_entry_.sum = pair[0]; - ret_entry_.max_level = stack_.back().max_level; - ret_entry_.has_side_effect = stack_.back().has_side_effect; - auto it = cache_sum_.find(ret_entry_.sum); - if (it != cache_sum_.end()) { - ret_entry_ = it->second; - } else { - ret_entry_.value = Sum2Expr(ret_entry_.sum, v.type()); - cache_sum_[ret_entry_.sum] = ret_entry_; - } - return ret_entry_.value; - } - // subroutine to do produce - Expr SumMulConst(ComExpr a, Expr v) { - int64_t value = GetConstIntValue(v); - if (value == 0) { - return make_zero(v.type()); - } - auto vsum = make_node(*a.operator->()); - vsum->base *= value; - for (auto& e : vsum->elem) { - e.scale *= value; - } - ret_entry_.sum = ComExpr(vsum); - ret_entry_.max_level = stack_.back().max_level; - ret_entry_.has_side_effect = stack_.back().has_side_effect; - auto it = cache_sum_.find(ret_entry_.sum); - if (it != cache_sum_.end()) { - ret_entry_ = it->second; - } else { - ret_entry_.value = Sum2Expr(ret_entry_.sum, v.type()); - cache_sum_[ret_entry_.sum] = ret_entry_; - } - return ret_entry_.value; - } - // add two ComExpr together - ComExpr SumAdd_(const ComExpr& suma, - const ComExpr& sumb, - int bscale) { - auto n = make_node(); - n->base = suma->base + sumb->base * bscale; - // merge of suma and sumb; - size_t i = 0, j = 0; - while (i < suma->elem.size() && j < sumb->elem.size()) { - const auto& a = suma->elem[i]; - const auto& b = sumb->elem[j]; - if (a.value.same_as(b.value) && a.level == b.level) { - ComExprEntry e = a; - e.scale = a.scale + b.scale * bscale; - if (e.scale != 0) { - n->elem.push_back(e); - } - ++i; ++j; - } else if (a < b) { - n->elem.push_back(a); - ++i; - } else { - ComExprEntry e = b; - e.scale *= bscale; - n->elem.push_back(e); - ++j; - } - } - for (; i < suma->elem.size(); ++i) { - n->elem.push_back(suma->elem[i]); - } - for (; j < sumb->elem.size(); ++j) { - ComExprEntry e = sumb->elem[j]; - e.scale *= bscale; - n->elem.push_back(e); - } - return ComExpr(n); - } - // subroutine to do produce - Expr SumAdd(CacheEntry a, CacheEntry b, int bscale) { - ret_entry_.sum = SumAdd_(a.AsSum(), b.AsSum(), bscale); - CHECK_NE(stack_.size(), 0U); - ret_entry_.max_level = stack_.back().max_level; - ret_entry_.has_side_effect = stack_.back().has_side_effect; - auto it = cache_sum_.find(ret_entry_.sum); - if (it != cache_sum_.end()) { - ret_entry_ = it->second; - } else { - ret_entry_.value = Sum2Expr(ret_entry_.sum, a.value.type()); - cache_sum_[ret_entry_.sum] = ret_entry_; - } - return ret_entry_.value; - } - // convert sum to expr - Expr Sum2Expr(const ComExpr& com, Type t) { - Expr vsum; - if (com->base > 0) { - vsum = make_const(t, com->base); - } - for (const ComExprEntry& e : com->elem) { - if (e.scale > 0) { - Expr v = e.value; - if (e.scale != 1) { - v = Mul::make(v, make_const(t, e.scale)); - } - if (vsum.defined()) { - vsum = Add::make(vsum, v); - } else { - vsum = v; - } - } - } - if (com->base < 0) { - if (vsum.defined()) { - vsum = Sub::make(vsum, make_const(t, -com->base)); - } else { - vsum = make_const(t, com->base); - } - } - for (const ComExprEntry& e : com->elem) { - if (e.scale < 0) { - Expr v = e.value; - if (e.scale != -1) { - v = Mul::make(v, make_const(t, -e.scale)); - } - if (vsum.defined()) { - vsum = Sub::make(vsum, v); - } else { - vsum = Sub::make(make_zero(t), v); - } - } - } - if (vsum.defined()) { - return vsum; - } else { - return make_zero(t); - } - } -}; - -using CInternal = Canonical::Internal; - -Canonical::Canonical(Map vrange) - : ptr_(std::make_shared(vrange)) {} - -Expr Canonical::Simplify(Expr expr) { - return ptr_->Mutate(expr); -} - -Stmt Canonical::Simplify(Stmt stmt) { - return ptr_->Mutate(stmt); -} - -void Canonical::SetRange(Var v, Range r, int level) { - ptr_->SetRange(v, r, level); -} -} // namespace arith - -namespace ir { - -Stmt CanonicalSimplify(Stmt stmt, Map vrange) { - return arith::Canonical(vrange).Simplify(stmt); -} - -Expr CanonicalSimplify(Expr expr, Map vrange) { - return arith::Canonical(vrange).Simplify(expr); -} - -template -T Simplify_(T a, Map vrange) { - using namespace HalideIR::Internal; - Scope rscope; - for (auto kv : vrange) { - Range r = kv.second; - rscope.push( - kv.first.get(), - Interval(r->min, - simplify(r->min + r->extent - make_const(r->min.type(), 1)))); - } - return HalideIR::Internal::simplify(a, true, rscope); -} - - -/*! - * \brief Simplify just the combiner of the given reduce node. - * - * This function applies Simplify to the components of the top reduction's - * combiner, but not to the source or condition of the reduction. - * It also removes all components which are not used to - * compute the resulting value (the value_index-th value). - * - * If \p expr is not a reduction node, it is left unchanged. - * - * \param expr The expression to be simplifed. - * \return Simplified expression. - */ -Expr SimplifyCombiner(const Expr& expr, const Map& vrange = Map()) { - const Reduce* op = expr.as(); - if (!op) { - return expr; - } - - // First simplify the results - Array simplified_result; - for (const auto& res : op->combiner->result) { - simplified_result.push_back(Simplify(res, vrange)); - } - - // Which components to keep - std::vector used(op->combiner->result.size(), false); - - // This function recursively marks the used components starting from - // the index idx - std::function mark_used; - mark_used = [&used, &simplified_result, op, &mark_used](size_t idx) { - // if the idx-th component was marked as used before, do nothing - if (used[idx]) return; - used[idx] = true; - - // check if the idx-th result expr uses some lhs or rhs variables - // and recursively mark the corresponding components - for (size_t i = 0; i < simplified_result.size(); ++i) - if (!used[i]) { - if (ExprUseVar(simplified_result[idx], op->combiner->lhs[i]) || - ExprUseVar(simplified_result[idx], op->combiner->rhs[i])) - mark_used(i); - } - }; - - // mark all used components starting from the value_index - mark_used(op->value_index); - - // components which have side effects should also be preserved - for (size_t i = 0; i < used.size(); ++i) { - if (HasSideEffect(op->source[i]) || HasSideEffect(op->combiner->identity_element[i]) || - HasSideEffect(op->combiner->result[i])) { - mark_used(i); - } - } - - int new_value_index = op->value_index; - Array new_result; - Array new_identity; - Array new_lhs; - Array new_rhs; - Array new_source; - - // new stuff is old stuff which is used - for (size_t i = 0; i < used.size(); ++i) { - if (used[i]) { - // We simplify the result and identity, but not the source - new_result.push_back(simplified_result[i]); - new_identity.push_back(Simplify(op->combiner->identity_element[i], vrange)); - new_lhs.push_back(op->combiner->lhs[i]); - new_rhs.push_back(op->combiner->rhs[i]); - new_source.push_back(op->source[i]); - } else if (static_cast(i) < op->value_index) { - // value_index should also be adjusted - new_value_index--; - } - } - - CommReducer new_combiner = CommReducerNode::make(new_lhs, new_rhs, new_result, new_identity); - return Reduce::make(new_combiner, new_source, op->axis, op->condition, new_value_index); -} - -/*! - * \brief Remove a single reduction over empty axis. - * - * If \p e is a reduction node and its axis is empty, replace it with its source, - * otherwise return \p e unchanged. - * - * \param e The expression to be transformed. - * \return The transformed expression. - */ -Expr RemoveEmptyReduction(const Expr& e) { - const Reduce* r = e.as(); - if (r && r->axis.empty()) { - // Note that here we assume that the identity element is indeed identity. Without this - // assumption we would have to perform a single iteration of the loop, i.e. use - // `(*r->combiner.get())(r->combiner->identity_element, r->source)[r->value_index]` - // instead of `r->source[r->value_index]`. The former may be more difficult to simplify. - return Select::make(r->condition, - r->source[r->value_index], - r->combiner->identity_element[r->value_index]); - } - return e; -} - -Expr Simplify(Expr a, Map vrange) { - // We should not pass an expression having a non-HalideIR op to - // Halide::Internal::simplify. Reduce op is the only such op at this time - // and it only appears as the top op in an expression. So we strip it - // first and send the sub-expressions to the simplifier. - if (const Reduce* r = a.as()) { - // If axis is empty, we can remove the reduce op completely. - if (r->axis.empty()) - return Simplify_(RemoveEmptyReduction(a), vrange); - - // Simplify the combiner of the reduction - a = SimplifyCombiner(a, vrange); - r = a.as(); - - // If axis is not empty then we add the information about ranges to vrange - for (const IterVar& iv : r->axis) { - if (vrange.count(iv->var)) { - Range existing_range = vrange[iv->var]; - CHECK(Equal(existing_range->min, iv->dom->min) && - Equal(existing_range->extent, iv->dom->extent)) - << "Simplify was given vrange stating that the range of the reduction var " - << iv << " is " << existing_range << ". This is probably a mistake."; - } - vrange.Set(iv->var, iv->dom); - } - - Array new_source; - for (auto& e : r->source) { - new_source.push_back(Simplify_(e, vrange)); - } - Expr new_condition = Simplify_(r->condition, vrange); - if (r->source.same_as(new_source) && - r->condition.same_as(new_condition)) { - return a; - } else { - return Reduce::make( - r->combiner, new_source, r->axis, new_condition, r->value_index); - } - } - return Simplify_(a, vrange); -} - -Stmt Simplify(Stmt a, Map vrange) { - return Simplify_(a, vrange); -} -} // namespace ir -} // namespace tvm diff --git a/src/arithmetic/canonical.h b/src/arithmetic/canonical.h deleted file mode 100644 index a02dbeef7e3a..000000000000 --- a/src/arithmetic/canonical.h +++ /dev/null @@ -1,56 +0,0 @@ -/*! - * Copyright (c) 2017 by Contributors - * \file canonical.h - * \brief Internal canonicalized expression simplification engine. - */ -#ifndef TVM_ARITHMETIC_CANONICAL_H_ -#define TVM_ARITHMETIC_CANONICAL_H_ - -#include -#include -#include - -namespace tvm { -namespace arith { - -/*! - * \brief A stateful CanonicalEngine over SSA. - * - * Simplify and CSE with canonicalization expressions. - * Each call's result will get cached, so next call will - * simply return the cached result. - */ -class Canonical { - public: - /*! \brief constructor */ - explicit Canonical(Map var_range); - /*! - * \brief simplify expression e. - * \param expr The expression to be simplified. - */ - Expr Simplify(Expr expr); - /*! - * \brief simplify stmt. - * \param stmt The stmt to be simplified. - */ - Stmt Simplify(Stmt expr); - /*! - * \brief Set range and level variable - * \param v The variable - * \param r The range of the variable, can be undefined. - * \param level The scope level of the variable, - * affect the order of formula in communicative ops. - */ - void SetRange(Var v, Range r, int level); - - class Internal; - private: - // Internal pointer - std::shared_ptr ptr_; -}; - - -} // namespace arith -} // namespace tvm - -#endif // TVM_ARITHMETIC_CANONICAL_H_ diff --git a/src/arithmetic/canonical_simplify.cc b/src/arithmetic/canonical_simplify.cc new file mode 100644 index 000000000000..d9b528291211 --- /dev/null +++ b/src/arithmetic/canonical_simplify.cc @@ -0,0 +1,903 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file canonical_simplify.cc + * \brief Canonical form based simplification. + */ +#include +#include +#include +#include "const_fold.h" +#include "pattern_match.h" +#include "rewrite_simplify.h" + +namespace tvm { +namespace arith { + +using namespace ir; + +class SumExpr; +class SplitExpr; + +/*! + * \brief Base class of all temporary expression introduced + * for canonicalization. + */ +class CanonicalExprNode : public BaseExprNode { + public: + /*! + * \brief Return the normal Expr that is equivalent to self. + * \note Can mutate the internal data structure. + * \return The normal expression. + */ + virtual Expr Normalize() const = 0; + + // overrides + void VisitAttrs(tvm::AttrVisitor* v) final { + } + void accept(HalideIR::Internal::IRVisitor* v, const Expr& e) const final { + LOG(FATAL) << "not supported"; + } + IRNodeType type_info() const final { + return IRNodeType::ExtensionExpr; + } + + static constexpr const char* _type_key = "arith.CanonicalExpr"; + TVM_DECLARE_BASE_NODE_INFO(CanonicalExprNode, BaseExprNode); +}; + +/*! + * \brief Internal "Split normal form" of expression. + * + * This is a special expression that represents + * a scaled value derived from a split of an index. + * + * result = ((index % upper_factor) / lower_factor) * scale + */ +class SplitExprNode : public CanonicalExprNode { + public: + /*! \brief The base index expression. */ + Expr index; + /*! \brief The division factor ratio. */ + int64_t lower_factor{1}; + /*! + * \brief The upper factor. + * invariance: (upper_factor == kPosInf || upper_factor % lower_factor == 0) + */ + int64_t upper_factor{kPosInf}; + /*! \brief scale to the expression. */ + int64_t scale{1}; + + /*! \brief verify that this is a valid entry. */ + void Verify() const { + CHECK(upper_factor == kPosInf || upper_factor % lower_factor == 0); + } + + Expr NormalizeWithScale(int64_t sscale) const { + Expr res = this->index; + Type dtype = this->type; + if (this->scale == 0) { + return make_const(dtype, 0); + } + if (this->upper_factor != SplitExprNode::kPosInf) { + res = res % make_const(dtype, this->upper_factor); + } + if (this->lower_factor != 1) { + res = res / make_const(dtype, this->lower_factor); + } + sscale *= this->scale; + if (sscale != 1) { + CHECK(!dtype.is_uint() || sscale > 0); + res = res * make_const(dtype, sscale); + } + return res; + } + + Expr Normalize() const final { + return NormalizeWithScale(1); + } + + void MulToSelf(int64_t scale) { + this->scale *= scale; + } + + inline bool IndexEqual(const SplitExpr& other) const; + + /*! \brief positive infty */ + static const constexpr int64_t kPosInf = ConstIntBoundNode::kPosInf; + static constexpr const char* _type_key = "arith.SplitExpr"; + TVM_DECLARE_NODE_TYPE_INFO(SplitExprNode, CanonicalExprNode); +}; + +TVM_DEFINE_COW_NODE_REF(SplitExpr, Expr, SplitExprNode); + +inline bool SplitExprNode::IndexEqual(const SplitExpr& other) const { + if (index.same_as(other->index)) return true; + return ir::Equal(index, other->index); +} + +/*! + * \brief Normal form that represents sum of expressions. + * + * result = sum(args) + base. + */ +class SumExprNode : public CanonicalExprNode { + public: + /*! + * \brief arguments to be summed up. + * + * args are divided into segments with the same index. + * within each segment, the SplitExpr is ordered in descending order of lower_factor. + */ + std::vector args; + /*! \brief Base value in the summation. */ + int64_t base{0}; + /*! + * \brief Return the normal Expr that is equivalent to self. + * \return The normal expression. + */ + Expr Normalize() const final { + // quick path 1. + if (this->args.size() == 0) { + return make_const(this->type, this->base); + } + return Normalize_(this->type, + SimplifySplitExprs(args), + base); + } + /*! + * \brief Whether self is divisible by scale. + * \param scale The scale to be applied. + */ + bool DivisibleBy(int64_t scale) { + if (base % scale != 0) return false; + for (size_t i = 0; i < this->args.size(); ++i) { + if (args[i]->scale % scale != 0) return false; + } + return true; + } + /*! + * \brief mul scale to self. + * \param scale The scale to be applied. + */ + void MulToSelf(int64_t scale) { + this->base *= scale; + for (size_t i = 0; i < this->args.size(); ++i) { + args[i].CopyOnWrite()->scale *= scale; + } + } + /*! + * \brief divide by scale. + * \param scale The scale to be applied. + */ + void DivideBy(int64_t scale) { + CHECK_EQ(this->base % scale, 0); + this->base /= scale; + for (size_t i = 0; i < this->args.size(); ++i) { + CHECK_EQ(args[i]->scale % scale, 0); + args[i].CopyOnWrite()->scale /= scale; + } + } + /*! + * \brief add constant value to self. + * \param value to be added. + */ + void AddToSelf(int64_t value) { + this->base += value; + } + /*! + * \brief self += other * scale; + * \param other The expression to be added. + * \param scale The additional scale on value. + */ + void AddToSelf(SplitExpr other, int64_t scale) { + if (other->scale == 0) return; + // We need to maintain the segment invariance: + // Same index are stored close to each other. + // sorted from big lower_factor to small one. + size_t start = 0; + for (; start < args.size(); ++start) { + if (args[start]->IndexEqual(other)) break; + } + for (size_t j = start; j < args.size(); ++j) { + if (!args[j]->IndexEqual(other) || + other->lower_factor > args[j]->lower_factor) { + other.CopyOnWrite()->scale *= scale; + this->args.insert(this->args.begin() + j, other); + return; + } + if (other->lower_factor == args[j]->lower_factor && + other->upper_factor == args[j]->upper_factor) { + args[j].CopyOnWrite()->scale += other->scale * scale; + return; + } + } + // Insert other in the end. + other.CopyOnWrite()->scale *= scale; + this->args.emplace_back(std::move(other)); + } + + void AddToSelf(const SumExpr& other, int64_t scale); + + static constexpr const char* _type_key = "arith.SumExpr"; + TVM_DECLARE_NODE_TYPE_INFO(SumExprNode, CanonicalExprNode); + + private: + /*! + * \brief Simplify the args by merging SplitExprs + * \param args The original list of arguments. + * \return simplified version. + */ + static std::vector + SimplifySplitExprs(std::vector args) { + // NOTE: This algorithm relies on the factor that args are divided into segments + // and each segment is sorted in descending order of lower_factor. + for (size_t i = 0; i < args.size(); ++i) { + if (args[i]->scale == 0) continue; + for (size_t j = i + 1; j < args.size(); ++j) { + SplitExpr& lhs = args[i]; + SplitExpr& rhs = args[j]; + if (!lhs->IndexEqual(rhs)) break; + if (lhs->upper_factor < rhs->lower_factor) break; + if (lhs->lower_factor == rhs->upper_factor && + lhs->scale % rhs->scale == 0 && + lhs->lower_factor == (lhs->scale / rhs->scale) * rhs->lower_factor) { + // Rules used in the proof: + // + // Rule 1: (x % (c * s)) / c = (x / c) % s + // Proof: + // x can always be decomposed into p * c * s + q * c + r + // where 0 <= q * c + r < c * s and 0 <= r < c. + // Then, lhs = ((p * c * s + q * c + r) % (c * s)) / c = (q * c + r) / c = q + // rhs = ((p * c * s + q * c + r) / c) % s = (p * s + q) % s = q + // Thus, lhs = rhs + // + // The above proof is for the floordiv. + // The same rule also holds for trucdiv(division rule in C). + // Because both sides only involve mul, div and mod, + // we can take abs of x, c and s, apply the floordiv proof, + // and finally add the sign back. + // + // Rule 2: (x / s) * s + x % s = x (true for both truc and floor div) + // + // General merge condition and proof: + // - x = lhs->index % lhs->upper_factor + // - s = lhs->scale / rhs->scale + // - c = rhs->lower_factor + // + // (x / (c * s)) * s + (x % (c * s)) / c + // => ((x / c) / s) * s + ((x / c) % s) + // => (x / c) + // + // Examples: + // + // (z / 6) * 6 + ((z % 6) / 3) * 3 + // => ((z / 6) * 2 + (z % 6) / 3) * 3 + // => (z / 3) * 3 + // note: x = z, c = 3, s = 2 + // + // ((z % 12) / 6) * 6 + ((z % 6) / 3) * 3 + // => (((z % 12) / 6) * 2 + ((z % 12) % 6) / 3) * 3 + // => ((z % 12) / 3) * 3 + // note: x = z % 12, c = 3, s = 2 + // note also the invariance lhs->upper_factor % lhs->lower_factor == 0 + // + SplitExprNode* merged = rhs.CopyOnWrite(); + merged->upper_factor = lhs->upper_factor; + // reset args[i] to be zero. + lhs.CopyOnWrite()->scale = 0; + break; + } + } + } + // sort by the entry + // Here we simply sort by descending order of scales. + // For now, we do not compare by index because that comparison + // can be runtime dependent and create inderminism. + // we do not sort by index for now because it can be costly + // to deep compare Exprs, and address of Vars can be runtime dependent. + // + auto fcompare = [](const SplitExpr& lhs, const SplitExpr& rhs) { + // order by scale first + if (lhs->scale > rhs->scale) return true; + if (lhs->scale < rhs->scale) return false; + // then order by factor + if (lhs->lower_factor > rhs->lower_factor) return true; + if (lhs->lower_factor < rhs->lower_factor) return false; + // then order by upper factor + if (lhs->upper_factor > rhs->upper_factor) return true; + if (lhs->upper_factor < rhs->upper_factor) return false; + // tie. + // TODO(tvm-team) We might consider index as the last comparison point, + // after we make deep comparator more derministic. + // Specifically, we can consider comparing names of vars and break ties with address. + return false; + }; + std::stable_sort(args.begin(), args.end(), fcompare); + return args; + } + static Expr Normalize_(Type dtype, + const std::vector& args, + int64_t base) { + // Positive scales first + Expr res = make_const(dtype, 0); + for (size_t i = 0; i < args.size(); ++i) { + if (args[i]->scale > 0) { + res = res + args[i]->Normalize(); + } + } + if (base > 0) { + res = res + make_const(dtype, base); + } + // negative scales follows using sub. + for (size_t i = 0; i < args.size(); ++i) { + if (args[i]->scale < 0) { + res = res - args[i]->NormalizeWithScale(-1); + } + } + if (base < 0) { + res = res - make_const(dtype, -base); + } + return res; + } +}; + +TVM_DEFINE_COW_NODE_REF(SumExpr, Expr, SumExprNode); + +void SumExprNode::AddToSelf(const SumExpr& other, int64_t scale) { + // NOTE: it is rare to have a balanced long expression, + // linear scan is fine for our case. + for (size_t i = 0; i < other->args.size(); ++i) { + this->AddToSelf(other->args[i], scale); + } + this->AddToSelf(other->base * scale); +} + +// Sub-class RewriteSimplifier::Impl to take benefit of +// rewriter for condition simplification etc. +class CanonicalSimplifier::Impl : public RewriteSimplifier::Impl { + public: + using Rewriter = RewriteSimplifier::Impl; + + explicit Impl(Analyzer* parent) + : Rewriter(parent) {} + + + Expr CanonicalSimplify(Expr expr) { + expr = Mutate(expr); + return expr; + } + + // override the original mutate function. + Expr Mutate(Expr expr) final { + expr = IRMutator::Mutate(expr); + return Normalize(expr); + } + + // Normal mutation without normalization. + Expr CanonicalMutate(Expr expr) { + return IRMutator::Mutate(expr); + } + + using Rewriter::Mutate_; + Expr Mutate_(const Add* op, const Expr& self) final; + Expr Mutate_(const Sub* op, const Expr& self) final; + Expr Mutate_(const Mul* op, const Expr& self) final; + Expr Mutate_(const Div* op, const Expr& self) final; + Expr Mutate_(const Mod* op, const Expr& self) final; + Expr Mutate_(const Reduce* op, const Expr& self) final; + + private: + /*! + * \brief compute lhs / cval + * \param lhs The left operand. + * \param cval The constant value. + * \return The result expression; + */ + SplitExpr SplitDivConst(SplitExpr lhs, int64_t cval); + /*! + * \brief compute lhs % cval + * \param lhs The left operand. + * \param cval The constant value. + * \return The result expression; + */ + SplitExpr SplitModConst(SplitExpr lhs, int64_t cval); + /*! + * \brief Detect if psum = q * coeff + r such that (q >= 0 && r >= 0) + * \param psum The sum expression. + * \param coeff The co-efficient. + * \param out_divisible The result divisible component. + * \param out_non_divisible The non-divisible component. + * \return Whether detection is successful. + */ + bool TryLinearEquation(const SumExprNode* psum, + int64_t coeff, + SumExpr* out_divisible, + SumExpr* out_non_divisible); + /*! + * \brief Normalize expr to normal expr. + * \param expr The input expression. + * \return Normalized expr. + */ + Expr Normalize(Expr expr) { + if (const auto* op = expr.as_derived()) { + return op->Normalize(); + } else { + return expr; + } + } + /*! + * \brief Create a SplitExpr from expr. + * \param expr The input expr. + * \return The transformed SplitExpr. + */ + SplitExpr ToSplitExpr(Expr expr) { + if (const auto* op = expr.as()) { + return GetRef(op); + } + if (const auto* op = expr.as_derived()) { + expr = op->Normalize(); + } + NodePtr n = make_node(); + n->type = expr.type(); + n->index = std::move(expr); + return SplitExpr(n); + } + /*! + * \brief Create a SumExpr from expr. + * \param expr The input expr. + * \return The transformed SumExpr. + */ + SumExpr ToSumExpr(Expr expr) { + if (const auto* op = expr.as()) { + return GetRef(op); + } + NodePtr n = make_node(); + n->type = expr.type(); + if (const auto* op = expr.as()) { + n->base = op->value; + return SumExpr(n); + } else { + n->args.emplace_back(ToSplitExpr(expr)); + return SumExpr(n); + } + } + // Simplify the combiner used in reduce. + Expr SimplifyReduceCombiner(const Reduce* op); +}; + +Expr CanonicalSimplifier::Impl:: +Mutate_(const Add* op, const Expr& self) { + if (!IsIndexType(op->type)) { + return Rewriter::Mutate_(op, self); + } + // normalize + Expr a = this->CanonicalMutate(op->a); + Expr b = this->CanonicalMutate(op->b); + + // const folding + Expr const_res = TryConstFold(a, b); + if (const_res.defined()) return const_res; + + // canonical form simplification. + SumExpr ret = ToSumExpr(std::move(a)); + + if (const auto* op = b.as()) { + ret.CopyOnWrite()->AddToSelf(op->value); + } else if (const auto* op = b.as()) { + ret.CopyOnWrite()->AddToSelf(GetRef(op), 1); + } else { + ret.CopyOnWrite()->AddToSelf(ToSplitExpr(b), 1); + } + return ret; +} + +Expr CanonicalSimplifier::Impl:: +Mutate_(const Sub* op, const Expr& self) { + if (!IsIndexType(op->type)) { + return Rewriter::Mutate_(op, self); + } + // normalize + Expr a = this->CanonicalMutate(op->a); + Expr b = this->CanonicalMutate(op->b); + + // const folding + Expr const_res = TryConstFold(a, b); + if (const_res.defined()) return const_res; + + // canonical form simplification. + SumExpr ret = ToSumExpr(std::move(a)); + + if (const auto* op = b.as()) { + ret.CopyOnWrite()->AddToSelf(-op->value); + } else if (const auto* op = b.as()) { + ret.CopyOnWrite()->AddToSelf(GetRef(op), -1); + } else { + ret.CopyOnWrite()->AddToSelf(ToSplitExpr(b), -1); + } + return ret; +} + + +Expr CanonicalSimplifier::Impl:: +Mutate_(const Mul* op, const Expr& self) { + if (!IsIndexType(op->type)) { + return Rewriter::Mutate_(op, self); + } + // normalize + Expr a = this->CanonicalMutate(op->a); + Expr b = this->CanonicalMutate(op->b); + + // const folding + Expr const_res = TryConstFold(a, b); + if (const_res.defined()) return const_res; + + // x * c + if (a.as()) { + std::swap(a, b); + } + if (const auto* bconst = b.as()) { + if (a.as()) { + SumExpr ret(std::move(a.node_)); + ret.CopyOnWrite()->MulToSelf(bconst->value); + return ret; + } else { + SplitExpr ret = ToSplitExpr(std::move(a)); + ret.CopyOnWrite()->MulToSelf(bconst->value); + return ret; + } + } + + // normal path. + a = Normalize(a); + b = Normalize(b); + if (op->a.same_as(a) && op->b.same_as(b)) { + return self; + } else { + return Mul::make(a, b); + } +} + + +bool CanonicalSimplifier::Impl:: +TryLinearEquation(const SumExprNode* psum, + int64_t coeff, + SumExpr* out_divisible, + SumExpr* out_non_divisible) { + auto divisible = make_node(); + auto non_divisible = make_node(); + divisible->type = psum->type; + non_divisible->type = psum->type; + + if (psum->base % coeff == 0) { + divisible->base = psum->base; + } else { + non_divisible->base = psum->base; + } + for (const auto& e : psum->args) { + if (e->scale % coeff == 0) { + divisible->args.push_back(e); + } else { + non_divisible->args.push_back(e); + } + } + *out_divisible = SumExpr(divisible); + *out_non_divisible = SumExpr(non_divisible); + + if (non_divisible->base == 0 && non_divisible->args.size() == 0) { + return true; + } + if (parent_->CanProveGreaterEqual(divisible->Normalize(), 0) && + parent_->CanProveGreaterEqual(non_divisible->Normalize(), 0)) { + return true; + } else { + return false; + } +} + +SplitExpr CanonicalSimplifier::Impl:: +SplitDivConst(SplitExpr lhs, int64_t cval) { + if (lhs->scale % cval == 0) { + lhs.CopyOnWrite()->scale /= cval; + return lhs; + } + + if (cval % lhs->scale == 0) { + int64_t scaled_cval = cval / lhs->scale; + if (lhs->upper_factor == SplitExprNode::kPosInf || + lhs->upper_factor % (lhs->lower_factor * scaled_cval) == 0) { + // directly fold division. + lhs.CopyOnWrite()->scale = 1; + lhs.CopyOnWrite()->lower_factor *= scaled_cval; + lhs->Verify(); + return lhs; + } else if (lhs->upper_factor <= (lhs->lower_factor * scaled_cval)) { + // (x % c1) / c2 => 0 when c2 >= c1 + return ToSplitExpr(make_zero(lhs.type())); + } else { + // move the upper_factor modular into index. + lhs.CopyOnWrite()->index = + lhs->index % make_const(lhs.type(), lhs->upper_factor); + lhs.CopyOnWrite()->upper_factor = SplitExprNode::kPosInf; + lhs.CopyOnWrite()->scale = 1; + lhs.CopyOnWrite()->lower_factor *= scaled_cval; + lhs->Verify(); + return lhs; + } + } + // directly return the split with cval == 1 + lhs = ToSplitExpr(Normalize(lhs)); + CHECK_EQ(lhs->scale, 1); + lhs.CopyOnWrite()->lower_factor *= cval; + return lhs; +} + +Expr CanonicalSimplifier::Impl:: +Mutate_(const Div* op, const Expr& self) { + if (!IsIndexType(op->type)) { + return Rewriter::Mutate_(op, self); + } + Expr a = this->CanonicalMutate(op->a); + Expr b = this->CanonicalMutate(op->b); + + // const folding + Expr const_res = TryConstFold
(a, b); + if (const_res.defined()) return const_res; + PVar c1; + // x / c1 + if (c1.Match(b) && c1.Eval()->value > 0) { + int64_t cval = c1.Eval()->value; + if (cval == 1) return a; + + if (const auto* psum = a.as()) { + SumExpr lhs, extra; + if (TryLinearEquation(psum, cval, &lhs, &extra)) { + lhs.CopyOnWrite()->DivideBy(cval); + Expr temp = Normalize(extra); + if (const auto* pconst = temp.as()) { + lhs.CopyOnWrite()->AddToSelf(pconst->value / cval); + } else { + // if extra <= cval, it means the extra can be eliminated. + if (TryCompare(temp, cval) != kLT) { + lhs.CopyOnWrite()->AddToSelf( + SplitDivConst(ToSplitExpr(temp), cval), 1); + } + } + return lhs; + } + } else { + // if a >= 0 && a < cval, then result == 0 + auto cbound = parent_->const_int_bound(Normalize(a)); + if (cbound->min_value >= 0 && cbound->max_value < cval) { + return make_zero(a.type()); + } + } + return SplitDivConst(ToSplitExpr(std::move(a)), cval); + } + // normal path + a = Normalize(a); + b = Normalize(b); + if (op->a.same_as(a) && op->b.same_as(b)) { + return self; + } else { + return Div::make(a, b); + } +} + +SplitExpr CanonicalSimplifier::Impl:: +SplitModConst(SplitExpr lhs, int64_t cval) { + if (lhs->scale % cval == 0) { + lhs.CopyOnWrite()->scale = 0; + return lhs; + } + if (cval % lhs->scale == 0) { + // (x * c1) % (c2 * c1) => (x % c2) * c1 + int64_t scaled_cval = cval / lhs->scale; + // (x / c1) % c2 => (x % (c1 * c2)) / c2 + int64_t new_upper_factor = lhs->lower_factor * scaled_cval; + // try to see if we can reduce the existing upper modular. + if (lhs->upper_factor == SplitExprNode::kPosInf || + lhs->upper_factor % new_upper_factor == 0) { + lhs.CopyOnWrite()->upper_factor = new_upper_factor; + lhs->Verify(); + return lhs; + } else if (new_upper_factor % lhs->upper_factor == 0) { + // (x % 2) % 4 => x % 2 + return lhs; + } + } + // Normalize the value. + lhs = ToSplitExpr(Normalize(lhs)); + CHECK_EQ(lhs->scale, 1); + CHECK_EQ(lhs->lower_factor, 1); + lhs.CopyOnWrite()->upper_factor = cval; + return lhs; +} + +Expr CanonicalSimplifier::Impl:: +Mutate_(const Mod* op, const Expr& self) { + if (!IsIndexType(op->type)) { + return Rewriter::Mutate_(op, self); + } + // normalize + Expr a = this->CanonicalMutate(op->a); + Expr b = this->CanonicalMutate(op->b); + + // const folding + Expr const_res = TryConstFold(a, b); + if (const_res.defined()) return const_res; + + PVar c1; + // x % c1 + if (c1.Match(b) && c1.Eval()->value > 0) { + int64_t cval = c1.Eval()->value; + if (const auto* psum = a.as()) { + SumExpr lhs, extra; + if (TryLinearEquation(psum, cval, &lhs, &extra)) { + Expr temp = Normalize(extra); + if (temp.as()) { + return temp % c1.Eval(); + } else { + // If temp < cval && temp >=0 then can remove the mod. + if (TryCompare(temp, cval) == kLT) { + return temp; + } else { + return SplitModConst(ToSplitExpr(temp), cval); + } + } + } + } else { + // if a >= 0 && a < cval, then result == 0 + auto cbound = parent_->const_int_bound(Normalize(a)); + if (cbound->min_value >= 0 && cbound->max_value < cval) { + return a; + } + } + return SplitModConst(ToSplitExpr(std::move(a)), cval); + } + // normal path + a = Normalize(a); + b = Normalize(b); + if (op->a.same_as(a) && op->b.same_as(b)) { + return self; + } else { + return Mod::make(a, b); + } +} + +// Simplify reduce expression. +Expr CanonicalSimplifier::Impl:: +SimplifyReduceCombiner(const Reduce* op) { + // First simplify the results + Array simplified_result; + for (const auto& res : op->combiner->result) { + Expr new_res = Mutate(res); + simplified_result.push_back(new_res); + } + + // Which components to keep + std::vector used(op->combiner->result.size(), false); + + // This function recursively marks the used components starting from + // the index idx + std::function mark_used; + mark_used = [&used, &simplified_result, op, &mark_used](size_t idx) { + // if the idx-th component was marked as used before, do nothing + if (used[idx]) return; + used[idx] = true; + + // check if the idx-th result expr uses some lhs or rhs variables + // and recursively mark the corresponding components + for (size_t i = 0; i < simplified_result.size(); ++i) + if (!used[i]) { + if (ExprUseVar(simplified_result[idx], op->combiner->lhs[i]) || + ExprUseVar(simplified_result[idx], op->combiner->rhs[i])) + mark_used(i); + } + }; + + // mark all used components starting from the value_index + mark_used(op->value_index); + + // components which have side effects should also be preserved + for (size_t i = 0; i < used.size(); ++i) { + if (HasSideEffect(op->source[i]) || + HasSideEffect(op->combiner->identity_element[i]) || + HasSideEffect(op->combiner->result[i])) { + mark_used(i); + } + } + + int new_value_index = op->value_index; + Array new_result; + Array new_identity; + Array new_lhs; + Array new_rhs; + Array new_source; + + // new stuff is old stuff which is used + for (size_t i = 0; i < used.size(); ++i) { + if (used[i]) { + // We simplify the result and identity, but not the source + new_result.push_back(simplified_result[i]); + new_identity.push_back(Mutate(op->combiner->identity_element[i])); + new_lhs.push_back(op->combiner->lhs[i]); + new_rhs.push_back(op->combiner->rhs[i]); + new_source.push_back(op->source[i]); + } else if (static_cast(i) < op->value_index) { + // value_index should also be adjusted + new_value_index--; + } + } + + CommReducer new_combiner = + CommReducerNode::make(new_lhs, new_rhs, new_result, new_identity); + return Reduce::make( + new_combiner, new_source, op->axis, op->condition, new_value_index); +} + +Expr CanonicalSimplifier::Impl:: +Mutate_(const Reduce* op, const Expr& self) { + // Setup the domain information before simplification. + for (const IterVar& iv : op->axis) { + parent_->Bind(iv->var, iv->dom); + } + // Recursively call simplification when necessary. + Expr ret = IRMutator::Mutate_(op, self); + op = ret.as(); + // already been simplified by const reduction axis removal + if (op == nullptr) return ret; + if (op->axis.empty()) { + // Note that here we assume that the identity element is indeed identity. Without this + // assumption we would have to perform a single iteration of the loop, i.e. use + // `(*op->combiner.get())(op->combineop->identity_element, op->source)[op->value_index]` + // instead of `op->source[op->value_index]`. The former may be more difficult to simplify. + return Mutate( + Select::make(op->condition, + op->source[op->value_index], + op->combiner->identity_element[op->value_index])); + } + // combiner simplification. + ret = SimplifyReduceCombiner(op); + return ret; +} + +Expr CanonicalSimplifier::operator()(const Expr& expr) { + return impl_->CanonicalSimplify(expr); +} + +void CanonicalSimplifier::Update(const Var& var, + const Expr& info, + bool override) { + impl_->Update(var, info, override); +} + + +CanonicalSimplifier::CanonicalSimplifier(Analyzer* parent) + : impl_(new Impl(parent)) { +} + +CanonicalSimplifier::~CanonicalSimplifier() { + delete impl_; +} + +} // namespace arith +} // namespace tvm diff --git a/src/arithmetic/compute_expr.h b/src/arithmetic/compute_expr.h index 218e9d218a66..ff2fb8dbd4ac 100644 --- a/src/arithmetic/compute_expr.h +++ b/src/arithmetic/compute_expr.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file compute_expr.h diff --git a/src/arithmetic/const_fold.h b/src/arithmetic/const_fold.h index 4c247c8a7b59..fbf8fe7e6f89 100644 --- a/src/arithmetic/const_fold.h +++ b/src/arithmetic/const_fold.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2019 by Contributors * \file const_fold.h @@ -7,6 +26,8 @@ #define TVM_ARITHMETIC_CONST_FOLD_H_ #include +#include +#include #include namespace tvm { diff --git a/src/arithmetic/const_int_bound.cc b/src/arithmetic/const_int_bound.cc index c83be8933b55..c591e58aa542 100644 --- a/src/arithmetic/const_int_bound.cc +++ b/src/arithmetic/const_int_bound.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2019 by Contributors * \file tvm/arithmetic/const_int_bound.cc @@ -37,6 +56,10 @@ struct ConstIntBoundAnalyzer::Entry { bool is_const(int64_t value) const { return min_value == max_value && min_value == value; } + + bool operator==(const Entry& other) const { + return min_value == other.min_value && max_value == other.max_value; + } }; class ConstIntBoundAnalyzer::Impl : @@ -55,7 +78,11 @@ class ConstIntBoundAnalyzer::Impl : const Entry& info, bool override) { if (!override) { - CHECK(!var_map_.count(var)); + auto it = var_map_.find(var); + if (it != var_map_.end()) { + CHECK(it->second == info) + << "var \'" << var << "\' already updated."; + } } var_map_[var] = info; } diff --git a/src/arithmetic/detect_linear_equation.cc b/src/arithmetic/detect_linear_equation.cc index 6f4d3cfb53bb..2fe21fef7e21 100644 --- a/src/arithmetic/detect_linear_equation.cc +++ b/src/arithmetic/detect_linear_equation.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file bound_deducer.cc @@ -127,25 +146,21 @@ Array DetectLinearEquation(const Expr& e, const Array& vars) { Expr base = e; Array coeff; - if (0 == vars.size()) { - coeff.push_back(make_const(Int(32), 1)); - } else { - for (Var v : vars) { - LinearEqEntry ret; - if (!LinearEqDetector(v).Detect(base, &ret)) { - return Array(); - } - coeff.push_back(ret.coeff); - base = std::move(ret.base); + for (Var v : vars) { + LinearEqEntry ret; + if (!LinearEqDetector(v).Detect(base, &ret)) { + return Array(); } + coeff.push_back(ret.coeff); + base = std::move(ret.base); + } - std::unordered_set vset; - for (size_t i = vars.size(); i != 1; --i) { - vset.insert(vars[i - 1].get()); - // The previous coeff contains the variable - if (ExprUseVar(coeff[i - 2], vset)) { - return Array(); - } + std::unordered_set vset; + for (size_t i = vars.size(); i > 1; --i) { + vset.insert(vars[i - 1].get()); + // The previous coeff contains the variable + if (ExprUseVar(coeff[i - 2], vset)) { + return Array(); } } coeff.push_back(base); diff --git a/src/arithmetic/domain_touched.cc b/src/arithmetic/domain_touched.cc index b4e7d13d19f6..fee6512b9f18 100644 --- a/src/arithmetic/domain_touched.cc +++ b/src/arithmetic/domain_touched.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file bound_deducer.cc diff --git a/src/arithmetic/int_op_overflow.h b/src/arithmetic/int_op_overflow.h index ef637b4b9521..87f4f059e858 100644 --- a/src/arithmetic/int_op_overflow.h +++ b/src/arithmetic/int_op_overflow.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2019 by Contributors * \file int_op_overflow.h diff --git a/src/arithmetic/int_set.cc b/src/arithmetic/int_set.cc index ed6e55904cdd..abbb7cd9744e 100644 --- a/src/arithmetic/int_set.cc +++ b/src/arithmetic/int_set.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file int_set.cc diff --git a/src/arithmetic/int_set_internal.h b/src/arithmetic/int_set_internal.h index cc2a4c307997..8b675cfbffda 100644 --- a/src/arithmetic/int_set_internal.h +++ b/src/arithmetic/int_set_internal.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file int_set_internal.h diff --git a/src/arithmetic/modular_set.cc b/src/arithmetic/modular_set.cc index 8112beef7551..5958233d6d52 100644 --- a/src/arithmetic/modular_set.cc +++ b/src/arithmetic/modular_set.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2019 by Contributors * \file modular_set.cc @@ -36,6 +55,18 @@ struct ModularSetAnalyzer::Entry { int64_t coeff{1}; int64_t base{0}; + Entry() = default; + + Entry(int64_t coeff, int64_t base) { + CHECK_GE(coeff, 0); + this->coeff = coeff; + if (coeff != 0) { + base = base % coeff; + if (base < 0) base += coeff; + } + this->base = base; + } + bool is_const() const { return coeff == 0; } @@ -53,10 +84,7 @@ class ModularSetAnalyzer::Impl : if (!override) { CHECK(!var_map_.count(var)); } - Entry e; - e.coeff = info->coeff; - e.base = info->base; - var_map_[var] = e; + var_map_[var] = Entry(info->coeff, info->base); } // Detect useful constraints and use them in the analysis scope. @@ -65,9 +93,7 @@ class ModularSetAnalyzer::Impl : PVar coeff, base; // pattern match interesting constraints if (((var % coeff) == base).Match(constraint)) { - Entry entry; - entry.coeff = coeff.Eval()->value; - entry.base = base.Eval()->value; + Entry entry(coeff.Eval()->value, base.Eval()->value); return UpdateByIntersect(var.Eval(), entry); } return nullptr; @@ -83,18 +109,12 @@ class ModularSetAnalyzer::Impl : } Entry VisitExpr_(const IntImm* op) final { - Entry ret; - ret.base = op->value; - ret.coeff = 0; - return ret; + return Entry(0, op->value); } Entry VisitExpr_(const UIntImm* op) final { if (op->value < std::numeric_limits::max()) { - Entry ret; - ret.base = static_cast(op->value); - ret.coeff = 0; - return ret; + return Entry(0, static_cast(op->value)); } else { return Everything(); } @@ -103,19 +123,15 @@ class ModularSetAnalyzer::Impl : Entry VisitExpr_(const Add* op) final { Entry a = VisitExpr(op->a); Entry b = VisitExpr(op->b); - Entry ret; - ret.coeff = ZeroAwareGCD(a.coeff, b.coeff); - ret.base = BaseSimplify(a.base + b.base, ret.coeff); - return ret; + int64_t coeff = ZeroAwareGCD(a.coeff, b.coeff); + return Entry(coeff, a.base + b.base); } Entry VisitExpr_(const Sub* op) final { Entry a = VisitExpr(op->a); Entry b = VisitExpr(op->b); - Entry ret; - ret.coeff = ZeroAwareGCD(a.coeff, b.coeff); - ret.base = BaseSimplify(a.base - b.base, ret.coeff); - return ret; + int64_t coeff = ZeroAwareGCD(a.coeff, b.coeff); + return Entry(coeff, a.base - b.base); } Entry VisitExpr_(const Mul* op) final { @@ -128,10 +144,8 @@ class ModularSetAnalyzer::Impl : int64_t pq = a.coeff * b.coeff; int64_t pm = a.coeff * b.base; int64_t qn = a.base * b.coeff; - Entry ret; - ret.coeff = ZeroAwareGCD(pq, ZeroAwareGCD(pm, qn)); - ret.base = BaseSimplify(a.base * b.base, ret.coeff); - return ret; + int64_t coeff = ZeroAwareGCD(pq, ZeroAwareGCD(pm, qn)); + return Entry(coeff, a.base * b.base); } Entry DivByConst(const Expr& lhs, @@ -140,20 +154,15 @@ class ModularSetAnalyzer::Impl : Entry a = VisitExpr(lhs); CHECK_NE(val, 0); if (a.coeff % val == 0) { - Entry ret; if (a.base == 0) { // a c x / c -> a x - ret.coeff = std::abs(a.coeff / val); - ret.base = 0; - return ret; + return Entry(std::abs(a.coeff / val), 0); } // positive division have a clear rounding mode. // Only handle case where we clearly know we need to round down. if (a.base > 0 && val > 0 && (round_down || parent_->CanProveGreaterEqual(lhs, 0))) { - ret.coeff = a.coeff / val; - ret.base = a.base / val; - return ret; + return Entry(a.coeff / val, a.base / val); } } return Everything(); @@ -251,16 +260,54 @@ class ModularSetAnalyzer::Impl : } int64_t base0 = a.base % coeff; int64_t base1 = b.base % coeff; - Entry ret; if (base0 == base1) { - ret.coeff = coeff; - ret.base = base0; - return ret; + return Entry(coeff, base0); + } else { + return Entry(ZeroAwareGCD(ZeroAwareGCD(base0, base1), coeff), base0); + } + } + /*! + * \brief Use Extended Euclidean algorithm to solve ax + by = gcd(a, b) + * \param a The first coefficient. + * \param b The second coefficient. + * \param x The solution of x. + * \param y The solution of y. + * \return The GCD of a and b. + */ + static int64_t ExtendedEuclidean(int64_t a, int64_t b, int64_t* x, int64_t* y) { + // Extended Euclidean algorithm + // if a < 0, the problem can be convert into + // |a|* (-x) + b * y = gcd(|a|, b) + // + // initial condition: + // a * 0 + b * 1 = b + // a * 1 + b * 0 = a + int64_t s = 0, old_s = 1; + int64_t r = b, old_r = a >= 0 ? a : -a; + // Iteration (r2 < r1): + // a * x1 + b * y1 = r1 + // a * x2 + b * y2 = r2 + // The above two eqs can derive the following eq (q = r1 / r2) + // a * (x1 - x2 * q) + b * (y1 - y2 * q) = r1 - r2 * q = r3 + // Because r3 < r2, the iteration can eventually terminate + while (r != 0) { + int64_t q = old_r / r; + int64_t tmp = old_r; + old_r = r; + r = tmp - q * r; + tmp = old_s; + old_s = s; + s = tmp - q * s; + } + + *x = a >= 0 ? old_s : -old_s; + if (b != 0) { + *y = (old_r - (*x) * a) / b; } else { - ret.coeff = ZeroAwareGCD(ZeroAwareGCD(base0, base1), coeff); - ret.base = 0; - return ret; + *y = 1; } + + return old_r; } /*! * \brief Create interect of two sets. @@ -268,24 +315,25 @@ class ModularSetAnalyzer::Impl : * \param b the right operand. */ static Entry Intersect(Entry a, Entry b) { - // simple rule for now: pick higher constraints. - // TODO(team-team): Use extended euclidean algorithm. - if (a.coeff == 0) return a; - if (b.coeff == 0) return b; - if (a.coeff >= b.coeff) return a; - return b; - } - /*! - * \brief Simplify base so that it is in [0, coeff) when coeff != 0. - * \param base The base value. - * \param coeff The coeff value. - * \return The simplified base. - */ - static int64_t BaseSimplify(int64_t base, int64_t coeff) { - if (coeff == 0) return base; - base = base % coeff; - if (base < 0) base += coeff; - return base; + int64_t x, y; + int64_t c1 = a.coeff, b1 = a.base, c2 = b.coeff, b2 = b.base; + // z = c1 * p + b1 + // z = c2 * q + b2 + // c1 * x + c2 * y = gcd(c1, c2) + // -> c1 * p - c2 * q = b2 - b1 + // -> p = (b2 - b1) / gcd * x + // -> q = (b2 - b1) / gcd * (-y) + // -> z = LCM(x, y) * k + (c1 * p + b1) + int64_t gcd = ExtendedEuclidean(c1, c2, &x, &y); + int64_t v = b2 - b1; + if (v % gcd == 0) { + x = v / gcd * x; + y = v / gcd * (-y); + int64_t coeff = c1 / gcd * c2; + return Entry(coeff, x * c1 + b1); + } else { + return Nothing(); + } } /*! * \brief Take GCD of a and b. @@ -311,9 +359,14 @@ class ModularSetAnalyzer::Impl : * \return Bound that represent everything dtype can represent. */ static Entry Everything() { - Entry ret; - ret.coeff = 1; ret.base = 0; - return ret; + return Entry(1, 0); + } + /*! + * \brief return an empty set + * \return Bound that represent everything dtype can represent. + */ + static Entry Nothing() { + return Entry(0, 1); } }; diff --git a/src/arithmetic/pattern_match.h b/src/arithmetic/pattern_match.h index 20c24b330cbd..39cf647c5dd2 100644 --- a/src/arithmetic/pattern_match.h +++ b/src/arithmetic/pattern_match.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2019 by Contributors * \file tvm/arithmetic/pattern_match.h diff --git a/src/arithmetic/rewrite_simplify.cc b/src/arithmetic/rewrite_simplify.cc index f031e094d84a..1ebb328925d0 100644 --- a/src/arithmetic/rewrite_simplify.cc +++ b/src/arithmetic/rewrite_simplify.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2019 by Contributors * \file rewrite_simplify.cc @@ -7,8 +26,10 @@ #include #include #include +#include #include "const_fold.h" #include "pattern_match.h" +#include "rewrite_simplify.h" namespace tvm { namespace arith { @@ -39,134 +60,55 @@ using namespace ir; return RecursiveRewrite((ResExpr).Eval()); \ } - // NOTE for developers: // // We mainly focus on index expression simplification. // Besides the RewriteSimplifier, some cases can be better // handled by CanonicalSimplifier. // -class RewriteSimplifier::Impl : public IRMutator { - public: - explicit Impl(Analyzer* parent) - : parent_(parent) {} - - void Update(const Var& var, - const Expr& info, - bool override) { - if (!override) { - CHECK(!var_map_.count(var)); + +// try to prove x equals val +RewriteSimplifier::Impl::CompareResult RewriteSimplifier::Impl:: +TryCompare(const Expr& x, int64_t val) { + Expr diff = Mutate(x); + if (const auto* ptr = diff.as()) { + if (ptr->value == val) { + return kEQ; + } else if (ptr->value > val) { + return kGT; + } else if (ptr->value < val) { + return kLT; } - var_map_[var] = info; } - - // Run simplification in post order - Expr PostOrderSimplify(Expr expr, int max_iter = 2) { - for (int i = 0; i < max_iter; ++i) { - Expr new_expr = this->Mutate(expr); - if (new_expr.same_as(expr)) return expr; - expr = new_expr; + if (val == 0) { + ModularSet dmod = parent_->modular_set(diff); + if (dmod->base != 0) { + return kNE; } - return expr; } - - Expr Mutate_(const Add* op, const Expr& self) final; - Expr Mutate_(const Sub* op, const Expr& self) final; - Expr Mutate_(const Mul* op, const Expr& self) final; - Expr Mutate_(const Div* op, const Expr& self) final; - Expr Mutate_(const Mod* op, const Expr& self) final; - Expr Mutate_(const Min* op, const Expr& self) final; - Expr Mutate_(const Max* op, const Expr& self) final; - Expr Mutate_(const EQ* op, const Expr& self) final; - Expr Mutate_(const NE* op, const Expr& self) final; - Expr Mutate_(const LT* op, const Expr& self) final; - Expr Mutate_(const LE* op, const Expr& self) final; - Expr Mutate_(const GT* op, const Expr& self) final; - Expr Mutate_(const GE* op, const Expr& self) final; - Expr Mutate_(const And* op, const Expr& self) final; - Expr Mutate_(const Or* op, const Expr& self) final; - Expr Mutate_(const Not* op, const Expr& self) final; - Expr Mutate_(const Select* op, const Expr& self) final; - Expr Mutate_(const Ramp* op, const Expr& self) final; - - private: - /*! \brief internal structure for comparison. */ - enum CompareResult { - kUnknown, - kEQ, - kGT, - kLT, - kGE, - kLE, - kNE - }; - // reference to the main analyzer - Analyzer* parent_; - // counter to record recursive rewrite depth. - int recur_depth_{0}; - // internal variable map - std::unordered_map var_map_; - // maximum number of recursion allowed during a single pass. - static const constexpr int kMaxRecurDepth = 5; - // Whether x >= val - bool CanProveGreaterEqual(const Expr& x, int64_t val) { - return parent_->CanProveGreaterEqual(x, val); + ConstIntBound dbound = parent_->const_int_bound(diff); + if (dbound->min_value > val) { + return kGT; } - // Whether x == val - bool CanProveEqual(const Expr& x, int64_t val) { - // TODO(tqchen) refer back to super-analyzer. - return TryCompare(x, val) == kEQ; + if (dbound->max_value < val) { + return kLT; } - // try to prove x equals val - CompareResult TryCompare(const Expr& x, int64_t val) { - Expr diff = Mutate(x); - if (const auto* ptr = diff.as()) { - if (ptr->value == val) { - return kEQ; - } else if (ptr->value > val) { - return kGT; - } else if (ptr->value < val) { - return kLT; - } - } - if (val == 0) { - ModularSet dmod = parent_->modular_set(diff); - if (dmod->base != 0) { - return kNE; - } - } - ConstIntBound dbound = parent_->const_int_bound(diff); - if (dbound->min_value > val) { - return kGT; - } - if (dbound->max_value < val) { - return kLT; - } - if (dbound->min_value >= val) { - return kGE; - } - if (dbound->max_value <= val) { - return kLE; - } - return kUnknown; + if (dbound->min_value >= val) { + return kGE; } - - // Recursive rewrite x - // we limit maximum depth of recursive rewrite allowed to - // avoid infinite loop - Expr RecursiveRewrite(const Expr& x) { - if (recur_depth_ >= kMaxRecurDepth) return x; - ++recur_depth_; - Expr res = Mutate(x); - --recur_depth_; - return res; + if (dbound->max_value <= val) { + return kLE; } + return kUnknown; +} - template - PConstWithTypeLike ZeroWithTypeLike(const Pattern& pattern) { - return PConstWithTypeLike(pattern.derived(), 0); +void RewriteSimplifier::Impl:: +Update(const Var& var, const Expr& info, bool override) { + if (!override) { + CHECK(!var_map_.count(var)); } -}; + var_map_[var] = info; +} Expr RewriteSimplifier::Impl:: Mutate_(const Add* op, const Expr& self) { @@ -1253,16 +1195,6 @@ Mutate_(const Or* op, const Expr& self) { return ret; } -Expr RewriteSimplifier::Impl:: -Mutate_(const Ramp* op, const Expr& self) { - Expr ret = IRMutator::Mutate_(op, self); - op = ret.as(); - if (is_zero(op->stride)) { - return Broadcast::make(op->base, op->lanes); - } - return ret; -} - Expr RewriteSimplifier::Impl:: Mutate_(const Select* op, const Expr& self) { Expr ret = IRMutator::Mutate_(op, self); @@ -1275,13 +1207,30 @@ Mutate_(const Select* op, const Expr& self) { } // Pattern var to match any expression PVar x, y; - TVM_TRY_REWRITE(select(x, y, y), y); return ret; } +Expr RewriteSimplifier::Impl:: +Mutate_(const Call* op, const Expr& self) { + Expr ret = IRMutator::Mutate_(op, self); + op = ret.as(); + if (op->is_intrinsic(Call::likely) && is_const(op->args[0])) { + return op->args[0]; + } + return ret; +} + Expr RewriteSimplifier::operator()(const Expr& expr) { - return impl_->PostOrderSimplify(expr); + // Run simplification in post order + Expr res = expr; + int max_iter = 2; + for (int i = 0; i < max_iter; ++i) { + Expr new_expr = impl_->Mutate(res); + if (new_expr.same_as(res)) return res; + res = new_expr; + } + return res; } void RewriteSimplifier::Update(const Var& var, @@ -1290,7 +1239,6 @@ void RewriteSimplifier::Update(const Var& var, impl_->Update(var, info, override); } - RewriteSimplifier::RewriteSimplifier(Analyzer* parent) : impl_(new Impl(parent)) { } diff --git a/src/arithmetic/rewrite_simplify.h b/src/arithmetic/rewrite_simplify.h new file mode 100644 index 000000000000..82c65f97f782 --- /dev/null +++ b/src/arithmetic/rewrite_simplify.h @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file rewrite_simplify.h + * \brief Rewrite-rule based simplification. + */ +#ifndef TVM_ARITHMETIC_REWRITE_SIMPLIFY_H_ +#define TVM_ARITHMETIC_REWRITE_SIMPLIFY_H_ + +#include +#include +#include +#include +#include "const_fold.h" +#include "pattern_match.h" + +namespace tvm { +namespace arith { + +using namespace ir; + +/*! + * \brief Rewrite-based simplifier. + * + * This class can be inheritated for other simplifiers. + */ +class RewriteSimplifier::Impl : public IRMutator { + public: + explicit Impl(Analyzer* parent) + : parent_(parent) {} + + void Update(const Var& var, const Expr& info, bool override); + Expr Mutate_(const Add* op, const Expr& self) override; + Expr Mutate_(const Sub* op, const Expr& self) override; + Expr Mutate_(const Mul* op, const Expr& self) override; + Expr Mutate_(const Div* op, const Expr& self) override; + Expr Mutate_(const Mod* op, const Expr& self) override; + Expr Mutate_(const Min* op, const Expr& self) override; + Expr Mutate_(const Max* op, const Expr& self) override; + Expr Mutate_(const EQ* op, const Expr& self) override; + Expr Mutate_(const NE* op, const Expr& self) override; + Expr Mutate_(const LT* op, const Expr& self) override; + Expr Mutate_(const LE* op, const Expr& self) override; + Expr Mutate_(const GT* op, const Expr& self) override; + Expr Mutate_(const GE* op, const Expr& self) override; + Expr Mutate_(const And* op, const Expr& self) override; + Expr Mutate_(const Or* op, const Expr& self) override; + Expr Mutate_(const Not* op, const Expr& self) override; + Expr Mutate_(const Select* op, const Expr& self) override; + Expr Mutate_(const Call* op, const Expr& self) override; + + protected: + /*! \brief internal structure for comparison. */ + enum CompareResult { + kUnknown, + kEQ, + kGT, + kGE, + kLT, + kLE, + kNE + }; + // reference to the main analyzer + Analyzer* parent_; + // counter to record recursive rewrite depth. + int recur_depth_{0}; + // internal variable map + std::unordered_map var_map_; + // maximum number of recursion allowed during a single pass. + static const constexpr int kMaxRecurDepth = 5; + + /*! + * \brief try to compare x against val. + * \param x The expression to be evaluated. + * \param val The constant value. + * \return comparison result. + */ + CompareResult TryCompare(const Expr& x, int64_t val); + + private: + // Whether x >= val + bool CanProveGreaterEqual(const Expr& x, int64_t val) { + return parent_->CanProveGreaterEqual(x, val); + } + // Whether x == val + bool CanProveEqual(const Expr& x, int64_t val) { + // TODO(tqchen) refer back to super-analyzer. + return TryCompare(x, val) == kEQ; + } + + // Recursive rewrite x + // we limit maximum depth of recursive rewrite allowed to + // avoid infinite loop + Expr RecursiveRewrite(const Expr& x) { + if (recur_depth_ >= kMaxRecurDepth) return x; + ++recur_depth_; + Expr res = Mutate(x); + --recur_depth_; + return res; + } + + template + PConstWithTypeLike ZeroWithTypeLike(const Pattern& pattern) { + return PConstWithTypeLike(pattern.derived(), 0); + } +}; + + +} // namespace arith +} // namespace tvm +#endif // TVM_ARITHMETIC_REWRITE_SIMPLIFY_H_ diff --git a/src/arithmetic/stmt_simplify.cc b/src/arithmetic/stmt_simplify.cc new file mode 100644 index 000000000000..c793214b92f4 --- /dev/null +++ b/src/arithmetic/stmt_simplify.cc @@ -0,0 +1,186 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file stmt_simplify.cc + * \brief Statement simplifier based on analyzer + */ +#include +#include +#include +#include +#include +#include +#include "arithmetic/Simplify.h" + +namespace tvm { +namespace arith { +// statement simplifier +using namespace ir; + +class StmtSimplifier : public IRMutator { + public: + Stmt Mutate_(const For* op, const Stmt& s) final { + Var loop_var(op->loop_var.node_); + analyzer_.Bind(loop_var, Range::make_by_min_extent(op->min, op->extent)); + return IRMutator::Mutate_(op, s); + } + + // IfThenElse + Stmt Mutate_(const IfThenElse* op, const Stmt& s) { + Expr condition = this->Mutate(op->condition); + Stmt then_case, else_case; + { + ConstraintContext ctx(&analyzer_, condition); + then_case = this->Mutate(op->then_case); + } + if (op->else_case.defined()) { + ConstraintContext ctx(&analyzer_, Mutate(Not::make(condition))); + else_case = this->Mutate(op->else_case); + } + if (is_one(condition)) return then_case; + if (is_zero(condition)) { + if (else_case.defined()) { + return else_case; + } + return Evaluate::make(0); + } + + if (condition.same_as(op->condition) && + then_case.same_as(op->then_case) && + else_case.same_as(op->else_case)) { + return s; + } else { + return IfThenElse::make(condition, then_case, else_case); + } + } + + // AttrStmt + Stmt Mutate_(const AttrStmt* op, const Stmt& s) { + if (op->attr_key == attr::thread_extent || + op->attr_key == attr::virtual_thread) { + IterVar iv(op->node.node_); + CHECK_NE(iv->thread_tag.length(), 0U); + if (!var_dom_.count(iv->var.get())) { + Range dom = Range::make_by_min_extent(0, op->value); + var_dom_[iv->var.get()] = dom; + analyzer_.Bind(iv->var, dom); + } + Stmt stmt = IRMutator::Mutate_(op, s); + return stmt; + } else { + return IRMutator::Mutate_(op, s); + } + } + + // AssertStmt + Stmt Mutate_(const AssertStmt* op, const Stmt& s) final { + Expr condition = this->Mutate(op->condition); + Expr message = this->Mutate(op->message); + ConstraintContext ctx(&analyzer_, condition); + Stmt body = this->Mutate(op->body); + + if (condition.same_as(op->condition) && + message.same_as(op->message) && + body.same_as(op->body)) { + return s; + } else { + return AssertStmt::make(condition, message, body); + } + } + + protected: + Analyzer analyzer_; + // variable domain + std::unordered_map var_dom_; +}; + + +class CanonicalStmtSimplifier : public StmtSimplifier { + public: + using StmtSimplifier::Mutate; + Expr Mutate(Expr expr) final { + return analyzer_.canonical_simplify(expr); + } + + Stmt CanonicalSimplify(Stmt stmt, Map vrange) { + for (auto kv : vrange) { + analyzer_.Bind(kv.first, kv.second); + } + return Mutate(stmt); + } +}; + +} // namespace arith + +namespace ir { + +Stmt CanonicalSimplify(Stmt stmt, Map vrange) { + return arith::CanonicalStmtSimplifier().CanonicalSimplify( + stmt, vrange); +} + +Expr CanonicalSimplify(Expr expr, Map vrange) { + arith::Analyzer analyzer; + for (auto kv : vrange) { + analyzer.Bind(kv.first, kv.second); + } + return analyzer.canonical_simplify(expr); +} + +template +T Simplify_(T a, Map vrange) { + using namespace HalideIR::Internal; + Scope rscope; + for (auto kv : vrange) { + Range r = kv.second; + rscope.push( + kv.first.get(), + Interval(r->min, + simplify(r->min + r->extent - make_const(r->min.type(), 1)))); + } + return HalideIR::Internal::simplify(a, true, rscope); +} + + +Expr Simplify(Expr a, Map vrange) { + // Simplify top level reduce. + if (const Reduce* r = a.as()) { + Array new_source; + for (auto& e : r->source) { + new_source.push_back(Simplify_(e, vrange)); + } + Expr new_condition = Simplify_(r->condition, vrange); + if (r->source.same_as(new_source) && + r->condition.same_as(new_condition)) { + return a; + } else { + return Reduce::make( + r->combiner, new_source, r->axis, new_condition, r->value_index); + } + } + return Simplify_(a, vrange); +} + +Stmt Simplify(Stmt a, Map vrange) { + return Simplify_(a, vrange); +} +} // namespace ir +} // namespace tvm diff --git a/src/autotvm/feature_visitor.cc b/src/autotvm/feature_visitor.cc index 01330e97b886..7f2057fd0602 100644 --- a/src/autotvm/feature_visitor.cc +++ b/src/autotvm/feature_visitor.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file feature_visitor.cc diff --git a/src/autotvm/feature_visitor.h b/src/autotvm/feature_visitor.h index 509a27e2638c..348182961eef 100644 --- a/src/autotvm/feature_visitor.h +++ b/src/autotvm/feature_visitor.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file feature_visitor.h diff --git a/src/autotvm/touch_extractor.cc b/src/autotvm/touch_extractor.cc index b1d5dea8fc9f..e24e757427ba 100644 --- a/src/autotvm/touch_extractor.cc +++ b/src/autotvm/touch_extractor.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file touch_extractor.cc diff --git a/src/autotvm/touch_extractor.h b/src/autotvm/touch_extractor.h index 18b7783ead1c..cad37895280f 100644 --- a/src/autotvm/touch_extractor.h +++ b/src/autotvm/touch_extractor.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file touch_extractor.h diff --git a/src/codegen/build_common.h b/src/codegen/build_common.h index fdb53d36651e..713922b1e326 100644 --- a/src/codegen/build_common.h +++ b/src/codegen/build_common.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * Common build utilities diff --git a/src/codegen/build_module.cc b/src/codegen/build_module.cc index f9190123a0a9..65542dd50810 100644 --- a/src/codegen/build_module.cc +++ b/src/codegen/build_module.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * Compile executable modules. diff --git a/src/codegen/codegen.cc b/src/codegen/codegen.cc index 12570e5881a9..ed9484b211b0 100644 --- a/src/codegen/codegen.cc +++ b/src/codegen/codegen.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file codegen.cc diff --git a/src/codegen/codegen_aocl.cc b/src/codegen/codegen_aocl.cc index d9167a7aadcd..6f899cbb0b53 100644 --- a/src/codegen/codegen_aocl.cc +++ b/src/codegen/codegen_aocl.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file codegen_aocl.cc diff --git a/src/codegen/codegen_c.cc b/src/codegen/codegen_c.cc index 9b73e4e77a2a..19f7a270b865 100644 --- a/src/codegen/codegen_c.cc +++ b/src/codegen/codegen_c.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file codegen_c.cc diff --git a/src/codegen/codegen_c.h b/src/codegen/codegen_c.h index c9af24a04a3c..a591b571f662 100644 --- a/src/codegen/codegen_c.h +++ b/src/codegen/codegen_c.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file codegen_c.h diff --git a/src/codegen/codegen_c_host.cc b/src/codegen/codegen_c_host.cc index 248354dbc339..5e33f11d5877 100644 --- a/src/codegen/codegen_c_host.cc +++ b/src/codegen/codegen_c_host.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file codegen_c_host.cc diff --git a/src/codegen/codegen_c_host.h b/src/codegen/codegen_c_host.h index eb47a7829e2c..4f20df4c85e3 100644 --- a/src/codegen/codegen_c_host.h +++ b/src/codegen/codegen_c_host.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file codegen_c_host.h diff --git a/src/codegen/codegen_cuda.cc b/src/codegen/codegen_cuda.cc index 0ab56a116eab..ef92f9ae3175 100644 --- a/src/codegen/codegen_cuda.cc +++ b/src/codegen/codegen_cuda.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file codegen_cuda.cc diff --git a/src/codegen/codegen_cuda.h b/src/codegen/codegen_cuda.h index cef2c77f9901..381784a13a57 100644 --- a/src/codegen/codegen_cuda.h +++ b/src/codegen/codegen_cuda.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file codegen_cuda.h diff --git a/src/codegen/codegen_metal.cc b/src/codegen/codegen_metal.cc index 031313190370..118904facbe1 100644 --- a/src/codegen/codegen_metal.cc +++ b/src/codegen/codegen_metal.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file codegen_metal.cc diff --git a/src/codegen/codegen_metal.h b/src/codegen/codegen_metal.h index 9779fb800ff9..5a94d8bba8f4 100644 --- a/src/codegen/codegen_metal.h +++ b/src/codegen/codegen_metal.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file codegen_metal.h diff --git a/src/codegen/codegen_opencl.cc b/src/codegen/codegen_opencl.cc index ae87bf9d9b93..96e1b9efe8dd 100644 --- a/src/codegen/codegen_opencl.cc +++ b/src/codegen/codegen_opencl.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file codegen_opencl.cc diff --git a/src/codegen/codegen_opencl.h b/src/codegen/codegen_opencl.h index 350b6c0f3402..0eff3a633ba3 100644 --- a/src/codegen/codegen_opencl.h +++ b/src/codegen/codegen_opencl.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file codegen_opencl.h diff --git a/src/codegen/codegen_opengl.cc b/src/codegen/codegen_opengl.cc index a4f63e8186ce..27d910e7211b 100644 --- a/src/codegen/codegen_opengl.cc +++ b/src/codegen/codegen_opengl.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file codegen_opengl.cc diff --git a/src/codegen/codegen_opengl.h b/src/codegen/codegen_opengl.h index d82e1cfba9e7..a938aef388cb 100644 --- a/src/codegen/codegen_opengl.h +++ b/src/codegen/codegen_opengl.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file codegen_opengl.h diff --git a/src/codegen/codegen_source_base.cc b/src/codegen/codegen_source_base.cc index 39a573ceec68..84609a9a928a 100644 --- a/src/codegen/codegen_source_base.cc +++ b/src/codegen/codegen_source_base.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file codegen_source_base.cc diff --git a/src/codegen/codegen_source_base.h b/src/codegen/codegen_source_base.h index 3fc46c35c7f7..8013208cd997 100644 --- a/src/codegen/codegen_source_base.h +++ b/src/codegen/codegen_source_base.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file codegen_source_base.h diff --git a/src/codegen/codegen_vhls.cc b/src/codegen/codegen_vhls.cc index 5776b895b4b3..460647a6e180 100644 --- a/src/codegen/codegen_vhls.cc +++ b/src/codegen/codegen_vhls.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file codegen_vhls.cc diff --git a/src/codegen/codegen_vhls.h b/src/codegen/codegen_vhls.h index c0faefc75837..3604d2b4ef7f 100644 --- a/src/codegen/codegen_vhls.h +++ b/src/codegen/codegen_vhls.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file codegen_vhls.h diff --git a/src/codegen/intrin_rule.cc b/src/codegen/intrin_rule.cc index f326fceb6ee8..5bc5c518bb5b 100644 --- a/src/codegen/intrin_rule.cc +++ b/src/codegen/intrin_rule.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file intrin_rule_default.cc diff --git a/src/codegen/intrin_rule.h b/src/codegen/intrin_rule.h index c900c9088880..79badadab01f 100644 --- a/src/codegen/intrin_rule.h +++ b/src/codegen/intrin_rule.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file intrin_rule.h diff --git a/src/codegen/intrin_rule_aocl.cc b/src/codegen/intrin_rule_aocl.cc index fc5dbe741d63..7016c33610f7 100644 --- a/src/codegen/intrin_rule_aocl.cc +++ b/src/codegen/intrin_rule_aocl.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file intrin_rule_aocl.cc diff --git a/src/codegen/intrin_rule_cuda.cc b/src/codegen/intrin_rule_cuda.cc index a6867c7f201c..22648386f150 100644 --- a/src/codegen/intrin_rule_cuda.cc +++ b/src/codegen/intrin_rule_cuda.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file intrin_rule_cuda.cc diff --git a/src/codegen/intrin_rule_metal.cc b/src/codegen/intrin_rule_metal.cc index 2e65d5537dd2..2f6474d4d36c 100644 --- a/src/codegen/intrin_rule_metal.cc +++ b/src/codegen/intrin_rule_metal.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file intrin_rule_metal.cc diff --git a/src/codegen/intrin_rule_opencl.cc b/src/codegen/intrin_rule_opencl.cc index e4cf11bf6e64..c8ceeca2107c 100644 --- a/src/codegen/intrin_rule_opencl.cc +++ b/src/codegen/intrin_rule_opencl.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file intrin_rule_opencl.cc diff --git a/src/codegen/intrin_rule_opengl.cc b/src/codegen/intrin_rule_opengl.cc index c9aa21c1a883..7d0e7c44c8e6 100644 --- a/src/codegen/intrin_rule_opengl.cc +++ b/src/codegen/intrin_rule_opengl.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file intrin_rule_opencl.cc diff --git a/src/codegen/intrin_rule_vhls.cc b/src/codegen/intrin_rule_vhls.cc index 996c45707364..1ec90636829e 100644 --- a/src/codegen/intrin_rule_vhls.cc +++ b/src/codegen/intrin_rule_vhls.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file intrin_rule_vhls.cc diff --git a/src/codegen/llvm/codegen_amdgpu.cc b/src/codegen/llvm/codegen_amdgpu.cc index 205d99f1ab65..22c432cc9e4b 100644 --- a/src/codegen/llvm/codegen_amdgpu.cc +++ b/src/codegen/llvm/codegen_amdgpu.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file codegen_amdgpu.cc diff --git a/src/codegen/llvm/codegen_arm.cc b/src/codegen/llvm/codegen_arm.cc index 9f19fa1f47f0..3518ef168234 100644 --- a/src/codegen/llvm/codegen_arm.cc +++ b/src/codegen/llvm/codegen_arm.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file codegen_arm.cc diff --git a/src/codegen/llvm/codegen_cpu.cc b/src/codegen/llvm/codegen_cpu.cc index 2f4c796b0b94..bd0e947e01ab 100644 --- a/src/codegen/llvm/codegen_cpu.cc +++ b/src/codegen/llvm/codegen_cpu.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file codegen_cpu.cc diff --git a/src/codegen/llvm/codegen_cpu.h b/src/codegen/llvm/codegen_cpu.h index 61f2c3feb02f..7f18f4a5071b 100644 --- a/src/codegen/llvm/codegen_cpu.h +++ b/src/codegen/llvm/codegen_cpu.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file codegen_llvm_cpu.h diff --git a/src/codegen/llvm/codegen_llvm.cc b/src/codegen/llvm/codegen_llvm.cc index 6b69f97a66fe..7946f906125f 100644 --- a/src/codegen/llvm/codegen_llvm.cc +++ b/src/codegen/llvm/codegen_llvm.cc @@ -1,12 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file codegen_llvm.cc */ #ifdef TVM_LLVM_VERSION // Part of the code are adapted from Halide's CodeGen_LLVM - #include #include + +#include + #include "codegen_llvm.h" #include "codegen_cpu.h" #include "../../pass/ir_util.h" @@ -410,12 +431,16 @@ llvm::Value* CodeGenLLVM::CreateBroadcast(llvm::Value* value, int lanes) { llvm::Value* CodeGenLLVM::CreateVecSlice(llvm::Value* vec, int begin, int extent) { int num_elems = static_cast(vec->getType()->getVectorNumElements()); if (extent == num_elems && begin == 0) return vec; - CHECK_LE(begin + extent, num_elems); - std::vector indices; + std::vector indices; + indices.reserve(extent); for (int i = 0; i < extent; ++i) { - indices.push_back(begin + i); + if (begin + i >= 0 && begin + i < num_elems) { + indices.push_back(llvm::ConstantInt::get(t_int32_, begin + i)); + } else { + indices.push_back(llvm::UndefValue::get(t_int32_)); + } } - return builder_->CreateShuffleVector(vec, vec, indices); + return builder_->CreateShuffleVector(vec, vec, llvm::ConstantVector::get(indices)); } llvm::Value* CodeGenLLVM::CreateVecFlip(llvm::Value* vec) { @@ -446,24 +471,31 @@ llvm::Value* CodeGenLLVM::CreateVecConcat(std::vector vecs) { v->getType()->getVectorNumElements()); } while (vecs.size() > 1) { - for (size_t i = 0; i < vecs.size(); i+=2) { - if (i + 1 >= vecs.size()) { - vecs[i / 2] = vecs[i]; continue; - } + std::vector new_vecs; + for (size_t i = 0; i < vecs.size() - 1; i += 2) { llvm::Value* lhs = vecs[i]; llvm::Value* rhs = vecs[i + 1]; - int lanes = static_cast(std::max( - lhs->getType()->getVectorNumElements(), - rhs->getType()->getVectorNumElements())); - lhs = CreateVecPad(lhs, lanes); - rhs = CreateVecPad(lhs, lanes); + const size_t lhs_lanes = lhs->getType()->getVectorNumElements(); + const size_t rhs_lanes = rhs->getType()->getVectorNumElements(); + if (lhs_lanes < rhs_lanes) { + lhs = CreateVecPad(lhs, rhs_lanes); + } else if (rhs_lanes < lhs_lanes) { + rhs = CreateVecPad(rhs, lhs_lanes); + } + const size_t shared_lanes = std::max(lhs_lanes, rhs_lanes); std::vector mask; - for (int i = 0; i < lanes * 2; ++i) { + for (size_t i = 0; i < lhs_lanes; ++i) { mask.push_back(i); } - vecs[i / 2] = builder_->CreateShuffleVector(lhs, rhs, mask); + for (size_t i = 0; i < rhs_lanes; ++i) { + mask.push_back(shared_lanes + i); + } + new_vecs.push_back(builder_->CreateShuffleVector(lhs, rhs, mask)); + } + if (vecs.size() % 2 != 0) { + new_vecs.push_back(vecs.back()); } - vecs.resize((vecs.size() + 1) / 2); + vecs.swap(new_vecs); } return CreateVecSlice(vecs[0], 0, total_lanes); } diff --git a/src/codegen/llvm/codegen_llvm.h b/src/codegen/llvm/codegen_llvm.h index 33362bc58157..0006b4cabbaf 100644 --- a/src/codegen/llvm/codegen_llvm.h +++ b/src/codegen/llvm/codegen_llvm.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file codegen_llvm.h diff --git a/src/codegen/llvm/codegen_nvptx.cc b/src/codegen/llvm/codegen_nvptx.cc index 0a9361c57de7..b1b541d4ab74 100644 --- a/src/codegen/llvm/codegen_nvptx.cc +++ b/src/codegen/llvm/codegen_nvptx.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file codegen_nvptx.cc diff --git a/src/codegen/llvm/codegen_x86_64.cc b/src/codegen/llvm/codegen_x86_64.cc new file mode 100644 index 000000000000..3a07f4f93d8a --- /dev/null +++ b/src/codegen/llvm/codegen_x86_64.cc @@ -0,0 +1,150 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file codegen_x86_64.cc + * \brief X86-64 specific code generator + */ +#ifdef TVM_LLVM_VERSION +#include "codegen_cpu.h" + +#include "llvm/MC/MCSubtargetInfo.h" + +namespace tvm { +namespace codegen { + +namespace { +bool TargetHasFeature(const llvm::TargetMachine& tm, const std::string& feature) { + // MCSubTargetInfo::checkFeatures was added in LLVM 6.0 +#if TVM_LLVM_VERSION >= 60 + const auto* MCInfo = tm.getMCSubtargetInfo(); + return MCInfo->checkFeatures(std::string("+") + feature); +#else + return false; + // TODO(tulloch) - enable this block, need to figure out how to reimplement + // this given visibility constraints, similar to + // https://github.com/rust-lang/rust/pull/31709 + + // Copied from + // https://github.com/llvm-mirror/llvm/blob/5136df4/lib/MC/MCSubtargetInfo.cpp#L78-L88. + + // auto checkFeatures = [&](const std::string FS) { + // llvm::SubtargetFeatures T(FS); + // llvm::FeatureBitset Set, All; + // for (std::string F : T.getFeatures()) { + // llvm::SubtargetFeatures::ApplyFeatureFlag(Set, F, MCInfo->ProcFeatures); + // if (F[0] == '-') { + // F[0] = '+'; + // } + // llvm::SubtargetFeatures::ApplyFeatureFlag(All, F, MCInfo->ProcFeatures); + // } + // return (MCInfo->getFeatureBits() & All) == Set; + // }; + // return checkFeatures(MCInfo, std::string("+") + feature); +#endif +} +} // namespace + +class CodeGenX86_64 final : public CodeGenCPU { + public: + llvm::Value* VisitExpr_(const Cast* op) override; + + private: + llvm::Value* CallVectorIntrin(llvm::Intrinsic::ID id, size_t intrin_lanes, llvm::Type* result_ty, + const std::vector& args); +}; + +llvm::Value* CodeGenX86_64::VisitExpr_(const Cast* op) { + // LLVM does not automatically generate the correct instruction sequences for + // half -> float conversion (i.e. using AVX2/AVX-512 vectorized variants of + // vcvtph2ps), so we explicitly generate them ourselves. + const auto from = op->value.type(); + const auto to = op->type; + if (from.is_float() && to.is_float() && from.bits() == 16 && to.bits() == 32) { + CHECK_EQ(from.lanes(), to.lanes()); + CHECK_NOTNULL(target_machine_); + + const auto has_f16c = TargetHasFeature(*target_machine_, "f16c"); + const auto has_avx512 = TargetHasFeature(*target_machine_, "avx512f"); + + if (from.lanes() >= 16 && has_avx512) { + return CallVectorIntrin( + ::llvm::Intrinsic::x86_avx512_mask_vcvtph2ps_512, 16, LLVMType(Float(32, from.lanes())), + { + MakeValue(ir::Call::make(Int(16, from.lanes()), ir::Call::reinterpret, {op->value}, + ir::Call::PureIntrinsic)), + MakeValue(ir::Broadcast::make(ir::FloatImm::make(Float(32), 0), from.lanes())), + /*mask=*/MakeValue(ir::IntImm::make(Int(16), -1)), + /*rounding-mode=*/MakeValue(ir::IntImm::make(Int(32), 4)), + }); + } + + if (from.lanes() >= 8 && has_f16c) { + return CallVectorIntrin( + ::llvm::Intrinsic::x86_vcvtph2ps_256, 8, LLVMType(Float(32, from.lanes())), + {MakeValue(ir::Call::make(Int(16, from.lanes()), ir::Call::reinterpret, {op->value}, + ir::Call::PureIntrinsic))}); + } + } + + return CodeGenCPU::VisitExpr_(op); +} + +llvm::Value* CodeGenX86_64::CallVectorIntrin(llvm::Intrinsic::ID id, size_t intrin_lanes, + llvm::Type* result_ty, + + const std::vector& args) { + llvm::Function* f = llvm::Intrinsic::getDeclaration(module_.get(), id, {}); + if (intrin_lanes == result_ty->getVectorNumElements()) { + return builder_->CreateCall(f, args); + } + + // Otherwise, we split the vector into intrin_lanes sized elements (widening where necessary), + // compute each result, and then concatenate the vectors (slicing the result if necessary). + CHECK_LT(intrin_lanes, result_ty->getVectorNumElements()); + std::vector split_results; + for (size_t i = 0; + i < static_cast(result_ty->getVectorNumElements()); + i += intrin_lanes) { + std::vector split_args; + for (const auto& v : args) { + if (v->getType()->isVectorTy()) { + CHECK_EQ(v->getType()->getVectorNumElements(), result_ty->getVectorNumElements()); + split_args.push_back(CreateVecSlice(v, i, intrin_lanes)); + } else { + split_args.push_back(v); + } + } + split_results.push_back(CallVectorIntrin( + id, intrin_lanes, llvm::VectorType::get(result_ty->getScalarType(), intrin_lanes), + split_args)); + } + return CreateVecSlice(CreateVecConcat(split_results), 0, result_ty->getVectorNumElements()); +} + +TVM_REGISTER_GLOBAL("tvm.codegen.llvm.target_x86-64") +.set_body([](const TVMArgs& targs, TVMRetValue* rv) { + CodeGenLLVM* cg = new CodeGenX86_64(); + *rv = static_cast(cg); + }); + +} // namespace codegen +} // namespace tvm +#endif // TVM_LLVM_VERSION diff --git a/src/codegen/llvm/intrin_rule_llvm.cc b/src/codegen/llvm/intrin_rule_llvm.cc index 307f0a3bc412..4afe0e5fd7cd 100644 --- a/src/codegen/llvm/intrin_rule_llvm.cc +++ b/src/codegen/llvm/intrin_rule_llvm.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file intrin_rule_llvm.cc diff --git a/src/codegen/llvm/intrin_rule_llvm.h b/src/codegen/llvm/intrin_rule_llvm.h index 30e7674c3297..69fe09a20eeb 100644 --- a/src/codegen/llvm/intrin_rule_llvm.h +++ b/src/codegen/llvm/intrin_rule_llvm.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file intrin_rule_llvm.h diff --git a/src/codegen/llvm/intrin_rule_nvptx.cc b/src/codegen/llvm/intrin_rule_nvptx.cc index d0b9f3693192..34ed07586311 100644 --- a/src/codegen/llvm/intrin_rule_nvptx.cc +++ b/src/codegen/llvm/intrin_rule_nvptx.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file intrin_rule_nvptx.cc diff --git a/src/codegen/llvm/intrin_rule_rocm.cc b/src/codegen/llvm/intrin_rule_rocm.cc index 092eb77f8f59..45f3c13ef971 100644 --- a/src/codegen/llvm/intrin_rule_rocm.cc +++ b/src/codegen/llvm/intrin_rule_rocm.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file intrin_rule_rocm.cc diff --git a/src/codegen/llvm/llvm_common.cc b/src/codegen/llvm/llvm_common.cc index 0b486fda92ed..f763d7147dd6 100644 --- a/src/codegen/llvm/llvm_common.cc +++ b/src/codegen/llvm/llvm_common.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file llvm_common.cc diff --git a/src/codegen/llvm/llvm_common.h b/src/codegen/llvm/llvm_common.h index ef324ddb4361..3d0f6c9da364 100644 --- a/src/codegen/llvm/llvm_common.h +++ b/src/codegen/llvm/llvm_common.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file llvm_common.h diff --git a/src/codegen/llvm/llvm_module.cc b/src/codegen/llvm/llvm_module.cc index 25de224e44cd..10b891ca2bda 100644 --- a/src/codegen/llvm/llvm_module.cc +++ b/src/codegen/llvm/llvm_module.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file llvm_module.cc diff --git a/src/codegen/opt/build_aocl_off.cc b/src/codegen/opt/build_aocl_off.cc index 535036016247..fc0e8e1f1b7c 100644 --- a/src/codegen/opt/build_aocl_off.cc +++ b/src/codegen/opt/build_aocl_off.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * Optional module when build aocl is switched to off diff --git a/src/codegen/opt/build_cuda_off.cc b/src/codegen/opt/build_cuda_off.cc index 4e2bfd03d71a..e3d690a76a71 100644 --- a/src/codegen/opt/build_cuda_off.cc +++ b/src/codegen/opt/build_cuda_off.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * Optional module when build cuda is switched to off diff --git a/src/codegen/opt/build_cuda_on.cc b/src/codegen/opt/build_cuda_on.cc index 2e5766f53b76..581c33086bee 100644 --- a/src/codegen/opt/build_cuda_on.cc +++ b/src/codegen/opt/build_cuda_on.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * Build cuda modules from source. diff --git a/src/codegen/opt/build_metal_off.cc b/src/codegen/opt/build_metal_off.cc index dfa2cc28cc8b..c1c065ea3778 100644 --- a/src/codegen/opt/build_metal_off.cc +++ b/src/codegen/opt/build_metal_off.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * Optional module when build metal is switched to off diff --git a/src/codegen/opt/build_opencl_off.cc b/src/codegen/opt/build_opencl_off.cc index adadb84e9b1c..e686cfb5850d 100644 --- a/src/codegen/opt/build_opencl_off.cc +++ b/src/codegen/opt/build_opencl_off.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * Optional module when build opencl is switched to off diff --git a/src/codegen/opt/build_opengl_off.cc b/src/codegen/opt/build_opengl_off.cc index 3f01dc98f0a5..2aa767b1e249 100644 --- a/src/codegen/opt/build_opengl_off.cc +++ b/src/codegen/opt/build_opengl_off.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * Optional module when build opencl is switched to off diff --git a/src/codegen/opt/build_rocm_off.cc b/src/codegen/opt/build_rocm_off.cc index 009fd13668d1..c84825b82f43 100644 --- a/src/codegen/opt/build_rocm_off.cc +++ b/src/codegen/opt/build_rocm_off.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * Optional module when build rocm is switched to off diff --git a/src/codegen/opt/build_sdaccel_off.cc b/src/codegen/opt/build_sdaccel_off.cc index f5e57cb10f9e..c65018c57ea4 100644 --- a/src/codegen/opt/build_sdaccel_off.cc +++ b/src/codegen/opt/build_sdaccel_off.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * Optional module when build opencl is switched to off diff --git a/src/codegen/source_module.cc b/src/codegen/source_module.cc index 56facea1567f..70047a6050db 100644 --- a/src/codegen/source_module.cc +++ b/src/codegen/source_module.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file source_module.cc diff --git a/src/codegen/spirv/build_vulkan.cc b/src/codegen/spirv/build_vulkan.cc index f5ec5628545a..2b1ef660fbdc 100644 --- a/src/codegen/spirv/build_vulkan.cc +++ b/src/codegen/spirv/build_vulkan.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file build_vulkan.cc diff --git a/src/codegen/spirv/codegen_spirv.cc b/src/codegen/spirv/codegen_spirv.cc index 8b1cabd9e386..e6fc0088dc81 100644 --- a/src/codegen/spirv/codegen_spirv.cc +++ b/src/codegen/spirv/codegen_spirv.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file codegen_spirv.cc diff --git a/src/codegen/spirv/codegen_spirv.h b/src/codegen/spirv/codegen_spirv.h index a8f648daf7d1..dcc2ee230a22 100644 --- a/src/codegen/spirv/codegen_spirv.h +++ b/src/codegen/spirv/codegen_spirv.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file ir_builder.h diff --git a/src/codegen/spirv/intrin_rule_spirv.cc b/src/codegen/spirv/intrin_rule_spirv.cc index a7fa46bda60a..a046cc4f458c 100644 --- a/src/codegen/spirv/intrin_rule_spirv.cc +++ b/src/codegen/spirv/intrin_rule_spirv.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file intrin_rule_spirv.cc diff --git a/src/codegen/spirv/ir_builder.cc b/src/codegen/spirv/ir_builder.cc index fdf4b9852430..72b68807a7d9 100644 --- a/src/codegen/spirv/ir_builder.cc +++ b/src/codegen/spirv/ir_builder.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file ir_builder.cc diff --git a/src/codegen/spirv/ir_builder.h b/src/codegen/spirv/ir_builder.h index 0e0a27fdabdf..ed2e5fadd51b 100644 --- a/src/codegen/spirv/ir_builder.h +++ b/src/codegen/spirv/ir_builder.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file ir_builder.h diff --git a/src/codegen/stackvm/codegen_stackvm.cc b/src/codegen/stackvm/codegen_stackvm.cc index 2ec5bb202857..8c4c258095d3 100644 --- a/src/codegen/stackvm/codegen_stackvm.cc +++ b/src/codegen/stackvm/codegen_stackvm.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file codegen_stackvm.cc diff --git a/src/codegen/stackvm/codegen_stackvm.h b/src/codegen/stackvm/codegen_stackvm.h index 23bd61dcb4c2..73af8ad630a5 100644 --- a/src/codegen/stackvm/codegen_stackvm.h +++ b/src/codegen/stackvm/codegen_stackvm.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file codegen_stack_vm.h diff --git a/src/codegen/verilog/codegen_verilog.cc b/src/codegen/verilog/codegen_verilog.cc deleted file mode 100644 index 2cef1387159b..000000000000 --- a/src/codegen/verilog/codegen_verilog.cc +++ /dev/null @@ -1,725 +0,0 @@ -/*! - * Copyright (c) 2017 by Contributors - * \file codegen_verilog.cc - */ -#include -#include -#include -#include -#include -#include "codegen_verilog.h" -#include "../../arithmetic/compute_expr.h" - -namespace tvm { -namespace codegen { -namespace verilog { - -using namespace ir; - -void CodeGenVerilog::Init() { - stream << "`include \"tvm_marcos.v\"\n\n"; -} - -void CodeGenVerilog::InitFuncState(LoweredFunc f) { - CodeGenSourceBase::ClearFuncState(); - cmap_.clear(); - tvm_vpi_modules_.clear(); - done_sigs_.clear(); -} - -void CodeGenVerilog::AddFunction(LoweredFunc f) { - // clear previous generated state. - this->InitFuncState(f); - // skip the first underscore, so SSA variable starts from _1 - GetUniqueName("_"); - GetUniqueName("rst"); - GetUniqueName("clk"); - GetUniqueName("done"); - GetUniqueName("enable"); - GetUniqueName("all_input_valid"); - // print out function body. - int func_scope = this->BeginScope(); - - // Stich things up. - stream << "module " << f->name << "(\n"; - PrintDecl("clk", kInput, Bool(1), ""); - stream << ",\n"; - PrintDecl("rst", kInput, Bool(1), ""); - VerilogFuncEntry entry; - for (size_t i = 0; i < f->args.size(); ++i) { - stream << ",\n"; - Var v = f->args[i]; - std::string vid = AllocVarID(v.get()); - entry.arg_ids.push_back(vid); - entry.arg_types.push_back(v.type()); - PrintDecl(vid, kInput, v.type(), ""); - } - stream << ",\n"; - PrintDecl("done", kOutput, Bool(1), ""); - stream << "\n);\n"; - this->CodeGen(MakePipeline(f)); - PrintAssignAnd("done", done_sigs_); - this->EndScope(func_scope); - this->PrintIndent(); - stream << "endmodule\n"; - entry.vpi_modules = std::move(tvm_vpi_modules_); - functions_[f->name] = entry; -} - -std::string VerilogCodeGenModule::AppendSimMain( - const std::string& func_name) const { - // Add main function for simulator hook - const VerilogFuncEntry& entry = fmap.at(func_name); - std::ostringstream stream; - stream << code; - stream << "\n" - << "module main();\n" - << " `TVM_DEFINE_TEST_SIGNAL(clk, rst)\n"; - // print out function body. - std::vector sargs; - for (size_t i = 0; i < entry.arg_types.size(); ++i) { - Type t = entry.arg_types[i]; - std::ostringstream sarg; - sarg << "tvm_arg" << i; - std::string vid = sarg.str(); - stream << " reg"; - if (t.bits() > 1) { - stream << "[" << t.bits() - 1 << ":0]"; - } - stream << " " << vid << ";\n"; - sargs.push_back(vid); - } - stream << " wire done;\n"; - stream << "\n " << func_name << " dut(\n" - << " .clk(clk),\n" - << " .rst(rst),\n"; - - for (size_t i = 0; i < entry.arg_ids.size(); ++i) { - stream << " ." << entry.arg_ids[i] << '(' - << sargs[i] << "),\n"; - } - stream << " .done(done)\n" - << " );\n"; - - - stream << " initial begin\n" - << " $tvm_session(clk"; - for (const std::string& mvpi : entry.vpi_modules) { - stream << ", dut." << mvpi; - } - stream << ");\n" - << " end\n"; - stream << "endmodule\n"; - return stream.str(); -} - -VerilogCodeGenModule CodeGenVerilog::Finish() { - VerilogCodeGenModule m; - m.code = stream.str(); - m.fmap = std::move(functions_); - return m; -} - -void CodeGenVerilog::PrintDecl( - const std::string& vid, VerilogVarType vtype, Type dtype, - const char* suffix, bool indent) { - if (indent) PrintIndent(); - switch (vtype) { - case kReg: stream << "reg "; break; - case kWire: stream << "wire "; break; - case kInput: stream << "input "; break; - case kOutput: stream << "output "; break; - default: LOG(FATAL) << "unsupported vtype=" << vtype; - } - int bits = dtype.bits(); - // bits for handle type. - if (dtype.is_handle()) { - bits = 64; - } - if (bits > 1) { - stream << "[" << bits - 1 << ":0] "; - } - stream << vid << suffix; -} - -void CodeGenVerilog::PrintSSAAssign( - const std::string& target, const std::string& src, Type t) { - // add target to list of declaration. - PrintDecl(target, kWire, t, ";\n", false); - PrintAssign(target, src); -} - -void CodeGenVerilog::PrintAssign( - const std::string& target, const std::string& src) { - PrintIndent(); - stream << "assign " << target << " = "; - if (src.length() > 3 && - src[0] == '(' && src[src.length() - 1] == ')') { - stream << src.substr(1, src.length() - 2); - } else { - stream << src; - } - stream << ";\n"; -} - -void CodeGenVerilog::PrintAssignAnd( - const std::string& target, const std::vector& conds) { - if (conds.size() != 0) { - std::ostringstream os_valid; - for (size_t i = 0; i < conds.size(); ++i) { - if (i != 0) os_valid << " && "; - os_valid << conds[i]; - } - PrintAssign(target, os_valid.str()); - } else { - PrintAssign(target, "1"); - } -} - -void CodeGenVerilog::PrintLine(const std::string& line) { - PrintIndent(); - stream << line << '\n'; -} - -VerilogValue CodeGenVerilog::MakeBinary(Type t, - VerilogValue a, - VerilogValue b, - const char *opstr) { - CHECK_EQ(t.lanes(), 1) - << "Do not yet support vectorized op"; - CHECK(t.is_int() || t.is_uint()) - << "Only support integer operations"; - std::ostringstream os; - os << a.vid << ' ' << opstr << ' '<< b.vid; - return GetSSAValue(os.str(), t); -} - -template -inline VerilogValue IntConst(const T* op, CodeGenVerilog* p) { - if (op->type.bits() <= 32 && op->type.lanes() == 1) { - std::ostringstream temp; - temp << op->value; - p->MarkConst(temp.str()); - return VerilogValue(temp.str(), kConst, op->type); - } else { - LOG(FATAL) << "Do not support integer constant type " << op->type; - return VerilogValue(); - } -} - -VerilogValue CodeGenVerilog::VisitExpr_(const IntImm *op) { - return IntConst(op, this); -} -VerilogValue CodeGenVerilog::VisitExpr_(const UIntImm *op) { - return IntConst(op, this); -} -VerilogValue CodeGenVerilog::VisitExpr_(const FloatImm *op) { - LOG(FATAL) << "Do not support float constant in Verilog"; - return VerilogValue(); -} -VerilogValue CodeGenVerilog::VisitExpr_(const StringImm *op) { - LOG(FATAL) << "Do not support string constant in Verilog"; - return VerilogValue(); -} - -VerilogValue CodeGenVerilog::VisitExpr_(const Cast *op) { - LOG(FATAL) << "Type cast not supported"; - return VerilogValue(); -} -VerilogValue CodeGenVerilog::VisitExpr_(const Variable *op) { - return VerilogValue(GetVarID(op), kReg, op->type); -} - -VerilogValue CodeGenVerilog::VisitExpr_(const Add *op) { - return MakeBinary(op->type, MakeValue(op->a), MakeValue(op->b), "+"); -} -VerilogValue CodeGenVerilog::VisitExpr_(const Sub *op) { - return MakeBinary(op->type, MakeValue(op->a), MakeValue(op->b), "-"); -} -VerilogValue CodeGenVerilog::VisitExpr_(const Mul *op) { - return MakeBinary(op->type, MakeValue(op->a), MakeValue(op->b), "*"); -} -VerilogValue CodeGenVerilog::VisitExpr_(const Div *op) { - int shift; - if (is_const_power_of_two_integer(op->b, &shift) && - (op->type.is_int() || op->type.is_uint())) { - return MakeValue(op->a >> make_const(op->b.type(), shift)); - } else { - LOG(FATAL) << "do not support synthesis division"; - } - return VerilogValue(); -} -VerilogValue CodeGenVerilog::VisitExpr_(const Mod *op) { - LOG(FATAL) << "do not support synthesis Mod"; - return VerilogValue(); -} -VerilogValue CodeGenVerilog::VisitExpr_(const Min *op) { - LOG(FATAL) << "not supported"; - return VerilogValue(); -} -VerilogValue CodeGenVerilog::VisitExpr_(const Max *op) { - LOG(FATAL) << "not supported"; - return VerilogValue(); -} -VerilogValue CodeGenVerilog::VisitExpr_(const EQ *op) { - return MakeBinary(op->type, MakeValue(op->a), MakeValue(op->b), "=="); -} -VerilogValue CodeGenVerilog::VisitExpr_(const NE *op) { - return MakeBinary(op->type, MakeValue(op->a), MakeValue(op->b), "!="); -} -VerilogValue CodeGenVerilog::VisitExpr_(const LT *op) { - return MakeBinary(op->type, MakeValue(op->a), MakeValue(op->b), "<"); -} -VerilogValue CodeGenVerilog::VisitExpr_(const LE *op) { - return MakeBinary(op->type, MakeValue(op->a), MakeValue(op->b), "<="); -} -VerilogValue CodeGenVerilog::VisitExpr_(const GT *op) { - return MakeBinary(op->type, MakeValue(op->a), MakeValue(op->b), ">"); -} -VerilogValue CodeGenVerilog::VisitExpr_(const GE *op) { - return MakeBinary(op->type, MakeValue(op->a), MakeValue(op->b), ">="); -} -VerilogValue CodeGenVerilog::VisitExpr_(const And *op) { - return MakeBinary(op->type, MakeValue(op->a), MakeValue(op->b), "&&"); -} -VerilogValue CodeGenVerilog::VisitExpr_(const Or *op) { - return MakeBinary(op->type, MakeValue(op->a), MakeValue(op->b), "||"); -} -VerilogValue CodeGenVerilog::VisitExpr_(const Not *op) { - VerilogValue value = MakeValue(op->a); - std::ostringstream os; - os << "(!" << value.vid << ")"; - return GetSSAValue(os.str(), op->type); -} - -VerilogValue CodeGenVerilog::VisitExpr_(const Call *op) { - if (op->is_intrinsic(Call::bitwise_and)) { - return MakeBinary( - op->type, MakeValue(op->args[0]), MakeValue(op->args[1]), "&"); - } else if (op->is_intrinsic(Call::bitwise_xor)) { - return MakeBinary( - op->type, MakeValue(op->args[0]), MakeValue(op->args[1]), "^"); - } else if (op->is_intrinsic(Call::bitwise_or)) { - return MakeBinary( - op->type, MakeValue(op->args[0]), MakeValue(op->args[1]), "|"); - } else if (op->is_intrinsic(Call::bitwise_not)) { - VerilogValue value = MakeValue(op->args[0]); - std::ostringstream os; - os << "(~" << value.vid << ")"; - return GetSSAValue(os.str(), op->type); - } else if (op->is_intrinsic(Call::shift_left)) { - return MakeBinary( - op->type, MakeValue(op->args[0]), MakeValue(op->args[1]), "<<"); - } else if (op->is_intrinsic(Call::shift_right)) { - return MakeBinary( - op->type, MakeValue(op->args[0]), MakeValue(op->args[1]), ">>"); - } else { - LOG(FATAL) << "Cannot generate call type " << op->name; - return VerilogValue(); - } -} - -VerilogValue CodeGenVerilog::VisitExpr_(const Let* op) { - VerilogValue value = MakeValue(op->value); - CHECK(!var_idmap_.count(op->var.get())); - var_idmap_[op->var.get()] = value.vid; - return value; -} - -VerilogValue CodeGenVerilog::VisitExpr_(const Ramp* op) { - LOG(FATAL) << "Ramp: not supported "; - return VerilogValue(); -} - -VerilogValue CodeGenVerilog::VisitExpr_(const Broadcast* op) { - LOG(FATAL) << "Broadcast: not supported "; - return VerilogValue(); -} - -VerilogValue CodeGenVerilog::VisitExpr_(const Select* op) { - LOG(FATAL) << "Select: not supported "; - return VerilogValue(); -} - -void CodeGenVerilog::CodeGen(const Pipeline& pipeline) { - // setup channel map. - for (auto kv : pipeline->channels) { - ChannelEntry e; e.block = kv.second; - cmap_[kv.first.get()] = e; - } - for (ComputeBlock stage : pipeline->stages) { - const Store* store = stage->body.as(); - CHECK(store); - const Load* load = store->value.as(); - if (load) { - MakeLoadToFIFO(stage, store, load); - } else { - MakeStore(stage, store); - } - } - for (const auto& kv : cmap_) { - MakeChannelUnit(kv.second); - } -} - -CodeGenVerilog::SignalEntry -CodeGenVerilog::MakeLoop(const Array& loop) { - SignalEntry sig; - // do not use init signal for now. - std::string init = "0"; - std::string lp_ready = GetUniqueName("lp_tmp_sig"); - sig.ready = GetUniqueName("loop_ready"); - sig.valid = GetUniqueName("loop_valid"); - PrintLine("// loop logic"); - PrintDecl(lp_ready, kWire, Bool(1)); - PrintDecl(sig.ready, kWire, Bool(1)); - - std::string end_loop = lp_ready; - for (size_t i = loop.size(); i != 0; --i) { - const For* for_op = loop[i - 1].as(); - int bits = for_op->loop_var.type().bits(); - VerilogValue min = MakeValue(for_op->min); - VerilogValue extent = MakeValue(for_op->extent); - CHECK(min.vtype == kConst && extent.vtype == kConst) - << "Only support constant loop domain"; - - std::string vid = AllocVarID(for_op->loop_var.get()); - std::string finish = GetUniqueName(vid + "_finish"); - this->PrintIndent(); - stream <<"`NONSTOP_LOOP(" << vid << ", " << bits << ", " << init - << ", " << end_loop << ", " << finish - << ", " << min.vid << ", " << extent.vid << ")\n"; - end_loop = finish; - } - if (loop.size() != 0) { - std::string local_ready = GetUniqueName("lp_tmp_sig"); - this->PrintIndent(); - stream <<"`WRAP_LOOP_ONCE(" << init << ", " << sig.valid - << ", " << sig.ready << ", " << end_loop << ", " << local_ready << ")\n"; - PrintAssign(lp_ready, local_ready); - } - return sig; -} - -void CodeGenVerilog::MakeStageInputs( - const ComputeBlock& block, - const std::string& enable, - std::string* out_all_input_valid) { - std::vector sigs; - sigs.push_back(MakeLoop(block->loop)); - // Input data path. - PrintLine("// stage inputs"); - for (auto kv : block->inputs) { - const Var& var = kv.first; - const StageInput& arg = kv.second; - std::string vid = AllocVarID(var.get()); - this->PrintDecl(vid, kWire, var.type()); - if (arg->input_type == kGlobalConst || - arg->input_type == kLoopVar) { - PrintAssign(vid, GetVarID(arg->var.get())); - } else if (arg->input_type == kChannel) { - std::string vid_valid = GetUniqueName(vid + "_valid"); - std::string vid_ready = GetUniqueName(vid + "_ready"); - this->PrintDecl(vid_valid, kWire, Bool(1)); - this->PrintDecl(vid_ready, kWire, Bool(1)); - ChannelEntry* e = GetChannelInfo(arg->var.get()); - // TODO(tqchen, thierry) add one cache here. - e->AssignPort("read_data", vid, var.type()); - e->AssignPort("read_valid", vid_valid, Bool(1)); - e->AssignPort("read_ready", vid_ready, Bool(1)); - e->AssignPort("read_addr", "0", Int(1)); - sigs.push_back(SignalEntry{vid_valid, vid_ready}); - } else { - LOG(FATAL) << "Unknown input type"; - } - } - - PrintLine("// stage input stall"); - std::string all_input_valid = GetUniqueName("all_input_valid"); - this->PrintDecl(all_input_valid, kWire, Bool(1)); - // forward all valid - std::vector valid_conds; - for (const SignalEntry& e : sigs) { - if (e.valid.length() != 0) { - valid_conds.push_back(e.valid); - } - } - PrintAssignAnd(all_input_valid, valid_conds); - // input ready signal - for (size_t i = 0; i < sigs.size(); ++i) { - if (sigs[i].ready.length() == 0) continue; - std::vector conds = {enable}; - for (size_t j = 0; j < sigs.size(); ++j) { - if (j != i && sigs[j].valid.length() != 0) { - conds.push_back(sigs[j].valid); - } - } - PrintAssignAnd(sigs[i].ready, conds); - } - *out_all_input_valid = all_input_valid; -} - -void CodeGenVerilog::MakeDelay(const std::string& dst, - const std::string& src, - Type dtype, - int delay, - const std::string& enable) { - PrintIndent(); - stream << "`DELAY(" << dst << ", " << src << ", " - << dtype.bits() << ", " << delay << ", " << enable << ")\n"; -} - -void CodeGenVerilog::MakeStore(const ComputeBlock& block, - const Store* store) { - std::string all_input_valid; - std::string enable = GetUniqueName("enable"); - this->PrintDecl(enable, kWire, Bool(1)); - MakeStageInputs(block, enable, &all_input_valid); - // Data path - PrintLine("// data path"); - VerilogValue value = MakeValue(store->value); - VerilogValue index = MakeValue(store->index); - PrintLine("// control and retiming"); - ChannelEntry* write_entry = GetChannelInfo(store->buffer_var.get()); - // TODO(tqchen, thierry) add delay model from expression.a - int delay = 2; - std::string ch_name = write_entry->block->channel->handle_var->name_hint; - std::string write_addr = GetUniqueName(ch_name + ".write_addr"); - std::string write_ready = GetUniqueName(ch_name + ".write_ready"); - std::string write_valid = GetUniqueName(ch_name + ".write_valid"); - std::string write_data = GetUniqueName(ch_name + ".write_data"); - PrintDecl(write_addr, kWire, store->index.type()); - PrintDecl(write_ready, kWire, Bool(1)); - PrintDecl(write_valid, kWire, Bool(1)); - PrintDecl(write_data, kWire, store->value.type()); - - MakeDelay(write_addr, index.vid, store->index.type(), delay, enable); - MakeDelay(write_data, value.vid, store->value.type(), delay, enable); - MakeDelay(write_valid, all_input_valid, Bool(1), delay, enable); - PrintAssign(enable, "!" + write_valid + " || " + write_ready); - write_entry->AssignPort("write_addr", write_addr, store->index.type()); - write_entry->AssignPort("write_ready", write_ready, Bool(1)); - write_entry->AssignPort("write_valid", write_valid, Bool(1)); - write_entry->AssignPort("write_data", write_data, store->value.type()); - // The triggers - for (size_t i = 0; i < block->triggers.size(); ++i) { - SignalTrigger trigger = block->triggers[i]; - CHECK(trigger->predicate.type() == Bool(1)); - ChannelEntry* trigger_ch = GetChannelInfo(trigger->channel_var.get()); - std::string port = trigger_ch->SignalPortName(trigger->signal_index); - VerilogValue v = MakeValue(trigger->predicate); - // Assign constant trigger. - if (v.vtype == kConst) { - trigger_ch->AssignPort(port, v.vid, Bool(1)); - } else { - // non-constant trigger - CHECK_EQ(trigger_ch, write_entry) - << "Can only triggger conditional event at write channel"; - std::string v_trigger = GetUniqueName(ch_name + "." + port); - MakeDelay(v_trigger, v.vid, Bool(1), delay, enable); - write_entry->AssignPort(port, v_trigger, Bool(1)); - } - } - stream << "\n"; -} - -void CodeGenVerilog::MakeLoadToFIFO(const ComputeBlock& block, - const Store* store, - const Load* load) { - ChannelEntry* write_entry = GetChannelInfo(store->buffer_var.get()); - ChannelEntry* load_entry = GetChannelInfo(load->buffer_var.get()); - std::string all_input_valid; - std::string enable = GetUniqueName("enable"); - this->PrintDecl(enable, kWire, Bool(1)); - MakeStageInputs(block, enable, &all_input_valid); - // data path - PrintLine("// data path"); - VerilogValue index = MakeValue(load->index); - // control and retiming - PrintLine("// control and retiming"); - // TODO(tqchen, thierry) add delay model from expression - int delay = 1; - std::string read_ch_name = load_entry->block->channel->handle_var->name_hint; - std::string write_ch_name = write_entry->block->channel->handle_var->name_hint; - std::string read_addr = GetUniqueName(read_ch_name + ".read_addr"); - std::string read_data = GetUniqueName(read_ch_name + ".read_data"); - std::string read_valid = GetUniqueName(read_ch_name + ".read_valid"); - std::string index_valid = GetUniqueName(read_ch_name + ".index_valid"); - std::string write_ready = GetUniqueName(write_ch_name + ".write_ready"); - std::string data_valid = GetUniqueName(read_ch_name + ".data_valid"); - std::string valid_delay = GetUniqueName(read_ch_name + ".valid_delay"); - PrintDecl(read_addr, kWire, load->index.type()); - PrintDecl(read_data, kWire, load->type); - PrintDecl(read_valid, kWire, Bool(1)); - PrintDecl(index_valid, kWire, Bool(1)); - PrintDecl(data_valid, kWire, Bool(1)); - MakeDelay(read_addr, index.vid, load->index.type(), delay, enable); - MakeDelay(index_valid, all_input_valid, Bool(1), delay, enable); - PrintAssignAnd(data_valid, {read_valid, index_valid}); - // The read ports. - load_entry->AssignPort("read_addr", read_addr, load->index.type()); - load_entry->AssignPort("read_data", read_data, load->type); - load_entry->AssignPort("read_valid", read_valid, Bool(1)); - // The write ports. - write_entry->AssignPort("write_ready", write_ready, Bool(1)); - write_entry->AssignPort("write_data", read_data, load->type); - write_entry->AssignPort("write_valid", valid_delay, Bool(1)); - write_entry->AssignPort("write_addr", "0", Int(1)); - // The not stall condition. - PrintAssignAnd(enable, {write_ready, read_valid}); - // The ready signal - PrintIndent(); - stream << "`BUFFER_READ_VALID_DELAY(" << valid_delay << ", " << data_valid - << ", " << write_ready << ")\n"; - // The triggers - for (size_t i = 0; i < block->triggers.size(); ++i) { - SignalTrigger trigger = block->triggers[i]; - CHECK(trigger->predicate.type() == Bool(1)); - ChannelEntry* trigger_ch = GetChannelInfo(trigger->channel_var.get()); - std::string port = trigger_ch->SignalPortName(trigger->signal_index); - VerilogValue v = MakeValue(trigger->predicate); - // Assign constant trigger. - if (v.vtype == kConst) { - trigger_ch->AssignPort(port, v.vid, Bool(1)); - } else { - // non-constant trigger - CHECK_EQ(trigger_ch, load_entry) - << "Can only triggger conditional event at load channel"; - std::string v_trigger = GetUniqueName(read_ch_name + "." + port); - MakeDelay(v_trigger, v.vid, Bool(1), delay, enable); - load_entry->AssignPort(port, v_trigger, Bool(1)); - } - } - stream << "\n"; -} - -void CodeGenVerilog::MakeChannelUnit(const ChannelEntry& ch) { - if (ch.block->read_window == 0) { - // This is a memory map - MakeChannelMemMap(ch); - } else if (ch.block->read_window == 1 && - ch.block->write_window == 1) { - MakeChannelFIFO(ch); - } else { - // general Buffer - MakeChannelBuffer(ch); - } -} - -void CodeGenVerilog::MakeChannelMemMap(const ChannelEntry& ch) { - Var ch_var = ch.block->channel->handle_var; - std::string dut = GetUniqueName(ch_var->name_hint + ".mmap"); - std::string mmap_addr = GetVarID(ch_var.get()); - - tvm_vpi_modules_.push_back(dut); - if (ch.ports.count("read_addr")) { - CHECK(!ch.ports.count("write_addr")) - << "Cannot read/write to same RAM"; - const PortEntry& read_addr = ch.GetPort("read_addr"); - const PortEntry& read_data = ch.GetPort("read_data"); - const PortEntry& read_valid = ch.GetPort("read_valid"); - stream << " // channel setup for " << ch_var << "\n" - << " tvm_vpi_read_mmap # (\n" - << " .DATA_WIDTH(" << read_data.dtype.bits() << "),\n" - << " .ADDR_WIDTH(" << read_addr.dtype.bits() << "),\n" - << " .BASE_ADDR_WIDTH(" << ch_var.type().bits() << ")\n" - << " ) " << dut << " (\n" - << " .clk(clk),\n" - << " .rst(rst),\n" - << " .addr(" << read_addr.value << "),\n" - << " .data_out(" << read_data.value << "),\n" - << " .mmap_addr(" << mmap_addr << ")\n" - << " );\n"; - PrintAssign(read_valid.value, "1"); - } else if (ch.ports.count("write_addr")) { - const PortEntry& write_addr = ch.GetPort("write_addr"); - const PortEntry& write_data = ch.GetPort("write_data"); - const PortEntry& write_valid = ch.GetPort("write_valid"); - const PortEntry& write_ready = ch.GetPort("write_ready"); - stream << " // channel setup for " << ch_var << "\n" - << " tvm_vpi_write_mmap # (\n" - << " .DATA_WIDTH(" << write_data.dtype.bits() << "),\n" - << " .ADDR_WIDTH(" << write_addr.dtype.bits() << "),\n" - << " .BASE_ADDR_WIDTH(" << ch_var.type().bits() << ")\n" - << " ) " << dut << " (\n" - << " .clk(clk),\n" - << " .rst(rst),\n" - << " .addr(" << write_addr.value << "),\n" - << " .data_in(" << write_data.value << "),\n" - << " .en(" << write_valid.value << "),\n" - << " .mmap_addr(" << mmap_addr << ")\n" - << " );\n"; - PrintAssign(write_ready.value, "1"); - // additional control signals - for (size_t i = 0; i < ch.block->ctrl_signals.size(); ++i) { - ControlSignal sig = ch.block->ctrl_signals[i]; - CHECK_EQ(sig->ctrl_type, kComputeFinish); - std::string port = ch.SignalPortName(i); - done_sigs_.push_back(ch.GetPort(port).value); - } - } -} - -void CodeGenVerilog::MakeChannelFIFO(const ChannelEntry& ch) { - Var ch_var = ch.block->channel->handle_var; - std::string dut = GetUniqueName(ch_var->name_hint + ".fifo_reg"); - - const PortEntry& write_data = ch.GetPort("write_data"); - const PortEntry& write_valid = ch.GetPort("write_valid"); - const PortEntry& write_ready = ch.GetPort("write_ready"); - - const PortEntry& read_data = ch.GetPort("read_data"); - const PortEntry& read_valid = ch.GetPort("read_valid"); - const PortEntry& read_ready = ch.GetPort("read_ready"); - - CHECK_EQ(write_data.dtype, read_data.dtype); - - stream << " // channel setup for " << ch_var << "\n" - << " `CACHE_REG(" << write_data.dtype.bits() - << ", " << write_data.value - << ", " << write_valid.value - << ", " << write_ready.value - << ", " << read_data.value - << ", " << read_valid.value - << ", " << read_ready.value - << ")\n"; -} - -void CodeGenVerilog::MakeChannelBuffer(const ChannelEntry& ch) { - LOG(FATAL) << "not implemeneted"; -} - -CodeGenVerilog::ChannelEntry* -CodeGenVerilog::GetChannelInfo(const Variable* var) { - auto it = cmap_.find(var); - CHECK(it != cmap_.end()) - << "cannot find channel for var " << var->name_hint; - return &(it->second); -} - -void CodeGenVerilog::ChannelEntry::AssignPort( - std::string port, std::string value, Type dtype) { - CHECK(!ports.count(port)) - << "port " << port - << " of channel " << block->channel << " has already been connected"; - ports[port] = PortEntry{value, dtype}; -} - -const CodeGenVerilog::PortEntry& -CodeGenVerilog::ChannelEntry::GetPort(const std::string& port) const { - auto it = ports.find(port); - CHECK(it != ports.end()) - << "port " << port - << " of channel " << block->channel << " has not been connected"; - return it->second; -} - -std::string CodeGenVerilog::ChannelEntry::SignalPortName(int index) const { - CHECK_LT(static_cast(index), block->ctrl_signals.size()); - std::ostringstream os; - os << "ctrl_port" << index; - return os.str(); -} -} // namespace verilog -} // namespace codegen -} // namespace tvm diff --git a/src/codegen/verilog/codegen_verilog.h b/src/codegen/verilog/codegen_verilog.h deleted file mode 100644 index a38640ac3799..000000000000 --- a/src/codegen/verilog/codegen_verilog.h +++ /dev/null @@ -1,223 +0,0 @@ -/*! - * Copyright (c) 2017 by Contributors - * \file codegen_verilog.h - * \brief Generate verilog code. - */ -#ifndef TVM_CODEGEN_VERILOG_CODEGEN_VERILOG_H_ -#define TVM_CODEGEN_VERILOG_CODEGEN_VERILOG_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "verilog_ir.h" -#include "../codegen_source_base.h" - -namespace tvm { -namespace codegen { -namespace verilog { -using namespace ir; - -/* \brief The variable type in register.*/ -enum VerilogVarType { - kWire, - kInput, - kOutput, - kReg, - kConst -}; - -/*! \brief The verilog value */ -struct VerilogValue { - /*! \brief The variable id */ - std::string vid; - /*! \brief The variable type */ - VerilogVarType vtype{kReg}; - /*! \brief The data type it encodes */ - Type dtype; - VerilogValue() {} - VerilogValue(std::string vid, VerilogVarType vtype, Type dtype) - : vid(vid), vtype(vtype), dtype(dtype) {} -}; - -/*! \brief Information of each procedure function generated */ -struct VerilogFuncEntry { - /*! \brief The original functions */ - std::vector arg_types; - /*! \brief The real argument ids of the function */ - std::vector arg_ids; - /*! \brief The VPI Modules in the function */ - std::vector vpi_modules; -}; - -/*! - * \brief The code module of generated verilog code. - */ -class VerilogCodeGenModule { - public: - /*! \brief the code of each modoules */ - std::string code; - /*! \brief map of functions */ - std::unordered_map fmap; - /*! - * \brief Generate a code that append simulator function to call func_name. - * \param func_name The function to be called. - * \return The generated code. - */ - std::string AppendSimMain(const std::string& func_name) const; -}; - -/*! - * \brief Verilog generator - */ -class CodeGenVerilog : - public ExprFunctor, - public CodeGenSourceBase { - public: - /*! - * \brief Initialize the code generator. - * \param output_ssa Whether output SSA. - */ - void Init(); - /*! - * \brief Add the function to the generated module. - * \param f The function to be compiled. - */ - void AddFunction(LoweredFunc f); - /*! - * \brief Finalize the compilation and return the code. - * \return The code. - */ - VerilogCodeGenModule Finish(); - /*! - * \brief Transform expression to verilog value. - * \param n The expression to be printed. - */ - VerilogValue MakeValue(const Expr& n) { - return VisitExpr(n); - } - // The following parts are overloadable print operations. - // expression - VerilogValue VisitExpr_(const Variable* op) final; - VerilogValue VisitExpr_(const Let* op) final; - VerilogValue VisitExpr_(const Call* op) final; - VerilogValue VisitExpr_(const Add* op) final; - VerilogValue VisitExpr_(const Sub* op) final; - VerilogValue VisitExpr_(const Mul* op) final; - VerilogValue VisitExpr_(const Div* op) final; - VerilogValue VisitExpr_(const Mod* op) final; - VerilogValue VisitExpr_(const Min* op) final; - VerilogValue VisitExpr_(const Max* op) final; - VerilogValue VisitExpr_(const EQ* op) final; - VerilogValue VisitExpr_(const NE* op) final; - VerilogValue VisitExpr_(const LT* op) final; - VerilogValue VisitExpr_(const LE* op) final; - VerilogValue VisitExpr_(const GT* op) final; - VerilogValue VisitExpr_(const GE* op) final; - VerilogValue VisitExpr_(const And* op) final; - VerilogValue VisitExpr_(const Or* op) final; - VerilogValue VisitExpr_(const Cast* op) final; - VerilogValue VisitExpr_(const Not* op) final; - VerilogValue VisitExpr_(const Select* op) final; - VerilogValue VisitExpr_(const Ramp* op) final; - VerilogValue VisitExpr_(const Broadcast* op) final; - VerilogValue VisitExpr_(const IntImm* op) final; - VerilogValue VisitExpr_(const UIntImm* op) final; - VerilogValue VisitExpr_(const FloatImm* op) final; - VerilogValue VisitExpr_(const StringImm* op) final; - - protected: - void InitFuncState(LoweredFunc f); - void PrintDecl(const std::string& vid, VerilogVarType vtype, Type dtype, - const char* suffix = ";\n", bool indent = true); - void PrintAssign( - const std::string& target, const std::string& src); - void PrintAssignAnd( - const std::string& target, const std::vector& conds); - void PrintLine(const std::string& line); - void PrintSSAAssign( - const std::string& target, const std::string& src, Type t) final; - // make binary op - VerilogValue MakeBinary(Type t, VerilogValue a, VerilogValue b, const char* opstr); - - private: - // Hand shake signal name. - // These name can be empty. - // Indicate that the signal is always true - // or do not need to take these signals. - struct SignalEntry { - std::string valid; - std::string ready; - }; - // Information about port - struct PortEntry { - // The port value - std::string value; - // The data type - Type dtype; - }; - // Channel setup - struct ChannelEntry { - // The channel block - ChannelBlock block; - // The port map, on how port is assigned. - std::unordered_map ports; - // Assign port to be valueo - void AssignPort(std::string port, std::string value, Type dtype); - // Assign port to be valueo - const PortEntry& GetPort(const std::string& port) const; - // Signal port name - std::string SignalPortName(int index) const; - }; - - // Get wire ssa value from s - VerilogValue GetSSAValue(std::string s, Type dtype) { - VerilogValue ret; - ret.vid = SSAGetID(s, dtype); - ret.vtype = kWire; - ret.dtype = dtype; - return ret; - } - void CodeGen(const Pipeline& pipeine); - // codegen the delays - void MakeDelay(const std::string& dst, - const std::string& src, - Type dtype, - int delay, - const std::string& not_stall); - // codegen the loop macros - SignalEntry MakeLoop(const Array& loop); - // codegen the loop macros - void MakeStageInputs(const ComputeBlock& block, - const std::string& not_stall, - std::string* out_all_input_valid); - // codegen compute block - void MakeStore(const ComputeBlock& block, const Store* store); - // Codegen of load statement into FIFO - void MakeLoadToFIFO(const ComputeBlock& block, - const Store* store, - const Load* load); - // Make channel unit. - void MakeChannelUnit(const ChannelEntry& ch); - void MakeChannelFIFO(const ChannelEntry& ch); - void MakeChannelBuffer(const ChannelEntry& ch); - void MakeChannelMemMap(const ChannelEntry& ch); - // Get channel information - ChannelEntry* GetChannelInfo(const Variable* var); - // channel setup map. - std::unordered_map cmap_; - // list of vpi modules to be hooked. - std::vector tvm_vpi_modules_; - // The signals for done. - std::vector done_sigs_; - // The verilog function. - std::unordered_map functions_; -}; -} // namespace verilog -} // namespace codegen -} // namespace tvm -#endif // TVM_CODEGEN_VERILOG_CODEGEN_VERILOG_H_ diff --git a/src/codegen/verilog/verilog_ir.cc b/src/codegen/verilog/verilog_ir.cc deleted file mode 100644 index e3be4c8c8b59..000000000000 --- a/src/codegen/verilog/verilog_ir.cc +++ /dev/null @@ -1,287 +0,0 @@ -/*! - * Copyright (c) 2017 by Contributors - * \file verilog_ir.cc - */ -#include -#include -#include -#include -#include "verilog_ir.h" -#include "../../arithmetic/compute_expr.h" - -namespace tvm { -namespace codegen { -namespace verilog { - -using namespace ir; - -ControlSignal ControlSignalNode::make( - ControlSignalType type, int advance_size) { - auto n = make_node(); - n->ctrl_type = type; - n->advance_size = advance_size; - return ControlSignal(n); -} - -StageInput StageInputNode::make(Var var, StageInputType input_type) { - NodePtr n = make_node(); - n->var = var; - n->input_type = input_type; - return StageInput(n); -} - -// Replace stage inputs by placeholder, update the input map. -class StageInputReplacer : public IRMutator { - public: - explicit StageInputReplacer( - const std::unordered_map& var_info) - : var_info_(var_info) {} - - Expr Mutate_(const Variable* op, const Expr& e) final { - if (replace_.count(op)) { - return replace_.at(op); - } - auto it = var_info_.find(op); - if (it == var_info_.end()) return e; - Var new_var(it->second->var->name_hint + ".sync", op->type); - inputs_.Set(new_var, it->second); - replace_[op] = new_var; - return std::move(new_var); - } - Expr Mutate_(const Load* op, const Expr& e) final { - CHECK(is_zero(op->index)) - << "Load should be in its own stage."; - if (replace_.count(op->buffer_var.get())) { - return replace_.at(op->buffer_var.get()); - } - auto it = var_info_.find(op->buffer_var.get()); - CHECK(it != var_info_.end()) - << "Load from unknown channel"; - Var data(it->second->var->name_hint + ".load.sync", op->type); - inputs_.Set(data, it->second); - replace_[op->buffer_var.get()] = data; - return std::move(data); - } - // inputs that get replaced. - Map inputs_; - // replacement map - std::unordered_map replace_; - // Variable replacement plan. - const std::unordered_map& var_info_; -}; - -/*! \brief Extract module block */ -class PipelineExtractor: public IRVisitor { - public: - Pipeline Extract(LoweredFunc f) { - // Initialize the memory map channels - // TODO(tqchen) move the logic to explicit specification. - for (auto arg : f->args) { - if (arg.type().is_handle()) { - arg_handle_[arg.get()] = arg; - } - } - pipeline_ = make_node(); - this->Visit(f->body); - // setup channels - for (const auto &kv : cmap_) { - pipeline_->channels.Set( - kv.second.node->channel->handle_var, - ChannelBlock(kv.second.node)); - } - pipeline_->args = f->args; - return Pipeline(pipeline_); - } - - void Visit_(const AttrStmt* op) final { - if (op->attr_key == attr::pipeline_stage_scope) { - CHECK(!in_pipeline_stage_); - in_pipeline_stage_ = true; - trigger_.emplace_back(std::make_pair(loop_.size(), op)); - IRVisitor::Visit_(op); - trigger_.pop_back(); - in_pipeline_stage_ = false; - } else if (op->attr_key == attr::channel_read_advance || - op->attr_key == attr::channel_write_advance) { - trigger_.emplace_back(std::make_pair(loop_.size(), op)); - IRVisitor::Visit_(op); - trigger_.pop_back(); - } else if (op->attr_key == attr::channel_read_scope || - op->attr_key == attr::channel_write_scope) { - Channel ch(op->node.node_); - ChannelEntry& cb = cmap_[ch->handle_var.get()]; - if (cb.node != nullptr) { - CHECK(cb.node->channel.same_as(ch)); - } else { - cb.node = make_node(); - cb.node->channel = ch; - } - if (op->attr_key == attr::channel_read_scope) { - CHECK_EQ(cb.read_ref_count, 0) - << "One channel can only be read from one consumer"; - ++cb.read_ref_count; - CHECK(arith::GetConstInt(op->value, &(cb.node->read_window))) - << "Only supprt constant read window"; - } else { - CHECK_EQ(cb.write_ref_count, 0) - << "One channel can only be write by one producer"; - ++cb.write_ref_count; - CHECK(arith::GetConstInt(op->value, &(cb.node->write_window))) - << "Only supprt constant write window"; - } - var_info_[ch->handle_var.get()] = - StageInputNode::make(ch->handle_var, kChannel); - IRVisitor::Visit_(op); - var_info_.erase(ch->handle_var.get()); - } else { - IRVisitor::Visit_(op); - } - } - void Visit_(const Block* op) final { - CHECK(!in_pipeline_stage_) - << "Do not support serial execution inside pipeline"; - IRVisitor::Visit_(op); - } - void Visit_(const IfThenElse* op) final { - LOG(FATAL) << "Not implemeneted"; - } - void Visit_(const For* op) final { - if (in_pipeline_stage_) { - loop_.push_back( - For::make(op->loop_var, op->min, op->extent, - op->for_type, op->device_api, Evaluate::make(0))); - var_info_[op->loop_var.get()] = - StageInputNode::make(Var(op->loop_var.node_), kLoopVar); - IRVisitor::Visit_(op); - var_info_.erase(op->loop_var.get()); - loop_.pop_back(); - } else { - IRVisitor::Visit_(op); - } - } - void Visit_(const Store* op) final { - // Check the access pattern - Channel arg_write = - CheckArgHandleAccess(op->buffer_var.get(), op->value.type(), false); - this->Visit(op->value); - // The replace logic - StageInputReplacer repl(var_info_); - // Setup the compute block. - NodePtr compute = - make_node(); - compute->loop = Array(loop_); - // setup the advance triggers - for (const auto& e : trigger_) { - const AttrStmt* attr = e.second; - Channel ch; - if (attr->attr_key == attr::pipeline_stage_scope) { - ch = arg_write; - if (!ch.defined()) continue; - } else { - ch = Channel(attr->node.node_); - } - NodePtr trigger - = make_node(); - trigger->channel_var = ch->handle_var; - // predicate for the trigger - Expr predicate = const_true(); - for (size_t i = e.first; i < loop_.size(); ++i) { - const For* loop = loop_[i].as(); - predicate = predicate && - (loop->loop_var == (loop->extent - 1)); - } - trigger->predicate = ir::Simplify(predicate); - // Add the signal back to the channels. - ChannelEntry& cb = cmap_.at(ch->handle_var.get()); - trigger->signal_index = static_cast(cb.node->ctrl_signals.size()); - // Grab the advance constant size. - int trigger_size = 0; - if (attr->attr_key == attr::pipeline_stage_scope) { - cb.node->ctrl_signals.push_back( - ControlSignalNode::make(kComputeFinish, 0)); - } else if (attr->attr_key == attr::channel_read_advance) { - CHECK(arith::GetConstInt(attr->value, &trigger_size)) - << "Only support constant advance size"; - cb.node->ctrl_signals.push_back( - ControlSignalNode::make(kReadAdvance, trigger_size)); - } else { - CHECK(arith::GetConstInt(attr->value, &trigger_size)) - << "Only support constant advance size"; - cb.node->ctrl_signals.push_back( - ControlSignalNode::make(kWriteAdvance, trigger_size)); - } - compute->triggers.push_back(SignalTrigger(trigger)); - } - - // Check if we are writing to FIFO. - const Load* load = op->value.as(); - if (is_zero(op->index) && load) { - compute->body = Store::make( - op->buffer_var, - Load::make(load->type, load->buffer_var, - repl.Mutate(load->index), op->predicate), - op->index, op->predicate); - } else { - compute->body = Store::make( - op->buffer_var, repl.Mutate(op->value), - repl.Mutate(op->index), op->predicate); - } - compute->inputs = repl.inputs_; - pipeline_->stages.push_back(ComputeBlock(compute)); - } - void Visit_(const LetStmt* op) final { - LOG(FATAL) << "cannot pass through let"; - } - void Visit_(const Evaluate* op) final { - LOG(FATAL) << "Not implemeneted"; - } - void Visit_(const Allocate* op) final { - CHECK(!in_pipeline_stage_); - } - void Visit_(const AssertStmt* op) final { - LOG(FATAL) << "Not implemeneted"; - } - void Visit_(const Load* op) final { - CheckArgHandleAccess(op->buffer_var.get(), op->type, true); - } - Channel CheckArgHandleAccess(const Variable* var, Type dtype, bool read_access) { - if (!arg_handle_.count(var)) return Channel(); - CHECK(!cmap_.count(var)) - << "Multiple access to the same handle"; - ChannelEntry& cb = cmap_[var]; - cb.node = make_node(); - cb.node->channel = ChannelNode::make(arg_handle_.at(var), dtype); - return cb.node->channel; - } - - private: - // The channel information. - struct ChannelEntry { - NodePtr node; - int read_ref_count{0}; - int write_ref_count{0}; - }; - // Whether we are inside the pipeline stage. - bool in_pipeline_stage_{false}; - // The current loop nest - std::vector loop_; - // Advance signal trigger - std::vector > trigger_; - // Read write scope - std::vector channel_scope_; - // The loop index. - std::unordered_map var_info_; - // The channel entry; - std::unordered_map cmap_; - // The argument handle map - std::unordered_map arg_handle_; - // The result block. - NodePtr pipeline_; -}; - -Pipeline MakePipeline(LoweredFunc f) { - return PipelineExtractor().Extract(f); -} -} // namespace verilog -} // namespace codegen -} // namespace tvm diff --git a/src/codegen/verilog/verilog_ir.h b/src/codegen/verilog/verilog_ir.h deleted file mode 100644 index 47057005ea2a..000000000000 --- a/src/codegen/verilog/verilog_ir.h +++ /dev/null @@ -1,188 +0,0 @@ -/*! - * Copyright (c) 2017 by Contributors - * \file verilog_ir.h - * \brief A lowered IR that resembles verilog blocks, - * This is data structure before final codegen. - */ -#ifndef TVM_CODEGEN_VERILOG_VERILOG_IR_H_ -#define TVM_CODEGEN_VERILOG_VERILOG_IR_H_ - -#include -#include -#include -#include -#include -#include -#include - -namespace tvm { -namespace codegen { -namespace verilog { - -/*! \brief The data argument type */ -enum StageInputType : int { - /*! \brief Data channel input. */ - kChannel, - /*! \brief Loop variable generated by compute block. */ - kLoopVar, - /*! \brief Global constant. */ - kGlobalConst -}; - -/*! \brief The data argument type */ -enum ControlSignalType : int { - // Read advance signal - kReadAdvance, - // Write advance signal - kWriteAdvance, - // Pipeline stage finish signal - kComputeFinish -}; - -class ControlSignal; -class StageInput; -class SignalTrigger; - -/*! \brief The control signal of a channel */ -struct ControlSignalNode : public Node { - /*! \brief The control signal type */ - ControlSignalType ctrl_type; - /*! \brief Advance size of the signal */ - int advance_size{0}; - // visit all attributes - void VisitAttrs(AttrVisitor* v) final { - v->Visit("ctrl_type", &ctrl_type); - v->Visit("advance_size", &advance_size); - } - static ControlSignal make(ControlSignalType ctrl_type, int advance_size); - static constexpr const char* _type_key = "VerilogControlSignal"; - TVM_DECLARE_NODE_TYPE_INFO(ControlSignalNode, Node); -}; - -TVM_DEFINE_NODE_REF(ControlSignal, ControlSignalNode); - -/*! \brief Information about channel. */ -struct ChannelBlockNode : public Node { - /*! \brief The channel we are refer to */ - Channel channel; - /*! \brief Read window */ - int read_window{0}; - /*! \brief Write window */ - int write_window{0}; - /*! \brief Control signals in the channel */ - Array ctrl_signals; - // visit all attributes - void VisitAttrs(AttrVisitor* v) final { - v->Visit("channel", &channel); - v->Visit("read_window", &read_window); - v->Visit("write_window", &write_window); - v->Visit("ctrl_signals", &ctrl_signals); - } - static constexpr const char* _type_key = "VerilogChannelBlock"; - TVM_DECLARE_NODE_TYPE_INFO(ChannelBlockNode, Node); -}; - -TVM_DEFINE_NODE_REF(ChannelBlock, ChannelBlockNode); - -/*! - * \brief Input to the compute block. - * These represents the data values that need to be shared; - */ -struct StageInputNode : public Node { - /*! - * \brief The corresponding var of the input - * For loop and global const it is the var. - * For channel this corresponds to the channel handle. - */ - Var var; - /*! \brief The type of the input. */ - StageInputType input_type; - // visit all attributes - void VisitAttrs(AttrVisitor* v) final { - v->Visit("var", &var); - v->Visit("input_type", &input_type); - } - // constructor - static StageInput make(Var var, StageInputType input_type); - static constexpr const char* _type_key = "VerilogStageInput"; - TVM_DECLARE_NODE_TYPE_INFO(StageInputNode, Node); -}; - -TVM_DEFINE_NODE_REF(StageInput, StageInputNode); - -/*! \brief The trigger signal for certain channel */ -struct SignalTriggerNode : public Node { - /*! \brief The channel handle variable */ - Var channel_var; - /*! \brief Boolean predicate to trigger the signal */ - Expr predicate; - /*! \brief siginal index of the channel */ - int signal_index; - // visit all attributes - void VisitAttrs(AttrVisitor* v) final { - v->Visit("channel_var", &channel_var); - v->Visit("predicate", &predicate); - v->Visit("signal_index", &signal_index); - } - // constructor - static constexpr const char* _type_key = "VerilogSignalTrigger"; - TVM_DECLARE_NODE_TYPE_INFO(SignalTriggerNode, Node); -}; - -TVM_DEFINE_NODE_REF(SignalTrigger, SignalTriggerNode); - -/*! \brief compute block for verilog */ -struct ComputeBlockNode : public Node { - /*! \brief The body of the block. */ - Stmt body; - /*! \brief The loop nest around the body, each is a For with no_op as body */ - Array loop; - /*! \brief The channel advance trigger */ - Array triggers; - /*! \brief The input variables that need to be synced. */ - Map inputs; - // visit all attributes - void VisitAttrs(AttrVisitor* v) final { - v->Visit("body", &body); - v->Visit("loop", &loop); - v->Visit("triggers", &triggers); - v->Visit("inputs", &inputs); - } - - static constexpr const char* _type_key = "VerilogComputeBlock"; - TVM_DECLARE_NODE_TYPE_INFO(ComputeBlockNode, Node); -}; - -TVM_DEFINE_NODE_REF(ComputeBlock, ComputeBlockNode); - -/*! \brief Codeblock for verilog module. */ -struct PipelineNode : public Node { - /*! \brief arguments to the module */ - Array args; - /*! \brief Computation stages */ - Array stages; - /*! \brief The data channels */ - Map channels; - - // visit all attributes - void VisitAttrs(AttrVisitor* v) final { - v->Visit("args", &args); - v->Visit("stages", &stages); - v->Visit("channels", &channels); - } - static constexpr const char* _type_key = "VerilogPipeline"; - TVM_DECLARE_NODE_TYPE_INFO(PipelineNode, Node); -}; - -TVM_DEFINE_NODE_REF(Pipeline, PipelineNode); - -/*! - * \brief Build a lowered verilog pipeline given function. - * \param f The function to be transformed. - * \param The created verilog pipeline. - */ -Pipeline MakePipeline(LoweredFunc f); -} // namespace verilog -} // namespace codegen -} // namespace tvm -#endif // TVM_CODEGEN_VERILOG_VERILOG_IR_H_ diff --git a/src/codegen/verilog/verilog_module.cc b/src/codegen/verilog/verilog_module.cc deleted file mode 100644 index 0670a02e34ac..000000000000 --- a/src/codegen/verilog/verilog_module.cc +++ /dev/null @@ -1,87 +0,0 @@ -/*! - * Copyright (c) 2017 by Contributors - * \file verilog_module.cc - * \brief Build verilog source code. - */ -#include -#include -#include -#include "codegen_verilog.h" -#include "../../runtime/file_util.h" -#include "../../runtime/meta_data.h" - -namespace tvm { -namespace codegen { -namespace verilog { -using runtime::TVMArgs; -using runtime::TVMRetValue; -using runtime::PackedFunc; - -// Simulator function -class VerilogModuleNode : public runtime::ModuleNode { - public: - VerilogModuleNode() : fmt_("v") {} - const char* type_key() const { - return "verilog"; - } - - PackedFunc GetFunction( - const std::string& name, - const std::shared_ptr& sptr_to_self) final { - CHECK(sptr_to_self.get() == this); - if (!m_.fmap.count(name)) return PackedFunc(); - auto f = [sptr_to_self, name, this](const runtime::TVMArgs& args, TVMRetValue* rv) { - auto* fsim = runtime::Registry::Get("tvm_callback_verilog_simulator"); - CHECK(fsim != nullptr) - << "tvm_callback_verilog_simulator is not registered," - <<" did you import tvm.addon.verilog?"; - std::string code = m_.AppendSimMain(name); - - if (const auto* f = runtime::Registry::Get("tvm_callback_verilog_postproc")) { - code = (*f)(code).operator std::string(); - } - std::vector values; - std::vector codes; - TVMValue v; - v.v_str = code.c_str(); - values.push_back(v); - codes.push_back(kStr); - for (int i = 0; i < args.num_args; ++i) { - values.push_back(args.values[i]); - codes.push_back(args.type_codes[i]); - } - fsim->CallPacked(TVMArgs(&values[0], &codes[0], args.num_args + 1), rv); - }; - return PackedFunc(f); - } - - std::string GetSource(const std::string& format) final { - return m_.code; - } - - void Init(const Array& funcs) { - CodeGenVerilog cg; - cg.Init(); - for (LoweredFunc f : funcs) { - cg.AddFunction(f); - } - m_ = cg.Finish(); - } - - private: - // the verilog code. data - VerilogCodeGenModule m_; - // format; - std::string fmt_; -}; - -TVM_REGISTER_API("codegen.build_verilog") -.set_body([](TVMArgs args, TVMRetValue* rv) { - std::shared_ptr n = - std::make_shared(); - n->Init(args[0]); - *rv = runtime::Module(n); - }); -} // namespace verilog -} // namespace codegen -} // namespace tvm diff --git a/src/codegen/verilog/vpi_device_api.cc b/src/codegen/verilog/vpi_device_api.cc deleted file mode 100644 index 656630351cf5..000000000000 --- a/src/codegen/verilog/vpi_device_api.cc +++ /dev/null @@ -1,426 +0,0 @@ -/*! - * Copyright (c) 2017 by Contributors - * \file vpi_device.cc - * \brief Simulated VPI RAM device. - */ -#include -#include -#include -#include -#include -#include -#include -#include "vpi_session.h" - -namespace tvm { -namespace codegen { - -/*! \brief Simulated device ram */ -class VPIDeviceAPI final : public runtime::DeviceAPI { - public: - VPIDeviceAPI() { - const char* s_ram_size = getenv("TVM_VPI_RAM_SIZE_MB"); - // 16 MB ram. - int ram_size = 32; - if (s_ram_size != nullptr) { - ram_size = atoi(s_ram_size); - } - ram_.resize(ram_size << 17); - ram_head_ = runtime::kAllocAlignment; - ram_max_ = ram_.size() * sizeof(int64_t); - LOG(INFO) << "Initialize VPI simulated ram " << ram_size << "MB ..."; - } - // convert address to real address - void* RealAddr(const void* addr, size_t size) const { - int64_t ptr = reinterpret_cast(addr); - CHECK_LE(ptr + size, ram_max_) - << "VPI: Illegal memory access"; - return (char*)(&ram_[0]) + ptr; // NOLINT(*) - } - // convert address to real address - void* RealAddrSafe(const void* addr, size_t size) const { - int64_t ptr = reinterpret_cast(addr); - if (ptr + size >= ram_max_) return nullptr; - return (char*)(&ram_[0]) + ptr; // NOLINT(*) - } - void SetDevice(TVMContext ctx) final {} - void GetAttr(TVMContext ctx, runtime::DeviceAttrKind kind, TVMRetValue* rv) final { - if (kind == runtime::kExist) { - *rv = 1; - } - } - void* AllocDataSpace(TVMContext ctx, - size_t size, - size_t alignment, - TVMType type_hint) final { - // always align to 32 bytes at least. - CHECK_LE(alignment, runtime::kAllocAlignment); - alignment = runtime::kAllocAlignment; - // always allocate block with aligned size. - size += alignment - (size % alignment); - // This is not thread safe, but fine for simulation. - auto it = free_blocks_.lower_bound(size); - if (it != free_blocks_.end()) { - size_t head = it->second; - free_blocks_.erase(it); - Block& b = block_map_.at(head); - CHECK(b.is_free); - b.is_free = false; - return reinterpret_cast(head); - } else { - CHECK_EQ(ram_head_ % runtime::kAllocAlignment, 0U); - Block b; - b.size = size; - b.is_free = false; - CHECK_LE(ram_head_ + size, ram_max_) - << "VPI: Out of memory"; - block_map_[ram_head_] = b; - void* ret = reinterpret_cast(ram_head_); - ram_head_ += size; - return ret; - } - } - void FreeDataSpace(TVMContext ctx, void* ptr) final { - size_t head = reinterpret_cast(ptr); - Block& b = block_map_.at(head); - b.is_free = true; - free_blocks_.insert({b.size, head}); - } - void CopyDataFromTo(const void* from, - size_t from_offset, - void* to, - size_t to_offset, - size_t size, - TVMContext ctx_from, - TVMContext ctx_to, - TVMType type_hint, - TVMStreamHandle stream) final { - if (static_cast(ctx_from.device_type) == kDLVPI) { - from = RealAddr(static_cast(from) + from_offset, size); - } - if (static_cast(ctx_to.device_type) == kDLVPI) { - to = RealAddr(static_cast(to) + to_offset, size); - } - memcpy(to, from, size); - } - void StreamSync(TVMContext ctx, TVMStreamHandle stream) final { - } - static VPIDeviceAPI* Global() { - static VPIDeviceAPI inst; - return &inst; - } - - private: - // allocator block for reuse - struct Block { - // The size of the block - size_t size; - // Whether this is already freed. - bool is_free{true}; - }; - // head -> blocks - std::unordered_map block_map_; - // size -> free heads. - std::multimap free_blocks_; - // top of the ram - size_t ram_head_, ram_max_; - // The ram space. - std::vector ram_; -}; - -/* !\brief vector buffer to help read/write */ -class VPIVecBuffer { - public: - // Put data into vec - void put_vec(const VPIHandle& h, size_t nwords, - const void* dptr, size_t size) { - wbuf_.resize(nwords); - vbuf_.resize(nwords); - memcpy(&wbuf_[0], dptr, size); - for (size_t i = 0; i < nwords; ++i) { - vbuf_[i].aval = wbuf_[i]; - vbuf_[i].bval = 0; - } - h.put_vec(vbuf_); - } - // read data from vec. - void get_vec(const VPIHandle& h, void* dptr, size_t size) { - h.get_vec(&vbuf_); - wbuf_.resize(vbuf_.size()); - for (size_t i = 0; i < vbuf_.size(); ++i) { - wbuf_[i] = vbuf_[i].aval; - CHECK_EQ(vbuf_[i].bval, 0) - << "Write indetermined value to RAM"; - } - memcpy(dptr, &wbuf_[0], size); - } - - private: - // Temporal buffers. - std::vector wbuf_; - std::vector vbuf_; -}; - -/*! - * \brief Memory interface for VPI memory. - */ -class VPIMemoryInterface { - public: - // Initialize the FSM. - void Init(VPIHandle module) { - device_ = VPIDeviceAPI::Global(); - in_rst_ = module["rst"]; - // read ports - in_read_dequeue_ = module["read_en"]; - out_reg_read_data_ = module["reg_read_data"]; - // Write ports - in_write_enqueue_ = module["write_en"]; - in_write_data_ = module["write_data_in"]; - // Status port - out_reg_read_valid_ = module["reg_read_valid"]; - out_reg_write_ready_ = module["reg_write_ready"]; - // memory control signal - ctrl_read_req_ = module["host_read_req"]; - ctrl_read_addr_ = module["host_read_addr"]; - ctrl_read_size_ = module["host_read_size"]; - ctrl_write_req_ = module["host_write_req"]; - ctrl_write_addr_ = module["host_write_addr"]; - ctrl_write_size_ = module["host_write_size"]; - // The bit and bytes; - size_t read_bits = out_reg_read_data_.size(); - size_t write_bits = in_write_data_.size(); - CHECK_EQ(read_bits % 8U, 0) - << "Read/write unit have to be multiple of 8 bit(bytes)"; - CHECK_EQ(write_bits % 8U, 0) - << "Read/write unit have to be multiple of 8 bit(bytes)"; - read_unit_bytes_ = read_bits / 8U; - write_unit_bytes_ = write_bits / 8U; - } - // Callback at neg-edge. - void AtNegEdge() { - // reset - if (in_rst_.get_int()) { - CHECK_EQ(pending_read_.size, 0U); - CHECK_EQ(pending_write_.size, 0U); - CHECK(read_tasks_.empty()); - CHECK(write_tasks_.empty()); - out_reg_write_ready_.put_int(0); - out_reg_read_valid_.put_int(0); - return; - } - // read write tasks - if (in_read_dequeue_.get_int() || !out_reg_read_valid_.get_int()) { - ReadFromFIFO(); - } - // update write full - if (in_write_enqueue_.get_int()) { - CHECK(out_reg_write_ready_.get_int()); - WriteToFIFO(); - } - if (pending_write_.size || write_tasks_.size()) { - out_reg_write_ready_.put_int(1); - } else { - out_reg_write_ready_.put_int(0); - } - // Control tasks - if (ctrl_read_req_.get_int()) { - FIFOTask tsk; - tsk.addr = reinterpret_cast(ctrl_read_addr_.get_int()); - tsk.size = static_cast(ctrl_read_size_.get_int()); - read_tasks_.push(tsk); - } - // Control tasks - if (ctrl_write_req_.get_int()) { - FIFOTask tsk; - tsk.addr = reinterpret_cast(ctrl_write_addr_.get_int()); - tsk.size = static_cast(ctrl_write_size_.get_int()); - write_tasks_.push(tsk); - } - } - - private: - // The FIFO tasks - struct FIFOTask { - char* addr{nullptr}; - size_t size{0}; - }; - // handle dequeue event - void ReadFromFIFO() { - if (pending_read_.size == 0) { - if (!read_tasks_.empty()) { - pending_read_ = read_tasks_.front(); - read_tasks_.pop(); - // translate to real memory addr - pending_read_.addr = static_cast( - device_->RealAddr( - pending_read_.addr, pending_read_.size)); - } - } - if (pending_read_.size != 0) { - // The size to be read - size_t nread = std::min(pending_read_.size, read_unit_bytes_); - // Read from the data - size_t nwords = (read_unit_bytes_ + 3) / 4; - vbuf_.put_vec(out_reg_read_data_, nwords, - pending_read_.addr, nread); - // Update the pointer - pending_read_.size -= nread; - pending_read_.addr += nread; - // read into the vector - out_reg_read_valid_.put_int(1); - } else { - out_reg_read_valid_.put_int(0); - } - } - // handle write event - void WriteToFIFO() { - if (pending_write_.size == 0) { - if (!write_tasks_.empty()) { - pending_write_ = write_tasks_.front(); - write_tasks_.pop(); - // translate to real memory addr - pending_write_.addr = static_cast( - device_->RealAddr( - pending_write_.addr, pending_write_.size)); - } - } - if (pending_write_.size != 0) { - // write to the ram. - size_t nwrite = std::min(pending_write_.size, write_unit_bytes_); - vbuf_.get_vec(in_write_data_, pending_write_.addr, nwrite); - // Update the pointer - pending_write_.size -= nwrite; - pending_write_.addr += nwrite; - } - } - // Device API - VPIDeviceAPI* device_{nullptr}; - // Input clock and reset - VPIHandle in_rst_; - // Read FIFO signal - VPIHandle in_read_dequeue_; - // Write FIFO signal - VPIHandle in_write_enqueue_; - VPIHandle in_write_data_; - // Read memory controler signals - VPIHandle ctrl_read_req_; - VPIHandle ctrl_read_addr_; - VPIHandle ctrl_read_size_; - // Write memory controler signal signals - VPIHandle ctrl_write_req_; - VPIHandle ctrl_write_addr_; - VPIHandle ctrl_write_size_; - // Read FIFO outputs - VPIHandle out_reg_read_data_; - VPIHandle out_reg_read_valid_; - // Write FIFO outputs - VPIHandle out_reg_write_ready_; - // Size of current pending read. - FIFOTask pending_read_; - FIFOTask pending_write_; - // The read/write task queues. - std::queue read_tasks_; - std::queue write_tasks_; - // Unit bytes for read/writing - size_t read_unit_bytes_; - size_t write_unit_bytes_; - // Temporal buffers. - VPIVecBuffer vbuf_; -}; - -// Read only memory map. -class VPIMemMapBase { - public: - // Initialize the FSM. - void Init(VPIHandle module, const std::string& data_port) { - device_ = VPIDeviceAPI::Global(); - // intiatialize the connections - rst_ = module["rst"]; - addr_ = module["addr"]; - data_ = module[data_port]; - mmap_addr_ = module["mmap_addr"]; - size_t unit_bits = data_.size(); - CHECK_EQ(unit_bits % 8U, 0) - << "Read/write unit have to be multiple of 8 bit(bytes)"; - unit_bytes_ = unit_bits / 8U; - } - void* RealAddr() { - int byte_offset = addr_.get_int() * unit_bytes_; - void* ptr = - device_->RealAddrSafe( - reinterpret_cast(mmap_addr_.get_int() + byte_offset), 1); - return ptr; - } - - protected: - // Device API - VPIDeviceAPI* device_{nullptr}; - VPIHandle rst_; - VPIHandle addr_; - VPIHandle data_; - VPIHandle mmap_addr_; - size_t unit_bytes_; - VPIVecBuffer vbuf_; -}; - -class VPIReadMemMap : public VPIMemMapBase { - public: - void Init(VPIHandle module) { - VPIMemMapBase::Init(module, "reg_data"); - } - void AtNegEdge() { - void* ptr = RealAddr(); - if (ptr == nullptr) return; - size_t nwords = (unit_bytes_ + 3) / 4; - vbuf_.put_vec(data_, nwords, ptr, unit_bytes_); - } -}; - -// Write only memory map. -class VPIWriteMemMap : public VPIMemMapBase { - public: - void Init(VPIHandle module) { - VPIMemMapBase::Init(module, "data_in"); - enable_ = module["en"]; - } - void AtNegEdge() { - if (!enable_.get_int() || rst_.get_int()) return; - void* ptr = RealAddr(); - CHECK(ptr != nullptr) - << "Illegal write to VPI RAM"; - vbuf_.get_vec(data_, ptr, unit_bytes_); - } - - private: - VPIHandle enable_; -}; - -TVM_REGISTER_GLOBAL("device_api.vpi") -.set_body([](runtime::TVMArgs args, runtime::TVMRetValue* rv) { - runtime::DeviceAPI* ptr = VPIDeviceAPI::Global(); - *rv = static_cast(ptr); - }); - -template -void TVMVPIHook(runtime::TVMArgs args, runtime::TVMRetValue* rv) { - VPIHandle m = args[0]; - std::shared_ptr p = std::make_shared(); - p->Init(m); - LOG(INFO) << "Hook " << m.name() << " to tvm vpi simulation..."; - PackedFunc pf([p](const runtime::TVMArgs&, runtime::TVMRetValue*) { - p->AtNegEdge(); - }); - *rv = pf; -} - -TVM_REGISTER_GLOBAL("_vpi_module_tvm_vpi_mem_interface") -.set_body(TVMVPIHook); - -TVM_REGISTER_GLOBAL("_vpi_module_tvm_vpi_read_mmap") -.set_body(TVMVPIHook); - -TVM_REGISTER_GLOBAL("_vpi_module_tvm_vpi_write_mmap") -.set_body(TVMVPIHook); - -} // namespace codegen -} // namespace tvm diff --git a/src/codegen/verilog/vpi_session.cc b/src/codegen/verilog/vpi_session.cc deleted file mode 100644 index 9ab5f79e62f9..000000000000 --- a/src/codegen/verilog/vpi_session.cc +++ /dev/null @@ -1,262 +0,0 @@ -/*! - * Copyright (c) 2017 by Contributors - * \file vpi_session.cc - * \brief IPC session call to verilog simulator via VPI. - */ -#include -#include -#include "vpi_session.h" - -namespace tvm { -namespace codegen { - -using namespace vpi; - -// helper class to get the node. -class VPISessionEntry { - public: - // Whether in control. - bool in_control{false}; - // Internal reader and writer. - common::Pipe reader; - common::Pipe writer; - // internal constructor - VPISessionEntry(int h_pipe_read, int h_pipe_write) - : reader(h_pipe_read), writer(h_pipe_write) { - } - ~VPISessionEntry() { - if (in_control) { - VPIReturnCode cd; - writer.Write(kShutDown); - reader.Read(&cd); - } - reader.Close(); - writer.Close(); - } - void ReadExpect(VPIReturnCode rcode) { - VPIReturnCode code; - CHECK(reader.Read(&code)); - CHECK_EQ(code, rcode) << "Error in simulation"; - } -}; - -// Inline implementations -inline VPISessionNode* VPISession::get() const { - return static_cast(node_.get()); -} -inline VPIHandleNode* VPIHandle::get() const { - return static_cast(node_.get()); -} - -VPIHandle VPIHandleCreate( - const std::shared_ptr& sess, - VPIRawHandle handle) { - auto n = make_node(); - n->sess = sess; - n->handle = handle; - return VPIHandle(n); -} - -VPIHandle GetHandleByName( - const std::shared_ptr& sess, - const std::string& name, - VPIRawHandle handle, - bool allow_undefined) { - VPISessionEntry* n = sess.get(); - CHECK(n->in_control); - n->writer.Write(kGetHandleByName); - n->writer.Write(name); - n->writer.Write(handle); - n->ReadExpect(kSuccess); - CHECK(n->reader.Read(&handle)); - if (handle != nullptr) { - return VPIHandleCreate(sess, handle); - } else { - CHECK(allow_undefined) - << "Cannot find handle with name=" << name; - return VPIHandle(); - } -} - -std::string VPIGetStrProp(VPIHandleNode* h, int code) { - VPISessionEntry* n = h->sess.get(); - CHECK(n->in_control); - n->writer.Write(kGetStrProp); - n->writer.Write(code); - n->writer.Write(h->handle); - n->ReadExpect(kSuccess); - std::string str; - CHECK(n->reader.Read(&str)); - return str; -} - -int VPIGetIntProp(VPIHandleNode* h, int code) { - VPISessionEntry* n = h->sess.get(); - CHECK(n->in_control); - n->writer.Write(kGetIntProp); - n->writer.Write(code); - n->writer.Write(h->handle); - n->ReadExpect(kSuccess); - int value; - CHECK(n->reader.Read(&value)); - return value; -} - -VPISession VPISession::make(int h_pipe_read, int h_pipe_write) { - auto n = make_node(); - n->sess = std::make_shared(h_pipe_read, h_pipe_write); - n->sess->in_control = true; - VPISession sess(n); - // The custom module handles - std::vector mod_handles; - n->sess->reader.Read(&mod_handles); - n->sess->ReadExpect(kPosEdgeTrigger); - // start Initialize the callbacks - for (VPIRawHandle raw_h : mod_handles) { - VPIHandle h = VPIHandleCreate(n->sess, raw_h); - CHECK_EQ(VPIGetIntProp(h.get(), kVPIType), kVPIModule) - << "Expect pass modules to $tvm_session after clk"; - std::string def = VPIGetStrProp(h.get(), kVPIDefName); - std::string callback_name = "_vpi_module_" + def; - const PackedFunc* f = runtime::Registry::Get(callback_name); - CHECK(f != nullptr) - << "Cannot find definition for tvm vpi module " << def; - PackedFunc cb = (*f)(h); - n->posedge_end_callbacks.push_back(cb); - } - return sess; -} - -VPIHandle VPISession::operator[](const std::string& name) const { - return GetHandleByName(get()->sess, name, nullptr, false); -} -VPIHandle VPISession::GetByName(const std::string& name, - bool allow_undefined) const { - return GetHandleByName(get()->sess, name, nullptr, true); -} - -void VPISession::yield() { - VPISessionEntry* n = get()->sess.get(); - CHECK(n->in_control); - for (const PackedFunc& f : get()->posedge_end_callbacks) { - f(); - } - n->writer.Write(kYield); - n->ReadExpect(kSuccess); - n->in_control = false; - n->ReadExpect(kPosEdgeTrigger); - n->in_control = true; -} - -void VPISession::shutdown() { - VPISessionEntry* n = get()->sess.get(); - if (n->in_control) { - n->writer.Write(kShutDown); - n->ReadExpect(kSuccess); - n->in_control = false; - } -} - -int VPIHandle::size() const { - return VPIGetIntProp(get(), kVPISize); -} - -void VPIHandle::put_int(int value) { - VPIHandleNode* h = get(); - VPISessionEntry* n = h->sess.get(); - CHECK(n->in_control); - n->writer.Write(kPutInt32); - n->writer.Write(h->handle); - n->writer.Write(value); - n->ReadExpect(kSuccess); -} - -int VPIHandle::get_int() const { - VPIHandleNode* h = get(); - VPISessionEntry* n = h->sess.get(); - CHECK(n->in_control); - n->writer.Write(kGetInt32); - n->writer.Write(h->handle); - n->ReadExpect(kSuccess); - int value; - CHECK(n->reader.Read(&value)); - return value; -} - -std::string VPIHandle::name() const { - return VPIGetStrProp(get(), kVPIFullName); -} - -void VPIHandle::put_vec(const std::vector& vec) const { - VPIHandleNode* h = get(); - VPISessionEntry* n = h->sess.get(); - CHECK(n->in_control); - n->writer.Write(kPutVec); - n->writer.Write(h->handle); - n->writer.Write(vec); - n->ReadExpect(kSuccess); -} - -void VPIHandle::get_vec(std::vector* vec) const { - VPIHandleNode* h = get(); - VPISessionEntry* n = h->sess.get(); - CHECK(n->in_control); - n->writer.Write(kGetVec); - n->writer.Write(h->handle); - n->ReadExpect(kSuccess); - CHECK(n->reader.Read(vec)); -} - -VPIHandle VPIHandle::operator[](const std::string& name) const { - VPIHandleNode* h = get(); - return GetHandleByName(h->sess, name, h->handle, false); -} - -// API registration -TVM_REGISTER_API("_vpi_SessMake") -.set_body([](TVMArgs args, TVMRetValue *ret) { - *ret = VPISession::make(args[0], args[1]); - }); - -TVM_REGISTER_API("_vpi_SessGetHandleByName") -.set_body([](TVMArgs args, TVMRetValue *ret) { - *ret = args[0].operator VPISession().operator[](args[1]); - }); - -TVM_REGISTER_API("_vpi_SessYield") -.set_body([](TVMArgs args, TVMRetValue *ret) { - args[0].operator VPISession().yield(); - }); - -TVM_REGISTER_API("_vpi_SessShutdown") -.set_body([](TVMArgs args, TVMRetValue *ret) { - args[0].operator VPISession().shutdown(); - }); - -TVM_REGISTER_API("_vpi_HandlePutInt") -.set_body([](TVMArgs args, TVMRetValue *ret) { - args[0].operator VPIHandle().put_int(args[1]); - }); - -TVM_REGISTER_API("_vpi_HandleGetInt") -.set_body([](TVMArgs args, TVMRetValue *ret) { - *ret = args[0].operator VPIHandle().get_int(); - }); - -TVM_REGISTER_API("_vpi_HandleGetName") -.set_body([](TVMArgs args, TVMRetValue *ret) { - *ret = args[0].operator VPIHandle().name(); - }); - -TVM_REGISTER_API("_vpi_HandleGetSize") -.set_body([](TVMArgs args, TVMRetValue *ret) { - *ret = args[0].operator VPIHandle().size(); - }); - -TVM_REGISTER_API("_vpi_HandleGetHandleByName") -.set_body([](TVMArgs args, TVMRetValue *ret) { - *ret = args[0].operator VPIHandle().operator[](args[1]); - }); - -} // namespace codegen -} // namespace tvm diff --git a/src/codegen/verilog/vpi_session.h b/src/codegen/verilog/vpi_session.h deleted file mode 100644 index 05447b4b70ad..000000000000 --- a/src/codegen/verilog/vpi_session.h +++ /dev/null @@ -1,135 +0,0 @@ -/*! - * Copyright (c) 2017 by Contributors - * \file vpi_session.h - * \brief IPC session call to verilog simulator via VPI. - */ -#ifndef TVM_CODEGEN_VERILOG_VPI_SESSION_H_ -#define TVM_CODEGEN_VERILOG_VPI_SESSION_H_ - -#include -#include -#include -#include -#include "../../common/pipe.h" -#include "../../../verilog/tvm_vpi.h" - -namespace tvm { -namespace codegen { - -// node containers -class VPISessionNode; -class VPIHandleNode; -class VPIHandle; -class VPISessionEntry; - -using runtime::PackedFunc; - -/*! \brief Environment */ -class VPISession : public NodeRef { - public: - VPISession() {} - explicit VPISession(NodePtr n) : NodeRef(n) {} - /*! - * \brief Get handle by name. - * \param name The name of the handle. - */ - VPIHandle operator[](const std::string& name) const; - /*! - * \brief Get handle by name. - * \param name The name of the handle. - * \param allow_undefined whether allow undefined - */ - VPIHandle GetByName(const std::string& name, bool allow_undefined) const; - /*! - * \brief Yield control back to the simulator - * Block until next cycle. - */ - void yield(); - /*! - * \brief Shutdown the session. - */ - void shutdown(); - /*! - * \brief Create new session by giving a read and write pipe to VPI process. - * \param h_pipe_read a read pipe from VPI process. - * \param h_pipe_write a write pipe from VPI process. - */ - static VPISession make(int h_pipe_read, int h_pipe_write); - // Internal methods. - using ContainerType = VPISessionNode; - inline VPISessionNode* get() const; -}; - -/*! \brief VPI Handle */ -class VPIHandle : public NodeRef { - public: - VPIHandle() {} - explicit VPIHandle(NodePtr n) : NodeRef(n) {} - /*! - * \brief Get handle by name. - * \param name The name of the handle. - */ - VPIHandle operator[](const std::string& name) const; - /*! \return number of bits */ - int size() const; - /*! - * \brief Set int value to the handle. - * \param value The value to set. - */ - void put_int(int value); - /*! - * \brief Get int value from handle. - * \return The result int value. - */ - int get_int() const; - /*! \return Name of the handle. */ - std::string name() const; - /*! - * \brief Put byte vector into the handle. - * \param vec The vector to be put. - * \return The result int value. - */ - void put_vec(const std::vector& vec) const; - /*! - * \brief Get byte vector from handle. - * \param vec The result data container. - */ - void get_vec(std::vector* vec) const; - // Internal methods - using ContainerType = VPIHandleNode; - inline VPIHandleNode* get() const; -}; - -/*! \brief Container for session. */ -class VPISessionNode : public Node { - public: - // internal session. - std::shared_ptr sess; - // callbacks at pos edge end. - std::vector posedge_end_callbacks; - - // visit all attributes - void VisitAttrs(AttrVisitor* v) final { - } - static constexpr const char* _type_key = "VPISession"; - TVM_DECLARE_NODE_TYPE_INFO(VPISessionNode, Node); -}; - -/*! \brief Container for handle */ -class VPIHandleNode : public Node { - public: - // internal session. - std::shared_ptr sess; - // Internal handle - vpi::VPIRawHandle handle; - - void VisitAttrs(AttrVisitor* v) final { - } - - static constexpr const char* _type_key = "VPIHandle"; - TVM_DECLARE_NODE_TYPE_INFO(VPIHandleNode, Node); -}; - -} // namespace codegen -} // namespace tvm -#endif // TVM_CODEGEN_VERILOG_VPI_SESSION_H_ diff --git a/src/common/arena.h b/src/common/arena.h index d58e02f4f8bf..5a70f20f98b6 100644 --- a/src/common/arena.h +++ b/src/common/arena.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright 2018 by Contributors * diff --git a/src/common/base64.h b/src/common/base64.h index 3f530e10a7e5..94fc1453030d 100644 --- a/src/common/base64.h +++ b/src/common/base64.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright 2018 by Contributors * diff --git a/src/common/pipe.h b/src/common/pipe.h index fce764509d68..4f049638ecb1 100644 --- a/src/common/pipe.h +++ b/src/common/pipe.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file pipe.h diff --git a/src/common/ring_buffer.h b/src/common/ring_buffer.h index dcec54d1823d..ebb8a362003a 100644 --- a/src/common/ring_buffer.h +++ b/src/common/ring_buffer.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file ring_buffer.h diff --git a/src/common/socket.h b/src/common/socket.h index 5c39f409d8e2..58705f16bf73 100644 --- a/src/common/socket.h +++ b/src/common/socket.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file socket.h diff --git a/src/contrib/cblas/cblas.cc b/src/contrib/cblas/cblas.cc index 7473d45562fd..4ca043f1bcfe 100644 --- a/src/contrib/cblas/cblas.cc +++ b/src/contrib/cblas/cblas.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file Use external cblas library call. diff --git a/src/contrib/cblas/gemm_common.h b/src/contrib/cblas/gemm_common.h index c69da5ea3e17..fe38b2a67513 100644 --- a/src/contrib/cblas/gemm_common.h +++ b/src/contrib/cblas/gemm_common.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file tvm/contrib/gemm.h diff --git a/src/contrib/cublas/cublas.cc b/src/contrib/cublas/cublas.cc index 364129b7cba7..694d19b39426 100644 --- a/src/contrib/cublas/cublas.cc +++ b/src/contrib/cublas/cublas.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file Use external cblas library call. diff --git a/src/contrib/cublas/cublas_utils.cc b/src/contrib/cublas/cublas_utils.cc index 0011fe853d8d..086c20868e45 100644 --- a/src/contrib/cublas/cublas_utils.cc +++ b/src/contrib/cublas/cublas_utils.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file Use external cudnn utils function diff --git a/src/contrib/cublas/cublas_utils.h b/src/contrib/cublas/cublas_utils.h index 2b0874757d98..f45c45812bd3 100644 --- a/src/contrib/cublas/cublas_utils.h +++ b/src/contrib/cublas/cublas_utils.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file Use external cudnn utils function diff --git a/src/contrib/cudnn/conv_forward.cc b/src/contrib/cudnn/conv_forward.cc index 4cd25f0c2fe4..c4d8b37a4906 100644 --- a/src/contrib/cudnn/conv_forward.cc +++ b/src/contrib/cudnn/conv_forward.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file Use external cudnn utils function diff --git a/src/contrib/cudnn/cudnn_utils.cc b/src/contrib/cudnn/cudnn_utils.cc index 5ca558f7d8ba..75bfc1333162 100644 --- a/src/contrib/cudnn/cudnn_utils.cc +++ b/src/contrib/cudnn/cudnn_utils.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file Use external cudnn utils function diff --git a/src/contrib/cudnn/cudnn_utils.h b/src/contrib/cudnn/cudnn_utils.h index 0e47f4dcf7de..c753854c3b78 100644 --- a/src/contrib/cudnn/cudnn_utils.h +++ b/src/contrib/cudnn/cudnn_utils.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file Use external cudnn utils function diff --git a/src/contrib/hybrid/codegen_hybrid.cc b/src/contrib/hybrid/codegen_hybrid.cc index 56564d668001..e98b366bd2c9 100644 --- a/src/contrib/hybrid/codegen_hybrid.cc +++ b/src/contrib/hybrid/codegen_hybrid.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! Copyright (c) 2019 by Contributors * \file codegen_hybrid.cc */ diff --git a/src/contrib/hybrid/codegen_hybrid.h b/src/contrib/hybrid/codegen_hybrid.h index cdd6b85b9f9e..e2975563a5b4 100644 --- a/src/contrib/hybrid/codegen_hybrid.h +++ b/src/contrib/hybrid/codegen_hybrid.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2019 by Contributors * \file codegen_hybrid.h diff --git a/src/contrib/miopen/conv_forward.cc b/src/contrib/miopen/conv_forward.cc index 7090560e3889..705a0d47a835 100644 --- a/src/contrib/miopen/conv_forward.cc +++ b/src/contrib/miopen/conv_forward.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file Use external miopen utils function diff --git a/src/contrib/miopen/miopen_utils.cc b/src/contrib/miopen/miopen_utils.cc index 3019b1b83e81..8faa4bdfee4e 100644 --- a/src/contrib/miopen/miopen_utils.cc +++ b/src/contrib/miopen/miopen_utils.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file Use external miopen utils function diff --git a/src/contrib/miopen/miopen_utils.h b/src/contrib/miopen/miopen_utils.h index b01fc017ed95..8f65fc7b28be 100644 --- a/src/contrib/miopen/miopen_utils.h +++ b/src/contrib/miopen/miopen_utils.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file Use external miopen utils function diff --git a/src/contrib/mps/conv.mm b/src/contrib/mps/conv.mm index fa279bd5cc95..064e6d53cfb8 100644 --- a/src/contrib/mps/conv.mm +++ b/src/contrib/mps/conv.mm @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #include "mps_utils.h" namespace tvm { @@ -38,7 +57,7 @@ [mpsimg readBytes:[temp contents] dataLayout:MPSDataLayoutHeightxWidthxFeatureChannels imageIndex:0]; - + }); TVM_REGISTER_GLOBAL("tvm.contrib.mps.img2buffer") @@ -147,7 +166,7 @@ [cb waitUntilCompleted]; (*f_img2buf)(&tmp_out, output); - + }); } // namespace contrib diff --git a/src/contrib/mps/gemm.mm b/src/contrib/mps/gemm.mm index 1d92ad2851d0..bc1216704cc4 100644 --- a/src/contrib/mps/gemm.mm +++ b/src/contrib/mps/gemm.mm @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ #include "mps_utils.h" @@ -80,7 +98,7 @@ rightMatrix:matrixB resultMatrix:matrixC]; [cb commit]; - + }); } // namespace contrib diff --git a/src/contrib/mps/mps_utils.h b/src/contrib/mps/mps_utils.h index f07156a252a3..99288a8928d8 100644 --- a/src/contrib/mps/mps_utils.h +++ b/src/contrib/mps/mps_utils.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file Use external mps utils function diff --git a/src/contrib/mps/mps_utils.mm b/src/contrib/mps/mps_utils.mm index bed8278a1d50..b3d4070ca6b7 100644 --- a/src/contrib/mps/mps_utils.mm +++ b/src/contrib/mps/mps_utils.mm @@ -1,7 +1,22 @@ -/*! - * Copyright (c) 2017 by Contributors - * \file Use external mps utils function +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ + #include "mps_utils.h" namespace tvm { diff --git a/src/contrib/nnpack/convolution.cc b/src/contrib/nnpack/convolution.cc index 538d29333b4a..2c0c1d26af62 100644 --- a/src/contrib/nnpack/convolution.cc +++ b/src/contrib/nnpack/convolution.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file Use external nnpack library call. diff --git a/src/contrib/nnpack/fully_connected.cc b/src/contrib/nnpack/fully_connected.cc index 80f981b29cf6..8387a2176f2b 100644 --- a/src/contrib/nnpack/fully_connected.cc +++ b/src/contrib/nnpack/fully_connected.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file Use external nnpack library call. diff --git a/src/contrib/nnpack/nnpack_utils.cc b/src/contrib/nnpack/nnpack_utils.cc index 12eb828cc7e6..f6f0b0d024f3 100644 --- a/src/contrib/nnpack/nnpack_utils.cc +++ b/src/contrib/nnpack/nnpack_utils.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file Use external nnpack library call. diff --git a/src/contrib/nnpack/nnpack_utils.h b/src/contrib/nnpack/nnpack_utils.h index 1d44adff16ef..9491802ca8a5 100644 --- a/src/contrib/nnpack/nnpack_utils.h +++ b/src/contrib/nnpack/nnpack_utils.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file Use external nnpack library call. diff --git a/src/contrib/random/mt_random_engine.cc b/src/contrib/random/mt_random_engine.cc index b4fcbde02dae..79224c983766 100644 --- a/src/contrib/random/mt_random_engine.cc +++ b/src/contrib/random/mt_random_engine.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file random/mt_random_engine.cc diff --git a/src/contrib/random/random.cc b/src/contrib/random/random.cc index 68821fe04124..f465902d437d 100644 --- a/src/contrib/random/random.cc +++ b/src/contrib/random/random.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file External random functions for tensor. diff --git a/src/contrib/random/sgx_random_engine.cc b/src/contrib/random/sgx_random_engine.cc index 4b40cb282bcc..98e2b616bb69 100644 --- a/src/contrib/random/sgx_random_engine.cc +++ b/src/contrib/random/sgx_random_engine.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file random/sgx_random_engine.h diff --git a/src/contrib/rocblas/rocblas.cc b/src/contrib/rocblas/rocblas.cc index 1dbf429461eb..fe9da83112e1 100644 --- a/src/contrib/rocblas/rocblas.cc +++ b/src/contrib/rocblas/rocblas.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file Use external rocblas library call. diff --git a/src/contrib/sort/sort.cc b/src/contrib/sort/sort.cc index 160e479b86b5..fd0107c4706d 100644 --- a/src/contrib/sort/sort.cc +++ b/src/contrib/sort/sort.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file Use standard C library call. diff --git a/src/lang/api_registry.cc b/src/lang/api_registry.cc index c9f84092f5da..e041f3a2dd2d 100644 --- a/src/lang/api_registry.cc +++ b/src/lang/api_registry.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file api_registry.cc diff --git a/src/lang/attr_functor.h b/src/lang/attr_functor.h index 8043d5388ac4..249ce523a3cc 100644 --- a/src/lang/attr_functor.h +++ b/src/lang/attr_functor.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file attr_functor.h diff --git a/src/lang/attrs.cc b/src/lang/attrs.cc index 1daf1e792553..ec2fd742ba14 100644 --- a/src/lang/attrs.cc +++ b/src/lang/attrs.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file attrs.cc diff --git a/src/lang/buffer.cc b/src/lang/buffer.cc index 524cad2eeac6..8c584c50b3c6 100644 --- a/src/lang/buffer.cc +++ b/src/lang/buffer.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file buffer.cc diff --git a/src/lang/channel.cc b/src/lang/channel.cc index dcc44a0d0611..6746a3c5ecb5 100644 --- a/src/lang/channel.cc +++ b/src/lang/channel.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file channel.cc diff --git a/src/lang/data_layout.cc b/src/lang/data_layout.cc index 636820bbee9b..71b323c57daa 100644 --- a/src/lang/data_layout.cc +++ b/src/lang/data_layout.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2019 by Contributors * \file src/lang/data_layout.cc diff --git a/src/lang/expr.cc b/src/lang/expr.cc index 3bf8fc9191fb..fed604922ee3 100644 --- a/src/lang/expr.cc +++ b/src/lang/expr.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file expr.cc diff --git a/src/lang/expr_operator.cc b/src/lang/expr_operator.cc index edbe0be3d5c5..4504ee23f812 100644 --- a/src/lang/expr_operator.cc +++ b/src/lang/expr_operator.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file expr_operator.cc diff --git a/src/lang/ir.cc b/src/lang/ir.cc index 875258540584..612a5e908b54 100644 --- a/src/lang/ir.cc +++ b/src/lang/ir.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file ir.cc diff --git a/src/lang/lowered_func.cc b/src/lang/lowered_func.cc index c199e7faa65d..626b9f7d8d80 100644 --- a/src/lang/lowered_func.cc +++ b/src/lang/lowered_func.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file lowered_func.cc diff --git a/src/lang/reflection.cc b/src/lang/reflection.cc index 86a11a7e5b42..32d521e80621 100644 --- a/src/lang/reflection.cc +++ b/src/lang/reflection.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file reflection.cc diff --git a/src/lang/target_info.cc b/src/lang/target_info.cc index 96178a3947fa..ff6a35286f20 100644 --- a/src/lang/target_info.cc +++ b/src/lang/target_info.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file target_info.cc diff --git a/src/lang/tensor.cc b/src/lang/tensor.cc index 9b1a58abcee4..bab7cf6d93ed 100644 --- a/src/lang/tensor.cc +++ b/src/lang/tensor.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file tensor.cc diff --git a/src/op/compute_op.cc b/src/op/compute_op.cc index 0f676f9793f3..bb91ed8d4a9f 100644 --- a/src/op/compute_op.cc +++ b/src/op/compute_op.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief Compute Op. diff --git a/src/op/compute_op.h b/src/op/compute_op.h index b0264835da5f..5e51873344c7 100644 --- a/src/op/compute_op.h +++ b/src/op/compute_op.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief Helper utilities to implement compute_op. diff --git a/src/op/cross_thread_reduction.cc b/src/op/cross_thread_reduction.cc index c4599dee9bd8..cde46bfaa1b5 100644 --- a/src/op/cross_thread_reduction.cc +++ b/src/op/cross_thread_reduction.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief Logics related to cross thread reduction, used by ComputeOpNode. diff --git a/src/op/extern_op.cc b/src/op/extern_op.cc index cc6d57092f2a..e6c6039b610e 100644 --- a/src/op/extern_op.cc +++ b/src/op/extern_op.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief External computation rule. diff --git a/src/op/hybrid_op.cc b/src/op/hybrid_op.cc index 550d9f985797..48773c644749 100644 --- a/src/op/hybrid_op.cc +++ b/src/op/hybrid_op.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2019 by Contributors * \brief Hybrid computation rule. diff --git a/src/op/hybrid_op.h b/src/op/hybrid_op.h index 892e420137d6..f8a3f86468d0 100644 --- a/src/op/hybrid_op.h +++ b/src/op/hybrid_op.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2019 by Contributors * \brief Helper utilities to implement hybrid_op. diff --git a/src/op/op_util.cc b/src/op/op_util.cc index b18552d5c562..e354102f0954 100644 --- a/src/op/op_util.cc +++ b/src/op/op_util.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief Utility to make loop nest. diff --git a/src/op/op_util.h b/src/op/op_util.h index de2e44c2ed59..82e88cfc1177 100644 --- a/src/op/op_util.h +++ b/src/op/op_util.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file op_util.h diff --git a/src/op/placeholder_op.cc b/src/op/placeholder_op.cc index fcd5993dafa5..f94b7d072e26 100644 --- a/src/op/placeholder_op.cc +++ b/src/op/placeholder_op.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief Placeholder op. diff --git a/src/op/scan_op.cc b/src/op/scan_op.cc index 610d4619390d..42b1331e3736 100644 --- a/src/op/scan_op.cc +++ b/src/op/scan_op.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief Scan Operator. diff --git a/src/op/tensor_compute_op.cc b/src/op/tensor_compute_op.cc index 3ccce0c5d38a..ed768c2ba216 100644 --- a/src/op/tensor_compute_op.cc +++ b/src/op/tensor_compute_op.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief Tensor Compute Op. diff --git a/src/op/tensorize.cc b/src/op/tensorize.cc index a61aac422284..00181aa37bb8 100644 --- a/src/op/tensorize.cc +++ b/src/op/tensorize.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief Logics related to tensorize, used by ComputeOpNode. diff --git a/src/pass/arg_binder.cc b/src/pass/arg_binder.cc index 623886c31b86..2822393d3f75 100644 --- a/src/pass/arg_binder.cc +++ b/src/pass/arg_binder.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file arg_binder.cc diff --git a/src/pass/arg_binder.h b/src/pass/arg_binder.h index 47734af2abe9..9de3a13270dc 100644 --- a/src/pass/arg_binder.h +++ b/src/pass/arg_binder.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file arg_binder.h diff --git a/src/pass/bound_checker.cc b/src/pass/bound_checker.cc index a7c03d0d1d60..274d8c68f787 100644 --- a/src/pass/bound_checker.cc +++ b/src/pass/bound_checker.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file bounds_checker.cc diff --git a/src/pass/combine_context_call.cc b/src/pass/combine_context_call.cc index d3cbb2842134..1e2842deb856 100644 --- a/src/pass/combine_context_call.cc +++ b/src/pass/combine_context_call.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * Combine calls into context related function into one. diff --git a/src/pass/coproc_sync.cc b/src/pass/coproc_sync.cc index 13dfef107e87..0afe1ca9935b 100644 --- a/src/pass/coproc_sync.cc +++ b/src/pass/coproc_sync.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file coproc_sync.cc diff --git a/src/pass/detect_device.cc b/src/pass/detect_device.cc index c5fb0dd1b8f3..548f623c25a8 100644 --- a/src/pass/detect_device.cc +++ b/src/pass/detect_device.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file detect_device.cc diff --git a/src/pass/inject_copy_intrin.cc b/src/pass/inject_copy_intrin.cc index 7ca1d133bd2d..a906ee3e5474 100644 --- a/src/pass/inject_copy_intrin.cc +++ b/src/pass/inject_copy_intrin.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief Replace certain copy with copy intrinsics. @@ -39,7 +58,6 @@ class CopyIntrinInjector : public IRMutator { bool MatchCopyPattern(Stmt stmt, Stmt *out) { using namespace arith; Stmt body = stmt; - bool is_single_point_copy = false; // strip the loops std::vector loops; @@ -60,7 +78,6 @@ class CopyIntrinInjector : public IRMutator { const Cast* cast = store->value.as(); const Load* load = store->value.as(); if (0 == loops.size()) { - is_single_point_copy = true; CHECK(!has_cond); } // for now only support true condition matching @@ -83,9 +100,8 @@ class CopyIntrinInjector : public IRMutator { arith::DetectLinearEquation(load->index, loop_vars); if (load_strides.size() == 0 || store_strides.size() == 0) return false; Array dst_shape; - auto loop_var_size = loop_vars.size(); - if (is_single_point_copy) { - loop_var_size = 1; + const size_t loop_var_size = loop_vars.size(); + if (loop_var_size == 0) { dst_shape.push_back(make_const(Int(32), 1)); } else { for (const For* op : loops) { @@ -132,6 +148,10 @@ class CopyIntrinInjector : public IRMutator { CHECK_EQ(load_strides.size(), loop_var_size + 1); Array src_strides(load_strides.begin(), load_strides.begin() + loop_var_size); Array dst_strides(store_strides.begin(), store_strides.begin() + loop_var_size); + if (loop_var_size == 0) { + src_strides.push_back(make_const(Int(32), 1)); + dst_strides.push_back(make_const(Int(32), 1)); + } Buffer dst = BufferNode::make( Var(store->buffer_var.node_), store->value.type(), diff --git a/src/pass/inject_double_buffer.cc b/src/pass/inject_double_buffer.cc index 1384ea1a89ac..94b4ab3cb4c9 100644 --- a/src/pass/inject_double_buffer.cc +++ b/src/pass/inject_double_buffer.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * diff --git a/src/pass/inject_prefetch.cc b/src/pass/inject_prefetch.cc index 2749cb6a2db3..009748e99e34 100644 --- a/src/pass/inject_prefetch.cc +++ b/src/pass/inject_prefetch.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file inject_prefetch.cc diff --git a/src/pass/inject_virtual_thread.cc b/src/pass/inject_virtual_thread.cc index 3fc2e24fb4f1..9009416192e0 100644 --- a/src/pass/inject_virtual_thread.cc +++ b/src/pass/inject_virtual_thread.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file inject_virtual_thread.cc diff --git a/src/pass/inline.cc b/src/pass/inline.cc index 8983147d3e26..f1c5ea4646dc 100644 --- a/src/pass/inline.cc +++ b/src/pass/inline.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file inline.cc diff --git a/src/pass/ir_deep_compare.cc b/src/pass/ir_deep_compare.cc index 2c0168ea5460..d35ea474d5fc 100644 --- a/src/pass/ir_deep_compare.cc +++ b/src/pass/ir_deep_compare.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file ir_deep_compare.cc diff --git a/src/pass/ir_mutator.cc b/src/pass/ir_mutator.cc index e82c4f554be0..a11847a5265a 100644 --- a/src/pass/ir_mutator.cc +++ b/src/pass/ir_mutator.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file ir_mutator.cc diff --git a/src/pass/ir_util.cc b/src/pass/ir_util.cc index 2658d5f3c307..d53b91b33b9f 100644 --- a/src/pass/ir_util.cc +++ b/src/pass/ir_util.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file ir_util.cc diff --git a/src/pass/ir_util.h b/src/pass/ir_util.h index 6af8421398de..29e212cc5af4 100644 --- a/src/pass/ir_util.h +++ b/src/pass/ir_util.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file ir_util.h diff --git a/src/pass/ir_visitor.cc b/src/pass/ir_visitor.cc index 12bad2bd5e86..ec8f840d15f6 100644 --- a/src/pass/ir_visitor.cc +++ b/src/pass/ir_visitor.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file ir_visitor.cc diff --git a/src/pass/lift_attr_scope.cc b/src/pass/lift_attr_scope.cc index d5fd53812b99..13e3a4e1755a 100644 --- a/src/pass/lift_attr_scope.cc +++ b/src/pass/lift_attr_scope.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * diff --git a/src/pass/loop_partition.cc b/src/pass/loop_partition.cc index 5747ca3c6a40..1869b39ff5a9 100644 --- a/src/pass/loop_partition.cc +++ b/src/pass/loop_partition.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file loop_partition.cc diff --git a/src/pass/lower_intrin.cc b/src/pass/lower_intrin.cc index 82eabf09b9e3..9403b71eb935 100644 --- a/src/pass/lower_intrin.cc +++ b/src/pass/lower_intrin.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * Lower intrinsic calls to device specific ir when possible. diff --git a/src/pass/lower_thread_allreduce.cc b/src/pass/lower_thread_allreduce.cc index 2f700ed9112d..d0490b2152a0 100644 --- a/src/pass/lower_thread_allreduce.cc +++ b/src/pass/lower_thread_allreduce.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * Lower allreduce to device implementable ir. @@ -78,7 +97,7 @@ class ThreadAllreduceBuilder final : public IRMutator { Expr Mutate_(const Load* op, const Expr& e) final { auto it = load_remap_.find(op->buffer_var.get()); if (it != load_remap_.end()) { - CHECK(is_zero(op->index)); + CHECK(is_zero(op->index)) << e; return it->second; } else { return IRMutator::Mutate_(op, e); @@ -175,6 +194,9 @@ class ThreadAllreduceBuilder final : public IRMutator { } std::vector seq; std::vector shared_bufs(size); + // This sync is necessary because there might be incomplete read of + // previous iteration on the same buffer. + seq.emplace_back(SyncThread("shared")); for (size_t idx = 0; idx < size; ++idx) { shared_bufs[idx] = Var("red_buf"+std::to_string(idx), Handle()); Expr pred = const_true(types[idx].lanes()); diff --git a/src/pass/lower_tvm_builtin.cc b/src/pass/lower_tvm_builtin.cc index 7820967c4b15..a11e3ceec1c5 100644 --- a/src/pass/lower_tvm_builtin.cc +++ b/src/pass/lower_tvm_builtin.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * Lower TVM related buildin intrinsics such as packed call. diff --git a/src/pass/lower_warp_memory.cc b/src/pass/lower_warp_memory.cc index 01ab2b51752e..2c795ba5dab7 100644 --- a/src/pass/lower_warp_memory.cc +++ b/src/pass/lower_warp_memory.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * diff --git a/src/pass/make_api.cc b/src/pass/make_api.cc index d4f033143d6a..dfb764f535c9 100644 --- a/src/pass/make_api.cc +++ b/src/pass/make_api.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file make_api.cc Build API function. diff --git a/src/pass/narrow_channel_access.cc b/src/pass/narrow_channel_access.cc index 7faf7d1b173e..731064edb012 100644 --- a/src/pass/narrow_channel_access.cc +++ b/src/pass/narrow_channel_access.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file narrow_channel_access.cc diff --git a/src/pass/remap_thread_axis.cc b/src/pass/remap_thread_axis.cc index 08a62b25e2c4..0a155967820d 100644 --- a/src/pass/remap_thread_axis.cc +++ b/src/pass/remap_thread_axis.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file remap_thread_axis.cc diff --git a/src/pass/remove_no_op.cc b/src/pass/remove_no_op.cc index 148be28d4715..c367bd65d78e 100644 --- a/src/pass/remove_no_op.cc +++ b/src/pass/remove_no_op.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file remove_no_op.cc diff --git a/src/pass/rewrite_unsafe_select.cc b/src/pass/rewrite_unsafe_select.cc index 9d8de1755cbd..871efcae615d 100644 --- a/src/pass/rewrite_unsafe_select.cc +++ b/src/pass/rewrite_unsafe_select.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file unsafe_select_rewrite.cc diff --git a/src/pass/simple_passes.cc b/src/pass/simple_passes.cc index a3ca2904b842..853badfd055d 100644 --- a/src/pass/simple_passes.cc +++ b/src/pass/simple_passes.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file simple_passes.cc diff --git a/src/pass/split_host_device.cc b/src/pass/split_host_device.cc index 5e0a2508c218..27d8a310221e 100644 --- a/src/pass/split_host_device.cc +++ b/src/pass/split_host_device.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file split_host_device.cc diff --git a/src/pass/split_pipeline.cc b/src/pass/split_pipeline.cc index c143a0d19153..9d379ac748f4 100644 --- a/src/pass/split_pipeline.cc +++ b/src/pass/split_pipeline.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file split_pipeline.cc diff --git a/src/pass/ssa.cc b/src/pass/ssa.cc index ed12160af01b..f481e3650e84 100644 --- a/src/pass/ssa.cc +++ b/src/pass/ssa.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * SSA related checks and pass. diff --git a/src/pass/storage_access.cc b/src/pass/storage_access.cc index 5894a3aad321..d0f77343ec15 100644 --- a/src/pass/storage_access.cc +++ b/src/pass/storage_access.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file storage_access.cc diff --git a/src/pass/storage_access.h b/src/pass/storage_access.h index 4f313f8e7c24..b84fa59c9d1f 100644 --- a/src/pass/storage_access.h +++ b/src/pass/storage_access.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file storage_access.h diff --git a/src/pass/storage_flatten.cc b/src/pass/storage_flatten.cc index 12913dde95af..215f6d739732 100644 --- a/src/pass/storage_flatten.cc +++ b/src/pass/storage_flatten.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file storage_flatten.cc diff --git a/src/pass/storage_rewrite.cc b/src/pass/storage_rewrite.cc index 3f7fd9512eb2..806a80ad4dc9 100644 --- a/src/pass/storage_rewrite.cc +++ b/src/pass/storage_rewrite.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file storage_rewrite.cc diff --git a/src/pass/storage_sync.cc b/src/pass/storage_sync.cc index 6f7fc886fd8c..c686bc37a02d 100644 --- a/src/pass/storage_sync.cc +++ b/src/pass/storage_sync.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file storage_sync.cc diff --git a/src/pass/unroll_loop.cc b/src/pass/unroll_loop.cc index f1f13cb87fa3..ead234e2c4a0 100644 --- a/src/pass/unroll_loop.cc +++ b/src/pass/unroll_loop.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * Loop unrolling as in Halide pipeline. diff --git a/src/pass/vectorize_loop.cc b/src/pass/vectorize_loop.cc index 282f1eee1399..bd0a91ce4a99 100644 --- a/src/pass/vectorize_loop.cc +++ b/src/pass/vectorize_loop.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file vectorize_loop.cc diff --git a/src/pass/verify_gpu_code.cc b/src/pass/verify_gpu_code.cc index adc0df06e6dd..f1de2906385b 100644 --- a/src/pass/verify_gpu_code.cc +++ b/src/pass/verify_gpu_code.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file verify_gpu_code.cc diff --git a/src/pass/verify_memory.cc b/src/pass/verify_memory.cc index bafaaa642ac7..447691ca0e23 100644 --- a/src/pass/verify_memory.cc +++ b/src/pass/verify_memory.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file verify_memory.cc diff --git a/src/relay/backend/compile_engine.cc b/src/relay/backend/compile_engine.cc index 0c667ced61ff..43515105bd94 100644 --- a/src/relay/backend/compile_engine.cc +++ b/src/relay/backend/compile_engine.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file relay/backend/compile_engine.cc diff --git a/src/relay/backend/compile_engine.h b/src/relay/backend/compile_engine.h index 40b53ab31e5e..391310612d23 100644 --- a/src/relay/backend/compile_engine.h +++ b/src/relay/backend/compile_engine.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file relay/backend/compile_engine.h diff --git a/src/relay/backend/graph_plan_memory.cc b/src/relay/backend/graph_plan_memory.cc index f3126e1753cf..5c2e5c4c289a 100644 --- a/src/relay/backend/graph_plan_memory.cc +++ b/src/relay/backend/graph_plan_memory.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file relay/backend/graph_mem_alloca.cc diff --git a/src/relay/backend/interpreter.cc b/src/relay/backend/interpreter.cc index cf0c6fa91a8b..1d659d8922d9 100644 --- a/src/relay/backend/interpreter.cc +++ b/src/relay/backend/interpreter.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file src/tvm/relay/interpreter.cc diff --git a/src/relay/backend/param_dict.cc b/src/relay/backend/param_dict.cc index af65eaf7f06a..0b9a299ae59b 100644 --- a/src/relay/backend/param_dict.cc +++ b/src/relay/backend/param_dict.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2019 by Contributors * \file param_dict.cc diff --git a/src/relay/backend/param_dict.h b/src/relay/backend/param_dict.h index 0c32d2bf4742..296c71ced644 100644 --- a/src/relay/backend/param_dict.h +++ b/src/relay/backend/param_dict.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2019 by Contributors * \file param_dict.h diff --git a/src/relay/ir/adt.cc b/src/relay/ir/adt.cc index 21d98036fb0d..2e7d854fbd2a 100644 --- a/src/relay/ir/adt.cc +++ b/src/relay/ir/adt.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file src/tvm/ir/adt.cc diff --git a/src/relay/ir/alpha_equal.cc b/src/relay/ir/alpha_equal.cc index aa9336b29153..967034519979 100644 --- a/src/relay/ir/alpha_equal.cc +++ b/src/relay/ir/alpha_equal.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file src/tvm/relay/ir/alpha_equal.cc diff --git a/src/relay/ir/base.cc b/src/relay/ir/base.cc index 4b67909213e1..9c35173bb47a 100644 --- a/src/relay/ir/base.cc +++ b/src/relay/ir/base.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file base.cc diff --git a/src/relay/ir/doc.cc b/src/relay/ir/doc.cc index ef98bd8ed1ed..3b7ffa6139ed 100644 --- a/src/relay/ir/doc.cc +++ b/src/relay/ir/doc.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2019 by Contributors * \file src/tvm/relay/doc.cc diff --git a/src/relay/ir/doc.h b/src/relay/ir/doc.h index b9a82555c479..5a6af8bf9de8 100644 --- a/src/relay/ir/doc.h +++ b/src/relay/ir/doc.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2019 by Contributors * \file tvm/relay/doc.h diff --git a/src/relay/ir/error.cc b/src/relay/ir/error.cc index 24f8d1c49b6b..e0f4bcb9b508 100644 --- a/src/relay/ir/error.cc +++ b/src/relay/ir/error.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file error_reporter.h @@ -91,7 +110,7 @@ void ErrorReporter::RenderErrors(const Module& module, bool use_color) { // // The annotation callback will annotate the error messages // contained in the map. - annotated_prog << RelayPrint(func, false, [&err_map](tvm::relay::Expr expr) { + annotated_prog << AsText(func, false, [&err_map](tvm::relay::Expr expr) { auto it = err_map.find(expr); if (it != err_map.end()) { return it->second; diff --git a/src/relay/ir/expr.cc b/src/relay/ir/expr.cc index 29fe98ba78f5..3108bc2501fe 100644 --- a/src/relay/ir/expr.cc +++ b/src/relay/ir/expr.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file src/tvm/ir/expr.cc diff --git a/src/relay/ir/expr_functor.cc b/src/relay/ir/expr_functor.cc index 8d2163e0ecc8..6df7efe51674 100644 --- a/src/relay/ir/expr_functor.cc +++ b/src/relay/ir/expr_functor.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file src/tvm/relay/expr_mutator.cc diff --git a/src/relay/ir/hash.cc b/src/relay/ir/hash.cc index 5e10906bec84..cb2be8b2c184 100644 --- a/src/relay/ir/hash.cc +++ b/src/relay/ir/hash.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file src/tvm/relay/ir/hash.cc diff --git a/src/relay/ir/module.cc b/src/relay/ir/module.cc index dc7b3074d2ef..38c9756841fc 100644 --- a/src/relay/ir/module.cc +++ b/src/relay/ir/module.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file module.cc diff --git a/src/relay/ir/op.cc b/src/relay/ir/op.cc index bc9955251a7e..4a23f59f9637 100644 --- a/src/relay/ir/op.cc +++ b/src/relay/ir/op.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file src/tvm/relay/op.cc diff --git a/src/relay/ir/pattern_functor.cc b/src/relay/ir/pattern_functor.cc index 6d2e9d296164..29171bfe9f68 100644 --- a/src/relay/ir/pattern_functor.cc +++ b/src/relay/ir/pattern_functor.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file src/tvm/relay/pattern_functor.cc diff --git a/src/relay/ir/pretty_printer.cc b/src/relay/ir/pretty_printer.cc index 40fcee68edc7..67cf9371bc27 100644 --- a/src/relay/ir/pretty_printer.cc +++ b/src/relay/ir/pretty_printer.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2019 by Contributors * \file pretty_printer.cc @@ -690,9 +709,9 @@ std::string PrettyPrint_(const NodeRef& node, return doc.str(); } -std::string RelayPrint(const NodeRef& node, - bool show_meta_data, - runtime::TypedPackedFunc annotate) { +std::string AsText(const NodeRef& node, + bool show_meta_data, + runtime::TypedPackedFunc annotate) { return PrettyPrint_(node, show_meta_data, annotate, true); } @@ -703,10 +722,10 @@ std::string PassDebugPrint(const NodeRef& node, return PrettyPrint_(node, show_meta_data, annotate, gnf); } -TVM_REGISTER_API("relay._expr.RelayPrint") +TVM_REGISTER_API("relay._expr.AsText") .set_body_typed)>(RelayPrint); + runtime::TypedPackedFunc)>(AsText); TVM_REGISTER_API("relay._ir_pass.pass_debug_print") .set_body_typed); +bool DeformableConv2DRel(const Array& types, int num_inputs, const Attrs& attrs, + const TypeReporter& reporter) { + CHECK_EQ(types.size(), 4); + const auto* data = types[0].as(); + const auto* weight = types[2].as(); + + CHECK(data); + auto* param = attrs.as(); + CHECK_EQ(param->data_layout, "NCHW") << "data layout not supported."; + CHECK_EQ(param->kernel_layout, "OIHW") << "kernel_layout not supported."; + + IndexExpr channels, dilated_ksize_y, dilated_ksize_x, ksize_y, ksize_x; + + // infer weight shape if kernel_size and channels are defiend + if (param->kernel_size.defined() && param->channels.defined()) { + CHECK_EQ(param->kernel_size.size(), 2); + CHECK_EQ(param->dilation.size(), 2); + Array wshape( + {param->channels, + data->shape[1] / param->groups, + param->kernel_size[0], + param->kernel_size[1]}); + channels = param->channels; + ksize_y = param->kernel_size[0]; + ksize_x = param->kernel_size[1]; + dilated_ksize_y = 1 + (param->kernel_size[0] - 1) * param->dilation[0]; + dilated_ksize_x = 1 + (param->kernel_size[1] - 1) * param->dilation[1]; + // assign result to reporter + reporter->Assign(types[2], TensorTypeNode::make(wshape, data->dtype)); + } else { + // use weight to infer the conv shape. + if (weight == nullptr) return false; + auto wshape = weight->shape; + if (param->kernel_size.defined()) { + CHECK_EQ(param->kernel_size.size(), 2); + // check the size + CHECK(reporter->AssertEQ(param->kernel_size[0], wshape[2]) && + reporter->AssertEQ(param->kernel_size[1], wshape[3])) + << "DeformableConv2D: shape of weight is inconsistent with kernel_size, " + << " kernel_size=" << param->kernel_size + << " wshape=" << wshape; + } + if (param->channels.defined()) { + CHECK(reporter->AssertEQ(param->channels, wshape[0])) + << "DeformableConv2D: shape of weight is inconsistent with channels, " + << " channels=" << param->channels + << " wshape=" << wshape; + } + CHECK(reporter->AssertEQ(data->shape[1] / param->groups, wshape[1])); + channels = wshape[0]; + ksize_y = wshape[2]; + ksize_x = wshape[3]; + dilated_ksize_y = 1 + (wshape[2] - 1) * param->dilation[0]; + dilated_ksize_x = 1 + (wshape[3] - 1) * param->dilation[1]; + } + // dilation + Array oshape({data->shape[0], channels, 0, 0}); + + oshape.Set(2, (data->shape[2] + param->padding[0] * 2 - dilated_ksize_y) / param->strides[0] + 1); + oshape.Set(3, (data->shape[3] + param->padding[1] * 2 - dilated_ksize_x) / param->strides[1] + 1); + DataType out_dtype = param->out_dtype; + + // infer offset shape + Array offset_shape({data->shape[0], 2 * ksize_y * ksize_x * param->deformable_groups, + oshape[2], oshape[3]}); + reporter->Assign(types[1], TensorTypeNode::make(offset_shape, data->dtype)); + if (out_dtype.bits() == 0) { + out_dtype = data->dtype; + } + + reporter->Assign(types[3], TensorTypeNode::make(oshape, out_dtype)); + return true; +} + + +TVM_REGISTER_NODE_TYPE(DeformableConv2DAttrs); + +RELAY_REGISTER_OP("nn.deformable_conv2d") + .describe(R"code(Compute 2-D deformable convolution on 4-D input. +The deformable convolution operation is described in https://arxiv.org/abs/1703.06211 + +For 2-D deformable convolution, the shapes are +- **data**: (batch_size, channel, height, width) +- **offset**: (batch_size, deformable_groups * kernel[0] * kernel[1] * 2, out_height, out_width) +- **weight**: (num_filter, channel, kernel[0], kernel[1]) +- **out**: (batch_size, num_filter, out_height, out_width). + +If `deformable_groups` is larger than 1, denoted by *dg*, then split the +input `offset` evenly into *dg* parts along the channel axis, and also evenly split `out` +evenly into *dg* parts along the channel axis. Next compute the deformable convolution, apply the +*i*-th part of the offset part on the *i*-th out. + +If `groups` is larger than 1, denoted by *g*, then split the input `data` evenly into *g* parts +along the channel axis, and also evenly split `weight` along the first dimension. Next compute +the convolution on the *i*-th part of the data with the *i*-th weight part. The output is obtained +by concating all the *g* results. +)code" TVM_ADD_FILELINE) +.set_attrs_type_key("relay.attrs.DeformableConv2D") +.set_num_inputs(3) +.add_argument("data", "Tensor", "The input tensor.") +.add_argument("offset", "Tensor", "The offset tensor.") +.add_argument("weight", "Tensor", "The weight tensor.") +.set_support_level(5) +.add_type_rel("DeformableConv2D", DeformableConv2DRel); + +// Positional relay function to create deformable_conv2d operator +// used by frontend FFI. +Expr MakeDeformableConv2D(Expr data, + Expr offset, + Expr weight, + Array strides, + Array padding, + Array dilation, + int deformable_groups, + int groups, + int channels, + Array kernel_size, + std::string data_layout, + std::string kernel_layout, + std::string out_layout, + DataType out_dtype) { + auto attrs = make_node(); + attrs->strides = strides; + attrs->padding = padding; + attrs->dilation = dilation; + attrs->deformable_groups = deformable_groups; + attrs->groups = groups; + attrs->channels = channels; + attrs->kernel_size = kernel_size; + attrs->data_layout = data_layout; + attrs->kernel_layout = kernel_layout; + attrs->out_layout = out_layout; + attrs->out_dtype = out_dtype; + static const Op& op = Op::Get("nn.deformable_conv2d"); + return CallNode::make(op, {data, offset, weight}, Attrs{attrs}, {}); +} + +TVM_REGISTER_API("relay.op.nn._make.deformable_conv2d") +.set_body([](const TVMArgs& args, TVMRetValue* rv) { + runtime::detail::unpack_call(MakeDeformableConv2D, args, rv); + }); + + } // namespace relay } // namespace tvm diff --git a/src/relay/op/nn/nn.cc b/src/relay/op/nn/nn.cc index 59f68d9d8880..d24431347f80 100644 --- a/src/relay/op/nn/nn.cc +++ b/src/relay/op/nn/nn.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file nn.cc diff --git a/src/relay/op/nn/pad.cc b/src/relay/op/nn/pad.cc index 5bab6399151a..c653e3b9f39d 100644 --- a/src/relay/op/nn/pad.cc +++ b/src/relay/op/nn/pad.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file pad.cc diff --git a/src/relay/op/nn/pooling.cc b/src/relay/op/nn/pooling.cc index 23704693732b..0717ee5c577f 100644 --- a/src/relay/op/nn/pooling.cc +++ b/src/relay/op/nn/pooling.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file pooling.cc diff --git a/src/relay/op/nn/upsampling.cc b/src/relay/op/nn/upsampling.cc index 70a20e25b4ea..98458b9dc258 100644 --- a/src/relay/op/nn/upsampling.cc +++ b/src/relay/op/nn/upsampling.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file upsampling.cc diff --git a/src/relay/op/op_common.h b/src/relay/op/op_common.h index 36cd04931903..4a6e845b2f02 100644 --- a/src/relay/op/op_common.h +++ b/src/relay/op/op_common.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file op_common.h diff --git a/src/relay/op/tensor/binary.cc b/src/relay/op/tensor/binary.cc index b8305c44c037..11138aabc9d4 100644 --- a/src/relay/op/tensor/binary.cc +++ b/src/relay/op/tensor/binary.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file binary.cc diff --git a/src/relay/op/tensor/reduce.cc b/src/relay/op/tensor/reduce.cc index 18817e8e4b6d..7bade46b31d4 100644 --- a/src/relay/op/tensor/reduce.cc +++ b/src/relay/op/tensor/reduce.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file reduce.cc diff --git a/src/relay/op/tensor/transform.cc b/src/relay/op/tensor/transform.cc index a0ea8f2e60a3..15eaceb41a2d 100644 --- a/src/relay/op/tensor/transform.cc +++ b/src/relay/op/tensor/transform.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file transform.cc @@ -753,24 +772,26 @@ Array TakeCompute(const Attrs& attrs, const auto* param = attrs.as(); CHECK(param != nullptr); if (!param->axis.defined()) { - return Array{ topi::take(inputs[0], inputs[1]) }; + return Array{ topi::take(inputs[0], inputs[1], param->mode) }; } else { - return Array{ topi::take(inputs[0], inputs[1], param->axis) }; + return Array{ topi::take(inputs[0], inputs[1], param->axis, param->mode) }; } } Expr MakeTake(Expr data, Expr indices, - Integer axis) { + Integer axis, + std::string mode) { auto attrs = make_node(); attrs->axis = std::move(axis); + attrs->mode = std::move(mode); static const Op& op = Op::Get("take"); return CallNode::make(op, {data, indices}, Attrs(attrs), {}); } TVM_REGISTER_API("relay.op._make.take") .set_body([](const TVMArgs& args, TVMRetValue* rv) { - runtime::detail::unpack_call(MakeTake, args, rv); + runtime::detail::unpack_call(MakeTake, args, rv); }); RELAY_REGISTER_OP("take") @@ -2120,5 +2141,75 @@ example below:: .set_attr("FTVMCompute", ReshapeCompute) .set_attr("TOpPattern", kInjective); +// gather_nd operator +bool GatherNDRel(const Array& types, + int num_inputs, + const Attrs& attrs, + const TypeReporter& reporter) { + // `types` contains: [data, indices, result] + CHECK_EQ(types.size(), 3); + const auto* data = types[0].as(); + const auto* indices = types[1].as(); + if (data == nullptr) { + CHECK(types[0].as()) + << "GatherND: expect input data type to be TensorType but get " + << types[0]; + return false; + } + if (indices == nullptr) { + CHECK(types[1].as()) + << "GatherND: expect indices type to be TensorType but get " + << types[1]; + return false; + } + const size_t ndim = data->shape.size(); + const IntImm* mdim = data->shape[0].as(); + const size_t kdim = indices->shape.size() - 1; + CHECK(size_t(mdim->value) <= ndim) + << "GatherND: indices shape does satisfy."; + + Array oshape; + for (size_t i = 1; i < kdim + 1; ++i) + oshape.push_back(indices->shape[i]); + for (size_t i = mdim->value; i < ndim; ++i) + oshape.push_back(data->shape[i]); + reporter->Assign(types[2], TensorTypeNode::make(oshape, data->dtype)); + return true; +} + +Array GatherNDCompute(const Attrs& attrs, + const Array& inputs, + const Type& out_type, + const Target& target) { + return { topi::gather_nd(inputs[0], inputs[1]) }; +} + +Expr MakeGatherND(Expr data, + Expr indices) { + static const Op& op = Op::Get("gather_nd"); + return CallNode::make(op, {data, indices}, {}); +} + +TVM_REGISTER_API("relay.op._make.gather_nd") +.set_body([](const TVMArgs& args, TVMRetValue* rv) { + runtime::detail::unpack_call(MakeGatherND, args, rv); +}); + +RELAY_REGISTER_OP("gather_nd") +.describe(R"code(Gather elements or slices from data and store to + a tensor whose shape is defined by indices. + +Given data with shape (X_0, X_1, ..., X_{N-1}) and indices with +shape (M, Y_0, ..., Y_{K-1}), the output will have shape +(Y_0, ..., Y_{K-1}, X_M, ..., X_{N-1}), where M <= N. If M == N, +output shape will simply be (Y_0, ..., Y_{K-1}). +)code" TVM_ADD_FILELINE) +.set_num_inputs(2) +.add_argument("data", "Tensor", "The input tensor.") +.set_support_level(3) +.add_type_rel("GatherND", GatherNDRel) +.set_attr("FTVMCompute", GatherNDCompute) +.set_attr("TOpPattern", kInjective); + } // namespace relay } // namespace tvm diff --git a/src/relay/op/tensor/unary.cc b/src/relay/op/tensor/unary.cc index 4befc4b664a8..781d99488448 100644 --- a/src/relay/op/tensor/unary.cc +++ b/src/relay/op/tensor/unary.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file unary.cc diff --git a/src/relay/op/type_relations.cc b/src/relay/op/type_relations.cc index 0ae7ab2f9e33..b4cdd98ac88b 100644 --- a/src/relay/op/type_relations.cc +++ b/src/relay/op/type_relations.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file type_relations.cc diff --git a/src/relay/op/type_relations.h b/src/relay/op/type_relations.h index 534e917a0b6c..7e3a4188c398 100644 --- a/src/relay/op/type_relations.h +++ b/src/relay/op/type_relations.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file tvm/relay/op/type_relations.h diff --git a/src/relay/op/vision/multibox_op.cc b/src/relay/op/vision/multibox_op.cc index 04f105c44744..2c9f76ba2015 100644 --- a/src/relay/op/vision/multibox_op.cc +++ b/src/relay/op/vision/multibox_op.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file multibox_op.cc diff --git a/src/relay/op/vision/nms.cc b/src/relay/op/vision/nms.cc index 6a94da032196..75161bfd1e92 100644 --- a/src/relay/op/vision/nms.cc +++ b/src/relay/op/vision/nms.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file nms.cc diff --git a/src/relay/op/vision/rcnn_op.cc b/src/relay/op/vision/rcnn_op.cc index f697133fcf31..70fe292ed9e5 100644 --- a/src/relay/op/vision/rcnn_op.cc +++ b/src/relay/op/vision/rcnn_op.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2019 by Contributors * \file rcnn_op.cc diff --git a/src/relay/op/vision/yolo.cc b/src/relay/op/vision/yolo.cc index b826d4c6e8e2..310e30a51890 100644 --- a/src/relay/op/vision/yolo.cc +++ b/src/relay/op/vision/yolo.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file yolo.cc diff --git a/src/relay/pass/alter_op_layout.cc b/src/relay/pass/alter_op_layout.cc index 30bc5c05a1d2..f51c201d0b2a 100644 --- a/src/relay/pass/alter_op_layout.cc +++ b/src/relay/pass/alter_op_layout.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file alter_op_layout.cc @@ -44,7 +63,7 @@ class TransformMemorizerNode : public Node { public: // map from (Expr, src_layout, dst_layout) to transformed Expr using TransformKey = std::tuple; - struct key_hash : public std::unary_function { +struct key_hash : public std::function { std::size_t operator()(const TransformKey& k) const { return dmlc::HashCombine(dmlc::HashCombine( std::hash()(std::get<0>(k)), std::get<1>(k)), (std::get<2>(k))); diff --git a/src/relay/pass/alter_op_layout.h b/src/relay/pass/alter_op_layout.h index 93d9ee52f687..e5040259a5c4 100644 --- a/src/relay/pass/alter_op_layout.h +++ b/src/relay/pass/alter_op_layout.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file alter_op_layout.h diff --git a/src/relay/pass/canonicalize_ops.cc b/src/relay/pass/canonicalize_ops.cc index 4482dc3954ab..c4350cc0c9db 100644 --- a/src/relay/pass/canonicalize_ops.cc +++ b/src/relay/pass/canonicalize_ops.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file canonicalize_ops.cc @@ -24,7 +43,11 @@ class BiasAddSimplifier : public ExprMutator { auto ttype = n->args[0]->type_as(); size_t n_dim = ttype->shape.size(); - Expr expanded_bias = ExpandBiasToMatchAxis(call->args[1], n_dim, {param->axis}); + int axis = param->axis; + if (axis < 0) { + axis += n_dim; + } + Expr expanded_bias = ExpandBiasToMatchAxis(call->args[1], n_dim, {axis}); Expr ret = Add(call->args[0], expanded_bias); ret->checked_type_ = n->checked_type_; return ret; diff --git a/src/relay/pass/combine_parallel_conv2d.cc b/src/relay/pass/combine_parallel_conv2d.cc index 44b239919ce2..cb53698762ad 100644 --- a/src/relay/pass/combine_parallel_conv2d.cc +++ b/src/relay/pass/combine_parallel_conv2d.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * diff --git a/src/relay/pass/dead_code.cc b/src/relay/pass/dead_code.cc index 0d2677e11c67..a6324560d2d3 100644 --- a/src/relay/pass/dead_code.cc +++ b/src/relay/pass/dead_code.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * diff --git a/src/relay/pass/device_annotation.cc b/src/relay/pass/device_annotation.cc index 3833dff23beb..6f063830cbe9 100644 --- a/src/relay/pass/device_annotation.cc +++ b/src/relay/pass/device_annotation.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * diff --git a/src/relay/pass/eliminate_common_subexpr.cc b/src/relay/pass/eliminate_common_subexpr.cc index 10e6f920f245..f8432f671855 100644 --- a/src/relay/pass/eliminate_common_subexpr.cc +++ b/src/relay/pass/eliminate_common_subexpr.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2019 by Contributors * diff --git a/src/relay/pass/expr_subst.cc b/src/relay/pass/expr_subst.cc index 67dc0d2f7049..0d5e4238f60e 100644 --- a/src/relay/pass/expr_subst.cc +++ b/src/relay/pass/expr_subst.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file expr_subst.h diff --git a/src/relay/pass/expr_subst.h b/src/relay/pass/expr_subst.h index 67892b3a0af7..c83575e942d9 100644 --- a/src/relay/pass/expr_subst.h +++ b/src/relay/pass/expr_subst.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file expr_subst.h diff --git a/src/relay/pass/fold_constant.cc b/src/relay/pass/fold_constant.cc index f4dd067e2eb1..9d55a548be10 100644 --- a/src/relay/pass/fold_constant.cc +++ b/src/relay/pass/fold_constant.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file constant_folding.cc diff --git a/src/relay/pass/fold_scale_axis.cc b/src/relay/pass/fold_scale_axis.cc index 044cc4e5d9c9..c738e3e3b731 100644 --- a/src/relay/pass/fold_scale_axis.cc +++ b/src/relay/pass/fold_scale_axis.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * diff --git a/src/relay/pass/forward_rewrite.cc b/src/relay/pass/forward_rewrite.cc index 4f33d4a053b7..88a2d669da9f 100644 --- a/src/relay/pass/forward_rewrite.cc +++ b/src/relay/pass/forward_rewrite.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * diff --git a/src/relay/pass/fuse_ops.cc b/src/relay/pass/fuse_ops.cc index 66ff9caf4ae4..4b50c64459a0 100644 --- a/src/relay/pass/fuse_ops.cc +++ b/src/relay/pass/fuse_ops.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * @@ -261,9 +280,28 @@ class IndexedForwardGraph::Creator : private ExprVisitor { } void VisitExpr_(const TupleGetItemNode* op) final { - CHECK(graph_.node_map.count(op)); - Node* node = graph_.node_map.at(op); - this->Update(op->tuple, node, kOpaque); + auto tuple_type = op->tuple->checked_type().as(); + CHECK(tuple_type); + // when TVM lowers a fused function, it expects all arguments to be a Tensor or + // a tuple containing only Tensors. But this tuple may contain a reference or + // another tuple. To avoid modifying codegen logic, we do not allow fusing through this node + // if the tuple contains such non Tensor fields. However, all fields will be recursively + // visited via call to ExprVisitor::VisitExpr_(op) below and corresponding visitor methods. + bool has_non_tensor = false; + for (auto ty : tuple_type->fields) { + if (!ty.as()) { + has_non_tensor = true; + break; + } + } + if (has_non_tensor) { + this->Update(op->tuple, nullptr, kOpaque); + } else { + CHECK(graph_.node_map.count(op)); + Node* node = graph_.node_map.at(op); + node->pattern = kInjective; + this->Update(op->tuple, node, kInjective); + } ExprVisitor::VisitExpr_(op); this->AddNode(op); } @@ -809,6 +847,23 @@ class FuseMutator : private ExprMutator { return TupleNode::make(new_fields); } + Expr VisitExpr_(const TupleGetItemNode* tuple_get) { + auto* ret_group = gmap_.at(tuple_get)->FindRoot(); + auto new_tuple = GetNewArguments({tuple_get->tuple}, ret_group)[0]; + auto new_node = TupleGetItemNode::make(new_tuple, tuple_get->index); + if (ret_group == gmap_.at(tuple_get)) { + if (gmap_.at(tuple_get->tuple.get())->FindRoot() != ret_group) { + // Isolated. This case occurs when tuple is created by an Opaque op + // e.g. multibox_transform_loc + return ExprMutator::VisitExpr_(tuple_get); + } + // A new function whose output is a tuple field access + return MakeNewFunction(ret_group, tuple_get->checked_type(), new_node); + } + // This is an intermediate node in the group + return new_node; + } + Expr MakeNewFunction(GraphPartitioner::Group* group, Type ret_type, Expr body) { const GroupInfo& ginfo = ginfo_[group]; auto func = FunctionNode::make(ginfo.params, body, ret_type, {}); @@ -835,7 +890,7 @@ class FuseMutator : private ExprMutator { // Debug function, dump the group assignment in text. void DebugDumpGroup(const Expr& body) { - std::string text = RelayPrint(body, false, [this](const Expr& expr) -> std::string { + std::string text = AsText(body, false, [this](const Expr& expr) -> std::string { auto it = gmap_.find(expr.get()); if (it == gmap_.end()) return ""; std::ostringstream os; diff --git a/src/relay/pass/gradient.cc b/src/relay/pass/gradient.cc index d564e02b5596..8a5d1df53a26 100644 --- a/src/relay/pass/gradient.cc +++ b/src/relay/pass/gradient.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file ad.cc diff --git a/src/relay/pass/kind_check.cc b/src/relay/pass/kind_check.cc index f1e539d71d48..0b96ce50658a 100644 --- a/src/relay/pass/kind_check.cc +++ b/src/relay/pass/kind_check.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * @@ -144,7 +163,7 @@ struct KindChecker : TypeFunctor { for (const auto& con : op->constructors) { if (!con->belong_to.same_as(op->header)) { ReportFatalError(RELAY_ERROR(con << " has header " << con->belong_to - << " but " << op << "has header " << op->header)); + << " but " << op << " has header " << op->header)); } for (const Type& t : con->inputs) { diff --git a/src/relay/pass/let_list.h b/src/relay/pass/let_list.h index 3afbcba96ae6..293f88979886 100644 --- a/src/relay/pass/let_list.h +++ b/src/relay/pass/let_list.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file let_list.h diff --git a/src/relay/pass/mac_count.cc b/src/relay/pass/mac_count.cc index e801cdc37d12..702e703cd902 100644 --- a/src/relay/pass/mac_count.cc +++ b/src/relay/pass/mac_count.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2019 by Contributors * diff --git a/src/relay/pass/pass_manager.cc b/src/relay/pass/pass_manager.cc index 078cdce982f5..fad3728d433e 100644 --- a/src/relay/pass/pass_manager.cc +++ b/src/relay/pass/pass_manager.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2019 by Contributors * \file src/relay/pass/pass_manager.cc diff --git a/src/relay/pass/pass_util.h b/src/relay/pass/pass_util.h index 888919354c98..df3294151ff0 100644 --- a/src/relay/pass/pass_util.h +++ b/src/relay/pass/pass_util.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors. * diff --git a/src/relay/pass/pattern_util.h b/src/relay/pass/pattern_util.h index 96038745474e..22307d12303e 100644 --- a/src/relay/pass/pattern_util.h +++ b/src/relay/pass/pattern_util.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors. * diff --git a/src/relay/pass/quantize.cc b/src/relay/pass/quantize.cc index cb02b7f6654d..cb0f9d9c5acb 100644 --- a/src/relay/pass/quantize.cc +++ b/src/relay/pass/quantize.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * diff --git a/src/relay/pass/quantize.h b/src/relay/pass/quantize.h index ed0a8b10a574..4d26dd6be4a5 100644 --- a/src/relay/pass/quantize.h +++ b/src/relay/pass/quantize.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors. * diff --git a/src/relay/pass/simplify_inference.cc b/src/relay/pass/simplify_inference.cc index 6acf4e65b1ac..28ebaaa75546 100644 --- a/src/relay/pass/simplify_inference.cc +++ b/src/relay/pass/simplify_inference.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file simplify_inference.cc diff --git a/src/relay/pass/to_a_normal_form.cc b/src/relay/pass/to_a_normal_form.cc index 46a4b92ac9b9..60fd6dbbaf1a 100644 --- a/src/relay/pass/to_a_normal_form.cc +++ b/src/relay/pass/to_a_normal_form.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * diff --git a/src/relay/pass/to_graph_normal_form.cc b/src/relay/pass/to_graph_normal_form.cc index bc1630263e3f..cc7e1a43068e 100644 --- a/src/relay/pass/to_graph_normal_form.cc +++ b/src/relay/pass/to_graph_normal_form.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * diff --git a/src/relay/pass/type_infer.cc b/src/relay/pass/type_infer.cc index ea6b9a95da50..5abf0b74ab68 100644 --- a/src/relay/pass/type_infer.cc +++ b/src/relay/pass/type_infer.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file type_infer.cc diff --git a/src/relay/pass/type_solver.cc b/src/relay/pass/type_solver.cc index a9a7949cd7f4..2ce441069aa9 100644 --- a/src/relay/pass/type_solver.cc +++ b/src/relay/pass/type_solver.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file type_solver.cc diff --git a/src/relay/pass/type_solver.h b/src/relay/pass/type_solver.h index 9f21799175fc..8b24e8605f5f 100644 --- a/src/relay/pass/type_solver.h +++ b/src/relay/pass/type_solver.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file type_solver.h diff --git a/src/relay/pass/util.cc b/src/relay/pass/util.cc index 76fc0aa1a45e..3080b5d72e30 100644 --- a/src/relay/pass/util.cc +++ b/src/relay/pass/util.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * diff --git a/src/relay/pass/well_formed.cc b/src/relay/pass/well_formed.cc index 159e073673da..86107d66e52f 100644 --- a/src/relay/pass/well_formed.cc +++ b/src/relay/pass/well_formed.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file well_formed.cc diff --git a/src/runtime/builtin_fp16.cc b/src/runtime/builtin_fp16.cc index eca4814b6114..2fb233ce6688 100644 --- a/src/runtime/builtin_fp16.cc +++ b/src/runtime/builtin_fp16.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file builtin_fp16.cc diff --git a/src/runtime/c_dsl_api.cc b/src/runtime/c_dsl_api.cc index ae39a1266d06..e45c89a0e9b3 100644 --- a/src/runtime/c_dsl_api.cc +++ b/src/runtime/c_dsl_api.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file cpu_dsl_api.cc diff --git a/src/runtime/c_runtime_api.cc b/src/runtime/c_runtime_api.cc index 3d74391a9ea5..59cdb7f0a467 100644 --- a/src/runtime/c_runtime_api.cc +++ b/src/runtime/c_runtime_api.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file c_runtime_api.cc diff --git a/src/runtime/cpu_device_api.cc b/src/runtime/cpu_device_api.cc index 6bd7022fd9f6..320e59580c36 100644 --- a/src/runtime/cpu_device_api.cc +++ b/src/runtime/cpu_device_api.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file cpu_device_api.cc diff --git a/src/runtime/cuda/cuda_common.h b/src/runtime/cuda/cuda_common.h index 782fbc5d87e6..fa85892b9740 100644 --- a/src/runtime/cuda/cuda_common.h +++ b/src/runtime/cuda/cuda_common.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file cuda_common.h diff --git a/src/runtime/cuda/cuda_device_api.cc b/src/runtime/cuda/cuda_device_api.cc index 8309b45a7963..f812156f1999 100644 --- a/src/runtime/cuda/cuda_device_api.cc +++ b/src/runtime/cuda/cuda_device_api.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file cuda_device_api.cc diff --git a/src/runtime/cuda/cuda_module.cc b/src/runtime/cuda/cuda_module.cc index 2b55ab922208..a46f0ebfdbdc 100644 --- a/src/runtime/cuda/cuda_module.cc +++ b/src/runtime/cuda/cuda_module.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file cuda_module.cc diff --git a/src/runtime/cuda/cuda_module.h b/src/runtime/cuda/cuda_module.h index e2a182d430d1..54ff38da6f33 100644 --- a/src/runtime/cuda/cuda_module.h +++ b/src/runtime/cuda/cuda_module.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file cuda_module.h diff --git a/src/runtime/dsl_api.h b/src/runtime/dsl_api.h index 3e1299bd8c96..6e79e250c56d 100644 --- a/src/runtime/dsl_api.h +++ b/src/runtime/dsl_api.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file cpu_dsl_api.cc diff --git a/src/runtime/dso_module.cc b/src/runtime/dso_module.cc index fe7c362472d1..4f69f2692d72 100644 --- a/src/runtime/dso_module.cc +++ b/src/runtime/dso_module.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file dso_dll_module.cc diff --git a/src/runtime/file_util.cc b/src/runtime/file_util.cc index a9ef8c0aa7d7..189bd0cbc3aa 100644 --- a/src/runtime/file_util.cc +++ b/src/runtime/file_util.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file file_util.cc diff --git a/src/runtime/file_util.h b/src/runtime/file_util.h index 3198f439adc4..d7038bdd3281 100644 --- a/src/runtime/file_util.h +++ b/src/runtime/file_util.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file file_util.h diff --git a/src/runtime/graph/debug/graph_runtime_debug.cc b/src/runtime/graph/debug/graph_runtime_debug.cc index 71a869e13ae6..23bb3109bf4f 100644 --- a/src/runtime/graph/debug/graph_runtime_debug.cc +++ b/src/runtime/graph/debug/graph_runtime_debug.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file graph_runtime_debug.cc diff --git a/src/runtime/graph/graph_runtime.cc b/src/runtime/graph/graph_runtime.cc index f8503b9077df..21bcbee88295 100644 --- a/src/runtime/graph/graph_runtime.cc +++ b/src/runtime/graph/graph_runtime.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file graph_runtime.cc diff --git a/src/runtime/graph/graph_runtime.h b/src/runtime/graph/graph_runtime.h index 8c454d7e3efe..0bbdf37b7d42 100644 --- a/src/runtime/graph/graph_runtime.h +++ b/src/runtime/graph/graph_runtime.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * diff --git a/src/runtime/meta_data.h b/src/runtime/meta_data.h index 40d08015e8cd..e5611e77b6a5 100644 --- a/src/runtime/meta_data.h +++ b/src/runtime/meta_data.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file meta_data.h diff --git a/src/runtime/metal/metal_common.h b/src/runtime/metal/metal_common.h index e1f381fa28fd..9f012b81f662 100644 --- a/src/runtime/metal/metal_common.h +++ b/src/runtime/metal/metal_common.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file metal_common.h diff --git a/src/runtime/metal/metal_device_api.mm b/src/runtime/metal/metal_device_api.mm index fcdbf13138a8..e38329add367 100644 --- a/src/runtime/metal/metal_device_api.mm +++ b/src/runtime/metal/metal_device_api.mm @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file metal_device_api.mm diff --git a/src/runtime/metal/metal_module.h b/src/runtime/metal/metal_module.h index d4f89875c38d..1e4bb6ee4f3f 100644 --- a/src/runtime/metal/metal_module.h +++ b/src/runtime/metal/metal_module.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file metal_module.h diff --git a/src/runtime/metal/metal_module.mm b/src/runtime/metal/metal_module.mm index cf470b6c8a34..e1f0e3fd534b 100644 --- a/src/runtime/metal/metal_module.mm +++ b/src/runtime/metal/metal_module.mm @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file metal_module.cc diff --git a/src/runtime/module.cc b/src/runtime/module.cc index 96b00380f19a..34f3dc9f8f83 100644 --- a/src/runtime/module.cc +++ b/src/runtime/module.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file module.cc diff --git a/src/runtime/module_util.cc b/src/runtime/module_util.cc index 2088efa93d18..456d28278abc 100644 --- a/src/runtime/module_util.cc +++ b/src/runtime/module_util.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file module_util.cc diff --git a/src/runtime/module_util.h b/src/runtime/module_util.h index 33717831b404..e5bbfe32766a 100644 --- a/src/runtime/module_util.h +++ b/src/runtime/module_util.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file module_util.h diff --git a/src/runtime/ndarray.cc b/src/runtime/ndarray.cc index 0ffa4c174544..39c17b8b3a81 100644 --- a/src/runtime/ndarray.cc +++ b/src/runtime/ndarray.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file ndarray.cc diff --git a/src/runtime/opencl/aocl/aocl_common.h b/src/runtime/opencl/aocl/aocl_common.h index 4561e60490c0..48a6b8eac0a1 100644 --- a/src/runtime/opencl/aocl/aocl_common.h +++ b/src/runtime/opencl/aocl/aocl_common.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file aocl_common.h diff --git a/src/runtime/opencl/aocl/aocl_device_api.cc b/src/runtime/opencl/aocl/aocl_device_api.cc index 61f636df6039..2442c4d2f1e3 100644 --- a/src/runtime/opencl/aocl/aocl_device_api.cc +++ b/src/runtime/opencl/aocl/aocl_device_api.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file aocl_device_api.cc diff --git a/src/runtime/opencl/aocl/aocl_module.cc b/src/runtime/opencl/aocl/aocl_module.cc index bbf2828fbd79..38e82edfe296 100644 --- a/src/runtime/opencl/aocl/aocl_module.cc +++ b/src/runtime/opencl/aocl/aocl_module.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file aocl_module.cc diff --git a/src/runtime/opencl/aocl/aocl_module.h b/src/runtime/opencl/aocl/aocl_module.h index bdb390379e9d..2e8322f75943 100644 --- a/src/runtime/opencl/aocl/aocl_module.h +++ b/src/runtime/opencl/aocl/aocl_module.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file aocl_module.h diff --git a/src/runtime/opencl/opencl_common.h b/src/runtime/opencl/opencl_common.h index 6e8472830296..ab84eef9d764 100644 --- a/src/runtime/opencl/opencl_common.h +++ b/src/runtime/opencl/opencl_common.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file opencl_common.h @@ -11,6 +30,16 @@ #include #include +/* There are many OpenCL platforms that do not yet support OpenCL 2.0, + * hence we use 1.2 APIs, some of which are now deprecated. In order + * to turn off the deprecation warnings (elevated to errors by + * -Werror) we explicitly disable the 1.2 deprecation warnings. + * + * At the point TVM supports minimum version 2.0, we can remove this + * define. + */ +#define CL_USE_DEPRECATED_OPENCL_1_2_APIS + #ifdef __APPLE__ #include #else diff --git a/src/runtime/opencl/opencl_device_api.cc b/src/runtime/opencl/opencl_device_api.cc index a5ad66b2def4..1e6af53f3860 100644 --- a/src/runtime/opencl/opencl_device_api.cc +++ b/src/runtime/opencl/opencl_device_api.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file opencl_device_api.cc diff --git a/src/runtime/opencl/opencl_module.cc b/src/runtime/opencl/opencl_module.cc index ed5c3c235ac1..543ffb9825b1 100644 --- a/src/runtime/opencl/opencl_module.cc +++ b/src/runtime/opencl/opencl_module.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file opencl_module.cc diff --git a/src/runtime/opencl/opencl_module.h b/src/runtime/opencl/opencl_module.h index 914c51f2714d..cd63382d8851 100644 --- a/src/runtime/opencl/opencl_module.h +++ b/src/runtime/opencl/opencl_module.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file opencl_module.h diff --git a/src/runtime/opencl/sdaccel/sdaccel_common.h b/src/runtime/opencl/sdaccel/sdaccel_common.h index 90578cf3aa2d..cf6d681c133b 100644 --- a/src/runtime/opencl/sdaccel/sdaccel_common.h +++ b/src/runtime/opencl/sdaccel/sdaccel_common.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file sdaccel_common.h diff --git a/src/runtime/opencl/sdaccel/sdaccel_device_api.cc b/src/runtime/opencl/sdaccel/sdaccel_device_api.cc index bc98759b9b3f..ffd6ff56ea6d 100644 --- a/src/runtime/opencl/sdaccel/sdaccel_device_api.cc +++ b/src/runtime/opencl/sdaccel/sdaccel_device_api.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file sdaccel_device_api.cc diff --git a/src/runtime/opencl/sdaccel/sdaccel_module.cc b/src/runtime/opencl/sdaccel/sdaccel_module.cc index de9a710fbfe8..9bfc9d2b2705 100644 --- a/src/runtime/opencl/sdaccel/sdaccel_module.cc +++ b/src/runtime/opencl/sdaccel/sdaccel_module.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file sdaccel_module.cc diff --git a/src/runtime/opencl/sdaccel/sdaccel_module.h b/src/runtime/opencl/sdaccel/sdaccel_module.h index ba2563aa3c76..2b54a07b9def 100644 --- a/src/runtime/opencl/sdaccel/sdaccel_module.h +++ b/src/runtime/opencl/sdaccel/sdaccel_module.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file sdaccel_module.h diff --git a/src/runtime/opengl/opengl_common.h b/src/runtime/opengl/opengl_common.h index 3d62d8faf252..0e6a322b0c8c 100644 --- a/src/runtime/opengl/opengl_common.h +++ b/src/runtime/opengl/opengl_common.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file opengl_common.h diff --git a/src/runtime/opengl/opengl_device_api.cc b/src/runtime/opengl/opengl_device_api.cc index 191b64b6ce0a..db065522c607 100644 --- a/src/runtime/opengl/opengl_device_api.cc +++ b/src/runtime/opengl/opengl_device_api.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file opengl_device_api.cc diff --git a/src/runtime/opengl/opengl_module.cc b/src/runtime/opengl/opengl_module.cc index af4add33f7a9..9a1f77430c11 100644 --- a/src/runtime/opengl/opengl_module.cc +++ b/src/runtime/opengl/opengl_module.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file opengl_module.cc diff --git a/src/runtime/opengl/opengl_module.h b/src/runtime/opengl/opengl_module.h index 6e3379da4509..b4459ae5a952 100644 --- a/src/runtime/opengl/opengl_module.h +++ b/src/runtime/opengl/opengl_module.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file opengl_module.h diff --git a/src/runtime/pack_args.h b/src/runtime/pack_args.h index 5170e5fd9e9a..3af44c0a54fe 100644 --- a/src/runtime/pack_args.h +++ b/src/runtime/pack_args.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file pack_args.h diff --git a/src/runtime/registry.cc b/src/runtime/registry.cc index 3c792fdb9063..913a618a3f63 100644 --- a/src/runtime/registry.cc +++ b/src/runtime/registry.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file registry.cc diff --git a/src/runtime/rocm/rocm_common.h b/src/runtime/rocm/rocm_common.h index a6898122e389..bfa485dcf0f6 100644 --- a/src/runtime/rocm/rocm_common.h +++ b/src/runtime/rocm/rocm_common.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file rocm_common.h diff --git a/src/runtime/rocm/rocm_device_api.cc b/src/runtime/rocm/rocm_device_api.cc index 355200a0cbb0..cff72f58f69a 100644 --- a/src/runtime/rocm/rocm_device_api.cc +++ b/src/runtime/rocm/rocm_device_api.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file rocm_device_api.cc diff --git a/src/runtime/rocm/rocm_module.cc b/src/runtime/rocm/rocm_module.cc index 290ae756331e..b7b93c7c4dfd 100644 --- a/src/runtime/rocm/rocm_module.cc +++ b/src/runtime/rocm/rocm_module.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file rocm_module.cc diff --git a/src/runtime/rocm/rocm_module.h b/src/runtime/rocm/rocm_module.h index dc2a964049dc..87940cf3c3e4 100644 --- a/src/runtime/rocm/rocm_module.h +++ b/src/runtime/rocm/rocm_module.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file rocm_module.h diff --git a/src/runtime/rpc/rpc_device_api.cc b/src/runtime/rpc/rpc_device_api.cc index 4242f8e1ae58..a69054a7fa60 100644 --- a/src/runtime/rpc/rpc_device_api.cc +++ b/src/runtime/rpc/rpc_device_api.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file rpc_device_api.cc diff --git a/src/runtime/rpc/rpc_event_impl.cc b/src/runtime/rpc/rpc_event_impl.cc index e553c6fad4a0..dfbdb2699d39 100644 --- a/src/runtime/rpc/rpc_event_impl.cc +++ b/src/runtime/rpc/rpc_event_impl.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file rpc_event_impl.cc diff --git a/src/runtime/rpc/rpc_module.cc b/src/runtime/rpc/rpc_module.cc index d5528617477f..2e1e64a73283 100644 --- a/src/runtime/rpc/rpc_module.cc +++ b/src/runtime/rpc/rpc_module.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file rpc_device_api.cc diff --git a/src/runtime/rpc/rpc_server_env.cc b/src/runtime/rpc/rpc_server_env.cc index 4d8486e31f34..d9002a9c1066 100644 --- a/src/runtime/rpc/rpc_server_env.cc +++ b/src/runtime/rpc/rpc_server_env.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file rpc_server_env.cc diff --git a/src/runtime/rpc/rpc_session.cc b/src/runtime/rpc/rpc_session.cc index 47701fd3f60d..f235ec8e8f0c 100644 --- a/src/runtime/rpc/rpc_session.cc +++ b/src/runtime/rpc/rpc_session.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file rpc_session.cc diff --git a/src/runtime/rpc/rpc_session.h b/src/runtime/rpc/rpc_session.h index d8ca1755aa9c..bc0bc8fe5918 100644 --- a/src/runtime/rpc/rpc_session.h +++ b/src/runtime/rpc/rpc_session.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file rpc_session.h diff --git a/src/runtime/rpc/rpc_socket_impl.cc b/src/runtime/rpc/rpc_socket_impl.cc index bf8bce9d0f7d..33d852f5a575 100644 --- a/src/runtime/rpc/rpc_socket_impl.cc +++ b/src/runtime/rpc/rpc_socket_impl.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file rpc_socket_impl.cc diff --git a/src/runtime/runtime_base.h b/src/runtime/runtime_base.h index 459538796e6a..e1b6c9141349 100644 --- a/src/runtime/runtime_base.h +++ b/src/runtime/runtime_base.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file runtime_base.h diff --git a/src/runtime/sgx/common.h b/src/runtime/sgx/common.h index a375bcd21dd2..43e295f2b388 100644 --- a/src/runtime/sgx/common.h +++ b/src/runtime/sgx/common.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file common.h diff --git a/src/runtime/sgx/trusted/ecall_registry.h b/src/runtime/sgx/trusted/ecall_registry.h index 4bc476aaef61..b4f3d604a872 100644 --- a/src/runtime/sgx/trusted/ecall_registry.h +++ b/src/runtime/sgx/trusted/ecall_registry.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file ecall_registry.h diff --git a/src/runtime/sgx/trusted/runtime.cc b/src/runtime/sgx/trusted/runtime.cc index b7f66efbc97c..f4d1e5765539 100644 --- a/src/runtime/sgx/trusted/runtime.cc +++ b/src/runtime/sgx/trusted/runtime.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file runtime_t.cc diff --git a/src/runtime/sgx/trusted/runtime.h b/src/runtime/sgx/trusted/runtime.h index 8a00c3e57072..1ba9eb7351b6 100644 --- a/src/runtime/sgx/trusted/runtime.h +++ b/src/runtime/sgx/trusted/runtime.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file trusted/runtime.h diff --git a/src/runtime/sgx/trusted/threading_backend.cc b/src/runtime/sgx/trusted/threading_backend.cc index fd9112c20228..f48759439d75 100644 --- a/src/runtime/sgx/trusted/threading_backend.cc +++ b/src/runtime/sgx/trusted/threading_backend.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file sgx/threading_backend.cc diff --git a/src/runtime/sgx/untrusted/sgx_module.cc b/src/runtime/sgx/untrusted/sgx_module.cc index fc0710ae3a53..b6aa48c0dcc9 100644 --- a/src/runtime/sgx/untrusted/sgx_module.cc +++ b/src/runtime/sgx/untrusted/sgx_module.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file sgx_module.cc diff --git a/src/runtime/stackvm/stackvm.cc b/src/runtime/stackvm/stackvm.cc index 131c60704dc5..fe6913e6478d 100644 --- a/src/runtime/stackvm/stackvm.cc +++ b/src/runtime/stackvm/stackvm.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * Implementation stack VM. diff --git a/src/runtime/stackvm/stackvm.h b/src/runtime/stackvm/stackvm.h index 87c4582f6bc8..82e06847fd1e 100644 --- a/src/runtime/stackvm/stackvm.h +++ b/src/runtime/stackvm/stackvm.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file stackvm.h diff --git a/src/runtime/stackvm/stackvm_module.cc b/src/runtime/stackvm/stackvm_module.cc index 20e7c5b604c8..5e6f96be50df 100644 --- a/src/runtime/stackvm/stackvm_module.cc +++ b/src/runtime/stackvm/stackvm_module.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file stackvm_module.cc diff --git a/src/runtime/stackvm/stackvm_module.h b/src/runtime/stackvm/stackvm_module.h index 34bda0ae59c2..241575e6d680 100644 --- a/src/runtime/stackvm/stackvm_module.h +++ b/src/runtime/stackvm/stackvm_module.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file stackvm_module.h diff --git a/src/runtime/system_lib_module.cc b/src/runtime/system_lib_module.cc index ed48cb1a9d44..247fae110747 100644 --- a/src/runtime/system_lib_module.cc +++ b/src/runtime/system_lib_module.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file system_lib_module.cc diff --git a/src/runtime/thread_pool.cc b/src/runtime/thread_pool.cc index e10738ab8bbe..c1d97f02e61a 100644 --- a/src/runtime/thread_pool.cc +++ b/src/runtime/thread_pool.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file thread_pool.cc diff --git a/src/runtime/thread_storage_scope.h b/src/runtime/thread_storage_scope.h index 81570b9aa77c..0934e46d4e21 100644 --- a/src/runtime/thread_storage_scope.h +++ b/src/runtime/thread_storage_scope.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file thread_storage_scope.h diff --git a/src/runtime/threading_backend.cc b/src/runtime/threading_backend.cc index e9f13d03ba16..ae98dfba18cc 100644 --- a/src/runtime/threading_backend.cc +++ b/src/runtime/threading_backend.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file threading_backend.cc diff --git a/src/runtime/vulkan/vulkan_common.h b/src/runtime/vulkan/vulkan_common.h index f869f3a2e67a..ad6100eb7499 100644 --- a/src/runtime/vulkan/vulkan_common.h +++ b/src/runtime/vulkan/vulkan_common.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file vulkan_common.h diff --git a/src/runtime/vulkan/vulkan_device_api.cc b/src/runtime/vulkan/vulkan_device_api.cc index cc89804806d2..7ebe278f3032 100644 --- a/src/runtime/vulkan/vulkan_device_api.cc +++ b/src/runtime/vulkan/vulkan_device_api.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file vulkan_device_api.cc diff --git a/src/runtime/vulkan/vulkan_module.cc b/src/runtime/vulkan/vulkan_module.cc index 4afe8cc782ce..cfa80bef151f 100644 --- a/src/runtime/vulkan/vulkan_module.cc +++ b/src/runtime/vulkan/vulkan_module.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file vulkan_module.cc diff --git a/src/runtime/vulkan/vulkan_module.h b/src/runtime/vulkan/vulkan_module.h index 41dcfd310dca..13e5ce6e8ef1 100644 --- a/src/runtime/vulkan/vulkan_module.h +++ b/src/runtime/vulkan/vulkan_module.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file metal_module.h diff --git a/src/runtime/workspace_pool.cc b/src/runtime/workspace_pool.cc index b3f616c3e55f..57ce12dfcf8f 100644 --- a/src/runtime/workspace_pool.cc +++ b/src/runtime/workspace_pool.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file workspace_pool.h diff --git a/src/runtime/workspace_pool.h b/src/runtime/workspace_pool.h index 3626e854b5cd..163612638f72 100644 --- a/src/runtime/workspace_pool.h +++ b/src/runtime/workspace_pool.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file workspace_pool.h diff --git a/src/schedule/auto_inline_elem_wise.cc b/src/schedule/auto_inline_elem_wise.cc index 1dc1ebbd9959..6725ab0b1cc7 100644 --- a/src/schedule/auto_inline_elem_wise.cc +++ b/src/schedule/auto_inline_elem_wise.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file auto_inline_elem_wise.cc diff --git a/src/schedule/bound.cc b/src/schedule/bound.cc index 05c04834e78c..1ff2c9fb6c79 100644 --- a/src/schedule/bound.cc +++ b/src/schedule/bound.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file bound.cc diff --git a/src/schedule/graph.cc b/src/schedule/graph.cc index 98b37140b9d1..09aaaf7ad14d 100644 --- a/src/schedule/graph.cc +++ b/src/schedule/graph.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file graph.cc diff --git a/src/schedule/graph.h b/src/schedule/graph.h index 50d35355cc64..cfbb59f0912f 100644 --- a/src/schedule/graph.h +++ b/src/schedule/graph.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file graph.h diff --git a/src/schedule/message_passing.cc b/src/schedule/message_passing.cc index 44614234bd55..ab91944d05a2 100644 --- a/src/schedule/message_passing.cc +++ b/src/schedule/message_passing.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file message_passing.cc diff --git a/src/schedule/message_passing.h b/src/schedule/message_passing.h index baf4a2415da3..3f0aff255c54 100644 --- a/src/schedule/message_passing.h +++ b/src/schedule/message_passing.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file message_passing.h diff --git a/src/schedule/schedule_dataflow_rewrite.cc b/src/schedule/schedule_dataflow_rewrite.cc index 774c623a5df2..cbb5ae3df0d6 100644 --- a/src/schedule/schedule_dataflow_rewrite.cc +++ b/src/schedule/schedule_dataflow_rewrite.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file schedule_dataflow_rewrite.cc @@ -603,8 +622,8 @@ void InjectInline(ScheduleNode* sch) { if (!op.same_as(s->op)) { for (int idx = 0; idx < s->op->num_outputs(); ++idx) { repl[s->op.output(idx)] = op.output(idx); - s->op = op; } + s->op = op; } } else { Operation op = s->op->ReplaceInputs(s->op, repl); diff --git a/src/schedule/schedule_lang.cc b/src/schedule/schedule_lang.cc index bd703a211206..ffee804198b6 100644 --- a/src/schedule/schedule_lang.cc +++ b/src/schedule/schedule_lang.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file schedule_lang.cc diff --git a/src/schedule/schedule_ops.cc b/src/schedule/schedule_ops.cc index ef76a2c1f28a..72d5635b6ea5 100644 --- a/src/schedule/schedule_ops.cc +++ b/src/schedule/schedule_ops.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2016 by Contributors * \file schedule_ops.cc diff --git a/tests/cpp/attrs_test.cc b/tests/cpp/attrs_test.cc index 138e0b242e02..038ad6f171ec 100644 --- a/tests/cpp/attrs_test.cc +++ b/tests/cpp/attrs_test.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #include #include #include diff --git a/tests/cpp/build_module_test.cc b/tests/cpp/build_module_test.cc index aa6e81e860f7..734e457d3bf1 100644 --- a/tests/cpp/build_module_test.cc +++ b/tests/cpp/build_module_test.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #include #include #include diff --git a/tests/cpp/container_test.cc b/tests/cpp/container_test.cc index 4a0500bf4faf..4d064908b35d 100644 --- a/tests/cpp/container_test.cc +++ b/tests/cpp/container_test.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #include #include #include diff --git a/tests/cpp/expr_test.cc b/tests/cpp/expr_test.cc index dca76205d79f..1c5dc7beb87f 100644 --- a/tests/cpp/expr_test.cc +++ b/tests/cpp/expr_test.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #include #include #include diff --git a/tests/cpp/ir_functor_test.cc b/tests/cpp/ir_functor_test.cc index db140f240344..d336537c13be 100644 --- a/tests/cpp/ir_functor_test.cc +++ b/tests/cpp/ir_functor_test.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #include #include #include diff --git a/tests/cpp/ir_mutator_test.cc b/tests/cpp/ir_mutator_test.cc index eecced8d90ab..5ecf4b764a29 100644 --- a/tests/cpp/ir_mutator_test.cc +++ b/tests/cpp/ir_mutator_test.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #include #include #include diff --git a/tests/cpp/ir_simplify_test.cc b/tests/cpp/ir_simplify_test.cc index 3d762c67e7fd..35968f8524de 100644 --- a/tests/cpp/ir_simplify_test.cc +++ b/tests/cpp/ir_simplify_test.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #include #include #include diff --git a/tests/cpp/ir_ssa_test.cc b/tests/cpp/ir_ssa_test.cc index 97251eb5eeeb..32524a50f462 100644 --- a/tests/cpp/ir_ssa_test.cc +++ b/tests/cpp/ir_ssa_test.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #include #include #include diff --git a/tests/cpp/ir_visitor_test.cc b/tests/cpp/ir_visitor_test.cc index 930b0a273143..f0dedc1e75a9 100644 --- a/tests/cpp/ir_visitor_test.cc +++ b/tests/cpp/ir_visitor_test.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #include #include #include diff --git a/tests/cpp/packed_func_test.cc b/tests/cpp/packed_func_test.cc index 83c0ba602927..bb8aef5a1e5a 100644 --- a/tests/cpp/packed_func_test.cc +++ b/tests/cpp/packed_func_test.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #include #include #include diff --git a/tests/cpp/pattern_match_test.cc b/tests/cpp/pattern_match_test.cc index ea1a8427e61a..934ac620fb73 100644 --- a/tests/cpp/pattern_match_test.cc +++ b/tests/cpp/pattern_match_test.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #include #include "../src/arithmetic/pattern_match.h" diff --git a/tests/cpp/relay_pass_type_infer_test.cc b/tests/cpp/relay_pass_type_infer_test.cc index 62f1d914b510..ffd0f7c4a26f 100644 --- a/tests/cpp/relay_pass_type_infer_test.cc +++ b/tests/cpp/relay_pass_type_infer_test.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #include #include #include diff --git a/tests/cpp/simple_passes_test.cc b/tests/cpp/simple_passes_test.cc index f2ef43a0eb25..860ecd56430a 100644 --- a/tests/cpp/simple_passes_test.cc +++ b/tests/cpp/simple_passes_test.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #include #include #include diff --git a/tests/cpp/tensor_test.cc b/tests/cpp/tensor_test.cc index df84c9a2eeb1..b14316f61e32 100644 --- a/tests/cpp/tensor_test.cc +++ b/tests/cpp/tensor_test.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #include #include #include diff --git a/tests/cpp/topi_ewise_test.cc b/tests/cpp/topi_ewise_test.cc index dc280aa7937a..8bd0293cc91a 100644 --- a/tests/cpp/topi_ewise_test.cc +++ b/tests/cpp/topi_ewise_test.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + #include #include #include diff --git a/tests/lint/add_asf_header.py b/tests/lint/add_asf_header.py new file mode 100644 index 000000000000..3d5cc719ef15 --- /dev/null +++ b/tests/lint/add_asf_header.py @@ -0,0 +1,163 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""Helper tool to add ASF header to files that cannot be handled by Rat.""" +import os +import sys + +header_cstyle = """ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +""".strip() + +header_mdstyle = """ + + + + + + + + + + + + + + + + +""".strip() + +header_pystyle = """ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +""".strip() + +header_rststyle = """ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +""".strip() + +header_groovystyle = """ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +""".strip() + +FMT_MAP = { + "toml" : header_pystyle, + "yml": header_pystyle, + "yaml": header_pystyle, + "rs" : header_cstyle, + "md" : header_mdstyle, + "cmake" : header_pystyle, + "rst" : header_rststyle, + "gradle" : header_groovystyle, +} + +def add_header(fname, header): + """Add header to file""" + if not os.path.exists(fname): + print("Cannot find %s ..." % fname) + return + + orig = open(fname).read() + if orig.find("Licensed to the Apache Software Foundation") != -1: + print("Skip file %s ..." % fname) + return + + with open(fname, "w") as outfile: + outfile.write(header + "\n\n") + outfile.write(orig) + print("Add header to %s" % fname) + + +def main(args): + if len(args) != 2: + print("Usage: python add_asf_header.py ") + + for l in open(args[1]): + if l.find("File:") != -1: + l = l.split(":")[-1] + fname = l.strip() + suffix = fname.split(".")[-1] + if suffix in FMT_MAP: + add_header(fname, FMT_MAP[suffix]) + else: + print("Cannot handle %s ..." % fname) + + +if __name__ == "__main__": + main(sys.argv) diff --git a/tests/lint/rat-excludes b/tests/lint/rat-excludes new file mode 100644 index 000000000000..235514b83073 --- /dev/null +++ b/tests/lint/rat-excludes @@ -0,0 +1,45 @@ +# subdirectories +3rdparty/* +.github/* + +# Binary or data files +.*\.css +.*\.ipynb +.*\.html +.*\.pyc +.*\.so +.*\.json +.*\.txt +.*\.svg +.*\.lst +.*\.xcodeproj +.*\.lproj +.*\.plist +.*\.lds +.*\.in +.*\.diff +.*\.edl +.*\.md5 +.*\.csv +.*\.mk +.*\.log + +# Generated modules +.*gen_modules/* +.*doxygen +core.cpp +build +_static +_build +.*~ + +# Specific files +package-list +MANIFEST +.gitignore +.gitmodules +.clang-format +rat-excludes +__init__.py +pylintrc +config.cmake diff --git a/tests/python/contrib/test_cblas.py b/tests/python/contrib/test_cblas.py index 890820ba4519..6705328ee50a 100644 --- a/tests/python/contrib/test_cblas.py +++ b/tests/python/contrib/test_cblas.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np from tvm.contrib import cblas diff --git a/tests/python/contrib/test_cublas.py b/tests/python/contrib/test_cublas.py index 07c7e9224fcb..de19b602f468 100644 --- a/tests/python/contrib/test_cublas.py +++ b/tests/python/contrib/test_cublas.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np from tvm.contrib import cublas diff --git a/tests/python/contrib/test_cudnn.py b/tests/python/contrib/test_cudnn.py index c197f5c5b0c6..0ce5f38c1246 100644 --- a/tests/python/contrib/test_cudnn.py +++ b/tests/python/contrib/test_cudnn.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm from tvm.contrib import cudnn import numpy as np @@ -42,7 +58,7 @@ def test_conv2d(): algo=1) yshape = [x.value for x in Y.shape] s = tvm.create_schedule(Y.op) - + def verify(): ctx = tvm.gpu(0) f = tvm.build(s, [X, W, Y], "cuda", target_host="llvm", name="conv2d") @@ -53,9 +69,9 @@ def verify(): y = tvm.nd.array(np.random.uniform(-1, 1, yshape).astype(np.float32), ctx) f(x, w, y) - + verify() - + if __name__ == "__main__": test_conv2d() diff --git a/tests/python/contrib/test_dlpack.py b/tests/python/contrib/test_dlpack.py index f97b002368ab..f39595582f03 100644 --- a/tests/python/contrib/test_dlpack.py +++ b/tests/python/contrib/test_dlpack.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np from tvm.contrib.dlpack import to_pytorch_func diff --git a/tests/python/contrib/test_miopen.py b/tests/python/contrib/test_miopen.py index 0d9e6dda2d7a..4abaa8d06985 100644 --- a/tests/python/contrib/test_miopen.py +++ b/tests/python/contrib/test_miopen.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm from tvm.contrib import miopen import numpy as np diff --git a/tests/python/contrib/test_mps.py b/tests/python/contrib/test_mps.py index 635724921708..dac49df78d06 100644 --- a/tests/python/contrib/test_mps.py +++ b/tests/python/contrib/test_mps.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np from tvm.contrib import mps @@ -74,7 +90,7 @@ def verify(A, B, C, target="llvm"): f(a, b, c) # print(c.asnumpy()) # print(c.shape) - + verify(A, B, C, s1) diff --git a/tests/python/contrib/test_mxnet_bridge.py b/tests/python/contrib/test_mxnet_bridge.py index d511ec61d6a3..536bad45e9e0 100644 --- a/tests/python/contrib/test_mxnet_bridge.py +++ b/tests/python/contrib/test_mxnet_bridge.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. def mxnet_check(): """This is a simple test function for MXNet bridge diff --git a/tests/python/contrib/test_nnpack.py b/tests/python/contrib/test_nnpack.py index 11e23c749403..0a49efd8f54a 100644 --- a/tests/python/contrib/test_nnpack.py +++ b/tests/python/contrib/test_nnpack.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np import scipy.signal diff --git a/tests/python/contrib/test_random.py b/tests/python/contrib/test_random.py index 6f846836043e..8257c4d7f9e1 100644 --- a/tests/python/contrib/test_random.py +++ b/tests/python/contrib/test_random.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np from tvm.contrib import random diff --git a/tests/python/contrib/test_rocblas.py b/tests/python/contrib/test_rocblas.py index 5f076a3e8963..0794524e7fa6 100644 --- a/tests/python/contrib/test_rocblas.py +++ b/tests/python/contrib/test_rocblas.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np from tvm.contrib import rocblas diff --git a/tests/python/contrib/test_rpc_proxy.py b/tests/python/contrib/test_rpc_proxy.py index 3a9364774ad6..b7c83806cccf 100644 --- a/tests/python/contrib/test_rpc_proxy.py +++ b/tests/python/contrib/test_rpc_proxy.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import logging import numpy as np diff --git a/tests/python/contrib/test_rpc_tracker.py b/tests/python/contrib/test_rpc_tracker.py index d8ecbaaa46e6..6abfc90c352b 100644 --- a/tests/python/contrib/test_rpc_tracker.py +++ b/tests/python/contrib/test_rpc_tracker.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import logging import numpy as np diff --git a/tests/python/contrib/test_sort.py b/tests/python/contrib/test_sort.py index f34dad9e41fb..856d3fa9cf83 100644 --- a/tests/python/contrib/test_sort.py +++ b/tests/python/contrib/test_sort.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np diff --git a/tests/python/contrib/test_sparse.py b/tests/python/contrib/test_sparse.py index ed46ba2ea74a..bc815f6a0718 100644 --- a/tests/python/contrib/test_sparse.py +++ b/tests/python/contrib/test_sparse.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import tvm.contrib.sparse as tvmsp import tvm.ndarray as _nd diff --git a/tests/python/frontend/caffe2/test_forward.py b/tests/python/frontend/caffe2/test_forward.py index 5e5dedc465a0..73cde08ea8b5 100644 --- a/tests/python/frontend/caffe2/test_forward.py +++ b/tests/python/frontend/caffe2/test_forward.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import tvm from tvm.contrib import graph_runtime diff --git a/tests/python/frontend/caffe2/test_graph.py b/tests/python/frontend/caffe2/test_graph.py old mode 100755 new mode 100644 index ebcbf5b51770..e5280932463d --- a/tests/python/frontend/caffe2/test_graph.py +++ b/tests/python/frontend/caffe2/test_graph.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test graph equality of caffe2 models.""" from tvm import relay from model_zoo import c2_squeezenet, relay_squeezenet diff --git a/tests/python/frontend/coreml/model_zoo/__init__.py b/tests/python/frontend/coreml/model_zoo/__init__.py index ca10a96ff649..b89075c7a04c 100644 --- a/tests/python/frontend/coreml/model_zoo/__init__.py +++ b/tests/python/frontend/coreml/model_zoo/__init__.py @@ -18,7 +18,7 @@ def get_resnet50(): def get_cat_image(): url = 'https://gist.githubusercontent.com/zhreshold/bcda4716699ac97ea44f791c24310193/raw/fa7ef0e9c9a5daea686d6473a62aacd1a5885849/cat.png' dst = 'cat.png' - real_dst = download_testdata(url, dst, module='coreml') + real_dst = download_testdata(url, dst, module='data') img = Image.open(real_dst).resize((224, 224)) img = np.transpose(img, (2, 0, 1))[np.newaxis, :] return np.asarray(img) \ No newline at end of file diff --git a/tests/python/frontend/coreml/test_forward.py b/tests/python/frontend/coreml/test_forward.py index f248ad7dd2f3..0fed49079fd2 100644 --- a/tests/python/frontend/coreml/test_forward.py +++ b/tests/python/frontend/coreml/test_forward.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np from coremltools.models.neural_network import NeuralNetworkBuilder diff --git a/tests/python/frontend/keras/test_forward.py b/tests/python/frontend/keras/test_forward.py index 90c07ac09042..35a9229443cb 100644 --- a/tests/python/frontend/keras/test_forward.py +++ b/tests/python/frontend/keras/test_forward.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import tvm from tvm import relay diff --git a/tests/python/frontend/mxnet/model_zoo/dcgan.py b/tests/python/frontend/mxnet/model_zoo/dcgan.py index 8af030b6b184..e606b78e1597 100644 --- a/tests/python/frontend/mxnet/model_zoo/dcgan.py +++ b/tests/python/frontend/mxnet/model_zoo/dcgan.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=unused-argument """ The MXNet symbol of DCGAN generator diff --git a/tests/python/frontend/mxnet/model_zoo/dqn.py b/tests/python/frontend/mxnet/model_zoo/dqn.py index e037511efdf2..e661e18debcb 100644 --- a/tests/python/frontend/mxnet/model_zoo/dqn.py +++ b/tests/python/frontend/mxnet/model_zoo/dqn.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ The mxnet symbol of Nature DQN diff --git a/tests/python/frontend/mxnet/model_zoo/inception_v3.py b/tests/python/frontend/mxnet/model_zoo/inception_v3.py index b8585bf05037..8e8f36a3e644 100644 --- a/tests/python/frontend/mxnet/model_zoo/inception_v3.py +++ b/tests/python/frontend/mxnet/model_zoo/inception_v3.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Inception V3, suitable for images with around 299 x 299 diff --git a/tests/python/frontend/mxnet/model_zoo/squeezenet.py b/tests/python/frontend/mxnet/model_zoo/squeezenet.py index deb896a21385..093da51a78a7 100644 --- a/tests/python/frontend/mxnet/model_zoo/squeezenet.py +++ b/tests/python/frontend/mxnet/model_zoo/squeezenet.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Symbol of SqueezeNet diff --git a/tests/python/frontend/mxnet/test_forward.py b/tests/python/frontend/mxnet/test_forward.py index faccfbfd12fe..d00efb39e16f 100644 --- a/tests/python/frontend/mxnet/test_forward.py +++ b/tests/python/frontend/mxnet/test_forward.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import operator @@ -464,7 +480,6 @@ def verify(data_shape, weight_shape): verify((2, 2), (4, 5)) verify((2, 3, 4), (4, 5)) - def test_forward_smooth_l1(): data = mx.sym.var('data') mx_sym = mx.sym.smooth_l1(data) @@ -472,6 +487,47 @@ def test_forward_smooth_l1(): mx_sym = mx.sym.smooth_l1(data, scalar=1.0) verify_mxnet_frontend_impl(mx_sym, (3, 4), (3, 4)) +def test_forward_take(): + def verify(shape, indices_src, axis, mode="clip"): + x_np = np.random.uniform(size=shape).astype("float32") + indices_np = np.array(indices_src, dtype="float32") + ref_res = mx.nd.take(mx.nd.array(x_np), mx.nd.array(indices_np), axis, mode) + mx_sym = mx.sym.take(mx.sym.var("x"), mx.sym.var("y"), axis, mode) + new_sym, _ = relay.frontend.from_mxnet(mx_sym, {"x": shape, "y": indices_np.shape}) + for target, ctx in ctx_list(): + for kind in ["graph", "debug"]: + intrp = relay.create_executor(kind, ctx=ctx, target=target) + op_res = intrp.evaluate(new_sym)(x_np, indices_np) + tvm.testing.assert_allclose(op_res.asnumpy(), ref_res.asnumpy()) + verify((2,2), [[[1,0],[0,1]]], 0) + verify((2,2), [[[1,0],[0,1]]], 1) + verify((4,3,5,6), [[2,1,0,0]], -2) + verify((3,4), [-1, 5], 0) + verify((3,4), [-1, 5], 0, mode="wrap") + verify((3,4), [-1, 5], 1) + verify((3,4), [-1, 5], 1, mode="wrap") + +def test_forward_gather_nd(): + def verify(xshape, yshape, y_data): + x_data = np.random.uniform(size=xshape).astype("float32") + ref_res = mx.nd.gather_nd(mx.nd.array(x_data), mx.nd.array(y_data)) + mx_sym = mx.sym.gather_nd(mx.sym.var("x_data"), mx.sym.var("y_data")) + new_sym, _ = relay.frontend.from_mxnet(mx_sym, {"x_data": xshape, "y_data": yshape}, {"x_data": "float32", "y_data": "int32"}) + for target, ctx in ctx_list(): + for kind in ["graph", "debug"]: + intrp = relay.create_executor(kind, ctx=ctx, target=target) + op_res = intrp.evaluate(new_sym)(x_data, y_data) + tvm.testing.assert_allclose(op_res.asnumpy(), ref_res.asnumpy()) + verify((2, 2), (2, 3), [[1, 1, 0], [0, 1, 0]]) + verify((2, 2, 2), (2, 2), [[0, 1], [1, 0]]) + +def test_forward_bilinear_resize(): + # add tests including scale_height and scale_width when mxnet is updated to version 1.5 + data = mx.sym.var('data') + mx_sym = mx.sym.contrib.BilinearResize2D(data, height=5, width=10) + verify_mxnet_frontend_impl(mx_sym, (1, 2, 3, 4), (1, 2, 5, 10)) + + if __name__ == '__main__': test_forward_mlp() test_forward_vgg() @@ -507,3 +563,6 @@ def test_forward_smooth_l1(): test_forward_full() test_forward_embedding() test_forward_smooth_l1() + test_forward_take() + test_forward_gather_nd() + test_forward_bilinear_resize() diff --git a/tests/python/frontend/mxnet/test_graph.py b/tests/python/frontend/mxnet/test_graph.py index c2bed8829b81..86312648c32c 100644 --- a/tests/python/frontend/mxnet/test_graph.py +++ b/tests/python/frontend/mxnet/test_graph.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import mxnet as mx from tvm import relay import model_zoo diff --git a/tests/python/frontend/nnvm_to_relay/test_forward.py b/tests/python/frontend/nnvm_to_relay/test_forward.py index f32fb803e49b..6a00b5a471f4 100644 --- a/tests/python/frontend/nnvm_to_relay/test_forward.py +++ b/tests/python/frontend/nnvm_to_relay/test_forward.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import tvm @@ -18,7 +34,7 @@ def get_nnvm_output(sym, x, params, target, ctx, dtype='float32'): m.set_input(**params) m.run() return m.get_output(0).asnumpy() - + def get_relay_output(sym, x, params, target, ctx, dtype='float32'): shape_dict = {'data': x.shape} func, params = to_relay(sym, shape_dict, dtype, params) diff --git a/tests/python/frontend/onnx/test_forward.py b/tests/python/frontend/onnx/test_forward.py index de95ff00aef9..1e89b9ddaa8c 100644 --- a/tests/python/frontend/onnx/test_forward.py +++ b/tests/python/frontend/onnx/test_forward.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import math import topi @@ -113,35 +129,36 @@ def test_reshape(): tvm.testing.assert_allclose(ref_shape, tvm_out.shape) -def test_reshape_like(): +def test_shape(): in_shape = (4, 3, 3, 4) - ref_shape = (3, 4, 4, 3) + ref_shape = (6, 2, 4, 3) - ref_array = np.random.uniform(size=ref_shape).astype('float32') + ref_array = np.array(ref_shape) ref_node = onnx.helper.make_node('Constant', inputs=[], outputs=['ref_in'], value=onnx.helper.make_tensor(name = 'const_tensor', - data_type = onnx.TensorProto.FLOAT, + data_type = onnx.TensorProto.INT32, dims = ref_array.shape, - vals = ref_array.flatten().astype(float))) - copy_node = helper.make_node("Identity", ["ref_in"], ["copy_in"]) - reshape_node = helper.make_node("Reshape", ["in", "copy_in"], ["out"]) + vals = ref_array.flatten().astype(int))) + reshape_node = helper.make_node("Reshape", ["in", "ref_in"], ["out"]) + + shape_node = helper.make_node("Shape", ['out'], ['final_out']) - graph = helper.make_graph([ref_node, copy_node, reshape_node], - "reshape_like_test", + graph = helper.make_graph([ref_node, reshape_node, shape_node], + "shape_test", inputs = [helper.make_tensor_value_info("in", TensorProto.FLOAT, list(in_shape))], - outputs = [helper.make_tensor_value_info("out", + outputs = [helper.make_tensor_value_info("final_out", TensorProto.FLOAT, list(ref_shape))]) - model = helper.make_model(graph, producer_name='reshape_like_test') + model = helper.make_model(graph, producer_name='shape_test') for target, ctx in ctx_list(): - x = np.random.uniform(size=in_shape).astype('float32') - tvm_out = get_tvm_output(model, x, target, ctx, ref_shape, 'float32') + x = np.random.uniform(size=in_shape).astype('int32') + tvm_out = get_tvm_output(model, x, target, ctx, ref_shape, 'int32') - tvm.testing.assert_allclose(ref_shape, tvm_out.shape) + tvm.testing.assert_allclose(ref_shape, tvm_out) def _test_power_iteration(x_shape, y_shape): if isinstance(y_shape, int): @@ -995,7 +1012,7 @@ def test_LogSoftmax(): if __name__ == '__main__': test_reshape() - test_reshape_like() + test_shape() test_power() test_squeeze() test_unsqueeze() diff --git a/tests/python/frontend/tensorflow/test_control_flow.py b/tests/python/frontend/tensorflow/test_control_flow.py index c5b38c319467..e76a849ae8c3 100644 --- a/tests/python/frontend/tensorflow/test_control_flow.py +++ b/tests/python/frontend/tensorflow/test_control_flow.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Unit tests for converting TensorFlow control flow op to Relay.""" import tensorflow as tf import numpy as np diff --git a/tests/python/frontend/tensorflow/test_forward.py b/tests/python/frontend/tensorflow/test_forward.py index 10368ea3d9ab..35dca8008dfc 100644 --- a/tests/python/frontend/tensorflow/test_forward.py +++ b/tests/python/frontend/tensorflow/test_forward.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=import-self, invalid-name, unused-argument """ Tensorflow testcases @@ -19,8 +35,8 @@ from tensorflow.python.ops import variable_scope from tensorflow.python.ops import variables from tensorflow.python.ops import init_ops -from tensorflow.core.framework import graph_pb2 +from distutils.version import LooseVersion import tvm.relay.testing.tf as tf_testing ####################################################################### @@ -108,7 +124,6 @@ def compare_tf_with_tvm(in_data, in_name, out_name, init_global_variables=False, in_node = [0]*len(in_name) for i in range(len(in_name)): in_node[i] = in_name[i].split(':')[0] if ":" in in_name[i] else in_name[i] - with tf.Session() as sess: if init_global_variables: sess.run(variables.global_variables_initializer()) @@ -473,17 +488,17 @@ def test_forward_stridedslice(): ####################################################################### -# Gather -# ------ +# Gather, GatherV2 +# ---------------- def _test_gather(ip_shape, indice_shape, indice_value, axis, dtype): - """ One iteration of a Gather """ + """ One iteration of a GatherV2 """ tf.reset_default_graph() in_data = tf.placeholder(dtype, ip_shape, name="in_data") indices = tf.placeholder("int32", indice_shape, name="indices") tf.gather(in_data, indices, axis=axis) - np_data = np.random.uniform(size=ip_shape).astype(dtype) + np_data = np.random.uniform(1, 10, size=ip_shape).astype(dtype) def _fill_indices(indice_value): indices = np.array(ip_shape, dtype=dtype) @@ -497,17 +512,55 @@ def _fill_indices(indice_value): compare_tf_with_tvm([np_data, np_indices], ['in_data:0', 'indices:0'], 'GatherV2:0') def test_forward_gather(): - '''test gather layer''' + '''test GatherV2 layer''' _test_gather((4,), (1,), 1, 0, 'int32') _test_gather((4,), (1,), 1, 0, 'float32') - _test_gather((1,4), (1,), [0], 0, 'int32') - _test_gather((4,), (1,2,2), [[[1,0],[0,1]]], 0, 'float32') - _test_gather((2,2), (1,2,2), [[[1,0],[0,1]]], 0, 'int32') - _test_gather((2,2), (1,2,2), [[[1,0],[0,1]]], 1, 'int32') - _test_gather((2,2), (1,2,2), [[[1,0],[0,1]]], 0, 'float32') - _test_gather((3,3,3), (1,1,2), [[[1,0]]], 0, 'int32') - _test_gather((3,3,3), (1,1,2), [[[1,0]]], 2, 'int32') - _test_gather((4,3,5,6), (1,4), [[2,1,0,0]], 0, 'float32') + _test_gather((1, 4), (1,), [0], 0, 'int32') + _test_gather((4,), (1, 2, 2), [[[1, 0],[0, 1]]], 0, 'float32') + _test_gather((2, 2), (1, 2, 2), [[[1, 0],[0, 1]]], 0, 'int32') + _test_gather((2, 2), (1, 2, 2), [[[1, 0],[0, 1]]], 1, 'int32') + _test_gather((2, 2), (1, 2, 2), [[[1, 0],[0, 1]]], 0, 'float32') + _test_gather((3, 3, 3), (1, 1, 2), [[[1, 0]]], 0, 'int32') + _test_gather((3, 3, 3), (1, 1, 2), [[[1, 0]]], 2, 'int32') + _test_gather((4, 3, 5, 6), (1, 4), [[2, 1, 0, 0]], 0, 'float32') + + +def _test_gather_v1(ip_shape, indice_shape, indice_value, dtype): + """ One iteration of a Gather""" + tf.reset_default_graph() + in_data = tf.placeholder(dtype, ip_shape, name="in_data") + indices = tf.placeholder("int32", indice_shape, name="indices") + tf.gather(in_data, indices) + np_data = np.random.uniform(size=ip_shape).astype(dtype) + + def _fill_indices(indice_value): + indices = np.array(ip_shape, dtype=dtype) + if isinstance(indice_value, int): + indices = np.array([indice_value], dtype='int32') + else: + indices = np.asarray(indice_value, dtype='int32') + return indices + np_indices = _fill_indices(indice_value) + + compare_tf_with_tvm([np_data, np_indices], ['in_data:0', 'indices:0'], 'Gather:0') + + +def test_forward_gather_v1(): + '''test gather layer''' + + if tf.__version__ < LooseVersion('1.7'): + _test_gather_v1((4,), (1, 2, 2), [[[1, 0], [0, 1]]], 'float32') + _test_gather_v1((4,), (1,), 1, 'int32') + _test_gather_v1((4,), (1,), 1, 'float32') + _test_gather_v1((1, 4), (1,), [0], 'int32') + _test_gather_v1((4,), (1, 2, 2), [[[1, 0], [0, 1]]], 'float32') + _test_gather_v1((2, 2), (1, 2, 2), [[[1, 0], [0, 1]]], 'int32') + _test_gather_v1((2, 2), (1, 2, 2), [[[1, 0], [0, 1]]], 'int32') + _test_gather_v1((2, 2), (1, 2, 2), [[[1, 0], [0, 1]]], 'float32') + _test_gather_v1((3, 3, 3), (1, 1, 2), [[[1, 0]]], 'int32') + _test_gather_v1((3, 3, 3), (1, 1, 2), [[[1, 0]]], 'int32') + _test_gather_v1((4, 3, 5, 6), (1, 4), [[2, 1, 0, 0]], 'float32') + ####################################################################### # Split @@ -582,10 +635,10 @@ def _test_unstack(ip_shape, axis, dtype): def test_forward_unstack(): '''test unstack layer''' _test_unstack((6,), 0, 'int32') - _test_unstack((2,6), 1, 'float64') + _test_unstack((2, 6), 1, 'float64') # negative axis - _test_unstack((1,4), -1, 'int32') - _test_unstack((3,6,4), -2, 'float32') + _test_unstack((1, 4), -1, 'int32') + _test_unstack((3, 6, 4), -2, 'float32') ####################################################################### @@ -825,6 +878,22 @@ def test_forward_logical(): test_logical_not() +####################################################################### +# Where, Select +# ------------- +def test_where(): + ''' Where: return elements depending on conditions''' + with tf.Graph().as_default(): + with tf.Session() as sess: + input1 = tf.placeholder(tf.int32, shape=[1, 4, 4, 3], name='input1') + input2 = tf.placeholder(tf.int32, shape=[1, 4, 4, 3], name='input2') + mask = input1 > input2 + tf.where(mask, input1 + 1, input2 * 2) + in_data1 = np.random.uniform(0, 10, size=(1, 4, 4, 3)).astype("uint32") + in_data2 = np.random.uniform(0, 10, size=(1, 4, 4, 3)).astype("uint32") + compare_tf_with_tvm([in_data1, in_data2], ['input1:0', 'input2:0'], 'Select:0') + + ####################################################################### # Inception V3 # ------------ @@ -1213,6 +1282,7 @@ def test_forward_rel_ops(): test_forward_crop() test_forward_pad() test_forward_gather() + test_forward_gather_v1() test_forward_stridedslice() test_forward_split() test_forward_unstack() @@ -1260,3 +1330,4 @@ def test_forward_rel_ops(): # Relational ops test_forward_rel_ops() test_forward_logical() + test_where() diff --git a/tests/python/frontend/tflite/test_forward.py b/tests/python/frontend/tflite/test_forward.py index 3c41792ae903..5f95d869ae74 100644 --- a/tests/python/frontend/tflite/test_forward.py +++ b/tests/python/frontend/tflite/test_forward.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=import-self, invalid-name, unused-argument """ TFLite testcases @@ -11,6 +27,8 @@ from tvm.contrib import util import tensorflow as tf from tensorflow.python.framework import constant_op +from tensorflow.python.framework import ops +from tensorflow.python.ops import math_ops from tensorflow.python.ops import nn_ops from tensorflow.python.ops import array_ops from tensorflow.python.ops import variables @@ -99,7 +117,7 @@ def run_tflite_graph(tflite_model_buf, input_data): def compare_tflite_with_tvm(tflite_in_data, tvm_in_data, in_name, input_tensors, - output_tensors, output_need_transpose_nchw=False, + output_tensors, output_need_transpose=False, init_global_variables=False): """Generic function to generate and compare TFLite and TVM output""" tflite_in_data = convert_to_list(tflite_in_data) @@ -126,9 +144,19 @@ def compare_tflite_with_tvm(tflite_in_data, tvm_in_data, in_name, input_tensors, tvm_output = run_tvm_graph(tflite_model_buffer, tvm_in_data, in_node, target=device) for i in range(len(tflite_output)): - if output_need_transpose_nchw: + if output_need_transpose: + dim = len(tvm_output[i].shape) + if dim == 3: + # N C H*W to N H*W C + axes = (0, 2, 1) + elif dim == 4: + # N C H W to N H W C + axes = (0, 2, 3, 1) + else: + raise NotImplementedError("Not support input shape {} of transpose : ". + format(str(dim))) tvm.testing.assert_allclose(tflite_output[i], - np.transpose(tvm_output[i], axes=(0, 2, 3, 1)), + np.transpose(tvm_output[i], axes=axes), atol=1e-5, rtol=1e-5) else: tvm.testing.assert_allclose(tflite_output[i], tvm_output[i], @@ -152,7 +180,7 @@ def _test_pooling_iteration(input_shape, **kwargs): out = nn_ops.pool(in_data, **kwargs) compare_tflite_with_tvm(x, tvm_data, 'Placeholder:0', [in_data], [out], - output_need_transpose_nchw=True) + output_need_transpose=True) def _test_pooling(input_shape, **kwargs): @@ -236,7 +264,7 @@ def _test_convolution(tensor_in_sizes, filter_in_sizes, # TFLite output is NHWC, TVM is NCHW, we need transpose compare_tflite_with_tvm(tflite_data_array, tvm_data_array, 'Placeholder:0', [in_data], [out], - output_need_transpose_nchw=True) + output_need_transpose=True) def test_forward_convolution(): @@ -330,6 +358,53 @@ def test_forward_concatenation(): np.arange(6).reshape((2, 1, 1, 3))], 1) +####################################################################### +# Add +# --- + +def _test_add(data): + """ One iteration of add """ + + assert len(data) == 2 + need_transpose = False + if len(data[0].shape) == 1 or len(data[0].shape) == 2: + tvm_data = data + elif len(data[0].shape) == 3: + need_transpose = True + tvm_data = [np.transpose(d, axes=(0, 2, 1)) for d in data] + elif len(data[0].shape) == 4: + need_transpose = True + tvm_data = [np.transpose(d, axes=(0, 3, 1, 2)) for d in data] + else: + raise NotImplementedError("Not support input shape {} of add : ". + format(str(len(data.shape)))) + + # Test with two tensors + with tf.Graph().as_default(): + in_data = [array_ops.placeholder(shape=data[0].shape, dtype=data[0].dtype, name='in_0'), + array_ops.placeholder(shape=data[1].shape, dtype=data[1].dtype, name='in_1')] + out = math_ops.add(in_data[0], in_data[1]) + compare_tflite_with_tvm(data, tvm_data, ['in_0:0','in_1:0'], + in_data, [out], need_transpose) + + # Test with tensor and constant + with tf.Graph().as_default(): + in_data = [array_ops.placeholder(shape=data[0].shape, dtype=data[0].dtype, name='in')] + out = math_ops.add(in_data[0], ops.convert_to_tensor(data[1], dtype=data[1].dtype)) + compare_tflite_with_tvm([data[0]], [tvm_data[0]], ['in:0'], + in_data, [out], need_transpose) + + +def test_forward_add(): + """ Add """ + _test_add([np.arange(6.0, dtype=np.float32).reshape((2, 1, 1, 3)), + np.arange(6.0, dtype=np.float32).reshape((2, 1, 1, 3))]) + _test_add([np.arange(6.0, dtype=np.float32).reshape((2, 1, 3)), + np.arange(6.0, dtype=np.float32).reshape((2, 1, 3))]) + _test_add([np.arange(3.0, dtype=np.float32).reshape((1, 3)), + np.arange(3.0, dtype=np.float32).reshape((1, 3))]) + + ####################################################################### # Squeeze # ------- @@ -388,7 +463,7 @@ def test_forward_softmax(): # Mobilenet # --------- -def test_forward_mobilenet(): +def test_forward_mobilenet_v1(): '''test mobilenet v1 tflite model''' # MobilenetV1 tflite_model_file = tf_testing.get_workload_official( @@ -403,6 +478,21 @@ def test_forward_mobilenet(): tvm.testing.assert_allclose(np.squeeze(tvm_output[0]), np.squeeze(tflite_output[0]), rtol=1e-5, atol=1e-5) +def test_forward_mobilenet_v2(): + '''test mobilenet v2 tflite model''' + # MobilenetV2 + tflite_model_file = tf_testing.get_workload_official( + "http://download.tensorflow.org/models/tflite_11_05_08/mobilenet_v2_1.0_224.tgz", + "mobilenet_v2_1.0_224.tflite") + with open(tflite_model_file, "rb") as f: + tflite_model_buf = f.read() + data = np.random.uniform(size=(1, 224, 224, 3)).astype('float32') + tvm_data = np.transpose(data, axes=(0, 3, 1, 2)) + tflite_output = run_tflite_graph(tflite_model_buf, data) + tvm_output = run_tvm_graph(tflite_model_buf, tvm_data, 'input') + tvm.testing.assert_allclose(np.squeeze(tvm_output[0]), np.squeeze(tflite_output[0]), + rtol=1e-5, atol=1e-5) + ####################################################################### # Inception V3 # ------------ @@ -436,6 +526,10 @@ def test_forward_inception_v3_net(): test_forward_pooling() test_forward_softmax() + # Math + test_forward_add() + # End to End - test_forward_mobilenet() + test_forward_mobilenet_v1() + test_forward_mobilenet_v2() test_forward_inception_v3_net() diff --git a/tests/python/integration/test_dot.py b/tests/python/integration/test_dot.py index 15243c8b1235..a08e7d3b1627 100644 --- a/tests/python/integration/test_dot.py +++ b/tests/python/integration/test_dot.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np diff --git a/tests/python/integration/test_ewise.py b/tests/python/integration/test_ewise.py index b3f17b7c1bb1..31a39c40fa1f 100644 --- a/tests/python/integration/test_ewise.py +++ b/tests/python/integration/test_ewise.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm from tvm.contrib import nvcc import numpy as np diff --git a/tests/python/integration/test_ewise_fpga.py b/tests/python/integration/test_ewise_fpga.py index 493cb5016cfe..c80b430b92ae 100644 --- a/tests/python/integration/test_ewise_fpga.py +++ b/tests/python/integration/test_ewise_fpga.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np import os diff --git a/tests/python/integration/test_gemm.py b/tests/python/integration/test_gemm.py index 928ba187a4d3..9b1a4bf10e19 100644 --- a/tests/python/integration/test_gemm.py +++ b/tests/python/integration/test_gemm.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np import time diff --git a/tests/python/integration/test_reduce.py b/tests/python/integration/test_reduce.py index 715db5d63fb6..05185bedf6cf 100644 --- a/tests/python/integration/test_reduce.py +++ b/tests/python/integration/test_reduce.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np diff --git a/tests/python/integration/test_scan.py b/tests/python/integration/test_scan.py index 49d1cf3b75ce..ab5f20df090f 100644 --- a/tests/python/integration/test_scan.py +++ b/tests/python/integration/test_scan.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np diff --git a/tests/python/integration/test_tuning.py b/tests/python/integration/test_tuning.py index 8e1b458a6d2f..fec7d3e4f83f 100644 --- a/tests/python/integration/test_tuning.py +++ b/tests/python/integration/test_tuning.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Test the tuner """ diff --git a/tests/python/integration/test_winograd_nnpack.py b/tests/python/integration/test_winograd_nnpack.py index 62dc3771f7cf..0681ba216dc4 100644 --- a/tests/python/integration/test_winograd_nnpack.py +++ b/tests/python/integration/test_winograd_nnpack.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import tvm from tvm import autotvm diff --git a/tests/python/relay/test_adt.py b/tests/python/relay/test_adt.py index e9e2915f28a8..58ab0c481f9c 100644 --- a/tests/python/relay/test_adt.py +++ b/tests/python/relay/test_adt.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm from tvm import relay from tvm.relay.ir_pass import infer_type @@ -31,6 +47,7 @@ map = p.map foldl = p.foldl foldr = p.foldr +foldr1 = p.foldr1 sum = p.sum concat = p.concat @@ -228,6 +245,23 @@ def test_foldr(): assert count(same[0]) == 1 and count(same[1]) == 2 and count(same[2]) == 3 +def test_foldr1(): + a = relay.TypeVar("a") + lhs = mod[p.foldr1].checked_type + rhs = relay.FuncType([relay.FuncType([a, a], a), l(a)], a, [a]) + assert lhs == rhs + + x = relay.Var("x") + y = relay.Var("y") + f = relay.Function([x, y], add(x, y)) + res = intrp.evaluate(foldr1(f, + cons(build_nat(1), + cons(build_nat(2), + cons(build_nat(3), nil()))))) + + assert count(res) == 6 + + def test_sum(): assert mod[sum].checked_type == relay.FuncType([l(nat())], nat()) res = intrp.evaluate(sum(cons(build_nat(1), cons(build_nat(2), nil())))) @@ -647,6 +681,7 @@ def test_iterate(): test_map() test_foldl() test_foldr() + test_foldr1() test_concat() test_filter() test_zip() diff --git a/tests/python/relay/test_autotvm_task_extraction.py b/tests/python/relay/test_autotvm_task_extraction.py index 8c93e4a56642..07116cd5faf5 100644 --- a/tests/python/relay/test_autotvm_task_extraction.py +++ b/tests/python/relay/test_autotvm_task_extraction.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test task extraction for autotvm""" import tvm.relay.testing from tvm import relay diff --git a/tests/python/relay/test_backend_compile_engine.py b/tests/python/relay/test_backend_compile_engine.py index fdc867ffaad6..3b479b847619 100644 --- a/tests/python/relay/test_backend_compile_engine.py +++ b/tests/python/relay/test_backend_compile_engine.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import tvm.testing import numpy as np diff --git a/tests/python/relay/test_backend_graph_runtime.py b/tests/python/relay/test_backend_graph_runtime.py index 434b0e6ddfa1..32687a4e8013 100644 --- a/tests/python/relay/test_backend_graph_runtime.py +++ b/tests/python/relay/test_backend_graph_runtime.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import tvm @@ -7,6 +23,7 @@ from tvm.relay.scope_builder import ScopeBuilder from tvm.relay.op import add from tvm.relay.module import Module +from tvm.relay.testing.config import ctx_list # @tq, @jr should we put this in testing ns? def check_rts(expr, args, expected_result, mod=None): @@ -127,9 +144,47 @@ def test_plan_memory(): assert len(device_types) == 1 +def test_gru_like(): + def unit(rnn_dim): + X = relay.var("X", shape=(1, rnn_dim)) + W = relay.var("y", shape=(3 * rnn_dim, rnn_dim)) + matmul = relay.nn.dense(X, W) + splitted = relay.split(matmul, indices_or_sections=3, axis=1) + out = relay.sigmoid(splitted[0]) + relay.tanh(splitted[1]) * relay.exp(splitted[2]) + return relay.Function([X, W], out) + + def sigmoid(x): + return 1 / (1 + np.exp(-x)) + + def unit_numpy(X, W): + prod = np.dot(X, W.transpose()) + splits = np.split(prod, indices_or_sections=3, axis=1) + return sigmoid(splits[0]) + np.tanh(splits[1]) * np.exp(splits[2]) + + dtype = "float32" + rnn_dim = 1000 + x = np.random.rand(1, rnn_dim).astype(dtype) + y = np.random.rand(3*rnn_dim, rnn_dim).astype(dtype) * 0.01 - 0.005 + out_shape = (1, rnn_dim) + z = unit(rnn_dim) + + for target, ctx in ctx_list(): + with relay.build_config(opt_level=2): + graph, lib, params = relay.build(z, target) + m = graph_runtime.create(graph, lib, ctx) + m.set_input("X", tvm.nd.array(x.astype(dtype))) + m.set_input("y", tvm.nd.array(y.astype(dtype))) + m.set_input(**params) + m.run() + out = m.get_output(0, tvm.nd.empty(out_shape, dtype)).asnumpy() + ref = unit_numpy(x, y) + tvm.testing.assert_allclose(out, ref, rtol=1e-5, atol=1e-5) + + if __name__ == "__main__": test_plan_memory() test_with_params() test_add_op_scalar() test_add_op_tensor() test_add_op_broadcast() + test_gru_like() diff --git a/tests/python/relay/test_backend_interpreter.py b/tests/python/relay/test_backend_interpreter.py index 773af1f9fe0e..da794e25ab56 100644 --- a/tests/python/relay/test_backend_interpreter.py +++ b/tests/python/relay/test_backend_interpreter.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import tvm import tvm.testing diff --git a/tests/python/relay/test_debug.py b/tests/python/relay/test_debug.py index d62e3026ad46..fc21f685cd92 100644 --- a/tests/python/relay/test_debug.py +++ b/tests/python/relay/test_debug.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. from tvm.relay import var, const, create_executor from tvm.relay.op import debug diff --git a/tests/python/relay/test_error_reporting.py b/tests/python/relay/test_error_reporting.py index 1720af21afea..c608ebba9b6d 100644 --- a/tests/python/relay/test_error_reporting.py +++ b/tests/python/relay/test_error_reporting.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm from tvm import relay diff --git a/tests/python/relay/test_expr_functor.py b/tests/python/relay/test_expr_functor.py index 17a799b18586..2a58c282b4c7 100644 --- a/tests/python/relay/test_expr_functor.py +++ b/tests/python/relay/test_expr_functor.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm from tvm import relay from tvm.relay import ExprFunctor, ExprMutator diff --git a/tests/python/relay/test_ir_bind.py b/tests/python/relay/test_ir_bind.py index 8377bb9fb953..754efa557db6 100644 --- a/tests/python/relay/test_ir_bind.py +++ b/tests/python/relay/test_ir_bind.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ test bind function.""" import tvm from tvm import relay diff --git a/tests/python/relay/test_ir_nodes.py b/tests/python/relay/test_ir_nodes.py index e041acca0e0c..cec277371252 100644 --- a/tests/python/relay/test_ir_nodes.py +++ b/tests/python/relay/test_ir_nodes.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ test ir""" import tvm from tvm import relay diff --git a/tests/python/relay/test_ir_op.py b/tests/python/relay/test_ir_op.py index f1d835d2b43b..8873e4d1c6b1 100644 --- a/tests/python/relay/test_ir_op.py +++ b/tests/python/relay/test_ir_op.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. from tvm import relay def test_op_attr(): diff --git a/tests/python/relay/test_ir_parser.py b/tests/python/relay/test_ir_parser.py index 08d4c430101b..d3c30be2a953 100644 --- a/tests/python/relay/test_ir_parser.py +++ b/tests/python/relay/test_ir_parser.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm from tvm import relay from tvm.relay.parser import enabled @@ -101,7 +117,7 @@ def test_comments(): def test_int_literal(): assert isinstance(relay.fromtext(SEMVER+"1"), relay.Constant) assert isinstance(relay.fromtext(SEMVER+"1").data, tvm.ndarray.NDArray) - + assert get_scalar(relay.fromtext(SEMVER+"1")) == 1 assert get_scalar(relay.fromtext(SEMVER+"10")) == 10 assert get_scalar(relay.fromtext(SEMVER+"0")) == 0 diff --git a/tests/python/relay/test_ir_text_printer.py b/tests/python/relay/test_ir_text_printer.py index d3e2d005a4e1..4206d68b83bf 100644 --- a/tests/python/relay/test_ir_text_printer.py +++ b/tests/python/relay/test_ir_text_printer.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import tvm.relay.testing import numpy as np diff --git a/tests/python/relay/test_ir_well_formed.py b/tests/python/relay/test_ir_well_formed.py index b9e907144785..e69f839e3ee6 100644 --- a/tests/python/relay/test_ir_well_formed.py +++ b/tests/python/relay/test_ir_well_formed.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm from tvm import relay from tvm.relay.ir_pass import well_formed diff --git a/tests/python/relay/test_op_grad_level1.py b/tests/python/relay/test_op_grad_level1.py index a9d91f757407..12b3ae3bf765 100644 --- a/tests/python/relay/test_op_grad_level1.py +++ b/tests/python/relay/test_op_grad_level1.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np from tvm import relay diff --git a/tests/python/relay/test_op_level1.py b/tests/python/relay/test_op_level1.py index b954e42bf1ab..94d3b157dd0d 100644 --- a/tests/python/relay/test_op_level1.py +++ b/tests/python/relay/test_op_level1.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import math import tvm import numpy as np diff --git a/tests/python/relay/test_op_level10.py b/tests/python/relay/test_op_level10.py index 1b1760692943..667dd87a6688 100644 --- a/tests/python/relay/test_op_level10.py +++ b/tests/python/relay/test_op_level10.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Support level10 operator test cases. """ import numpy as np diff --git a/tests/python/relay/test_op_level2.py b/tests/python/relay/test_op_level2.py index c8a38565ac7a..a6efd8cf0971 100644 --- a/tests/python/relay/test_op_level2.py +++ b/tests/python/relay/test_op_level2.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Support level2 operator test cases. """ import tvm diff --git a/tests/python/relay/test_op_level3.py b/tests/python/relay/test_op_level3.py index 10ace54e8b12..15cb3265b679 100644 --- a/tests/python/relay/test_op_level3.py +++ b/tests/python/relay/test_op_level3.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Support level3 operator test cases. """ import tvm @@ -243,17 +259,17 @@ def verify_take(dshape, indices_shape, oshape, axis=None): verify_take((d1, d2, d3, d4), (d5, d6), (d1, d2, d5, d6, d4), -2) def test_take(): - def verify_take(src_shape, indices_src, axis=None): + def verify_take(src_shape, indices_src, axis=None, mode="clip"): src_dtype = "float32" indices_dtype = "int32" indices_src = np.array(indices_src, dtype=indices_dtype) x = relay.var("x", relay.TensorType(src_shape, src_dtype)) indices = relay.var("indices", relay.TensorType(indices_src.shape, indices_dtype)) - z = relay.take(x, indices, axis=axis) + z = relay.take(x, indices, axis=axis, mode=mode) func = relay.Function([x, indices], z) x_data = np.random.uniform(low=-1, high=1, size=src_shape).astype(src_dtype) - ref_res = np.take(x_data, indices=indices_src, axis=axis) + ref_res = np.take(x_data, indices=indices_src, axis=axis, mode=mode) for target, ctx in ctx_list(): for kind in ["graph", "debug"]: @@ -269,6 +285,12 @@ def verify_take(src_shape, indices_src, axis=None): verify_take((2,2), [[[1,0],[0,1]]], 0) verify_take((2,2), [[[1,0],[0,1]]], 1) verify_take((4,3,5,6), [[2,1,0,0]], -2) + verify_take((3,4), [-5, 20]) + verify_take((3,4), [-5, 20], mode="wrap") + verify_take((3,4), [-1, 2], axis=0) + verify_take((3,4), [-1, 2], axis=0, mode="wrap") + verify_take((3,4), [-1, 2], axis=1) + verify_take((3,4), [-1, 2], axis=1, mode="wrap") def test_split_infer_type(): @@ -547,7 +569,6 @@ def verify_stack(dshapes, axis): verify_stack([(2, 2, 3, 4), (2, 2, 3, 4), (2, 2, 3, 4), (2, 2, 3, 4)], -1) - def test_reverse(): def verify_reverse(dshape, axis): x = relay.var("x", relay.TensorType(dshape, "float32")) @@ -567,6 +588,25 @@ def verify_reverse(dshape, axis): verify_reverse((2, 3, 4), -1) +def test_gather_nd(): + def verify_gather_nd(xshape, yshape, y_data): + x = relay.var("x", relay.TensorType(xshape, "float32")) + y = relay.var("y", relay.TensorType(yshape, "int32")) + z = relay.gather_nd(x, y) + + func = relay.Function([x, y], z) + x_data = np.random.uniform(size=xshape).astype("float32") + ref_res = x_data[y_data] + + for target, ctx in ctx_list(): + for kind in ["graph", "debug"]: + intrp = relay.create_executor(kind, ctx=ctx, target=target) + op_res = intrp.evaluate(func)(x_data, y_data) + tvm.testing.assert_allclose(op_res.asnumpy(), ref_res, rtol=1e-5) + verify_gather_nd((2, 2), (2, 3), [[1, 1, 0], [0, 1, 0]]) + verify_gather_nd((2, 2, 2), (2, 2), [[0, 1], [1, 0]]) + + if __name__ == "__main__": test_cast() test_zeros_ones() @@ -595,3 +635,4 @@ def verify_reverse(dshape, axis): test_stack() test_tile() test_repeat() + test_gather_nd() diff --git a/tests/python/relay/test_op_level4.py b/tests/python/relay/test_op_level4.py index ae7fe320940a..8db90fbf91f0 100644 --- a/tests/python/relay/test_op_level4.py +++ b/tests/python/relay/test_op_level4.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np from tvm import relay diff --git a/tests/python/relay/test_op_level5.py b/tests/python/relay/test_op_level5.py index 71f843ec7e00..7e1c37169978 100644 --- a/tests/python/relay/test_op_level5.py +++ b/tests/python/relay/test_op_level5.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Support level5 operator test cases. """ import math @@ -489,6 +505,66 @@ def verify_yolo_reorg(shape, stride): verify_yolo_reorg((1, 100, 20, 20), 10) verify_yolo_reorg((1, 4, 6, 6), 2) + +def test_deformable_conv2d(): + def test_infer_type(batch, in_channel, size, out_channel, deformable_groups, groups): + data_shape = (batch, in_channel, size, size) + data = relay.var("data", shape=data_shape) + offset = relay.var("offset") + kernel = relay.var("kernel") + kernel_size = (3, 3) + y = relay.nn.deformable_conv2d(data, offset, kernel, + strides=(1, 1), + padding=(1, 1), + dilation=(1, 1), + kernel_size=kernel_size, + deformable_groups=deformable_groups, + groups=groups, + channels=out_channel) + weight_shape = (out_channel, in_channel // groups, kernel_size[0], kernel_size[1]) + out_shape = (batch, out_channel, size, size) + offset_shape = (batch, 2 * kernel_size[0] * kernel_size[1] * deformable_groups, out_shape[2], out_shape[3]) + yy = relay.ir_pass.infer_type(y) + assert yy.checked_type == relay.TensorType(out_shape) + assert yy.args[1].checked_type == relay.TensorType(offset_shape), yy.args[1].checked_type + assert yy.args[2].checked_type == relay.TensorType(weight_shape) + + test_infer_type(1, 4, 16, 4, 4, 1) + test_infer_type(2, 4, 16, 4, 1, 2) + + + def test_run(batch, in_channel, size, out_channel, deformable_groups, groups): + kernel_size = (3, 3) + data_shape = (batch, in_channel, size, size) + offset_shape = (batch, 2 * kernel_size[0] * kernel_size[1] * deformable_groups, size, size) + kernel_shape = (out_channel, in_channel // groups, kernel_size[0], kernel_size[1]) + dtype = 'float32' + data = relay.var("data", shape=data_shape, dtype=dtype) + offset = relay.var("offset") + kernel = relay.var("kernel") + y = relay.nn.deformable_conv2d(data, offset, kernel, + strides=(1, 1), + padding=(1, 1), + dilation=(1, 1), + kernel_size=kernel_size, + deformable_groups=deformable_groups, + groups=groups, + channels=out_channel) + func = relay.Function([data, offset, kernel], y) + data = np.random.uniform(size=data_shape).astype(dtype) + offset = np.random.uniform(size=offset_shape).astype(dtype) + kernel = np.random.uniform(size=kernel_shape).astype(dtype) + ref_res = topi.testing.deformable_conv2d_nchw_python(data, offset, kernel, stride=(1, 1), padding=(1, 1), dilation=(1, 1), deformable_groups=deformable_groups, groups=groups) + + for target, ctx in ctx_list(): + for kind in ["graph", "debug"]: + intrp1 = relay.create_executor(kind, ctx=ctx, target=target) + op_res1 = intrp1.evaluate(func)(data, offset, kernel) + tvm.testing.assert_allclose(op_res1.asnumpy(), ref_res, rtol=1e-5, atol=1e-5) + test_run(1, 4, 16, 4, 1, 1) + test_run(2, 4, 16, 4, 4, 1) + + if __name__ == "__main__": test_resize_infer_type() test_resize() @@ -501,3 +577,4 @@ def verify_yolo_reorg(shape, stride): test_yolo_reorg_infer_shape() test_yolo_reorg() test_non_max_suppression() + test_deformable_conv2d() diff --git a/tests/python/relay/test_param_dict.py b/tests/python/relay/test_param_dict.py index b398ea8ba2f5..4161b908c7a8 100644 --- a/tests/python/relay/test_param_dict.py +++ b/tests/python/relay/test_param_dict.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import os import numpy as np import tvm diff --git a/tests/python/relay/test_pass_alpha_equal.py b/tests/python/relay/test_pass_alpha_equal.py index ca86aaa3313e..f00dc85eb7f8 100644 --- a/tests/python/relay/test_pass_alpha_equal.py +++ b/tests/python/relay/test_pass_alpha_equal.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np from tvm import relay diff --git a/tests/python/relay/test_pass_alter_op_layout.py b/tests/python/relay/test_pass_alter_op_layout.py index 7771f808cc75..0f21288245d9 100644 --- a/tests/python/relay/test_pass_alter_op_layout.py +++ b/tests/python/relay/test_pass_alter_op_layout.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test alter op layout pass""" from tvm import relay @@ -446,7 +462,7 @@ def expected(): a = infer_type(a) a = canonicalize_ops(a) a = infer_type(a) - + a = alter_op_layout(a) a = infer_type(a) diff --git a/tests/python/relay/test_pass_annotation.py b/tests/python/relay/test_pass_annotation.py index 3e1098af8d11..ebf9ba913cac 100644 --- a/tests/python/relay/test_pass_annotation.py +++ b/tests/python/relay/test_pass_annotation.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Unit tests for heterogeneous compilation and execution.""" import json import numpy as np diff --git a/tests/python/relay/test_pass_check_kind.py b/tests/python/relay/test_pass_check_kind.py index 4eab59a6edd0..4d9a2e77eae2 100644 --- a/tests/python/relay/test_pass_check_kind.py +++ b/tests/python/relay/test_pass_check_kind.py @@ -1,241 +1,257 @@ -import tvm -from tvm import relay -from tvm.relay.ir_pass import check_kind -from nose.tools import raises - - -def test_typevar_kind(): - # returns the same kind - tp1 = relay.TypeVar('tp1', relay.Kind.Type) - tp2 = relay.TypeVar('tp2', relay.Kind.Shape) - tp3 = relay.TypeVar('tp3', relay.Kind.Constraint) - - assert check_kind(tp1) == relay.Kind.Type - assert check_kind(tp2) == relay.Kind.Shape - assert check_kind(tp3) == relay.Kind.Constraint - - -def test_tuple_kind(): - # only contain type kinds - tp = relay.TypeVar('tp', relay.Kind.Type) - tt = relay.TensorType(tvm.convert([1, 2, 3]), 'float32') - tf = relay.FuncType(tvm.convert([]), tt, tvm.convert([]), tvm.convert([])) - fields = tvm.convert([tp, tf, tt]) - - tup_ty = relay.TupleType(fields) - assert check_kind(tup_ty) == relay.Kind.Type - - -def test_func_kind(): - # only contain type kinds - tp1 = relay.TypeVar('tp1', relay.Kind.Type) - tp2 = relay.TypeVar('tp2', relay.Kind.Type) - - shape = tvm.convert([1, 2, 3]) - dtype = 'float32' - tensor_type = relay.TensorType(shape, dtype) - - tr = relay.TypeRelation(None, tvm.convert([tensor_type, tp1]) , 1, None) - - type_params = tvm.convert([tp1, tp2]) - type_constraints = tvm.convert([tr]) - arg_types = tvm.convert([tp1, tensor_type]) - ret_type = relay.TupleType(tvm.convert([tp2, tensor_type])) - - tf = relay.FuncType(arg_types, ret_type, type_params, type_constraints) - assert check_kind(tf) == relay.Kind.Type - - -def test_ref_kind(): - # only contain type kinds - tt = relay.TensorType(tvm.convert([1, 2, 3]), 'float32') - ft = relay.FuncType(tvm.convert([]), tt, tvm.convert([]), tvm.convert([])) - - rt1 = relay.RefType(tt) - assert check_kind(rt1) == relay.Kind.Type - rt2 = relay.RefType(ft) - assert check_kind(rt2) == relay.Kind.Type - rt3 = relay.RefType(relay.TupleType([rt1, rt2])) - assert check_kind(rt3) == relay.Kind.Type - - -def test_relation_kind(): - # only have type kinds for arguments - tp = relay.TypeVar('tp', relay.Kind.Type) - tt = relay.TensorType(tvm.convert([1, 2, 3]), 'float32') - tf = relay.FuncType(tvm.convert([]), tt, tvm.convert([]), tvm.convert([])) - args = tvm.convert([tf, tt, tp]) - - tr = relay.TypeRelation(None, args, 2, None) - assert check_kind(tr) == relay.Kind.Constraint - - -def test_global_typevar_kind(): - v1 = relay.GlobalTypeVar('gtv1', relay.Kind.AdtHandle) - v2 = relay.GlobalTypeVar('gtv2', relay.Kind.Type) - - assert check_kind(v1) == relay.Kind.AdtHandle - assert check_kind(v2) == relay.Kind.Type - - -def test_typecall_kind(): - gtv = relay.GlobalTypeVar('gtv') - - mod = relay.Module() - data = relay.TypeData(gtv, [], []) - mod[gtv] = data - empty_call = relay.TypeCall(gtv, []) - assert check_kind(empty_call, mod) == relay.Kind.Type - - new_mod = relay.Module() - tv = relay.TypeVar('tv') - new_data = relay.TypeData(gtv, [tv], []) - new_mod[gtv] = new_data - call = relay.TypeCall(gtv, [relay.TupleType([])]) - assert check_kind(call, new_mod) == relay.Kind.Type - - -@raises(tvm._ffi.base.TVMError) -def test_invalid_tuple_kind(): - tp1 = relay.TypeVar('tp1', relay.Kind.Shape) - tp2 = relay.TypeVar('tp2', relay.Kind.BaseType) - tp3 = relay.TypeVar('tp3', relay.Kind.ShapeVar) - fields = tvm.convert([tp1, tp2, tp3]) - - tup_ty = relay.TupleType(fields) - check_kind(tup_ty) - - -@raises(tvm._ffi.base.TVMError) -def test_invalid_func_kind(): - tp1 = relay.TypeVar('tp1', relay.Kind.Shape) - tp2 = relay.TypeVar('tp2', relay.Kind.BaseType) - tp3 = relay.TypeVar('tp3', relay.Kind.ShapeVar) - - type_params = tvm.convert([tp1, tp2, tp3]) - type_constraints = tvm.convert([]) - arg_types = tvm.convert([tp1, tp2]) - ret_type = tp3 - - tf = relay.FuncType(arg_types, ret_type, type_params, type_constraints) - check_kind(tf) - - -@raises(tvm._ffi.base.TVMError) -def test_invalid_ref_kind(): - tp = relay.TypeVar('tp', relay.Kind.Shape) - rt = relay.RefType(tp) - check_kind(rt) - - -@raises(tvm._ffi.base.TVMError) -def test_invalid_relation_kind(): - tp1 = relay.TypeVar('tp1', relay.Kind.Shape) - tp2 = relay.TypeVar('tp2', relay.Kind.BaseType) - tp3 = relay.TypeVar('tp3', relay.Kind.ShapeVar) - args = tvm.convert([tp1, tp2, tp3]) - - func = tvm.get_env_func("tvm.relay.type_relation.Broadcast") - tr = relay.TypeRelation(func, args, 2, None) - check_kind(tr) - - -@raises(tvm._ffi.base.TVMError) -def test_typecall_invalid_callee(): - # global type var must be an ADT handle - gtv = relay.GlobalTypeVar('v1', relay.Kind.Type) - check_kind(relay.TypeCall(gtv, [])) - - -@raises(tvm._ffi.base.TVMError) -def test_typecall_invalid_args(): - # args must all be type kind - mod = relay.Module() - gtv = relay.GlobalTypeVar('v1') - data = relay.TypeData(gtv, [], []) - mod[gtv] = data - - check_kind(relay.TypeCall(gtv, [data])) - - -@raises(tvm._ffi.base.TVMError) -def test_typecall_invalid_num_args(): - mod = relay.Module() - gtv = relay.GlobalTypeVar('v1') - tv = relay.TypeVar('tv') - data = relay.TypeData(gtv, [tv], []) - mod[gtv] = data - check_kind(relay.TypeCall(gtv, [])) - - -@raises(tvm._ffi.base.TVMError) -def test_func_with_invalid_ret_type(): - tp1 = relay.TypeVar('tp1', relay.Kind.Type) - tp2 = relay.TypeVar('tp2', relay.Kind.Shape) - tf = relay.FuncType(tvm.convert([tp1]), tp2, tvm.convert([tp1, tp2]), tvm.convert([])) - - check_kind(tf) - - -@raises(tvm._ffi.base.TVMError) -def test_func_with_invalid_arg_types(): - tp1 = relay.TypeVar('tp1', relay.Kind.Shape) - tp2 = relay.TypeVar('tp2', relay.Kind.Type) - tf = relay.FuncType(tvm.convert([tp1]), tp2, tvm.convert([tp1, tp2]), tvm.convert([])) - - check_kind(tf) - - -@raises(tvm._ffi.base.TVMError) -def test_func_with_invalid_tuple(): - tp1 = relay.TypeVar('tp1', relay.Kind.Shape) - - ret_type = relay.TupleType(tvm.convert([tp1, tp1, tp1])) - - tf = relay.FuncType(tvm.convert([]), ret_type, tvm.convert([tp1]), tvm.convert([])) - check_kind(tf) - - -@raises(tvm._ffi.base.TVMError) -def test_func_with_invalid_relation(): - tp1 = relay.TypeVar('tp1', relay.Kind.Type) - tp2 = relay.TypeVar('tp2', relay.Kind.Shape) - tp3 = relay.TypeVar('tp3', relay.Kind.ShapeVar) - - func = tvm.get_env_func("tvm.relay.type_relation.Identity") - tr = relay.TypeRelation(func, tvm.convert([tp2, tp3]), 1, None) - - tf = relay.FuncType(tvm.convert([tp1]), tp1, tvm.convert([tp1, tp2, tp3]), tvm.convert([tr])) - check_kind(tf) - - -@raises(tvm._ffi.base.TVMError) -def test_tuple_with_invalid_func(): - tensor_type = relay.TensorType(tvm.convert([1, 2, 3]), 'float32') - - tp1 = relay.TypeVar('tp1', relay.Kind.Shape) - tf = relay.FuncType(tvm.convert([]), tp1, tvm.convert([tp1]), tvm.convert([])) - - tup_ty = relay.TupleType(tvm.convert([tensor_type, tf])) - check_kind(tup_ty) - - -if __name__ == "__main__": - test_tuple_kind() - test_func_kind() - test_ref_kind() - test_relation_kind() - test_global_typevar_kind() - test_typecall_kind() - test_invalid_tuple_kind() - test_invalid_func_kind() - test_invalid_ref_kind() - test_invalid_relation_kind() - test_typecall_invalid_callee() - test_typecall_invalid_args() - test_typecall_invalid_num_args() - test_func_with_invalid_ret_type() - test_func_with_invalid_arg_types() - test_func_with_invalid_tuple() - test_func_with_invalid_relation() - test_tuple_with_invalid_func() +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +import tvm +from tvm import relay +from tvm.relay.ir_pass import check_kind +from nose.tools import raises + + +def test_typevar_kind(): + # returns the same kind + tp1 = relay.TypeVar('tp1', relay.Kind.Type) + tp2 = relay.TypeVar('tp2', relay.Kind.Shape) + tp3 = relay.TypeVar('tp3', relay.Kind.Constraint) + + assert check_kind(tp1) == relay.Kind.Type + assert check_kind(tp2) == relay.Kind.Shape + assert check_kind(tp3) == relay.Kind.Constraint + + +def test_tuple_kind(): + # only contain type kinds + tp = relay.TypeVar('tp', relay.Kind.Type) + tt = relay.TensorType(tvm.convert([1, 2, 3]), 'float32') + tf = relay.FuncType(tvm.convert([]), tt, tvm.convert([]), tvm.convert([])) + fields = tvm.convert([tp, tf, tt]) + + tup_ty = relay.TupleType(fields) + assert check_kind(tup_ty) == relay.Kind.Type + + +def test_func_kind(): + # only contain type kinds + tp1 = relay.TypeVar('tp1', relay.Kind.Type) + tp2 = relay.TypeVar('tp2', relay.Kind.Type) + + shape = tvm.convert([1, 2, 3]) + dtype = 'float32' + tensor_type = relay.TensorType(shape, dtype) + + tr = relay.TypeRelation(None, tvm.convert([tensor_type, tp1]) , 1, None) + + type_params = tvm.convert([tp1, tp2]) + type_constraints = tvm.convert([tr]) + arg_types = tvm.convert([tp1, tensor_type]) + ret_type = relay.TupleType(tvm.convert([tp2, tensor_type])) + + tf = relay.FuncType(arg_types, ret_type, type_params, type_constraints) + assert check_kind(tf) == relay.Kind.Type + + +def test_ref_kind(): + # only contain type kinds + tt = relay.TensorType(tvm.convert([1, 2, 3]), 'float32') + ft = relay.FuncType(tvm.convert([]), tt, tvm.convert([]), tvm.convert([])) + + rt1 = relay.RefType(tt) + assert check_kind(rt1) == relay.Kind.Type + rt2 = relay.RefType(ft) + assert check_kind(rt2) == relay.Kind.Type + rt3 = relay.RefType(relay.TupleType([rt1, rt2])) + assert check_kind(rt3) == relay.Kind.Type + + +def test_relation_kind(): + # only have type kinds for arguments + tp = relay.TypeVar('tp', relay.Kind.Type) + tt = relay.TensorType(tvm.convert([1, 2, 3]), 'float32') + tf = relay.FuncType(tvm.convert([]), tt, tvm.convert([]), tvm.convert([])) + args = tvm.convert([tf, tt, tp]) + + tr = relay.TypeRelation(None, args, 2, None) + assert check_kind(tr) == relay.Kind.Constraint + + +def test_global_typevar_kind(): + v1 = relay.GlobalTypeVar('gtv1', relay.Kind.AdtHandle) + v2 = relay.GlobalTypeVar('gtv2', relay.Kind.Type) + + assert check_kind(v1) == relay.Kind.AdtHandle + assert check_kind(v2) == relay.Kind.Type + + +def test_typecall_kind(): + gtv = relay.GlobalTypeVar('gtv') + + mod = relay.Module() + data = relay.TypeData(gtv, [], []) + mod[gtv] = data + empty_call = relay.TypeCall(gtv, []) + assert check_kind(empty_call, mod) == relay.Kind.Type + + new_mod = relay.Module() + tv = relay.TypeVar('tv') + new_data = relay.TypeData(gtv, [tv], []) + new_mod[gtv] = new_data + call = relay.TypeCall(gtv, [relay.TupleType([])]) + assert check_kind(call, new_mod) == relay.Kind.Type + + +@raises(tvm._ffi.base.TVMError) +def test_invalid_tuple_kind(): + tp1 = relay.TypeVar('tp1', relay.Kind.Shape) + tp2 = relay.TypeVar('tp2', relay.Kind.BaseType) + tp3 = relay.TypeVar('tp3', relay.Kind.ShapeVar) + fields = tvm.convert([tp1, tp2, tp3]) + + tup_ty = relay.TupleType(fields) + check_kind(tup_ty) + + +@raises(tvm._ffi.base.TVMError) +def test_invalid_func_kind(): + tp1 = relay.TypeVar('tp1', relay.Kind.Shape) + tp2 = relay.TypeVar('tp2', relay.Kind.BaseType) + tp3 = relay.TypeVar('tp3', relay.Kind.ShapeVar) + + type_params = tvm.convert([tp1, tp2, tp3]) + type_constraints = tvm.convert([]) + arg_types = tvm.convert([tp1, tp2]) + ret_type = tp3 + + tf = relay.FuncType(arg_types, ret_type, type_params, type_constraints) + check_kind(tf) + + +@raises(tvm._ffi.base.TVMError) +def test_invalid_ref_kind(): + tp = relay.TypeVar('tp', relay.Kind.Shape) + rt = relay.RefType(tp) + check_kind(rt) + + +@raises(tvm._ffi.base.TVMError) +def test_invalid_relation_kind(): + tp1 = relay.TypeVar('tp1', relay.Kind.Shape) + tp2 = relay.TypeVar('tp2', relay.Kind.BaseType) + tp3 = relay.TypeVar('tp3', relay.Kind.ShapeVar) + args = tvm.convert([tp1, tp2, tp3]) + + func = tvm.get_env_func("tvm.relay.type_relation.Broadcast") + tr = relay.TypeRelation(func, args, 2, None) + check_kind(tr) + + +@raises(tvm._ffi.base.TVMError) +def test_typecall_invalid_callee(): + # global type var must be an ADT handle + gtv = relay.GlobalTypeVar('v1', relay.Kind.Type) + check_kind(relay.TypeCall(gtv, [])) + + +@raises(tvm._ffi.base.TVMError) +def test_typecall_invalid_args(): + # args must all be type kind + mod = relay.Module() + gtv = relay.GlobalTypeVar('v1') + data = relay.TypeData(gtv, [], []) + mod[gtv] = data + + check_kind(relay.TypeCall(gtv, [data])) + + +@raises(tvm._ffi.base.TVMError) +def test_typecall_invalid_num_args(): + mod = relay.Module() + gtv = relay.GlobalTypeVar('v1') + tv = relay.TypeVar('tv') + data = relay.TypeData(gtv, [tv], []) + mod[gtv] = data + check_kind(relay.TypeCall(gtv, [])) + + +@raises(tvm._ffi.base.TVMError) +def test_func_with_invalid_ret_type(): + tp1 = relay.TypeVar('tp1', relay.Kind.Type) + tp2 = relay.TypeVar('tp2', relay.Kind.Shape) + tf = relay.FuncType(tvm.convert([tp1]), tp2, tvm.convert([tp1, tp2]), tvm.convert([])) + + check_kind(tf) + + +@raises(tvm._ffi.base.TVMError) +def test_func_with_invalid_arg_types(): + tp1 = relay.TypeVar('tp1', relay.Kind.Shape) + tp2 = relay.TypeVar('tp2', relay.Kind.Type) + tf = relay.FuncType(tvm.convert([tp1]), tp2, tvm.convert([tp1, tp2]), tvm.convert([])) + + check_kind(tf) + + +@raises(tvm._ffi.base.TVMError) +def test_func_with_invalid_tuple(): + tp1 = relay.TypeVar('tp1', relay.Kind.Shape) + + ret_type = relay.TupleType(tvm.convert([tp1, tp1, tp1])) + + tf = relay.FuncType(tvm.convert([]), ret_type, tvm.convert([tp1]), tvm.convert([])) + check_kind(tf) + + +@raises(tvm._ffi.base.TVMError) +def test_func_with_invalid_relation(): + tp1 = relay.TypeVar('tp1', relay.Kind.Type) + tp2 = relay.TypeVar('tp2', relay.Kind.Shape) + tp3 = relay.TypeVar('tp3', relay.Kind.ShapeVar) + + func = tvm.get_env_func("tvm.relay.type_relation.Identity") + tr = relay.TypeRelation(func, tvm.convert([tp2, tp3]), 1, None) + + tf = relay.FuncType(tvm.convert([tp1]), tp1, tvm.convert([tp1, tp2, tp3]), tvm.convert([tr])) + check_kind(tf) + + +@raises(tvm._ffi.base.TVMError) +def test_tuple_with_invalid_func(): + tensor_type = relay.TensorType(tvm.convert([1, 2, 3]), 'float32') + + tp1 = relay.TypeVar('tp1', relay.Kind.Shape) + tf = relay.FuncType(tvm.convert([]), tp1, tvm.convert([tp1]), tvm.convert([])) + + tup_ty = relay.TupleType(tvm.convert([tensor_type, tf])) + check_kind(tup_ty) + + +if __name__ == "__main__": + test_tuple_kind() + test_func_kind() + test_ref_kind() + test_relation_kind() + test_global_typevar_kind() + test_typecall_kind() + test_invalid_tuple_kind() + test_invalid_func_kind() + test_invalid_ref_kind() + test_invalid_relation_kind() + test_typecall_invalid_callee() + test_typecall_invalid_args() + test_typecall_invalid_num_args() + test_func_with_invalid_ret_type() + test_func_with_invalid_arg_types() + test_func_with_invalid_tuple() + test_func_with_invalid_relation() + test_tuple_with_invalid_func() diff --git a/tests/python/relay/test_pass_combine_parallel_conv2d.py b/tests/python/relay/test_pass_combine_parallel_conv2d.py index 7d0a5a08555e..0d6e1e39b509 100644 --- a/tests/python/relay/test_pass_combine_parallel_conv2d.py +++ b/tests/python/relay/test_pass_combine_parallel_conv2d.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. from tvm import relay import numpy as np diff --git a/tests/python/relay/test_pass_dead_code_elimination.py b/tests/python/relay/test_pass_dead_code_elimination.py index b88f6500de1a..9014a47f2ef3 100644 --- a/tests/python/relay/test_pass_dead_code_elimination.py +++ b/tests/python/relay/test_pass_dead_code_elimination.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm from tvm import relay from tvm.relay.ir_pass import dead_code_elimination, alpha_equal diff --git a/tests/python/relay/test_pass_eliminate_common_subexpr.py b/tests/python/relay/test_pass_eliminate_common_subexpr.py index 381a54a3d324..1ebd834d4da7 100644 --- a/tests/python/relay/test_pass_eliminate_common_subexpr.py +++ b/tests/python/relay/test_pass_eliminate_common_subexpr.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test eliminate common subexpr pass""" from tvm import relay from tvm.relay.op import register_alter_op_layout diff --git a/tests/python/relay/test_pass_fold_constant.py b/tests/python/relay/test_pass_fold_constant.py index 315a83a92a35..2abeaa8f8db8 100644 --- a/tests/python/relay/test_pass_fold_constant.py +++ b/tests/python/relay/test_pass_fold_constant.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import tvm from tvm import relay diff --git a/tests/python/relay/test_pass_fold_scale_axis.py b/tests/python/relay/test_pass_fold_scale_axis.py index dd9e7522fecf..383f0072059f 100644 --- a/tests/python/relay/test_pass_fold_scale_axis.py +++ b/tests/python/relay/test_pass_fold_scale_axis.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. from tvm import relay import numpy as np diff --git a/tests/python/relay/test_pass_fuse_ops.py b/tests/python/relay/test_pass_fuse_ops.py index 634d69bae823..baafbeebd560 100644 --- a/tests/python/relay/test_pass_fuse_ops.py +++ b/tests/python/relay/test_pass_fuse_ops.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm from tvm import relay @@ -217,7 +233,6 @@ def expected(dshape): assert not relay.ir_pass.free_vars(zz) after = relay.ir_pass.infer_type(expected(dshape)) assert relay.ir_pass.alpha_equal(zz, after) - print(zz.astext()) def test_stop_fusion(): @@ -287,6 +302,81 @@ def expected(dshape, dtype): assert relay.ir_pass.alpha_equal(f, after) +def test_fuse_tuple_get_elemwise(): + def before(dim): + X = relay.var("X", shape=(1, dim)) + W = relay.var("W", shape=(3 * dim, dim)) + matmul = relay.nn.dense(X, W) + splitted = relay.split(matmul, indices_or_sections=3, axis=1) + out = relay.sigmoid(splitted[0]) + relay.tanh(splitted[1]) * relay.exp(splitted[2]) + return relay.Function([X, W], out) + + def expected(dim): + p0 = relay.var("p0", shape=(1, dim)) + p1 = relay.var("p1", shape=(3 * dim, dim)) + matmul = relay.nn.dense(p0, p1) + f0 = relay.Function([p0, p1], matmul) + + p01 = relay.var("p01", shape=(1, 3 * dim)) + splitted = relay.split(p01, indices_or_sections=3, axis=1) + out = relay.sigmoid(splitted[0]) + relay.tanh(splitted[1]) * relay.exp(splitted[2]) + f1 = relay.Function([p01], out) + + X = relay.var("X", shape=(1, dim)) + W = relay.var("W", shape=(3 * dim, dim)) + y = relay.Call(f0, [X, W]) + z = relay.Call(f1, [y]) + return relay.Function([X, W], z) + + dim = 10 + z = before(dim) + z = relay.ir_pass.infer_type(z) + zz = relay.ir_pass.fuse_ops(z, opt_level=0) + assert not relay.ir_pass.free_vars(zz) + zz = relay.ir_pass.fuse_ops(z, opt_level=2) + zz = relay.ir_pass.infer_type(zz) + assert not relay.ir_pass.free_vars(zz) + after = relay.ir_pass.infer_type(expected(dim)) + assert relay.ir_pass.alpha_equal(zz, after) + + +def test_tuple_get_root(): + def before(dim): + X = relay.var("X", shape=(1, 3 * dim)) + W = relay.var("W", shape=(dim, dim)) + splitted = relay.split(X, indices_or_sections=3, axis=1) + out = relay.nn.dense(splitted[0], W) + return relay.Function([X, W], out) + + def expected(dim): + p0 = relay.var("p0", shape=(1, 3 * dim)) + splitted = relay.split(p0, indices_or_sections=3, axis=1) + out = splitted[0] + f0 = relay.Function([p0], out) + + p01 = relay.var("p01", shape=(1, dim)) + p1 = relay.var("p1", shape=(dim, dim)) + out = relay.nn.dense(p01, p1) + f1 = relay.Function([p01, p1], out) + + X = relay.var("X", shape=(1, 3 * dim)) + W = relay.var("W", shape=(dim, dim)) + y = relay.Call(f0, [X]) + z = relay.Call(f1, [y, W]) + return relay.Function([X, W], z) + + dim = 10 + z = before(dim) + z = relay.ir_pass.infer_type(z) + zz = relay.ir_pass.fuse_ops(z, opt_level=0) + assert not relay.ir_pass.free_vars(zz) + zz = relay.ir_pass.fuse_ops(z, opt_level=2) + zz = relay.ir_pass.infer_type(zz) + assert not relay.ir_pass.free_vars(zz) + after = relay.ir_pass.infer_type(expected(dim)) + assert relay.ir_pass.alpha_equal(zz, after) + + if __name__ == "__main__": test_fuse_simple() test_conv2d_fuse() @@ -295,3 +385,5 @@ def expected(dshape, dtype): test_tuple_strided_slice() test_stop_fusion() test_fuse_myia_regression() + test_fuse_tuple_get_elemwise() + test_tuple_get_root() diff --git a/tests/python/relay/test_pass_gradient.py b/tests/python/relay/test_pass_gradient.py index 400941f12617..d6489a8f3377 100644 --- a/tests/python/relay/test_pass_gradient.py +++ b/tests/python/relay/test_pass_gradient.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm from tvm import relay from tvm.relay.ir_pass import free_vars, free_type_vars, gradient @@ -20,8 +36,8 @@ def test_id(): ex = create_executor() x = rand(dtype, *shape) forward, (grad,) = ex.evaluate(back_func)(x) - np.testing.assert_allclose(forward.asnumpy(), x.asnumpy()) - np.testing.assert_allclose(grad.asnumpy(), np.ones_like(x.asnumpy())) + tvm.testing.assert_allclose(forward.asnumpy(), x.asnumpy()) + tvm.testing.assert_allclose(grad.asnumpy(), np.ones_like(x.asnumpy())) def test_add(): @@ -35,8 +51,8 @@ def test_add(): ex = create_executor() x = rand(dtype, *shape) forward, (grad,) = ex.evaluate(back_func)(x) - np.testing.assert_allclose(forward.asnumpy(), 2 * x.asnumpy()) - np.testing.assert_allclose(grad.asnumpy(), 2 * np.ones_like(x.asnumpy())) + tvm.testing.assert_allclose(forward.asnumpy(), 2 * x.asnumpy()) + tvm.testing.assert_allclose(grad.asnumpy(), 2 * np.ones_like(x.asnumpy())) def test_temp_add(): @@ -51,8 +67,8 @@ def test_temp_add(): ex = create_executor() x = rand(dtype, *shape) forward, (grad,) = ex.evaluate(back_func)(x) - np.testing.assert_allclose(forward.asnumpy(), 4 * x.asnumpy()) - np.testing.assert_allclose(grad.asnumpy(), 4 * np.ones_like(x.asnumpy())) + tvm.testing.assert_allclose(forward.asnumpy(), 4 * x.asnumpy()) + tvm.testing.assert_allclose(grad.asnumpy(), 4 * np.ones_like(x.asnumpy())) def test_sub(): @@ -66,8 +82,8 @@ def test_sub(): ex = create_executor() x = rand(dtype, *shape) forward, (grad,) = ex.evaluate(back_func)(x) - np.testing.assert_allclose(forward.asnumpy(), np.zeros_like(x.asnumpy())) - np.testing.assert_allclose(grad.asnumpy(), np.zeros_like(x.asnumpy())) + tvm.testing.assert_allclose(forward.asnumpy(), np.zeros_like(x.asnumpy())) + tvm.testing.assert_allclose(grad.asnumpy(), np.zeros_like(x.asnumpy())) def test_broadcast_add(): @@ -90,11 +106,11 @@ def test_broadcast_add(): relay.TupleType([t1, t2])])) ex = create_executor() forward, (grad_x, grad_y) = ex.evaluate(full_func)(x_nd, y_nd) - np.testing.assert_allclose(forward.asnumpy(), expected_forward) - np.testing.assert_allclose(grad_x.asnumpy(), - np.ones_like(expected_forward).sum(axis=2, keepdims=True)) - np.testing.assert_allclose(grad_y.asnumpy(), - np.ones_like(expected_forward).sum(axis=(0, 1), keepdims=True).squeeze(axis=0)) + tvm.testing.assert_allclose(forward.asnumpy(), expected_forward) + tvm.testing.assert_allclose(grad_x.asnumpy(), + np.ones_like(expected_forward).sum(axis=2, keepdims=True)) + tvm.testing.assert_allclose(grad_y.asnumpy(), + np.ones_like(expected_forward).sum(axis=(0, 1), keepdims=True).squeeze(axis=0)) def test_broadcast_subtract(): @@ -117,11 +133,11 @@ def test_broadcast_subtract(): relay.TupleType([t1, t2])])) ex = create_executor() forward, (grad_x, grad_y) = ex.evaluate(full_func)(x_nd, y_nd) - np.testing.assert_allclose(forward.asnumpy(), expected_forward) - np.testing.assert_allclose(grad_x.asnumpy(), - np.ones_like(expected_forward).sum(axis=2, keepdims=True)) - np.testing.assert_allclose(grad_y.asnumpy(), - -np.ones_like(expected_forward).sum(axis=(0, 1), keepdims=True).squeeze(axis=0)) + tvm.testing.assert_allclose(forward.asnumpy(), expected_forward) + tvm.testing.assert_allclose(grad_x.asnumpy(), + np.ones_like(expected_forward).sum(axis=2, keepdims=True)) + tvm.testing.assert_allclose(grad_y.asnumpy(), + -np.ones_like(expected_forward).sum(axis=(0, 1), keepdims=True).squeeze(axis=0)) def test_tuple(): @@ -147,10 +163,10 @@ def test_tuple(): expected_forward = x_np + y_np - z_np ex = create_executor() forward, (grad_x, grad_y, grad_z) = ex.evaluate(back_func)(x_nd, y_nd, z_nd) - np.testing.assert_allclose(forward.asnumpy(), expected_forward) - np.testing.assert_allclose(grad_x.asnumpy(), np.ones_like(grad_x.asnumpy())) - np.testing.assert_allclose(grad_y.asnumpy(), np.ones_like(grad_y.asnumpy())) - np.testing.assert_allclose(grad_z.asnumpy(), -1 * np.ones_like(grad_z.asnumpy())) + tvm.testing.assert_allclose(forward.asnumpy(), expected_forward) + tvm.testing.assert_allclose(grad_x.asnumpy(), np.ones_like(grad_x.asnumpy())) + tvm.testing.assert_allclose(grad_y.asnumpy(), np.ones_like(grad_y.asnumpy())) + tvm.testing.assert_allclose(grad_z.asnumpy(), -1 * np.ones_like(grad_z.asnumpy())) def test_pow(): @@ -168,8 +184,9 @@ def test_pow(): i_nd = rand(dtype, *shape) ex = create_executor(mod=mod) forward, (grad_i,) = ex.evaluate(back_func)(i_nd) - np.testing.assert_allclose(forward.asnumpy(), 8 * i_nd.asnumpy()) - np.testing.assert_allclose(grad_i.asnumpy(), 8 * np.ones_like(grad_i.asnumpy())) + tvm.testing.assert_allclose(forward.asnumpy(), 8 * i_nd.asnumpy()) + tvm.testing.assert_allclose(grad_i.asnumpy(), 8 * np.ones_like(grad_i.asnumpy())) + def test_ref(): shape = (10, 10) @@ -187,8 +204,28 @@ def test_ref(): x_nd = rand(dtype, *shape) ex = create_executor() forward, (grad_x,) = ex.evaluate(back_func)(x_nd) - np.testing.assert_allclose(forward.asnumpy(), 2 * x_nd.asnumpy()) - np.testing.assert_allclose(grad_x.asnumpy(), 2 * np.ones_like(grad_x.asnumpy())) + tvm.testing.assert_allclose(forward.asnumpy(), 2 * x_nd.asnumpy()) + tvm.testing.assert_allclose(grad_x.asnumpy(), 2 * np.ones_like(grad_x.asnumpy())) + + +def test_square_second_order(): + shape = (10, 10) + dtype = 'float32' + t = relay.TensorType(shape, dtype) + x = relay.var("x", t) + func = relay.Function([x], x * x) + back_func = relay.ir_pass.infer_type(gradient(func)) + y = relay.var("y", t) + back_func_adjusted = relay.Function([y], relay.TupleGetItem(relay.TupleGetItem(back_func(y), 1), 0)) + back_func_adjusted = relay.ir_pass.infer_type(back_func_adjusted) + back_back_func = relay.ir_pass.infer_type(gradient(back_func_adjusted)) + assert back_func.checked_type == relay.FuncType([t], relay.TupleType([t, relay.TupleType([t])])) + x_nd = rand(dtype, *shape) + ex = create_executor() + forward, (grad_x,) = ex.evaluate(back_back_func)(x_nd) + tvm.testing.assert_allclose(forward.asnumpy(), 2 * x_nd.asnumpy()) + tvm.testing.assert_allclose(grad_x.asnumpy(), 2 * np.ones_like(grad_x.asnumpy())) + if __name__ == "__main__": test_id() @@ -200,3 +237,4 @@ def test_ref(): test_tuple() test_pow() test_ref() + test_square_second_order() diff --git a/tests/python/relay/test_pass_mac_count.py b/tests/python/relay/test_pass_mac_count.py index 0c0144e246d3..5a975fd41364 100644 --- a/tests/python/relay/test_pass_mac_count.py +++ b/tests/python/relay/test_pass_mac_count.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Unit tests for MAC counter.""" import tvm from tvm import relay diff --git a/tests/python/relay/test_pass_manager.py b/tests/python/relay/test_pass_manager.py index 7b6f9a1d9ec5..b8216775ee1c 100644 --- a/tests/python/relay/test_pass_manager.py +++ b/tests/python/relay/test_pass_manager.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Unit tests for relay pass manager.""" import numpy as np diff --git a/tests/python/relay/test_pass_quantize.py b/tests/python/relay/test_pass_quantize.py index edff37e46d32..a9a683c43263 100644 --- a/tests/python/relay/test_pass_quantize.py +++ b/tests/python/relay/test_pass_quantize.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import math import numpy as np import tvm @@ -38,40 +54,40 @@ def test_simulated_quantize(): # out = np.around(arr.asnumpy() / scale * 128).astype('int8') # out = np.clip(out, -127, 127) # return relay.const(out, 'int8') -# +# # n, c, h, w = 1, 3, 224, 224 # def make_graph(data): # weight = relay.var("conv_weight") # out = relay.nn.conv2d(data, weight, kernel_size=(3, 3), padding=(1, 1), channels=c) # out = relay.Function(relay.ir_pass.free_vars(out), out) # return out -# +# # def make_qgraph(data, weight): # out = data * relay.const(32.0) # out = relay.round(out) # out = relay.clip(out, a_min=-127, a_max=127) # out = out.astype('int8') -# +# # out = relay.nn.conv2d(out, weight, kernel_size=(3, 3), # padding=(1, 1), channels=c, out_dtype='int32') # out = out.astype('float32') # out = relay.multiply(out, relay.const(0.00024414062)) # out = relay.Function(relay.ir_pass.free_vars(out), out) # return out -# +# # data = relay.var("data", relay.TensorType((n, c, h, w), "float32")) # graph = make_graph(data) # dataset, params = make_dataset(graph, 10) -# +# # with qtz.qconfig(skip_k_conv=0, global_scale=4.0, # round_for_shift=False, store_lowbit_output=False): # qgraph0 = qtz.quantize(graph, params) # qgraph0 = relay.ir_pass.infer_type(qgraph0) -# +# # conv_weight = quantize_weight(params['conv_weight']) # qgraph1 = make_qgraph(data, conv_weight) # qgraph1 = relay.ir_pass.infer_type(qgraph1) -# +# # graph = relay.create_executor('graph') # res0 = graph.evaluate(qgraph0)(dataset[0]['data']) # res1 = graph.evaluate(qgraph1)(dataset[0]['data']) diff --git a/tests/python/relay/test_pass_simplify_inference.py b/tests/python/relay/test_pass_simplify_inference.py index 7585a88063ab..1387f276b290 100644 --- a/tests/python/relay/test_pass_simplify_inference.py +++ b/tests/python/relay/test_pass_simplify_inference.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. from tvm import relay as rly from tvm.relay.ir_pass import simplify_inference, alpha_equal diff --git a/tests/python/relay/test_pass_vars.py b/tests/python/relay/test_pass_vars.py index afdaddca922a..2f1ef36e7878 100644 --- a/tests/python/relay/test_pass_vars.py +++ b/tests/python/relay/test_pass_vars.py @@ -1,178 +1,194 @@ -import tvm -from tvm import relay -from tvm.relay.ir_pass import (free_vars, free_type_vars, - bound_vars, bound_type_vars, - all_vars, all_type_vars) - -def assert_vars_match(actual, expected): - assert len(actual) == len(expected) - for i in range(len(actual)): - assert actual[i] == expected[i] - - -def test_free_vars(): - ty = relay.TensorType([], "int32") - x = relay.Var("x", ty) - fvx = free_vars(x) - assert len(fvx) == 1 - assert fvx[0] == x - v = relay.Constant(tvm.nd.array(10)) - - let = relay.Let(x, v, x) - fvx = free_vars(let) - assert len(free_vars(let)) == 0 - f = relay.Function([x], x, ty) - assert len(free_vars(f)) == 0 - - -def test_free_vars_tuple(): - t = relay.Var('t') - fv = free_vars(relay.Tuple([t, t])) - assert len(fv) == 1 - assert fv[0] == t - fv = free_vars(relay.TupleGetItem(t, 123)) - assert len(fv) == 1 - assert fv[0] == t - - -def test_free_type_vars(): - tp = relay.TypeVar("") - ty = relay.TupleType([tp, relay.TensorType([], "int32")]) - x = relay.Var("x", ty) - y = relay.Var("y") - let = relay.Let(x, y, x) - fvl = free_vars(let) - assert len(fvl) == 1 - assert fvl[0] == y - ftvl = free_type_vars(let) - assert len(ftvl) == 1 - assert ftvl[0] == tp - - -def test_bound_vars(): - x = relay.Var("x") - y = relay.Var("y") - z = relay.Var("z") - a = relay.Var("a") - - f1 = relay.Function([x, y, z], relay.Let(a, x, relay.Tuple([]))) - assert_vars_match(bound_vars(f1), [x, y, z, a]) - - tup = relay.Tuple([x, y, z, a]) - assert len(bound_vars(tup)) == 0 - - f2 = relay.Function([x, y], relay.Tuple([x, y, z, a])) - assert_vars_match(bound_vars(f2), [x, y]) - - -def test_match_vars(): - mod = relay.Module() - p = relay.prelude.Prelude(mod) - - x = relay.Var('x') - y = relay.Var('y') - z = relay.Var('z') - - match1 = relay.Match(p.nil(), [ - relay.Clause(relay.PatternConstructor(p.nil), z), - relay.Clause(relay.PatternConstructor(p.cons, - [relay.PatternVar(x), - relay.PatternVar(y)]), - p.cons(x, y)) - ]) - - match2 = relay.Match(p.nil(), [ - relay.Clause(relay.PatternConstructor(p.cons, [ - relay.PatternWildcard(), - relay.PatternVar(x) - ]), - y), - relay.Clause(relay.PatternWildcard(), z) - ]) - - assert_vars_match(bound_vars(match1), [x, y]) - assert_vars_match(free_vars(match1), [z]) - assert_vars_match(all_vars(match1), [z, x, y]) - - assert_vars_match(bound_vars(match2), [x]) - assert_vars_match(free_vars(match2), [y, z]) - assert_vars_match(all_vars(match2), [x, y, z]) - - -def test_bound_type_vars(): - a = relay.TypeVar("a") - b = relay.TypeVar("b") - c = relay.TypeVar("c") - - ft1 = relay.FuncType([a], b, [a, b]) - bound_ft1 = bound_type_vars(ft1) - assert_vars_match(bound_type_vars(ft1), [a, b]) - - ft2 = relay.FuncType([], c, [a]) - assert_vars_match(bound_type_vars(ft2), [a]) - - tup_ty = relay.TupleType([a, b, c]) - assert len(bound_type_vars(tup_ty)) == 0 - - f1 = relay.Function([], relay.Tuple([]), type_params=[a, b]) - assert_vars_match(bound_type_vars(f1), [a, b]) - - f2 = relay.Function([], relay.Tuple([]), c) - assert len(bound_type_vars(f2)) == 0 - - x = relay.Var("x", a) - let1 = relay.Let(x, relay.Tuple([]), x) - assert len(bound_type_vars(let1)) == 0 - - let2 = relay.Let(x, relay.Function([], relay.Tuple([]), type_params=[b, c]), x) - assert_vars_match(bound_type_vars(let2), [b, c]) - - -def test_all_vars(): - x = relay.Var("x") - y = relay.Var("y") - z = relay.Var("z") - - f1 = relay.Function([x, y], z) - assert_vars_match(all_vars(f1), [x, y, z]) - - f2 = relay.Function([x], relay.Let(y, relay.Tuple([]), z)) - assert_vars_match(all_vars(f2), [x, y, z]) - - f3 = relay.Function([x], relay.Tuple([y, z])) - assert_vars_match(all_vars(f3), [x, y, z]) - - tup = relay.Tuple([x, y, z]) - assert_vars_match(all_vars(tup), [x, y, z]) - - -def test_all_type_vars(): - a = relay.TypeVar("a") - b = relay.TypeVar("b") - c = relay.TypeVar("c") - - ft1 = relay.FuncType([b], c, [a]) - assert_vars_match(all_type_vars(ft1), [a, b, c]) - - ft2 = relay.FuncType([], relay.TupleType([a, b, c]), []) - assert_vars_match(all_type_vars(ft2), [a, b, c]) - - w = relay.Var("w") - x = relay.Var("x", a) - y = relay.Var("y", b) - z = relay.Var("z", c) - - f1 = relay.Function([x], y, b, [a]) - assert_vars_match(all_type_vars(f1), [a, b]) - - f2 = relay.Function([x], relay.Let(y, x, z)) - assert_vars_match(all_type_vars(f2), [a, b, c]) - - f3 = relay.Function([], relay.Tuple([x, y, z]), ret_type=relay.TupleType([a, b, c])) - assert_vars_match(all_type_vars(f3), [a, b, c]) - - f4 = relay.Function([w], relay.Tuple([]), type_params=[a, b, c]) - assert_vars_match(all_type_vars(f4), [a, b, c]) - - f5 = relay.Function([w], w) - assert len(all_type_vars(f5)) == 0 +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +import tvm +from tvm import relay +from tvm.relay.ir_pass import (free_vars, free_type_vars, + bound_vars, bound_type_vars, + all_vars, all_type_vars) + +def assert_vars_match(actual, expected): + assert len(actual) == len(expected) + for i in range(len(actual)): + assert actual[i] == expected[i] + + +def test_free_vars(): + ty = relay.TensorType([], "int32") + x = relay.Var("x", ty) + fvx = free_vars(x) + assert len(fvx) == 1 + assert fvx[0] == x + v = relay.Constant(tvm.nd.array(10)) + + let = relay.Let(x, v, x) + fvx = free_vars(let) + assert len(free_vars(let)) == 0 + f = relay.Function([x], x, ty) + assert len(free_vars(f)) == 0 + + +def test_free_vars_tuple(): + t = relay.Var('t') + fv = free_vars(relay.Tuple([t, t])) + assert len(fv) == 1 + assert fv[0] == t + fv = free_vars(relay.TupleGetItem(t, 123)) + assert len(fv) == 1 + assert fv[0] == t + + +def test_free_type_vars(): + tp = relay.TypeVar("") + ty = relay.TupleType([tp, relay.TensorType([], "int32")]) + x = relay.Var("x", ty) + y = relay.Var("y") + let = relay.Let(x, y, x) + fvl = free_vars(let) + assert len(fvl) == 1 + assert fvl[0] == y + ftvl = free_type_vars(let) + assert len(ftvl) == 1 + assert ftvl[0] == tp + + +def test_bound_vars(): + x = relay.Var("x") + y = relay.Var("y") + z = relay.Var("z") + a = relay.Var("a") + + f1 = relay.Function([x, y, z], relay.Let(a, x, relay.Tuple([]))) + assert_vars_match(bound_vars(f1), [x, y, z, a]) + + tup = relay.Tuple([x, y, z, a]) + assert len(bound_vars(tup)) == 0 + + f2 = relay.Function([x, y], relay.Tuple([x, y, z, a])) + assert_vars_match(bound_vars(f2), [x, y]) + + +def test_match_vars(): + mod = relay.Module() + p = relay.prelude.Prelude(mod) + + x = relay.Var('x') + y = relay.Var('y') + z = relay.Var('z') + + match1 = relay.Match(p.nil(), [ + relay.Clause(relay.PatternConstructor(p.nil), z), + relay.Clause(relay.PatternConstructor(p.cons, + [relay.PatternVar(x), + relay.PatternVar(y)]), + p.cons(x, y)) + ]) + + match2 = relay.Match(p.nil(), [ + relay.Clause(relay.PatternConstructor(p.cons, [ + relay.PatternWildcard(), + relay.PatternVar(x) + ]), + y), + relay.Clause(relay.PatternWildcard(), z) + ]) + + assert_vars_match(bound_vars(match1), [x, y]) + assert_vars_match(free_vars(match1), [z]) + assert_vars_match(all_vars(match1), [z, x, y]) + + assert_vars_match(bound_vars(match2), [x]) + assert_vars_match(free_vars(match2), [y, z]) + assert_vars_match(all_vars(match2), [x, y, z]) + + +def test_bound_type_vars(): + a = relay.TypeVar("a") + b = relay.TypeVar("b") + c = relay.TypeVar("c") + + ft1 = relay.FuncType([a], b, [a, b]) + bound_ft1 = bound_type_vars(ft1) + assert_vars_match(bound_type_vars(ft1), [a, b]) + + ft2 = relay.FuncType([], c, [a]) + assert_vars_match(bound_type_vars(ft2), [a]) + + tup_ty = relay.TupleType([a, b, c]) + assert len(bound_type_vars(tup_ty)) == 0 + + f1 = relay.Function([], relay.Tuple([]), type_params=[a, b]) + assert_vars_match(bound_type_vars(f1), [a, b]) + + f2 = relay.Function([], relay.Tuple([]), c) + assert len(bound_type_vars(f2)) == 0 + + x = relay.Var("x", a) + let1 = relay.Let(x, relay.Tuple([]), x) + assert len(bound_type_vars(let1)) == 0 + + let2 = relay.Let(x, relay.Function([], relay.Tuple([]), type_params=[b, c]), x) + assert_vars_match(bound_type_vars(let2), [b, c]) + + +def test_all_vars(): + x = relay.Var("x") + y = relay.Var("y") + z = relay.Var("z") + + f1 = relay.Function([x, y], z) + assert_vars_match(all_vars(f1), [x, y, z]) + + f2 = relay.Function([x], relay.Let(y, relay.Tuple([]), z)) + assert_vars_match(all_vars(f2), [x, y, z]) + + f3 = relay.Function([x], relay.Tuple([y, z])) + assert_vars_match(all_vars(f3), [x, y, z]) + + tup = relay.Tuple([x, y, z]) + assert_vars_match(all_vars(tup), [x, y, z]) + + +def test_all_type_vars(): + a = relay.TypeVar("a") + b = relay.TypeVar("b") + c = relay.TypeVar("c") + + ft1 = relay.FuncType([b], c, [a]) + assert_vars_match(all_type_vars(ft1), [a, b, c]) + + ft2 = relay.FuncType([], relay.TupleType([a, b, c]), []) + assert_vars_match(all_type_vars(ft2), [a, b, c]) + + w = relay.Var("w") + x = relay.Var("x", a) + y = relay.Var("y", b) + z = relay.Var("z", c) + + f1 = relay.Function([x], y, b, [a]) + assert_vars_match(all_type_vars(f1), [a, b]) + + f2 = relay.Function([x], relay.Let(y, x, z)) + assert_vars_match(all_type_vars(f2), [a, b, c]) + + f3 = relay.Function([], relay.Tuple([x, y, z]), ret_type=relay.TupleType([a, b, c])) + assert_vars_match(all_type_vars(f3), [a, b, c]) + + f4 = relay.Function([w], relay.Tuple([]), type_params=[a, b, c]) + assert_vars_match(all_type_vars(f4), [a, b, c]) + + f5 = relay.Function([w], w) + assert len(all_type_vars(f5)) == 0 diff --git a/tests/python/relay/test_to_a_normal_form.py b/tests/python/relay/test_to_a_normal_form.py index 392e1769e57d..9e1e8728f131 100644 --- a/tests/python/relay/test_to_a_normal_form.py +++ b/tests/python/relay/test_to_a_normal_form.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import tvm from tvm import relay diff --git a/tests/python/relay/test_to_graph_normal_form.py b/tests/python/relay/test_to_graph_normal_form.py index ac86799b6b8c..75975663a20c 100644 --- a/tests/python/relay/test_to_graph_normal_form.py +++ b/tests/python/relay/test_to_graph_normal_form.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import tvm from tvm import relay diff --git a/tests/python/relay/test_type_infer.py b/tests/python/relay/test_type_infer.py index 8fb83ece0ebd..4dfe59b8a6a3 100644 --- a/tests/python/relay/test_type_infer.py +++ b/tests/python/relay/test_type_infer.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test that type checker correcly computes types for expressions. """ diff --git a/tests/python/relay/test_type_solver.py b/tests/python/relay/test_type_solver.py index 8bcd912f841e..81f0222c029a 100644 --- a/tests/python/relay/test_type_solver.py +++ b/tests/python/relay/test_type_solver.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm from tvm import relay from nose.tools import raises diff --git a/tests/python/relay/test_typecall.py b/tests/python/relay/test_typecall.py index 6f002c438a52..4cb8f4f5d2ce 100644 --- a/tests/python/relay/test_typecall.py +++ b/tests/python/relay/test_typecall.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. from tvm import relay from tvm.relay.ir_pass import infer_type @@ -15,7 +31,7 @@ def test_id_type(): id_type = relay.GlobalTypeVar("id") a = relay.TypeVar("a") mod[id_type] = relay.TypeData(id_type, [a], []) - + b = relay.TypeVar("b") make_id = relay.Var("make_id", relay.FuncType([b], id_type(b), [b])) t = relay.scalar_type("float32") diff --git a/tests/python/unittest/test_arith_canonical_simplify.py b/tests/python/unittest/test_arith_canonical_simplify.py new file mode 100644 index 000000000000..6af058523cd8 --- /dev/null +++ b/tests/python/unittest/test_arith_canonical_simplify.py @@ -0,0 +1,166 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +import tvm + +class CanonicalChecker: + def __init__(self): + self.analyzer = tvm.arith.Analyzer() + + def verify(self, data, expected): + res = self.analyzer.canonical_simplify(data) + assert tvm.ir_pass.Equal(res, expected), "data={}, res={}, expected={}".format(data, res, expected) + + +def test_mul_sum_simplify(): + ck = CanonicalChecker() + x, y, z = tvm.var("x"), tvm.var("y"), tvm.var("z") + ck.verify(2 + (3 * x + z + y + 1) * 4 + x, + x * 13 + z * 4 + y * 4 +6) + ck.verify((x + y + x + y * 3) / 2, y * 2 + x) + ck.verify((x + y + x + y * 3) % 2, 0) + ck.verify(x * 3 - 4 * x + 1, 1 - x) + ck.verify(y + x * 3 - 5 * x + 1 + y, y * 2 + 1 - x * 2) + + +def test_split_index_simplify(): + ck = CanonicalChecker() + x, y, z = tvm.var("x"), tvm.var("y"), tvm.var("z") + ck.verify((x/3) *3 + x % 3, x) + ck.verify((x/6) * 6 + ((x/3) % 2) * 3 + x % 3, x) + + # split div const + ck.verify(((x % 16) / 2) * 2 / 4, (x % 16) / 4) + ck.verify((x % 2) / 8, 0) + ck.verify((x % 2) / 7, 0) + ck.verify(((x % 16) / 2) * 2 / 6, (x % 16) / 6) + + # split mod const + ck.verify((x * 8) % 16, (x % 2) * 8) + ck.verify((x * 8) % 2, 0) + + # simplify then fold + ck.analyzer.update(x, tvm.arith.ConstIntBound(0, 1000)) + ck.analyzer.update(y, tvm.arith.ConstIntBound(0, 1000)) + ck.verify((x * 4 + y) / 2 * 2 + (x * 4 + y) % 2, x * 4 + y) + # complex fold + ck.verify((z * 9 + y) / 2 * 2 + (z * 9 + y) % 2, z * 9 + y) + + + +def test_div_simplify(): + ck = CanonicalChecker() + x = tvm.var("x") + ck.verify((16+48*x)/16, x*3 + 1) + # (17+48*x)/16 is not simplifiable for arbitrary x because when 17+48*x<0 + # (17+48*x)/16 != 1+3*x + ck.verify((17+48*x)/16, (x * 48 + 17) / 16) + # However, when x >= 0, then 17+48*x >= 0 and (17+48*x)/16 can be simplified + ck.analyzer.update(x, tvm.arith.ConstIntBound(0, 10)) + ck.verify((17+48*x)/16, x * 3 + 1) + # Trying expressions that are not simplifiable for any values of the variables + ck.verify((17+47*x)/16, (x * 47 + 17) / 16) + + +def test_canonical_mixed(): + ck = CanonicalChecker() + x = tvm.var("x") + z = tvm.const(3, "int32") + ck.verify(x / (z*z) - x / (z*z), 0) + ck.verify(x / (z+z) - x / (z+z), 0) + + +def test_reduce_combiner_simplify(): + ck = CanonicalChecker() + dummy = tvm.var('dummy') + comm_reducer = tvm.comm_reducer + prod = comm_reducer(lambda x, y: x*y, lambda t0: tvm.const(1, t0)) + + sum_or_prod = comm_reducer( + lambda x, y: tvm.expr.Select(dummy < 0, + x + y, x*y), + lambda t0: tvm.expr.Select(dummy < 0, + tvm.const(0, t0), tvm.const(1, t0))) + sum_and_prod = comm_reducer( + lambda x, y: (x[0] + y[0], + x[1]*y[1]), + lambda t0, t1: (tvm.const(0, t0), + tvm.const(5, t0) - tvm.const(4, t0))) + some_reducer1 = comm_reducer( + lambda x, y: (x[0] + y[0], + x[0] + y[0] + x[1] + y[1], + x[0]*y[2] + y[0]*x[2], + x[1] + y[2], + 4.0), + lambda t0, t1, t2, t3, t4: (tvm.const(0, t0), + tvm.const(1, t1), + tvm.const(2, t2), + tvm.const(3, t3), + tvm.const(4, t4))) + + k = tvm.reduce_axis((0, 10), name="k") + A = tvm.placeholder((10,), name='A') + # Test that SimplifyCombiner makes use of vranges + ck.analyzer.update(dummy, tvm.arith.ConstIntBound(-10, -4)) + ck.verify(sum_or_prod(A[k], k), tvm.sum(A[k], k)) + ck.analyzer.update(dummy, tvm.arith.ConstIntBound(5, 9), True) + ck.verify(sum_or_prod(A[k], k), prod(A[k], k)) + ck.analyzer.update(dummy, tvm.arith.ConstIntBound(-10, 100), True) + ck.verify(sum_and_prod((A[k], A[10-k]), k)[0], tvm.sum(A[k], k)) + ck.verify(sum_and_prod((A[k], A[10-k]), k)[1], prod(A[10-k], k)) + + reference_simplified_sources = [[A[0]], + [A[0], A[1]], + [A[0], A[2]], + [A[0], A[1], A[2], A[3]], + [A[4]]] + for j in range(5): + # Here we use the j-th component of the result, so only it and the components it + # depends on are left. + simplified = ck.analyzer.canonical_simplify( + some_reducer1((A[0], A[1], A[2], A[3], A[4]), k)[j]) + + # Check that the remaining components are the expected ones. + for lhs, rhs in zip(simplified.source, reference_simplified_sources[j]): + assert tvm.ir_pass.Equal(lhs, rhs) + + # Test that components with side effects are not removed + side_effect = lambda *xs: tvm.make.Call("int32", "dummy", xs, tvm.expr.Call.Intrinsic, None, 0) + ck.verify(sum_and_prod((A[k], side_effect(A[10-k])), k)[0], + sum_and_prod((A[k], side_effect(A[10-k])), k)[0]) + ck.verify(sum_and_prod((side_effect(A[k]), A[10-k]), k)[0], + tvm.sum(side_effect(A[k]), k)) + + +def test_reduce_simplify(): + ck = CanonicalChecker() + k = tvm.reduce_axis((0, 10), name="k") + j = tvm.reduce_axis((-5, 3), name="j") + A = tvm.placeholder((10,), name='A') + ck.verify(tvm.sum(tvm.expr.Select(k + j < 12, k + j, 0), [k, j]), + tvm.sum(k + j, [k, j])) + ck.verify(tvm.sum(A[3], []), A[3]) + # The rule below is not typical, removed for now + ck.verify(tvm.sum(k / 10, k), tvm.sum(tvm.const(0, "int32"), k)) + + +if __name__ == "__main__": + test_div_simplify() + test_reduce_simplify() + test_reduce_combiner_simplify() + test_mul_sum_simplify() + test_split_index_simplify() + test_canonical_mixed() diff --git a/tests/python/unittest/test_arith_const_int_bound.py b/tests/python/unittest/test_arith_const_int_bound.py index 968692208f5d..8a45c798a883 100644 --- a/tests/python/unittest/test_arith_const_int_bound.py +++ b/tests/python/unittest/test_arith_const_int_bound.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_dtype_bound(): diff --git a/tests/python/unittest/test_arith_detect_clip_bound.py b/tests/python/unittest/test_arith_detect_clip_bound.py index d5ea61ac0722..3301c24049ae 100644 --- a/tests/python/unittest/test_arith_detect_clip_bound.py +++ b/tests/python/unittest/test_arith_detect_clip_bound.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_basic(): diff --git a/tests/python/unittest/test_arith_detect_linear_equation.py b/tests/python/unittest/test_arith_detect_linear_equation.py index 2b0f327b65b2..cacb62456b79 100644 --- a/tests/python/unittest/test_arith_detect_linear_equation.py +++ b/tests/python/unittest/test_arith_detect_linear_equation.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_basic(): @@ -20,6 +36,10 @@ def test_basic(): m = tvm.arith.DetectLinearEquation(b * 7, [a]) assert m[0].value == 0 + m = tvm.arith.DetectLinearEquation(b * 7, []) + assert len(m) == 1 + assert tvm.ir_pass.Simplify(m[0] - b * 7).value == 0 + def test_multivariate(): v = [tvm.var("v%d" % i) for i in range(4)] b = tvm.var("b") @@ -42,6 +62,10 @@ def test_multivariate(): assert(m[0].value == 0) assert(tvm.ir_pass.Simplify(m[1] - (v[0] - v[1])).value == 0) + m = tvm.arith.DetectLinearEquation((v[0] - v[1]), []) + assert(len(m) == 1) + assert(tvm.ir_pass.Simplify(m[0] - (v[0] - v[1])).value == 0) + if __name__ == "__main__": test_basic() test_multivariate() diff --git a/tests/python/unittest/test_arith_domain_touched.py b/tests/python/unittest/test_arith_domain_touched.py index 383811ea9ed3..9139cc2ce29f 100644 --- a/tests/python/unittest/test_arith_domain_touched.py +++ b/tests/python/unittest/test_arith_domain_touched.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_domain_touched(): @@ -13,7 +29,7 @@ def test_domain_touched(): tvm.make.Provide( a.op, 0, - tvm.make.Call(b.dtype, 'b', [i - 1, j + 1], 3, b.op, 0) + + tvm.make.Call(b.dtype, 'b', [i - 1, j + 1], 3, b.op, 0) + tvm.make.Call(a.dtype, 'a', [i - 1, j - 1], 3, a.op, 0), [i, j] ) diff --git a/tests/python/unittest/test_arith_intset.py b/tests/python/unittest/test_arith_intset.py index 9b869feddc9d..650efdfb2f0a 100644 --- a/tests/python/unittest/test_arith_intset.py +++ b/tests/python/unittest/test_arith_intset.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_basic(): diff --git a/tests/python/unittest/test_arith_modular_set.py b/tests/python/unittest/test_arith_modular_set.py index 06ae5197b974..c5a4731f0f5e 100644 --- a/tests/python/unittest/test_arith_modular_set.py +++ b/tests/python/unittest/test_arith_modular_set.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm @@ -117,6 +133,22 @@ def test_constraint_scope(): assert m.coeff == 1 assert m.base == 0 +def test_intersect(): + a = tvm.var("a") + analyzer = tvm.arith.Analyzer() + with analyzer.constraint_scope(a % 4 == 1): + with analyzer.constraint_scope(a % 3 == 1): + m = analyzer.modular_set(a) + assert m.coeff == 12 + assert m.base == 1 + + with analyzer.constraint_scope(a % 3 == 2): + with analyzer.constraint_scope(a % 5 == 3): + with analyzer.constraint_scope(a % 7 == 2): + m = analyzer.modular_set(a) + assert m.coeff == 105 + assert m.base == 23 + if __name__ == "__main__": test_cast() @@ -126,3 +158,4 @@ def test_constraint_scope(): test_min_max_select() test_mix_index() test_constraint_scope() + test_intersect() diff --git a/tests/python/unittest/test_arith_rewrite_simplify.py b/tests/python/unittest/test_arith_rewrite_simplify.py index 62e6ea9c6c8e..e752d7c632ab 100644 --- a/tests/python/unittest/test_arith_rewrite_simplify.py +++ b/tests/python/unittest/test_arith_rewrite_simplify.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm class RewriteChecker: diff --git a/tests/python/unittest/test_arith_simplify.py b/tests/python/unittest/test_arith_simplify.py index 71818708fbf6..b8c5a3a16d5c 100644 --- a/tests/python/unittest/test_arith_simplify.py +++ b/tests/python/unittest/test_arith_simplify.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def csimplify(z): @@ -21,7 +37,6 @@ def test_simplify(): assert zz.a == x and zz.b.value == 4 n = tvm.var('n') - assert tvm.ir_pass.Equal(tvm.ir_pass.CanonicalSimplify(n % (-1)), tvm.const(0, "int32")) assert tvm.ir_pass.Equal(tvm.ir_pass.CanonicalSimplify(n % 1), tvm.const(0, "int32")) assert tvm.ir_pass.Equal(tvm.ir_pass.CanonicalSimplify(n / 1), n) tvm.ir_pass.CanonicalSimplify(n / (-1)) @@ -29,37 +44,22 @@ def test_simplify(): # assert tvm.ir_pass.Equal(tvm.ir_pass.CanonicalSimplify(n / (-1)), # tvm.ir_pass.CanonicalSimplify(-n)) -def test_simplify_div(): - x = tvm.var('x') - assert tvm.ir_pass.CanonicalSimplify((16+48*x)/16 - (1 + (x*3))).value == 0 - # (17+48*x)/16 is not simplifiable for arbitrary x because when 17+48*x<0 - # (17+48*x)/16 != 1+3*x - r = tvm.ir_pass.CanonicalSimplify((17+48*x)/16) - assert r.b.value == 16 - assert tvm.ir_pass.CanonicalSimplify(r.a - (17 + 48*x)).value == 0 - # However, when x >= 0, then 17+48*x >= 0 and (17+48*x)/16 can be simplified - assert tvm.ir_pass.CanonicalSimplify((17+48*x)/16 - (1 + (x*3)), {x: tvm.Range(0,10)}).value == 0 - - # Trying expressions that are not simplifiable for any values of the variables - r = tvm.ir_pass.CanonicalSimplify((17+47*x)/16, {x: tvm.Range(0,10)}) - assert r.b.value == 16 - assert tvm.ir_pass.CanonicalSimplify(r.a - (17+47*x)).value == 0 - - r = tvm.ir_pass.CanonicalSimplify((8*x - 17)/8, {x : tvm.Range(4,10)}) - assert tvm.ir_pass.CanonicalSimplify(r - (x-3)).value == 0 - def test_simplify_mod(): - """Not yet working, mock design""" ib = tvm.ir_builder.create() n = tvm.var('n') - j = tvm.var('j') A = ib.pointer("float32", name="A") - with ib.for_range(0, 16, name="i") as i: - A[i] = A[((n * 4 + j * 2) * 8 + i+1) % 16] + with ib.for_range(0, 10, name="j") as j: + with ib.for_range(0, 16, name="i") as i: + A[i] = A[(j * 32 + i+1) % 16] body = ib.get() stmt = tvm.ir_pass.CanonicalSimplify(body) - diff = tvm.ir_pass.CanonicalSimplify(stmt.body.value.index - (1 + i) % 16) + diff = tvm.ir_pass.CanonicalSimplify(stmt.body.body.value.index - (1 + i) % 16) assert diff.value == 0 + # if we can't prove that j is non-negative, we can't prove that (j+16) % 16 is j%16 + index = tvm.ir_pass.CanonicalSimplify((j + 16) % 16) + assert index != j + index = tvm.ir_pass.CanonicalSimplify((j + 16) % 16, {j: tvm.Range(0, 6)}) + assert index == j # if we can't prove that j+n*32 is non-negative, we can't prove that (j+n*32) % 16 is j%16 index = tvm.ir_pass.CanonicalSimplify( (j + n * 32) % 16, {j: tvm.Range(0, 6)}) @@ -95,8 +95,8 @@ def test_modular(): y: tvm.Range(i32_const(0), i32_const(2)), x: tvm.Range(i32_const(0), i32_const(14))} idx = ry * 16 + rx + y * 16 + x - z1 = tvm.ir_pass.CanonicalSimplify(idx // 16, vmap) z2 = tvm.ir_pass.CanonicalSimplify(idx % 16, vmap) + z1 = tvm.ir_pass.CanonicalSimplify(idx // 16, vmap) assert tvm.ir_pass.CanonicalSimplify(z1 - (ry + y)).value == 0 assert tvm.ir_pass.CanonicalSimplify(z2 - (rx + x)).value == 0 @@ -117,10 +117,9 @@ def test_const_propagation(): if __name__ == "__main__": - test_simplify_div() - test_simplify_mod() test_modular() test_simplify() test_mul() test_simplify_minmax() test_const_propagation() + test_simplify_mod() diff --git a/tests/python/unittest/test_autotvm_common.py b/tests/python/unittest/test_autotvm_common.py index ed39c3846c8c..4f8758e2eaf7 100644 --- a/tests/python/unittest/test_autotvm_common.py +++ b/tests/python/unittest/test_autotvm_common.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Common utilities for testing autotvm""" import time diff --git a/tests/python/unittest/test_autotvm_database.py b/tests/python/unittest/test_autotvm_database.py index aa956f61bbcf..4c530dc83f7a 100644 --- a/tests/python/unittest/test_autotvm_database.py +++ b/tests/python/unittest/test_autotvm_database.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test database""" import copy import logging diff --git a/tests/python/unittest/test_autotvm_dispatch_context.py b/tests/python/unittest/test_autotvm_dispatch_context.py index 1f2a7e276a32..716ab7f807f9 100644 --- a/tests/python/unittest/test_autotvm_dispatch_context.py +++ b/tests/python/unittest/test_autotvm_dispatch_context.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test dispatcher. The dispatcher can choose which template to use according to the parameters of workload""" diff --git a/tests/python/unittest/test_autotvm_executor.py b/tests/python/unittest/test_autotvm_executor.py index 6dd104210ccf..3877db31f68a 100644 --- a/tests/python/unittest/test_autotvm_executor.py +++ b/tests/python/unittest/test_autotvm_executor.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test local executor""" import time diff --git a/tests/python/unittest/test_autotvm_feature.py b/tests/python/unittest/test_autotvm_feature.py index 43754c27e0ea..401a8d3be407 100644 --- a/tests/python/unittest/test_autotvm_feature.py +++ b/tests/python/unittest/test_autotvm_feature.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test feature extraction""" import numpy as np diff --git a/tests/python/unittest/test_autotvm_flop_calculator.py b/tests/python/unittest/test_autotvm_flop_calculator.py index c5c046894f0c..2507732c3993 100644 --- a/tests/python/unittest/test_autotvm_flop_calculator.py +++ b/tests/python/unittest/test_autotvm_flop_calculator.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test flop calculation""" import tvm diff --git a/tests/python/unittest/test_autotvm_measure.py b/tests/python/unittest/test_autotvm_measure.py index e540a11f241b..29009487cd7e 100644 --- a/tests/python/unittest/test_autotvm_measure.py +++ b/tests/python/unittest/test_autotvm_measure.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test builder and runner""" import logging import time diff --git a/tests/python/unittest/test_autotvm_record.py b/tests/python/unittest/test_autotvm_record.py index 0d8bc9dcdfac..f83dd7c74d0b 100644 --- a/tests/python/unittest/test_autotvm_record.py +++ b/tests/python/unittest/test_autotvm_record.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """test the correctness of dump and load of data log""" import time diff --git a/tests/python/unittest/test_autotvm_space.py b/tests/python/unittest/test_autotvm_space.py index 7866226083cc..1da3fb0182ba 100644 --- a/tests/python/unittest/test_autotvm_space.py +++ b/tests/python/unittest/test_autotvm_space.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test space definition primitives""" import tvm diff --git a/tests/python/unittest/test_autotvm_xgboost_model.py b/tests/python/unittest/test_autotvm_xgboost_model.py index 58da219f2e48..24677c566c66 100644 --- a/tests/python/unittest/test_autotvm_xgboost_model.py +++ b/tests/python/unittest/test_autotvm_xgboost_model.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import time import numpy as np diff --git a/tests/python/unittest/test_build_lower.py b/tests/python/unittest/test_build_lower.py index 37ef2a41741d..8600fc2b4628 100644 --- a/tests/python/unittest/test_build_lower.py +++ b/tests/python/unittest/test_build_lower.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_lower_rfactor(): diff --git a/tests/python/unittest/test_codegen_arm.py b/tests/python/unittest/test_codegen_arm.py index 049696f95135..0eb009d08716 100644 --- a/tests/python/unittest/test_codegen_arm.py +++ b/tests/python/unittest/test_codegen_arm.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import re import os diff --git a/tests/python/unittest/test_codegen_bool.py b/tests/python/unittest/test_codegen_bool.py index e2592c416345..0a9f8fb8331b 100644 --- a/tests/python/unittest/test_codegen_bool.py +++ b/tests/python/unittest/test_codegen_bool.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """codegen related to bool types""" import tvm diff --git a/tests/python/unittest/test_codegen_c_host.py b/tests/python/unittest/test_codegen_c_host.py index f6a69c3a7b13..5161c6899db9 100644 --- a/tests/python/unittest/test_codegen_c_host.py +++ b/tests/python/unittest/test_codegen_c_host.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np from tvm.contrib import util diff --git a/tests/python/unittest/test_codegen_cross_llvm.py b/tests/python/unittest/test_codegen_cross_llvm.py index 5b9c509aedf2..5018bf7e3b0a 100644 --- a/tests/python/unittest/test_codegen_cross_llvm.py +++ b/tests/python/unittest/test_codegen_cross_llvm.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test cross compilation""" import tvm import os diff --git a/tests/python/unittest/test_codegen_cuda.py b/tests/python/unittest/test_codegen_cuda.py index d3b770790bdb..f28b4ccfd1da 100644 --- a/tests/python/unittest/test_codegen_cuda.py +++ b/tests/python/unittest/test_codegen_cuda.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np from tvm.contrib.nvcc import have_fp16, have_int8 @@ -28,7 +44,7 @@ def check_cuda(dtype, n, lanes): c = tvm.nd.empty((n,), B.dtype, ctx) fun(a, c) tvm.testing.assert_allclose(c.asnumpy(), a.asnumpy() + 1) - + check_cuda("float32", 64, 2) check_cuda("float16", 64, 2) @@ -44,7 +60,7 @@ def check_cuda(dtype, n, lanes): return A = tvm.placeholder((n,), name='A', dtype="%sx%d" % (dtype, lanes)) B = tvm.placeholder((n,), name='B', dtype="%sx%d" % (dtype, lanes)) - C = tvm.placeholder((n,), name='C', dtype="int32") + C = tvm.placeholder((n,), name='C', dtype="int32") D = tvm.compute((n,), lambda i: tvm.call_pure_extern("int32", "__dp4a", A[i], B[i], C[i]), name='D') s = tvm.create_schedule(D.op) diff --git a/tests/python/unittest/test_codegen_device.py b/tests/python/unittest/test_codegen_device.py index ee7644cea677..95329756beef 100644 --- a/tests/python/unittest/test_codegen_device.py +++ b/tests/python/unittest/test_codegen_device.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm from tvm.contrib import util import numpy as np diff --git a/tests/python/unittest/test_codegen_extern.py b/tests/python/unittest/test_codegen_extern.py index 7512f0d23634..2062221d2160 100644 --- a/tests/python/unittest/test_codegen_extern.py +++ b/tests/python/unittest/test_codegen_extern.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np @@ -47,7 +63,7 @@ def check_target(target): c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx) f(a, c) tvm.testing.assert_allclose(c.asnumpy(), a.asnumpy() + 1) - + check_target("llvm") check_target("opencl") check_target("cuda") diff --git a/tests/python/unittest/test_codegen_llvm.py b/tests/python/unittest/test_codegen_llvm.py index ad139749978d..81a5e7c74d59 100644 --- a/tests/python/unittest/test_codegen_llvm.py +++ b/tests/python/unittest/test_codegen_llvm.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm from tvm.contrib import util, clang import numpy as np diff --git a/tests/python/unittest/test_codegen_opencl.py b/tests/python/unittest/test_codegen_opencl.py index 37aaadc5bb23..c484664bdfd8 100644 --- a/tests/python/unittest/test_codegen_opencl.py +++ b/tests/python/unittest/test_codegen_opencl.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm target = 'opencl' diff --git a/tests/python/unittest/test_codegen_static_init.py b/tests/python/unittest/test_codegen_static_init.py index 1a03de9ee000..b1092309e70a 100644 --- a/tests/python/unittest/test_codegen_static_init.py +++ b/tests/python/unittest/test_codegen_static_init.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import ctypes import numpy as np diff --git a/tests/python/unittest/test_codegen_vm_basic.py b/tests/python/unittest/test_codegen_vm_basic.py index 10195b9d9e6a..a9b382f1fd61 100644 --- a/tests/python/unittest/test_codegen_vm_basic.py +++ b/tests/python/unittest/test_codegen_vm_basic.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np diff --git a/tests/python/unittest/test_codegen_x86.py b/tests/python/unittest/test_codegen_x86.py new file mode 100644 index 000000000000..06591a3cbf76 --- /dev/null +++ b/tests/python/unittest/test_codegen_x86.py @@ -0,0 +1,76 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +import tvm +import re + + +def test_fp16_to_fp32(): + if tvm.codegen.llvm_version_major() < 6: + print("Skipping due to LLVM version being {} < 6".format( + tvm.codegen.llvm_version_major())) + return + + def fp16_to_fp32(target, width, match=None, not_match=None): + elements = 64 + n = tvm.convert(elements) + A = tvm.placeholder((n, width), dtype="float16", name='A') + B = tvm.compute(A.shape, lambda *i: A(*i).astype("float32"), name='B') + s = tvm.create_schedule(B.op) + s[B].vectorize(s[B].op.axis[1]) + f = tvm.build(s, [A, B], target) + + assembly = f.get_source('asm').splitlines() + if match: + matches = [l for l in assembly if re.search(match, l)] + assert matches + if not_match: + not_matches = [l for l in assembly if re.search(not_match, l)] + assert not not_matches + + + fp16_to_fp32( + 'llvm -mcpu=skylake-avx512', 15, + match="vcvtph2ps.*ymm", not_match="vcvtph2ps.*zmm") + fp16_to_fp32( + 'llvm -mcpu=skylake-avx512', 16, + match="vcvtph2ps.*zmm") + fp16_to_fp32( + 'llvm -mcpu=skylake-avx512', 17, + match="vcvtph2ps.*zmm") + fp16_to_fp32( + 'llvm -mcpu=skylake-avx512', 49, + match="vcvtph2ps.*zmm") + fp16_to_fp32( + 'llvm -mcpu=skylake-avx512 -mattr=-avx512f', 49, + match="vcvtph2ps.*ymm", + not_match="vcvtph2ps.*zmm") + fp16_to_fp32( + 'llvm -mcpu=skylake-avx512 -mattr=-f16c,-avx512f', 49, + not_match="vcvtph2ps") + fp16_to_fp32( + 'llvm -mcpu=core-avx2', 8, + match="vcvtph2ps.*ymm") + fp16_to_fp32( + 'llvm -mcpu=core-avx2', 9, + match="vcvtph2ps.*ymm") + fp16_to_fp32( + 'llvm', 9, + not_match="vcvtph2ps") + + +if __name__ == "__main__": + test_fp16_to_fp32() diff --git a/tests/python/unittest/test_hybrid_script.py b/tests/python/unittest/test_hybrid_script.py index 5bed58c8f617..254264662fdc 100644 --- a/tests/python/unittest/test_hybrid_script.py +++ b/tests/python/unittest/test_hybrid_script.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm, inspect, sys, traceback, numpy, nose, types, os from tvm.contrib import util from tvm.hybrid import script @@ -339,9 +355,9 @@ def foo(a): for k in const_range(len_j): total[0] += a[i, k] c[i] = total[0] - + return c - + a = tvm.placeholder((8, 4), 'float32') c = foo(a) s = tvm.create_schedule(c.op) @@ -522,7 +538,7 @@ def downstream(a): b[i] = a[i] * i return b - + a = tvm.placeholder((20, ), 'float32') b = downstream(a) c = tvm.compute((20, ), lambda x: b[x] + 1.0) diff --git a/tests/python/unittest/test_ir_builder.py b/tests/python/unittest/test_ir_builder.py index a257571752e4..322c37ef6dc6 100644 --- a/tests/python/unittest/test_ir_builder.py +++ b/tests/python/unittest/test_ir_builder.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np diff --git a/tests/python/unittest/test_lang_basic.py b/tests/python/unittest/test_lang_basic.py index 09567c06fe41..25c0aa14bad7 100644 --- a/tests/python/unittest/test_lang_basic.py +++ b/tests/python/unittest/test_lang_basic.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_const(): diff --git a/tests/python/unittest/test_lang_buffer.py b/tests/python/unittest/test_lang_buffer.py index 85c9fbeee53e..e0bb0279c09f 100644 --- a/tests/python/unittest/test_lang_buffer.py +++ b/tests/python/unittest/test_lang_buffer.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm from tvm.schedule import Buffer diff --git a/tests/python/unittest/test_lang_constructor.py b/tests/python/unittest/test_lang_constructor.py index caca08afa804..a0d39f2daffe 100644 --- a/tests/python/unittest/test_lang_constructor.py +++ b/tests/python/unittest/test_lang_constructor.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_expr_constructor(): diff --git a/tests/python/unittest/test_lang_container.py b/tests/python/unittest/test_lang_container.py index 8683e56088a0..cce7479a4278 100644 --- a/tests/python/unittest/test_lang_container.py +++ b/tests/python/unittest/test_lang_container.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_array(): diff --git a/tests/python/unittest/test_lang_data_layout.py b/tests/python/unittest/test_lang_data_layout.py index 73d626e32fa7..164fe1a23098 100644 --- a/tests/python/unittest/test_lang_data_layout.py +++ b/tests/python/unittest/test_lang_data_layout.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test layout and bijective-layout node""" import tvm diff --git a/tests/python/unittest/test_lang_group.py b/tests/python/unittest/test_lang_group.py index 475076ef297b..dc6837e2be46 100644 --- a/tests/python/unittest/test_lang_group.py +++ b/tests/python/unittest/test_lang_group.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test group effect""" import tvm diff --git a/tests/python/unittest/test_lang_operator.py b/tests/python/unittest/test_lang_operator.py index 371f276cb025..da309815b9f4 100644 --- a/tests/python/unittest/test_lang_operator.py +++ b/tests/python/unittest/test_lang_operator.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_const_fold(): diff --git a/tests/python/unittest/test_lang_reflection.py b/tests/python/unittest/test_lang_reflection.py index 103cd6c5f219..18230bf5e1fa 100644 --- a/tests/python/unittest/test_lang_reflection.py +++ b/tests/python/unittest/test_lang_reflection.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_const_saveload_json(): diff --git a/tests/python/unittest/test_lang_schedule.py b/tests/python/unittest/test_lang_schedule.py index a00785dea7af..fb33e2b6fc0a 100644 --- a/tests/python/unittest/test_lang_schedule.py +++ b/tests/python/unittest/test_lang_schedule.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. from nose.tools import raises import tvm import pickle as pkl diff --git a/tests/python/unittest/test_lang_tag.py b/tests/python/unittest/test_lang_tag.py index e141830b0595..a87971657a3f 100644 --- a/tests/python/unittest/test_lang_tag.py +++ b/tests/python/unittest/test_lang_tag.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import json import tvm diff --git a/tests/python/unittest/test_lang_target.py b/tests/python/unittest/test_lang_target.py index 42e2c3fcb2e3..85417d462c33 100644 --- a/tests/python/unittest/test_lang_target.py +++ b/tests/python/unittest/test_lang_target.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm @tvm.target.generic_func diff --git a/tests/python/unittest/test_lang_tensor.py b/tests/python/unittest/test_lang_tensor.py index 50492ca41fca..44aca3b324bb 100644 --- a/tests/python/unittest/test_lang_tensor.py +++ b/tests/python/unittest/test_lang_tensor.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm from topi.nn.pooling import pool diff --git a/tests/python/unittest/test_lang_tensor_overload_op.py b/tests/python/unittest/test_lang_tensor_overload_op.py index ee6eaf74a79c..7571df57e089 100644 --- a/tests/python/unittest/test_lang_tensor_overload_op.py +++ b/tests/python/unittest/test_lang_tensor_overload_op.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import tvm import topi diff --git a/tests/python/unittest/test_lang_verify_compute.py b/tests/python/unittest/test_lang_verify_compute.py index 1b9ecf453267..f06131ceb8cd 100644 --- a/tests/python/unittest/test_lang_verify_compute.py +++ b/tests/python/unittest/test_lang_verify_compute.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_verify_compute(): @@ -61,4 +77,4 @@ def test_verify_compute(): if __name__ == "__main__": - test_verify_compute() \ No newline at end of file + test_verify_compute() diff --git a/tests/python/unittest/test_module_load.py b/tests/python/unittest/test_module_load.py index 8ee3ea5e06c0..ca508f88f1a7 100644 --- a/tests/python/unittest/test_module_load.py +++ b/tests/python/unittest/test_module_load.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm from tvm.contrib import cc, util import ctypes diff --git a/tests/python/unittest/test_pass_attrs_hash_equal.py b/tests/python/unittest/test_pass_attrs_hash_equal.py index 2d6987aeb183..bb4c196ddc71 100644 --- a/tests/python/unittest/test_pass_attrs_hash_equal.py +++ b/tests/python/unittest/test_pass_attrs_hash_equal.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_attrs_equal(): diff --git a/tests/python/unittest/test_pass_basic.py b/tests/python/unittest/test_pass_basic.py index 8e74188aeb82..fc76c306731c 100644 --- a/tests/python/unittest/test_pass_basic.py +++ b/tests/python/unittest/test_pass_basic.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_simplify(): diff --git a/tests/python/unittest/test_pass_bound_checkers.py b/tests/python/unittest/test_pass_bound_checkers.py index bb552f078f1a..9dc2fe4214fc 100644 --- a/tests/python/unittest/test_pass_bound_checkers.py +++ b/tests/python/unittest/test_pass_bound_checkers.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. from nose.tools import raises import tvm import numpy as np diff --git a/tests/python/unittest/test_pass_combine_context_call.py b/tests/python/unittest/test_pass_combine_context_call.py index d662b715f041..a25568f719d2 100644 --- a/tests/python/unittest/test_pass_combine_context_call.py +++ b/tests/python/unittest/test_pass_combine_context_call.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_for(): diff --git a/tests/python/unittest/test_pass_decorate_device_scope.py b/tests/python/unittest/test_pass_decorate_device_scope.py index 1d9eb899a642..d36fe8d37964 100644 --- a/tests/python/unittest/test_pass_decorate_device_scope.py +++ b/tests/python/unittest/test_pass_decorate_device_scope.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_decorate_device(): @@ -20,7 +36,7 @@ def test_decorate_device(): assert isinstance(stmt2, tvm.stmt.AttrStmt) assert stmt2.attr_key == "device_scope" assert stmt1 == stmt2.body - + if __name__ == "__main__": test_decorate_device() diff --git a/tests/python/unittest/test_pass_equal.py b/tests/python/unittest/test_pass_equal.py index 1c13b82ea8ef..7b9fd7f97ac1 100644 --- a/tests/python/unittest/test_pass_equal.py +++ b/tests/python/unittest/test_pass_equal.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_equal_expr(): diff --git a/tests/python/unittest/test_pass_inject_copy_intrin.py b/tests/python/unittest/test_pass_inject_copy_intrin.py index 19e03503e1af..83b0f718f824 100644 --- a/tests/python/unittest/test_pass_inject_copy_intrin.py +++ b/tests/python/unittest/test_pass_inject_copy_intrin.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_copy2d(): diff --git a/tests/python/unittest/test_pass_inject_double_buffer.py b/tests/python/unittest/test_pass_inject_double_buffer.py index 0e3500edf2e3..dc517e2ee28b 100644 --- a/tests/python/unittest/test_pass_inject_double_buffer.py +++ b/tests/python/unittest/test_pass_inject_double_buffer.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_double_buffer(): diff --git a/tests/python/unittest/test_pass_inject_vthread.py b/tests/python/unittest/test_pass_inject_vthread.py index 16f4c4652a3d..cb2fa201aff4 100644 --- a/tests/python/unittest/test_pass_inject_vthread.py +++ b/tests/python/unittest/test_pass_inject_vthread.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_vthread(): diff --git a/tests/python/unittest/test_pass_inline.py b/tests/python/unittest/test_pass_inline.py index 398c0d34d58d..e8b86fc75d7e 100644 --- a/tests/python/unittest/test_pass_inline.py +++ b/tests/python/unittest/test_pass_inline.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_inline(): diff --git a/tests/python/unittest/test_pass_ir_transform.py b/tests/python/unittest/test_pass_ir_transform.py index 87c82c5e5f5f..098e0d7700cb 100644 --- a/tests/python/unittest/test_pass_ir_transform.py +++ b/tests/python/unittest/test_pass_ir_transform.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_ir_transform(): diff --git a/tests/python/unittest/test_pass_lift_attr_scope.py b/tests/python/unittest/test_pass_lift_attr_scope.py index 2ca6334d0cfd..d786ca8c8108 100644 --- a/tests/python/unittest/test_pass_lift_attr_scope.py +++ b/tests/python/unittest/test_pass_lift_attr_scope.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_coproc_lift(): diff --git a/tests/python/unittest/test_pass_loop_partition.py b/tests/python/unittest/test_pass_loop_partition.py index b4e9e11169f8..80b4f9232c50 100644 --- a/tests/python/unittest/test_pass_loop_partition.py +++ b/tests/python/unittest/test_pass_loop_partition.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def collect_visit(stmt, f): diff --git a/tests/python/unittest/test_pass_lower_warp_memory.py b/tests/python/unittest/test_pass_lower_warp_memory.py index 9793b21371bd..4f0927137444 100644 --- a/tests/python/unittest/test_pass_lower_warp_memory.py +++ b/tests/python/unittest/test_pass_lower_warp_memory.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_lower_warp_mem(): diff --git a/tests/python/unittest/test_pass_makeapi.py b/tests/python/unittest/test_pass_makeapi.py index 7dc61b6f59dc..c506ccb799b3 100644 --- a/tests/python/unittest/test_pass_makeapi.py +++ b/tests/python/unittest/test_pass_makeapi.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy diff --git a/tests/python/unittest/test_pass_remove_no_op.py b/tests/python/unittest/test_pass_remove_no_op.py index ab36de1847ec..b6fb171624ca 100644 --- a/tests/python/unittest/test_pass_remove_no_op.py +++ b/tests/python/unittest/test_pass_remove_no_op.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_remove_no_op(): diff --git a/tests/python/unittest/test_pass_rewrite_unsafe_select.py b/tests/python/unittest/test_pass_rewrite_unsafe_select.py index 92f7f2c4b8b1..b2d73ec00ce8 100644 --- a/tests/python/unittest/test_pass_rewrite_unsafe_select.py +++ b/tests/python/unittest/test_pass_rewrite_unsafe_select.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm diff --git a/tests/python/unittest/test_pass_simplify.py b/tests/python/unittest/test_pass_simplify.py index 939a08f5b8c2..44c301ab7ef6 100644 --- a/tests/python/unittest/test_pass_simplify.py +++ b/tests/python/unittest/test_pass_simplify.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy from tvm import comm_reducer @@ -35,109 +51,8 @@ def test_bound(): ret = tvm.ir_pass.Simplify(m % 10, vrange) assert ret == m -def test_canonical(): - x = tvm.var("x") - z = tvm.const(3, "int32") - ret = tvm.ir_pass.CanonicalSimplify(x / (z*z) - x / (z*z)) - assert(tvm.ir_pass.Equal(ret, 0)) - - ret = tvm.ir_pass.CanonicalSimplify(x / (z+z) - x / (z+z)) - assert(tvm.ir_pass.Equal(ret, 0)) - - #make sure terms are ordered based on their top operators (e.g., / always precedes %) - ret1 = tvm.ir_pass.CanonicalSimplify(x % 3 + x / 3) - ret2 = tvm.ir_pass.CanonicalSimplify(x / 3 + x % 3) - assert(tvm.ir_pass.Equal(ret1, ret2)) - - #when top operators match, compare string representation of terms - ret1 = tvm.ir_pass.CanonicalSimplify(x % 4 + x % 3) - ret2 = tvm.ir_pass.CanonicalSimplify(x % 3 + x % 4) - assert (tvm.ir_pass.Equal(ret1, ret2)) - - -def test_simplify_combiner(): - dummy = tvm.var('dummy') - - prod = comm_reducer(lambda x, y: x*y, lambda t0: tvm.const(1, t0)) - - sum_or_prod = comm_reducer(lambda x, y: tvm.expr.Select(dummy < 0, - x + y, x*y), - lambda t0: tvm.expr.Select(dummy < 0, - tvm.const(0, t0), tvm.const(1, t0))) - - sum_and_prod = comm_reducer(lambda x, y: (x[0] + y[0], - x[1]*y[1]), - lambda t0, t1: (tvm.const(0, t0), - tvm.const(5, t0) - tvm.const(4, t0))) - - sum_and_prod2 = comm_reducer(lambda x, y: (x[0] + y[0], - x[1]*y[1] + 0*x[0] + y[0] - y[0]), - lambda t0, t1: (tvm.const(5, t0) - tvm.const(5, t0), - tvm.const(1, t1))) - - some_reducer1 = comm_reducer(lambda x, y: (x[0] + y[0], - x[0] + y[0] + x[1] + y[1], - x[0]*y[2] + y[0]*x[2], - x[1] + y[2], - 4.0), - lambda t0, t1, t2, t3, t4: (tvm.const(0, t0), - tvm.const(1, t1), - tvm.const(2, t2), - tvm.const(3, t3), - tvm.const(4, t4))) - - k = tvm.reduce_axis((0, 10), name="k") - A = tvm.placeholder((10,), name='A') - - # Test that SimplifyCombiner makes use of vranges - vrange = {dummy: tvm.Range(-10, -5)} - assert Equal(Simplify(sum_or_prod(A[k], k), vrange), tvm.sum(A[k], k)) - vrange = {dummy: tvm.Range(5, 10)} - assert Equal(Simplify(sum_or_prod(A[k], k), vrange), prod(A[k], k)) - - assert Equal(Simplify(sum_and_prod((A[k], A[10-k]), k)[0]), tvm.sum(A[k], k)) - assert Equal(Simplify(sum_and_prod((A[k], A[10-k]), k)[1]), prod(A[10-k], k)) - - assert Equal(Simplify(sum_and_prod2((A[k], A[10-k]), k)[0]), tvm.sum(A[k], k)) - assert Equal(Simplify(sum_and_prod2((A[k], A[10-k]), k)[1]), prod(A[10-k], k)) - - reference_simplified_sources = [[A[0]], - [A[0], A[1]], - [A[0], A[2]], - [A[0], A[1], A[2], A[3]], - [A[4]]] - for j in range(5): - # Here we use the j-th component of the result, so only it and the components it - # depends on are left. - simplified = Simplify(some_reducer1((A[0], A[1], A[2], A[3], A[4]), k)[j]) - - # Check that the remaining components are the expected ones. - for lhs, rhs in zip(simplified.source, reference_simplified_sources[j]): - assert Equal(lhs, rhs) - - # Test that components with side effects are not removed - side_effect = lambda *xs: tvm.make.Call("int32", "dummy", xs, tvm.expr.Call.Intrinsic, None, 0) - assert Equal(Simplify(sum_and_prod((A[k], side_effect(A[10-k])), k)[0]), - sum_and_prod((A[k], side_effect(A[10-k])), k)[0]) - assert Equal(Simplify(sum_and_prod((side_effect(A[k]), A[10-k]), k)[0]), - tvm.sum(side_effect(A[k]), k)) - - -def test_simplify_reduce(): - k = tvm.reduce_axis((0, 10), name="k") - j = tvm.reduce_axis((-5, 3), name="j") - A = tvm.placeholder((10,), name='A') - - assert Equal(Simplify(tvm.sum(k/10, k)), tvm.sum(tvm.const(0, "int32"), k)) - assert Equal(Simplify(tvm.sum(A[3], [])), A[3]) - assert Equal(Simplify(tvm.sum(tvm.expr.Select(k + j < 12, k + j, 0), [k, j])), - tvm.sum(k + j, [k, j])) - if __name__ == "__main__": test_bound() test_basic() test_simplify() - test_canonical() - test_simplify_combiner() - test_simplify_reduce() diff --git a/tests/python/unittest/test_pass_split_host_device.py b/tests/python/unittest/test_pass_split_host_device.py index 24cc497944d7..631998fdaa75 100644 --- a/tests/python/unittest/test_pass_split_host_device.py +++ b/tests/python/unittest/test_pass_split_host_device.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. from nose.tools import raises import tvm diff --git a/tests/python/unittest/test_pass_split_pipeline.py b/tests/python/unittest/test_pass_split_pipeline.py index 2cb3a5533088..380053420f44 100644 --- a/tests/python/unittest/test_pass_split_pipeline.py +++ b/tests/python/unittest/test_pass_split_pipeline.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def lower(s, args): diff --git a/tests/python/unittest/test_pass_storage_flatten.py b/tests/python/unittest/test_pass_storage_flatten.py index 655df1da4e15..02edfe7d3261 100644 --- a/tests/python/unittest/test_pass_storage_flatten.py +++ b/tests/python/unittest/test_pass_storage_flatten.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_flatten2(): diff --git a/tests/python/unittest/test_pass_storage_rewrite.py b/tests/python/unittest/test_pass_storage_rewrite.py index 52851d4afe95..6fd6f8b1ce52 100644 --- a/tests/python/unittest/test_pass_storage_rewrite.py +++ b/tests/python/unittest/test_pass_storage_rewrite.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_storage_share(): diff --git a/tests/python/unittest/test_pass_storage_sync.py b/tests/python/unittest/test_pass_storage_sync.py index 2286dd53e981..5c7024abe518 100644 --- a/tests/python/unittest/test_pass_storage_sync.py +++ b/tests/python/unittest/test_pass_storage_sync.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_storage_sync(): @@ -100,7 +116,7 @@ def __check_list(tvm_array, py_list): with ib.new_scope(): ib.scope_attr(cp, "coproc_scope", 3) A[0] = 0.0 - + stmt = ib.get() stmt = tvm.ir_pass.CoProcSync(stmt) slist = tvm.make.stmt_list(stmt.first.body.body) @@ -112,7 +128,7 @@ def __check_list(tvm_array, py_list): assert(__check_list(push_st.value.args, [2,3])) assert(pop_st.value.name == "cop.coproc_dep_pop") assert(__check_list(pop_st.value.args, [2,3])) - + if __name__ == "__main__": test_coproc_sync() diff --git a/tests/python/unittest/test_pass_unroll.py b/tests/python/unittest/test_pass_unroll.py index d51c3f016d03..fc8d0dc5f5c8 100644 --- a/tests/python/unittest/test_pass_unroll.py +++ b/tests/python/unittest/test_pass_unroll.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import os diff --git a/tests/python/unittest/test_pass_vectorize.py b/tests/python/unittest/test_pass_vectorize.py index 1fbcc655ac80..03516872e835 100644 --- a/tests/python/unittest/test_pass_vectorize.py +++ b/tests/python/unittest/test_pass_vectorize.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_vectorize_loop(): diff --git a/tests/python/unittest/test_pass_verify_gpu_code.py b/tests/python/unittest/test_pass_verify_gpu_code.py index e3884a727852..b49b52ec46b7 100644 --- a/tests/python/unittest/test_pass_verify_gpu_code.py +++ b/tests/python/unittest/test_pass_verify_gpu_code.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test gpu code verifier""" import tvm diff --git a/tests/python/unittest/test_pass_verify_memory.py b/tests/python/unittest/test_pass_verify_memory.py index d1f5d4326621..e76b6e55144f 100644 --- a/tests/python/unittest/test_pass_verify_memory.py +++ b/tests/python/unittest/test_pass_verify_memory.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm # The following DLDeviceType/TVMDeviceExtType values @@ -26,7 +42,7 @@ def lower(sch, args): return func -# All computations are bound. +# All computations are bound. # So VerifyMemory pass is expected to succeed. # def test_verify_memory_all_bind(): @@ -41,12 +57,12 @@ def test_verify_memory_all_bind(): s[B].bind(tx, tvm.thread_axis("threadIdx.x")) func = lower(s, [A, B]) - + for dev_type in gpu_devices + other_devices: assert tvm.ir_pass.VerifyMemory(func, dev_type) -# Computations are not bound. +# Computations are not bound. # So VerifyMemory pass fails when device type is GPU. # def test_verify_memory_not_bind(): @@ -57,7 +73,7 @@ def test_verify_memory_not_bind(): # B is not bound to threads. s = tvm.create_schedule(B.op) - func = lower(s, [A, B]) + func = lower(s, [A, B]) for dev_type in gpu_devices: assert not tvm.ir_pass.VerifyMemory(func, dev_type) @@ -65,7 +81,7 @@ def test_verify_memory_not_bind(): assert tvm.ir_pass.VerifyMemory(func, dev_type) -# Computations are partially bound. +# Computations are partially bound. # So VerifyMemory pass fails when device type is GPU. # def test_verify_memory_partially_bind(): @@ -81,7 +97,7 @@ def test_verify_memory_partially_bind(): s[C].bind(bx, tvm.thread_axis("blockIdx.x")) s[C].bind(tx, tvm.thread_axis("threadIdx.x")) - func = lower(s, [A, B, C, D]) + func = lower(s, [A, B, C, D]) for dev_type in gpu_devices: assert not tvm.ir_pass.VerifyMemory(func, dev_type) @@ -93,4 +109,4 @@ def test_verify_memory_partially_bind(): test_verify_memory_all_bind() test_verify_memory_not_bind() test_verify_memory_partially_bind() - + diff --git a/tests/python/unittest/test_pass_virtual_thread.py b/tests/python/unittest/test_pass_virtual_thread.py index 1b1096b070a8..48a769faed31 100644 --- a/tests/python/unittest/test_pass_virtual_thread.py +++ b/tests/python/unittest/test_pass_virtual_thread.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_virtual_thread(): diff --git a/tests/python/unittest/test_runtime_error.py b/tests/python/unittest/test_runtime_error.py index b8ea5a1506c2..10a76019de47 100644 --- a/tests/python/unittest/test_runtime_error.py +++ b/tests/python/unittest/test_runtime_error.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test runtime error handling""" import tvm diff --git a/tests/python/unittest/test_runtime_extension.py b/tests/python/unittest/test_runtime_extension.py index 89d30ffc1c46..205e5caadd60 100644 --- a/tests/python/unittest/test_runtime_extension.py +++ b/tests/python/unittest/test_runtime_extension.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np diff --git a/tests/python/unittest/test_runtime_graph.py b/tests/python/unittest/test_runtime_graph.py index 9978c5992910..20af8a005b77 100644 --- a/tests/python/unittest/test_runtime_graph.py +++ b/tests/python/unittest/test_runtime_graph.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np import json diff --git a/tests/python/unittest/test_runtime_graph_debug.py b/tests/python/unittest/test_runtime_graph_debug.py index 4bbe6509c40c..3de270732403 100644 --- a/tests/python/unittest/test_runtime_graph_debug.py +++ b/tests/python/unittest/test_runtime_graph_debug.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import os import tvm import numpy as np @@ -64,6 +80,22 @@ def check_verify(): #Verify the tensors are dumped assert(len(os.listdir(directory)) > 1) + CHROME_TRACE_FILE_NAME = '_tvmdbg_execution_trace.json' + assert(os.path.exists(os.path.join(directory, CHROME_TRACE_FILE_NAME))) + + with open(os.path.join(directory, CHROME_TRACE_FILE_NAME)) as f: + trace = json.load(f) + assert trace["displayTimeUnit"] == "ns" + events = trace["traceEvents"] + assert len(events) == 4 + assert all(event["ph"] in ('B', 'E') for event in events) + assert all(event["pid"] == 1 for event in events) + assert all(event["tid"] == 1 for event in events) + assert all(event["name"] == 'x' for event in events[:2]) + assert all(event["name"] == 'add' for event in events[2:]) + assert events[0]["ts"] == 0 + assert events[0]["ph"] == 'B' + #verify the output is correct out = mod.get_output(0, tvm.nd.empty((n,))) np.testing.assert_equal(out.asnumpy(), a + 1) diff --git a/tests/python/unittest/test_runtime_heterogeneous.py b/tests/python/unittest/test_runtime_heterogeneous.py index 3272165f0b02..e0ae2e18a3d6 100644 --- a/tests/python/unittest/test_runtime_heterogeneous.py +++ b/tests/python/unittest/test_runtime_heterogeneous.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=too-many-locals """Unit tests for heterogeneous runtime""" import json diff --git a/tests/python/unittest/test_runtime_measure.py b/tests/python/unittest/test_runtime_measure.py index 4513a268ac20..0fc72d06ec37 100644 --- a/tests/python/unittest/test_runtime_measure.py +++ b/tests/python/unittest/test_runtime_measure.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import time import ctypes @@ -28,7 +44,7 @@ def my_debug(filename): with open(filename, "r") as fin: ct = len(fin.readline()) - + assert ct == 2 @@ -41,7 +57,7 @@ def my_debug(filename): ct = len(fin.readline()) assert ct > 10 + 2 - + if __name__ == "__main__": test_min_repeat_ms() diff --git a/tests/python/unittest/test_runtime_ndarray.py b/tests/python/unittest/test_runtime_ndarray.py index 935f8f38a804..ed23a0bc9d9d 100644 --- a/tests/python/unittest/test_runtime_ndarray.py +++ b/tests/python/unittest/test_runtime_ndarray.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np diff --git a/tests/python/unittest/test_runtime_packed_func.py b/tests/python/unittest/test_runtime_packed_func.py index 734deac22487..c7120c5bb62f 100644 --- a/tests/python/unittest/test_runtime_packed_func.py +++ b/tests/python/unittest/test_runtime_packed_func.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np diff --git a/tests/python/unittest/test_runtime_rpc.py b/tests/python/unittest/test_runtime_rpc.py index eb7458555979..8b16ae1e7ba5 100644 --- a/tests/python/unittest/test_runtime_rpc.py +++ b/tests/python/unittest/test_runtime_rpc.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import os import logging diff --git a/tests/python/unittest/test_schedule_bound_inference.py b/tests/python/unittest/test_schedule_bound_inference.py index 791de5597264..f16305779a43 100644 --- a/tests/python/unittest/test_schedule_bound_inference.py +++ b/tests/python/unittest/test_schedule_bound_inference.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_bound1(): diff --git a/tests/python/unittest/test_schedule_graph.py b/tests/python/unittest/test_schedule_graph.py index b4b76e69018b..d77c1d470aba 100644 --- a/tests/python/unittest/test_schedule_graph.py +++ b/tests/python/unittest/test_schedule_graph.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_scan(): diff --git a/tests/python/unittest/test_schedule_lstm.py b/tests/python/unittest/test_schedule_lstm.py index 2f942cb514fc..21cf8e81badd 100644 --- a/tests/python/unittest/test_schedule_lstm.py +++ b/tests/python/unittest/test_schedule_lstm.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def test_lstm_cell_inline(): diff --git a/tests/python/unittest/test_schedule_schedule_ops.py b/tests/python/unittest/test_schedule_schedule_ops.py index c7cf1c142dd0..864d6aea2799 100644 --- a/tests/python/unittest/test_schedule_schedule_ops.py +++ b/tests/python/unittest/test_schedule_schedule_ops.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np @@ -459,6 +475,26 @@ def test_reduction_and_dummy_fuse_split(): f(*args) assert np.all(args[0].asnumpy() == n) +def test_schedule_compute_inline(): + shape = [10, 1024] + A = tvm.placeholder(shape, name="A") + B = tvm.placeholder(shape, name="B") + C = tvm.compute(shape, lambda *index:A(*index)+ B(*index), name = "C") + def _compute(*index) : + return C(*index) , C(*index) * B(*index) + F,E = tvm.compute(shape, _compute, name = "F") + + s = tvm.create_schedule([F.op, E.op]) + AL = s.cache_read(A, "local", [C]) + BL = s.cache_read(B, "local", [C,E]) + CL = s.cache_write(C, "local") + FL, EL = s.cache_write([F, E], "local") + s[C].compute_inline() + + s = s.normalize() + bounds = tvm.schedule.InferBound(s) + stmt = tvm.schedule.ScheduleOps(s, bounds) + if __name__ == "__main__": test_loop_dep_reduce() test_loop_dep_reduce_cache_write() @@ -483,3 +519,4 @@ def test_reduction_and_dummy_fuse_split(): test_schedule_tensor_compute2() test_schedule_tensor_compute3() test_reduction_and_dummy_fuse_split() + test_schedule_compute_inline() diff --git a/tests/python/unittest/test_schedule_tensorize.py b/tests/python/unittest/test_schedule_tensorize.py index 259c302eddd8..b8b9e3d158b5 100644 --- a/tests/python/unittest/test_schedule_tensorize.py +++ b/tests/python/unittest/test_schedule_tensorize.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm def intrin_vadd(n): diff --git a/tests/python/unittest/test_testing.py b/tests/python/unittest/test_testing.py index 852bf2ce7e11..b17d8893a955 100644 --- a/tests/python/unittest/test_testing.py +++ b/tests/python/unittest/test_testing.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import tvm from tvm.testing import check_numerical_grads diff --git a/tests/scripts/task_build.sh b/tests/scripts/task_build.sh index 2225d6eea5c3..2440f0f6e79c 100755 --- a/tests/scripts/task_build.sh +++ b/tests/scripts/task_build.sh @@ -1,2 +1,18 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. cd $1 && cmake .. && make $2 && cd .. diff --git a/tests/scripts/task_clean.sh b/tests/scripts/task_clean.sh index 815680bfdc0c..bee75cebc742 100755 --- a/tests/scripts/task_clean.sh +++ b/tests/scripts/task_clean.sh @@ -1,3 +1,19 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. echo "Cleanup data..." cd $1 && rm -rf Cmake* && cd .. diff --git a/tests/scripts/task_cpp_unittest.sh b/tests/scripts/task_cpp_unittest.sh index 339019b0aa4d..793eb91b5d11 100755 --- a/tests/scripts/task_cpp_unittest.sh +++ b/tests/scripts/task_cpp_unittest.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/tests/scripts/task_golang.sh b/tests/scripts/task_golang.sh index 672445c99743..3e72756fcafe 100755 --- a/tests/scripts/task_golang.sh +++ b/tests/scripts/task_golang.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/tests/scripts/task_java_unittest.sh b/tests/scripts/task_java_unittest.sh index fa85f24ef801..6dc25c825c04 100755 --- a/tests/scripts/task_java_unittest.sh +++ b/tests/scripts/task_java_unittest.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/tests/scripts/task_lint.sh b/tests/scripts/task_lint.sh index 318671b082e6..99836748b572 100755 --- a/tests/scripts/task_lint.sh +++ b/tests/scripts/task_lint.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/tests/scripts/task_python_docs.sh b/tests/scripts/task_python_docs.sh index b076a557b6af..b2a3fc1cb176 100755 --- a/tests/scripts/task_python_docs.sh +++ b/tests/scripts/task_python_docs.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/tests/scripts/task_python_frontend.sh b/tests/scripts/task_python_frontend.sh index 4a192ef142ff..ffcd0a104914 100755 --- a/tests/scripts/task_python_frontend.sh +++ b/tests/scripts/task_python_frontend.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u @@ -36,6 +52,9 @@ python3 -m nose -v nnvm/tests/python/frontend/tensorflow echo "Running nnvm CoreML frontend test..." python3 -m nose -v nnvm/tests/python/frontend/coreml +echo "Running nnvm DarkNet frontend test..." +python3 -m nose -v nnvm/tests/python/frontend/darknet || exit -1 + echo "Running relay MXNet frontend test..." python3 -m nose -v tests/python/frontend/mxnet diff --git a/tests/scripts/task_python_integration.sh b/tests/scripts/task_python_integration.sh index abed38d6639d..54e41d39e6e2 100755 --- a/tests/scripts/task_python_integration.sh +++ b/tests/scripts/task_python_integration.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/tests/scripts/task_python_topi.sh b/tests/scripts/task_python_topi.sh index 58c4d18cdc31..bd89604c52ef 100755 --- a/tests/scripts/task_python_topi.sh +++ b/tests/scripts/task_python_topi.sh @@ -1,3 +1,21 @@ +#!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + set -e set -u diff --git a/tests/scripts/task_python_unittest.sh b/tests/scripts/task_python_unittest.sh index 1c1f4c6f1390..6f6b2777d1d0 100755 --- a/tests/scripts/task_python_unittest.sh +++ b/tests/scripts/task_python_unittest.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/tests/scripts/task_python_vta.sh b/tests/scripts/task_python_vta.sh index ea71fda17864..be0f0c694aab 100755 --- a/tests/scripts/task_python_vta.sh +++ b/tests/scripts/task_python_vta.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/tests/scripts/task_rust.sh b/tests/scripts/task_rust.sh index be0181b4d95b..46cafe3ccd79 100755 --- a/tests/scripts/task_rust.sh +++ b/tests/scripts/task_rust.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u @@ -14,11 +30,11 @@ cargo fmt -- --check # test common cd $RUST_DIR/common -cargo build --features runtime -cargo test --features runtime --tests +cargo build +cargo test --tests -cargo build --features frontend -cargo test --features frontend --tests +cargo build --features bindings +cargo test --features bindings --tests # test runtime cd $RUST_DIR/runtime diff --git a/tests/scripts/task_verilog_test.sh b/tests/scripts/task_verilog_test.sh index 69b5aeb90420..8d725844bb5f 100755 --- a/tests/scripts/task_verilog_test.sh +++ b/tests/scripts/task_verilog_test.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/tests/scripts/task_web_build.sh b/tests/scripts/task_web_build.sh index a134442a02fe..25854f5e6d21 100755 --- a/tests/scripts/task_web_build.sh +++ b/tests/scripts/task_web_build.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. cp /emsdk-portable/.emscripten ~/.emscripten source /emsdk-portable/emsdk_env.sh make -j4 diff --git a/tests/scripts/task_web_test.sh b/tests/scripts/task_web_test.sh index 5ac5f1ae8ae7..4b383a1780aa 100755 --- a/tests/scripts/task_web_test.sh +++ b/tests/scripts/task_web_test.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. set -e set -u diff --git a/tests/travis/run_test.sh b/tests/travis/run_test.sh old mode 100755 new mode 100644 index bb23e2df058a..008fd2182459 --- a/tests/travis/run_test.sh +++ b/tests/travis/run_test.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. if [ ${TASK} == "lint" ] || [ ${TASK} == "all_test" ]; then if [ ! ${TRAVIS_OS_NAME} == "osx" ]; then diff --git a/tests/travis/setup.sh b/tests/travis/setup.sh old mode 100755 new mode 100644 index 066b163748f2..6e4d4903382e --- a/tests/travis/setup.sh +++ b/tests/travis/setup.sh @@ -1,4 +1,20 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. if [ ${TASK} == "python_test" ] || [ ${TASK} == "all_test" ]; then if [ ${TRAVIS_OS_NAME} == "osx" ]; then diff --git a/tests/travis/travis_after_failure.sh b/tests/travis/travis_after_failure.sh old mode 100755 new mode 100644 index a9bf588e2f88..36bf5d2347fd --- a/tests/travis/travis_after_failure.sh +++ b/tests/travis/travis_after_failure.sh @@ -1 +1,17 @@ #!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. diff --git a/tests/verilog/integration/test_codegen_verilog.py b/tests/verilog/integration/test_codegen_verilog.py deleted file mode 100644 index 7ce264797012..000000000000 --- a/tests/verilog/integration/test_codegen_verilog.py +++ /dev/null @@ -1,69 +0,0 @@ -import tvm -from tvm.contrib import verilog -import numpy as np - -def lower(s, args, name): - binds = {} - arg_list = [] - - for x in args: - assert isinstance(x, tvm.tensor.Tensor) - buf = tvm.decl_buffer(x.shape, dtype=x.dtype, name=x.op.name) - binds[x] = buf - arg_list.append(buf) - s = s.normalize() - bounds = tvm.schedule.InferBound(s) - stmt = tvm.schedule.ScheduleOps(s, bounds) - stmt = tvm.ir_pass.StorageFlatten(stmt, binds, 64) - stmt = tvm.ir_pass.CanonicalSimplify(stmt) - stmt = tvm.ir_pass.Simplify(stmt) - stmt = tvm.ir_pass.SplitPipeline(stmt, True) - fapi = tvm.ir_pass.MakeAPI(stmt, name, arg_list, 0, True) - return fapi - -@tvm.register_func -def tvm_callback_verilog_postproc(code): - """Hook to inspect the verilog code before actually run it""" - print(code) - return code - -def test_add_pipeline(): - nn = 128 - n = tvm.convert(nn) - A = tvm.placeholder((n,), name='A', dtype='int32') - B = tvm.placeholder((n,), name='B', dtype='int32') - C = tvm.compute(A.shape, lambda i: A[i] + B[i], name='C') - s = tvm.create_schedule(C.op) - - px, x = s[C].split(C.op.axis[0], nparts=1) - s[C].bind(px, tvm.thread_axis("pipeline")) - fapi = lower(s, [A, B, C], "myadd") - fsplits = [x for x in tvm.ir_pass.SplitHostDevice(fapi)] - fsplits[0] = tvm.ir_pass.LowerTVMBuiltin(fsplits[0]) - print("------") - - def check_target(device, host="stackvm"): - if not tvm.module.enabled(host): - return - if not tvm.module.enabled(device): - return - ctx = tvm.vpi(0) - mhost = tvm.codegen.build_module(fsplits[0], host) - mdev = tvm.codegen.build_module(fsplits[1:], device) - mhost.import_module(mdev) - code = mdev.get_source() - f = mhost.entry_func - # launch the kernel. - n = nn - a = tvm.nd.array((np.random.uniform(size=n) * 128).astype(A.dtype), ctx) - b = tvm.nd.array((np.random.uniform(size=n) * 128).astype(A.dtype), ctx) - c = tvm.nd.array(np.zeros(n, dtype=C.dtype), ctx) - f(a, b, c) - print("Check correctness...") - tvm.testing.assert_allclose( - c.asnumpy(), a.asnumpy() + b.asnumpy()) - check_target("verilog") - - -if __name__ == "__main__": - test_add_pipeline() diff --git a/tests/verilog/unittest/test_buffer_doublebuff.py b/tests/verilog/unittest/test_buffer_doublebuff.py deleted file mode 100644 index e3ef918ba070..000000000000 --- a/tests/verilog/unittest/test_buffer_doublebuff.py +++ /dev/null @@ -1,73 +0,0 @@ -import tvm -import numpy as np -from tvm.contrib import verilog - -def test_buffer_doublebuff(): - # Test the tvm_buffer.v module as a double buffer - # Window size is 16, buffer size is 32 - window_width = 16 - set_size = 8 - - # Find file will search root/verilog and root/tests/verilog - sess = verilog.session([ - verilog.find_file("test_buffer_doublebuff.v"), - verilog.find_file("tvm_buffer.v") - ]) - - # Get the handles by their names - rst = sess.main.rst - write_advance = sess.main.write_advance - write_addr = sess.main.write_addr - write_valid = sess.main.write_valid - write_ready = sess.main.write_ready - write_data = sess.main.write_data - read_data = sess.main.read_data - read_data_valid = sess.main.read_data_valid - - # Simulation input data - test_data = np.arange(window_width*set_size).astype('int8') - - # Initial state - rst.put_int(1) - write_advance.put_int(0) - write_addr.put_int(0) - write_valid.put_int(0) - write_data.put_int(0) - - # De-assert reset - sess.yield_until_next_cycle() - rst.put_int(0) - - # Leave the following signals set to true - sess.yield_until_next_cycle() - write_valid.put_int(1) - - # Main simulation loop - write_idx = 0 - read_idx = 0 - while read_idx < len(test_data): - # write logic - if (write_idx < len(test_data)): - write_advance.put_int(0) - if (write_ready.get_int()): - write_data.put_int(int(test_data[write_idx])) - write_addr.put_int(write_idx % window_width) - if (write_idx%window_width==window_width-1): - write_advance.put_int(1) - write_idx += 1 - else: - write_advance.put_int(0) - write_valid.put_int(0) - - # correctness checks - if (read_data_valid.get_int()): - assert(read_data.get_int()==test_data[read_idx]) - # print "{} {}".format(read_data.get_int(), test_data[read_idx]) - read_idx += 1 - - # step - sess.yield_until_next_cycle() - - -if __name__ == "__main__": - test_buffer_doublebuff() diff --git a/tests/verilog/unittest/test_buffer_doublebuff.v b/tests/verilog/unittest/test_buffer_doublebuff.v deleted file mode 100644 index f9a7a92d5a5c..000000000000 --- a/tests/verilog/unittest/test_buffer_doublebuff.v +++ /dev/null @@ -1,107 +0,0 @@ -module main(); - - // Parameters - parameter PER=10; - - // Double buffer parameters - parameter DATA_WIDTH = 8; - parameter DEPTH = 32; - parameter CNTR_WIDTH = 6; // floor(log(32)) + 1 - parameter RD_WINDOW = 16; - parameter RD_ADVANCE = 16; - parameter RD_ADDR_WIDTH = 5; // floor(log(16)) + 1 - parameter WR_WINDOW = 16; - parameter WR_ADVANCE = 16; - parameter WR_ADDR_WIDTH = 5; // floor(log(16)) + 1 - - // Clock & reset - reg clk; - reg rst; - - // Read port inputs - reg read_advance; - reg [RD_ADDR_WIDTH-1:0] read_addr; - reg read_ready; - // Write port outputs - reg write_advance; - reg [DATA_WIDTH-1:0] write_data; - reg [WR_ADDR_WIDTH-1:0] write_addr; - reg write_valid; - - // Outputs - wire [DATA_WIDTH-1:0] read_data; - wire read_valid; - wire write_ready; - wire [CNTR_WIDTH-1:0] status_counter; - - // Module instantiation - tvm_buffer #( - .DATA_WIDTH(DATA_WIDTH), - .DEPTH(DEPTH), - .CNTR_WIDTH(CNTR_WIDTH), - .RD_WINDOW(RD_WINDOW), - .RD_ADVANCE(RD_ADVANCE), - .RD_ADDR_WIDTH(RD_ADDR_WIDTH), - .WR_WINDOW(WR_WINDOW), - .WR_ADVANCE(WR_ADVANCE), - .WR_ADDR_WIDTH(WR_ADDR_WIDTH) - ) uut ( - .clk(clk), - .rst(rst), - .read_advance(read_advance), - .read_data(read_data), - .read_addr(read_addr), - .read_ready(read_ready), - .read_valid(read_valid), - .write_advance(write_advance), - .write_data(write_data), - .write_addr(write_addr), - .write_ready(write_ready), - .write_valid(write_valid), - .status_counter(status_counter) - ); - - // clock generation - always begin - #(PER/2) clk =~ clk; - end - - // read logic - always @(posedge clk) begin - if (rst) begin - read_advance <= 0; - read_addr <= 0; - read_ready <= 0; - end else begin - if (read_valid) begin - read_ready <= 1; - end else begin - read_ready <= 0; - end - if (read_addr%RD_WINDOW==RD_WINDOW-2) begin - read_advance <= 1; - end else begin - read_advance <= 0; - end - if (read_ready) begin - read_addr <= (read_addr+1) % WR_WINDOW; - end else begin - read_addr <= read_addr % WR_WINDOW; - end - end - end - - // read_data_valid logic - reg read_data_valid; - always @(posedge clk) begin - if (rst) - read_data_valid <= 0; - else - read_data_valid <= read_ready; - end - - initial begin - // This will allow tvm session to be called every cycle. - $tvm_session(clk); - end -endmodule diff --git a/tests/verilog/unittest/test_buffer_fifo.py b/tests/verilog/unittest/test_buffer_fifo.py deleted file mode 100644 index 4fc44872570c..000000000000 --- a/tests/verilog/unittest/test_buffer_fifo.py +++ /dev/null @@ -1,53 +0,0 @@ -import tvm -import numpy as np -from tvm.contrib import verilog - -def test_buffer_fifo(): - # Test the tvm_buffer.v module as a fifo - - # Find file will search root/verilog and root/tests/verilog - sess = verilog.session([ - verilog.find_file("test_buffer_fifo.v"), - verilog.find_file("tvm_buffer.v") - ]) - - # Get the handles by their names - rst = sess.main.rst - enq = sess.main.enq - write_data = sess.main.write_data - read_data = sess.main.read_data - read_data_valid = sess.main.read_data_valid - - # Simulation input data - test_data = np.arange(16).astype('int8') - - # Initial state - rst.put_int(1) - enq.put_int(0) - write_data.put_int(0) - - # De-assert reset - sess.yield_until_next_cycle() - rst.put_int(0) - - # Main simulation loop - read_idx = 0 - write_idx = 0 - while read_idx < len(test_data): - # write logic - if (write_idx < len(test_data)): - enq.put_int(1) - write_data.put_int(write_idx) - write_idx += 1 - else: - enq.put_int(0) - # read logic - if (read_data_valid.get_int()): - assert(read_data.get_int()==test_data[read_idx]) - read_idx += 1 - # step - sess.yield_until_next_cycle() - - -if __name__ == "__main__": - test_buffer_fifo() diff --git a/tests/verilog/unittest/test_buffer_fifo.v b/tests/verilog/unittest/test_buffer_fifo.v deleted file mode 100644 index a20f77d4b042..000000000000 --- a/tests/verilog/unittest/test_buffer_fifo.v +++ /dev/null @@ -1,89 +0,0 @@ -module main(); - - // Parameters - parameter PER=10; - - // FIFO parameters - parameter DATA_WIDTH = 8; - parameter DEPTH = 32; - parameter CNTR_WIDTH = 6; // floor(log(32)) + 1 - parameter RD_WINDOW = 1; - parameter RD_ADVANCE = 1; - parameter RD_ADDR_WIDTH = 1; - parameter WR_WINDOW = 1; - parameter WR_ADVANCE = 1; - parameter WR_ADDR_WIDTH = 1; - - // Clock & reset - reg clk; - reg rst; - - // Module inputs - reg [DATA_WIDTH-1:0] write_data; - // FIFO interface abstraction: - // Connect deq to read_advance and read_ready - // Connect enq to write_advance and write_valid - // Set read_addr and write_addr to 0 - reg deq; - reg enq; - - // Module outputs - wire [DATA_WIDTH-1:0] read_data; - wire read_valid; - wire write_ready; - wire [CNTR_WIDTH-1:0] status_counter; - - // Module instantiation - tvm_buffer #( - .DATA_WIDTH(DATA_WIDTH), - .DEPTH(DEPTH), - .CNTR_WIDTH(CNTR_WIDTH), - .RD_WINDOW(RD_WINDOW), - .RD_ADVANCE(RD_ADVANCE), - .RD_ADDR_WIDTH(RD_ADDR_WIDTH), - .WR_WINDOW(WR_WINDOW), - .WR_ADVANCE(WR_ADVANCE), - .WR_ADDR_WIDTH(WR_ADDR_WIDTH) - ) uut ( - .clk(clk), - .rst(rst), - .read_advance(deq), - .read_addr({RD_ADDR_WIDTH{1'b0}}), - .read_ready(deq), - .read_valid(read_valid), - .read_data(read_data), - .write_advance(enq), - .write_addr({WR_ADDR_WIDTH{1'b0}}), - .write_ready(write_ready), - .write_valid(enq), - .write_data(write_data), - .status_counter(status_counter) - ); - - // clock generation - always begin - #(PER/2) clk =~ clk; - end - - // fifo read logic - always @(posedge clk) begin - if (rst) - deq <= 0; - else - deq <= read_valid; - end - - // read_data_valid logic - reg read_data_valid; - always @(posedge clk) begin - if (rst) - read_data_valid <= 0; - else - read_data_valid <= deq; - end - - initial begin - // This will allow tvm session to be called every cycle. - $tvm_session(clk); - end -endmodule diff --git a/tests/verilog/unittest/test_buffer_linebuff.py b/tests/verilog/unittest/test_buffer_linebuff.py deleted file mode 100644 index d2f155edeb6a..000000000000 --- a/tests/verilog/unittest/test_buffer_linebuff.py +++ /dev/null @@ -1,74 +0,0 @@ -import tvm -import numpy as np -from tvm.contrib import verilog - -def test_buffer_linebuff(): - # Test the tvm_buffer.v module as a line buffer - # Window is 8x8, kernel is 3x3 - window_width = 8 - kernel_width = 3 - - # Find file will search root/verilog and root/tests/verilog - sess = verilog.session([ - verilog.find_file("test_buffer_linebuff.v"), - verilog.find_file("tvm_buffer.v") - ]) - - # Get the handles by their names - rst = sess.main.rst - write_advance = sess.main.write_advance - write_valid = sess.main.write_valid - write_ready = sess.main.write_ready - write_data = sess.main.write_data - read_data = sess.main.read_data - read_data_valid = sess.main.read_data_valid - - # Simulation input data - test_data = np.arange(window_width*window_width).astype('int8') - - # Initial state - rst.put_int(1) - write_advance.put_int(0) - write_valid.put_int(0) - write_data.put_int(0) - - # De-assert reset - sess.yield_until_next_cycle() - rst.put_int(0) - - # Leave the following signals set to true - sess.yield_until_next_cycle() - write_advance.put_int(1) - write_valid.put_int(1) - - # Main simulation loop - write_idx = 0 - read_idx = 0 - while read_idx < (window_width-kernel_width+1)*(window_width-kernel_width+1)*kernel_width*kernel_width: - # write logic - if (write_idx < len(test_data)): - if (write_ready.get_int()): - write_data.put_int(int(test_data[write_idx])) - write_idx += 1 - else: - write_advance.put_int(0) - write_valid.put_int(0) - - # correctness checks - if (read_data_valid.get_int()): - # Derive convolution window indices - baseIdx = read_idx // (kernel_width*kernel_width) - offsetIdx = read_idx % (kernel_width*kernel_width) - yOffset = offsetIdx // kernel_width - xOffset = offsetIdx%kernel_width - pixIndex = baseIdx + yOffset * window_width + xOffset - assert(read_data.get_int()==test_data[pixIndex]) - # print "{} {}".format(read_data.get_int(), test_data[pixIndex]) - read_idx += 1 - - # step - sess.yield_until_next_cycle() - - -if __name__ == "__main__": - test_buffer_linebuff() diff --git a/tests/verilog/unittest/test_buffer_linebuff.v b/tests/verilog/unittest/test_buffer_linebuff.v deleted file mode 100644 index 641947a5ed24..000000000000 --- a/tests/verilog/unittest/test_buffer_linebuff.v +++ /dev/null @@ -1,121 +0,0 @@ -module main(); - - // Parameters - parameter PER=10; - - // In this example we perform a 3x3 convolution of an 8x8 input image - // Therefore the window size here is (3-1)*8+3 = 19 - parameter IMAGE_WIDTH = 8; - parameter KERNEL_WIDTH = 3; - // Line buffer parameters - parameter DATA_WIDTH = 8; - parameter DEPTH = 20; // (3-1)*8+3+1 - parameter CNTR_WIDTH = 5; // floor(log(20)) + 1 - parameter RD_WINDOW = 19; // (3-1)*8+3 - parameter RD_ADVANCE = 1; - parameter RD_ADDR_WIDTH = 5; // floor(log(19)) + 1 - parameter WR_WINDOW = 1; - parameter WR_ADVANCE = 1; - parameter WR_ADDR_WIDTH = 1; - - // Clock & reset - reg clk; - reg rst; - - // Read port inputs - reg read_advance; - reg [RD_ADDR_WIDTH-1:0] read_addr; - reg read_ready; - // Write port outputs - reg write_advance; - reg [DATA_WIDTH-1:0] write_data; - reg write_valid; - - // Outputs - wire [DATA_WIDTH-1:0] read_data; - wire read_valid; - wire write_ready; - wire [CNTR_WIDTH-1:0] status_counter; - - // Module instantiation - tvm_buffer #( - .DATA_WIDTH(DATA_WIDTH), - .DEPTH(DEPTH), - .CNTR_WIDTH(CNTR_WIDTH), - .RD_WINDOW(RD_WINDOW), - .RD_ADVANCE(RD_ADVANCE), - .RD_ADDR_WIDTH(RD_ADDR_WIDTH), - .WR_WINDOW(WR_WINDOW), - .WR_ADVANCE(WR_ADVANCE), - .WR_ADDR_WIDTH(WR_ADDR_WIDTH) - ) uut ( - .clk(clk), - .rst(rst), - .read_advance(read_advance), - .read_data(read_data), - .read_addr(read_addr), - .read_ready(read_ready), - .read_valid(read_valid), - .write_advance(write_advance), - .write_data(write_data), - .write_addr({WR_ADDR_WIDTH{1'b0}}), - .write_ready(write_ready), - .write_valid(write_valid), - .status_counter(status_counter) - ); - - // clock generation - always begin - #(PER/2) clk =~ clk; - end - - // read logic - localparam KERNEL_SIZE = KERNEL_WIDTH*KERNEL_WIDTH; - reg [3:0] read_counter; - always @(posedge clk) begin - if (rst) begin - read_counter <= KERNEL_SIZE-1; - read_advance <= 0; - read_addr <= -1; - read_ready <= 0; - end else begin - if (read_valid) begin - read_counter <= (read_counter+1)%KERNEL_SIZE; - read_ready <= 1; - // Only advance at the last inner loop iteration - if (read_counter==KERNEL_SIZE-2) begin - read_advance <= 1; - end else begin - read_advance <= 0; - end - // Read address should describe a loop - if (read_counter==KERNEL_SIZE-1) begin - read_addr <= 0; - end else if (read_counter%KERNEL_WIDTH==KERNEL_WIDTH-1) begin - read_addr <= read_addr+IMAGE_WIDTH-KERNEL_WIDTH+1; - end else begin - read_addr <= read_addr+1; - end - end else begin - read_counter <= read_counter; - read_advance <= 0; - read_addr <= read_addr; - read_ready <= 0; - end - end - end - - // read_data_valid logic - reg read_data_valid; - always @(posedge clk) begin - if (rst) - read_data_valid <= 0; - else - read_data_valid <= read_ready; - end - - initial begin - // This will allow tvm session to be called every cycle. - $tvm_session(clk); - end -endmodule diff --git a/tests/verilog/unittest/test_cache_reg.py b/tests/verilog/unittest/test_cache_reg.py deleted file mode 100644 index 3ed7bd2c39cd..000000000000 --- a/tests/verilog/unittest/test_cache_reg.py +++ /dev/null @@ -1,48 +0,0 @@ -import tvm -from tvm.contrib import verilog -from testing_util import FIFODelayedWriter, FIFODelayedReader - -def run_with_lag(n, read_lag, write_lag): - data = list(range(n)) - # head ptr of a - sess = verilog.session([ - verilog.find_file("test_cache_reg.v") - ]) - rst = sess.main.rst - in_data = sess.main.in_data - in_valid = sess.main.in_valid - in_ready = sess.main.in_ready - - out_data = sess.main.out_data - out_valid = sess.main.out_valid - out_ready = sess.main.out_ready - # hook up reader - reader = FIFODelayedReader(out_data, out_valid, out_ready, read_lag) - writer = FIFODelayedWriter(in_data, in_valid, in_ready, data, write_lag) - rst.put_int(1) - sess.yield_until_next_cycle() - rst.put_int(0) - sess.yield_until_next_cycle() - sess.yield_callbacks.append(reader) - sess.yield_callbacks.append(writer) - timeout = sum(read_lag) + sum(write_lag) + n + 10 - for t in range(timeout): - sess.yield_until_next_cycle() - if len(reader.data) == n: - break - assert tuple(reader.data) == tuple(range(n)) - assert len(writer.data) == 0 - sess.shutdown() - -def test_fifo(): - n = 20 - # slow reader - run_with_lag(n, read_lag=[3,4,8], write_lag=[]) - # slow writer - run_with_lag(n, read_lag=[0], write_lag=[0, 2, 10]) - # mix - run_with_lag(n, read_lag=[3, 4, 8], write_lag=[0, 2, 10]) - - -if __name__ == "__main__": - test_fifo() diff --git a/tests/verilog/unittest/test_cache_reg.v b/tests/verilog/unittest/test_cache_reg.v deleted file mode 100644 index 030b8bc34b33..000000000000 --- a/tests/verilog/unittest/test_cache_reg.v +++ /dev/null @@ -1,20 +0,0 @@ -`include "tvm_marcos.v" - -module main(); - `TVM_DEFINE_TEST_SIGNAL(clk, rst) - - reg[31:0] in_data; - wire[31:0] out_data; - wire in_ready; - reg in_valid; - reg out_ready; - wire out_valid; - - `CACHE_REG(32, in_data, in_valid, in_ready, - out_data, out_valid, out_ready) - - initial begin - // This will allow tvm session to be called every cycle. - $tvm_session(clk); - end -endmodule diff --git a/tests/verilog/unittest/test_counter.py b/tests/verilog/unittest/test_counter.py deleted file mode 100644 index c32904d5c50d..000000000000 --- a/tests/verilog/unittest/test_counter.py +++ /dev/null @@ -1,53 +0,0 @@ -import tvm -from tvm.contrib import verilog - -def test_counter(): - # Start a new session by run simulation on test_counter.v - # Find file will search root/verilog and root/tests/verilog - sess = verilog.session([ - verilog.find_file("test_counter.v"), - verilog.find_file("example_counter.v") - ]) - # Get the handles by their names - rst = sess.main.rst - counter = sess.main.counter - cnt = sess.main["counter_unit1"] - assert(counter.name == "main.counter") - assert(counter.size == 4) - rst.put_int(1) - # This will advance the cycle to next pos-edge of clk. - sess.yield_until_next_cycle() - rst.put_int(0) - sess.yield_until_next_cycle() - - for i in range(10): - # get value of counter. - assert(counter.get_int() == i) - sess.yield_until_next_cycle() - - -def test_scratch(): - sess = verilog.session([ - verilog.find_file("test_counter.v"), - verilog.find_file("example_counter.v") - ]) - # Get the handles by their names - rst = sess.main.rst - counter = sess.main.counter - rst.put_int(1) - # This will advance the cycle to next pos-edge of clk. - sess.yield_until_next_cycle() - rst.put_int(0) - temp = 0 - for i in range(10): - if rst.get_int(): - rst.put_int(0) - temp = counter.get_int() - elif counter.get_int() == 3: - rst.put_int(1) - print("counter=%d, temp=%d" % (counter.get_int(), temp)) - sess.yield_until_next_cycle() - -if __name__ == "__main__": - test_scratch() - test_counter() diff --git a/tests/verilog/unittest/test_counter.v b/tests/verilog/unittest/test_counter.v deleted file mode 100644 index ca421532b2d9..000000000000 --- a/tests/verilog/unittest/test_counter.v +++ /dev/null @@ -1,13 +0,0 @@ -`include "tvm_marcos.v" - -module main(); - `TVM_DEFINE_TEST_SIGNAL(clk, rst) - - wire[3:0] counter; - counter counter_unit1(.clk(clk), .rst(rst), .out(counter)); - - initial begin - // This will allow tvm session to be called every cycle. - $tvm_session(clk); - end -endmodule diff --git a/tests/verilog/unittest/test_loop.py b/tests/verilog/unittest/test_loop.py deleted file mode 100644 index 3958444cbf9a..000000000000 --- a/tests/verilog/unittest/test_loop.py +++ /dev/null @@ -1,30 +0,0 @@ -import tvm -from tvm.contrib import verilog - -def test_loop(): - sess = verilog.session([ - verilog.find_file("test_loop.v") - ]) - # Get the handles by their names - rst = sess.main.rst - iter0 = sess.main.iter0 - iter1 = sess.main.iter1 - ready = sess.main.ready - - rst.put_int(1) - ready.put_int(1) - # This will advance the cycle to next pos-edge of clk. - sess.yield_until_next_cycle() - rst.put_int(0) - sess.yield_until_next_cycle() - - for k in range(0, 1): - for i in range(0, 3): - for j in range(0, 4): - assert(iter1.get_int() == i) - assert(iter0.get_int() == j) - sess.yield_until_next_cycle() - - -if __name__ == "__main__": - test_loop() diff --git a/tests/verilog/unittest/test_loop.v b/tests/verilog/unittest/test_loop.v deleted file mode 100644 index 4422c0dcfcc6..000000000000 --- a/tests/verilog/unittest/test_loop.v +++ /dev/null @@ -1,19 +0,0 @@ -`include "tvm_marcos.v" - -module main(); - `TVM_DEFINE_TEST_SIGNAL(clk, rst) - - reg ready; - wire lp_ready; - - `NONSTOP_LOOP(iter0, 4, 0, lp_ready, iter0_finish, 0, 4) - `NONSTOP_LOOP(iter1, 4, 0, iter0_finish, iter1_finish, 0, 3) - `WRAP_LOOP_ONCE(0, valid, ready, iter1_finish, loop_ready) - assign lp_ready = loop_ready; - - - initial begin - // This will allow tvm session to be called every cycle. - $tvm_session(clk); - end -endmodule diff --git a/tests/verilog/unittest/test_vpi_mem_interface.py b/tests/verilog/unittest/test_vpi_mem_interface.py deleted file mode 100644 index 1aae8d0360db..000000000000 --- a/tests/verilog/unittest/test_vpi_mem_interface.py +++ /dev/null @@ -1,132 +0,0 @@ -import tvm -import numpy as np -from tvm.contrib import verilog - -class FIFOReader(object): - """Auxiliary class to read from FIFO """ - def __init__(self, read_data, read_valid): - self.read_data = read_data - self.read_valid = read_valid - self.data = [] - - def __call__(self): - if self.read_valid.get_int(): - self.data.append(self.read_data.get_int()) - -class FIFOWriter(object): - """Auxiliary class to write to FIFO """ - def __init__(self, write_data, write_enable, write_pend, data): - self.write_data = write_data - self.write_enable = write_enable - self.write_pend = write_pend - self.data = data - - def __call__(self): - if self.data and self.write_pend.get_int(): - self.write_enable.put_int(1) - self.write_data.put_int(int(self.data[0])) - del self.data[0] - else: - self.write_enable.put_int(0) - - -def test_ram_read(): - n = 10 - # context for VPI RAM - ctx = tvm.vpi(0) - a_np = np.arange(n).astype('int8') - a = tvm.nd.array(a_np, ctx) - - # head ptr of a - a_ptr = int(a.handle[0].data) - sess = verilog.session([ - verilog.find_file("test_vpi_mem_interface.v"), - verilog.find_file("tvm_vpi_mem_interface.v") - ]) - rst = sess.main.rst - read_data = sess.main.read_data - read_valid = sess.main.read_data_valid - read_en = sess.main.read_en - host_read_req = sess.main.read_req - host_read_addr = sess.main.read_addr - host_read_size = sess.main.read_size - rst.put_int(1) - sess.yield_until_next_cycle() - rst.put_int(0) - # hook up reader - reader = FIFOReader(read_data, read_valid) - sess.yield_callbacks.append(reader) - # request read - host_read_req.put_int(1) - host_read_addr.put_int(a_ptr) - host_read_size.put_int(a.shape[0]) - - sess.yield_until_next_cycle() - # second read request - host_read_addr.put_int(a_ptr + 2) - host_read_size.put_int(a.shape[0] - 2) - - sess.yield_until_next_cycle() - host_read_req.put_int(0) - read_en.put_int(1) - - # yield until read is done - for i in range(a.shape[0] * 3): - sess.yield_until_next_cycle() - sess.shutdown() - # check if result matches - r = np.concatenate((a_np, a_np[2:])) - np.testing.assert_equal(np.array(reader.data), r) - -def test_ram_write(): - n = 10 - # read from offset - offset = 2 - # context for VPI RAM - ctx = tvm.vpi(0) - a_np = np.zeros(n).astype('int8') - a = tvm.nd.array(a_np, ctx) - w_data = list(range(2, n)) - r_data = np.array(w_data, dtype='int8') - - # head ptr of a - a_ptr = int(a.handle[0].data) - - sess = verilog.session([ - verilog.find_file("test_vpi_mem_interface.v"), - verilog.find_file("tvm_vpi_mem_interface.v") - ]) - rst = sess.main.rst - write_data = sess.main.write_data - write_en = sess.main.write_en - write_ready = sess.main.write_data_ready - host_write_req = sess.main.write_req - host_write_addr = sess.main.write_addr - host_write_size = sess.main.write_size - - rst.put_int(1) - sess.yield_until_next_cycle() - rst.put_int(0) - # hook up writeer - writer = FIFOWriter(write_data, write_en, write_ready, w_data) - - sess.yield_callbacks.append(writer) - # request write - host_write_req.put_int(1) - host_write_addr.put_int(a_ptr + offset) - host_write_size.put_int(a.shape[0] - offset) - - sess.yield_until_next_cycle() - host_write_req.put_int(0) - - # yield until write is done - for i in range(a.shape[0]+2): - sess.yield_until_next_cycle() - sess.shutdown() - # check if result matches - np.testing.assert_equal(a.asnumpy()[2:], r_data) - - -if __name__ == "__main__": - test_ram_read() - test_ram_write() diff --git a/tests/verilog/unittest/test_vpi_mem_interface.v b/tests/verilog/unittest/test_vpi_mem_interface.v deleted file mode 100644 index def8905edc5a..000000000000 --- a/tests/verilog/unittest/test_vpi_mem_interface.v +++ /dev/null @@ -1,57 +0,0 @@ -module main(); - parameter PER = 10; - parameter WIDTH = 8; - - reg clk; - reg rst; - // read channels - reg read_en; - wire [WIDTH-1:0] read_data; - wire read_data_valid; - // write channels - reg write_en; - reg [WIDTH-1:0] write_data; - wire write_data_ready; - // controls - reg read_req; - reg [31:0] read_addr; - reg [31:0] read_size; - reg write_req; - reg [31:0] write_addr; - reg [31:0] write_size; - - - always begin - #(PER/2) clk =~ clk; - end - - tvm_vpi_mem_interface # - ( - .READ_WIDTH(WIDTH), - .WRITE_WIDTH(WIDTH), - .ADDR_WIDTH(32), - .SIZE_WIDTH(32) - ) - mem - ( - .clk(clk), - .rst(rst), - .read_en(read_en), - .read_data_out(read_data), - .read_data_valid(read_data_valid), - .write_en(write_en), - .write_data_in(write_data), - .write_data_ready(write_data_ready), - .host_read_req(read_req), - .host_read_addr(read_addr), - .host_read_size(read_size), - .host_write_req(write_req), - .host_write_addr(write_addr), - .host_write_size(write_size) - ); - - initial begin - // pass myram to session to hook it up with simulation - $tvm_session(clk, mem); - end -endmodule diff --git a/tests/verilog/unittest/test_vpi_mmap.py b/tests/verilog/unittest/test_vpi_mmap.py deleted file mode 100644 index 03ae6e942a36..000000000000 --- a/tests/verilog/unittest/test_vpi_mmap.py +++ /dev/null @@ -1,56 +0,0 @@ -import tvm -import numpy as np -from tvm.contrib import verilog - -def test_mmap(): - n = 10 - # context for VPI RAM - ctx = tvm.vpi(0) - a_np = np.arange(n).astype('int8') - a = tvm.nd.array(a_np, ctx) - - # head ptr of a - a_ptr = int(a.handle[0].data) - sess = verilog.session([ - verilog.find_file("test_vpi_mmap.v"), - verilog.find_file("tvm_vpi_mmap.v") - ]) - rst = sess.main.rst - read_addr = sess.main.read_addr - read_data = sess.main.read_data - write_addr = sess.main.write_addr - write_data = sess.main.write_data - write_en = sess.main.write_en - mmap_addr = sess.main.mmap_addr - - # setup memory map. - rst.put_int(1) - sess.yield_until_next_cycle() - rst.put_int(0) - write_en.put_int(0) - mmap_addr.put_int(a_ptr) - sess.yield_until_next_cycle() - - # read test - for i in range(n): - read_addr.put_int(i) - sess.yield_until_next_cycle() - # read addr get set this cycle - sess.yield_until_next_cycle() - # get the data out - assert(read_data.get_int() == i) - - # write test - for i in reversed(range(n)): - write_addr.put_int(i) - write_en.put_int(1) - write_data.put_int(i + 1) - sess.yield_until_next_cycle() - write_en.put_int(0) - sess.yield_until_next_cycle() - - np.testing.assert_equal(a.asnumpy(), a_np + 1) - - -if __name__ == "__main__": - test_mmap() diff --git a/tests/verilog/unittest/test_vpi_mmap.v b/tests/verilog/unittest/test_vpi_mmap.v deleted file mode 100644 index c922c43b4575..000000000000 --- a/tests/verilog/unittest/test_vpi_mmap.v +++ /dev/null @@ -1,53 +0,0 @@ -module main(); - parameter PER = 10; - parameter DATA_WIDTH = 8; - parameter ADDR_WIDTH = 8; - reg clk; - reg rst; - // read channels - reg [ADDR_WIDTH-1:0] read_addr; - wire [DATA_WIDTH-1:0] read_data; - // write channels - reg [ADDR_WIDTH-1:0] write_addr; - reg [DATA_WIDTH-1:0] write_data; - reg write_en; - // mmap base - reg [31:0] mmap_addr; - - always begin - #(PER/2) clk =~ clk; - end - - tvm_vpi_read_mmap # - ( - .DATA_WIDTH(DATA_WIDTH), - .ADDR_WIDTH(ADDR_WIDTH) - ) - rmmap - ( - .clk(clk), - .rst(rst), - .addr(read_addr), - .data_out(read_data), - .mmap_addr(mmap_addr) - ); - - tvm_vpi_write_mmap # - ( - .DATA_WIDTH(DATA_WIDTH), - .ADDR_WIDTH(ADDR_WIDTH) - ) - wmmap - ( - .clk(clk), - .rst(rst), - .addr(write_addr), - .data_in(write_data), - .en(write_en), - .mmap_addr(mmap_addr) - ); - - initial begin - $tvm_session(clk, rmmap, wmmap); - end -endmodule diff --git a/tests/verilog/unittest/testing_util.py b/tests/verilog/unittest/testing_util.py deleted file mode 100644 index 6a459f9d8d88..000000000000 --- a/tests/verilog/unittest/testing_util.py +++ /dev/null @@ -1,62 +0,0 @@ -"""Common utilities for test""" - -class FIFODelayedReader(object): - """Reader that have specified ready lag.""" - def __init__(self, read_data, read_valid, read_ready, lag): - self.read_data = read_data - self.read_valid = read_valid - self.read_ready = read_ready - self.read_ready.put_int(1) - self.lag = list(reversed(lag)) - self.data = [] - self.wait_counter = 0 - self.wait_state = False - - def __call__(self): - """Logic as if always at pos-edge""" - if not self.wait_state: - if (self.read_ready.get_int() and - self.read_valid.get_int()): - self.data.append(self.read_data.get_int()) - self.wait_counter = self.lag.pop() if self.lag else 0 - self.wait_state = True - - if self.wait_state: - if self.wait_counter == 0: - self.read_ready.put_int(1) - self.wait_state = False - else: - self.wait_counter -= 1 - self.read_ready.put_int(0) - - -class FIFODelayedWriter(object): - """Auxiliary class to write to FIFO """ - def __init__(self, write_data, write_valid, write_ready, data, lag): - self.write_data = write_data - self.write_valid = write_valid - self.write_ready = write_ready - self.write_valid.put_int(0) - self.lag = list(reversed(lag)) - self.data = list(reversed(data)) - self.wait_counter = 0 - self.wait_state = True - - def __call__(self): - """Logic as if always at pos-edge""" - if not self.wait_state: - if self.write_ready.get_int(): - self.wait_counter = self.lag.pop() if self.lag else 0 - self.wait_state = True - - if self.wait_state: - if self.wait_counter == 0: - if self.data: - self.write_valid.put_int(1) - self.write_data.put_int(self.data.pop()) - self.wait_state = False - else: - self.write_valid.put_int(0) - else: - self.write_valid.put_int(0) - self.wait_counter -= 1 diff --git a/tests/web/prepare_test_libs.py b/tests/web/prepare_test_libs.py index 6feef3683cb1..4b98e5db4206 100644 --- a/tests/web/prepare_test_libs.py +++ b/tests/web/prepare_test_libs.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # Prepare test library for js. import tvm from tvm.contrib import emscripten diff --git a/tests/web/test_basic.js b/tests/web/test_basic.js index 774c5bdd7ca0..6852319dbc12 100644 --- a/tests/web/test_basic.js +++ b/tests/web/test_basic.js @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + // Load Emscripten Module, need to change path to root/build const path = require("path"); process.chdir(path.join(__dirname, "../../build")); diff --git a/tests/web/test_module_load.js b/tests/web/test_module_load.js index e08a0adf8b3a..af5e436afcaf 100644 --- a/tests/web/test_module_load.js +++ b/tests/web/test_module_load.js @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + // Load Emscripten Module, need to change path to root/lib const path = require("path"); process.chdir(path.join(__dirname, "../../build")); diff --git a/tests/web/test_packed_func.js b/tests/web/test_packed_func.js index 766be4f8aa4a..d239f7346e74 100644 --- a/tests/web/test_packed_func.js +++ b/tests/web/test_packed_func.js @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + // Load Emscripten Module, need to change path to root/build const path = require("path"); process.chdir(path.join(__dirname, "../../build")); diff --git a/tests/web/websock_rpc_test.py b/tests/web/websock_rpc_test.py index 0c1c8b050720..b1b4e4c70f91 100644 --- a/tests/web/websock_rpc_test.py +++ b/tests/web/websock_rpc_test.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Simple testcode to test Javascript RPC To use it, start a rpc proxy with "python -m tvm.exec.rpc_proxy". diff --git a/tests/webgl/README.md b/tests/webgl/README.md index c9f2ae3d2272..5303cc059740 100644 --- a/tests/webgl/README.md +++ b/tests/webgl/README.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + ## Test cases for the WebGL backend Any test case with name `test_local_...` tests the C++ OpenGL backend on the diff --git a/tests/webgl/test_local_gemm.py b/tests/webgl/test_local_gemm.py index e3b9c862a5f9..7d32aee1f0e0 100644 --- a/tests/webgl/test_local_gemm.py +++ b/tests/webgl/test_local_gemm.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np diff --git a/tests/webgl/test_local_multi_stage.py b/tests/webgl/test_local_multi_stage.py index 1791241d68ee..36ae1827da58 100644 --- a/tests/webgl/test_local_multi_stage.py +++ b/tests/webgl/test_local_multi_stage.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np diff --git a/tests/webgl/test_local_save_load.py b/tests/webgl/test_local_save_load.py index bcf9f0a8d5bf..b2f30a6e632f 100644 --- a/tests/webgl/test_local_save_load.py +++ b/tests/webgl/test_local_save_load.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import tvm from tvm import rpc diff --git a/tests/webgl/test_local_topi_conv2d_nchw.py b/tests/webgl/test_local_topi_conv2d_nchw.py index 598446456b4e..c03d9dcc9007 100644 --- a/tests/webgl/test_local_topi_conv2d_nchw.py +++ b/tests/webgl/test_local_topi_conv2d_nchw.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Example code to do convolution. Copied from topi/tests/python/test_topi_conv2d_nchw.py. Should be removed once we fix OpenGL testing on Jenkins.""" diff --git a/tests/webgl/test_local_topi_dense.py b/tests/webgl/test_local_topi_dense.py index 75f6dac5d1f8..aaac53c67948 100644 --- a/tests/webgl/test_local_topi_dense.py +++ b/tests/webgl/test_local_topi_dense.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test code for dense operator Copied from topi/tests/python/test_topi_dense.py. Should be removed once we fix OpenGL testing on Jenkins. diff --git a/tests/webgl/test_local_topi_pooling.py b/tests/webgl/test_local_topi_pooling.py index 35e893b94e6e..c3163a204904 100644 --- a/tests/webgl/test_local_topi_pooling.py +++ b/tests/webgl/test_local_topi_pooling.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test code for pooling Copied from topi/tests/python/test_topi_pooling.py. Should be removed once we fix OpenGL testing on Jenkins. diff --git a/tests/webgl/test_local_topi_softmax.py b/tests/webgl/test_local_topi_softmax.py index 45c0c18098ed..ade09b73442c 100644 --- a/tests/webgl/test_local_topi_softmax.py +++ b/tests/webgl/test_local_topi_softmax.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test code for softmax Copied from topi/tests/python/test_topi_softmax.py. Should be removed once we fix OpenGL testing on Jenkins. diff --git a/tests/webgl/test_remote_save_load.py b/tests/webgl/test_remote_save_load.py index f14b2f2a2eae..13b2288e6713 100644 --- a/tests/webgl/test_remote_save_load.py +++ b/tests/webgl/test_remote_save_load.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ The following instruction is based on web/README.md. diff --git a/tests/webgl/test_static_webgl_library.py b/tests/webgl/test_static_webgl_library.py index 262416c42506..365f821845ae 100644 --- a/tests/webgl/test_static_webgl_library.py +++ b/tests/webgl/test_static_webgl_library.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Create a static WebGL library and run it in the browser.""" from __future__ import absolute_import, print_function diff --git a/topi/README.md b/topi/README.md index 180d241bb06b..4da591041e17 100644 --- a/topi/README.md +++ b/topi/README.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + # TOPI: TVM Operator Inventory TOPI is the operator collection library for TVM intended at sharing the effort of crafting diff --git a/topi/include/topi/broadcast.h b/topi/include/topi/broadcast.h index 88007ee94e85..c1675caf9e5b 100644 --- a/topi/include/topi/broadcast.h +++ b/topi/include/topi/broadcast.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief Broadcast op constructions diff --git a/topi/include/topi/contrib/cublas.h b/topi/include/topi/contrib/cublas.h index 0ec81cc405cb..c1d1b4e2c2dd 100644 --- a/topi/include/topi/contrib/cublas.h +++ b/topi/include/topi/contrib/cublas.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief External function interface to cuBLAS libraries diff --git a/topi/include/topi/contrib/rocblas.h b/topi/include/topi/contrib/rocblas.h index 5abdc4259c29..64652200a488 100644 --- a/topi/include/topi/contrib/rocblas.h +++ b/topi/include/topi/contrib/rocblas.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief External function interface to rocBLAS libraries diff --git a/topi/include/topi/cuda/dense.h b/topi/include/topi/cuda/dense.h index 77e29fc7fdbb..5cfdce000ede 100644 --- a/topi/include/topi/cuda/dense.h +++ b/topi/include/topi/cuda/dense.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file cuda/dense.h diff --git a/topi/include/topi/cuda/extern.h b/topi/include/topi/cuda/extern.h index 475ab6ba8a19..f7008dd6b05a 100644 --- a/topi/include/topi/cuda/extern.h +++ b/topi/include/topi/cuda/extern.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file cuda/extern.h diff --git a/topi/include/topi/cuda/injective.h b/topi/include/topi/cuda/injective.h index 91c6df3a2a3c..e540292fbf09 100644 --- a/topi/include/topi/cuda/injective.h +++ b/topi/include/topi/cuda/injective.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file cuda/injective.h diff --git a/topi/include/topi/cuda/normalization.h b/topi/include/topi/cuda/normalization.h index 91578c46d266..3de95aa4a2fd 100644 --- a/topi/include/topi/cuda/normalization.h +++ b/topi/include/topi/cuda/normalization.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file cuda/normalization.h diff --git a/topi/include/topi/cuda/pooling.h b/topi/include/topi/cuda/pooling.h index d1c006e3a215..fe775fcc1d45 100644 --- a/topi/include/topi/cuda/pooling.h +++ b/topi/include/topi/cuda/pooling.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file cuda/pooling.h diff --git a/topi/include/topi/cuda/reduction.h b/topi/include/topi/cuda/reduction.h index a1670873cc31..6dfa6ac7c8cf 100644 --- a/topi/include/topi/cuda/reduction.h +++ b/topi/include/topi/cuda/reduction.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file cuda/reduction.h diff --git a/topi/include/topi/cuda/softmax.h b/topi/include/topi/cuda/softmax.h index 8d22f4b4b46d..2c7c6f0518f8 100644 --- a/topi/include/topi/cuda/softmax.h +++ b/topi/include/topi/cuda/softmax.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file cuda/injective.h diff --git a/topi/include/topi/detail/array_utils.h b/topi/include/topi/detail/array_utils.h index 3e77650cda6f..7c5ceccc160a 100644 --- a/topi/include/topi/detail/array_utils.h +++ b/topi/include/topi/detail/array_utils.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file array_utils.h diff --git a/topi/include/topi/detail/broadcast.h b/topi/include/topi/detail/broadcast.h index 19ada244f28e..0e05ef38b355 100644 --- a/topi/include/topi/detail/broadcast.h +++ b/topi/include/topi/detail/broadcast.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief Detail broadcast. diff --git a/topi/include/topi/detail/constant_utils.h b/topi/include/topi/detail/constant_utils.h index 7ff137418c48..b04a03fcf544 100644 --- a/topi/include/topi/detail/constant_utils.h +++ b/topi/include/topi/detail/constant_utils.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file constant_utils.h diff --git a/topi/include/topi/detail/extern.h b/topi/include/topi/detail/extern.h index 44170b75b9a0..ac00e52899fa 100644 --- a/topi/include/topi/detail/extern.h +++ b/topi/include/topi/detail/extern.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file detail/extern.h diff --git a/topi/include/topi/detail/fuse.h b/topi/include/topi/detail/fuse.h index 85ca0f9efacb..23df2b7f829b 100644 --- a/topi/include/topi/detail/fuse.h +++ b/topi/include/topi/detail/fuse.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file fuse.h diff --git a/topi/include/topi/detail/pad_utils.h b/topi/include/topi/detail/pad_utils.h index f982f35844fa..d30dd94b5e2e 100644 --- a/topi/include/topi/detail/pad_utils.h +++ b/topi/include/topi/detail/pad_utils.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file pad_utils.h diff --git a/topi/include/topi/detail/ravel_unravel.h b/topi/include/topi/detail/ravel_unravel.h index d5a45270c35f..b51ff9365230 100644 --- a/topi/include/topi/detail/ravel_unravel.h +++ b/topi/include/topi/detail/ravel_unravel.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file ravel_unravel.h diff --git a/topi/include/topi/elemwise.h b/topi/include/topi/elemwise.h index e5d8778041b1..9a32e34eda73 100644 --- a/topi/include/topi/elemwise.h +++ b/topi/include/topi/elemwise.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file elemwise.h diff --git a/topi/include/topi/generic/default.h b/topi/include/topi/generic/default.h index 5e0615742a14..091e8a9b8325 100644 --- a/topi/include/topi/generic/default.h +++ b/topi/include/topi/generic/default.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file generic/default.h diff --git a/topi/include/topi/generic/extern.h b/topi/include/topi/generic/extern.h index e14054f29b68..0a84327e26ad 100644 --- a/topi/include/topi/generic/extern.h +++ b/topi/include/topi/generic/extern.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file generic/extern.h diff --git a/topi/include/topi/generic/injective.h b/topi/include/topi/generic/injective.h index c1d63eac6af7..5c42b0518920 100644 --- a/topi/include/topi/generic/injective.h +++ b/topi/include/topi/generic/injective.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file generic/injective.h diff --git a/topi/include/topi/image/resize.h b/topi/include/topi/image/resize.h index 9981980539be..fb577a8f06ef 100644 --- a/topi/include/topi/image/resize.h +++ b/topi/include/topi/image/resize.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file topi/image/resize.h diff --git a/topi/include/topi/nn.h b/topi/include/topi/nn.h index 653c0a5f70ce..10f5d4992f6a 100644 --- a/topi/include/topi/nn.h +++ b/topi/include/topi/nn.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief NN op constructions diff --git a/topi/include/topi/nn/batch_matmul.h b/topi/include/topi/nn/batch_matmul.h index 968e1b0c697c..61525fc2a9fe 100644 --- a/topi/include/topi/nn/batch_matmul.h +++ b/topi/include/topi/nn/batch_matmul.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2019 by Contributors * \brief Batch matmul op constructions diff --git a/topi/include/topi/nn/bnn.h b/topi/include/topi/nn/bnn.h index f7b1b860d461..f6d331be73e4 100644 --- a/topi/include/topi/nn/bnn.h +++ b/topi/include/topi/nn/bnn.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief Binary op constructions diff --git a/topi/include/topi/nn/dense.h b/topi/include/topi/nn/dense.h index 695b8e187856..755aad6b784d 100644 --- a/topi/include/topi/nn/dense.h +++ b/topi/include/topi/nn/dense.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief Dense op constructions diff --git a/topi/include/topi/nn/dilate.h b/topi/include/topi/nn/dilate.h index a37efbb713f0..4c4dbd7b50ff 100644 --- a/topi/include/topi/nn/dilate.h +++ b/topi/include/topi/nn/dilate.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief Dilate op constructions diff --git a/topi/include/topi/nn/flatten.h b/topi/include/topi/nn/flatten.h index d9577be36e5d..edba7eec37e1 100644 --- a/topi/include/topi/nn/flatten.h +++ b/topi/include/topi/nn/flatten.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief Softmax op constructions diff --git a/topi/include/topi/nn/l2_normalize.h b/topi/include/topi/nn/l2_normalize.h index 4f9bdb61ab70..1078370baada 100644 --- a/topi/include/topi/nn/l2_normalize.h +++ b/topi/include/topi/nn/l2_normalize.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief l2 normalization op constructions diff --git a/topi/include/topi/nn/local_response_norm.h b/topi/include/topi/nn/local_response_norm.h index 96e1fdcbda48..a0d3d1ed8391 100644 --- a/topi/include/topi/nn/local_response_norm.h +++ b/topi/include/topi/nn/local_response_norm.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief local response normalization op constructions diff --git a/topi/include/topi/nn/mapping.h b/topi/include/topi/nn/mapping.h index 60cd6d6310a7..15b13b18d5aa 100644 --- a/topi/include/topi/nn/mapping.h +++ b/topi/include/topi/nn/mapping.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief Mapping op constructions diff --git a/topi/include/topi/nn/pooling.h b/topi/include/topi/nn/pooling.h index 795d04a31a46..86d5aff9ec35 100644 --- a/topi/include/topi/nn/pooling.h +++ b/topi/include/topi/nn/pooling.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief Pooling op constructions diff --git a/topi/include/topi/nn/softmax.h b/topi/include/topi/nn/softmax.h index 8ee747ccd07c..9f0b7a2837d9 100644 --- a/topi/include/topi/nn/softmax.h +++ b/topi/include/topi/nn/softmax.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief Softmax op constructions diff --git a/topi/include/topi/nn/upsampling.h b/topi/include/topi/nn/upsampling.h index e0fe2991c649..eb75d5dd8d92 100644 --- a/topi/include/topi/nn/upsampling.h +++ b/topi/include/topi/nn/upsampling.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file topi/nn/upsampling.h diff --git a/topi/include/topi/reduction.h b/topi/include/topi/reduction.h index 60027af80d4a..b24c4577c4e5 100644 --- a/topi/include/topi/reduction.h +++ b/topi/include/topi/reduction.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file topi/reduction.h diff --git a/topi/include/topi/rocm/dense.h b/topi/include/topi/rocm/dense.h index 6f171f6780fc..67e60492a12d 100644 --- a/topi/include/topi/rocm/dense.h +++ b/topi/include/topi/rocm/dense.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file rocm/dense.h diff --git a/topi/include/topi/rocm/normalization.h b/topi/include/topi/rocm/normalization.h index b12e64aba963..e1c989914b17 100644 --- a/topi/include/topi/rocm/normalization.h +++ b/topi/include/topi/rocm/normalization.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file rocm/normalization.h diff --git a/topi/include/topi/tags.h b/topi/include/topi/tags.h index 8c92644d96d3..59fbf6bc21f1 100644 --- a/topi/include/topi/tags.h +++ b/topi/include/topi/tags.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief Tag definitions diff --git a/topi/include/topi/transform.h b/topi/include/topi/transform.h index 464bd6facad5..abb8455d45b5 100644 --- a/topi/include/topi/transform.h +++ b/topi/include/topi/transform.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file topi/transform.h @@ -604,22 +623,29 @@ inline Array split_sections(const Tensor& x, */ inline Tensor take(const Tensor& a, const Tensor& indices, + std::string mode = "clip", std::string name = "tensor", std::string tag = kInjective) { Array a_shape = a->shape; - Array out_shape; - for (size_t j = 0; j < indices->shape.size(); ++j) { - out_shape.push_back(indices->shape[j]); + Array out_shape = indices->shape; + Expr a_size = 1; + for (size_t i = 0; i < a_shape.size(); ++i) { + a_size = a_size * a_shape[i]; } - return compute( + if (mode == "clip") { + return compute( out_shape, [&](const Array& out_index) { - Array indices_position; - for (size_t j = 0; j < indices->shape.size(); ++j) { - indices_position.push_back(out_index[j]); - } - return a(UnravelIndex(indices(indices_position), a_shape)); + auto idx = tvm::min(tvm::max(0, indices(out_index)), a_size - 1); + return a(UnravelIndex(idx, a_shape)); }, name, tag); + } else { // mode == "wrap" + return compute( + out_shape, [&](const Array& out_index) { + auto idx = (indices(out_index) % a_size + a_size) % a_size; + return a(UnravelIndex(idx, a_shape)); + }, name, tag); + } } /*! @@ -637,12 +663,15 @@ inline Tensor take(const Tensor& a, inline Tensor take(const Tensor& a, const Tensor& indices, int axis, + std::string mode = "clip", std::string name = "tensor", std::string tag = kInjective) { if (axis < 0) { axis += static_cast(a->shape.size()); } + CHECK_GE(axis, 0) << "axis out of bounds"; CHECK_LT(axis, a->shape.size()) << "axis out of bounds"; + auto axis_dim = a->shape[axis]; int indices_len = static_cast(indices->shape.size()); Array out_shape; @@ -655,7 +684,27 @@ inline Tensor take(const Tensor& a, out_shape.push_back(a->shape[i]); } } - return compute( + if (mode == "clip") { + return compute( + out_shape, [&](const Array& out_index) { + Array indices_position; + for (size_t j = axis; j < static_cast(axis+indices_len); ++j) { + indices_position.push_back(out_index[j]); + } + Array real_indices; + for (size_t j = 0; j < static_cast(axis); ++j) { + real_indices.push_back(out_index[j]); + } + auto idx = tvm::min(tvm::max(0, indices(indices_position)), + axis_dim - 1); + real_indices.push_back(idx); + for (size_t j = axis + indices_len; j < out_index.size(); ++j) { + real_indices.push_back(out_index[j]); + } + return a(real_indices); + }, name, tag); + } else { // mode == "wrap" + return compute( out_shape, [&](const Array& out_index) { Array indices_position; for (size_t j = axis; j < static_cast(axis+indices_len); ++j) { @@ -665,12 +714,14 @@ inline Tensor take(const Tensor& a, for (size_t j = 0; j < static_cast(axis); ++j) { real_indices.push_back(out_index[j]); } - real_indices.push_back(indices(indices_position)); + auto idx = (indices(indices_position) % axis_dim + axis_dim) % axis_dim; + real_indices.push_back(idx); for (size_t j = axis + indices_len; j < out_index.size(); ++j) { real_indices.push_back(out_index[j]); } return a(real_indices); }, name, tag); + } } /*! diff --git a/topi/include/topi/vision/reorg.h b/topi/include/topi/vision/reorg.h index dd73b940682d..c1f410fb9bcc 100644 --- a/topi/include/topi/vision/reorg.h +++ b/topi/include/topi/vision/reorg.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \brief Reorg op constructions diff --git a/topi/include/topi/x86/bnn.h b/topi/include/topi/x86/bnn.h index f379ada8a516..e21a322f5e63 100644 --- a/topi/include/topi/x86/bnn.h +++ b/topi/include/topi/x86/bnn.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file x86/bnn.h diff --git a/topi/include/topi/x86/default.h b/topi/include/topi/x86/default.h index 5d71855a8c94..6f47b3937da4 100644 --- a/topi/include/topi/x86/default.h +++ b/topi/include/topi/x86/default.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file x86/default.h diff --git a/topi/include/topi/x86/injective.h b/topi/include/topi/x86/injective.h index 9e5a603af908..e80c941788f8 100644 --- a/topi/include/topi/x86/injective.h +++ b/topi/include/topi/x86/injective.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file x86/injective.h diff --git a/topi/python/setup.py b/topi/python/setup.py index dadb79453857..bff0576705dc 100644 --- a/topi/python/setup.py +++ b/topi/python/setup.py @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # pylint: disable=invalid-name, exec-used """Setup TOPI package.""" from __future__ import absolute_import diff --git a/topi/python/topi/arm_cpu/bitserial_conv2d.py b/topi/python/topi/arm_cpu/bitserial_conv2d.py index ffef3ce81b98..1a4087168fc5 100644 --- a/topi/python/topi/arm_cpu/bitserial_conv2d.py +++ b/topi/python/topi/arm_cpu/bitserial_conv2d.py @@ -1,100 +1,60 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name,unused-variable,invalid-name -"""Bitserial conv2d schedule on raspberry pi""" +"""Bitserial conv2d schedule on arm cpu""" from __future__ import absolute_import as _abs -from collections import namedtuple import tvm +from tvm import autotvm from .. import tag from ..nn.pad import pad -from ..nn.bitserial_conv2d import bitserial_conv2d, _get_schedule, _get_workload, bitpack -from ..nn.bitserial_conv2d import SpatialPackNCHW, _WORKLOADS, spatial_pack_nchw +from ..nn.bitserial_conv2d import bitpack, bitserial_conv2d_nhwc from ..nn.util import get_pad_tuple -from ..util import get_const_int +from ..util import get_const_int, get_const_tuple from .. import generic -RaspSpatialPack = namedtuple('SpatialPack', - ['vh', 'vw', 'vc', 'ba', 'bc', 'split_ci', 'kfactor']) - -_QUANTIZED_SCHEDULES_NHWC = [ - RaspSpatialPack(2, 2, 8, 1, 1, False, 8), - RaspSpatialPack(1, 4, 8, 4, 1, False, 8), - RaspSpatialPack(1, 4, 8, 1, 16, False, 8), - RaspSpatialPack(1, 4, 8, 4, 8, False, 8), - RaspSpatialPack(1, 7, 8, 3, 8, False, 16), - RaspSpatialPack(1, 2, 8, 1, 8, False, 16), - RaspSpatialPack(2, 1, 8, 1, 4, False, 16), - RaspSpatialPack(1, 7, 8, 1, 1, True, 16), - RaspSpatialPack(1, 1, 8, 1, 16, True, 16), - RaspSpatialPack(1, 1, 8, 1, 8, True, 16), - RaspSpatialPack(1, 1, 8, 1, 16, True, 16), -] - -_QUANTIZED_SCHEDULES_NCHW = [ - # resnet - SpatialPackNCHW(2, 2, 8, 1, 1), - SpatialPackNCHW(1, 4, 8, 4, 1), - SpatialPackNCHW(1, 4, 8, 1, 16), - SpatialPackNCHW(1, 4, 8, 4, 8), - SpatialPackNCHW(1, 7, 8, 3, 8), - SpatialPackNCHW(1, 2, 8, 1, 8), - SpatialPackNCHW(2, 1, 8, 1, 4), - SpatialPackNCHW(1, 7, 8, 1, 1), - SpatialPackNCHW(1, 1, 8, 1, 16), - SpatialPackNCHW(1, 1, 8, 1, 8), - SpatialPackNCHW(1, 1, 8, 1, 16), -] - -@_get_schedule.register("arm_cpu") -def _get_schedule_bitserial_conv2d(wkl, layout): - if wkl not in _WORKLOADS: - raise ValueError("no schedule for such workload: {}".format(wkl)) - idx = _WORKLOADS.index(wkl) - if layout == "NCHW": - sch = _QUANTIZED_SCHEDULES_NCHW[idx] - elif layout == "NHWC": - sch = _QUANTIZED_SCHEDULES_NHWC[idx] - return sch - - -@bitserial_conv2d.register("arm_cpu") -def _declaration_bitserial_conv2d(data, kernel, stride, padding, activation_bits, weight_bits, - layout='NCHW', pack_dtype=None, out_dtype=None, dorefa=False): - if out_dtype is None: - out_dtype = data.dtype - assert data.shape[0].value == 1, "only support batch size=1 convolution on rasp" - assert layout in ("NCHW", "NHWC"), "only support layouts NCHW and NHWC" - if dorefa: - assert layout == "NCHW", "Cannot support dorea with NHWC layout yet" - wkl = _get_workload(data, kernel, stride, padding, out_dtype, layout) - sch = _get_schedule(wkl, layout) - if layout == "NCHW": - return spatial_pack_nchw(data, kernel, stride, padding, activation_bits, weight_bits, - pack_dtype=pack_dtype, out_dtype=out_dtype, dorefa=dorefa) - return _spatial_pack_nhwc(data, kernel, stride, padding, activation_bits, - weight_bits, out_dtype) - -def _kernel_vec_spatial_pack_nhwc(kernel, kernel_bits, VC): - kernel_q = bitpack(kernel, kernel_bits, pack_axis=2, bit_axis=2, pack_type='uint8') +def _kernel_vec_spatial_pack_nhwc(kernel, kernel_bits, VC, use_bitpack=True): + if use_bitpack: + kernel_q = bitpack(kernel, kernel_bits, pack_axis=2, bit_axis=2, pack_type='uint8') + else: + kernel_q = kernel KH, KW, KB, CI, CO = kernel_q.shape kvshape = (CO//VC, KH, KW, KB, VC, CI) return tvm.compute(kvshape, lambda co, dh, dw, b, vc, ci: \ kernel_q[dh][dw][b][ci][co*VC+vc], name='kernel_vec') -def _spatial_pack_nhwc(data, kernel, stride, padding, activation_bits, weight_bits, out_dtype): +@autotvm.register_topi_compute(bitserial_conv2d_nhwc, 'arm_cpu', 'direct') +def spatial_pack_nhwc(cfg, data, kernel, stride, padding, activation_bits, weight_bits, + pack_dtype, out_dtype, unipolar): """ Compute convolution with pack on spatial axes. """ assert data.shape[0].value == 1, "spatial pack convolution only support batch size=1" - wkl = _get_workload(data, kernel, stride, padding, out_dtype, "NHWC") - sch = _get_schedule(wkl, "NHWC") - VH = sch.vh - VW = sch.vw - VC = sch.vc + assert pack_dtype == 'uint8', "only support packing into uint8 bits" + assert out_dtype == 'int16', "only support output type of int16" - data_q = bitpack(data, activation_bits, pack_axis=3, bit_axis=3, pack_type='uint8') - kernel_vec = _kernel_vec_spatial_pack_nhwc(kernel, weight_bits, VC) - N, H, W, IB, CI = data_q.shape - OCO, KH, KW, KB, VC, _ = kernel_vec.shape + N, H, W, CI = get_const_tuple(data.shape) + if len(kernel.shape) == 4: + KH, KW, _, CO = get_const_tuple(kernel.shape) + CI_packed = CI // 8 + else: + KH, KW, KB, CI_packed, CO = get_const_tuple(kernel.shape) - CO = OCO * VC - HPAD, WPAD, _, _ = get_pad_tuple(padding, kernel) + if isinstance(padding, int) or (isinstance(padding, (tuple, list)) and len(padding) == 2): + TPAD, LPAD, DPAD, RPAD = get_pad_tuple(padding, kernel) + else: + TPAD, LPAD, DPAD, RPAD = padding if isinstance(stride, (tuple, list)): HSTR, WSTR = stride @@ -102,75 +62,151 @@ def _spatial_pack_nhwc(data, kernel, stride, padding, activation_bits, weight_bi HSTR, WSTR = stride, stride HCAT, WCAT = KH-1, KW-1 - PAD_H = H + 2*HPAD - PAD_W = W + 2*WPAD - OH = (H + 2*HPAD - KH) // HSTR + 1 - OW = (W + 2*WPAD - KW) // WSTR + 1 + PAD_H = H + (TPAD + DPAD) + PAD_W = W + (LPAD + RPAD) + OH = (PAD_H - KH) // HSTR + 1 + OW = (PAD_W - KW) // WSTR + 1 + oshape = (1, OH, OW, CO) + + # Pad input channels of weights and data when it is not a multiple of 8 + if CI_packed % 8 != 0: + CI_PAD = CI_packed % 8 + CI_packed += CI_PAD + else: + CI_PAD = 0 + + # ==================== define configuration space ==================== + n, oh, ow, co = cfg.axis(N), cfg.axis(OH), cfg.axis(OW), cfg.axis(CO) + ci, kh, kw = cfg.reduce_axis(CI_packed), cfg.reduce_axis(KH), cfg.reduce_axis(KW) + ib, kb = cfg.reduce_axis(activation_bits), cfg.reduce_axis(weight_bits) + + co, vc = cfg.define_split('tile_co', co, policy='all', num_outputs=2, + filter=lambda x: x.size[-1] == 8) + oh, vh = cfg.define_split('tile_oh', oh, policy='all', num_outputs=2, + filter=lambda x: x.size[-1] >= 2) + ow, vw = cfg.define_split('tile_ow', ow, policy='all', num_outputs=2, + filter=lambda x: x.size[-1] >= 2) + ci_o, ci_i = cfg.define_split("tile_ci", ci, num_outputs=2, + filter=lambda x: x.size[-1] == 8 or x.size[-1] == 16) + re_axes = cfg.define_reorder("reorder_0", + [n, oh, ow, co, vh, vw, kh, kw, ci_o, kb, ib, vc, ci_i], + policy='candidate', candidate=[ + [n, oh, ow, co, vh, vw, kh, kw, ci_o, kb, ib, vc, ci_i], + [n, oh, ow, co, vh, vw, kw, kh, ci_o, kb, ib, vc, ci_i],]) + cfg.add_flop(2 * N * OH * OW * CO * CI * 8 * KH * KW) # these are actually binary ops + # ==================== + + VC = cfg["tile_co"].size[-1] + VH = cfg["tile_oh"].size[-1] + VW = cfg["tile_ow"].size[-1] + + data_q = bitpack(data, activation_bits, pack_axis=3, bit_axis=3, pack_type='uint8') + + kernel_vec = _kernel_vec_spatial_pack_nhwc(kernel, weight_bits, VC, len(kernel.shape) == 4) + if kernel_vec.shape[-1] % 8 != 0 and CI_PAD != 0: + kernel_vec = pad(kernel_vec, [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, CI_PAD]) + + N, H, W, IB, CI = data_q.shape + OCO, KH, KW, KB, VC, CI = kernel_vec.shape + dvshape = (N, PAD_H//(VH*HSTR), PAD_W//(VW*WSTR), VH*HSTR+HCAT, VW*WSTR+WCAT, IB, CI) ovshape = (1, OH // VH, OW // VW, CO // VC, VH, VW, VC) - oshape = (1, OH, OW, CO) - if (HPAD != 0 and WPAD != 0): - data_pad = pad(data_q, (0, HPAD, WPAD, 0, 0), name="data_pad") + if (TPAD != 0 and RPAD != 0): + data_pad = pad(data_q, (0, TPAD, LPAD, 0, 0), (0, DPAD, RPAD, 0, CI_PAD), name="data_pad") + elif CI_PAD != 0: + data_pad = pad(data_q, (0, 0, 0, 0, 0), (0, 0, 0, 0, CI_PAD), name="data_pad") else: data_pad = data_q data_vec = tvm.compute(dvshape, lambda n, h, w, vh, vw, b, ci: \ data_pad[n][h*VH*HSTR+vh][w*VW*WSTR+vw][b][ci], name='data_vec') - ci = tvm.reduce_axis((0, CI), name='ci') dh = tvm.reduce_axis((0, KH), name='dh') dw = tvm.reduce_axis((0, KW), name='dw') ib = tvm.reduce_axis((0, IB), name='ib') kb = tvm.reduce_axis((0, KB), name='kb') - def _conv(n, h, w, co, vh, vw, vc): + def _bipolar_conv(n, h, w, co, vh, vw, vc): return tvm.sum((tvm.popcount( kernel_vec[co, dh, dw, kb, vc, ci].astype('uint16') & data_vec[n, h, w, vh*HSTR+dh, vw*WSTR+dw, ib, ci].astype('uint16')) << (kb + ib).astype('uint16')), axis=[dh, dw, kb, ib, ci]) + def _unipolar_conv(n, h, w, co, vh, vw, vc): + return tvm.sum( + ((tvm.popcount(kernel_vec[co, dh, dw, kb, vc, ci].astype('int16') & + data_vec[n, h, w, vh*HSTR+dh, vw*WSTR+dw, ib, ci].astype('int16')) - + tvm.popcount(~kernel_vec[co, dh, dw, kb, vc, ci].astype('int16') & + data_vec[n, h, w, vh*HSTR+dh, vw*WSTR+dw, ib, ci]).astype('int16')) + << (kb + ib).astype('int16')), axis=[dh, dw, kb, ib, ci]) + if unipolar: + conv_vec = tvm.compute(ovshape, _unipolar_conv, name='conv_vec', tag='unipolar') + else: + conv_vec = tvm.compute(ovshape, _bipolar_conv, name='conv_vec', tag='bipolar') - conv = tvm.compute(ovshape, _conv, name='conv') + conv = tvm.compute(oshape, lambda n, h, w, co: + conv_vec[n][h//VH][w//VW][co//VC][h%VH][w%VW][co%VC].astype(out_dtype), + name='conv', tag='spatial_bitserial_conv_nhwc') - return tvm.compute(oshape, lambda n, h, w, co: - conv[n][h//VH][w//VW][co//VC][h%VH][w%VW][co%VC].astype(out_dtype), - name='output_vec', tag='spatial_bitserial_conv_nhwc') + return conv -def _intrin_popcount(m, k_i, w_b, x_b): - dtype = 'uint8' - w = tvm.placeholder((w_b, m, k_i), dtype=dtype, name='w') - x = tvm.placeholder((x_b, k_i,), dtype=dtype, name='x') +def _intrin_popcount(m, k_i, w_b, x_b, unipolar): + pack_dtype = 'uint8' + w = tvm.placeholder((w_b, m, k_i), dtype=pack_dtype, name='w') + x = tvm.placeholder((x_b, k_i,), dtype=pack_dtype, name='x') k = tvm.reduce_axis((0, k_i), name='k') bw = tvm.reduce_axis((0, w_b), name='bw') bx = tvm.reduce_axis((0, x_b), name='bx') - z = tvm.compute((m,), lambda i: - tvm.sum(tvm.popcount(w[bw, i, k].astype('uint16') & - x[bx, k].astype('uint16')) - << (bw+bx).astype('uint16'), axis=[bw, bx, k]), name='z') - + if unipolar: + dtype = 'int16' + z = tvm.compute((m,), lambda i: + tvm.sum((tvm.popcount(w[bw, i, k].astype(dtype) & x[bx, k].astype(dtype)) - + tvm.popcount(~w[bw, i, k].astype(dtype) & x[bx, k].astype(dtype))) + << (bw+bx).astype(dtype), axis=[bw, bx, k]), name='z') + else: + dtype = 'uint16' + z = tvm.compute((m,), lambda i: + tvm.sum(tvm.popcount(w[bw, i, k].astype(dtype) & x[bx, k].astype(dtype)) + << (bw+bx).astype(dtype), axis=[bw, bx, k]), name='z') Wb = tvm.decl_buffer(w.shape, w.dtype, name="W", offset_factor=k_i, - strides=[tvm.var('ldw'), tvm.var('ldw'), 1]) + strides=[tvm.var('ldw'), tvm.var('ldw'), 1]) # stride can be inferred Xb = tvm.decl_buffer(x.shape, x.dtype, name="X", offset_factor=k_i, strides=[tvm.var('ldw'), 1]) + Zb = tvm.decl_buffer(z.shape, z.dtype, + name="Z", + offset_factor=1, + strides=[1]) def _intrin_func(ins, outs): ww, xx = ins zz = outs[0] - vpadd = "llvm.arm.neon.vpadd.v8u8" - vpadalu = "llvm.arm.neon.vpadalu.v16u8.v8u16" + args_1 = tvm.const(1, 'uint32') args_2 = tvm.const(2, 'uint32') + if unipolar: + vpadd = "llvm.arm.neon.vpadd.v8i8" + vpadalu = "llvm.arm.neon.vpadals.v16i8.v8i16" + full_dtype = 'int8x16' + half_dtype = 'int8x8' + return_dtype = 'int16x8' + else: + vpadd = "llvm.arm.neon.vpadd.v8u8" + vpadalu = "llvm.arm.neon.vpadalu.v16u8.v8u16" + full_dtype = 'uint8x16' + half_dtype = 'uint8x8' + return_dtype = 'uint16x8' + def _instr(index): irb = tvm.ir_builder.create() - if index == 1: - irb.emit(zz.vstore(0, tvm.const(0, 'uint16x8'))) + if index == 1: # reduce reset + irb.emit(zz.vstore(0, tvm.const(0, return_dtype))) return irb.get() - + # body and reduce update cnts8 = [None] * 8 cnts4 = [None] * 4 cnts2 = [None] * 2 @@ -178,154 +214,108 @@ def _instr(index): for bx in range(x_b): if k_i == 16: for i in range(m): - ands = ww.vload([bw, i, 0], 'uint8x16') & xx.vload([bx, 0], 'uint8x16') - cnts = tvm.popcount(ands) - upper_half = tvm.call_pure_intrin('uint8x8', 'vectorhigh', cnts) - lower_half = tvm.call_pure_intrin('uint8x8', 'vectorlow', cnts) + w_ = ww.vload([bw, i, 0], 'uint8x16').astype(full_dtype) + x_ = xx.vload([bx, 0], 'uint8x16').astype(full_dtype) + if unipolar: + cnts = tvm.popcount(w_ & x_) - tvm.popcount(~w_ & x_) + else: + cnts = tvm.popcount(w_ & x_) + upper_half = tvm.call_pure_intrin(half_dtype, 'vectorhigh', cnts) + lower_half = tvm.call_pure_intrin(half_dtype, 'vectorlow', cnts) cnts8[i] = upper_half + lower_half for i in range(m//2): - cnts4[i] = tvm.call_llvm_intrin('uint8x8', vpadd, + cnts4[i] = tvm.call_llvm_intrin(half_dtype, vpadd, args_1, cnts8[i*2], cnts8[i*2+1]) for i in range(m//4): - cnts2[i] = tvm.call_llvm_intrin('uint8x8', vpadd, + cnts2[i] = tvm.call_llvm_intrin(half_dtype, vpadd, args_1, cnts4[i*2], cnts4[i*2+1]) - cnts = tvm.call_pure_intrin('uint8x16', 'vectorcombine', cnts2[0], cnts2[1]) - shifted_cnts = cnts << tvm.const(bw+bx, dtype) - out = tvm.call_llvm_intrin('uint16x8', vpadalu, - args_2, zz.vload(0, 'uint16x8'), shifted_cnts) + cnts = tvm.call_pure_intrin(full_dtype, 'vectorcombine', cnts2[0], cnts2[1]) + shifted_cnts = cnts << tvm.const(bw+bx, pack_dtype) + out = tvm.call_llvm_intrin(return_dtype, vpadalu, + args_2, zz.vload(0, return_dtype), shifted_cnts) else: # ki == 8 for i in range(m): - ands = ww.vload([bw, i, 0], 'uint8x8') & xx.vload([bx, 0], 'uint8x8') - cnts8[i] = tvm.popcount(ands) + w_ = ww.vload([bw, i, 0], 'uint8x8').astype(half_dtype) + x_ = xx.vload([bx, 0], 'uint8x8').astype(half_dtype) + if unipolar: + cnts8[i] = tvm.popcount(w_ & x_) - tvm.popcount(~w_ & x_) + else: + cnts8[i] = tvm.popcount(w_ & x_) for i in range(m//2): - cnts4[i] = tvm.call_llvm_intrin('uint8x8', vpadd, + cnts4[i] = tvm.call_llvm_intrin(half_dtype, vpadd, args_1, cnts8[i*2], cnts8[i*2+1]) for i in range(m//4): - cnts2[i] = tvm.call_llvm_intrin('uint8x8', vpadd, + cnts2[i] = tvm.call_llvm_intrin(half_dtype, vpadd, args_1, cnts4[i*2], cnts4[i*2+1]) - cnts = tvm.call_pure_intrin('uint8x16', 'vectorcombine', cnts2[0], cnts2[1]) - shifted_cnts = cnts << tvm.const(bw+bx, dtype) - out = tvm.call_llvm_intrin('uint16x8', vpadalu, - args_2, zz.vload(0, 'uint16x8'), shifted_cnts) + cnts = tvm.call_pure_intrin(full_dtype, 'vectorcombine', cnts2[0], cnts2[1]) + shifted_cnts = cnts << tvm.const(bw+bx, pack_dtype) + out = tvm.call_llvm_intrin(return_dtype, vpadalu, + args_2, zz.vload(0, return_dtype), shifted_cnts) irb.emit(zz.vstore(0, out)) return irb.get() # body, reset, update return _instr(0), _instr(1), _instr(2) with tvm.build_config(offset_factor=1, partition_const_loop=True): - return tvm.decl_tensor_intrin(z.op, _intrin_func, binds={w: Wb, x:Xb}) + return tvm.decl_tensor_intrin(z.op, _intrin_func, binds={w: Wb, x:Xb, z:Zb}) # ARM specific schedule that using custom microkernel -def _schedule_spatial_conv2d_nhwc(s, data, data_q, data_pad, data_vec, - kernel, kernel_q, kernel_vec, - conv_out, output, last): - # no stride and padding info here - _, H, W, IB, CI = data_q.shape - KH, KW, KB, _, CO = kernel_q.shape +def _schedule_spatial_conv2d_nhwc(cfg, s, data_pad, data_vec, kernel_vec, + conv_out, output, last, unipolar): + _, _, _, _, _, IB, CI = data_vec.shape + _, KH, KW, KB, _, _ = kernel_vec.shape KB = get_const_int(KB) IB = get_const_int(IB) - if data_pad is None: - padding = (0, 0) - _, in_h, in_w, _, _ = data_q.shape - kern_h, kern_w, _, _ = kernel.shape - _, out_h, out_w, _ = output.shape - hstride = (in_h - kern_h) // (out_h - 1) - wstride = (in_w - kern_w) // (out_w - 1) - stride = get_const_int(hstride), get_const_int(wstride) - else: - _, in_h, in_w, _, _ = data_q.shape - _, pad_h, pad_w, _, _ = data_pad.shape - hpad = (pad_h - in_h) // 2 - wpad = (pad_w - in_w) // 2 - padding = get_const_int(hpad), get_const_int(wpad) - - _, in_h, in_w, _, _ = data_pad.shape - kern_h, kern_w, _, _ = kernel.shape - _, out_h, out_w, _ = output.shape - hstride = (in_h - kern_h) // (out_h - 1) - wstride = (in_w - kern_w) // (out_w - 1) - stride = get_const_int(hstride), get_const_int(wstride) - - wkl = _get_workload(data, kernel, stride, padding, output.dtype, "NHWC") - sch = _get_schedule(wkl, "NHWC") - - VH = sch.vh - VW = sch.vw - VC = sch.vc - ba = sch.ba - bc = sch.bc - - ##### Schedule data packing + VC = cfg["tile_co"].size[-1] + VH = cfg["tile_oh"].size[-1] + VW = cfg["tile_ow"].size[-1] + + ##### Schedule data padding and packing if data_pad is not None: s[data_pad].compute_inline() _, h, _, _, _, _, _ = s[data_vec].op.axis - if ba == 1: - oaxis = h - paxis = h - else: - oh, ih = s[data_vec].split(h, ba) - oaxis = oh - paxis = ih - - s[data_vec].parallel(paxis) - s[data_vec].pragma(oaxis, "parallel_launch_point") - s[data_vec].pragma(paxis, "parallel_stride_pattern") - s[data_vec].pragma(oaxis, "parallel_barrier_when_finish") + cfg.define_split("tile_ah", cfg.axis(h), policy="all", num_outputs=2, max_factor=32) + oh, ih = cfg["tile_ah"].apply(s, data_vec, h) + s[data_vec].parallel(oh) - ##### Schedule kernel packing + #### Schedule kernel packing co, _, _, _, _, _ = s[kernel_vec].op.axis - if bc == 1: - oaxis = co - paxis = co - else: - oco, ico = s[kernel_vec].split(co, bc) - oaxis = oco - paxis = ico - - s[kernel_vec].parallel(paxis) - s[kernel_vec].pragma(oaxis, "parallel_launch_point") - s[kernel_vec].pragma(paxis, "parallel_stride_pattern") - s[kernel_vec].pragma(oaxis, "parallel_barrier_when_finish") + cfg.define_split("tile_bco", cfg.axis(co), policy="all", num_outputs=2, max_factor=32) + oco, ico = cfg["tile_bco"].apply(s, kernel_vec, co) + s[kernel_vec].parallel(oco) ##### Schedule Convolution n, oh, ow, co, vh, vw, vc = s[conv_out].op.axis - dh, dw, kb, ib, ci = s[conv_out].op.reduce_axis + kh, kw, kb, ib, ci = s[conv_out].op.reduce_axis - kfactor = sch.kfactor - if sch.split_ci: - oci, ici = s[conv_out].split(ci, kfactor) - s[conv_out].reorder(n, oh, ow, co, vh, vw, dh, dw, oci, kb, ib, vc, ici) - else: - s[conv_out].reorder(n, oh, ow, co, vh, vw, dh, dw, kb, ib, vc, ci) + ci_o, ci_i = cfg['tile_ci'].apply(s, conv_out, ci) + re_axes = cfg["reorder_0"].apply(s, conv_out, + [n, oh, ow, co, vh, vw, kh, kw, ci_o, kb, ib, vc, ci_i]) - pc = _intrin_popcount(8, kfactor, KB, IB) - s[conv_out].tensorize(kb, pc) + # Use microkernel + kfactor = cfg['tile_ci'].size[1] + if kfactor % 8 == 0: + pc = _intrin_popcount(VC, kfactor, KB, IB, unipolar) + s[conv_out].tensorize(kb, pc) n, h, w, co = s[last].op.axis - co, vc = s[last].split(co, VC) - oh, ow, vh, vw = s[last].tile(h, w, VH, VW) - s[last].reorder(n, oh, ow, co, vc, vh, vw) - s[last].vectorize(vw) + co, vc = cfg['tile_co'].apply(s, last, co) + oh, vh = cfg['tile_oh'].apply(s, last, h) + ow, vw = cfg['tile_ow'].apply(s, last, w) + s[last].reorder(n, oh, ow, co, vh, vw, vc) + s[last].vectorize(vc) if last != output: s[last].compute_inline() - s[conv_out].compute_at(s[last], ow) - if co == 1: - oaxis = oh - paxis = oh - else: - oho, iho = s[last].split(oh, bc) - oaxis = oho - paxis = iho - - s[last].parallel(paxis) + s[conv_out].compute_at(s[last], co) + s[last].parallel(oh) s = s.normalize() return s -@generic.schedule_bitserial_conv2d_nhwc.register(["arm_cpu"]) -def schedule_bitserial_conv2d_nhwc(outs): - """Raspverry pi schedule for bitserial conv2d""" +@autotvm.register_topi_schedule(generic.nn.schedule_bitserial_conv2d_nhwc, 'arm_cpu', 'direct') +def schedule_bitserial_conv2d_nhwc(cfg, outs): + """Arm cpu schedule for bitserial conv2d""" s = tvm.create_schedule([x.op for x in outs]) scheduled_ops = [] @@ -344,10 +334,6 @@ def traverse(op): conv_out = op.input_tensors[0] kernel_vec = conv_out.op.input_tensors[0] kernel_q = kernel_vec.op.input_tensors[0] - kernel = kernel_q.op.input_tensors[0] - if "QuantizeInput" in kernel.op.name: - # Need to go up 1 further, from the combine in bitpack - kernel = kernel.op.input_tensors[0] data_vec = conv_out.op.input_tensors[1] data_q = data_vec.op.input_tensors[0] data = data_q.op.input_tensors[0] @@ -355,13 +341,10 @@ def traverse(op): if isinstance(data_q.op, tvm.tensor.ComputeOp) and "pad" in data_q.op.tag: data_pad = data_q data_q = data - data = data_q.op.input_tensors[0] - if "QuantizeInput" in data.op.name: - # Need to go up 1 further, from the combine in bitpack data = data.op.input_tensors[0] - - _schedule_spatial_conv2d_nhwc(s, data, data_q, data_pad, data_vec, - kernel, kernel_q, kernel_vec, conv_out, output, outs[0]) + unipolar = "unipolar" in conv_out.op.tag + _schedule_spatial_conv2d_nhwc(cfg, s, data_pad, data_vec, kernel_vec, + conv_out, output, outs[0], unipolar) scheduled_ops.append(op) traverse(outs[0].op) diff --git a/topi/python/topi/arm_cpu/conv2d.py b/topi/python/topi/arm_cpu/conv2d.py index 62c7ea1fb94f..3e1ebaa647e3 100644 --- a/topi/python/topi/arm_cpu/conv2d.py +++ b/topi/python/topi/arm_cpu/conv2d.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable, no-else-return, unused-argument """Conv2D schedule for ARM CPU""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/arm_cpu/conv2d_transpose.py b/topi/python/topi/arm_cpu/conv2d_transpose.py index 99f199782ed2..99cb046776e5 100644 --- a/topi/python/topi/arm_cpu/conv2d_transpose.py +++ b/topi/python/topi/arm_cpu/conv2d_transpose.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable """Transposed 2D convolution operators (sometimes called Deconvolution).""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/arm_cpu/depthwise_conv2d.py b/topi/python/topi/arm_cpu/depthwise_conv2d.py index 1e25eb58dbae..e09e355ad8aa 100644 --- a/topi/python/topi/arm_cpu/depthwise_conv2d.py +++ b/topi/python/topi/arm_cpu/depthwise_conv2d.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name,unused-variable """Depthwise convolution schedule for ARM CPU""" diff --git a/topi/python/topi/arm_cpu/injective.py b/topi/python/topi/arm_cpu/injective.py old mode 100755 new mode 100644 index 09ea86cea3a3..9afdc32cf117 --- a/topi/python/topi/arm_cpu/injective.py +++ b/topi/python/topi/arm_cpu/injective.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable """Schedule for pooling operators""" import tvm diff --git a/topi/python/topi/broadcast.py b/topi/python/topi/broadcast.py index 9cfd99fbeec4..0b6dbb5664e1 100644 --- a/topi/python/topi/broadcast.py +++ b/topi/python/topi/broadcast.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Broadcast operators""" from __future__ import absolute_import as _abs from .import cpp as _cpp diff --git a/topi/python/topi/cpp.py b/topi/python/topi/cpp.py index 3321b5b68289..a1c1c8e94a84 100644 --- a/topi/python/topi/cpp.py +++ b/topi/python/topi/cpp.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """FFI for C++ TOPI ops and schedules""" import sys import os diff --git a/topi/python/topi/cuda/__init__.py b/topi/python/topi/cuda/__init__.py index ba577cd944f0..706ecfb7f4bc 100644 --- a/topi/python/topi/cuda/__init__.py +++ b/topi/python/topi/cuda/__init__.py @@ -2,7 +2,7 @@ """CUDA specific declaration and schedules.""" from __future__ import absolute_import as _abs -from . import conv2d, depthwise_conv2d, conv2d_transpose_nchw, group_conv2d_nchw +from . import conv2d, depthwise_conv2d, conv2d_transpose_nchw, deformable_conv2d, group_conv2d_nchw from .conv2d_hwcn import schedule_conv2d_hwcn from .depthwise_conv2d import schedule_depthwise_conv2d_backward_input_nhwc from .depthwise_conv2d import schedule_depthwise_conv2d_backward_weight_nhwc diff --git a/topi/python/topi/cuda/batch_matmul.py b/topi/python/topi/cuda/batch_matmul.py index a1fa256028da..c973f1d8ea34 100644 --- a/topi/python/topi/cuda/batch_matmul.py +++ b/topi/python/topi/cuda/batch_matmul.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name,too-many-locals,unused-variable """cuda batch_matmul operators""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/cuda/conv2d.py b/topi/python/topi/cuda/conv2d.py index ca456134a6ce..256f91567b71 100644 --- a/topi/python/topi/cuda/conv2d.py +++ b/topi/python/topi/cuda/conv2d.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Compute definition for conv2d with cuda backend""" import tvm diff --git a/topi/python/topi/cuda/conv2d_direct.py b/topi/python/topi/cuda/conv2d_direct.py index 9b315a6b0fc1..2e769171cad6 100644 --- a/topi/python/topi/cuda/conv2d_direct.py +++ b/topi/python/topi/cuda/conv2d_direct.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """The templates for cuda conv2d operators""" import tvm diff --git a/topi/python/topi/cuda/conv2d_hwcn.py b/topi/python/topi/cuda/conv2d_hwcn.py index bbf89d22fca5..7907fc90c491 100644 --- a/topi/python/topi/cuda/conv2d_hwcn.py +++ b/topi/python/topi/cuda/conv2d_hwcn.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, too-many-locals, too-many-statements """Schedule for conv2d_hwcn with auto fusion""" import tvm diff --git a/topi/python/topi/cuda/conv2d_int8.py b/topi/python/topi/cuda/conv2d_int8.py index 637c5de35513..25d49451810d 100644 --- a/topi/python/topi/cuda/conv2d_int8.py +++ b/topi/python/topi/cuda/conv2d_int8.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Int8 conv2d in NCHWc layout""" import tvm diff --git a/topi/python/topi/cuda/conv2d_transpose_nchw.py b/topi/python/topi/cuda/conv2d_transpose_nchw.py index 380c721169e1..4bbb135376a3 100644 --- a/topi/python/topi/cuda/conv2d_transpose_nchw.py +++ b/topi/python/topi/cuda/conv2d_transpose_nchw.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Conv2d transpose template for cuda backend""" diff --git a/topi/python/topi/cuda/conv2d_winograd.py b/topi/python/topi/cuda/conv2d_winograd.py index a8d961ae062e..7fe3a4d7e3d6 100644 --- a/topi/python/topi/cuda/conv2d_winograd.py +++ b/topi/python/topi/cuda/conv2d_winograd.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name,unused-variable,unused-argument """Winograd template for cuda backend""" diff --git a/topi/python/topi/cuda/deformable_conv2d.py b/topi/python/topi/cuda/deformable_conv2d.py new file mode 100644 index 000000000000..a0e1cb8f5fc6 --- /dev/null +++ b/topi/python/topi/cuda/deformable_conv2d.py @@ -0,0 +1,142 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# pylint: disable=invalid-name +"""Schedule template of deformable conv2d with cuda backend""" +import tvm +from tvm import autotvm +from .. import nn, generic +from ..util import traverse_inline + + +autotvm.register_topi_compute(nn.deformable_conv2d_nchw, ["cuda", "gpu"], "direct", + nn.deformable_conv2d_nchw.fdefault) + + +@autotvm.register_topi_schedule(generic.schedule_deformable_conv2d_nchw, ["cuda", "gpu"], "direct") +def schedule_deformable_conv2d_nchw_cuda(cfg, outs): + """TOPI schedule callback of deformable conv2d for cuda gpu + + Parameters + ---------- + cfg: ConfigEntity + The config for this template + + outs: Array of Tensor + The computation graph description of conv2d + in the format of an array of tensors. + + Returns + ------- + s: Schedule + The computation schedule for conv2d. + """ + outs = [outs] if isinstance(outs, tvm.tensor.Tensor) else outs + s = tvm.create_schedule([x.op for x in outs]) + + def _callback(op): + if op.tag == 'deformable_conv2d_nchw': + schedule_direct_cuda(cfg, s, op.output(0)) + + traverse_inline(s, outs[0].op, _callback) + return s + + +def schedule_direct_cuda(cfg, s, conv): + """Schedule template of deformable conv2d""" + n, f, y, x = s[conv].op.axis + rc, ry, rx = s[conv].op.reduce_axis + cfg.define_split("tile_f", f, num_outputs=4) + cfg.define_split("tile_y", y, num_outputs=4) + cfg.define_split("tile_x", x, num_outputs=4) + cfg.define_split("tile_rc", rc, num_outputs=2) + cfg.define_split("tile_ry", ry, num_outputs=2) + cfg.define_split("tile_rx", rx, num_outputs=2) + cfg.define_knob("auto_unroll_max_step", [0, 512, 1500]) + + target = tvm.target.current_target() + if target.target_name in ['nvptx', 'rocm']: + cfg.define_knob("unroll_explicit", [1]) + else: + cfg.define_knob("unroll_explicit", [0, 1]) + + data_deform, kernel = s[conv].op.input_tensors + + s[data_deform].compute_inline() + if isinstance(kernel.op, tvm.tensor.ComputeOp) and 'dilate' in kernel.op.tag: + s[kernel].compute_inline() + + if conv.op in s.outputs: + output = conv + OL = s.cache_write(conv, 'local') + else: + output = s.outputs[0].output(0) + s[conv].set_scope('local') + OL = conv + + # create cache stage + AA = s.cache_read(data_deform, 'shared', [OL]) + WW = s.cache_read(kernel, 'shared', [OL]) + + # tile and bind spatial axes + n, f, y, x = s[output].op.axis + kernel_scope, n = s[output].split(n, nparts=1) + + bf, vf, tf, fi = cfg["tile_f"].apply(s, output, f) + by, vy, ty, yi = cfg["tile_y"].apply(s, output, y) + bx, vx, tx, xi = cfg["tile_x"].apply(s, output, x) + + bf = s[output].fuse(n, bf) + s[output].bind(bf, tvm.thread_axis("blockIdx.z")) + s[output].bind(by, tvm.thread_axis("blockIdx.y")) + s[output].bind(bx, tvm.thread_axis("blockIdx.x")) + s[output].bind(vf, tvm.thread_axis("vthread")) + s[output].bind(vy, tvm.thread_axis("vthread")) + s[output].bind(vx, tvm.thread_axis("vthread")) + s[output].bind(tf, tvm.thread_axis("threadIdx.z")) + s[output].bind(ty, tvm.thread_axis("threadIdx.y")) + s[output].bind(tx, tvm.thread_axis("threadIdx.x")) + s[output].reorder(bf, by, bx, vf, vy, vx, tf, ty, tx, fi, yi, xi) + s[OL].compute_at(s[output], tx) + + # tile reduction axes + n, f, y, x = s[OL].op.axis + rc, ry, rx = s[OL].op.reduce_axis + rco, rci = cfg['tile_rc'].apply(s, OL, rc) + ryo, ryi = cfg['tile_ry'].apply(s, OL, ry) + rxo, rxi = cfg['tile_rx'].apply(s, OL, rx) + s[OL].reorder(rco, ryo, rxo, rci, ryi, rxi, n, f, y, x) + cfg.define_reorder("reorder_inner", [rco, ryo, rxo], "all") + cfg["reorder_inner"].apply(s, OL, [rco, ryo, rxo]) + cfg["reorder_inner"].apply(s, OL, [rci, ryi, rxi]) + + cache_loc = [rco, ryo, rxo][cfg["reorder_inner"].perm[-1]] + s[AA].compute_at(s[OL], cache_loc) + s[WW].compute_at(s[OL], cache_loc) + + # cooperative fetching + for load in [AA, WW]: + fused = s[load].fuse(*s[load].op.axis) + tz, fused = s[load].split(fused, nparts=cfg["tile_f"].size[2]) + ty, fused = s[load].split(fused, nparts=cfg["tile_y"].size[2]) + tx, fused = s[load].split(fused, nparts=cfg["tile_x"].size[2]) + s[load].bind(tz, tvm.thread_axis("threadIdx.z")) + s[load].bind(ty, tvm.thread_axis("threadIdx.y")) + s[load].bind(tx, tvm.thread_axis("threadIdx.x")) + + # unroll + s[output].pragma(kernel_scope, 'auto_unroll_max_step', cfg['auto_unroll_max_step'].val) + s[output].pragma(kernel_scope, 'unroll_explicit', cfg['unroll_explicit'].val) diff --git a/topi/python/topi/cuda/dense.py b/topi/python/topi/cuda/dense.py index 6981d88e4e3d..680567cf5791 100644 --- a/topi/python/topi/cuda/dense.py +++ b/topi/python/topi/cuda/dense.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable """Schedule for dense operator""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/cuda/depthwise_conv2d.py b/topi/python/topi/cuda/depthwise_conv2d.py index 0214ed78b4e7..2903098b7997 100644 --- a/topi/python/topi/cuda/depthwise_conv2d.py +++ b/topi/python/topi/cuda/depthwise_conv2d.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Schedule for depthwise_conv2d with auto fusion""" import tvm diff --git a/topi/python/topi/cuda/extern.py b/topi/python/topi/cuda/extern.py index 94046196c074..74b88ec4ccd7 100644 --- a/topi/python/topi/cuda/extern.py +++ b/topi/python/topi/cuda/extern.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable, """Schedule for cudnn and miopen extern op""" import tvm diff --git a/topi/python/topi/cuda/group_conv2d_nchw.py b/topi/python/topi/cuda/group_conv2d_nchw.py index 739691131284..601b9b6e062c 100644 --- a/topi/python/topi/cuda/group_conv2d_nchw.py +++ b/topi/python/topi/cuda/group_conv2d_nchw.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """The template for cuda group_conv2d_nchw""" import tvm diff --git a/topi/python/topi/cuda/injective.py b/topi/python/topi/cuda/injective.py index 4ca89fb3ecd3..8a16c5ca2dd4 100644 --- a/topi/python/topi/cuda/injective.py +++ b/topi/python/topi/cuda/injective.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable, """Schedule for composition of injective operator""" import tvm diff --git a/topi/python/topi/cuda/nms.py b/topi/python/topi/cuda/nms.py index 6e91f30847c1..e6377fa40c52 100644 --- a/topi/python/topi/cuda/nms.py +++ b/topi/python/topi/cuda/nms.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, no-member, too-many-locals, too-many-arguments, too-many-statements, singleton-comparison, unused-argument """Non-maximum suppression operator""" import math diff --git a/topi/python/topi/cuda/nn.py b/topi/python/topi/cuda/nn.py index b503b2dad50f..288e36b7ac3d 100644 --- a/topi/python/topi/cuda/nn.py +++ b/topi/python/topi/cuda/nn.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """scheduler functions for cuda backend""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/cuda/pooling.py b/topi/python/topi/cuda/pooling.py index 6b36e9a8743f..ac3644ddd1b8 100644 --- a/topi/python/topi/cuda/pooling.py +++ b/topi/python/topi/cuda/pooling.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable, unused-argument """Schedule for pooling operators""" import tvm diff --git a/topi/python/topi/cuda/rcnn/proposal.py b/topi/python/topi/cuda/rcnn/proposal.py index b684b24d6269..06226d1b40b9 100644 --- a/topi/python/topi/cuda/rcnn/proposal.py +++ b/topi/python/topi/cuda/rcnn/proposal.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, singleton-comparison """Proposal operator""" import math diff --git a/topi/python/topi/cuda/reduction.py b/topi/python/topi/cuda/reduction.py index e8c029d4a871..ff7232cc0fac 100644 --- a/topi/python/topi/cuda/reduction.py +++ b/topi/python/topi/cuda/reduction.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name,unused-variable,too-many-locals,len-as-condition """Schedule for reduce operators""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/cuda/softmax.py b/topi/python/topi/cuda/softmax.py index c4f59ffb91c7..bb885fcb000b 100644 --- a/topi/python/topi/cuda/softmax.py +++ b/topi/python/topi/cuda/softmax.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable, trailing-whitespace """Schedule for softmax operator""" import tvm diff --git a/topi/python/topi/cuda/ssd/multibox.py b/topi/python/topi/cuda/ssd/multibox.py index 11062824deb0..38b76f36801e 100644 --- a/topi/python/topi/cuda/ssd/multibox.py +++ b/topi/python/topi/cuda/ssd/multibox.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, no-member, too-many-locals, too-many-arguments, too-many-statements, too-many-function-args """SSD multibox operators""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/cuda/tensor_intrin.py b/topi/python/topi/cuda/tensor_intrin.py index 26ae7587c5df..8f46d278d950 100644 --- a/topi/python/topi/cuda/tensor_intrin.py +++ b/topi/python/topi/cuda/tensor_intrin.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Tensor intrinsics on CUDA.""" #pylint: disable=invalid-name import tvm diff --git a/topi/python/topi/cuda/vision.py b/topi/python/topi/cuda/vision.py index 8ce452f41dc7..5d7bc9e00da6 100644 --- a/topi/python/topi/cuda/vision.py +++ b/topi/python/topi/cuda/vision.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable, unused-argument, no-member """Schedule for vision operators""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/generic/extern.py b/topi/python/topi/generic/extern.py index 92a47f8a9630..3728222fa622 100644 --- a/topi/python/topi/generic/extern.py +++ b/topi/python/topi/generic/extern.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """generic declaration and schedules.""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/generic/injective.py b/topi/python/topi/generic/injective.py index 975e4c11ea41..ec1732f394f2 100644 --- a/topi/python/topi/generic/injective.py +++ b/topi/python/topi/generic/injective.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """generic declaration and schedules.""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/generic/nn.py b/topi/python/topi/generic/nn.py index 40c6b34e2ac0..70ce5791d905 100644 --- a/topi/python/topi/generic/nn.py +++ b/topi/python/topi/generic/nn.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name,unused-argument """Generic nn operators""" from __future__ import absolute_import as _abs @@ -242,6 +258,24 @@ def schedule_group_conv2d_nchw(outs): return _default_schedule(outs, False) +@tvm.target.generic_func +def schedule_deformable_conv2d_nchw(outs): + """Schedule for deformable_conv2d_nchw + + Parameters + ---------- + outs: Array of Tensor + The computation graph description of deformable_conv2d_nchw + in the format of an array of tensors. + + Returns + ------- + sch: Schedule + The computation schedule for the op. + """ + return _default_schedule(outs, False) + + @tvm.target.generic_func def schedule_bitserial_conv2d_nchw(outs): """Schedule for bitserial_conv2d_nchw diff --git a/topi/python/topi/generic/vision.py b/topi/python/topi/generic/vision.py index a682ddddd8d3..a1e096a85880 100644 --- a/topi/python/topi/generic/vision.py +++ b/topi/python/topi/generic/vision.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, no-member """Generic vision operators""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/generic_op_impl.py b/topi/python/topi/generic_op_impl.py index 9123b46cabbe..b4b719fb35d4 100644 --- a/topi/python/topi/generic_op_impl.py +++ b/topi/python/topi/generic_op_impl.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Implementation of generic operators in the presence of Tensor""" # pylint: disable=invalid-name, too-many-arguments from __future__ import absolute_import as _abs diff --git a/topi/python/topi/hls/injective.py b/topi/python/topi/hls/injective.py index 21dfeb95df1b..5a43306f361b 100644 --- a/topi/python/topi/hls/injective.py +++ b/topi/python/topi/hls/injective.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable, """Schedule for composition of injective operator""" import tvm diff --git a/topi/python/topi/hls/nn.py b/topi/python/topi/hls/nn.py index 536453fc629c..5ce8394de981 100644 --- a/topi/python/topi/hls/nn.py +++ b/topi/python/topi/hls/nn.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name,unused-variable,unused-argument """HLS nn operators""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/image/resize.py b/topi/python/topi/image/resize.py index 461214cb1fbd..60fcf377c030 100644 --- a/topi/python/topi/image/resize.py +++ b/topi/python/topi/image/resize.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """TVM operator input resize compute.""" from __future__ import absolute_import import topi diff --git a/topi/python/topi/intel_graphics/conv2d.py b/topi/python/topi/intel_graphics/conv2d.py index 554deaad35a3..0cdbe365dda3 100644 --- a/topi/python/topi/intel_graphics/conv2d.py +++ b/topi/python/topi/intel_graphics/conv2d.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name,unused-variable,unused-argument,no-else-return, too-many-arguments, too-many-locals, too-many-statements, no-member, too-many-branches, too-many-boolean-expressions """conv2d schedule on Intel Graphics""" diff --git a/topi/python/topi/mali/conv2d.py b/topi/python/topi/mali/conv2d.py index 9a8b64fc7581..1d89d7e7cef6 100644 --- a/topi/python/topi/mali/conv2d.py +++ b/topi/python/topi/mali/conv2d.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name,unused-variable,unused-argument,no-else-return """conv2d schedule on ARM Mali GPU""" import numpy as np diff --git a/topi/python/topi/mali/dense.py b/topi/python/topi/mali/dense.py index ec21b806d0ad..6096a99c97c2 100644 --- a/topi/python/topi/mali/dense.py +++ b/topi/python/topi/mali/dense.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name,unused-variable """dense schedule on ARM Mali GPU""" diff --git a/topi/python/topi/mali/depthwise_conv2d.py b/topi/python/topi/mali/depthwise_conv2d.py index 8652ba583260..274b2944e4d9 100644 --- a/topi/python/topi/mali/depthwise_conv2d.py +++ b/topi/python/topi/mali/depthwise_conv2d.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name,unused-variable,unused-argument """depthwise_conv2d schedule on ARM Mali GPU""" diff --git a/topi/python/topi/math.py b/topi/python/topi/math.py index faddc8ac8a90..c63f041b959e 100644 --- a/topi/python/topi/math.py +++ b/topi/python/topi/math.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Elementwise operators""" # pylint: disable=redefined-builtin from __future__ import absolute_import as _abs diff --git a/topi/python/topi/nn/__init__.py b/topi/python/topi/nn/__init__.py index 941fec91a6bd..65eb7341babd 100644 --- a/topi/python/topi/nn/__init__.py +++ b/topi/python/topi/nn/__init__.py @@ -3,6 +3,7 @@ from __future__ import absolute_import as _abs from .conv2d import * +from .deformable_conv2d import * from .depthwise_conv2d import * from .elemwise import * from .dilate import * diff --git a/topi/python/topi/nn/batch_matmul.py b/topi/python/topi/nn/batch_matmul.py index 07e363868b05..c8ca3e3ca2a6 100644 --- a/topi/python/topi/nn/batch_matmul.py +++ b/topi/python/topi/nn/batch_matmul.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Binary Neural Network (BNN) Operators""" # pylint: disable=invalid-name from __future__ import absolute_import as _abs diff --git a/topi/python/topi/nn/bitserial_conv2d.py b/topi/python/topi/nn/bitserial_conv2d.py index d41a99a04a9d..5da90f134984 100644 --- a/topi/python/topi/nn/bitserial_conv2d.py +++ b/topi/python/topi/nn/bitserial_conv2d.py @@ -1,70 +1,48 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable, too-many-locals, too-many-arguments, unused-argument """Bitserial Conv2D operators""" from __future__ import absolute_import as _abs -from collections import namedtuple import numpy as np import tvm +from tvm import autotvm from topi.transform import concatenate from .pad import pad from .util import get_pad_tuple from ..util import get_const_tuple, get_const_int -# workload description of conv2d -Workload = namedtuple('Workload', - ['in_dtype', 'out_dtype', 'height', 'width', 'in_filter', 'out_filter', - 'hkernel', 'wkernel', 'hpad', 'wpad', 'hstride', 'wstride']) - -SpatialPackNCHW = namedtuple('SpatialPack', - ['vh', 'vw', 'vc', 'ba', 'bc']) - -SpatialPackNHWC = namedtuple('SpatialPack', - ['vh', 'vw', 'vc', 'ba', 'bc']) - -_WORKLOADS = [ - # workloads of resnet18 on imagenet - # input_size, input_size, ic, oc, kh, kw, pad, pad, stride, stride - Workload('uint32', 'int32', 56, 56, 64, 64, 3, 3, 1, 1, 1, 1), - Workload('uint32', 'int32', 56, 56, 64, 64, 1, 1, 0, 0, 1, 1), - Workload('uint32', 'int32', 56, 56, 64, 128, 3, 3, 1, 1, 2, 2), - Workload('uint32', 'int32', 56, 56, 64, 128, 1, 1, 0, 0, 2, 2), - Workload('uint32', 'int32', 28, 28, 128, 128, 3, 3, 1, 1, 1, 1), - Workload('uint32', 'int32', 28, 28, 128, 256, 3, 3, 1, 1, 2, 2), - Workload('uint32', 'int32', 28, 28, 128, 256, 1, 1, 0, 0, 2, 2), - Workload('uint32', 'int32', 14, 14, 256, 256, 3, 3, 1, 1, 1, 1), - Workload('uint32', 'int32', 14, 14, 256, 512, 3, 3, 1, 1, 2, 2), - Workload('uint32', 'int32', 14, 14, 256, 512, 1, 1, 0, 0, 2, 2), - Workload('uint32', 'int32', 7, 7, 512, 512, 3, 3, 1, 1, 1, 1), - - # workload of alexnet on cifar10 - Workload('int32', 'int32', 27, 27, 96, 192, 5, 5, 2, 2, 1, 1), - Workload('int32', 'int32', 13, 13, 192, 384, 3, 3, 1, 1, 1, 1), - Workload('int32', 'int32', 13, 13, 384, 384, 3, 3, 1, 1, 1, 1), - Workload('int32', 'int32', 13, 13, 384, 256, 3, 3, 1, 1, 1, 1), -] - @tvm.target.generic_func -def bitserial_conv2d(data, kernel, stride, padding, activation_bits, weight_bits, - layout='NCHW', pack_dtype='uint32', out_dtype='int32', dorefa=True): +def bitserial_conv2d_nchw(data, kernel, stride, padding, activation_bits, weight_bits, + pack_dtype='uint32', out_dtype='int16', unipolar=True): """Bitserial Conv2D operator. Parameters ---------- input : tvm.Tensor - 4-D with shape [batch, in_channel, in_height, in_width] or - [batch, in_height, in_width, in_channel] + 4-D with shape [batch, in_channel, in_height, in_width] filter : tvm.Tensor - 4-D with shape [num_filter, in_channel, filter_height, filter_width] or - [filter_height, filter_width, in_channel, num_filter] + 4-D with shape [num_filter, in_channel, filter_height, filter_width] stride : int or a list/tuple of two ints stride size, or [stride_height, stride_width] - padding : int or a list/tuple of two ints - padding size, or [pad_height, pad_width] - - layout : str - layout of data + padding : int or a list/tuple of two or four ints + padding size, [pad_height, pad_width], [pad_top, pad_left, pad_down, pad_right] activation_bits: int number of bits used for activations/input elements @@ -78,63 +56,184 @@ def bitserial_conv2d(data, kernel, stride, padding, activation_bits, weight_bits pack_dtype: str bit packing type - dorefa: bool - preform the bitserial dot-product using 2 popcounts (required for DoReFa-Net) + unipolar: bool + if binarization style is in unipolar 1/0 format, instead of bipolar -1/+1 format Returns ------- output : tvm.Tensor - 4-D with shape [batch, out_channel, out_height, out_width] or - [batch, out_height, out_width, out_channel] + 4-D with shape [batch, out_channel, out_height, out_width] """ - # search platform specific declaration first - # default declaration - if layout == 'NCHW': - return spatial_pack_nchw(data, kernel, stride, padding, activation_bits, weight_bits, - pack_dtype=pack_dtype, out_dtype=out_dtype, dorefa=dorefa) - if layout == 'NHWC': - return spatial_pack_nhwc(data, kernel, stride, padding, activation_bits, weight_bits, - pack_dtype=pack_dtype, out_dtype=out_dtype, dorefa=dorefa) - raise ValueError("not support this layout {} yet".format(layout)) - -def _get_workload(data, kernel, stride, padding, out_dtype, layout): - """ Get the workload structure. """ - assert layout in ("NCHW", "NHWC"), \ - "Only support layouts NCHW and NHWC" - if layout == "NCHW": - _, CI, IH, IW = [x.value for x in data.shape] - CO, _, KH, KW = [x.value for x in kernel.shape] - else: # NHWC - IH, IW = data.shape[1].value, data.shape[2].value - KH, KW, CI, CO = [x for x in get_const_tuple(kernel.shape)] - - HPAD, WPAD, _, _ = get_pad_tuple(padding, kernel) - if isinstance(stride, (tuple, list)): - HSTR, WSTR = stride + assert isinstance(stride, int) or len(stride) == 2 + Input_q = bitpack(data, activation_bits, pack_axis=1, bit_axis=2, pack_type=pack_dtype) + Filter_q = bitpack(filter, weight_bits, pack_axis=1, bit_axis=4, pack_type=pack_dtype) + batch, in_channel, activation_bits, in_height, in_width = Input_q.shape + num_filter, channel, kernel_h, kernel_w, weight_bits = Filter_q.shape + + if isinstance(padding, int) or (isinstance(padding, (tuple, list)) and len(padding) == 2): + TPAD, LPAD, DPAD, RPAD = get_pad_tuple(padding, kernel) else: - HSTR, WSTR = stride, stride + TPAD, LPAD, DPAD, RPAD = padding + pad_before = [0, 0, 0, TPAD, LPAD] + pad_after = [0, 0, 0, DPAD, RPAD] + + PadInput_q = pad(Input_q, pad_before, pad_after, name="pad_temp") + # compute the output shape + if isinstance(stride, int): + stride_h = stride_w = stride + else: + stride_h, stride_w = stride + out_channel = num_filter + out_height = (in_height - kernel_h + TPAD + DPAD) // stride_h + 1 + out_width = (in_width - kernel_w + LPAD + RPAD) // stride_w + 1 + + rc = tvm.reduce_axis((0, in_channel), name='rc') + ry = tvm.reduce_axis((0, kernel_h), name='ry') + rx = tvm.reduce_axis((0, kernel_w), name='rx') + b1 = tvm.reduce_axis((0, activation_bits), name='b1') + b2 = tvm.reduce_axis((0, weight_bits), name='b2') + + if unipolar: + def _conv(nn, ff, yy, xx): + b1b2 = (b1+b2).astype(out_dtype) + return tvm.sum( + ((tvm.popcount(PadInput_q[nn, rc, b1, yy * stride_h + ry, xx * stride_w + rx] & + Filter_q[ff, rc, ry, rx, b2]) - + tvm.popcount(PadInput_q[nn, rc, b1, yy * stride_h + ry, xx * stride_w + rx] & + ~Filter_q[ff, rc, ry, rx, b2])) + << (b1b2)).astype(out_dtype), + axis=[rc, ry, rx, b2, b1]).astype(out_dtype) + else: + def _conv(nn, ff, yy, xx): + b1b2 = (b1+b2).astype(out_dtype) + return tvm.sum((tvm.popcount( + PadInput_q[nn, rc, b1, yy * stride_h + ry, xx * stride_w + rx] & + Filter_q[ff, rc, ry, rx, b2])<< (b1b2)).astype(out_dtype), + axis=[rc, ry, rx, b2, b1]).astype(out_dtype) - return Workload(data.dtype, out_dtype, IH, IW, CI, CO, KH, KW, HPAD, WPAD, HSTR, WSTR) + return tvm.compute((batch, out_channel, out_height, out_width), _conv, + name="Conv2dOutput", tag="bitserial_conv2d_nchw") @tvm.target.generic_func -def _get_schedule(wkl, layout): - # pylint: disable=unreachable - """ Get the platform specific schedule. """ - target = tvm.target.current_target() - raise RuntimeError( - "No schedule for current target:{}".format(target)) - # This return has no use, merely to supress pylint warning - return wkl - -def spatial_pack_nchw(data, kernel, stride, padding, in_bits, weight_bits, - pack_dtype, out_dtype, dorefa=False): +def bitserial_conv2d_nhwc(data, kernel, stride, padding, activation_bits, weight_bits, + pack_dtype='uint32', out_dtype='int16', unipolar=True): + """Bitserial Conv2D operator. + + Parameters + ---------- + input : tvm.Tensor + 4-D with shape [batch, in_height, in_width, in_channel] + + filter : tvm.Tensor + 4-D with shape [filter_height, filter_width, in_channel, num_filter] + + stride : int or a list/tuple of two ints + stride size, or [stride_height, stride_width] + + padding : int or a list/tuple of two or four ints + padding size, [pad_height, pad_width], [pad_top, pad_left, pad_down, pad_right] + + activation_bits: int + number of bits used for activations/input elements + + weight_bits: int + number of bits used for weight elements + + out_dtype: str + return type of convolution + + pack_dtype: str + bit packing type + + unipolar: bool + if binarization style is in unipolar 1/0 format, instead of bipolar -1/+1 format + + Returns + ------- + output : tvm.Tensor + 4-D with shape [batch, out_height, out_width, out_channel] + """ + assert isinstance(stride, int) or len(stride) == 2 + Input_q = bitpack(data, activation_bits, pack_axis=3, bit_axis=4, pack_type=pack_dtype) + if len(kernel.shape) == 4: + Filter_q = bitpack(kernel, weight_bits, pack_axis=2, bit_axis=4, pack_type=pack_dtype) + kernel_h, kernel_w, _, num_filter, _ = get_const_tuple(Filter_q.shape) + else: + Filter_q = kernel + kernel_h, kernel_w, _, _, num_filter = get_const_tuple(Filter_q.shape) + batch, in_height, in_width, in_channel_q, _ = get_const_tuple(Input_q.shape) + + if isinstance(padding, int) or (isinstance(padding, (tuple, list)) and len(padding) == 2): + TPAD, LPAD, DPAD, RPAD = get_pad_tuple(padding, kernel) + else: + TPAD, LPAD, DPAD, RPAD = padding + pad_before = [0, TPAD, LPAD, 0, 0] + pad_after = [0, DPAD, RPAD, 0, 0] + + # compute the output shape + if isinstance(stride, int): + stride_h = stride_w = stride + else: + stride_h, stride_w = stride + out_channel = num_filter + out_height = (in_height - kernel_h + TPAD + DPAD) // stride_h + 1 + out_width = (in_width - kernel_w + LPAD + RPAD) // stride_w + 1 + PadInput_q = pad(Input_q, pad_before, pad_after, name="PaddedInput") + + rc = tvm.reduce_axis((0, in_channel_q), name='rc') + ry = tvm.reduce_axis((0, kernel_h), name='ry') + rx = tvm.reduce_axis((0, kernel_w), name='rx') + b1 = tvm.reduce_axis((0, activation_bits), name='b1') + b2 = tvm.reduce_axis((0, weight_bits), name='b2') + + if unipolar: + def _conv(nn, yy, xx, ff): + b1b2 = (b1+b2).astype(out_dtype) + return tvm.sum( + ((tvm.popcount(PadInput_q[nn, yy * stride_h + ry, xx * stride_w + rx, rc, b1] & + Filter_q[ry, rx, rc, ff, b2]) - + tvm.popcount(PadInput_q[nn, yy * stride_h + ry, xx * stride_w + rx, rc, b1] & + ~Filter_q[ry, rx, rc, ff, b2])) + << b1b2).astype(out_dtype), + axis=[rc, ry, rx, b2, b1]) + + else: + def _conv(nn, yy, xx, ff): + b1b2 = (b1+b2).astype(out_dtype) + return tvm.sum((tvm.popcount( + PadInput_q[nn, yy * stride_h + ry, xx * stride_w + rx, rc, b1] & + Filter_q[ry, rx, rc, ff, b2]) << b1b2).astype(out_dtype), + axis=[rc, ry, rx, b2, b1]) + + conv = tvm.compute((batch, out_height, out_width, out_channel), _conv, + name="Conv2dOutput", tag="bitserial_conv2d_nhwc") + + return conv + +@autotvm.register_topi_compute(bitserial_conv2d_nchw, ['cpu', 'arm_cpu'], 'direct') +def spatial_pack_nchw(cfg, data, kernel, stride, padding, in_bits, weight_bits, + pack_dtype='uint32', out_dtype='int16', unipolar=True): """ Compute convolution with pack on spatial axes. """ assert data.shape[0].value == 1, "spatial pack convolution only support batch size=1" data_q = bitpack(data, in_bits, pack_axis=1, bit_axis=0, pack_type=pack_dtype) - kernel_q = bitpack(kernel, weight_bits, pack_axis=1, bit_axis=0, pack_type=pack_dtype) - IB, _, CI, H, W = data_q.shape - KB, CO, _, KH, KW = kernel_q.shape - HPAD, WPAD, _, _ = get_pad_tuple(padding, kernel) + # Check if kernel is already bitpacked + if len(kernel.shape) == 4: + kernel_q = bitpack(kernel, weight_bits, pack_axis=1, bit_axis=0, pack_type=pack_dtype) + KB, CO, _, KH, KW = get_const_tuple(kernel_q.shape) + else: + kernel_vec = kernel + OCO, _, KH, KW, KB, VC = get_const_tuple(kernel_vec.shape) + CO = OCO * VC + + IB, N, CI, H, W = get_const_tuple(data_q.shape) + KB, CO, _, KH, KW = get_const_tuple(kernel_q.shape) + + if isinstance(padding, int) or (isinstance(padding, (tuple, list)) and len(padding) == 2): + TPAD, LPAD, DPAD, RPAD = get_pad_tuple(padding, kernel) + else: + TPAD, LPAD, DPAD, RPAD = padding + pad_before = [0, 0, 0, TPAD, LPAD] + pad_after = [0, 0, 0, DPAD, RPAD] if isinstance(stride, (tuple, list)): HSTR, WSTR = stride @@ -142,38 +241,50 @@ def spatial_pack_nchw(data, kernel, stride, padding, in_bits, weight_bits, HSTR, WSTR = stride, stride HCAT, WCAT = KH-1, KW-1 - wkl = _get_workload(data, kernel, stride, padding, out_dtype, "NCHW") - sch = _get_schedule(wkl, "NCHW") - VH = sch.vh - VW = sch.vw - VC = sch.vc - - TH = H + 2*HPAD - TW = W + 2*WPAD - OH = (H + 2*HPAD - KH) // HSTR + 1 - OW = (W + 2*WPAD - KW) // WSTR + 1 + TH = H + TPAD + DPAD + TW = W + LPAD + RPAD + OH = (H + TPAD + DPAD - KH) // HSTR + 1 + OW = (W + LPAD + RPAD - KW) // WSTR + 1 + + # ==================== define configuration space ==================== + n, co, oh, ow = cfg.axis(N), cfg.axis(CO), cfg.axis(OH), cfg.axis(OW) + ci, kh, kw = cfg.reduce_axis(CI), cfg.reduce_axis(KH), cfg.reduce_axis(KW) + ib, kb = cfg.reduce_axis(in_bits), cfg.reduce_axis(weight_bits) + + co, vc = cfg.define_split('tile_co', co, policy='all', num_outputs=2, + filter=lambda x: max(x.size[1:]) <= 16) + oh, vh = cfg.define_split('tile_oh', oh, policy='all', num_outputs=2, + filter=lambda x: max(x.size[1:]) <= 16) + ow, vw = cfg.define_split('tile_ow', ow, policy='all', num_outputs=2, + filter=lambda x: max(x.size[1:]) <= 16) + cfg.define_annotate('ann_reduce', [ib, kb, kh, kw], policy='try_unroll') + + re_axes = cfg.define_reorder("reorder_0", + [n, co, oh, ow, vc, vh, vw, kh, kw, kb, ib, ci], + policy='interval_all', interval=(6, 11)) + cfg.add_flop(2 * N * OH * OW * CO * CI * 8 * KH * KW) # these are actually binary ops + # ==================== + + VC = cfg["tile_co"].size[-1] + VH = cfg["tile_oh"].size[-1] + VW = cfg["tile_ow"].size[-1] - dshape = (IB, 1, CI, H, W) - dpshape = (IB, 1, CI, TH, TW) dvshape = (1, TH//(VH*HSTR), TW//(VW*WSTR), CI, VH*HSTR+HCAT, VW*WSTR+WCAT, IB) - - kshape = (KB, CO, CI, KH, KW) kvshape = (CO//VC, CI, KH, KW, KB, VC) - ovshape = (1, CO//VC, OH//VH, OW//VW, VH, VW, VC) oshape = (1, CO, OH, OW) - DOPAD = (HPAD != 0 and WPAD != 0) - if DOPAD: - data_pad = pad(data_q, (0, 0, 0, HPAD, WPAD), name="data_pad") + if (TPAD != 0 and RPAD != 0): + data_pad = pad(data_q, (0, 0, 0, TPAD, LPAD), (0, 0, 0, DPAD, RPAD), name="data_pad") else: data_pad = data_q data_vec = tvm.compute(dvshape, lambda n, h, w, ci, vh, vw, b: \ data_pad[b][n][ci][h*VH*HSTR+vh][w*VW*WSTR+vw], name='data_vec') - kernel_vec = tvm.compute(kvshape, lambda co, ci, dh, dw, b, vc: \ - kernel_q[b][co*VC+vc][ci][dh][dw], name='kernel_vec') + if len(kernel.shape) == 4: + kernel_vec = tvm.compute(kvshape, lambda co, ci, dh, dw, b, vc: \ + kernel_q[b][co*VC+vc][ci][dh][dw], name='kernel_vec') ci = tvm.reduce_axis((0, CI), name='ci') dh = tvm.reduce_axis((0, KH), name='dh') @@ -183,7 +294,7 @@ def spatial_pack_nchw(data, kernel, stride, padding, in_bits, weight_bits, def _conv(n, co, h, w, vh, vw, vc): b1b2 = (b1+b2).astype(out_dtype) - if dorefa: + if unipolar: return tvm.sum((tvm.popcount( data_vec[n, h, w, ci, vh*HSTR+dh, vw*WSTR+dw, b1].astype(out_dtype) & kernel_vec[co, ci, dh, dw, b2, vc].astype(out_dtype)) - @@ -203,15 +314,28 @@ def _conv(n, co, h, w, vh, vw, vc): conv[n][co//VC][h//VH][w//VW][h%VH][w%VW][co%VC], name='conv_vec', tag='spatial_bitserial_conv_nchw') -def spatial_pack_nhwc(data, kernel, stride, padding, in_bits, weight_bits, - pack_dtype, out_dtype, dorefa=False): +@autotvm.register_topi_compute(bitserial_conv2d_nhwc, 'cpu', 'direct') +def spatial_pack_nhwc(cfg, data, kernel, stride, padding, in_bits, weight_bits, + pack_dtype='uint32', out_dtype='int16', unipolar=True): """ Compute convolution with pack on spatial axes. """ assert data.shape[0].value == 1, "spatial pack convolution only support batch size=1" data_q = bitpack(data, in_bits, pack_axis=3, bit_axis=4, pack_type=pack_dtype) - kernel_q = bitpack(kernel, weight_bits, pack_axis=2, bit_axis=4, pack_type=pack_dtype) - _, H, W, CI, IB = data_q.shape - KH, KW, _, CO, KB = kernel_q.shape - HPAD, WPAD, _, _ = get_pad_tuple(padding, kernel) + pack_kernel = len(kernel.shape) == 4 + + if pack_kernel: + kernel_q = bitpack(kernel, weight_bits, pack_axis=2, bit_axis=4, pack_type=pack_dtype) + else: + kernel_q = kernel + + KH, KW, _, CO, KB = get_const_tuple(kernel_q.shape) + N, H, W, CI, IB = get_const_tuple(data_q.shape) + + if isinstance(padding, int) or (isinstance(padding, (tuple, list)) and len(padding) == 2): + TPAD, LPAD, DPAD, RPAD = get_pad_tuple(padding, kernel) + else: + TPAD, LPAD, DPAD, RPAD = padding + pad_before = [0, TPAD, LPAD, 0, 0] + pad_after = [0, DPAD, RPAD, 0, 0] if isinstance(stride, (tuple, list)): HSTR, WSTR = stride @@ -219,24 +343,41 @@ def spatial_pack_nhwc(data, kernel, stride, padding, in_bits, weight_bits, HSTR, WSTR = stride, stride HCAT, WCAT = KH-1, KW-1 - wkl = _get_workload(data, kernel, stride, padding, out_dtype, "NHWC") - sch = _get_schedule(wkl, "NHWC") - VH = sch.vh - VW = sch.vw - VC = sch.vc + PAD_H = H + (TPAD + DPAD) + PAD_W = W + (LPAD + RPAD) + OH = (PAD_H - KH) // HSTR + 1 + OW = (PAD_W - KW) // WSTR + 1 + oshape = (1, OH, OW, CO) - PAD_H = H + 2*HPAD - PAD_W = W + 2*WPAD - OH = (H + 2*HPAD - KH) // HSTR + 1 - OW = (W + 2*WPAD - KW) // WSTR + 1 + # ==================== define configuration space ==================== + n, oh, ow, co = cfg.axis(N), cfg.axis(OH), cfg.axis(OW), cfg.axis(CO) + ci, kh, kw = cfg.reduce_axis(CI), cfg.reduce_axis(KH), cfg.reduce_axis(KW) + ib, kb = cfg.reduce_axis(in_bits), cfg.reduce_axis(weight_bits) + + co, vc = cfg.define_split('tile_co', co, policy='all', num_outputs=2, + filter=lambda x: max(x.size[1:]) <= 16) + oh, vh = cfg.define_split('tile_oh', oh, policy='all', num_outputs=2, + filter=lambda x: max(x.size[1:]) <= 16) + ow, vw = cfg.define_split('tile_ow', ow, policy='all', num_outputs=2, + filter=lambda x: max(x.size[1:]) <= 16) + cfg.define_annotate('ann_reduce', [ib, kb, kh, kw], policy='try_unroll') + re_axes = cfg.define_reorder("reorder_0", + [n, oh, ow, co, vh, vw, kh, kw, kb, ib, vc, ci], + policy='interval_all', interval=(3, 7)) + cfg.add_flop(2 * N * OH * OW * CO * CI * 8 * KH * KW) # these are actually binary ops + # ==================== + + VC = cfg["tile_co"].size[-1] + VH = cfg["tile_oh"].size[-1] + VW = cfg["tile_ow"].size[-1] dvshape = (1, PAD_H//(VH*HSTR), PAD_W//(VW*WSTR), VH*HSTR+HCAT, VW*WSTR+WCAT, CI, IB) kvshape = (CO, KH, KW, CI, VC, KB) ovshape = (1, OH, OW, CO, VH, VW, VC) oshape = (1, OH, OW, CO) - if (HPAD != 0 and WPAD != 0): - data_pad = pad(data_q, (0, HPAD, WPAD, 0, 0), name="data_pad") + if (DPAD != 0 and RPAD != 0): + data_pad = pad(data_q, (0, TPAD, LPAD, 0, 0), (0, DPAD, RPAD, 0, 0), name="data_pad") else: data_pad = data_q @@ -254,12 +395,12 @@ def spatial_pack_nhwc(data, kernel, stride, padding, in_bits, weight_bits, def _conv(n, h, w, co, vh, vw, vc): b1b2 = (b1+b2).astype(out_dtype) - if dorefa: + if unipolar: return tvm.sum( - (tvm.popcount(data_vec[n, h, w, vh*HSTR+dh, vw*WSTR+dw, ci, b1].astype(out_dtype) & - kernel_vec[co, dh, dw, ci, vc, b2].astype(out_dtype)) - - tvm.popcount(data_vec[n, h, w, vh*HSTR+dh, vw*WSTR+dw, ci, b1].astype(out_dtype) & - ~kernel_vec[co, dh, dw, ci, vc, b2]).astype(out_dtype)) << b1b2, + ((tvm.popcount(data_vec[n, h, w, vh*HSTR+dh, vw*WSTR+dw, ci, b1] & + kernel_vec[co, dh, dw, ci, vc, b2]).astype(out_dtype) - + tvm.popcount(data_vec[n, h, w, vh*HSTR+dh, vw*WSTR+dw, ci, b1]& + ~kernel_vec[co, dh, dw, ci, vc, b2]).astype(out_dtype)) << b1b2), axis=[dh, dw, ci, b1, b2]) return tvm.sum(tvm.popcount( @@ -273,6 +414,7 @@ def _conv(n, h, w, co, vh, vw, vc): conv[n][h//VH][w//VW][co//VC][h%VH][w%VW][co%VC], name='output_unpack', tag='spatial_bitserial_conv_nhwc') + def bitpack(data, bits, pack_axis, bit_axis, pack_type, name="QuantizeInput"): """Packs data into format necessary for bitserial computation pack_axis : int @@ -334,8 +476,3 @@ def _bitpack(*indices): if bits > 1: return concatenate(output_tuple, axis=bit_axis) return output_tuple - -_SCH_TO_DECL_FUNC_QUANT = { - SpatialPackNCHW: spatial_pack_nchw, - SpatialPackNHWC: spatial_pack_nhwc, -} diff --git a/topi/python/topi/nn/bnn.py b/topi/python/topi/nn/bnn.py index 591a082e7d30..e3b841e0b673 100644 --- a/topi/python/topi/nn/bnn.py +++ b/topi/python/topi/nn/bnn.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Binary Neural Network (BNN) Operators""" from __future__ import absolute_import as _abs import tvm diff --git a/topi/python/topi/nn/conv2d.py b/topi/python/topi/nn/conv2d.py index a67f608d26dc..49c0bd79eacc 100644 --- a/topi/python/topi/nn/conv2d.py +++ b/topi/python/topi/nn/conv2d.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable, too-many-locals # pylint: disable=unused-argument, redefined-builtin """Conv2D operators""" @@ -329,7 +345,68 @@ def conv2d_NCHWc(data, kernel, stride, padding, dilation, layout, out_layout, ou """ # search platform specific declaration first # default declaration - raise ValueError("missing register for topi.nn.conv2d_NCHWc") + # layout and out_layout are not used here, + # we keep them for debug convenience when dumping autotvm workload + pad_top, pad_left, pad_down, pad_right = get_pad_tuple(padding, + (dilated_kernel_h, + dilated_kernel_w)) + HPAD = pad_top + pad_down + WPAD = pad_left + pad_right + HSTR, WSTR = stride if isinstance(stride, (tuple, list)) else (stride, stride) + dh, dw = dilation if isinstance(dilation, (tuple, list)) else (dilation, dilation) + assert (dh, dw) == (1, 1), "Does not support dilation" + + n, ic_chunk, ih, iw, ic_bn = get_const_tuple(data.shape) + in_channel = ic_chunk * ic_bn + if data.dtype == 'uint8': + oc_chunk, _, kernel_height, kernel_width, _, oc_bn, _ = get_const_tuple(kernel.shape) + else: + oc_chunk, _, kernel_height, kernel_width, _, oc_bn = get_const_tuple(kernel.shape) + num_filter = oc_chunk * oc_bn + + # output shape + out_height = (ih + 2 * HPAD - kernel_height) // HSTR + 1 + out_width = (iw + 2 * WPAD - kernel_width) // WSTR + 1 + oshape = (n, oc_chunk, out_height, out_width, oc_bn) + + # DOPAD + DOPAD = (HPAD != 0 or WPAD != 0) + if DOPAD: + data_pad = pad(data, (0, 0, HPAD, WPAD, 0), name="data_pad") + else: + data_pad = data + + ic = tvm.reduce_axis((0, in_channel), name='ic') + kh = tvm.reduce_axis((0, kernel_height), name='kh') + kw = tvm.reduce_axis((0, kernel_width), name='kw') + + if data.dtype == 'uint8': + assert out_dtype == "int32", \ + "INT8 convolution requires input dtype = uint8 and output dtype=int32" + # Intel performs dot product of 2 "4" Int8 values + # Current implementation requires ic_bn to be a multiple of 4 + n_elems = 4 + assert ic_bn % n_elems == 0 + + ic_outer = tvm.reduce_axis((0, in_channel//ic_bn), name='ic_outer') + ic_f_inner = tvm.reduce_axis((0, ic_bn//n_elems), name='ic_f_inner') + ic_s_inner = tvm.reduce_axis((0, n_elems), name='ic_s_inner') + return tvm.compute(oshape, lambda n, oc_chunk, oh, ow, oc_block: + tvm.sum(data_pad[n, ic_outer, oh*HSTR+kh, ow*WSTR+kw, + ic_f_inner * n_elems + ic_s_inner] + .astype(out_dtype) * + kernel[oc_chunk, ic_outer, kh, kw, ic_f_inner, + oc_block, ic_s_inner].astype(out_dtype), + axis=[kh, kw, ic_outer, ic_f_inner, ic_s_inner]), + name='conv2d_NCHWc_int8', tag="conv2d_NCHWc_int8") + # else: fp implementation + return tvm.compute(oshape, lambda n, oc_chunk, oh, ow, oc_block: + tvm.sum(data_pad[n, ic//ic_bn, oh*HSTR+kh, ow*WSTR+kw, + ic%ic_bn].astype(out_dtype) * + kernel[oc_chunk, ic//ic_bn, kh, kw, ic%ic_bn, oc_block], + axis=[ic, kh, kw]), + name='conv2d_NCHWc', tag="conv2d_NCHWc") + def conv2d_winograd_weight_transform(kernel, tile_size): diff --git a/topi/python/topi/nn/conv2d_transpose.py b/topi/python/topi/nn/conv2d_transpose.py index f9fdd3f1b2dc..083abf3be588 100644 --- a/topi/python/topi/nn/conv2d_transpose.py +++ b/topi/python/topi/nn/conv2d_transpose.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable """Transposed 2D convolution operators (sometimes called Deconvolution).""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/nn/deformable_conv2d.py b/topi/python/topi/nn/deformable_conv2d.py new file mode 100644 index 000000000000..fb050165e57a --- /dev/null +++ b/topi/python/topi/nn/deformable_conv2d.py @@ -0,0 +1,115 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# pylint: disable=invalid-name, too-many-locals, too-many-arguments +"""Deformable Conv2D operators""" +import tvm + +from .util import get_pad_tuple +from ..util import get_const_tuple +from ..cpp.image import bilinear_sample_nchw + +@tvm.target.generic_func +def deformable_conv2d_nchw(data, offset, kernel, strides, padding, dilation, deformable_groups, + groups, out_dtype): + """Deformable conv2D operator in NCHW layout. + + The deformable convolution operation is described in https://arxiv.org/abs/1703.06211 + + Parameters + ---------- + data : tvm.Tensor + 4-D with shape [batch, in_channel, in_height, in_width] + + offset : tvm.Tensor + 4-D with shape [batch, deformable_groups * filter_height * filter_width * 2, + out_height, out_width]. + + kernel : tvm.Tensor + 4-D with shape [num_filter, in_channel, filter_height, filter_width] + + strides : int or a list/tuple of two ints + stride size, or [stride_height, stride_width] + + padding : int or a list/tuple of two ints + padding size, or [pad_height, pad_width] + + dilation : int or a list/tuple of two ints + dilation size, or [dilation_height, dilation_width] + + deformable_groups : int + number of deformable groups + + groups : int + number of groups + + Returns + ------- + output : tvm.Tensor + 4-D with shape [batch, out_channel, out_height, out_width] + """ + if out_dtype is None: + out_dtype = data.dtype + + if isinstance(strides, int): + stride_h = stride_w = strides + else: + stride_h, stride_w = strides + + if isinstance(dilation, int): + dilation_h = dilation_w = dilation + else: + dilation_h, dilation_w = dilation + + batch, in_channel, in_height, in_width = get_const_tuple(data.shape) + out_channel, channel, kernel_h, kernel_w = get_const_tuple(kernel.shape) + _, _, out_height, out_width = get_const_tuple(offset.shape) + assert in_channel % deformable_groups == 0, "Input cahnnels must divide deformable group size" + assert groups == 1, "deformable_conv2d_nchw does not support groups > 1" + + ic_per_dgroup = channel // deformable_groups + + dilated_kernel_h = (kernel_h - 1) * dilation_h + 1 + dilated_kernel_w = (kernel_w - 1) * dilation_w + 1 + pad_top, pad_left, _, _ = get_pad_tuple( + padding, (dilated_kernel_h, dilated_kernel_w)) + rc = tvm.reduce_axis((0, in_channel), name='rc') + ry = tvm.reduce_axis((0, kernel_h), name='ry') + rx = tvm.reduce_axis((0, kernel_w), name='rx') + + zero = tvm.const(0.0, data.dtype) + + def _bilinear(n, c, h, w): + outside = tvm.any(h < 0, w < 0, h >= in_height, w >= in_width) + val = bilinear_sample_nchw(data, (n, c, h, w), in_height - 1, in_width - 1) + return tvm.if_then_else(outside, zero, val) + + data_deform = \ + tvm.compute((batch, in_channel, kernel_h, kernel_w, out_height, out_width), + lambda n, c, kh, kw, y, x: + _bilinear(n, c, + y * stride_h - pad_top + kh * dilation_h + + offset[n, c // ic_per_dgroup * (kernel_w*kernel_h*2) + + (kh * kernel_w + kw) * 2, y, x], + x * stride_w - pad_left + kw * dilation_w + + offset[n, c // ic_per_dgroup * (kernel_w*kernel_h*2) + + (kh * kernel_w + kw) * 2 + 1, y, x])) + return tvm.compute( + (batch, out_channel, out_height, out_width), + lambda n, f, y, x: tvm.sum( + data_deform[n, rc, ry, rx, y, x].astype(out_dtype) * + kernel[f, rc, ry, rx].astype(out_dtype), + axis=[rc, ry, rx]), tag="deformable_conv2d_nchw") diff --git a/topi/python/topi/nn/dense.py b/topi/python/topi/nn/dense.py index abd424a64aeb..6c4aba1e84ef 100644 --- a/topi/python/topi/nn/dense.py +++ b/topi/python/topi/nn/dense.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """TVM operator fully connected compute.""" from __future__ import absolute_import import tvm diff --git a/topi/python/topi/nn/depthwise_conv2d.py b/topi/python/topi/nn/depthwise_conv2d.py index abb638039f48..460f4fefe678 100644 --- a/topi/python/topi/nn/depthwise_conv2d.py +++ b/topi/python/topi/nn/depthwise_conv2d.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable, too-many-locals, unused-argument """Depthwise convolution operators""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/nn/dilate.py b/topi/python/topi/nn/dilate.py index 3460ffec90ca..24bf0d3a7cdf 100644 --- a/topi/python/topi/nn/dilate.py +++ b/topi/python/topi/nn/dilate.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Dilation operators""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/nn/elemwise.py b/topi/python/topi/nn/elemwise.py index 6a2697795f4d..e9f301942aa3 100644 --- a/topi/python/topi/nn/elemwise.py +++ b/topi/python/topi/nn/elemwise.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Elementwise operators""" from __future__ import absolute_import as _abs import tvm diff --git a/topi/python/topi/nn/flatten.py b/topi/python/topi/nn/flatten.py index e3f853044cce..eb07f5eb7e1c 100644 --- a/topi/python/topi/nn/flatten.py +++ b/topi/python/topi/nn/flatten.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """TVM operator flatten compute.""" from __future__ import absolute_import import tvm diff --git a/topi/python/topi/nn/l2_normalize.py b/topi/python/topi/nn/l2_normalize.py index 951084379eec..d83ed10290ec 100644 --- a/topi/python/topi/nn/l2_normalize.py +++ b/topi/python/topi/nn/l2_normalize.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """TVM operator for l2 normalize""" from __future__ import absolute_import diff --git a/topi/python/topi/nn/local_response_norm.py b/topi/python/topi/nn/local_response_norm.py index 73eb41242513..de002bfffbe6 100644 --- a/topi/python/topi/nn/local_response_norm.py +++ b/topi/python/topi/nn/local_response_norm.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """TVM operator for local response norm compute.""" from __future__ import absolute_import diff --git a/topi/python/topi/nn/mapping.py b/topi/python/topi/nn/mapping.py index fb777c12183f..b2222bdeb87d 100644 --- a/topi/python/topi/nn/mapping.py +++ b/topi/python/topi/nn/mapping.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, line-too-long """Operators of one-to-one-mapping on the first input""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/nn/pad.py b/topi/python/topi/nn/pad.py index 6dda3feb599c..9beed858d6a0 100644 --- a/topi/python/topi/nn/pad.py +++ b/topi/python/topi/nn/pad.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Pad the data by constant value """ from __future__ import absolute_import as _abs import tvm diff --git a/topi/python/topi/nn/pooling.py b/topi/python/topi/nn/pooling.py index 18077cbcca7f..258de99a5842 100644 --- a/topi/python/topi/nn/pooling.py +++ b/topi/python/topi/nn/pooling.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """TVM operator pooling compute.""" from __future__ import absolute_import import tvm diff --git a/topi/python/topi/nn/softmax.py b/topi/python/topi/nn/softmax.py index 5e73f7633f4d..c02fd67f12bb 100644 --- a/topi/python/topi/nn/softmax.py +++ b/topi/python/topi/nn/softmax.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """TVM operator for softmax and log_softmax compute.""" from __future__ import absolute_import diff --git a/topi/python/topi/nn/upsampling.py b/topi/python/topi/nn/upsampling.py index 4b4ddcefea4e..14c7c05e00fa 100644 --- a/topi/python/topi/nn/upsampling.py +++ b/topi/python/topi/nn/upsampling.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """TVM operator upsampling compute.""" from __future__ import absolute_import import topi diff --git a/topi/python/topi/nn/util.py b/topi/python/topi/nn/util.py index 103635959f8d..7c0957cc7fc4 100644 --- a/topi/python/topi/nn/util.py +++ b/topi/python/topi/nn/util.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable """NN operator common utilities""" from __future__ import absolute_import diff --git a/topi/python/topi/opengl/conv2d_nchw.py b/topi/python/topi/opengl/conv2d_nchw.py index a1e089e37aa2..fec347628924 100644 --- a/topi/python/topi/opengl/conv2d_nchw.py +++ b/topi/python/topi/opengl/conv2d_nchw.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. #pylint: disable=invalid-name, no-member, too-many-locals, too-many-statements, too-many-arguments, too-many-branches, line-too-long """Schedule for conv2d_nchw with auto fusion""" import tvm diff --git a/topi/python/topi/opengl/dense.py b/topi/python/topi/opengl/dense.py index b98769b534ef..e2858cd1fbc9 100644 --- a/topi/python/topi/opengl/dense.py +++ b/topi/python/topi/opengl/dense.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable """Schedule for dense operator""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/opengl/injective.py b/topi/python/topi/opengl/injective.py index 9665e330864f..1f3f4942ac95 100644 --- a/topi/python/topi/opengl/injective.py +++ b/topi/python/topi/opengl/injective.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable, """Schedule for composition of injective operator""" import tvm diff --git a/topi/python/topi/opengl/pooling.py b/topi/python/topi/opengl/pooling.py index d6dbf0eac5c2..95dc561f6b08 100644 --- a/topi/python/topi/opengl/pooling.py +++ b/topi/python/topi/opengl/pooling.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable, unused-argument """Schedule for pooling operators""" import tvm diff --git a/topi/python/topi/opengl/softmax.py b/topi/python/topi/opengl/softmax.py index a5bf4371eb13..b9d9c29c1541 100644 --- a/topi/python/topi/opengl/softmax.py +++ b/topi/python/topi/opengl/softmax.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable, trailing-whitespace """Schedule for softmax operator""" import tvm diff --git a/topi/python/topi/reduction.py b/topi/python/topi/reduction.py index 7a4f161a8fee..ce1326b78162 100644 --- a/topi/python/topi/reduction.py +++ b/topi/python/topi/reduction.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=redefined-builtin,consider-using-enumerate,no-member """Reduce operators""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/rocm/conv2d.py b/topi/python/topi/rocm/conv2d.py index b5839c0c866b..7acc1b8e16a7 100644 --- a/topi/python/topi/rocm/conv2d.py +++ b/topi/python/topi/rocm/conv2d.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Compute definition for conv2d with rocm backend""" import tvm diff --git a/topi/python/topi/rocm/dense.py b/topi/python/topi/rocm/dense.py index cfeed247a4a1..f0ed1cd4b70c 100644 --- a/topi/python/topi/rocm/dense.py +++ b/topi/python/topi/rocm/dense.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable """Schedule for dense operator""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/rocm/nn.py b/topi/python/topi/rocm/nn.py index 5a9b2ad84db0..d7649f811662 100644 --- a/topi/python/topi/rocm/nn.py +++ b/topi/python/topi/rocm/nn.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """scheduler for normalization functions on rocm backend""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/sparse/csrmm.py b/topi/python/topi/sparse/csrmm.py index f0574bf3df6d..29f9cb4dbaa6 100644 --- a/topi/python/topi/sparse/csrmm.py +++ b/topi/python/topi/sparse/csrmm.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """TVM operator compute SpMM in CSR format.""" from __future__ import absolute_import import tvm diff --git a/topi/python/topi/sparse/csrmv.py b/topi/python/topi/sparse/csrmv.py index 7cd101711cca..fb9f10b151c0 100644 --- a/topi/python/topi/sparse/csrmv.py +++ b/topi/python/topi/sparse/csrmv.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """TVM operator compute SpMV in CSR format.""" from __future__ import absolute_import import tvm diff --git a/topi/python/topi/sparse/dense.py b/topi/python/topi/sparse/dense.py index 01f323bc8ce9..fe21e2fdf90e 100644 --- a/topi/python/topi/sparse/dense.py +++ b/topi/python/topi/sparse/dense.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """TVM operator compute Dense in CSR format.""" from __future__ import absolute_import import tvm diff --git a/topi/python/topi/tag.py b/topi/python/topi/tag.py index 6ed610729155..57cd41149f7f 100644 --- a/topi/python/topi/tag.py +++ b/topi/python/topi/tag.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Namespace of all tag system in tvm Each operator can be tagged by a tag, which indicate its type. diff --git a/topi/python/topi/tensor.py b/topi/python/topi/tensor.py index 06f23bbe7703..0231efcca272 100644 --- a/topi/python/topi/tensor.py +++ b/topi/python/topi/tensor.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name,consider-using-enumerate,unused-argument,len-as-condition """Elementwise operators""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/testing/__init__.py b/topi/python/topi/testing/__init__.py index 2eabb4b3d95b..40c1bdc83cac 100644 --- a/topi/python/topi/testing/__init__.py +++ b/topi/python/topi/testing/__init__.py @@ -8,6 +8,7 @@ from .conv2d_nchw_python import conv2d_nchw_python from .conv2d_nhwc_python import conv2d_nhwc_python from .conv2d_transpose_nchw_python import conv2d_transpose_nchw_python +from .deformable_conv2d_nchw_python import deformable_conv2d_nchw_python from .depthwise_conv2d_python import depthwise_conv2d_python_nchw, depthwise_conv2d_python_nhwc from .dilate_python import dilate_python from .softmax_python import softmax_python, log_softmax_python diff --git a/topi/python/topi/testing/batch_matmul.py b/topi/python/topi/testing/batch_matmul.py index a7b2f9344f29..c864f8d5e13d 100644 --- a/topi/python/topi/testing/batch_matmul.py +++ b/topi/python/topi/testing/batch_matmul.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Batch matmul in python""" import numpy as np diff --git a/topi/python/topi/testing/bilinear_resize_python.py b/topi/python/topi/testing/bilinear_resize_python.py index c014b075681a..6764ed348d49 100644 --- a/topi/python/topi/testing/bilinear_resize_python.py +++ b/topi/python/topi/testing/bilinear_resize_python.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, line-too-long, unused-variable, too-many-locals """Bilinear Scale in python""" import math diff --git a/topi/python/topi/testing/conv2d_hwcn_python.py b/topi/python/topi/testing/conv2d_hwcn_python.py index c84efce5e777..07a771837810 100644 --- a/topi/python/topi/testing/conv2d_hwcn_python.py +++ b/topi/python/topi/testing/conv2d_hwcn_python.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, line-too-long, unused-variable, too-many-locals """Convolution in python""" import numpy as np diff --git a/topi/python/topi/testing/conv2d_nchw_python.py b/topi/python/topi/testing/conv2d_nchw_python.py index 7d2aa0d0fedf..c2cc021c6866 100644 --- a/topi/python/topi/testing/conv2d_nchw_python.py +++ b/topi/python/topi/testing/conv2d_nchw_python.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, line-too-long, unused-variable, too-many-locals, too-many-branches """Convolution in python""" import numpy as np diff --git a/topi/python/topi/testing/conv2d_nhwc_python.py b/topi/python/topi/testing/conv2d_nhwc_python.py index a872bddab09b..d2ef40c64d21 100644 --- a/topi/python/topi/testing/conv2d_nhwc_python.py +++ b/topi/python/topi/testing/conv2d_nhwc_python.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, line-too-long, unused-variable, too-many-locals """Convolution in python""" import numpy as np diff --git a/topi/python/topi/testing/conv2d_transpose_nchw_python.py b/topi/python/topi/testing/conv2d_transpose_nchw_python.py index 2b78452b95cd..60b9d69c81de 100644 --- a/topi/python/topi/testing/conv2d_transpose_nchw_python.py +++ b/topi/python/topi/testing/conv2d_transpose_nchw_python.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=unused-variable """Transposed convolution in python""" import numpy as np diff --git a/topi/python/topi/testing/deformable_conv2d_nchw_python.py b/topi/python/topi/testing/deformable_conv2d_nchw_python.py new file mode 100644 index 000000000000..7e179db4c87d --- /dev/null +++ b/topi/python/topi/testing/deformable_conv2d_nchw_python.py @@ -0,0 +1,123 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# pylint: disable=invalid-name, too-many-locals, too-many-arguments +"""Deformable convolution in python""" +import itertools +import numpy as np + + +def deformable_conv2d_nchw_python(a_np, offset_np, w_np, stride, padding, dilation, + deformable_groups, groups): + """Deformable convolution operator in NCHW layout. + + Parameters + ---------- + a_np : numpy.ndarray + 4-D with shape [batch, in_channel, in_height, in_width] + + offset_np : numpy.ndarray + 4-D with shape [batch, deformable_groups * filter_height * filter_width * 2, + out_height, out_width] + + w_np : numpy.ndarray + 4-D with shape [num_filter, in_channel, filter_height, filter_width] + + stride : int or a list/tuple of two ints + Stride size, or [stride_height, stride_width] + + padding : int or str or a list/tuple of two ints + Padding size, or ['VALID', 'SAME'], or [pad_height, pad_width] + + dilation : int or a list/tuple of two ints + Dilation size, or [dilate_height, dilate_width] + + deformable_groups : int + Number of deformable groups + + groups : int + Number of groups + + Returns + ------- + b_np : np.ndarray + 4-D with shape [batch, out_channel, out_height, out_width] + """ + batch, in_channel, in_height, in_width = a_np.shape + out_channel, _, kernel_h, kernel_w = w_np.shape + out_height, out_width = offset_np.shape[-2:] + dtype = a_np.dtype + ic_per_dgroup = in_channel // deformable_groups + assert groups == 1, "deformable_conv2d_nchw_python does not support groups > 1" + + if isinstance(stride, int): + stride_h = stride_w = stride + else: + stride_h, stride_w = stride + if isinstance(padding, int): + pad_h = pad_w = padding * 2 + elif isinstance(padding, (list, tuple)): + pad_h, pad_w = padding[0] * 2, padding[1] * 2 + else: + pad_h = 0 if padding == 'VALID' else kernel_h - 1 + pad_w = 0 if padding == 'VALID' else kernel_w - 1 + pad_top = int(np.ceil(float(pad_h) / 2)) + pad_left = int(np.ceil(float(pad_w) / 2)) + if isinstance(dilation, int): + dilation_h = dilation_w = dilation + else: + dilation_h, dilation_w = dilation + + + def _bilinear(n, c, h, w): + low_h, low_w = int(h), int(w) + high_h = min(low_h + 1, in_height - 1) + high_w = min(low_w + 1, in_width - 1) + y_lerp = h - low_h + x_lerp = w - low_w + + bottom = (1 - x_lerp) * a_np[n, c, low_h, low_w] + x_lerp * a_np[n, c, low_h, high_w] + top = (1 - x_lerp) * a_np[n, c, high_h, low_w] + x_lerp * a_np[n, c, high_h, high_w] + return (1 - y_lerp) * bottom + y_lerp * top + + + a_deform = np.zeros((batch, in_channel, out_height, out_width, kernel_h, kernel_w), dtype=dtype) + for n, h, w in itertools.product(range(batch), range(out_height), range(out_width)): + offset = offset_np[n, :, h, w].reshape(deformable_groups, kernel_h, kernel_w, 2) + in_h = h * stride_h - pad_top + in_w = w * stride_w - pad_left + + index_h_base, index_w_base = np.meshgrid( + np.arange(in_h, in_h + kernel_h * dilation_h, dilation_h, dtype=offset_np.dtype), + np.arange(in_w, in_w + kernel_w * dilation_w, dilation_w, dtype=offset_np.dtype), + indexing='ij') + + for c, kh, kw in itertools.product(range(in_channel), range(kernel_h), range(kernel_w)): + dg = c // ic_per_dgroup + index_h = index_h_base + offset[dg, ..., 0] + index_w = index_w_base + offset[dg, ..., 1] + + y, x = index_h[kh, kw], index_w[kh, kw] + if y < 0 or y >= in_height or x < 0 or x >= in_width: + continue + a_deform[n, c, h, w, kh, kw] = _bilinear(n, c, y, x) + + b_np = np.zeros((batch, out_channel, out_height, out_width), dtype=dtype) + for n, c, f, h, w in itertools.product(range(batch), range(in_channel), range(out_channel), + range(out_height), range(out_width)): + b_np[n, f, h, w] += np.tensordot(a_deform[n, c, h, w], w_np[f, c]) + + return b_np diff --git a/topi/python/topi/testing/depthwise_conv2d_python.py b/topi/python/topi/testing/depthwise_conv2d_python.py index d7baf4a1beaf..566bb93f42a7 100644 --- a/topi/python/topi/testing/depthwise_conv2d_python.py +++ b/topi/python/topi/testing/depthwise_conv2d_python.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable, line-too-long """Depthwise convolution in python""" import numpy as np diff --git a/topi/python/topi/testing/dilate_python.py b/topi/python/topi/testing/dilate_python.py index 89ac2c109fb6..8eaef9280c08 100644 --- a/topi/python/topi/testing/dilate_python.py +++ b/topi/python/topi/testing/dilate_python.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Dilate operation in python""" import numpy as np diff --git a/topi/python/topi/testing/gather_nd_python.py b/topi/python/topi/testing/gather_nd_python.py index e2d74cfee1fd..25c8a9f052f9 100644 --- a/topi/python/topi/testing/gather_nd_python.py +++ b/topi/python/topi/testing/gather_nd_python.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, line-too-long, unused-variable, too-many-locals """gather_nd in python""" import numpy as np diff --git a/topi/python/topi/testing/l2_normalize_python.py b/topi/python/topi/testing/l2_normalize_python.py index 98f1843233a7..c333fa59d142 100644 --- a/topi/python/topi/testing/l2_normalize_python.py +++ b/topi/python/topi/testing/l2_normalize_python.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, line-too-long, unused-variable, too-many-locals """L2 normalize in python""" import numpy as np diff --git a/topi/python/topi/testing/lrn_python.py b/topi/python/topi/testing/lrn_python.py index 4e44e8bcb635..9af662f16d70 100644 --- a/topi/python/topi/testing/lrn_python.py +++ b/topi/python/topi/testing/lrn_python.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, line-too-long, unused-variable, too-many-locals """LRN in python""" from itertools import product diff --git a/topi/python/topi/testing/reorg_python.py b/topi/python/topi/testing/reorg_python.py index 185e5566e5bc..00b1dee8a472 100644 --- a/topi/python/topi/testing/reorg_python.py +++ b/topi/python/topi/testing/reorg_python.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, line-too-long, unused-variable, too-many-locals """Reorg in python""" import numpy as np diff --git a/topi/python/topi/testing/roi_align_python.py b/topi/python/topi/testing/roi_align_python.py index 67866d5901ba..6ba2061abd75 100644 --- a/topi/python/topi/testing/roi_align_python.py +++ b/topi/python/topi/testing/roi_align_python.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, too-many-nested-blocks "Roi align in python" import math diff --git a/topi/python/topi/testing/roi_pool_python.py b/topi/python/topi/testing/roi_pool_python.py index b37d5034d1c0..075d7a9b4e6b 100644 --- a/topi/python/topi/testing/roi_pool_python.py +++ b/topi/python/topi/testing/roi_pool_python.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, too-many-nested-blocks "Roi pool in python" import math diff --git a/topi/python/topi/testing/slice_axis_python.py b/topi/python/topi/testing/slice_axis_python.py index 589e5914a36c..4a8598875177 100644 --- a/topi/python/topi/testing/slice_axis_python.py +++ b/topi/python/topi/testing/slice_axis_python.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Slice axis in python""" def slice_axis_python(data, axis, begin, end=None): diff --git a/topi/python/topi/testing/softmax_python.py b/topi/python/topi/testing/softmax_python.py index 0cdbee1bdc07..119625cc44ef 100644 --- a/topi/python/topi/testing/softmax_python.py +++ b/topi/python/topi/testing/softmax_python.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, trailing-whitespace """Softmax and log_softmax operation in python""" import numpy as np diff --git a/topi/python/topi/testing/strided_slice_python.py b/topi/python/topi/testing/strided_slice_python.py index 4407b3bec1c7..b842da73df78 100644 --- a/topi/python/topi/testing/strided_slice_python.py +++ b/topi/python/topi/testing/strided_slice_python.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """gather_nd in python""" def strided_slice_python(data, begin, end, strides): diff --git a/topi/python/topi/testing/upsampling_python.py b/topi/python/topi/testing/upsampling_python.py index 341dd8f6ceb0..8ee964010c82 100644 --- a/topi/python/topi/testing/upsampling_python.py +++ b/topi/python/topi/testing/upsampling_python.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, line-too-long, unused-variable, too-many-locals """Upsampling in python""" import numpy as np diff --git a/topi/python/topi/transform.py b/topi/python/topi/transform.py index 2c109cd92c52..2ad1f6e10057 100644 --- a/topi/python/topi/transform.py +++ b/topi/python/topi/transform.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name,consider-using-enumerate """Injective transformation operators""" from __future__ import absolute_import as _abs @@ -228,7 +244,7 @@ def split(ary, indices_or_sections, axis=0): return cpp.split(ary, indices_or_sections, axis) -def take(a, indices, axis=None): +def take(a, indices, axis=None, mode="clip"): """Take elements from an array along an axis. Parameters @@ -243,13 +259,18 @@ def take(a, indices, axis=None): The axis over which to select values. By default, the flattened input array is used. + mode : str, optional + Specifies how out-of-bound indices will behave. + clip - clip to the range (default) + wrap - wrap around the indices + Returns ------- ret : tvm.Tensor """ if axis is None: - return cpp.take(a, indices) - return cpp.take(a, indices, int(axis)) + return cpp.take(a, indices, mode) + return cpp.take(a, indices, int(axis), mode) def gather_nd(a, indices): diff --git a/topi/python/topi/util.py b/topi/python/topi/util.py index d630628b4379..f648245c6bb7 100644 --- a/topi/python/topi/util.py +++ b/topi/python/topi/util.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Common topi utilities""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/vision/nms.py b/topi/python/topi/vision/nms.py index 169daea2d4d3..d8b15aac42c6 100644 --- a/topi/python/topi/vision/nms.py +++ b/topi/python/topi/vision/nms.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, no-member, too-many-locals, too-many-arguments, undefined-variable, too-many-nested-blocks, too-many-branches, too-many-statements """Non-maximum suppression operator""" import tvm diff --git a/topi/python/topi/vision/rcnn/proposal.py b/topi/python/topi/vision/rcnn/proposal.py index d9b1f98e2286..1df25a06566d 100644 --- a/topi/python/topi/vision/rcnn/proposal.py +++ b/topi/python/topi/vision/rcnn/proposal.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Proposal operator""" import math diff --git a/topi/python/topi/vision/rcnn/roi_align.py b/topi/python/topi/vision/rcnn/roi_align.py index 760dce10d536..c861ddd50554 100644 --- a/topi/python/topi/vision/rcnn/roi_align.py +++ b/topi/python/topi/vision/rcnn/roi_align.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Roi align operator""" import tvm diff --git a/topi/python/topi/vision/rcnn/roi_pool.py b/topi/python/topi/vision/rcnn/roi_pool.py index 65260864092d..702f551e35eb 100644 --- a/topi/python/topi/vision/rcnn/roi_pool.py +++ b/topi/python/topi/vision/rcnn/roi_pool.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """ROI pool operator""" import tvm diff --git a/topi/python/topi/vision/reorg.py b/topi/python/topi/vision/reorg.py index 9f4fa70a71f6..7adfc73d9be1 100644 --- a/topi/python/topi/vision/reorg.py +++ b/topi/python/topi/vision/reorg.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ REORG Operator ==================== diff --git a/topi/python/topi/vision/ssd/multibox.py b/topi/python/topi/vision/ssd/multibox.py index 2de1723dbd7b..799669003753 100644 --- a/topi/python/topi/vision/ssd/multibox.py +++ b/topi/python/topi/vision/ssd/multibox.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, no-member, too-many-locals, too-many-arguments, undefined-variable """SSD multibox operators""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/x86/batch_matmul.py b/topi/python/topi/x86/batch_matmul.py index 37890e389366..73687606859a 100644 --- a/topi/python/topi/x86/batch_matmul.py +++ b/topi/python/topi/x86/batch_matmul.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name,too-many-locals,unused-variable """x86 batch_matmul operators""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/x86/binarize_pack.py b/topi/python/topi/x86/binarize_pack.py index adf0a714b3fb..ea2bbed7345e 100644 --- a/topi/python/topi/x86/binarize_pack.py +++ b/topi/python/topi/x86/binarize_pack.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """Schedule for binarization and bit-packing.""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/x86/binary_dense.py b/topi/python/topi/x86/binary_dense.py index 4a3da5541efd..483af4fcb927 100644 --- a/topi/python/topi/x86/binary_dense.py +++ b/topi/python/topi/x86/binary_dense.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable, unused-argument """Schedule for binary dense operator.""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/x86/bitserial_conv2d.py b/topi/python/topi/x86/bitserial_conv2d.py index 327f15a49e07..f6570bc716f3 100644 --- a/topi/python/topi/x86/bitserial_conv2d.py +++ b/topi/python/topi/x86/bitserial_conv2d.py @@ -1,74 +1,29 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name,unused-variable,invalid-name """Bitserial conv2d schedule on x86""" import tvm +from tvm import autotvm from topi.util import get_const_int from .. import generic, tag -from ..nn.bitserial_conv2d import bitserial_conv2d, _get_schedule, _get_workload -from ..nn.bitserial_conv2d import SpatialPackNCHW, SpatialPackNHWC -from ..nn.bitserial_conv2d import _WORKLOADS, _SCH_TO_DECL_FUNC_QUANT - -_QUANTIZED_SCHEDULES_NCHW = [ - # resnet - SpatialPackNCHW(2, 2, 8, 1, 1), - SpatialPackNCHW(1, 4, 8, 4, 1), - SpatialPackNCHW(1, 4, 8, 1, 16), - SpatialPackNCHW(1, 4, 8, 4, 8), - SpatialPackNCHW(1, 7, 8, 3, 8), - SpatialPackNCHW(1, 2, 8, 1, 8), - SpatialPackNCHW(2, 1, 8, 1, 4), - SpatialPackNCHW(1, 7, 8, 1, 1), - SpatialPackNCHW(1, 1, 8, 1, 16), - SpatialPackNCHW(1, 1, 8, 1, 8), - SpatialPackNCHW(1, 1, 8, 1, 16), - - SpatialPackNCHW(3, 3, 16, 3, 16), - SpatialPackNCHW(1, 1, 16, 2, 16), - SpatialPackNCHW(1, 1, 8, 1, 16), - SpatialPackNCHW(1, 1, 8, 1, 16), -] - -_QUANTIZED_SCHEDULES_NHWC = [ - # resnet - SpatialPackNHWC(2, 2, 8, 1, 1), - SpatialPackNHWC(1, 4, 8, 4, 1), - SpatialPackNHWC(1, 4, 8, 1, 16), - SpatialPackNHWC(1, 4, 8, 4, 8), - SpatialPackNHWC(1, 7, 8, 3, 8), - SpatialPackNHWC(1, 2, 8, 1, 8), - SpatialPackNHWC(2, 1, 8, 1, 4), - SpatialPackNHWC(1, 7, 8, 1, 1), - SpatialPackNHWC(1, 1, 8, 1, 16), - SpatialPackNHWC(1, 1, 8, 1, 8), - SpatialPackNHWC(1, 1, 8, 1, 16), -] - -@_get_schedule.register("cpu") -def _get_schedule_bitserial_conv2d(wkl, layout): - if wkl not in _WORKLOADS: - raise ValueError("no schedule for such workload: {}".format(wkl)) - idx = _WORKLOADS.index(wkl) - if layout == "NCHW": - sch = _QUANTIZED_SCHEDULES_NCHW[idx] - elif layout == "NHWC": - sch = _QUANTIZED_SCHEDULES_NHWC[idx] - return sch - -@bitserial_conv2d.register("cpu") -def _declaration_bitserial_conv2d(data, kernel, stride, padding, activation_bits, weight_bits, - layout='NCHW', pack_dtype=None, out_dtype=None, dorefa=False): - if out_dtype is None: - out_dtype = data.dtype - assert data.shape[0].value == 1, "only support batch size=1 convolution on rasp" - assert layout in ("NCHW", "NHWC"), "only support layouts NCHW and NHWC" - - wkl = _get_workload(data, kernel, stride, padding, out_dtype, layout) - sch = _get_schedule(wkl, layout) - return _SCH_TO_DECL_FUNC_QUANT[type(sch)](data, kernel, stride, padding, activation_bits, - weight_bits, pack_dtype, out_dtype, dorefa) - -@generic.schedule_bitserial_conv2d_nchw.register(["cpu"]) -@generic.schedule_bitserial_conv2d_nhwc.register(["cpu"]) -def schedule_bitserial_conv2d(outs): + +@autotvm.register_topi_schedule(generic.nn.schedule_bitserial_conv2d_nchw, ['cpu'], 'direct') +@autotvm.register_topi_schedule(generic.nn.schedule_bitserial_conv2d_nhwc, ['cpu'], 'direct') +def schedule_bitserial_conv2d(cfg, outs): """CPU schedule for bitserial convolutions NCHW and NHWC""" s = tvm.create_schedule([x.op for x in outs]) scheduled_ops = [] @@ -88,7 +43,6 @@ def traverse(op): conv_out = op.input_tensors[0] kernel_vec = conv_out.op.input_tensors[1] kernel_q = kernel_vec.op.input_tensors[0] - kernel = kernel_q.op.input_tensors[0] data_vec = conv_out.op.input_tensors[0] data_q = data_vec.op.input_tensors[0] data = data_q.op.input_tensors[0] @@ -97,29 +51,27 @@ def traverse(op): data_pad = data_q data_q = data data = data_q.op.input_tensors[0] - if "QuantizeInput" in kernel.op.name: - # Need to go up 1 further, from the combine in bitpack - kernel = kernel.op.input_tensors[0] + if "QuantizeInput" in data.op.name: # Need to go up 1 further, from the combine in bitpack data = data.op.input_tensors[0] if 'spatial_bitserial_conv_nchw' in op.tag: - _schedule_spatial_conv2d_nchw(s, data, data_q, data_pad, data_vec, - kernel, kernel_q, kernel_vec, - conv_out, output, outs[0]) + _schedule_bitserial_conv2d_nchw(cfg, s, data_q, data_pad, data_vec, + kernel_q, kernel_vec, + conv_out, output, outs[0]) elif 'spatial_bitserial_conv_nhwc' in op.tag: - _schedule_spatial_conv2d_nhwc(s, data, data_q, data_pad, data_vec, - kernel, kernel_q, kernel_vec, - conv_out, output, outs[0]) + _schedule_bitserial_conv2d_nhwc(cfg, s, data_q, data_pad, data_vec, + kernel_q, kernel_vec, + conv_out, output, outs[0]) scheduled_ops.append(op) traverse(outs[0].op) return s -def _schedule_spatial_conv2d_nchw(s, data, data_q, data_pad, data_vec, - kernel, kernel_q, kernel_vec, - conv_out, output, last): +def _schedule_bitserial_conv2d_nchw(cfg, s, data_q, data_pad, data_vec, + kernel_q, kernel_vec, + conv_out, output, last): IB, _, CI, IH, IW = data_q.shape KB, CO, _, KH, KW = kernel_q.shape _, _, OH, OW = output.shape @@ -138,37 +90,21 @@ def _schedule_spatial_conv2d_nchw(s, data, data_q, data_pad, data_vec, wstride = get_const_int((TW - KW) // (OW - 1)) stride = (hstride, wstride) - wkl = _get_workload(data, kernel, stride, padding, output.dtype, "NCHW") - sch = _get_schedule(wkl, "NCHW") - VH = sch.vh - VW = sch.vw - VC = sch.vc - ba = sch.ba - bc = sch.bc - - CC = s.cache_write(conv_out, "global") - n, co, oh, ow, vh, vw, vc = s[conv_out].op.axis - s[conv_out].vectorize(vc) - - s[CC].compute_at(s[conv_out], ow) - n, co, oh, ow, vh, vw, vc = s[CC].op.axis - ci, dh, dw, b1, b2 = s[CC].op.reduce_axis - s[CC].reorder(ci, dh, vh, dw, vw, b1, b2, vc) - s[CC].unroll(b1) - s[CC].unroll(b2) - s[CC].vectorize(vc) + VC = cfg["tile_co"].size[-1] + VH = cfg["tile_oh"].size[-1] + VW = cfg["tile_ow"].size[-1] - ##### Schedule A + ##### Schedule Data padding, and bitpacking if data_pad is not None: s[data_pad].compute_inline() - _, h, _, _, _, _, vw = s[data_vec].op.axis - s[data_vec].vectorize(vw) - if ba == 1: - oaxis = h - paxis = h + _, _, h, _, _, _, _ = s[data_vec].op.axis + cfg.define_split("tile_ah", cfg.axis(h), policy="all", num_outputs=2, max_factor=32) + oh, ih = cfg["tile_ah"].apply(s, data_vec, h) + if cfg["tile_ah"].size[1] == 1: + oaxis = oh + paxis = oh else: - oh, ih = s[data_vec].split(h, ba) oaxis = oh paxis = ih @@ -178,14 +114,14 @@ def _schedule_spatial_conv2d_nchw(s, data, data_q, data_pad, data_vec, s[data_vec].pragma(oaxis, "parallel_barrier_when_finish") - ##### Schedule B - co, _, _, _, _, vc = s[kernel_vec].op.axis - s[kernel_vec].vectorize(vc) - if bc == 1: - oaxis = co - paxis = co + ##### Schedule Kenerl bitpacking + co, _, _, _, _, _ = s[kernel_vec].op.axis + cfg.define_split("tile_bco", cfg.axis(co), policy="all", num_outputs=2, max_factor=32) + oco, ico = cfg["tile_bco"].apply(s, kernel_vec, co) + if cfg["tile_bco"].size[1] == 1: + oaxis = oco + paxis = oco else: - oco, ico = s[kernel_vec].split(co, bc) oaxis = oco paxis = ico @@ -195,7 +131,23 @@ def _schedule_spatial_conv2d_nchw(s, data, data_q, data_pad, data_vec, s[kernel_vec].pragma(oaxis, "parallel_barrier_when_finish") - ##### Schedule C + ##### Schedule Convolution + n, co, oh, ow, vh, vw, vc = s[conv_out].op.axis + ci, dh, dw, ib, kb = s[conv_out].op.reduce_axis + + # s[conv_out].reorder(n, oh, ow, co, vh, vw, dh, dw, ci, vc, b1, b2) + cfg["reorder_0"].apply(s, conv_out, [n, co, oh, ow, vc, vh, vw, dh, dw, kb, ib, ci]) + cfg["ann_reduce"].apply(s, conv_out, [kb, ib, dh, dw], + axis_lens=[get_const_int(kb.dom.extent), + get_const_int(ib.dom.extent), + get_const_int(dh.dom.extent), + get_const_int(dw.dom.extent)], + max_unroll=16, + cfg=cfg) + + s[conv_out].vectorize(vc) + + # # Schedule output n, co, h, w = s[last].op.axis co, vc = s[last].split(co, VC) oh, ow, vh, vw = s[last].tile(h, w, VH, VW) @@ -204,89 +156,58 @@ def _schedule_spatial_conv2d_nchw(s, data, data_q, data_pad, data_vec, s[output].compute_inline() s[conv_out].compute_at(s[last], ow) - if bc == 1: - oaxis = co - paxis = co + oco, ico = cfg["tile_oh"].apply(s, last, co) + if cfg["tile_oh"].size[1] == 1: + oaxis = oco + paxis = oco else: oco, ico = s[last].split(co, bc) oaxis = oco paxis = ico - s[last].parallel(paxis) - s[last].pragma(oaxis, "parallel_launch_point") - s[last].pragma(paxis, "parallel_stride_pattern") - s[last].pragma(oaxis, "parallel_barrier_when_finish") - + s[last].parallel(oco) return s -def _schedule_spatial_conv2d_nhwc(s, data, data_q, data_pad, data_vec, - kernel, kernel_q, kernel_vec, - conv_out, output, last): +def _schedule_bitserial_conv2d_nhwc(cfg, s, data_q, data_pad, data_vec, + kernel_q, kernel_vec, + conv_out, output, last): # no stride and padding info here _, IH, IW, CI, IB = data_q.shape KH, KW, _, CO, KB = kernel_q.shape _, OH, OW, _ = output.shape - # Infer padding and stride - if data_pad is None: - padding = (0, 0) - TH, TW = IH, IW - else: - _, TH, TW, _, _ = data_pad.shape - hpad = get_const_int((TH - IH) // 2) - wpad = get_const_int((TW - IW) // 2) - padding = (hpad, wpad) - hstride = get_const_int((TH - KH) // (OH - 1)) - wstride = get_const_int((TW - KW) // (OW - 1)) - stride = (hstride, wstride) + VC = cfg["tile_co"].size[-1] + VH = cfg["tile_oh"].size[-1] + VW = cfg["tile_ow"].size[-1] - wkl = _get_workload(data, kernel, stride, padding, last.dtype, "NHWC") - sch = _get_schedule(wkl, "NHWC") - VH = sch.vh - VW = sch.vw - VC = sch.vc - ba = sch.ba - bc = sch.bc - - ##### Schedule data packing + ##### Schedule data padding and packing if data_pad is not None: s[data_pad].compute_inline() _, h, _, _, _, _, _ = s[data_vec].op.axis - if ba == 1: - oaxis = h - paxis = h - else: - oh, ih = s[data_vec].split(h, ba) - oaxis = oh - paxis = ih - s[data_vec].parallel(paxis) - s[data_vec].pragma(oaxis, "parallel_launch_point") - s[data_vec].pragma(paxis, "parallel_stride_pattern") - s[data_vec].pragma(oaxis, "parallel_barrier_when_finish") - + cfg.define_split("tile_ah", cfg.axis(h), policy="all", num_outputs=2, max_factor=32) + oh, ih = cfg["tile_ah"].apply(s, data_vec, h) + s[data_vec].parallel(oh) ##### Schedule kernel packing co, _, _, _, _, _ = s[kernel_vec].op.axis - if bc == 1: - oaxis = co - paxis = co - else: - oco, ico = s[kernel_vec].split(co, bc) - oaxis = oco - paxis = ico - - s[kernel_vec].parallel(paxis) - s[kernel_vec].pragma(oaxis, "parallel_launch_point") - s[kernel_vec].pragma(paxis, "parallel_stride_pattern") - s[kernel_vec].pragma(oaxis, "parallel_barrier_when_finish") - + cfg.define_split("tile_bco", cfg.axis(co), policy="all", num_outputs=2, max_factor=32) + oco, ico = cfg["tile_bco"].apply(s, kernel_vec, co) + s[kernel_vec].parallel(oco) ##### Schedule Convolution n, oh, ow, co, vh, vw, vc = s[conv_out].op.axis dh, dw, ci, b1, b2 = s[conv_out].op.reduce_axis - s[conv_out].reorder(n, oh, ow, co, vh, vw, dh, dw, ci, vc, b1, b2) + # s[conv_out].reorder(n, oh, ow, co, vh, vw, dh, dw, ci, vc, b1, b2) + cfg["reorder_0"].apply(s, conv_out, [n, oh, ow, co, vh, vw, dh, dw, ci, vc, b1, b2]) + cfg["ann_reduce"].apply(s, conv_out, [b1, b2, dh, dw], + axis_lens=[get_const_int(b1.dom.extent), + get_const_int(b2.dom.extent), + get_const_int(dh.dom.extent), + get_const_int(dw.dom.extent)], + max_unroll=16, + cfg=cfg) s[conv_out].unroll(b1) s[conv_out].unroll(b2) @@ -302,17 +223,7 @@ def _schedule_spatial_conv2d_nhwc(s, data, data_q, data_pad, data_vec, s[output].compute_inline() s[conv_out].compute_at(s[last], ow) - if bc == 1: - oaxis = oh - paxis = oh - else: - oho, iho = s[last].split(oh, bc) - oaxis = oho - paxis = iho - - s[last].parallel(paxis) - s[last].pragma(oaxis, "parallel_launch_point") - s[last].pragma(paxis, "parallel_stride_pattern") - s[last].pragma(oaxis, "parallel_barrier_when_finish") + oho, iho = cfg["tile_oh"].apply(s, last, oh) # reuse parameter + s[last].parallel(oho) return s diff --git a/topi/python/topi/x86/check_targets.py b/topi/python/topi/x86/check_targets.py index fad74eaf582a..1b929c2ef752 100644 --- a/topi/python/topi/x86/check_targets.py +++ b/topi/python/topi/x86/check_targets.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name,unused-variable,invalid-name,unused-argument """Checks different x86 targets for target specific schedules""" diff --git a/topi/python/topi/x86/conv2d.py b/topi/python/topi/x86/conv2d.py index f7bfc3520b36..5806590d266a 100644 --- a/topi/python/topi/x86/conv2d.py +++ b/topi/python/topi/x86/conv2d.py @@ -1,7 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name,unused-variable,unused-argument,no-member """Conv2D schedule on x86""" import logging +import re import tvm from tvm import autotvm @@ -41,9 +58,22 @@ def _create_tuning_space(cfg, data, kernel, strides, padding, dilation, layout): """Create schedule configuration from input arguments""" dshape = get_const_tuple(data.shape) kshape = get_const_tuple(kernel.shape) + pat = re.compile(r'NCHW.+(\d+)c') if layout == 'NCHW': n, ic, h, w = dshape oc, _, kh, kw = kshape + elif pat.match(layout) is not None: + n, ic_chunk, h, w, ic_bn = dshape + if data.dtype == 'uint8': + oc_chunk, k_ic, kh, kw, k_ic_f, oc_bn, k_ic_s = kshape + ic = ic_chunk*ic_bn + assert ic == k_ic*k_ic_f*kic_s + else: + oc_chunk, k_ic_chunk, kh, kw, k_ic_bn, oc_bn = kshape + assert ic_chunk == k_ic_chunk + assert ic_bn == k_ic_bn + ic = ic_chunk*ic_bn + oc = oc_chunk*oc_bn else: raise ValueError("Not support this layout {} with " "schedule template.".format(layout)) @@ -258,7 +288,14 @@ def traverse(op): @autotvm.task.register("topi_x86_conv2d_NCHWc") def _topi_nn_conv2d_NCHWc(*args, **kwargs): assert not kwargs, "Do not support kwargs in template function call" - data, kernel, strides, padding, dilation, origin_layout, dtype = deserialize_args(args) + args = deserialize_args(args) + + if len(args) == 7: + data, kernel, strides, padding, dilation, origin_layout, dtype = args + else: + assert len(args) == 8 + data, kernel, strides, padding, dilation, origin_layout, out_layout, dtype = args + raw_data_shape = get_const_tuple(data.shape) raw_kernel_shape = get_const_tuple(kernel.shape) diff --git a/topi/python/topi/x86/conv2d_avx_1x1.py b/topi/python/topi/x86/conv2d_avx_1x1.py index d44e3899293d..bcd2cefc2bdf 100644 --- a/topi/python/topi/x86/conv2d_avx_1x1.py +++ b/topi/python/topi/x86/conv2d_avx_1x1.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name,unused-variable,unused-argument,invalid-name """1x1 Conv2D schedule on for Intel CPU""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/x86/conv2d_avx_common.py b/topi/python/topi/x86/conv2d_avx_common.py index 1b8ee5fe9be4..3ab68d71b948 100644 --- a/topi/python/topi/x86/conv2d_avx_common.py +++ b/topi/python/topi/x86/conv2d_avx_common.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name,unused-variable,unused-argument,invalid-name """Conv2D schedule on for Intel CPU""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/x86/dense.py b/topi/python/topi/x86/dense.py index 33575b4c399d..01f3a735f30b 100644 --- a/topi/python/topi/x86/dense.py +++ b/topi/python/topi/x86/dense.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name,too-many-locals,unused-variable """x86 dense operators""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/x86/depthwise_conv2d.py b/topi/python/topi/x86/depthwise_conv2d.py index 3c0673a29a96..f570aaf7e70d 100644 --- a/topi/python/topi/x86/depthwise_conv2d.py +++ b/topi/python/topi/x86/depthwise_conv2d.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name,unused-variable,unused-argument,no-member """Depthwise Conv2D schedule on x86""" import tvm diff --git a/topi/python/topi/x86/injective.py b/topi/python/topi/x86/injective.py index 06847bf9f427..37080e03d8e4 100644 --- a/topi/python/topi/x86/injective.py +++ b/topi/python/topi/x86/injective.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name """x86 declaration and schedules.""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/x86/nn.py b/topi/python/topi/x86/nn.py index 73463242e96d..445bc693b097 100644 --- a/topi/python/topi/x86/nn.py +++ b/topi/python/topi/x86/nn.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name,too-many-locals,unused-variable """x86 nn operators""" from __future__ import absolute_import as _abs diff --git a/topi/python/topi/x86/pooling.py b/topi/python/topi/x86/pooling.py index 5fce5f32afb6..4cf213aac86d 100644 --- a/topi/python/topi/x86/pooling.py +++ b/topi/python/topi/x86/pooling.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # pylint: disable=invalid-name, unused-variable """Schedule for pooling operators""" import tvm diff --git a/topi/python/topi/x86/tensor_intrin.py b/topi/python/topi/x86/tensor_intrin.py index 28e57f1c10f8..48fa75d81c9b 100644 --- a/topi/python/topi/x86/tensor_intrin.py +++ b/topi/python/topi/x86/tensor_intrin.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Core kernel of dot product of 4 Int8 operations""" #pylint: disable=invalid-name import tvm diff --git a/topi/python/topi/x86/util.py b/topi/python/topi/x86/util.py index 678ff8e24cff..f0b3c755e1e2 100644 --- a/topi/python/topi/x86/util.py +++ b/topi/python/topi/x86/util.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Common x86 related utilities""" from __future__ import absolute_import as _abs import tvm diff --git a/topi/recipe/broadcast/test_broadcast_map.py b/topi/recipe/broadcast/test_broadcast_map.py index 11a4a34647db..4f8a4dece2c5 100644 --- a/topi/recipe/broadcast/test_broadcast_map.py +++ b/topi/recipe/broadcast/test_broadcast_map.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import os import tvm from tvm.contrib import nvcc diff --git a/topi/recipe/conv/depthwise_conv2d_test.py b/topi/recipe/conv/depthwise_conv2d_test.py index cce36517a5ea..0cfa42d931ef 100644 --- a/topi/recipe/conv/depthwise_conv2d_test.py +++ b/topi/recipe/conv/depthwise_conv2d_test.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import os import tvm import numpy as np diff --git a/topi/recipe/conv/test_conv2d_hwcn_map.py b/topi/recipe/conv/test_conv2d_hwcn_map.py index c92dcc5d8fe7..80dc11620842 100644 --- a/topi/recipe/conv/test_conv2d_hwcn_map.py +++ b/topi/recipe/conv/test_conv2d_hwcn_map.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Example code to do convolution.""" import os import numpy as np diff --git a/topi/recipe/conv/test_conv_int8_intel.py b/topi/recipe/conv/test_conv_int8_intel.py index 593f913db15d..df4a41cfe6d5 100644 --- a/topi/recipe/conv/test_conv_int8_intel.py +++ b/topi/recipe/conv/test_conv_int8_intel.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. #pylint: disable-msg=too-many-arguments, too-many-locals, assignment-from-no-return """ Conv Int8 functional and performance testing""" import sys diff --git a/topi/recipe/gemm/android_gemm_square.py b/topi/recipe/gemm/android_gemm_square.py index 361c56f636b2..46129cbc1f30 100644 --- a/topi/recipe/gemm/android_gemm_square.py +++ b/topi/recipe/gemm/android_gemm_square.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Example code to do square matrix multiplication on Android Phone.""" import tvm import os diff --git a/topi/recipe/gemm/cuda_gemm_square.py b/topi/recipe/gemm/cuda_gemm_square.py index 2a47e22e0b59..899379e9e488 100644 --- a/topi/recipe/gemm/cuda_gemm_square.py +++ b/topi/recipe/gemm/cuda_gemm_square.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Example code to do square matrix multiplication.""" import tvm import os diff --git a/topi/recipe/gemm/gemm_int8.py b/topi/recipe/gemm/gemm_int8.py index 43029094a25c..cf3621479d41 100644 --- a/topi/recipe/gemm/gemm_int8.py +++ b/topi/recipe/gemm/gemm_int8.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. "Example code to perform int8 GEMM" import logging import sys diff --git a/topi/recipe/reduce/test_reduce_map.py b/topi/recipe/reduce/test_reduce_map.py index 5fadf10d94f9..1adc41374f9c 100644 --- a/topi/recipe/reduce/test_reduce_map.py +++ b/topi/recipe/reduce/test_reduce_map.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import os import tvm from tvm.contrib import nvcc diff --git a/topi/recipe/rnn/lstm.py b/topi/recipe/rnn/lstm.py index f627d6ce8f8e..0d7635d08288 100644 --- a/topi/recipe/rnn/lstm.py +++ b/topi/recipe/rnn/lstm.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """LSTM Example, still work in progress..""" import tvm import os diff --git a/topi/recipe/rnn/matexp.py b/topi/recipe/rnn/matexp.py index dddadb8ba5f3..7466008d81e3 100644 --- a/topi/recipe/rnn/matexp.py +++ b/topi/recipe/rnn/matexp.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Matrix exponential example. This is an example for matrix exponential, diff --git a/topi/src/topi.cc b/topi/src/topi.cc index aed2eab9c6bc..47e999c74587 100644 --- a/topi/src/topi.cc +++ b/topi/src/topi.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \brief Registration of TVM operators and schedules @@ -297,11 +316,13 @@ TVM_REGISTER_GLOBAL("topi.layout_transform") TVM_REGISTER_GLOBAL("topi.take") .set_body([](TVMArgs args, TVMRetValue *rv) { - if (args.size() == 2) { - *rv = take(args[0], args[1]); + if (args.size() == 3) { + std::string mode = args[2]; + *rv = take(args[0], args[1], mode); } else { int axis = args[2]; - *rv = take(args[0], args[1], axis); + std::string mode = args[3]; + *rv = take(args[0], args[1], axis, mode); } }); diff --git a/topi/tests/python/common.py b/topi/tests/python/common.py index f34f3b331fd1..d814c7a4012a 100644 --- a/topi/tests/python/common.py +++ b/topi/tests/python/common.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Common utility for topi test""" from tvm import autotvm diff --git a/topi/tests/python/test_topi_basic.py b/topi/tests/python/test_topi_basic.py index 077331cd6d1a..d18bbe537da1 100644 --- a/topi/tests/python/test_topi_basic.py +++ b/topi/tests/python/test_topi_basic.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import topi from topi import util diff --git a/topi/tests/python/test_topi_batch_matmul.py b/topi/tests/python/test_topi_batch_matmul.py index f699d6aa8dcb..d1f50c86464b 100644 --- a/topi/tests/python/test_topi_batch_matmul.py +++ b/topi/tests/python/test_topi_batch_matmul.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test code for batch_matmul operator""" import numpy as np import tvm diff --git a/topi/tests/python/test_topi_bitserial_conv2d.py b/topi/tests/python/test_topi_bitserial_conv2d.py index 6979cf1ce437..eeaeed15df1c 100644 --- a/topi/tests/python/test_topi_bitserial_conv2d.py +++ b/topi/tests/python/test_topi_bitserial_conv2d.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import tvm import topi @@ -10,17 +26,17 @@ def generate_quantized_np(shape, bits, out_dtype): max_val = 1 << bits return np.random.randint(min_val, max_val, size=shape).astype(out_dtype) -def verify_bitserial_conv2d_nchw(batch, in_size, in_channel, num_filter, kernel, stride, padding, - activation_bits, weight_bits, dorefa): +def verify_bitserial_conv2d_nchw(batch, in_size, in_channel, num_filter, kernel, stride, padding, + activation_bits, weight_bits, unipolar): in_height = in_width = in_size - input_type = 'uint32' + input_dtype = 'uint32' out_dtype = 'int32' with tvm.target.create('llvm'): - A = tvm.placeholder((batch, in_channel, in_height, in_width), dtype=input_type, name='A') - W = tvm.placeholder((num_filter, in_channel, kernel, kernel), dtype=input_type, name='W') - B = topi.nn.bitserial_conv2d(A, W, stride, padding, activation_bits, weight_bits, - out_dtype=out_dtype, layout="NCHW", dorefa=dorefa) + A = tvm.placeholder((batch, in_channel, in_height, in_width), dtype=input_dtype, name='A') + W = tvm.placeholder((num_filter, in_channel, kernel, kernel), dtype=input_dtype, name='W') + B = topi.nn.bitserial_conv2d_nchw(A, W, stride, padding, activation_bits, weight_bits, + out_dtype=out_dtype, unipolar=unipolar) s = topi.generic.schedule_bitserial_conv2d_nchw([B]) a_shape = get_const_tuple(A.shape) @@ -28,9 +44,9 @@ def verify_bitserial_conv2d_nchw(batch, in_size, in_channel, num_filter, kernel, @memoize("topi.tests.test_topi_bitseral_conv2d_nchw") def get_ref_data(): - a_np = generate_quantized_np(get_const_tuple(a_shape), activation_bits, input_type) - w_np = generate_quantized_np(get_const_tuple(w_shape), weight_bits, input_type) - if dorefa: + a_np = generate_quantized_np(get_const_tuple(a_shape), activation_bits, input_dtype) + w_np = generate_quantized_np(get_const_tuple(w_shape), weight_bits, input_dtype) + if unipolar: w_ = np.copy(w_np).astype(out_dtype) for x in np.nditer(w_, op_flags=['readwrite']): x[...] = 1 if x == 1 else -1 @@ -48,17 +64,17 @@ def get_ref_data(): func(a, w, b) tvm.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) -def verify_bitserial_conv2d_nhwc(batch, in_size, in_channel, num_filter, kernel, stride, padding, - activation_bits, weight_bits, dorefa): +def verify_bitserial_conv2d_nhwc(batch, in_size, in_channel, num_filter, kernel, stride, padding, + activation_bits, weight_bits, unipolar): in_height = in_width = in_size - input_type='uint32' + input_dtype='uint32' out_dtype='int32' with tvm.target.create('llvm'): - A = tvm.placeholder((batch, in_height, in_width, in_channel), dtype=input_type, name='A') - W = tvm.placeholder((kernel, kernel, in_channel, num_filter), dtype=input_type, name='W') - B = topi.nn.bitserial_conv2d(A, W, stride, padding, activation_bits, weight_bits, out_dtype=out_dtype, - layout="NHWC", dorefa=dorefa) + A = tvm.placeholder((batch, in_height, in_width, in_channel), dtype=input_dtype, name='A') + W = tvm.placeholder((kernel, kernel, in_channel, num_filter), dtype=input_dtype, name='W') + B = topi.nn.bitserial_conv2d_nhwc(A, W, stride, padding, activation_bits, weight_bits, + out_dtype=out_dtype, unipolar=unipolar) s = topi.generic.schedule_bitserial_conv2d_nhwc([B]) a_shape = get_const_tuple(A.shape) @@ -66,9 +82,9 @@ def verify_bitserial_conv2d_nhwc(batch, in_size, in_channel, num_filter, kernel, @memoize("topi.tests.test_topi_bitseral_conv2d_nhwc") def get_ref_data(): - a_np = generate_quantized_np(get_const_tuple(a_shape), activation_bits, input_type) - w_np = generate_quantized_np(get_const_tuple(w_shape), weight_bits, input_type) - if dorefa: + a_np = generate_quantized_np(get_const_tuple(a_shape), activation_bits, input_dtype) + w_np = generate_quantized_np(get_const_tuple(w_shape), weight_bits, input_dtype) + if unipolar: w_ = np.copy(w_np).astype(out_dtype) for x in np.nditer(w_, op_flags=['readwrite']): x[...] = 1 if x == 1 else -1 diff --git a/topi/tests/python/test_topi_bitserial_conv2d_rasp.py b/topi/tests/python/test_topi_bitserial_conv2d_rasp.py index de467818d37f..1b2f40de1b21 100644 --- a/topi/tests/python/test_topi_bitserial_conv2d_rasp.py +++ b/topi/tests/python/test_topi_bitserial_conv2d_rasp.py @@ -1,9 +1,26 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import os import re import numpy as np import tvm import topi import topi.testing +from topi.util import get_const_tuple def generate_quantized_np(shape, bits, out_dtype): np.random.seed(0) @@ -12,21 +29,22 @@ def generate_quantized_np(shape, bits, out_dtype): return np.random.randint(min_val, max_val, size=shape).astype(out_dtype) # Verify that certain special instructions from the tensorize pass exist -def verify_bitserial_conv2d_nhwc(batch, in_size, in_channel, num_filter, kernel, stride, padding, - activation_bits, weight_bits, dorefa): +def verify_bitserial_conv2d_nhwc(batch, in_size, in_channel, num_filter, kernel, stride, padding, + activation_bits, weight_bits, unipolar): in_height = in_width = in_size input_type = 'uint32' - out_dtype = 'int32' + out_dtype = 'int16' - with tvm.target.arm_cpu('rasp3b'): + device = 'llvm -device=arm_cpu -model=bcm2837 -target=armv7l-linux-gnueabihf -mattr=+neon' + with tvm.target.create(device): A = tvm.placeholder((batch, in_height, in_width, in_channel), dtype=input_type, name='A') W = tvm.placeholder((kernel, kernel, in_channel, num_filter), dtype=input_type, name='W') - B = topi.nn.bitserial_conv2d(A, W, stride, padding, activation_bits, weight_bits, out_dtype=out_dtype, - layout="NHWC", dorefa=dorefa) + B = topi.nn.bitserial_conv2d_nhwc(A, W, stride, padding, activation_bits, weight_bits, + pack_dtype='uint8', out_dtype='int16', unipolar=unipolar) s = topi.generic.schedule_bitserial_conv2d_nhwc([B]) - func = tvm.build(s, [A, W, B], tvm.target.arm_cpu('rasp3b')) - + func = tvm.build(s, [A, W, B], device) + assembly = func.get_source('asm') matches = re.findall("vpadal", assembly) assert (len(matches) > 0) @@ -35,6 +53,33 @@ def verify_bitserial_conv2d_nhwc(batch, in_size, in_channel, num_filter, kernel, matches = re.findall("vpadd", assembly) assert (len(matches) > 0) + ctx = tvm.context(device, 0) + if 'arm' not in os.uname()[4]: + print ("Skipped running code, not an arm device") + return + + print("Running on target: %s" % device) + + def get_ref_data(): + a_np = generate_quantized_np(get_const_tuple(A.shape), activation_bits, input_type) + w_np = generate_quantized_np(get_const_tuple(W.shape), weight_bits, input_type) + if unipolar: + w_ = np.copy(w_np).astype(out_dtype) + for x in np.nditer(w_, op_flags=['readwrite']): + x[...] = 1 if x == 1 else -1 + b_np = topi.testing.conv2d_nhwc_python(a_np, w_, stride, padding).astype(out_dtype) + else: + b_np = topi.testing.conv2d_nhwc_python(a_np, w_np, stride, padding).astype(out_dtype) + return a_np, w_np, b_np + a_np, w_np, b_np = get_ref_data() + a = tvm.nd.array(a_np, ctx) + w = tvm.nd.array(w_np, ctx) + b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=B.dtype), ctx) + func = tvm.build(s, [A, W, B], device) + + func(a, w, b) + np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) + def test_bitserial_conv2d(): in_size = 56 ic, oc = 64, 64 @@ -45,6 +90,9 @@ def test_bitserial_conv2d(): verify_bitserial_conv2d_nhwc(1, in_size, ic, oc, k, stride, pad, 1, 1, False) verify_bitserial_conv2d_nhwc(1, in_size, ic, oc, k, stride, pad, 2, 1, False) + verify_bitserial_conv2d_nhwc(1, in_size, ic, oc, k, stride, pad, 1, 1, True) + verify_bitserial_conv2d_nhwc(1, in_size, ic, oc, k, stride, pad, 2, 1, True) + if __name__ == "__main__": test_bitserial_conv2d() diff --git a/topi/tests/python/test_topi_bnn.py b/topi/tests/python/test_topi_bnn.py index 7d132bfff0fe..13da6af9eb02 100644 --- a/topi/tests/python/test_topi_bnn.py +++ b/topi/tests/python/test_topi_bnn.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test code for binary neural network operators.""" import numpy as np import tvm diff --git a/topi/tests/python/test_topi_broadcast.py b/topi/tests/python/test_topi_broadcast.py index 3be938852fdf..3701630be412 100644 --- a/topi/tests/python/test_topi_broadcast.py +++ b/topi/tests/python/test_topi_broadcast.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test code for broadcasting operators.""" from common import get_all_backend import numpy as np diff --git a/topi/tests/python/test_topi_clip.py b/topi/tests/python/test_topi_clip.py index 128a45c46f60..585374f33a64 100644 --- a/topi/tests/python/test_topi_clip.py +++ b/topi/tests/python/test_topi_clip.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test code for clip operator""" import numpy as np import tvm diff --git a/topi/tests/python/test_topi_conv2d_NCHWc.py b/topi/tests/python/test_topi_conv2d_NCHWc.py index 73c1fdae2d66..5aca0c00c4d6 100644 --- a/topi/tests/python/test_topi_conv2d_NCHWc.py +++ b/topi/tests/python/test_topi_conv2d_NCHWc.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test for NCHW[x]c convolution""" import numpy as np diff --git a/topi/tests/python/test_topi_conv2d_hwcn.py b/topi/tests/python/test_topi_conv2d_hwcn.py index 1af7fa4938dd..297df827b542 100644 --- a/topi/tests/python/test_topi_conv2d_hwcn.py +++ b/topi/tests/python/test_topi_conv2d_hwcn.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Example code to do convolution.""" import os import numpy as np diff --git a/topi/tests/python/test_topi_conv2d_int8.py b/topi/tests/python/test_topi_conv2d_int8.py index 272a72f82619..b76c1af1353c 100644 --- a/topi/tests/python/test_topi_conv2d_int8.py +++ b/topi/tests/python/test_topi_conv2d_int8.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Example code to do convolution.""" import numpy as np diff --git a/topi/tests/python/test_topi_conv2d_nchw.py b/topi/tests/python/test_topi_conv2d_nchw.py index c0dc1953d2c2..ca1cef22d9c8 100644 --- a/topi/tests/python/test_topi_conv2d_nchw.py +++ b/topi/tests/python/test_topi_conv2d_nchw.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Example code to do convolution.""" import numpy as np @@ -136,7 +152,8 @@ def test_conv2d_nchw(): verify_conv2d_nchw(1, 128, 17, 128, 7, 1, 3) verify_conv2d_nchw(1, 128, 17, 192, 1, 1, 0) verify_conv2d_nchw(1, 768, 17, 160, 1, 1, 0) - verify_conv2d_nchw(1, 160, 17, 160, 1, 1, 0) + # disable these tests due to some bugs of llvm with nvptx + # verify_conv2d_nchw(1, 160, 17, 160, 1, 1, 0) verify_conv2d_nchw(1, 160, 17, 192, 7, 1, 3) verify_conv2d_nchw(1, 160, 17, 160, 7, 1, 3) verify_conv2d_nchw(1, 160, 17, 192, 1, 1, 0) diff --git a/topi/tests/python/test_topi_conv2d_nhwc.py b/topi/tests/python/test_topi_conv2d_nhwc.py index af55f5bc172c..d53748c590c7 100644 --- a/topi/tests/python/test_topi_conv2d_nhwc.py +++ b/topi/tests/python/test_topi_conv2d_nhwc.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Example code to do convolution.""" import os import numpy as np diff --git a/topi/tests/python/test_topi_conv2d_transpose_nchw.py b/topi/tests/python/test_topi_conv2d_transpose_nchw.py index 296772f4e9f5..1a2d779ac28b 100644 --- a/topi/tests/python/test_topi_conv2d_transpose_nchw.py +++ b/topi/tests/python/test_topi_conv2d_transpose_nchw.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test code for transposed convolution.""" import numpy as np import tvm diff --git a/topi/tests/python/test_topi_conv2d_winograd.py b/topi/tests/python/test_topi_conv2d_winograd.py index a76c9c62e008..b68ea4609fdb 100644 --- a/topi/tests/python/test_topi_conv2d_winograd.py +++ b/topi/tests/python/test_topi_conv2d_winograd.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Example code to do convolution.""" import numpy as np diff --git a/topi/tests/python/test_topi_deformable_conv2d.py b/topi/tests/python/test_topi_deformable_conv2d.py new file mode 100644 index 000000000000..45222b6bd489 --- /dev/null +++ b/topi/tests/python/test_topi_deformable_conv2d.py @@ -0,0 +1,88 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +import numpy as np +import tvm +from tvm import autotvm +import topi +import topi.testing +from tvm.contrib.pickle_memoize import memoize +from topi.util import get_const_tuple + +from common import get_all_backend + + +def verify_deformable_conv2d_nchw(batch, in_channel, in_size, num_filter, kernel, stride, padding, dilation=1, deformable_groups=1, groups=1): + print("Workload: (%d, %d, %d, %d, %d, %d, %d, %d, %d, %d)" % (batch, in_channel, in_size, + num_filter, kernel, stride, padding, dilation, deformable_groups, groups)) + + A = tvm.placeholder((batch, in_channel, in_size, in_size), name='A') + out_size = (in_size - (kernel - 1) * dilation - 1 + 2 * padding) // stride + 1 + Offset = tvm.placeholder((batch, deformable_groups * kernel * kernel * 2, out_size, out_size), name='offset') + W = tvm.placeholder((num_filter, in_channel, kernel, kernel), name='W') + bias = tvm.placeholder((num_filter, 1, 1), name='bias') + + a_shape = get_const_tuple(A.shape) + offset_shape = get_const_tuple(Offset.shape) + w_shape = get_const_tuple(W.shape) + bias_shape = get_const_tuple(bias.shape) + dtype = A.dtype + + @memoize("topi.tests.test_topi_deformable_conv2d_nchw.verify_deformable_conv2d_nchw") + def get_ref_data(): + a_np = np.random.uniform(size=a_shape).astype(dtype) + offset_np = np.random.randn(*offset_shape).astype(dtype) + w_np = np.random.uniform(size=w_shape).astype(dtype) + b_np = np.random.uniform(size=bias_shape).astype(dtype) + c_np = topi.testing.deformable_conv2d_nchw_python(a_np, offset_np, w_np, stride, padding, + dilation, deformable_groups, groups) + + return a_np, offset_np, w_np, c_np + + a_np, offset_np, w_np, c_np = get_ref_data() + + def check_device(device): + ctx = tvm.context(device, 0) + if not ctx.exist: + print("Skip because %s is not enabled" % device) + return + print("Running on target: %s" % device) + with tvm.target.create(device): + C = topi.nn.deformable_conv2d_nchw(A, Offset, W, stride, padding, dilation, + deformable_groups, groups, out_dtype=dtype) + s = topi.generic.schedule_deformable_conv2d_nchw([C]) + + a = tvm.nd.array(a_np, ctx) + offset = tvm.nd.array(offset_np, ctx) + w = tvm.nd.array(w_np, ctx) + c = tvm.nd.empty(c_np.shape, dtype=c_np.dtype, ctx=ctx) + + func = tvm.build(s, [A, Offset, W, C], device) + func(a, offset, w, c) + tvm.testing.assert_allclose(c.asnumpy(), c_np, rtol=1e-5) + + for device in ['llvm', 'cuda']: + check_device(device) + + +def test_deformable_conv2d_nchw(): + verify_deformable_conv2d_nchw(1, 16, 7, 16, 1, 1, 0, deformable_groups=4) + verify_deformable_conv2d_nchw(1, 16, 7, 16, 3, 1, 1, dilation=2, deformable_groups=4) + verify_deformable_conv2d_nchw(1, 16, 7, 16, 3, 1, 2, dilation=2) + + +if __name__ == "__main__": + test_deformable_conv2d_nchw() diff --git a/topi/tests/python/test_topi_dense.py b/topi/tests/python/test_topi_dense.py index d9202661096b..cf386e45aa71 100644 --- a/topi/tests/python/test_topi_dense.py +++ b/topi/tests/python/test_topi_dense.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test code for dense operator""" import numpy as np import tvm diff --git a/topi/tests/python/test_topi_depthwise_conv2d.py b/topi/tests/python/test_topi_depthwise_conv2d.py index 42db236308dd..d34d56e7fc86 100644 --- a/topi/tests/python/test_topi_depthwise_conv2d.py +++ b/topi/tests/python/test_topi_depthwise_conv2d.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm from tvm import autotvm import topi diff --git a/topi/tests/python/test_topi_depthwise_conv2d_back_input.py b/topi/tests/python/test_topi_depthwise_conv2d_back_input.py index 78b01ef42167..ad44429612ce 100644 --- a/topi/tests/python/test_topi_depthwise_conv2d_back_input.py +++ b/topi/tests/python/test_topi_depthwise_conv2d_back_input.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import topi import numpy as np diff --git a/topi/tests/python/test_topi_depthwise_conv2d_back_weight.py b/topi/tests/python/test_topi_depthwise_conv2d_back_weight.py index 50838a7c863f..2e09e675c502 100644 --- a/topi/tests/python/test_topi_depthwise_conv2d_back_weight.py +++ b/topi/tests/python/test_topi_depthwise_conv2d_back_weight.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import topi import topi.testing diff --git a/topi/tests/python/test_topi_dilate.py b/topi/tests/python/test_topi_dilate.py index d1e157f5e52f..24988212e52a 100644 --- a/topi/tests/python/test_topi_dilate.py +++ b/topi/tests/python/test_topi_dilate.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import topi import topi.testing diff --git a/topi/tests/python/test_topi_group_conv2d.py b/topi/tests/python/test_topi_group_conv2d.py index c1ff656fcd93..5116db29e740 100644 --- a/topi/tests/python/test_topi_group_conv2d.py +++ b/topi/tests/python/test_topi_group_conv2d.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Example code to do group convolution.""" import numpy as np diff --git a/topi/tests/python/test_topi_l2norm.py b/topi/tests/python/test_topi_l2norm.py index 2bf799407398..e57cf0bfe946 100644 --- a/topi/tests/python/test_topi_l2norm.py +++ b/topi/tests/python/test_topi_l2norm.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test code for L2 normalization""" import numpy as np import tvm diff --git a/topi/tests/python/test_topi_lrn.py b/topi/tests/python/test_topi_lrn.py index 2f96a86f164e..3407c6b26f56 100644 --- a/topi/tests/python/test_topi_lrn.py +++ b/topi/tests/python/test_topi_lrn.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test code for local response normalization""" import numpy as np import tvm diff --git a/topi/tests/python/test_topi_math.py b/topi/tests/python/test_topi_math.py index f2f2471c868f..42e3e68a2db9 100644 --- a/topi/tests/python/test_topi_math.py +++ b/topi/tests/python/test_topi_math.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import tvm import topi diff --git a/topi/tests/python/test_topi_matmul.py b/topi/tests/python/test_topi_matmul.py index 2a8eaeb608dd..c712970945fc 100644 --- a/topi/tests/python/test_topi_matmul.py +++ b/topi/tests/python/test_topi_matmul.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import numpy as np import tvm import topi diff --git a/topi/tests/python/test_topi_pooling.py b/topi/tests/python/test_topi_pooling.py index 273320fce727..36dcd0fc2b2e 100644 --- a/topi/tests/python/test_topi_pooling.py +++ b/topi/tests/python/test_topi_pooling.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test code for pooling""" import numpy as np import tvm diff --git a/topi/tests/python/test_topi_reduce.py b/topi/tests/python/test_topi_reduce.py index 77a33d86ed3e..1882cbd7f896 100644 --- a/topi/tests/python/test_topi_reduce.py +++ b/topi/tests/python/test_topi_reduce.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test code for reduce.""" import os import numpy as np diff --git a/topi/tests/python/test_topi_relu.py b/topi/tests/python/test_topi_relu.py index 5aa9c1ee57a0..5c41647846cb 100644 --- a/topi/tests/python/test_topi_relu.py +++ b/topi/tests/python/test_topi_relu.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test code for relu activation""" import os import numpy as np diff --git a/topi/tests/python/test_topi_reorg.py b/topi/tests/python/test_topi_reorg.py index 339cafe3ba41..4edb0a195e22 100644 --- a/topi/tests/python/test_topi_reorg.py +++ b/topi/tests/python/test_topi_reorg.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Example code to do reorg.""" import numpy as np import topi diff --git a/topi/tests/python/test_topi_resize.py b/topi/tests/python/test_topi_resize.py index 80966b15ddbe..26a5e3549de7 100644 --- a/topi/tests/python/test_topi_resize.py +++ b/topi/tests/python/test_topi_resize.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test code for bilinear scale """ import numpy as np import tvm diff --git a/topi/tests/python/test_topi_softmax.py b/topi/tests/python/test_topi_softmax.py index 649251bc3adb..4836eef07508 100644 --- a/topi/tests/python/test_topi_softmax.py +++ b/topi/tests/python/test_topi_softmax.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test code for softmax""" import os import numpy as np diff --git a/topi/tests/python/test_topi_sparse.py b/topi/tests/python/test_topi_sparse.py index 16a5ad33f201..e0c8eec7c28c 100644 --- a/topi/tests/python/test_topi_sparse.py +++ b/topi/tests/python/test_topi_sparse.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test code for sparse operator""" import numpy as np import tvm diff --git a/topi/tests/python/test_topi_tensor.py b/topi/tests/python/test_topi_tensor.py index f54472716521..ccf886e552ee 100644 --- a/topi/tests/python/test_topi_tensor.py +++ b/topi/tests/python/test_topi_tensor.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test code for tensor operator""" import numpy as np import tvm diff --git a/topi/tests/python/test_topi_transform.py b/topi/tests/python/test_topi_transform.py index 59c1090480c2..a078eacae85b 100644 --- a/topi/tests/python/test_topi_transform.py +++ b/topi/tests/python/test_topi_transform.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test code for broadcasting operators.""" import numpy as np import tvm @@ -232,16 +248,16 @@ def check_device(device): for device in ["llvm", "cuda", "opencl", "sdaccel", "aocl_sw_emu"]: check_device(device) -def verify_take(src_shape, indices_src, axis=None): +def verify_take(src_shape, indices_src, axis=None, mode="clip"): src_dtype = "float32" indices_dtype = "int32" indices_src = np.array(indices_src, dtype=indices_dtype) A = tvm.placeholder(shape=src_shape, dtype=src_dtype, name="A") indices = tvm.placeholder(shape=indices_src.shape, dtype=indices_dtype, name="indices") if axis is None: - out_tensor = topi.take(a=A, indices=indices) + out_tensor = topi.take(a=A, indices=indices, mode=mode) else: - out_tensor = topi.take(a=A, indices=indices, axis=axis) + out_tensor = topi.take(a=A, indices=indices, axis=axis, mode=mode) def check_device(device): ctx = tvm.context(device, 0) @@ -259,9 +275,9 @@ def check_device(device): data_npy = np.arange(shape_size, dtype=src_dtype).reshape((src_shape)) if axis is None: - out_npys = np.take(data_npy, indices_src) + out_npys = np.take(data_npy, indices_src, mode=mode) else: - out_npys = np.take(data_npy, indices_src, axis=axis) + out_npys = np.take(data_npy, indices_src, axis=axis, mode=mode) data_nd = tvm.nd.array(data_npy, ctx) indices_nd = tvm.nd.array(indices_src, ctx) out_nd = tvm.nd.empty(out_npys.shape, ctx=ctx, dtype=src_dtype) @@ -498,6 +514,12 @@ def test_take(): verify_take((2,2), [[[1,0],[0,1]]], 0) verify_take((2,2), [[[1,0],[0,1]]], 1) verify_take((4,3,5,6), [[2,1,0,0]], -2) + verify_take((3,4), [-5, 20]) + verify_take((3,4), [-5, 20], mode="wrap") + verify_take((3,4), [-1, 2], axis=0) + verify_take((3,4), [-1, 2], axis=0, mode="wrap") + verify_take((3,4), [-1, 2], axis=1) + verify_take((3,4), [-1, 2], axis=1, mode="wrap") def test_gather_nd(): for indices_dtype in ['int32', 'float32']: diff --git a/topi/tests/python/test_topi_upsampling.py b/topi/tests/python/test_topi_upsampling.py index 60f6e5655fff..0838f02303f6 100644 --- a/topi/tests/python/test_topi_upsampling.py +++ b/topi/tests/python/test_topi_upsampling.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test code for upsampling""" import numpy as np import tvm diff --git a/topi/tests/python/test_topi_vision.py b/topi/tests/python/test_topi_vision.py index 5cb5ead4daae..6bb57b541c88 100644 --- a/topi/tests/python/test_topi_vision.py +++ b/topi/tests/python/test_topi_vision.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test code for vision package""" from __future__ import print_function import math diff --git a/tutorials/autotvm/tune_conv2d_cuda.py b/tutorials/autotvm/tune_conv2d_cuda.py index 347aa4207c9b..1783a16258a9 100644 --- a/tutorials/autotvm/tune_conv2d_cuda.py +++ b/tutorials/autotvm/tune_conv2d_cuda.py @@ -1,9 +1,25 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Tuning High Performance Convolution on NVIDIA GPUs ========================================================================= **Author**: `Lianmin Zheng `_ -This is an advanced tutorial for writing high performance tunable template for +This is an advanced tutorial for writing high performance tunable template for NVIDIA GPU. By running auto-tuner on this template, we can outperform the vendor provided library CuDNN in many cases. """ @@ -41,18 +57,18 @@ ###################################################################### # Step 1: Define the search space # -------------------------------- -# There are plenty of useful schedule primitives in tvm. You can also find -# some tutorials that describe them in more details, such as +# There are plenty of useful schedule primitives in tvm. You can also find +# some tutorials that describe them in more details, such as # (1). :ref:`opt-conv-gpu` # (2). `Optimizing DepthwiseConv on NVIDIA GPU `_ -# +# # However, their implementations are manually tuned for some special input # shapes. In this section, we build a large enough space to cover # the techniques used in these tutorials. Then we rely on the efficient auto-tuner # to search through this space and pick some good configurations. -# +# # If you are familiar with writing cuda schedule, you can find the following -# template is very general. Actually this template can be easily modified +# template is very general. Actually this template can be easily modified # to tune other operators such as depthwise convolution and gemm. # In order to fully understand this template, you should be familiar with # the schedule primitives and auto tuning API. You can refer to the above diff --git a/tutorials/autotvm/tune_relay_arm.py b/tutorials/autotvm/tune_relay_arm.py index b56cb1f1dd42..0f5ab8237461 100644 --- a/tutorials/autotvm/tune_relay_arm.py +++ b/tutorials/autotvm/tune_relay_arm.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Auto-tuning a convolutional network for ARM CPU =============================================== diff --git a/tutorials/autotvm/tune_relay_cuda.py b/tutorials/autotvm/tune_relay_cuda.py index b0675ad502db..f8ef71996ff4 100644 --- a/tutorials/autotvm/tune_relay_cuda.py +++ b/tutorials/autotvm/tune_relay_cuda.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Auto-tuning a convolutional network for NVIDIA GPU ================================================== diff --git a/tutorials/autotvm/tune_relay_mobile_gpu.py b/tutorials/autotvm/tune_relay_mobile_gpu.py index 37c191cac067..57aea56aa993 100644 --- a/tutorials/autotvm/tune_relay_mobile_gpu.py +++ b/tutorials/autotvm/tune_relay_mobile_gpu.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Auto-tuning a convolutional network for Mobile GPU ================================================== diff --git a/tutorials/autotvm/tune_relay_x86.py b/tutorials/autotvm/tune_relay_x86.py index 588e20dece57..0fa4e31f2b19 100644 --- a/tutorials/autotvm/tune_relay_x86.py +++ b/tutorials/autotvm/tune_relay_x86.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Auto-tuning a convolutional network for x86 CPU =============================================== diff --git a/tutorials/autotvm/tune_simple_template.py b/tutorials/autotvm/tune_simple_template.py index 15b883dcbd73..dac4f157f44a 100644 --- a/tutorials/autotvm/tune_simple_template.py +++ b/tutorials/autotvm/tune_simple_template.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Writing tunable template and Using auto-tuner ============================================= @@ -261,7 +277,7 @@ def matmul(N, L, M, dtype): ################################################################ # Then we need to define how to measure the generated code and pick a tuner. # Since our space is small, a random tuner is just okay. -# +# # We only make 10 trials in this tutorial for demonstration. In practice, # you can do more trials according to your time budget. # We will log the tuning results into a log file. This file can be @@ -286,9 +302,9 @@ def matmul(N, L, M, dtype): ######################################################################### # Finally we apply history best from the cache file and check its correctness. -# We can call the function :code:`matmul` directly under the +# We can call the function :code:`matmul` directly under the # :any:`autotvm.apply_history_best` context. When we call this function, -# it will query the dispatch context with its argument and get the best config +# it will query the dispatch context with its argument and get the best config # with the same argument. # apply history best from log file diff --git a/tutorials/cross_compilation_and_rpc.py b/tutorials/cross_compilation_and_rpc.py index 6c23368f840a..1872b7dafe74 100644 --- a/tutorials/cross_compilation_and_rpc.py +++ b/tutorials/cross_compilation_and_rpc.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ .. _tutorial-cross-compilation-and-rpc: @@ -26,7 +42,7 @@ # All instructions in both this section and next section should be # executed on the target device, e.g. Raspberry Pi. And we assume it # has Linux running. -# +# # Since we do compilation on local machine, the remote device is only used # for running the generated code. We only need to build tvm runtime on # the remote device. @@ -185,7 +201,7 @@ # Run OpenCL Kernel Remotely by RPC # --------------------------------- # As for remote OpenCL devices, the workflow is almost the same as above. -# You can define the kernel, upload files, and run by RPC. +# You can define the kernel, upload files, and run by RPC. # # .. note:: # diff --git a/tutorials/dev/low_level_custom_pass.py b/tutorials/dev/low_level_custom_pass.py index bdb7019f6b17..eb672bbe151a 100644 --- a/tutorials/dev/low_level_custom_pass.py +++ b/tutorials/dev/low_level_custom_pass.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Writing a Customized Pass ========================= diff --git a/tutorials/frontend/deploy_model_on_rasp.py b/tutorials/frontend/deploy_model_on_rasp.py index b90127b3858e..8015b0b1c89e 100644 --- a/tutorials/frontend/deploy_model_on_rasp.py +++ b/tutorials/frontend/deploy_model_on_rasp.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ .. _tutorial-deploy-model-on-rasp: @@ -14,6 +30,7 @@ import tvm.relay as relay from tvm import rpc from tvm.contrib import util, graph_runtime as runtime +from tvm.contrib.download import download_testdata ###################################################################### # .. _build-tvm-runtime-on-device: @@ -28,7 +45,7 @@ # All instructions in both this section and next section should be # executed on the target device, e.g. Raspberry Pi. And we assume it # has Linux running. -# +# # Since we do compilation on local machine, the remote device is only used # for running the generated code. We only need to build tvm runtime on # the remote device. @@ -45,7 +62,7 @@ # # After building runtime successfully, we need to set environment varibles # in :code:`~/.bashrc` file. We can edit :code:`~/.bashrc` -# using :code:`vi ~/.bashrc` and add the line below (Assuming your TVM +# using :code:`vi ~/.bashrc` and add the line below (Assuming your TVM # directory is in :code:`~/tvm`): # # .. code-block:: bash @@ -76,13 +93,12 @@ # Prepare the Pre-trained Model # ----------------------------- # Back to the host machine, which should have a full TVM installed (with LLVM). -# +# # We will use pre-trained model from # `MXNet Gluon model zoo `_. # You can found more details about this part at tutorial :ref:`tutorial-from-mxnet`. from mxnet.gluon.model_zoo.vision import get_model -from mxnet.gluon.utils import download from PIL import Image import numpy as np @@ -92,9 +108,10 @@ ###################################################################### # In order to test our model, here we download an image of cat and # transform its format. +img_url = 'https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true' img_name = 'cat.png' -download('https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true', img_name) -image = Image.open(img_name).resize((224, 224)) +img_path = download_testdata(img_url, img_name, module='data') +image = Image.open(img_path).resize((224, 224)) def transform_image(image): image = np.array(image) - np.array([123., 117., 104.]) @@ -112,9 +129,9 @@ def transform_image(image): '4d0b62f3d01426887599d4f7ede23ee5/raw/', '596b27d23537e5a1b5751d2b0481ef172f58b539/', 'imagenet1000_clsid_to_human.txt']) -synset_name = 'synset.txt' -download(synset_url, synset_name) -with open(synset_name) as f: +synset_name = 'imagenet1000_clsid_to_human.txt' +synset_path = download_testdata(synset_url, synset_name, module='data') +with open(synset_path) as f: synset = eval(f.read()) ###################################################################### diff --git a/tutorials/frontend/deploy_ssd_gluoncv.py b/tutorials/frontend/deploy_ssd_gluoncv.py index f0063ead190b..fe84283ad191 100644 --- a/tutorials/frontend/deploy_ssd_gluoncv.py +++ b/tutorials/frontend/deploy_ssd_gluoncv.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Deploy Single Shot Multibox Detector(SSD) model =============================================== @@ -12,6 +28,7 @@ from tvm.relay.testing.config import ctx_list from tvm import relay from tvm.contrib import graph_runtime +from tvm.contrib.download import download_testdata from gluoncv import model_zoo, data, utils @@ -49,9 +66,9 @@ ###################################################################### # Download and pre-process demo image -im_fname = utils.download('https://github.com/dmlc/web-data/blob/master/' + - 'gluoncv/detection/street_small.jpg?raw=true', - path='street_small.jpg') +im_fname = download_testdata('https://github.com/dmlc/web-data/blob/master/' + + 'gluoncv/detection/street_small.jpg?raw=true', + 'street_small.jpg', module='data') x, img = data.transforms.presets.ssd.load_test(im_fname, short=512) ###################################################################### diff --git a/tutorials/frontend/from_caffe2.py b/tutorials/frontend/from_caffe2.py index fce7f30d865d..8185767cb038 100644 --- a/tutorials/frontend/from_caffe2.py +++ b/tutorials/frontend/from_caffe2.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Compile Caffe2 Models ===================== @@ -19,21 +35,6 @@ or please refer to official site https://caffe2.ai/docs/getting-started.html """ -###################################################################### -# Utils for downloading files -# ---------------------------- -def download(url, path, overwrite=False): - import os - if os.path.isfile(path) and not overwrite: - print('File {} exists, skip.'.format(path)) - return - print('Downloading from url {} to {}'.format(url, path)) - try: - import urllib.request - urllib.request.urlretrieve(url, path) - except: - import urllib - urllib.urlretrieve(url, path) ###################################################################### # Load pretrained Caffe2 model @@ -52,12 +53,13 @@ def __init__(self, model_name): # Load a test image # ------------------ # A single cat dominates the examples! +from tvm.contrib.download import download_testdata from PIL import Image from matplotlib import pyplot as plt import numpy as np img_url = 'https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true' -download(img_url, 'cat.png') -img = Image.open('cat.png').resize((224, 224)) +img_path = download_testdata(img_url, 'cat.png', module='data') +img = Image.open(img_path).resize((224, 224)) plt.imshow(img) plt.show() # input preprocess @@ -118,9 +120,9 @@ def transform_image(image): '4d0b62f3d01426887599d4f7ede23ee5/raw/', '596b27d23537e5a1b5751d2b0481ef172f58b539/', 'imagenet1000_clsid_to_human.txt']) -synset_name = 'synset.txt' -download(synset_url, synset_name) -with open(synset_name) as f: +synset_name = 'imagenet1000_clsid_to_human.txt' +synset_path = download_testdata(synset_url, synset_name, module='data') +with open(synset_path) as f: synset = eval(f.read()) print('Relay top-1 id: {}, class name: {}'.format(top1_tvm, synset[top1_tvm])) # confirm correctness with caffe2 output diff --git a/tutorials/frontend/from_coreml.py b/tutorials/frontend/from_coreml.py index a79e21921068..e0c31445f6a8 100644 --- a/tutorials/frontend/from_coreml.py +++ b/tutorials/frontend/from_coreml.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Compile CoreML Models ===================== @@ -19,23 +35,11 @@ """ import tvm import tvm.relay as relay +from tvm.contrib.download import download_testdata import coremltools as cm import numpy as np from PIL import Image -def download(url, path, overwrite=False): - import os - if os.path.isfile(path) and not overwrite: - print('File {} existed, skip.'.format(path)) - return - print('Downloading from url {} to {}'.format(url, path)) - try: - import urllib.request - urllib.request.urlretrieve(url, path) - except: - import urllib - urllib.urlretrieve(url, path) - ###################################################################### # Load pretrained CoreML model # ---------------------------- @@ -43,17 +47,17 @@ def download(url, path, overwrite=False): # provided by apple in this example model_url = 'https://docs-assets.developer.apple.com/coreml/models/MobileNet.mlmodel' model_file = 'mobilenet.mlmodel' -download(model_url, model_file) +model_path = download_testdata(model_url, model_file, module='coreml') # Now you have mobilenet.mlmodel on disk -mlmodel = cm.models.MLModel(model_file) +mlmodel = cm.models.MLModel(model_path) ###################################################################### # Load a test image # ------------------ # A single cat dominates the examples! img_url = 'https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true' -download(img_url, 'cat.png') -img = Image.open('cat.png').resize((224, 224)) +img_path = download_testdata(img_url, 'cat.png', module='data') +img = Image.open(img_path).resize((224, 224)) x = np.transpose(img, (2, 0, 1))[np.newaxis, :] ###################################################################### @@ -94,8 +98,8 @@ def download(url, path, overwrite=False): '4d0b62f3d01426887599d4f7ede23ee5/raw/', '596b27d23537e5a1b5751d2b0481ef172f58b539/', 'imagenet1000_clsid_to_human.txt']) -synset_name = 'synset.txt' -download(synset_url, synset_name) -with open(synset_name) as f: +synset_name = 'imagenet1000_clsid_to_human.txt' +synset_path = download_testdata(synset_url, synset_name, module='data') +with open(synset_path) as f: synset = eval(f.read()) print('Top-1 id', top1, 'class name', synset[top1]) diff --git a/tutorials/frontend/from_keras.py b/tutorials/frontend/from_keras.py index 0e30a8d012a8..23c7eaf6b2b1 100644 --- a/tutorials/frontend/from_keras.py +++ b/tutorials/frontend/from_keras.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Compile Keras Models ===================== @@ -20,22 +36,10 @@ """ import tvm import tvm.relay as relay +from tvm.contrib.download import download_testdata import keras import numpy as np -def download(url, path, overwrite=False): - import os - if os.path.isfile(path) and not overwrite: - print('File {} exists, skip.'.format(path)) - return - print('Downloading from url {} to {}'.format(url, path)) - try: - import urllib.request - urllib.request.urlretrieve(url, path) - except: - import urllib - urllib.urlretrieve(url, path) - ###################################################################### # Load pretrained keras model # ---------------------------- @@ -43,10 +47,10 @@ def download(url, path, overwrite=False): weights_url = ''.join(['https://github.com/fchollet/deep-learning-models/releases/', 'download/v0.2/resnet50_weights_tf_dim_ordering_tf_kernels.h5']) weights_file = 'resnet50_weights.h5' -download(weights_url, weights_file) +weights_path = download_testdata(weights_url, weights_file, module='keras') keras_resnet50 = keras.applications.resnet50.ResNet50(include_top=True, weights=None, input_shape=(224, 224, 3), classes=1000) -keras_resnet50.load_weights('resnet50_weights.h5') +keras_resnet50.load_weights(weights_path) ###################################################################### # Load a test image @@ -56,8 +60,8 @@ def download(url, path, overwrite=False): from matplotlib import pyplot as plt from keras.applications.resnet50 import preprocess_input img_url = 'https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true' -download(img_url, 'cat.png') -img = Image.open('cat.png').resize((224, 224)) +img_path = download_testdata(img_url, 'cat.png', module='data') +img = Image.open(img_path).resize((224, 224)) plt.imshow(img) plt.show() # input preprocess @@ -92,9 +96,9 @@ def download(url, path, overwrite=False): '4d0b62f3d01426887599d4f7ede23ee5/raw/', '596b27d23537e5a1b5751d2b0481ef172f58b539/', 'imagenet1000_clsid_to_human.txt']) -synset_name = 'synset.txt' -download(synset_url, synset_name) -with open(synset_name) as f: +synset_name = 'imagenet1000_clsid_to_human.txt' +synset_path = download_testdata(synset_url, synset_name, module='data') +with open(synset_path) as f: synset = eval(f.read()) print('Relay top-1 id: {}, class name: {}'.format(top1_tvm, synset[top1_tvm])) # confirm correctness with keras output diff --git a/tutorials/frontend/from_mxnet.py b/tutorials/frontend/from_mxnet.py index a465350a0df8..2629dfaafaab 100644 --- a/tutorials/frontend/from_mxnet.py +++ b/tutorials/frontend/from_mxnet.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ .. _tutorial-from-mxnet: @@ -29,22 +45,23 @@ # Download Resnet18 model from Gluon Model Zoo # --------------------------------------------- # In this section, we download a pretrained imagenet model and classify an image. +from tvm.contrib.download import download_testdata from mxnet.gluon.model_zoo.vision import get_model -from mxnet.gluon.utils import download from PIL import Image from matplotlib import pyplot as plt block = get_model('resnet18_v1', pretrained=True) +img_url = 'https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true' img_name = 'cat.png' synset_url = ''.join(['https://gist.githubusercontent.com/zhreshold/', '4d0b62f3d01426887599d4f7ede23ee5/raw/', '596b27d23537e5a1b5751d2b0481ef172f58b539/', 'imagenet1000_clsid_to_human.txt']) -synset_name = 'synset.txt' -download('https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true', img_name) -download(synset_url, synset_name) -with open(synset_name) as f: +synset_name = 'imagenet1000_clsid_to_human.txt' +img_path = download_testdata(img_url, 'cat.png', module='data') +synset_path = download_testdata(synset_url, synset_name, module='data') +with open(synset_path) as f: synset = eval(f.read()) -image = Image.open(img_name).resize((224, 224)) +image = Image.open(img_path).resize((224, 224)) plt.imshow(image) plt.show() diff --git a/tutorials/frontend/from_onnx.py b/tutorials/frontend/from_onnx.py index 90b0c1c6645c..b177516b9a92 100644 --- a/tutorials/frontend/from_onnx.py +++ b/tutorials/frontend/from_onnx.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Compile ONNX Models =================== @@ -20,19 +36,7 @@ import numpy as np import tvm import tvm.relay as relay - -def download(url, path, overwrite=False): - import os - if os.path.isfile(path) and not overwrite: - print('File {} existed, skip.'.format(path)) - return - print('Downloading from url {} to {}'.format(url, path)) - try: - import urllib.request - urllib.request.urlretrieve(url, path) - except: - import urllib - urllib.urlretrieve(url, path) +from tvm.contrib.download import download_testdata ###################################################################### # Load pretrained ONNX model @@ -44,9 +48,9 @@ def download(url, path, overwrite=False): 'bcda4716699ac97ea44f791c24310193/raw/', '93672b029103648953c4e5ad3ac3aadf346a4cdc/', 'super_resolution_0.2.onnx']) -download(model_url, 'super_resolution.onnx', False) +model_path = download_testdata(model_url, 'super_resolution.onnx', module='onnx') # now you have super_resolution.onnx on disk -onnx_model = onnx.load('super_resolution.onnx') +onnx_model = onnx.load(model_path) ###################################################################### # Load a test image @@ -54,8 +58,8 @@ def download(url, path, overwrite=False): # A single cat dominates the examples! from PIL import Image img_url = 'https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true' -download(img_url, 'cat.png') -img = Image.open('cat.png').resize((224, 224)) +img_path = download_testdata(img_url, 'cat.png', module='data') +img = Image.open(img_path).resize((224, 224)) img_ycbcr = img.convert("YCbCr") # convert to YCbCr img_y, img_cb, img_cr = img_ycbcr.split() x = np.array(img_y)[np.newaxis, np.newaxis, :, :] diff --git a/tutorials/frontend/from_tensorflow.py b/tutorials/frontend/from_tensorflow.py index 1f76db890ade..58f63a0b7e78 100644 --- a/tutorials/frontend/from_tensorflow.py +++ b/tutorials/frontend/from_tensorflow.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Compile Tensorflow Models ========================= @@ -43,8 +59,8 @@ map_proto_url = os.path.join(repo_base, map_proto) # Human readable text for labels -lable_map = 'imagenet_synset_to_human_label_map.txt' -lable_map_url = os.path.join(repo_base, lable_map) +label_map = 'imagenet_synset_to_human_label_map.txt' +label_map_url = os.path.join(repo_base, label_map) # Target settings # Use these commented settings to build for cuda. @@ -61,19 +77,19 @@ # Download required files # ----------------------- # Download files listed above. -from mxnet.gluon.utils import download +from tvm.contrib.download import download_testdata -download(image_url, img_name) -download(model_url, model_name) -download(map_proto_url, map_proto) -download(lable_map_url, lable_map) +img_path = download_testdata(image_url, img_name, module='data') +model_path = download_testdata(model_url, model_name, module=['tf', 'InceptionV1']) +map_proto_path = download_testdata(map_proto_url, map_proto, module='data') +label_path = download_testdata(label_map_url, label_map, module='data') ###################################################################### # Import model # ------------ # Creates tensorflow graph definition from protobuf file. -with tf.gfile.FastGFile(os.path.join("./", model_name), 'rb') as f: +with tf.gfile.FastGFile(model_path, 'rb') as f: graph_def = tf.GraphDef() graph_def.ParseFromString(f.read()) graph = tf.import_graph_def(graph_def, name='') @@ -94,7 +110,7 @@ # from PIL import Image -image = Image.open(img_name).resize((299, 299)) +image = Image.open(img_path).resize((299, 299)) x = np.array(image) @@ -110,7 +126,7 @@ dtype_dict = {'DecodeJpeg/contents': 'uint8'} sym, params = relay.frontend.from_tensorflow(graph_def, layout=layout, shape=shape_dict) -print ("Tensorflow protobuf imported to relay frontend.") +print("Tensorflow protobuf imported to relay frontend.") ###################################################################### # Relay Build # ----------- @@ -148,8 +164,8 @@ predictions = np.squeeze(predictions) # Creates node ID --> English string lookup. -node_lookup = tf_testing.NodeLookup(label_lookup_path=os.path.join("./", map_proto), - uid_lookup_path=os.path.join("./", lable_map)) +node_lookup = tf_testing.NodeLookup(label_lookup_path=map_proto_path, + uid_lookup_path=label_path) # Print top 5 predictions from TVM output. top_k = predictions.argsort()[-5:][::-1] @@ -166,7 +182,7 @@ def create_graph(): """Creates a graph from saved GraphDef file and returns a saver.""" # Creates graph from saved graph_def.pb. - with tf.gfile.FastGFile(model_name, 'rb') as f: + with tf.gfile.FastGFile(model_path, 'rb') as f: graph_def = tf.GraphDef() graph_def.ParseFromString(f.read()) graph = tf.import_graph_def(graph_def, name='') @@ -200,8 +216,8 @@ def run_inference_on_image(image): predictions = np.squeeze(predictions) # Creates node ID --> English string lookup. - node_lookup = tf_testing.NodeLookup(label_lookup_path=os.path.join("./", map_proto), - uid_lookup_path=os.path.join("./", lable_map)) + node_lookup = tf_testing.NodeLookup(label_lookup_path=map_proto_path, + uid_lookup_path=label_path) # Print top 5 predictions from tensorflow. top_k = predictions.argsort()[-5:][::-1] @@ -211,4 +227,4 @@ def run_inference_on_image(image): score = predictions[node_id] print('%s (score = %.5f)' % (human_string, score)) -run_inference_on_image (img_name) +run_inference_on_image(img_path) diff --git a/tutorials/frontend/from_tflite.py b/tutorials/frontend/from_tflite.py index cfa18af291b1..52ecb65b3689 100644 --- a/tutorials/frontend/from_tflite.py +++ b/tutorials/frontend/from_tflite.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Compile TFLite Models =================== @@ -52,25 +68,14 @@ ###################################################################### # Utils for downloading and extracting zip files # --------------------------------------------- - -def download(url, path, overwrite=False): - import os - if os.path.isfile(path) and not overwrite: - print('File {} existed, skip.'.format(path)) - return - print('Downloading from url {} to {}'.format(url, path)) - try: - import urllib.request - urllib.request.urlretrieve(url, path) - except: - import urllib - urllib.urlretrieve(url, path) +import os def extract(path): import tarfile if path.endswith("tgz") or path.endswith("gz"): + dir_path = os.path.dirname(path) tar = tarfile.open(path) - tar.extractall() + tar.extractall(path=dir_path) tar.close() else: raise RuntimeError('Could not decompress the file: ' + path) @@ -80,14 +85,17 @@ def extract(path): # Load pretrained TFLite model # --------------------------------------------- # we load mobilenet V1 TFLite model provided by Google +from tvm.contrib.download import download_testdata + model_url = "http://download.tensorflow.org/models/mobilenet_v1_2018_08_02/mobilenet_v1_1.0_224.tgz" # we download model tar file and extract, finally get mobilenet_v1_1.0_224.tflite -download(model_url, "mobilenet_v1_1.0_224.tgz", False) -extract("mobilenet_v1_1.0_224.tgz") +model_path = download_testdata(model_url, "mobilenet_v1_1.0_224.tgz", module=['tf', 'official']) +model_dir = os.path.dirname(model_path) +extract(model_path) # now we have mobilenet_v1_1.0_224.tflite on disk and open it -tflite_model_file = "mobilenet_v1_1.0_224.tflite" +tflite_model_file = os.path.join(model_dir, "mobilenet_v1_1.0_224.tflite") tflite_model_buf = open(tflite_model_file, "rb").read() # get TFLite model from buffer @@ -103,8 +111,8 @@ def extract(path): import numpy as np image_url = 'https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true' -download(image_url, 'cat.png') -resized_image = Image.open('cat.png').resize((224, 224)) +image_path = download_testdata(image_url, 'cat.png', module='data') +resized_image = Image.open(image_path).resize((224, 224)) plt.imshow(resized_image) plt.show() image_data = np.asarray(resized_image).astype("float32") @@ -179,11 +187,11 @@ def extract(path): 'app/src/main/assets/', 'labels_mobilenet_quant_v1_224.txt']) label_file = "labels_mobilenet_quant_v1_224.txt" -download(label_file_url, label_file) +label_path = download_testdata(label_file_url, label_file, module='data') # map id to 1001 classes labels = dict() -with open(label_file) as f: +with open(label_path) as f: for id, line in enumerate(f): labels[id] = line diff --git a/tutorials/frontend/using_external_lib.py b/tutorials/frontend/using_external_lib.py index fb4b52ea5cf1..a33d4eb9dc7a 100644 --- a/tutorials/frontend/using_external_lib.py +++ b/tutorials/frontend/using_external_lib.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Using External Libraries in Relay ================================ diff --git a/tutorials/language/extern_op.py b/tutorials/language/extern_op.py index 59efe5000f03..071968ce2b1f 100644 --- a/tutorials/language/extern_op.py +++ b/tutorials/language/extern_op.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ External Tensor Functions ========================= diff --git a/tutorials/language/intrin_math.py b/tutorials/language/intrin_math.py index 44c0692c04fa..d266b7cb743a 100644 --- a/tutorials/language/intrin_math.py +++ b/tutorials/language/intrin_math.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Intrinsics and Math Functions ============================= diff --git a/tutorials/language/reduction.py b/tutorials/language/reduction.py index 8be614b2f6ea..0b631cb077f4 100644 --- a/tutorials/language/reduction.py +++ b/tutorials/language/reduction.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Reduction ========= diff --git a/tutorials/language/scan.py b/tutorials/language/scan.py index 8b8f848ffa13..be637fba0f70 100644 --- a/tutorials/language/scan.py +++ b/tutorials/language/scan.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Scan and Recurrent Kernel ========================= diff --git a/tutorials/language/schedule_primitives.py b/tutorials/language/schedule_primitives.py index 751dd42563f0..44283818edf4 100644 --- a/tutorials/language/schedule_primitives.py +++ b/tutorials/language/schedule_primitives.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Schedule Primitives in TVM ========================== diff --git a/tutorials/language/tensorize.py b/tutorials/language/tensorize.py index 4115de1b2eb4..7fb2d5368c9c 100644 --- a/tutorials/language/tensorize.py +++ b/tutorials/language/tensorize.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Use Tensorize to Leverage Hardware Intrinsics ============================================= diff --git a/tutorials/language/tuple_inputs.py b/tutorials/language/tuple_inputs.py index ab948fe9f18d..8fb8083c3480 100644 --- a/tutorials/language/tuple_inputs.py +++ b/tutorials/language/tuple_inputs.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Compute and Reduce with Tuple Inputs ======================================= diff --git a/tutorials/optimize/opt_conv_cuda.py b/tutorials/optimize/opt_conv_cuda.py index d39f213bf3d7..74d1e6d8b6a0 100644 --- a/tutorials/optimize/opt_conv_cuda.py +++ b/tutorials/optimize/opt_conv_cuda.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ .. _opt-conv-gpu: diff --git a/tutorials/optimize/opt_gemm.py b/tutorials/optimize/opt_gemm.py index ecb8707d399b..0fb73ec40dbb 100644 --- a/tutorials/optimize/opt_gemm.py +++ b/tutorials/optimize/opt_gemm.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ .. _opt-gemm: diff --git a/tutorials/relay_quick_start.py b/tutorials/relay_quick_start.py index 286114fe997f..b21f4fc5571c 100644 --- a/tutorials/relay_quick_start.py +++ b/tutorials/relay_quick_start.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ .. _tutorial-relay-quick-start: diff --git a/tutorials/tensor_expr_get_started.py b/tutorials/tensor_expr_get_started.py index cb08b6bb5ee2..b066fbad57c6 100644 --- a/tutorials/tensor_expr_get_started.py +++ b/tutorials/tensor_expr_get_started.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Get Started with Tensor Expression ================================== diff --git a/tutorials/topi/intro_topi.py b/tutorials/topi/intro_topi.py index 8b8124c95e2b..0b0d1c8d8ec3 100644 --- a/tutorials/topi/intro_topi.py +++ b/tutorials/topi/intro_topi.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ Introduction to TOPI ==================== diff --git a/verilog/README.md b/verilog/README.md deleted file mode 100644 index 016d25a5c264..000000000000 --- a/verilog/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# Verilog Code Guidline - -The verilog backend is still at early alpha and not yet ready to use. - -- Use ```my_port_name``` for variable naming. -- Always use suffix to indicate certain usage. - -## Common Suffix - -- ```clk```: clock -- ```rst```: reset -- ```in```: input port -- ```out```: output port -- ```en```: enable signal -- ```addr```: address port -- ```valid```: valid signal in FIFO handshake. -- ```ready```: ready signal in FIFO handshake. diff --git a/verilog/example_counter.v b/verilog/example_counter.v deleted file mode 100644 index 08305a077964..000000000000 --- a/verilog/example_counter.v +++ /dev/null @@ -1,17 +0,0 @@ -// a counter that counts up -// Use as example of testcaase -module counter(clk, rst, out); - input clk; - input rst; - output [3:0] out; - reg [3:0] counter; - assign out = counter; - - always @(posedge clk) begin - if (rst) begin - counter <= 0; - end else begin - counter <= counter +1; - end - end -endmodule diff --git a/verilog/tvm_buffer.v b/verilog/tvm_buffer.v deleted file mode 100644 index 402d09b619a7..000000000000 --- a/verilog/tvm_buffer.v +++ /dev/null @@ -1,118 +0,0 @@ -// Buffer used to add intermediate data buffering in channels -// -// Data within the read/write window is directly accessible via rd_addr/wr_addr. -// The read_advance/write_advance signals update the read/write data pointers by adding RD_WINDOW/WR_WINDOW. -// The status_counter indicate how many items are currently in the buffer (only registered after an advance signal is asserted). -// The ready/valid signals are used to implement a handshake protocol. -// -// Usage: create and pass instance to additional arguments of $tvm_session. - - -module tvm_buffer #( - parameter DATA_WIDTH = 256, - parameter DEPTH = 1024, - parameter CNTR_WIDTH = 10, // log base 2 of BUFF_DEPTH - parameter RD_WINDOW = 8, // set to 1 for FIFO behavior, or DEPTH for SRAM behavior - parameter RD_ADVANCE = 2, // window advance (set to 1 for FIFO behavior) - parameter RD_ADDR_WIDTH = 3, // log base 2 of RD_WINDOW - parameter WR_WINDOW = 8, // set to 1 for FIFO behavior, or DEPTH for SRAM behavior - parameter WR_ADVANCE = 2, // window advance (set to 1 for FIFO behavior) - parameter WR_ADDR_WIDTH = 3 // log base 2 of WR_WINDOW -) ( - input clk, - input rst, - // Read ports - input read_advance, // Window advance (read pointer) - input [RD_ADDR_WIDTH-1:0] read_addr, // Read address offset - input read_ready, // Read ready (dequeue) - output read_valid, // Read valid (not empty) - output [DATA_WIDTH-1:0] read_data, // Read data port - // Write ports - input write_advance, // Window advance (write pointer) - input [WR_ADDR_WIDTH-1:0] write_addr, // Write address offset - output write_ready, // Write ready (not full) - input write_valid, // Write valid (enqueue) - input [DATA_WIDTH-1:0] write_data, // Write data port - // Other outputs - output [CNTR_WIDTH-1:0] status_counter // Number of elements currently in FIFO -); - - // Outputs that need to be latched - reg read_data; - reg status_counter; - - // Internal registers (read pointer, write pointer) - reg[CNTR_WIDTH-1:0] read_ptr; - reg[CNTR_WIDTH-1:0] write_ptr; - - // RAM instance - reg [DATA_WIDTH-1:0] ram[DEPTH-1:0]; - - // Empty and full logic - assign read_valid = (status_counter>=RD_WINDOW) ? 1'b1 : 1'b0; - assign write_ready = (status_counter<(DEPTH-WR_WINDOW)) ? 1'b1 : 1'b0; - - // Counter logic (only affected by enq and deq) - always @(posedge clk) begin - // Case 1: system reset - if (rst==1'b1) begin - status_counter <= 0; - // Case 2: simultaneous write advance and read advance and deq - end else if ((write_advance && write_ready) && (read_advance && read_valid)) begin - status_counter <= status_counter + (WR_ADVANCE - RD_ADVANCE); - // Case 3: write advance - end else if (write_advance && write_ready) begin - status_counter <= status_counter + WR_ADVANCE; - // Case 4: deq - end else if (read_advance && read_valid) begin - status_counter <= status_counter - RD_ADVANCE; - // Default - end else begin - status_counter <= status_counter; - end - end - - // Output logic - always @(posedge clk) begin - if (rst==1'b1) begin - read_data <= 0; - end else begin - if(read_ready) begin - read_data <= ram[(read_ptr+read_addr)%DEPTH]; - end else begin - read_data <= read_data; - end - end - end - - // RAM writing logic - always @(posedge clk) begin - if(write_valid) begin - ram[((write_ptr+write_addr)%DEPTH)] <= write_data; - end - end - - // Read and write pointer logic - always@(posedge clk) begin - if (rst==1'b1) begin - write_ptr <= 0; - read_ptr <= 0; - end else begin - // Increment write pointer by WR_ADVANCE when asserting write_advance - // When performing a write, no need to update the write pointer - if (write_advance && write_ready) begin - write_ptr <= (write_ptr + WR_ADVANCE) % DEPTH; - end else begin - write_ptr <= write_ptr; - end - // Increment read pointer by RD_ADVANCE when asserting read_advance - // When performing a read, no need to update the read pointer - if(read_advance && read_valid) begin - read_ptr <= (read_ptr + RD_ADVANCE) % DEPTH; - end else begin - read_ptr <= read_ptr; - end - end - end - -endmodule // tvm_buffer diff --git a/verilog/tvm_marcos.v b/verilog/tvm_marcos.v deleted file mode 100644 index 497e67f78789..000000000000 --- a/verilog/tvm_marcos.v +++ /dev/null @@ -1,120 +0,0 @@ -// Nonstop version of loop -// Always keeps looping when increase == true -// At end is a signal to indicate the next cycle is end -// Use that to signal parent loop to advance. -`define NONSTOP_LOOP(iter, width, init, ready, finish, min, extent)\ - reg [width-1:0] iter;\ - wire finish;\ - always@(posedge clk) begin\ - if (rst || init) begin\ - iter <= (min);\ - end else if(ready) begin\ - if (iter != ((extent)-1)) begin\ - iter <= iter + 1;\ - end else begin\ - iter <= (min);\ - end\ - end else begin\ - iter <= iter;\ - end\ - end\ - assign finish = (ready && (iter == (extent) - 1)); - - -// Wrap a nonstop loop to normal loop that loop only once. -// Use done signal to control the non-stop body to stop. -// The init and done behaves like normal loop -`define WRAP_LOOP_ONCE(init, valid, ready, body_finish, body_ready)\ - reg valid;\ - wire body_ready;\ - always@(posedge clk) begin\ - if (rst || init) begin\ - valid <= 1;\ - end else if(body_finish) begin\ - valid <= 0;\ - end else begin\ - valid <= valid;\ - end\ - end\ - assign body_ready = (valid && ready); - -// Assign dst as src delayed by specific cycles. -`define DELAY(dst, src, width, delay, not_stall)\ - reg [(width)*(delay)-1:0] src``_dly_chain;\ - always@(posedge clk) begin\ - if(rst) begin\ - src``_dly_chain <= 0;\ - end else if (not_stall) begin\ - src``_dly_chain[(width)-1:0] <= src;\ - if((delay) != 1) begin\ - src``_dly_chain[(delay)*(width)-1:(width)] <= src``_dly_chain[((delay)-1)*(width)-1:0];\ - end\ - end else begin\ - src``_dly_chain <= src``_dly_chain;\ - end\ - end\ - assign dst = src``_dly_chain[(delay)*(width)-1:((delay)-1)*(width)]; - -// TVM generate clock signal -`define TVM_DEFINE_TEST_SIGNAL(clk, rst)\ - parameter PER = 10;\ - reg clk;\ - reg rst;\ - always begin\ - #(PER/2) clk =~ clk;\ - end - -// Control logic on buffer/RAM read valid. -// This delays the valid signal by one cycle and retain it when write_ready == 0 -`define BUFFER_READ_VALID_DELAY(dst, data_valid, write_ready)\ - reg dst;\ - always@(posedge clk) begin\ - if(rst) begin\ - dst <= 0;\ - end else if (write_ready) begin\ - dst <= (data_valid);\ - end else begin\ - dst <= dst;\ - end\ - end\ - -// A cache register that add one cycle lag to the ready signal -// This allows the signal to flow more smoothly -`define CACHE_REG(width, in_data, in_valid, in_ready, out_data, out_valid, out_ready)\ - reg [width-1:0] out_data``_state_;\ - reg [width-1:0] out_data``_overflow_;\ - reg out_valid``_state_;\ - reg out_valid``_overflow_;\ - always@(posedge clk) begin\ - if(rst) begin\ - out_valid``_overflow_ <= 0;\ - out_valid``_state_ <= 0;\ - end else if (out_valid``_overflow_) begin\ - if (out_ready) begin\ - out_valid``_state_ <= 1;\ - out_data``_state_ <= out_data``_overflow_;\ - out_valid``_overflow_ <= 0;\ - out_data``_overflow_ <= 0;\ - end else begin\ - out_valid``_state_ <= 1;\ - out_data``_state_ <= out_data``_state_;\ - out_valid``_overflow_ <= out_valid``_overflow_;\ - out_data``_overflow_ <= out_data``_overflow_;\ - end\ - end else begin\ - if (!out_ready && out_valid``_state_) begin\ - out_valid``_state_ <= 1;\ - out_data``_state_ <= out_data``_state_;\ - out_valid``_overflow_ <= in_valid;\ - out_data``_overflow_ <= in_data;\ - end else begin\ - out_valid``_state_ <= in_valid;\ - out_data``_state_ <= in_data;\ - out_valid``_overflow_ <= out_valid``_overflow_;\ - out_data``_overflow_ <= out_data``_overflow_;\ - end\ - end\ - end\ // always@ (posedge clk) - assign in_ready = !out_valid``_overflow_;\ - assign out_data = out_data``_state_;\ - assign out_valid = out_valid``_state_; diff --git a/verilog/tvm_vpi.cc b/verilog/tvm_vpi.cc deleted file mode 100644 index 949b660ce447..000000000000 --- a/verilog/tvm_vpi.cc +++ /dev/null @@ -1,269 +0,0 @@ -/*! - * Copyright (c) 2017 by Contributors - * \file tvm_vpi.cc - * \brief Messages passed around VPI used for simulation. - */ -#include -#include -#include -#include -#include -#include -#include -#include "tvm_vpi.h" -#include "../src/common/pipe.h" - -namespace tvm { -namespace vpi { -// standard consistency checks -static_assert(sizeof(vpiHandle) == sizeof(VPIRawHandle), - "VPI standard"); -// type codes -static_assert(vpiModule == kVPIModule, "VPI standard"); -// Property code -static_assert(vpiType == kVPIType, "VPI standard"); -static_assert(vpiFullName == kVPIFullName, "VPI standard"); -static_assert(vpiSize == kVPISize, "VPI standard"); -static_assert(vpiDefName == kVPIDefName, "VPI standard"); - -// IPC client for VPI -class IPCClient { - public: - // constructor - IPCClient(int64_t hread, int64_t hwrite) - : reader_(hread), writer_(hwrite) { - } - void Init() { - vpiHandle argv = vpi_handle(vpiSysTfCall, 0); - vpiHandle arg_iter = vpi_iterate(vpiArgument, argv); - clock_ = vpi_scan(arg_iter); - std::vector handles; - while (vpiHandle h = vpi_scan(arg_iter)) { - handles.push_back(h); - } - writer_.Write(handles); - PutInt(clock_, 0); - } - int Callback() { - if (!GetInt(clock_)) { - try { - return AtNegEdge(); - } catch (const std::runtime_error& e) { - reader_.Close(); - writer_.Close(); - vpi_printf("ERROR: encountered %s\n", e.what()); - vpi_control(vpiFinish, 1); - return 0; - } - } else { - return 0; - } - } - // called at neg edge. - int AtNegEdge() { - // This is actually called at neg-edge - // The put values won't take effect until next neg-edge. - // This allow us to see the registers before snc - writer_.Write(kPosEdgeTrigger); - VPICallCode rcode; - VPIRawHandle handle; - int32_t index, value; - - while (true) { - CHECK(reader_.Read(&rcode)); - switch (rcode) { - case kGetHandleByName: { - std::string str; - CHECK(reader_.Read(&str)); - CHECK(reader_.Read(&handle)); - handle = vpi_handle_by_name( - str.c_str(), static_cast(handle)); - writer_.Write(kSuccess); - writer_.Write(handle); - break; - } - case kGetHandleByIndex: { - CHECK(reader_.Read(&handle)); - CHECK(reader_.Read(&index)); - handle = vpi_handle_by_index( - static_cast(handle), index); - writer_.Write(kSuccess); - writer_.Write(handle); - break; - } - case kGetStrProp: { - CHECK(reader_.Read(&value)); - CHECK(reader_.Read(&handle)); - std::string prop = vpi_get_str( - value, static_cast(handle)); - writer_.Write(kSuccess); - writer_.Write(prop); - break; - } - case kGetIntProp: { - CHECK(reader_.Read(&value)); - CHECK(reader_.Read(&handle)); - value = vpi_get(value, static_cast(handle)); - writer_.Write(kSuccess); - writer_.Write(value); - break; - } - case kGetInt32: { - CHECK(reader_.Read(&handle)); - value = GetInt(static_cast(handle)); - writer_.Write(kSuccess); - writer_.Write(value); - break; - } - case kPutInt32: { - CHECK(reader_.Read(&handle)); - CHECK(reader_.Read(&value)); - CHECK(handle != clock_) << "Cannot write to clock"; - PutInt(static_cast(handle), value); - writer_.Write(kSuccess); - break; - } - case kGetVec: { - CHECK(reader_.Read(&handle)); - vpiHandle h = static_cast(handle); - int bits = vpi_get(vpiSize, h); - int nwords = (bits + 31) / 32; - s_vpi_value value_s; - value_s.format = vpiVectorVal; - vpi_get_value(h, &value_s); - vec_buf_.resize(nwords); - for (size_t i = 0; i < vec_buf_.size(); ++i) { - vec_buf_[i].aval = value_s.value.vector[i].aval; - vec_buf_[i].bval = value_s.value.vector[i].bval; - } - writer_.Write(kSuccess); - writer_.Write(vec_buf_); - break; - } - case kPutVec: { - CHECK(reader_.Read(&handle)); - CHECK(reader_.Read(&vec_buf_)); - CHECK(handle != clock_) << "Cannot write to clock"; - vpiHandle h = static_cast(handle); - svec_buf_.resize(vec_buf_.size()); - for (size_t i = 0; i < vec_buf_.size(); ++i) { - svec_buf_[i].aval = vec_buf_[i].aval; - svec_buf_[i].bval = vec_buf_[i].bval; - } - s_vpi_value value_s; - s_vpi_time time_s; - time_s.type = vpiSimTime; - time_s.high = 0; - time_s.low = 10; - value_s.format = vpiVectorVal; - value_s.value.vector = &svec_buf_[0]; - vpi_put_value(h, &value_s, &time_s, vpiTransportDelay); - writer_.Write(kSuccess); - break; - } - case kYield: { - writer_.Write(kSuccess); - return 0; - } - case kShutDown : { - writer_.Write(kSuccess); - vpi_control(vpiFinish, 0); - return 0; - } - } - } - } - // Create a new FSM from ENV. - static IPCClient* Create() { - const char* d_read = getenv("TVM_DREAD_PIPE"); - const char* d_write = getenv("TVM_DWRITE_PIPE"); - const char* h_read = getenv("TVM_HREAD_PIPE"); - const char* h_write = getenv("TVM_HWRITE_PIPE"); - if (d_write == nullptr || - d_read == nullptr || - h_read == nullptr || - h_write == nullptr) { - vpi_printf("ERROR: need environment var TVM_READ_PIPE, TVM_WRITE_PIPE\n"); - vpi_control(vpiFinish, 1); - return nullptr; - } - // close host side pipe. - common::Pipe(atoi(h_read)).Close(); - common::Pipe(atoi(h_write)).Close(); - IPCClient* client = new IPCClient(atoi(d_read), atoi(d_write)); - client->Init(); - return client; - } - // Get integer from handle. - static int GetInt(vpiHandle h) { - s_vpi_value value_s; - value_s.format = vpiIntVal; - vpi_get_value(h, &value_s); - return value_s.value.integer; - } - // Put integer into handle. - static void PutInt(vpiHandle h, int value) { - s_vpi_value value_s; - s_vpi_time time_s; - time_s.type = vpiSimTime; - time_s.high = 0; - time_s.low = 10; - value_s.format = vpiIntVal; - value_s.value.integer = value; - vpi_put_value(h, &value_s, &time_s, vpiTransportDelay); - } - // Handles - vpiHandle clock_; - // the communicator - common::Pipe reader_, writer_; - // data buf - std::vector vec_buf_; - std::vector svec_buf_; -}; -} // namespace vpi -} // namespace tvm - -extern "C" { -static PLI_INT32 tvm_host_clock_cb(p_cb_data cb_data) { - return reinterpret_cast( - cb_data->user_data)->Callback(); -} - -static PLI_INT32 tvm_init(char* cb) { - s_vpi_value value_s; - s_vpi_time time_s; - s_cb_data cb_data_s; - tvm::vpi::IPCClient* client = tvm::vpi::IPCClient::Create(); - if (client) { - cb_data_s.user_data = reinterpret_cast(client); - cb_data_s.reason = cbValueChange; - cb_data_s.cb_rtn = tvm_host_clock_cb; - cb_data_s.time = &time_s; - cb_data_s.value = &value_s; - time_s.type = vpiSuppressTime; - value_s.format = vpiIntVal; - cb_data_s.obj = client->clock_; - vpi_register_cb(&cb_data_s); - } else { - vpi_printf("ERROR: canot initalize host\n"); - vpi_control(vpiFinish, 1); - } - return 0; -} - -void tvm_vpi_register() { - s_vpi_systf_data tf_data; - tf_data.type = vpiSysTask; - tf_data.tfname = "$tvm_session"; - tf_data.calltf = tvm_init; - tf_data.compiletf = nullptr; - tf_data.sizetf = nullptr; - tf_data.user_data = nullptr; - vpi_register_systf(&tf_data); -} - -void (*vlog_startup_routines[])() = { - tvm_vpi_register, - 0 -}; -} // extern "C" diff --git a/verilog/tvm_vpi.h b/verilog/tvm_vpi.h deleted file mode 100644 index 3925e8aedda4..000000000000 --- a/verilog/tvm_vpi.h +++ /dev/null @@ -1,55 +0,0 @@ -/*! - * Copyright (c) 2017 by Contributors - * \file tvm_vpi.h - * \brief Messages passed around VPI used for simulation. - */ -#ifndef VERILOG_TVM_VPI_H_ -#define VERILOG_TVM_VPI_H_ - -namespace tvm { -namespace vpi { - -enum VPICallCode : int { - kGetHandleByName, - kGetHandleByIndex, - kGetStrProp, - kGetIntProp, - kGetInt32, - kPutInt32, - kGetVec, - kPutVec, - kYield, - kShutDown -}; - -enum VPIReturnCode : int { - kPosEdgeTrigger = 0, - kSuccess = 1, - kFail = 2 -}; - -// VPI type code as in IEEE standard. -enum VPITypeCode { - kVPIModule = 32 -}; - -// VPI property code as in IEEE standard. -enum VPIPropCode { - kVPIType = 1, - kVPIFullName = 3, - kVPISize = 4, - kVPIDefName = 9 -}; - -/*! \brief The vector value used in trasmission */ -struct VPIVecVal { - int aval; - int bval; -}; - -/*! \brief User facing vpi handle. */ -typedef void* VPIRawHandle; - -} // namespace vpi -} // namespace tvm -#endif // VERILOG_TVM_VPI_H_ diff --git a/verilog/tvm_vpi_mem_interface.v b/verilog/tvm_vpi_mem_interface.v deleted file mode 100644 index 932af8d06280..000000000000 --- a/verilog/tvm_vpi_mem_interface.v +++ /dev/null @@ -1,43 +0,0 @@ -// Memory controller to access TVM VPI simulated RAM. -// -// You only see the wires and registers but no logics here. -// The real computation is implemented via TVM VPI -// -// Usage: create and pass instance to additional arguments of $tvm_session. -// Then it will be automatically hook up the RAM logic. -// -module tvm_vpi_mem_interface - #( - parameter READ_WIDTH = 8, - parameter WRITE_WIDTH = 8, - parameter ADDR_WIDTH = 32, - parameter SIZE_WIDTH = 32 - ) - ( - input clk, - input rst, - // Read Ports - input read_en, // Read buffer enable - output [READ_WIDTH-1:0] read_data_out, // The data port for read - output read_data_valid, // Read is valid. - // Write ports - input write_en, // Write buffer enable - input [WRITE_WIDTH-1:0] write_data_in, // Input data to write. - output write_data_ready, // There are still pending write - // Status port - // Control signal ports to issue tasks - input host_read_req, // Read request - input [ADDR_WIDTH-1:0] host_read_addr, // The address to issue a read task - input [SIZE_WIDTH-1:0] host_read_size, // The size of a read - input host_write_req, // Write request. - input [ADDR_WIDTH-1:0] host_write_addr, // The write address - input [SIZE_WIDTH-1:0] host_write_size // The write size - ); - reg [READ_WIDTH-1:0] reg_read_data; - reg reg_read_valid; - reg reg_write_ready; - // The wires up. - assign read_data_out = reg_read_data; - assign read_data_valid = reg_read_valid; - assign write_data_ready = reg_write_ready; -endmodule diff --git a/verilog/tvm_vpi_mmap.v b/verilog/tvm_vpi_mmap.v deleted file mode 100644 index 1f7793954cf5..000000000000 --- a/verilog/tvm_vpi_mmap.v +++ /dev/null @@ -1,43 +0,0 @@ -// TVM mmap maps virtual DRAM into interface of SRAM. -// This allows create testcases that directly access DRAM. - -// Read only memory map, one cycle read. -// Usage: create and pass instance to additional arguments of $tvm_session. -module tvm_vpi_read_mmap - #( - parameter DATA_WIDTH = 8, - parameter ADDR_WIDTH = 8, - parameter BASE_ADDR_WIDTH = 32 - ) - ( - input clk, - input rst, - // Read Ports - input [ADDR_WIDTH-1:0] addr, // Local offset in terms of number of units - output [DATA_WIDTH-1:0] data_out, // The data port for read - // Configure port - input [BASE_ADDR_WIDTH-1:0] mmap_addr // The base address of memory map. - ); - reg [DATA_WIDTH-1:0] reg_data; - assign data_out = reg_data; -endmodule - -// Write only memory map, one cycle write. -// Usage: create and pass instance to additional arguments of $tvm_session. -module tvm_vpi_write_mmap - #( - parameter DATA_WIDTH = 8, - parameter ADDR_WIDTH = 8, - parameter BASE_ADDR_WIDTH = 32 - ) - ( - input clk, - input rst, - // Write Ports - input [ADDR_WIDTH-1:0] addr, // Local offset in terms of number of units - input [DATA_WIDTH-1:0] data_in, // The data port for write - input en, // The enable port for write - // Configure port - input [BASE_ADDR_WIDTH-1:0] mmap_addr // The base address of memap - ); -endmodule diff --git a/verilog/verilog.mk b/verilog/verilog.mk deleted file mode 100644 index 57931dbd81ae..000000000000 --- a/verilog/verilog.mk +++ /dev/null @@ -1,10 +0,0 @@ -VPI_CFLAGS=`iverilog-vpi --cflags` -VPI_LDFLAGS=`iverilog-vpi --ldflags` - -VER_SRCS = $(wildcard verilog/*.v) - -VER_LIBS=lib/tvm_vpi.vpi - -lib/tvm_vpi.vpi: verilog/tvm_vpi.cc verilog/tvm_vpi.h - @mkdir -p $(@D) - $(CXX) $(VPI_CFLAGS) $(CFLAGS) -o $@ $(filter %.cc, $^) $(LDFLAGS) $(VPI_LDFLAGS) diff --git a/version.py b/version.py index b0c0b2af109e..1df897a40fb4 100644 --- a/version.py +++ b/version.py @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + """ This is the global script that set the version information of TVM. This script runs and update all the locations that related to versions diff --git a/vta/README.md b/vta/README.md index 4b1d17ff4bb4..eb09e613b438 100644 --- a/vta/README.md +++ b/vta/README.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + VTA: Open, Modular, Deep Learning Accelerator Stack =================================================== VTA (versatile tensor accelerator) is an open-source deep learning accelerator complemented with an end-to-end TVM-based compiler stack. diff --git a/vta/config/README.md b/vta/config/README.md index 152621666ef1..b675ef293e10 100644 --- a/vta/config/README.md +++ b/vta/config/README.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + # VTA Configuration Each VTA runtime/hardware configuration is specified by vta_config.json file. diff --git a/vta/config/vta_config.py b/vta/config/vta_config.py index 69c21fe80940..ea07e5a7770c 100644 --- a/vta/config/vta_config.py +++ b/vta/config/vta_config.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """VTA config tool""" import os import sys diff --git a/vta/hardware/xilinx/Makefile b/vta/hardware/xilinx/Makefile index 0c365be0ed61..af13cdc166f8 100644 --- a/vta/hardware/xilinx/Makefile +++ b/vta/hardware/xilinx/Makefile @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + # Directories ROOTDIR = $(CURDIR) BUILD_NAME = build diff --git a/vta/hardware/xilinx/README.md b/vta/hardware/xilinx/README.md index cd44c725711d..a49dae87cc3b 100644 --- a/vta/hardware/xilinx/README.md +++ b/vta/hardware/xilinx/README.md @@ -1 +1,18 @@ + + + + + + + + + + + + + + + + + Complete instructions on how to build custom FPGA hardware designs are available on the [TVM documentation webpage](https://docs.tvm.ai/vta/install.html#vta-fpga-toolchain-installation). \ No newline at end of file diff --git a/vta/hardware/xilinx/scripts/compile_designs.py b/vta/hardware/xilinx/scripts/compile_designs.py index a064a7198014..75995909dc84 100644 --- a/vta/hardware/xilinx/scripts/compile_designs.py +++ b/vta/hardware/xilinx/scripts/compile_designs.py @@ -1,4 +1,20 @@ #!/usr/bin/env python +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import argparse import datetime import logging @@ -196,9 +212,9 @@ def cli(): num_confs += 1 cmd = get_make_command(job, build_dir, conf, b, args.mode, args.slurm) sb_file = job+".sb" - file = open(sb_file,"w") + file = open(sb_file,"w") file.write(cmd) - file.close() + file.close() call(["echo", cmd]) if args.slurm: call(["sbatch", sb_file]) diff --git a/vta/hardware/xilinx/scripts/hls.tcl b/vta/hardware/xilinx/scripts/hls.tcl index 57efe9c28132..3d308bc58d25 100644 --- a/vta/hardware/xilinx/scripts/hls.tcl +++ b/vta/hardware/xilinx/scripts/hls.tcl @@ -1,217 +1,233 @@ -# -# Copyright (c) 2018 by Contributors -# file: hls.tcl -# brief: HLS generation script. -# - -# Command line arguments: -# Arg 1: path to design sources -# Arg 2: path to sim sources -# Arg 3: path to test sources -# Arg 4: path to include sources -# Arg 5: mode -# Arg 6: debug -# Arg 7: no_dsp -# Arg 8: no_alu -# Arg 9: target clock period -# Arg 10: input type width (log) -# Arg 11: weight type width (log) -# Arg 12: accum type width (log) -# Arg 13: output type width (log) -# Arg 14: batch size (log) -# Arg 15: in block size (log) -# Arg 16: out block size (log) -# Arg 17: uop buffer size in B (log) -# Arg 18: inp buffer size in B (log) -# Arg 19: wgt buffer size in B (log) -# Arg 20: acc buffer size in B (log) -# Arg 21: out buffer size in B (log) - -if { [llength $argv] eq 23 } { - set src_dir [lindex $argv 2] - set sim_dir [lindex $argv 3] - set test_dir [lindex $argv 4] - set include_dir [lindex $argv 5] - set mode [lindex $argv 6] - set debug [lindex $argv 7] - set no_dsp [lindex $argv 8] - set no_alu [lindex $argv 9] - set target_period [lindex $argv 10] - set inp_width [lindex $argv 11] - set wgt_width [lindex $argv 12] - set acc_width [lindex $argv 13] - set out_width [lindex $argv 14] - set batch [lindex $argv 15] - set block_in [lindex $argv 16] - set block_out [lindex $argv 17] - set uop_buff_size [lindex $argv 18] - set inp_buff_size [lindex $argv 19] - set wgt_buff_size [lindex $argv 20] - set acc_buff_size [lindex $argv 21] - set out_buff_size [lindex $argv 22] -} else { - set src_dir "../src" - set sim_dir "../sim" - set test_dir "../../src/test" - set include_dir "../../include" - set mode "all" - set debug "false" - set no_dsp "true" - set no_alu "false" - set target_period 10 - set inp_width 3 - set wgt_width 3 - set acc_width 5 - set out_width 3 - set batch 1 - set block_in 4 - set block_out 4 - set uop_buff_size 15 - set inp_buff_size 15 - set wgt_buff_size 15 - set acc_buff_size 17 - set out_buff_size 15 - exit -} - -# Initializes the HLS design and sets HLS pragmas for memory partitioning. -# This is necessary because of a Vivado restriction that doesn't allow for -# buses wider than 1024 bits. -proc init_design {per inp_width wgt_width out_width batch block_in block_out} { - - # Set device number - set_part {xc7z020clg484-1} - - # Set the clock frequency - create_clock -period $per -name default - - # Set input partition factor to (INP_VECTOR_WIDTH*BATCH/1024) - set inp_partition_factor [expr {(1 << ($inp_width + $block_in + $batch)) / 1024}] - if {$inp_partition_factor == 0} { - set_directive_array_reshape -type complete -dim 2 "load" inp_mem - set_directive_array_reshape -type complete -dim 2 "compute" inp_mem - } else { - # Set input reshaping factor below to (1024/INP_VECTOR_WIDTH) - set inp_reshape_factor [expr {1024 / (1 << ($inp_width + $block_in))}] - set_directive_array_partition -type block -factor $inp_partition_factor -dim 2 "load" inp_mem - set_directive_array_partition -type block -factor $inp_partition_factor -dim 2 "compute" inp_mem - set_directive_array_reshape -type block -factor $inp_reshape_factor -dim 2 "load" inp_mem - set_directive_array_reshape -type block -factor $inp_reshape_factor -dim 2 "compute" inp_mem - } - # Set weight partition factor to (WGT_VECTOR_WIDTH*BLOCK_OUT/1024) - set wgt_partition_factor [expr {(1 << ($wgt_width + $block_in + $block_out)) / 1024}] - if {$wgt_partition_factor == 0} { - set_directive_array_reshape -type complete -dim 2 "load" wgt_mem - set_directive_array_reshape -type complete -dim 2 "compute" wgt_mem - } else { - # Set weight reshaping factor below to (1024/WGT_VECTOR_WIDTH) - set wgt_reshape_factor [expr {1024 / (1 << ($wgt_width + $block_in))}] - set_directive_array_partition -type block -factor $wgt_partition_factor -dim 2 "load" wgt_mem - set_directive_array_partition -type block -factor $wgt_partition_factor -dim 2 "compute" wgt_mem - set_directive_array_reshape -type block -factor $wgt_reshape_factor -dim 2 "load" wgt_mem - set_directive_array_reshape -type block -factor $wgt_reshape_factor -dim 2 "compute" wgt_mem - } - # Set output partition factor to (OUT_VECTOR_WIDTH*BATCH/1024) - set out_partition_factor [expr {(1 << ($out_width + $block_out + $batch)) / 1024}] - if {$out_partition_factor == 0} { - set_directive_array_reshape -type complete -dim 2 "compute" out_mem - set_directive_array_reshape -type complete -dim 2 "store" out_mem - } else { - # Set output reshaping factor below to (1024/OUT_VECTOR_WIDTH) - set out_reshape_factor [expr {1024 / (1 << ($out_width + $block_out))}] - set_directive_array_partition -type block -factor $out_partition_factor -dim 2 "compute" out_mem - set_directive_array_partition -type block -factor $out_partition_factor -dim 2 "store" out_mem - set_directive_array_reshape -type block -factor $out_reshape_factor -dim 2 "compute" out_mem - set_directive_array_reshape -type block -factor $out_reshape_factor -dim 2 "store" out_mem - } -} - -# C define flags to pass to compiler -set cflags "-I $include_dir -I $src_dir -I $test_dir \ - -DVTA_LOG_WGT_WIDTH=$wgt_width -DVTA_LOG_INP_WIDTH=$inp_width \ - -DVTA_LOG_ACC_WIDTH=$acc_width -DVTA_LOG_OUT_WIDTH=$out_width \ - -DVTA_LOG_BATCH=$batch -DVTA_LOG_BLOCK_OUT=$block_out -DVTA_LOG_BLOCK_IN=$block_in \ - -DVTA_LOG_UOP_BUFF_SIZE=$uop_buff_size -DVTA_LOG_INP_BUFF_SIZE=$inp_buff_size \ - -DVTA_LOG_WGT_BUFF_SIZE=$wgt_buff_size -DVTA_LOG_ACC_BUFF_SIZE=$acc_buff_size \ - -DVTA_LOG_OUT_BUFF_SIZE=$out_buff_size" -if {$debug=="true"} { - append cflags " -DVTA_DEBUG=1" -} -if {$no_dsp=="true"} { - append cflags " -DNO_DSP" -} -if {$no_alu=="true"} { - append cflags " -DNO_ALU" -} - -# HLS behavioral sim -if {$mode=="all" || $mode=="sim"} { - open_project vta_sim - set_top vta - add_files $src_dir/vta.cc -cflags $cflags - add_files -tb $sim_dir/vta_test.cc -cflags $cflags - add_files -tb $test_dir/test_lib.cc -cflags $cflags - open_solution "solution0" - init_design $target_period $inp_width $wgt_width $out_width $batch $block_in $block_out - csim_design -clean - close_project -} - -# Generate fetch stage -if {$mode=="all" || $mode=="skip_sim" || $mode=="fetch"} { - open_project vta_fetch - set_top fetch - add_files $src_dir/vta.cc -cflags $cflags - open_solution "solution0" - init_design $target_period $inp_width $wgt_width $out_width $batch $block_in $block_out - csynth_design - if {$mode=="all" || $mode=="skip_sim"} { - export_design -format ip_catalog - } - close_project -} - -# Generate load stage -if {$mode=="all" || $mode=="skip_sim" || $mode=="load"} { - open_project vta_load - set_top load - add_files $src_dir/vta.cc -cflags $cflags - open_solution "solution0" - init_design $target_period $inp_width $wgt_width $out_width $batch $block_in $block_out - csynth_design - if {$mode=="all" || $mode=="skip_sim"} { - export_design -format ip_catalog - } - close_project -} - -# Generate compute stage -if {$mode=="all" || $mode=="skip_sim" || $mode=="compute"} { - open_project vta_compute - set_top compute - add_files $src_dir/vta.cc -cflags $cflags - open_solution "solution0" - init_design $target_period $inp_width $wgt_width $out_width $batch $block_in $block_out - csynth_design - if {$mode=="all" || $mode=="skip_sim"} { - export_design -format ip_catalog - } - close_project -} - -# Generate store stage -if {$mode=="all" || $mode=="skip_sim" || $mode=="store"} { - open_project vta_store - set_top store - add_files $src_dir/vta.cc -cflags $cflags - open_solution "solution0" - init_design $target_period $inp_width $wgt_width $out_width $batch $block_in $block_out - csynth_design - if {$mode=="all" || $mode=="skip_sim"} { - export_design -format ip_catalog - } - close_project -} - -exit - +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# Copyright (c) 2018 by Contributors +# file: hls.tcl +# brief: HLS generation script. +# + +# Command line arguments: +# Arg 1: path to design sources +# Arg 2: path to sim sources +# Arg 3: path to test sources +# Arg 4: path to include sources +# Arg 5: mode +# Arg 6: debug +# Arg 7: no_dsp +# Arg 8: no_alu +# Arg 9: target clock period +# Arg 10: input type width (log) +# Arg 11: weight type width (log) +# Arg 12: accum type width (log) +# Arg 13: output type width (log) +# Arg 14: batch size (log) +# Arg 15: in block size (log) +# Arg 16: out block size (log) +# Arg 17: uop buffer size in B (log) +# Arg 18: inp buffer size in B (log) +# Arg 19: wgt buffer size in B (log) +# Arg 20: acc buffer size in B (log) +# Arg 21: out buffer size in B (log) + +if { [llength $argv] eq 23 } { + set src_dir [lindex $argv 2] + set sim_dir [lindex $argv 3] + set test_dir [lindex $argv 4] + set include_dir [lindex $argv 5] + set mode [lindex $argv 6] + set debug [lindex $argv 7] + set no_dsp [lindex $argv 8] + set no_alu [lindex $argv 9] + set target_period [lindex $argv 10] + set inp_width [lindex $argv 11] + set wgt_width [lindex $argv 12] + set acc_width [lindex $argv 13] + set out_width [lindex $argv 14] + set batch [lindex $argv 15] + set block_in [lindex $argv 16] + set block_out [lindex $argv 17] + set uop_buff_size [lindex $argv 18] + set inp_buff_size [lindex $argv 19] + set wgt_buff_size [lindex $argv 20] + set acc_buff_size [lindex $argv 21] + set out_buff_size [lindex $argv 22] +} else { + set src_dir "../src" + set sim_dir "../sim" + set test_dir "../../src/test" + set include_dir "../../include" + set mode "all" + set debug "false" + set no_dsp "true" + set no_alu "false" + set target_period 10 + set inp_width 3 + set wgt_width 3 + set acc_width 5 + set out_width 3 + set batch 1 + set block_in 4 + set block_out 4 + set uop_buff_size 15 + set inp_buff_size 15 + set wgt_buff_size 15 + set acc_buff_size 17 + set out_buff_size 15 + exit +} + +# Initializes the HLS design and sets HLS pragmas for memory partitioning. +# This is necessary because of a Vivado restriction that doesn't allow for +# buses wider than 1024 bits. +proc init_design {per inp_width wgt_width out_width batch block_in block_out} { + + # Set device number + set_part {xc7z020clg484-1} + + # Set the clock frequency + create_clock -period $per -name default + + # Set input partition factor to (INP_VECTOR_WIDTH*BATCH/1024) + set inp_partition_factor [expr {(1 << ($inp_width + $block_in + $batch)) / 1024}] + if {$inp_partition_factor == 0} { + set_directive_array_reshape -type complete -dim 2 "load" inp_mem + set_directive_array_reshape -type complete -dim 2 "compute" inp_mem + } else { + # Set input reshaping factor below to (1024/INP_VECTOR_WIDTH) + set inp_reshape_factor [expr {1024 / (1 << ($inp_width + $block_in))}] + set_directive_array_partition -type block -factor $inp_partition_factor -dim 2 "load" inp_mem + set_directive_array_partition -type block -factor $inp_partition_factor -dim 2 "compute" inp_mem + set_directive_array_reshape -type block -factor $inp_reshape_factor -dim 2 "load" inp_mem + set_directive_array_reshape -type block -factor $inp_reshape_factor -dim 2 "compute" inp_mem + } + # Set weight partition factor to (WGT_VECTOR_WIDTH*BLOCK_OUT/1024) + set wgt_partition_factor [expr {(1 << ($wgt_width + $block_in + $block_out)) / 1024}] + if {$wgt_partition_factor == 0} { + set_directive_array_reshape -type complete -dim 2 "load" wgt_mem + set_directive_array_reshape -type complete -dim 2 "compute" wgt_mem + } else { + # Set weight reshaping factor below to (1024/WGT_VECTOR_WIDTH) + set wgt_reshape_factor [expr {1024 / (1 << ($wgt_width + $block_in))}] + set_directive_array_partition -type block -factor $wgt_partition_factor -dim 2 "load" wgt_mem + set_directive_array_partition -type block -factor $wgt_partition_factor -dim 2 "compute" wgt_mem + set_directive_array_reshape -type block -factor $wgt_reshape_factor -dim 2 "load" wgt_mem + set_directive_array_reshape -type block -factor $wgt_reshape_factor -dim 2 "compute" wgt_mem + } + # Set output partition factor to (OUT_VECTOR_WIDTH*BATCH/1024) + set out_partition_factor [expr {(1 << ($out_width + $block_out + $batch)) / 1024}] + if {$out_partition_factor == 0} { + set_directive_array_reshape -type complete -dim 2 "compute" out_mem + set_directive_array_reshape -type complete -dim 2 "store" out_mem + } else { + # Set output reshaping factor below to (1024/OUT_VECTOR_WIDTH) + set out_reshape_factor [expr {1024 / (1 << ($out_width + $block_out))}] + set_directive_array_partition -type block -factor $out_partition_factor -dim 2 "compute" out_mem + set_directive_array_partition -type block -factor $out_partition_factor -dim 2 "store" out_mem + set_directive_array_reshape -type block -factor $out_reshape_factor -dim 2 "compute" out_mem + set_directive_array_reshape -type block -factor $out_reshape_factor -dim 2 "store" out_mem + } +} + +# C define flags to pass to compiler +set cflags "-I $include_dir -I $src_dir -I $test_dir \ + -DVTA_LOG_WGT_WIDTH=$wgt_width -DVTA_LOG_INP_WIDTH=$inp_width \ + -DVTA_LOG_ACC_WIDTH=$acc_width -DVTA_LOG_OUT_WIDTH=$out_width \ + -DVTA_LOG_BATCH=$batch -DVTA_LOG_BLOCK_OUT=$block_out -DVTA_LOG_BLOCK_IN=$block_in \ + -DVTA_LOG_UOP_BUFF_SIZE=$uop_buff_size -DVTA_LOG_INP_BUFF_SIZE=$inp_buff_size \ + -DVTA_LOG_WGT_BUFF_SIZE=$wgt_buff_size -DVTA_LOG_ACC_BUFF_SIZE=$acc_buff_size \ + -DVTA_LOG_OUT_BUFF_SIZE=$out_buff_size" +if {$debug=="true"} { + append cflags " -DVTA_DEBUG=1" +} +if {$no_dsp=="true"} { + append cflags " -DNO_DSP" +} +if {$no_alu=="true"} { + append cflags " -DNO_ALU" +} + +# HLS behavioral sim +if {$mode=="all" || $mode=="sim"} { + open_project vta_sim + set_top vta + add_files $src_dir/vta.cc -cflags $cflags + add_files -tb $sim_dir/vta_test.cc -cflags $cflags + add_files -tb $test_dir/test_lib.cc -cflags $cflags + open_solution "solution0" + init_design $target_period $inp_width $wgt_width $out_width $batch $block_in $block_out + csim_design -clean + close_project +} + +# Generate fetch stage +if {$mode=="all" || $mode=="skip_sim" || $mode=="fetch"} { + open_project vta_fetch + set_top fetch + add_files $src_dir/vta.cc -cflags $cflags + open_solution "solution0" + init_design $target_period $inp_width $wgt_width $out_width $batch $block_in $block_out + csynth_design + if {$mode=="all" || $mode=="skip_sim"} { + export_design -format ip_catalog + } + close_project +} + +# Generate load stage +if {$mode=="all" || $mode=="skip_sim" || $mode=="load"} { + open_project vta_load + set_top load + add_files $src_dir/vta.cc -cflags $cflags + open_solution "solution0" + init_design $target_period $inp_width $wgt_width $out_width $batch $block_in $block_out + csynth_design + if {$mode=="all" || $mode=="skip_sim"} { + export_design -format ip_catalog + } + close_project +} + +# Generate compute stage +if {$mode=="all" || $mode=="skip_sim" || $mode=="compute"} { + open_project vta_compute + set_top compute + add_files $src_dir/vta.cc -cflags $cflags + open_solution "solution0" + init_design $target_period $inp_width $wgt_width $out_width $batch $block_in $block_out + csynth_design + if {$mode=="all" || $mode=="skip_sim"} { + export_design -format ip_catalog + } + close_project +} + +# Generate store stage +if {$mode=="all" || $mode=="skip_sim" || $mode=="store"} { + open_project vta_store + set_top store + add_files $src_dir/vta.cc -cflags $cflags + open_solution "solution0" + init_design $target_period $inp_width $wgt_width $out_width $batch $block_in $block_out + csynth_design + if {$mode=="all" || $mode=="skip_sim"} { + export_design -format ip_catalog + } + close_project +} + +exit + diff --git a/vta/hardware/xilinx/scripts/hsi.tcl b/vta/hardware/xilinx/scripts/hsi.tcl index 1567b078a3e4..bbe3f67d1601 100644 --- a/vta/hardware/xilinx/scripts/hsi.tcl +++ b/vta/hardware/xilinx/scripts/hsi.tcl @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # # Copyright (c) 2018 by Contributors # file: hsi.tcl diff --git a/vta/hardware/xilinx/scripts/vivado.tcl b/vta/hardware/xilinx/scripts/vivado.tcl index b519d540bd4e..9cfa10ea7482 100644 --- a/vta/hardware/xilinx/scripts/vivado.tcl +++ b/vta/hardware/xilinx/scripts/vivado.tcl @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. # # Copyright (c) 2018 by Xilinx, Contributors # file: vivado.tcl diff --git a/vta/hardware/xilinx/sim/vta_test.cc b/vta/hardware/xilinx/sim/vta_test.cc index e1c28834a691..d21d121a8ddb 100644 --- a/vta/hardware/xilinx/sim/vta_test.cc +++ b/vta/hardware/xilinx/sim/vta_test.cc @@ -1,60 +1,79 @@ -/*! - * Copyright (c) 2018 by Contributors - * \file vta_test.cpp - * \brief Simulation tests for the VTA design. - */ - -#include -#include -#include - -#include "../src/vta.h" -#include "../../../tests/hardware/common/test_lib.h" - -int main(void) { -#if DEBUG == 1 - printParameters(); -#endif - - // Micro op bound - assert(VTA_UOP_GEM_2_1 < VTA_UOP_WIDTH); - assert(VTA_UOP_ALU_1_1 < VTA_UOP_WIDTH); - // Make sure there is no misaligment - assert(VTA_INSN_GEM_9_1 < VTA_INSN_GEM_A_0); - assert(VTA_INSN_MEM_7_1 < VTA_INSN_MEM_8_0); - // Instruction bounds - assert(VTA_INSN_MEM_E_1 < VTA_INS_WIDTH); - assert(VTA_INSN_GEM_F_1 < VTA_INS_WIDTH); - assert(VTA_INSN_ALU_G_1 < VTA_INS_WIDTH); - - int status = 0; - - // Run ALU test (vector-scalar operators) - status |= alu_test(VTA_ALU_OPCODE_MIN, true, VTA_BLOCK_OUT, 128, true); - status |= alu_test(VTA_ALU_OPCODE_MIN, true, VTA_BLOCK_OUT, 128, false); - status |= alu_test(VTA_ALU_OPCODE_MAX, true, VTA_BLOCK_OUT, 128, true); - status |= alu_test(VTA_ALU_OPCODE_MAX, true, VTA_BLOCK_OUT, 128, false); - status |= alu_test(VTA_ALU_OPCODE_ADD, true, VTA_BLOCK_OUT, 128, true); - status |= alu_test(VTA_ALU_OPCODE_ADD, true, VTA_BLOCK_OUT, 128, false); - status |= alu_test(VTA_ALU_OPCODE_SHR, true, VTA_BLOCK_OUT, 128, true); - status |= alu_test(VTA_ALU_OPCODE_SHR, true, VTA_BLOCK_OUT, 128, false); - - // Run ALU test (vector-vector operators) - status |= alu_test(VTA_ALU_OPCODE_MIN, false, VTA_BLOCK_OUT, 128, true); - status |= alu_test(VTA_ALU_OPCODE_MIN, false, VTA_BLOCK_OUT, 128, false); - status |= alu_test(VTA_ALU_OPCODE_MAX, false, VTA_BLOCK_OUT, 128, true); - status |= alu_test(VTA_ALU_OPCODE_MAX, false, VTA_BLOCK_OUT, 128, false); - status |= alu_test(VTA_ALU_OPCODE_ADD, false, VTA_BLOCK_OUT, 128, true); - status |= alu_test(VTA_ALU_OPCODE_ADD, false, VTA_BLOCK_OUT, 128, false); - - // Run blocked GEMM test - status |= blocked_gemm_test(256, 256, VTA_BLOCK_OUT*4, true, 2); - status |= blocked_gemm_test(256, 256, VTA_BLOCK_OUT*4, false, 2); - status |= blocked_gemm_test(256, 256, VTA_BLOCK_OUT*4, true, 1); - status |= blocked_gemm_test(256, 256, VTA_BLOCK_OUT*4, false, 1); - - // Simple GEMM unit test - status |= gemm_test(64, 64, 64, true); - - return status; -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2018 by Contributors + * \file vta_test.cpp + * \brief Simulation tests for the VTA design. + */ + +#include +#include +#include + +#include "../src/vta.h" +#include "../../../tests/hardware/common/test_lib.h" + +int main(void) { +#if DEBUG == 1 + printParameters(); +#endif + + // Micro op bound + assert(VTA_UOP_GEM_2_1 < VTA_UOP_WIDTH); + assert(VTA_UOP_ALU_1_1 < VTA_UOP_WIDTH); + // Make sure there is no misaligment + assert(VTA_INSN_GEM_9_1 < VTA_INSN_GEM_A_0); + assert(VTA_INSN_MEM_7_1 < VTA_INSN_MEM_8_0); + // Instruction bounds + assert(VTA_INSN_MEM_E_1 < VTA_INS_WIDTH); + assert(VTA_INSN_GEM_F_1 < VTA_INS_WIDTH); + assert(VTA_INSN_ALU_G_1 < VTA_INS_WIDTH); + + int status = 0; + + // Run ALU test (vector-scalar operators) + status |= alu_test(VTA_ALU_OPCODE_MIN, true, VTA_BLOCK_OUT, 128, true); + status |= alu_test(VTA_ALU_OPCODE_MIN, true, VTA_BLOCK_OUT, 128, false); + status |= alu_test(VTA_ALU_OPCODE_MAX, true, VTA_BLOCK_OUT, 128, true); + status |= alu_test(VTA_ALU_OPCODE_MAX, true, VTA_BLOCK_OUT, 128, false); + status |= alu_test(VTA_ALU_OPCODE_ADD, true, VTA_BLOCK_OUT, 128, true); + status |= alu_test(VTA_ALU_OPCODE_ADD, true, VTA_BLOCK_OUT, 128, false); + status |= alu_test(VTA_ALU_OPCODE_SHR, true, VTA_BLOCK_OUT, 128, true); + status |= alu_test(VTA_ALU_OPCODE_SHR, true, VTA_BLOCK_OUT, 128, false); + + // Run ALU test (vector-vector operators) + status |= alu_test(VTA_ALU_OPCODE_MIN, false, VTA_BLOCK_OUT, 128, true); + status |= alu_test(VTA_ALU_OPCODE_MIN, false, VTA_BLOCK_OUT, 128, false); + status |= alu_test(VTA_ALU_OPCODE_MAX, false, VTA_BLOCK_OUT, 128, true); + status |= alu_test(VTA_ALU_OPCODE_MAX, false, VTA_BLOCK_OUT, 128, false); + status |= alu_test(VTA_ALU_OPCODE_ADD, false, VTA_BLOCK_OUT, 128, true); + status |= alu_test(VTA_ALU_OPCODE_ADD, false, VTA_BLOCK_OUT, 128, false); + + // Run blocked GEMM test + status |= blocked_gemm_test(256, 256, VTA_BLOCK_OUT*4, true, 2); + status |= blocked_gemm_test(256, 256, VTA_BLOCK_OUT*4, false, 2); + status |= blocked_gemm_test(256, 256, VTA_BLOCK_OUT*4, true, 1); + status |= blocked_gemm_test(256, 256, VTA_BLOCK_OUT*4, false, 1); + + // Simple GEMM unit test + status |= gemm_test(64, 64, 64, true); + + return status; +} diff --git a/vta/hardware/xilinx/src/vta.cc b/vta/hardware/xilinx/src/vta.cc index 5ca2cec6575d..da8ea7435a90 100644 --- a/vta/hardware/xilinx/src/vta.cc +++ b/vta/hardware/xilinx/src/vta.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file vta.cpp diff --git a/vta/hardware/xilinx/src/vta.h b/vta/hardware/xilinx/src/vta.h index 6118f867fd0c..6480debbe4f9 100644 --- a/vta/hardware/xilinx/src/vta.h +++ b/vta/hardware/xilinx/src/vta.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file vta.h diff --git a/vta/include/vta/driver.h b/vta/include/vta/driver.h index 588819a5fe6b..ed041853b117 100644 --- a/vta/include/vta/driver.h +++ b/vta/include/vta/driver.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file driver.h diff --git a/vta/include/vta/hw_spec.h b/vta/include/vta/hw_spec.h index 5bcd44c16bdf..36b0a5d26b3b 100644 --- a/vta/include/vta/hw_spec.h +++ b/vta/include/vta/hw_spec.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file hw_spec.h diff --git a/vta/include/vta/runtime.h b/vta/include/vta/runtime.h index 5af915696134..e19e1ab87aa7 100644 --- a/vta/include/vta/runtime.h +++ b/vta/include/vta/runtime.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file runtime.h diff --git a/vta/python/vta/bitstream.py b/vta/python/vta/bitstream.py index 329e741f7d1c..7c5ee5523e38 100644 --- a/vta/python/vta/bitstream.py +++ b/vta/python/vta/bitstream.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """VTA specific bitstream management library.""" from __future__ import absolute_import as _abs diff --git a/vta/python/vta/build_module.py b/vta/python/vta/build_module.py index e6804aa53191..471dc90746de 100644 --- a/vta/python/vta/build_module.py +++ b/vta/python/vta/build_module.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """VTA specific buildin for runtime.""" from __future__ import absolute_import as _abs diff --git a/vta/python/vta/environment.py b/vta/python/vta/environment.py index 3a145be590d5..d5400d868ae4 100644 --- a/vta/python/vta/environment.py +++ b/vta/python/vta/environment.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Configurable VTA Hareware Environment scope.""" # pylint: disable=invalid-name from __future__ import absolute_import as _abs diff --git a/vta/python/vta/exec/rpc_server.py b/vta/python/vta/exec/rpc_server.py index c318e2dd5178..5ca5d596a007 100644 --- a/vta/python/vta/exec/rpc_server.py +++ b/vta/python/vta/exec/rpc_server.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """VTA customized TVM RPC Server Provides additional runtime function and library loading. diff --git a/vta/python/vta/graph.py b/vta/python/vta/graph.py index 0b746e0458af..1a626eeb888c 100644 --- a/vta/python/vta/graph.py +++ b/vta/python/vta/graph.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Graph transformation specific to accelerator. This module provide specific NNVM graph transformations diff --git a/vta/python/vta/intrin.py b/vta/python/vta/intrin.py index 8255b8b7df2e..77c7ff2e8315 100644 --- a/vta/python/vta/intrin.py +++ b/vta/python/vta/intrin.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """VTA related intrinsics""" from __future__ import absolute_import as _abs diff --git a/vta/python/vta/ir_pass.py b/vta/python/vta/ir_pass.py index 9800cc6472b3..5484fbe43807 100644 --- a/vta/python/vta/ir_pass.py +++ b/vta/python/vta/ir_pass.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Additional IR Pass for VTA""" # pylint: disable=len-as-condition from __future__ import absolute_import as _abs diff --git a/vta/python/vta/libinfo.py b/vta/python/vta/libinfo.py index f7de9c55b1a0..19f9d3047ebc 100644 --- a/vta/python/vta/libinfo.py +++ b/vta/python/vta/libinfo.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Library information.""" from __future__ import absolute_import import sys diff --git a/vta/python/vta/pkg_config.py b/vta/python/vta/pkg_config.py index 30b4808f5e2d..3b2824765010 100644 --- a/vta/python/vta/pkg_config.py +++ b/vta/python/vta/pkg_config.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """VTA Package configuration module This module is dependency free and can be used to configure package. diff --git a/vta/python/vta/rpc_client.py b/vta/python/vta/rpc_client.py index 999250cd789d..a5bafab498a5 100644 --- a/vta/python/vta/rpc_client.py +++ b/vta/python/vta/rpc_client.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """VTA RPC client function""" import os diff --git a/vta/python/vta/testing/simulator.py b/vta/python/vta/testing/simulator.py index 5695c9419c8b..a1e15ba69880 100644 --- a/vta/python/vta/testing/simulator.py +++ b/vta/python/vta/testing/simulator.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Utilities to start simulator.""" import ctypes import json diff --git a/vta/python/vta/testing/util.py b/vta/python/vta/testing/util.py index c01d206e9126..48dd08588962 100644 --- a/vta/python/vta/testing/util.py +++ b/vta/python/vta/testing/util.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Test Utilities""" from __future__ import absolute_import as _abs diff --git a/vta/python/vta/top/arm_conv2d.py b/vta/python/vta/top/arm_conv2d.py index 634348a87cfe..6e34917c0b71 100644 --- a/vta/python/vta/top/arm_conv2d.py +++ b/vta/python/vta/top/arm_conv2d.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Reuse conv2d schedule from ARM CPU""" import tvm diff --git a/vta/python/vta/top/vta_conv2d.py b/vta/python/vta/top/vta_conv2d.py index 2fd11a887da0..9d0d3dfe3d72 100644 --- a/vta/python/vta/top/vta_conv2d.py +++ b/vta/python/vta/top/vta_conv2d.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Namespace for supporting packed_conv2d + ewise variant of nnvm.""" from __future__ import absolute_import as _abs diff --git a/vta/src/device_api.cc b/vta/src/device_api.cc index a2729baa2591..3da9f01011a4 100644 --- a/vta/src/device_api.cc +++ b/vta/src/device_api.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file device_api.cc diff --git a/vta/src/pynq/pynq_driver.cc b/vta/src/pynq/pynq_driver.cc index 5c597d918b5f..be9d0fe26dd8 100644 --- a/vta/src/pynq/pynq_driver.cc +++ b/vta/src/pynq/pynq_driver.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file pynq_driver.c diff --git a/vta/src/pynq/pynq_driver.h b/vta/src/pynq/pynq_driver.h index 4a0b03ac25bd..61ff7f2c91b5 100644 --- a/vta/src/pynq/pynq_driver.h +++ b/vta/src/pynq/pynq_driver.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file vta_pynq_driver.h diff --git a/vta/src/runtime.cc b/vta/src/runtime.cc index b2d5abfc1b6e..9c8de1aaae5e 100644 --- a/vta/src/runtime.cc +++ b/vta/src/runtime.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file runtime.cc diff --git a/vta/src/sim/sim_driver.cc b/vta/src/sim/sim_driver.cc index 60645818757c..803a54d6b96a 100644 --- a/vta/src/sim/sim_driver.cc +++ b/vta/src/sim/sim_driver.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file sim_driver.cc diff --git a/vta/tests/hardware/common/test_lib.cc b/vta/tests/hardware/common/test_lib.cc index 98b5f9a030b9..291016a4ef3f 100644 --- a/vta/tests/hardware/common/test_lib.cc +++ b/vta/tests/hardware/common/test_lib.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file test_lib.cpp diff --git a/vta/tests/hardware/common/test_lib.h b/vta/tests/hardware/common/test_lib.h index 0e8f30df7d92..611aa60db0b7 100644 --- a/vta/tests/hardware/common/test_lib.h +++ b/vta/tests/hardware/common/test_lib.h @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file test_lib.cpp diff --git a/vta/tests/hardware/metal_test/Makefile b/vta/tests/hardware/metal_test/Makefile index 4174b4e4726d..67563f324734 100644 --- a/vta/tests/hardware/metal_test/Makefile +++ b/vta/tests/hardware/metal_test/Makefile @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + CC ?= g++ CFLAGS = -Wall -O3 -std=c++11 -I/usr/include LDFLAGS = -L/usr/lib -L/opt/python3.6/lib/python3.6/site-packages/pynq/lib/ diff --git a/vta/tests/hardware/metal_test/metal_test.cc b/vta/tests/hardware/metal_test/metal_test.cc index 48d719ff4b32..9c4600716996 100644 --- a/vta/tests/hardware/metal_test/metal_test.cc +++ b/vta/tests/hardware/metal_test/metal_test.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2018 by Contributors * \file metal_test.cpp diff --git a/vta/tests/python/integration/test_benchmark_gemm.py b/vta/tests/python/integration/test_benchmark_gemm.py index da867c9b8270..7a36352be076 100644 --- a/vta/tests/python/integration/test_benchmark_gemm.py +++ b/vta/tests/python/integration/test_benchmark_gemm.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import tvm import numpy as np from tvm.contrib import util diff --git a/vta/tests/python/integration/test_benchmark_topi_conv2d.py b/vta/tests/python/integration/test_benchmark_topi_conv2d.py index 6915ff8285ba..8a03cb020260 100644 --- a/vta/tests/python/integration/test_benchmark_topi_conv2d.py +++ b/vta/tests/python/integration/test_benchmark_topi_conv2d.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Testing if we can generate code in topi style""" import tvm diff --git a/vta/tests/python/pynq/test_program_rpc.py b/vta/tests/python/pynq/test_program_rpc.py index 3bccb963bb67..a7ef6f28cc50 100644 --- a/vta/tests/python/pynq/test_program_rpc.py +++ b/vta/tests/python/pynq/test_program_rpc.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import os import tvm from tvm import rpc diff --git a/vta/tests/python/unittest/test_environment.py b/vta/tests/python/unittest/test_environment.py index 9d6597abe200..d5f7a6f43be9 100644 --- a/vta/tests/python/unittest/test_environment.py +++ b/vta/tests/python/unittest/test_environment.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. import vta diff --git a/vta/tests/python/unittest/test_vta_insn.py b/vta/tests/python/unittest/test_vta_insn.py index b9803684b22f..58835bbe3eab 100644 --- a/vta/tests/python/unittest/test_vta_insn.py +++ b/vta/tests/python/unittest/test_vta_insn.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """Unit test VTA's instructions """ import tvm import numpy as np diff --git a/vta/tutorials/convolution_opt.py b/vta/tutorials/convolution_opt.py index f4d3997b0146..67b589550742 100644 --- a/vta/tutorials/convolution_opt.py +++ b/vta/tutorials/convolution_opt.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ 2D Convolution Optimization =========================== diff --git a/vta/tutorials/matrix_multiply.py b/vta/tutorials/matrix_multiply.py index 4c8e716ff665..bf3960be4281 100644 --- a/vta/tutorials/matrix_multiply.py +++ b/vta/tutorials/matrix_multiply.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ .. _basic-mat-mult: diff --git a/vta/tutorials/matrix_multiply_opt.py b/vta/tutorials/matrix_multiply_opt.py index 4e1f4167f84b..10ba770f9f37 100644 --- a/vta/tutorials/matrix_multiply_opt.py +++ b/vta/tutorials/matrix_multiply_opt.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ .. _vta-mat-mult-opt: diff --git a/vta/tutorials/resnet.py b/vta/tutorials/resnet.py index 45bd9edf3ad5..df3bb0607284 100644 --- a/vta/tutorials/resnet.py +++ b/vta/tutorials/resnet.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ ResNet Inference Example ======================== diff --git a/vta/tutorials/vta_get_started.py b/vta/tutorials/vta_get_started.py index 73f6e2bd5472..93a0add50a87 100644 --- a/vta/tutorials/vta_get_started.py +++ b/vta/tutorials/vta_get_started.py @@ -1,3 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. """ .. _vta-get-started: diff --git a/web/.eslintrc.js b/web/.eslintrc.js index e331d8d574d5..2e82ba50e3c4 100644 --- a/web/.eslintrc.js +++ b/web/.eslintrc.js @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + module.exports = { "env": { "browser": true, diff --git a/web/README.md b/web/README.md index c6b7065c15f8..ddefe9a4f324 100644 --- a/web/README.md +++ b/web/README.md @@ -1,3 +1,20 @@ + + + + + + + + + + + + + + + + + # TVM WebAssembly and Javascript Backend This folder contains TVM WebAssembly and Javascript backend through Emscripten. diff --git a/web/example_rpc_node.js b/web/example_rpc_node.js index 300c6ea4d2f9..45f917a3234b 100644 --- a/web/example_rpc_node.js +++ b/web/example_rpc_node.js @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + // Javascript RPC server example // Start and connect to websocket proxy. diff --git a/web/tvm_runtime.js b/web/tvm_runtime.js index fe303d57b0c6..a336a802b80f 100644 --- a/web/tvm_runtime.js +++ b/web/tvm_runtime.js @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /** * TVM Javascript web runtime library. * diff --git a/web/web_runtime.cc b/web/web_runtime.cc index f556d190c3d4..273d43b38f22 100644 --- a/web/web_runtime.cc +++ b/web/web_runtime.cc @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /*! * Copyright (c) 2017 by Contributors * \file web_runtime.cc