Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[RUNTIME] Implement TVMDSOOp(TensorFlow custom op) for TVM runtime #4459

Merged
merged 44 commits into from
Apr 7, 2020

Conversation

tobegit3hub
Copy link
Contributor

@tobegit3hub tobegit3hub commented Dec 3, 2019

RFC: #4464 .

This PR contains three parts to achieve the goal to run TVM op in TensorFlow.

  1. The kernel and definition of TensorFlow custom op.
  2. The Python package in tvm.contrib to load TVMDSOOp easily.
  3. The config and CMake file to build TVMDSOOp easily.

@tobegit3hub
Copy link
Contributor Author

It would be great if @tqchen would help to review this.

@tobegit3hub tobegit3hub changed the title [WIP] Implement TVMDSOOp(TensorFlow custom op) for TVM runtime Implement TVMDSOOp(TensorFlow custom op) for TVM runtime Dec 4, 2019
@tqchen
Copy link
Member

tqchen commented Dec 19, 2019

@tobegit3hub please fix the lint error. @soiferj @jwfromm @zhiics @FrozenGene would be great if you can help review this pr

@tqchen tqchen changed the title Implement TVMDSOOp(TensorFlow custom op) for TVM runtime [RUNTIME] Implement TVMDSOOp(TensorFlow custom op) for TVM runtime Dec 19, 2019
@zhiics
Copy link
Member

zhiics commented Dec 19, 2019

Sure. I will do a pass by tomorrow.

CMakeLists.txt Outdated Show resolved Hide resolved
cmake/modules/contrib/TFOP.cmake Outdated Show resolved Hide resolved
cmake/modules/contrib/TFOP.cmake Outdated Show resolved Hide resolved
cmake/modules/contrib/TFOP.cmake Outdated Show resolved Hide resolved
python/tvm/contrib/tf_op/module.py Outdated Show resolved Hide resolved
python/tvm/contrib/tf_op/module.py Outdated Show resolved Hide resolved
src/contrib/tf_op/tvm_dso_op_kernels.cc Outdated Show resolved Hide resolved
src/contrib/tf_op/tvm_dso_op_kernels.cc Outdated Show resolved Hide resolved
src/contrib/tf_op/tvm_dso_op_kernels.cc Outdated Show resolved Hide resolved
src/contrib/tf_op/tvm_dso_op_kernels.cc Outdated Show resolved Hide resolved
Copy link
Member

@zhiics zhiics left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am half way done. Will spend some time on the remaining files. Some high level comments/questions are:

  • Style, please make sure you keep consistent to the currently code style in TVM. For example, indentation for Python and C++, number of blank lines between functions, etc.
  • Naming, we might need to debate a bit about TVMDSOOp
  • Testing, please add some unit tests. I think we need both Python tests and gtest.
  • I've finished reviewing, but I am wondering how dynamic shape is handled?

python/tvm/contrib/tf_op/module.py Outdated Show resolved Hide resolved
python/tvm/contrib/tf_op/module.py Outdated Show resolved Hide resolved
python/tvm/contrib/tf_op/module.py Outdated Show resolved Hide resolved
python/tvm/contrib/tf_op/module.py Outdated Show resolved Hide resolved
src/contrib/tf_op/index_seq.h Outdated Show resolved Hide resolved
src/contrib/tf_op/tvm_dso_op_kernels.cc Outdated Show resolved Hide resolved
src/contrib/tf_op/tvm_dso_op_kernels.cc Outdated Show resolved Hide resolved
src/contrib/tf_op/tvm_dso_op_kernels.cc Outdated Show resolved Hide resolved
src/contrib/tf_op/tvm_dso_op_kernels.cc Outdated Show resolved Hide resolved
src/contrib/tf_op/index_seq.h Outdated Show resolved Hide resolved
@tobegit3hub
Copy link
Contributor Author

tobegit3hub commented Dec 23, 2019

Thanks @FrozenGene and @zhiics . We will fix for these comments soon.

Since TensorFlow allow custom operators to accept dynamic shape whose first dimension is -1, we can get the actual input dimension from input tensor in kernel compute function. The output dimension should be specified by users. Now we support specifying the fixed dimension or pass the shape op which is the transformation of input tensor.

CMakeLists.txt Outdated Show resolved Hide resolved
src/contrib/tf_op/tvm_dso_op_kernels.cc Outdated Show resolved Hide resolved
src/contrib/tf_op/tvm_dso_op_kernels.cc Show resolved Hide resolved
@tqchen tqchen added the status: need update need update based on feedbacks label Jan 5, 2020
tobegit3hub and others added 2 commits January 6, 2020 18:25
feat: Update tf tvmdso op by review comments

See merge request internal-open-source/incubator-tvm!2
baoxinqi and others added 2 commits January 16, 2020 16:24
fix: Update with pr comments

See merge request internal-open-source/incubator-tvm!3
baoxinqi and others added 2 commits January 16, 2020 17:30
fix: Fix lint

See merge request internal-open-source/incubator-tvm!4
@tobegit3hub
Copy link
Contributor Author

Hi @zhiics and @FrozenGene , we have updated the code for the comments. Would you like to review again when you are free?

@wrongtest-intellif
Copy link
Contributor

Hi @zhiics, we have updated the code for the comments. Would you like to review again when you are free? 8ac182f

@zhiics
Copy link
Member

zhiics commented Apr 2, 2020

I think @gmagogsfm had a concern about the variable number of inputs/outputs, has this been fixed?

@wrongtest-intellif
Copy link
Contributor

Oh I miss it. @gmagogsfm remind a nice mechanism in TF to handle variable number of input tensors which will greatly simplify the current op definitions.

I tend to make it in next PR, because currently we rely on template argument
NUM_INPUTS to invoke variadic TVM function with array typed input arguments. If we use input: list(T) to define variable inputs, we have to get another way to do the invocation. Any suggestions for this improvement @tobegit3hub ?

@gmagogsfm
Copy link

@wrongtest
You can invoke TVM packed func with a variadic number of inputs with TVMArgsSetter

https://github.com/apache/incubator-tvm/blob/e0122c0ea68043372220e4e02b81692c34832227/src/runtime/contrib/example_ext_runtime/example_ext_runtime.cc#L191

Let me know if you have other questions, happy to help.

@wrongtest-intellif
Copy link
Contributor

Thanks for your help! We update the code and now there is no need to define different op for different input args. @gmagogsfm

@zhiics
Copy link
Member

zhiics commented Apr 3, 2020

I will do a final round review in the next couple of days. I think overall it looks good to me now. @tqchen can you also take a look?

cmake/config.cmake Outdated Show resolved Hide resolved
Copy link
Member

@zhiics zhiics left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the effort. LGTM. Let's follow up in separate PRs and see how we can enable the tests to help ppl to try it out.

@FrozenGene
Copy link
Member

I will review it one round today. If no other comment, I will approve today.

@FrozenGene
Copy link
Member

Wish we have one doc / tutorial to instruct users how to use this feature in the next pr.

@tqchen tqchen merged commit 53a4ad3 into apache:master Apr 7, 2020
@tqchen
Copy link
Member

tqchen commented Apr 8, 2020

Thanks @tobegit3hub @FrozenGene @zhiics @soiferj @wrongtest @gmagogsfm @yzhliu . This PR is now merged

@tqchen tqchen added status: accepted and removed status: need review status: need test case need test cases to cover the change status: need update need update based on feedbacks labels Apr 8, 2020
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Apr 16, 2020
…pache#4459)

* Add implementation of TVMDSOOp

* feat: Update cmake script to work with c++11 and in-repo build

* feat: Use libtvm as oplib dependency

* fix: Add missing link dependency to libtvm

* feat: Update tf tvmdso op by review comments

* fix: Update with pr comments

* fix: Fix lint

* feat: Add test script and fix gpu shape

* feat: Add test script and fix gpu shape

* fix: Conditional build tftvm op for gpu

* fix: Conditional build tftvm op for gpu

* fix: Fix pylint of tf_op module.py

* fix: Fix pylint of tf_op module.py

* feat: Conditional enable gpu test for tftvm op

* feat: Conditional enable gpu test for tftvm op

* feat: Add tf_tvmdsoop test script as an app test

* fix: Fix gpu/cpu enabled check on tvm in test script

* fix: Make tf tvmdso op test script runnable with pytest

* remove unused test script test_tfop_module.py

* fix: Remove pushd & popd in tfdsoop test script

* fix: Upgrade tftvmop use python3 to find TensorFlow

* fix: Upgrade tftvmop use python3 to find TensorFlow

* fix: Change target_link_options to target_link_libraries

* fix: Add tftvmop build script's c++ option

* fix: Add tvm library path to tf op test library path

* fix: Debug ci build for tftvm dso op

* fix: Fix cmake error and skip tfop test

* fix: Fix typo and indentation issues

* feat: Use TF list input op def

* fix: Fix style and unexpected changes

Co-authored-by: baoxinqi <baoxinqi@4paradigm.com>
Co-authored-by: Chen Dihao <chendihao@4paradigm.com>
Co-authored-by: wrongtest <wrongtest@4paradigm.com>
zhiics pushed a commit to neo-ai/tvm that referenced this pull request Apr 17, 2020
…pache#4459)

* Add implementation of TVMDSOOp

* feat: Update cmake script to work with c++11 and in-repo build

* feat: Use libtvm as oplib dependency

* fix: Add missing link dependency to libtvm

* feat: Update tf tvmdso op by review comments

* fix: Update with pr comments

* fix: Fix lint

* feat: Add test script and fix gpu shape

* feat: Add test script and fix gpu shape

* fix: Conditional build tftvm op for gpu

* fix: Conditional build tftvm op for gpu

* fix: Fix pylint of tf_op module.py

* fix: Fix pylint of tf_op module.py

* feat: Conditional enable gpu test for tftvm op

* feat: Conditional enable gpu test for tftvm op

* feat: Add tf_tvmdsoop test script as an app test

* fix: Fix gpu/cpu enabled check on tvm in test script

* fix: Make tf tvmdso op test script runnable with pytest

* remove unused test script test_tfop_module.py

* fix: Remove pushd & popd in tfdsoop test script

* fix: Upgrade tftvmop use python3 to find TensorFlow

* fix: Upgrade tftvmop use python3 to find TensorFlow

* fix: Change target_link_options to target_link_libraries

* fix: Add tftvmop build script's c++ option

* fix: Add tvm library path to tf op test library path

* fix: Debug ci build for tftvm dso op

* fix: Fix cmake error and skip tfop test

* fix: Fix typo and indentation issues

* feat: Use TF list input op def

* fix: Fix style and unexpected changes

Co-authored-by: baoxinqi <baoxinqi@4paradigm.com>
Co-authored-by: Chen Dihao <chendihao@4paradigm.com>
Co-authored-by: wrongtest <wrongtest@4paradigm.com>
dpankratz pushed a commit to dpankratz/incubator-tvm that referenced this pull request Apr 24, 2020
…pache#4459)

* Add implementation of TVMDSOOp

* feat: Update cmake script to work with c++11 and in-repo build

* feat: Use libtvm as oplib dependency

* fix: Add missing link dependency to libtvm

* feat: Update tf tvmdso op by review comments

* fix: Update with pr comments

* fix: Fix lint

* feat: Add test script and fix gpu shape

* feat: Add test script and fix gpu shape

* fix: Conditional build tftvm op for gpu

* fix: Conditional build tftvm op for gpu

* fix: Fix pylint of tf_op module.py

* fix: Fix pylint of tf_op module.py

* feat: Conditional enable gpu test for tftvm op

* feat: Conditional enable gpu test for tftvm op

* feat: Add tf_tvmdsoop test script as an app test

* fix: Fix gpu/cpu enabled check on tvm in test script

* fix: Make tf tvmdso op test script runnable with pytest

* remove unused test script test_tfop_module.py

* fix: Remove pushd & popd in tfdsoop test script

* fix: Upgrade tftvmop use python3 to find TensorFlow

* fix: Upgrade tftvmop use python3 to find TensorFlow

* fix: Change target_link_options to target_link_libraries

* fix: Add tftvmop build script's c++ option

* fix: Add tvm library path to tf op test library path

* fix: Debug ci build for tftvm dso op

* fix: Fix cmake error and skip tfop test

* fix: Fix typo and indentation issues

* feat: Use TF list input op def

* fix: Fix style and unexpected changes

Co-authored-by: baoxinqi <baoxinqi@4paradigm.com>
Co-authored-by: Chen Dihao <chendihao@4paradigm.com>
Co-authored-by: wrongtest <wrongtest@4paradigm.com>
@zhanghaohit zhanghaohit deleted the add_tvmdsoop branch December 17, 2020 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants