Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Fixing issue #17840 #18526

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open

Fixing issue #17840 #18526

wants to merge 27 commits into from

Conversation

jinboci
Copy link
Contributor

@jinboci jinboci commented Jun 9, 2020

Description

(Brief description on what this PR is about)
Fixing issue #17840. Referring to the tutorial, the problems causing the issue #17840 include:

  • The TVMOp GPU module was not saved,
  • The TVMOp GPU module was not loaded or imported.

This pull request fixes the issue by saving the compiled GPU module to libtvmop.cubin and loading it when import mxnet.

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at https://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the best of my knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Feature1, tests, (and when applicable, API doc)
  • Feature2, tests, (and when applicable, API doc)

Comments

  • If this change is a backward incompatible change, why must this change be made.
  • Interesting edge cases to note here

@jinboci jinboci requested a review from szha as a code owner June 9, 2020 15:18
@mxnet-bot
Copy link

Hey @jinboci , Thanks for submitting the PR
All tests are already queued to run once. If tests fail, you can trigger one or more tests again with the following commands:

  • To trigger all jobs: @mxnet-bot run ci [all]
  • To trigger specific jobs: @mxnet-bot run ci [job1, job2]

CI supported jobs: [website, windows-cpu, unix-cpu, centos-gpu, sanity, edge, unix-gpu, windows-gpu, centos-cpu, clang, miscellaneous]


Note:
Only following 3 categories can trigger CI :PR Author, MXNet Committer, Jenkins Admin.
All CI tests must pass before the PR can be merged.

@jinboci
Copy link
Contributor Author

jinboci commented Jun 10, 2020

@mxnet-bot run ci [unix-cpu]

@mxnet-bot
Copy link

Jenkins CI successfully triggered : [unix-cpu]

imported_modules
except NameError:
imported_modules = []
if len(imported_modules):
Copy link
Member

Choose a reason for hiding this comment

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

why checking imported_modules while actually accessing func_binary.imported_modules ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I fixed it.

libpath_module->Load(libpath);
#if MXNET_USE_CUDA
tvm::runtime::TVMOpModule cubin_module;
cubin_module.Load("libtvmop.cubin");
Copy link
Member

Choose a reason for hiding this comment

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

it should combine with the libpath, otherwise it is loading from ./libtvmop.cubin

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Thanks!

@jinboci
Copy link
Contributor Author

jinboci commented Jun 11, 2020

@mxnet-bot run ci [all]

@mxnet-bot
Copy link

Jenkins CI successfully triggered : [unix-cpu, edge, centos-cpu, website, windows-cpu, clang, sanity, centos-gpu, windows-gpu, unix-gpu, miscellaneous]

@jinboci
Copy link
Contributor Author

jinboci commented Jun 11, 2020

@mxnet-bot run ci [all]

@mxnet-bot
Copy link

Jenkins CI successfully triggered : [clang, edge, sanity, unix-cpu, windows-cpu, centos-cpu, miscellaneous, website, windows-gpu, centos-gpu, unix-gpu]

src/c_api/c_api.cc Outdated Show resolved Hide resolved
libpath_module->Load(libpath);
#if MXNET_USE_CUDA
std::string libpathstr(libpath);
std::string cubinpath = libpathstr.substr(0, libpathstr.size() - 11) + "libtvmop.cubin";
Copy link
Member

Choose a reason for hiding this comment

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

would be better to pass libpath as dir, and do libpath + "libtvmop.so" as well to keep consistency.

Copy link
Contributor Author

@jinboci jinboci Jun 12, 2020

Choose a reason for hiding this comment

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

I rewrite it in a more elegant way :)

Yes, but MXLoadTVMOp is called at:
https://github.com/apache/incubator-mxnet/blob/1bf881f381f91b157a26d9beddcaa8f4960cc038/python/mxnet/tvmop.py#L31-L32
where _LIB_TVM_OP is returned from the
https://github.com/apache/incubator-mxnet/blob/1bf881f381f91b157a26d9beddcaa8f4960cc038/python/mxnet/libinfo.py#L25
, and _LIB_TVM_OP[0] is the path of libtvmop.so.
We may need to modify find_lib_path or write a new function to get the directory that libtvmop.so locates.

try:
func_binary.imported_modules
except NameError:
func_binary.imported_modules = []
Copy link
Member

Choose a reason for hiding this comment

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

from https://github.com/apache/incubator-tvm/blob/master/python/tvm/runtime/module.py#L136 we can see func_binary.imported_modules should always exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your review. I have deleted these lines.

@jinboci jinboci mentioned this pull request Jun 12, 2020
7 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants